Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and force version number in input file #40

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,17 @@ cmake_minimum_required (VERSION 2.6)
project(WorldBuilder C CXX Fortran)

# load in version info and export it
FILE(STRINGS "${CMAKE_SOURCE_DIR}/VERSION" ASPECT_PACKAGE_VERSION LIMIT_COUNT 1)

FILE(STRINGS "${CMAKE_SOURCE_DIR}/VERSION" WORLD_BUILDER_VERSION LIMIT_COUNT 1)

string(REPLACE "-" "." VERSION_LIST_TEMP ${WORLD_BUILDER_VERSION})
string(REPLACE "." ";" VERSION_LIST ${VERSION_LIST_TEMP})
list(LENGTH VERSION_LIST VERSION_LENGTH)
list(GET VERSION_LIST 0 WORLD_BUILDER_VERSION_MAJOR)
list(GET VERSION_LIST 1 WORLD_BUILDER_VERSION_MINOR)
list(GET VERSION_LIST 2 WORLD_BUILDER_VERSION_PATCH)
if (${VERSION_LENGTH} GREATER 3)
list(GET VERSION_LIST 3 WORLD_BUILDER_VERSION_LABEL)
endif()
# the commit's SHA1, and whether the building workspace was dirty or not
find_package(Git)
execute_process(COMMAND
Expand Down
1 change: 1 addition & 0 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ namespace WorldBuilder
static const std::string MAJOR;
static const std::string MINOR;
static const std::string PATCH;
static const std::string LABEL;

static const std::string GIT_SHA1;
static const std::string GIT_BRANCH;
Expand Down
7 changes: 4 additions & 3 deletions source/config.cc.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@

using namespace WorldBuilder;

const std::string Version::MAJOR = "@VERSION_MAJOR@";
const std::string Version::MINOR = "@VERSION_MINOR@";
const std::string Version::PATCH = "@VERSION_PATCH@";
const std::string Version::MAJOR = "@WORLD_BUILDER_VERSION_MAJOR@";
const std::string Version::MINOR = "@WORLD_BUILDER_VERSION_MINOR@";
const std::string Version::PATCH = "@WORLD_BUILDER_VERSION_PATCH@";
const std::string Version::LABEL = "@WORLD_BUILDER_VERSION_LABEL@";

const std::string Version::GIT_SHA1 = "@GIT_SHA1@";
const std::string Version::GIT_BRANCH = "@GIT_BRANCH@";
Expand Down
17 changes: 15 additions & 2 deletions source/world.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#include <sstream>


#include <config.h>
#include <world_builder/world.h>
#include <world_builder/utilities.h>
#include <world_builder/assert.h>
Expand Down Expand Up @@ -50,7 +50,20 @@ namespace WorldBuilder
void World::declare_and_parse(Parameters &prm)
{
/**
* First load the coordinate system parameters.
* First load the major version number in the file and check the major
* version number of the program.
*/
prm.load_entry("version", true, Types::UnsignedInt(NaN::ISNAN,
"The major version number for which the input file was written."));

WBAssertThrow(prm.get_unsigned_int("version") == Utilities::string_to_unsigned_int(Version::MAJOR),
"The major version for which is input file was written is not the "
"same as the version of the World Builder you are running. This means "
"That there have been incompatible changes made between the versions. "
"Verify those changes and wheter they affect your model. If this is not "
"the case, adjust the version number in the input file.");
/**
* Seconly load the coordinate system parameters.
*/
prm.load_entry("coordinate system", false, Types::CoordinateSystem("cartesian","This determines the coordinate system"));

Expand Down
1 change: 1 addition & 0 deletions tests/app/app_spherical.wb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"version":0,
"cross section": [[100e3,100e3],[400e3,500e3]],
"coordinate system":{"spherical":{"depth method":"starting point"}},
"surface rotation point": ["0","0"],
Expand Down
1 change: 1 addition & 0 deletions tests/app/app_wb1.wb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"version":0,
"cross section": [[100e3,100e3],[400e3,500e3]],
"coordinate system":{"Cartesian":{}},
"surface rotation point": ["165e3","166e3"],
Expand Down
1 change: 1 addition & 0 deletions tests/app/app_wb2.wb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"version":0,
"surface rotation point": ["165e3","166e3"],
"surface rotation angle": "0",
"minimum parts per distance unit": 5,
Expand Down
1 change: 1 addition & 0 deletions tests/app/app_wb3.wb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"version":0,
"surface rotation point": ["165e3","166e3"],
"surface rotation angle": "0",
"sinimum parts per distance unit": 5,
Expand Down
1 change: 1 addition & 0 deletions tests/data/continental_plate.wb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"version":0,
"cross section": [[100e3,100e3],[400e3,500e3]],
"coordinate system":{"cartesian":{}},
"surface rotation point": ["165e3","166e3"],
Expand Down
1 change: 1 addition & 0 deletions tests/data/oceanic_plate_cartesian.wb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"version":0,
"cross section": [[100e3,100e3],[400e3,500e3]],
"coordinate system":{"cartesian":{}},
"surface rotation point": ["165e3","166e3"],
Expand Down
1 change: 1 addition & 0 deletions tests/data/oceanic_plate_spherical.wb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"version":0,
"cross section": [[100e3,100e3],[400e3,500e3]],
"coordinate system":{"spherical":{"depth method":"starting point"}},
"surface rotation point": ["165e3","166e3"],
Expand Down
1 change: 1 addition & 0 deletions tests/data/simple_wb1.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"version":0,
"cross section": [[100e3,100e3],[400e3,500e3]],
"coordinate system":{"cartesian":{}},
"surface rotation point": ["165e3","166e3"],
Expand Down
1 change: 1 addition & 0 deletions tests/data/simple_wb2.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"version":0,
"surface rotation point": ["165e3","166e3"],
"surface rotation angle": "0",
"minimum parts per distance unit": 5,
Expand Down
1 change: 1 addition & 0 deletions tests/data/simple_wb3.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"version":0,
"surface rotation point": ["165e3","166e3"],
"surface rotation angle": "0",
"minimum parts per distance unit": 5,
Expand Down
1 change: 1 addition & 0 deletions tests/data/subducting_plate_constant_angles_cartesian.wb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"version":0,
"cross section": [[100e3,100e3],[400e3,500e3]],
"coordinate system":{"cartesian":{}},
"surface rotation point": ["165e3","166e3"],
Expand Down
1 change: 1 addition & 0 deletions tests/data/subducting_plate_different_angles_cartesian.wb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"version":0,
"cross section": [[100e3,100e3],[400e3,500e3]],
"coordinate system":{"cartesian":{}},
"surface rotation point": ["165e3","166e3"],
Expand Down
1 change: 1 addition & 0 deletions tests/data/subducting_plate_different_angles_spherical.wb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"version":0,
"cross section": [[100e3,100e3],[400e3,500e3]],
"coordinate system":{"spherical":{"depth method":"starting point"}},
"surface rotation point": ["165e3","166e3"],
Expand Down
1 change: 1 addition & 0 deletions tests/unit_tests/unit_test_world_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1573,6 +1573,7 @@ TEST_CASE("WorldBuilder Types: print_tree")
std::stringstream output;
output <<
"{\n" <<
" \"version\": \"0\",\n"
" \"cross section\": \n" <<
" {\n" <<
" \"\": \n" <<
Expand Down