Skip to content

Commit e8eb2c9

Browse files
committed
try fix windows bug 0003...
1 parent 8de1cdb commit e8eb2c9

File tree

1 file changed

+130
-129
lines changed

1 file changed

+130
-129
lines changed

source/world_builder/parameters.cc

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

0 commit comments

Comments
 (0)