Skip to content

Commit db08599

Browse files
committed
try fix windows bug 0005...
1 parent 59ad675 commit db08599

File tree

2 files changed

+135
-135
lines changed

2 files changed

+135
-135
lines changed

source/world_builder/parameters.cc

Lines changed: 134 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -700,140 +700,140 @@ namespace WorldBuilder
700700
}
701701
}
702702
}
703-
else if (input_type == InputTypes::STRING_TYPE)
704-
{
705-
/*
706-
// case 5: a string. Get the string and decode it
707-
std::string value = "";
708-
709-
try
710-
{
711-
value = Pointer((strict_base + "/" + name).c_str()).Get(parameters)->GetString();
712-
}
713-
catch (...)
714-
{
715-
WBAssertThrow(false, "Could not convert values of " << strict_base << "/" << name << " into a String. "
716-
<< "The provided value was \"" << Pointer((strict_base + "/" + name).c_str()).Get(parameters)->GetString() << "\".");
717-
}
718-
if (value.substr(0,8) == "Litho1.0")
719-
{
720-
/ *
721-
enum LayerType
722-
{
723-
// ASTHENOSPHERE,
724-
LITHOSPHERE,
725-
CRUST3,
726-
CRUST2,
727-
CRUST1,
728-
SEDIMENT3,
729-
SEDIMENT2,
730-
SEDIMENT1,
731-
ICE,
732-
WATER,
733-
MAX_LAYERTYPE
734-
};
735-
size_t colon_location = value.find(':');
736-
WBAssertThrow(colon_location!= std::string::npos,"when choosing Litho1.0 you need to specify a subunit with the colon (:)." );
737-
std::string rest_of_string = value.substr(colon_location); // TODO: improve and make more robust, look at gwb-dat example
738-
while ((!rest_of_string.empty()) && (rest_of_string[0] == ' '))
739-
rest_of_string.erase(rest_of_string.begin());
740-
while ((!rest_of_string.empty()) && (rest_of_string[0] == ':'))
741-
rest_of_string.erase(rest_of_string.begin());
742-
while ((!rest_of_string.empty()) && (rest_of_string[0] == ' '))
743-
rest_of_string.erase(rest_of_string.begin());
744-
while ((!rest_of_string.empty()) && (rest_of_string[rest_of_string.size() - 1] == ' '))
745-
rest_of_string.erase(rest_of_string.end() - 1);
746-
LayerType layer_type = LayerType::MAX_LAYERTYPE;
747-
if (rest_of_string == "lithosphere")
748-
{
749-
layer_type = LayerType::LITHOSPHERE;
750-
}
751-
else if (rest_of_string == "crust 3")
752-
{
753-
layer_type = LayerType::CRUST3;
754-
}
755-
else if (rest_of_string == "crust 2")
756-
{
757-
layer_type = LayerType::CRUST2;
758-
}
759-
else if (rest_of_string == "crust 1")
760-
{
761-
layer_type = LayerType::CRUST1;
762-
}
763-
else if (rest_of_string == "sediment 3")
764-
{
765-
layer_type = LayerType::SEDIMENT3;
766-
}
767-
else if (rest_of_string == "sediment 2")
768-
{
769-
layer_type = LayerType::SEDIMENT2;
770-
}
771-
else if (rest_of_string == "sediment 1")
772-
{
773-
layer_type = LayerType::SEDIMENT1;
774-
}
775-
else if (rest_of_string == "ice")
776-
{
777-
layer_type = LayerType::ICE;
778-
}
779-
else if (rest_of_string == "water")
780-
{
781-
layer_type = LayerType::WATER;
782-
}
783-
WBAssertThrow(layer_type != LayerType::MAX_LAYERTYPE, "Could not find litho1.0 layer type " << rest_of_string);
784-
std::string litho_1_0_path = "";
785-
Value *value_pointer = Pointer("/Litho1.0 path").Get(parameters);
786-
WBAssertThrow(value_pointer != nullptr, "You are using the Litho1.0 dataset, but you have not specified the path to the dataset. Please add below \"version\": \"Litho1.0 path\". ");
787-
try
788-
{
789-
litho_1_0_path = value_pointer->GetString();
790-
}
791-
catch (...)
792-
{
793-
WBAssertThrow(false, "Could not convert values of /Litho1.0 path into a String. ");
794-
}
703+
//else if (input_type == InputTypes::STRING_TYPE)
704+
//{
705+
/*
706+
// case 5: a string. Get the string and decode it
707+
std::string value = "";
708+
709+
try
710+
{
711+
value = Pointer((strict_base + "/" + name).c_str()).Get(parameters)->GetString();
712+
}
713+
catch (...)
714+
{
715+
WBAssertThrow(false, "Could not convert values of " << strict_base << "/" << name << " into a String. "
716+
<< "The provided value was \"" << Pointer((strict_base + "/" + name).c_str()).Get(parameters)->GetString() << "\".");
717+
}
718+
if (value.substr(0,8) == "Litho1.0")
719+
{
720+
/ *
721+
enum LayerType
722+
{
723+
// ASTHENOSPHERE,
724+
LITHOSPHERE,
725+
CRUST3,
726+
CRUST2,
727+
CRUST1,
728+
SEDIMENT3,
729+
SEDIMENT2,
730+
SEDIMENT1,
731+
ICE,
732+
WATER,
733+
MAX_LAYERTYPE
734+
};
735+
size_t colon_location = value.find(':');
736+
WBAssertThrow(colon_location!= std::string::npos,"when choosing Litho1.0 you need to specify a subunit with the colon (:)." );
737+
std::string rest_of_string = value.substr(colon_location); // TODO: improve and make more robust, look at gwb-dat example
738+
while ((!rest_of_string.empty()) && (rest_of_string[0] == ' '))
739+
rest_of_string.erase(rest_of_string.begin());
740+
while ((!rest_of_string.empty()) && (rest_of_string[0] == ':'))
741+
rest_of_string.erase(rest_of_string.begin());
742+
while ((!rest_of_string.empty()) && (rest_of_string[0] == ' '))
743+
rest_of_string.erase(rest_of_string.begin());
744+
while ((!rest_of_string.empty()) && (rest_of_string[rest_of_string.size() - 1] == ' '))
745+
rest_of_string.erase(rest_of_string.end() - 1);
746+
LayerType layer_type = LayerType::MAX_LAYERTYPE;
747+
if (rest_of_string == "lithosphere")
748+
{
749+
layer_type = LayerType::LITHOSPHERE;
750+
}
751+
else if (rest_of_string == "crust 3")
752+
{
753+
layer_type = LayerType::CRUST3;
754+
}
755+
else if (rest_of_string == "crust 2")
756+
{
757+
layer_type = LayerType::CRUST2;
758+
}
759+
else if (rest_of_string == "crust 1")
760+
{
761+
layer_type = LayerType::CRUST1;
762+
}
763+
else if (rest_of_string == "sediment 3")
764+
{
765+
layer_type = LayerType::SEDIMENT3;
766+
}
767+
else if (rest_of_string == "sediment 2")
768+
{
769+
layer_type = LayerType::SEDIMENT2;
770+
}
771+
else if (rest_of_string == "sediment 1")
772+
{
773+
layer_type = LayerType::SEDIMENT1;
774+
}
775+
else if (rest_of_string == "ice")
776+
{
777+
layer_type = LayerType::ICE;
778+
}
779+
else if (rest_of_string == "water")
780+
{
781+
layer_type = LayerType::WATER;
782+
}
783+
WBAssertThrow(layer_type != LayerType::MAX_LAYERTYPE, "Could not find litho1.0 layer type " << rest_of_string);
784+
std::string litho_1_0_path = "";
785+
Value *value_pointer = Pointer("/Litho1.0 path").Get(parameters);
786+
WBAssertThrow(value_pointer != nullptr, "You are using the Litho1.0 dataset, but you have not specified the path to the dataset. Please add below \"version\": \"Litho1.0 path\". ");
787+
try
788+
{
789+
litho_1_0_path = value_pointer->GetString();
790+
}
791+
catch (...)
792+
{
793+
WBAssertThrow(false, "Could not convert values of /Litho1.0 path into a String. ");
794+
}
795795
796-
constexpr int n1 = 40; //962;
797-
constexpr int n_layers = 9;
798-
float depth_data[n1 * n_layers];
799-
char tessfile[255];
800-
snprintf(tessfile, 254, "%s/litho_depth_data.bin", litho_1_0_path.c_str());
801-
FILE *fptrb = nullptr;
802-
if ((fptrb = fopen(tessfile, "rb")) == nullptr)
803-
{
804-
WBAssertThrow(false, "ERROR: Could not open file " << tessfile);
805-
}
806-
const size_t ret_code = fread(&depth_data, sizeof(float), n1 * n_layers, fptrb);
807-
WBAssertThrow(ret_code == n1 * n_layers, "Error in reading the Litho1.0 data.");
808-
fclose(fptrb);
809-
810-
snprintf(tessfile, 254, "%s/Icosahedron_Level7_LatLon_mod.txt",
811-
litho_1_0_path.c_str());
812-
FILE *fp = nullptr;
813-
if ((fp = fopen(tessfile, "r")) == nullptr)
814-
{
815-
WBAssertThrow(false, "ERROR: Could not open file " << tessfile);
816-
}
817-
818-
size_t counter_location_data = 0;
819-
float latitude, glatitude, longitude = 0;
820-
while (fscanf(fp, "%f %f %f", &latitude, &glatitude, &longitude) != EOF)
821-
{
822-
const size_t global_index = (counter_location_data/2)*n_layers+static_cast<size_t> (layer_type);
823-
result.first.emplace_back(depth_data[global_index]);
824-
result.second.emplace_back(longitude * Consts::PI / 180.);
825-
result.second.emplace_back(latitude * Consts::PI / 180.);
826-
counter_location_data += 2;
827-
}
828-
829-
fclose(fp);* /
830-
}
831-
else
832-
{
833-
WBAssertThrow(false,"Could not find \"" << value << "\" in \"" << strict_base << "/" << name << "\". ");
834-
}
835-
assert(result.first.size() > 0);*/
836-
}
796+
constexpr int n1 = 40; //962;
797+
constexpr int n_layers = 9;
798+
float depth_data[n1 * n_layers];
799+
char tessfile[255];
800+
snprintf(tessfile, 254, "%s/litho_depth_data.bin", litho_1_0_path.c_str());
801+
FILE *fptrb = nullptr;
802+
if ((fptrb = fopen(tessfile, "rb")) == nullptr)
803+
{
804+
WBAssertThrow(false, "ERROR: Could not open file " << tessfile);
805+
}
806+
const size_t ret_code = fread(&depth_data, sizeof(float), n1 * n_layers, fptrb);
807+
WBAssertThrow(ret_code == n1 * n_layers, "Error in reading the Litho1.0 data.");
808+
fclose(fptrb);
809+
810+
snprintf(tessfile, 254, "%s/Icosahedron_Level7_LatLon_mod.txt",
811+
litho_1_0_path.c_str());
812+
FILE *fp = nullptr;
813+
if ((fp = fopen(tessfile, "r")) == nullptr)
814+
{
815+
WBAssertThrow(false, "ERROR: Could not open file " << tessfile);
816+
}
817+
818+
size_t counter_location_data = 0;
819+
float latitude, glatitude, longitude = 0;
820+
while (fscanf(fp, "%f %f %f", &latitude, &glatitude, &longitude) != EOF)
821+
{
822+
const size_t global_index = (counter_location_data/2)*n_layers+static_cast<size_t> (layer_type);
823+
result.first.emplace_back(depth_data[global_index]);
824+
result.second.emplace_back(longitude * Consts::PI / 180.);
825+
result.second.emplace_back(latitude * Consts::PI / 180.);
826+
counter_location_data += 2;
827+
}
828+
829+
fclose(fp);* /
830+
}
831+
else
832+
{
833+
WBAssertThrow(false,"Could not find \"" << value << "\" in \"" << strict_base << "/" << name << "\". ");
834+
}
835+
assert(result.first.size() > 0);*/
836+
//}
837837
else
838838
{
839839
// case 2: there one value, not an array
@@ -855,7 +855,7 @@ namespace WorldBuilder
855855
// there is no user defined value. Case one: return the default value and no points
856856
result.first.emplace_back(default_value);
857857
}
858-
assert(result.first.size() > 0);
858+
//assert(result.first.size() > 0);
859859
WBAssertThrow(result.first.size() > 0, "Internal error: no entries returned when fetching value at points.");
860860
return result;
861861
}

tests/unit_tests/unit_test_world_builder.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4151,7 +4151,7 @@ TEST_CASE("WorldBuilder Parameters")
41514151

41524152

41534153
CHECK_THROWS_WITH(prm.get("one value at points one value string",additional_points),
4154-
Contains("Could not find"));
4154+
Contains("Could not convert values of /one value at points one value string into a double. The provided value was \"test1\"."));
41554155
CHECK_THROWS_WITH(prm.get("array value at points one value string",additional_points),
41564156
Contains("Could not convert values of /array value at points one value string/0/0 into a double. The provided value was \"test2\"."));
41574157
CHECK_THROWS_WITH(prm.get("value at points set ap val string",additional_points),

0 commit comments

Comments
 (0)