Skip to content

Commit 8de1cdb

Browse files
committed
try fix windows bug 0002...
1 parent 23d9e67 commit 8de1cdb

File tree

1 file changed

+109
-108
lines changed

1 file changed

+109
-108
lines changed

source/world_builder/parameters.cc

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

0 commit comments

Comments
 (0)