Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
ogs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dmitri Naumov
ogs
Commits
0d20088f
Commit
0d20088f
authored
5 years ago
by
Karsten Rink
Committed by
Lars Bilke
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
static functions + const params
parent
aa268e1a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Applications/Utils/FileConverter/NetCdfConverter.cpp
+38
-34
38 additions, 34 deletions
Applications/Utils/FileConverter/NetCdfConverter.cpp
with
38 additions
and
34 deletions
Applications/Utils/FileConverter/NetCdfConverter.cpp
+
38
−
34
View file @
0d20088f
...
@@ -34,13 +34,14 @@ using namespace netCDF;
...
@@ -34,13 +34,14 @@ using namespace netCDF;
const
double
no_data
=
-
9999
;
const
double
no_data
=
-
9999
;
void
checkExit
(
std
::
string
const
&
str
)
static
void
checkExit
(
std
::
string
const
&
str
)
{
{
if
(
str
==
"x"
||
str
==
"exit"
)
if
(
str
==
"x"
||
str
==
"exit"
)
exit
(
0
);
exit
(
0
);
}
}
void
showErrorMessage
(
std
::
size_t
const
error_id
,
std
::
size_t
const
max
=
0
)
static
void
showErrorMessage
(
std
::
size_t
const
error_id
,
std
::
size_t
const
max
=
0
)
{
{
if
(
error_id
==
0
)
if
(
error_id
==
0
)
{
{
...
@@ -58,8 +59,9 @@ void showErrorMessage(std::size_t const error_id, std::size_t const max = 0)
...
@@ -58,8 +59,9 @@ void showErrorMessage(std::size_t const error_id, std::size_t const max = 0)
}
}
}
}
std
::
size_t
parseInput
(
std
::
string
const
&
request_str
,
std
::
size_t
max_val
,
static
std
::
size_t
parseInput
(
std
::
string
const
&
request_str
,
bool
has_info
=
false
)
std
::
size_t
const
max_val
,
bool
const
has_info
=
false
)
{
{
while
(
true
)
while
(
true
)
{
{
...
@@ -87,13 +89,14 @@ std::size_t parseInput(std::string const& request_str, std::size_t max_val,
...
@@ -87,13 +89,14 @@ std::size_t parseInput(std::string const& request_str, std::size_t max_val,
return
std
::
numeric_limits
<
std
::
size_t
>::
max
();
return
std
::
numeric_limits
<
std
::
size_t
>::
max
();
}
}
NcVar
getDimVar
(
NcFile
const
&
dataset
,
NcVar
const
&
var
,
std
::
size_t
const
dim
)
static
NcVar
getDimVar
(
NcFile
const
&
dataset
,
NcVar
const
&
var
,
std
::
size_t
const
dim
)
{
{
NcDim
const
&
dim_obj
=
var
.
getDim
(
dim
);
NcDim
const
&
dim_obj
=
var
.
getDim
(
dim
);
return
dataset
.
getVar
(
dim_obj
.
getName
());
return
dataset
.
getVar
(
dim_obj
.
getName
());
}
}
std
::
vector
<
std
::
string
>
getArrays
(
NcFile
const
&
dataset
)
static
std
::
vector
<
std
::
string
>
getArrays
(
NcFile
const
&
dataset
)
{
{
auto
const
&
names
=
dataset
.
getVars
();
auto
const
&
names
=
dataset
.
getVars
();
std
::
vector
<
std
::
string
>
var_names
;
std
::
vector
<
std
::
string
>
var_names
;
...
@@ -104,7 +107,7 @@ std::vector<std::string> getArrays(NcFile const& dataset)
...
@@ -104,7 +107,7 @@ std::vector<std::string> getArrays(NcFile const& dataset)
return
var_names
;
return
var_names
;
}
}
void
showArrays
(
NcFile
const
&
dataset
)
static
void
showArrays
(
NcFile
const
&
dataset
)
{
{
std
::
size_t
const
n_vars
(
dataset
.
getDimCount
());
std
::
size_t
const
n_vars
(
dataset
.
getDimCount
());
std
::
cout
<<
"The NetCDF file contains the following "
<<
n_vars
std
::
cout
<<
"The NetCDF file contains the following "
<<
n_vars
...
@@ -121,7 +124,7 @@ void showArrays(NcFile const& dataset)
...
@@ -121,7 +124,7 @@ void showArrays(NcFile const& dataset)
std
::
cout
<<
"
\n
"
;
std
::
cout
<<
"
\n
"
;
}
}
void
showArraysDims
(
NcVar
const
&
var
)
static
void
showArraysDims
(
NcVar
const
&
var
)
{
{
std
::
cout
<<
"Data array
\"
"
<<
var
.
getName
()
std
::
cout
<<
"Data array
\"
"
<<
var
.
getName
()
<<
"
\"
contains the following dimensions:
\n
"
;
<<
"
\"
contains the following dimensions:
\n
"
;
...
@@ -132,7 +135,7 @@ void showArraysDims(NcVar const& var)
...
@@ -132,7 +135,7 @@ void showArraysDims(NcVar const& var)
std
::
cout
<<
"
\n
"
;
std
::
cout
<<
"
\n
"
;
}
}
std
::
pair
<
double
,
double
>
getBoundaries
(
NcVar
const
&
var
)
static
std
::
pair
<
double
,
double
>
getBoundaries
(
NcVar
const
&
var
)
{
{
if
(
var
.
getDimCount
()
==
1
)
if
(
var
.
getDimCount
()
==
1
)
{
{
...
@@ -145,7 +148,7 @@ std::pair<double, double> getBoundaries(NcVar const& var)
...
@@ -145,7 +148,7 @@ std::pair<double, double> getBoundaries(NcVar const& var)
return
std
::
make_pair
(
0
,
0
);
return
std
::
make_pair
(
0
,
0
);
}
}
MathLib
::
Point3d
getOrigin
(
NcFile
const
&
dataset
,
NcVar
const
&
var
,
static
MathLib
::
Point3d
getOrigin
(
NcFile
const
&
dataset
,
NcVar
const
&
var
,
std
::
array
<
std
::
size_t
,
4
>
const
&
dim_idx_map
,
std
::
array
<
std
::
size_t
,
4
>
const
&
dim_idx_map
,
bool
is_time_dep
)
bool
is_time_dep
)
{
{
...
@@ -162,8 +165,8 @@ MathLib::Point3d getOrigin(NcFile const& dataset, NcVar const& var,
...
@@ -162,8 +165,8 @@ MathLib::Point3d getOrigin(NcFile const& dataset, NcVar const& var,
return
origin
;
return
origin
;
}
}
void
flipRaster
(
std
::
vector
<
double
>&
data
,
std
::
size_t
width
,
static
void
flipRaster
(
std
::
vector
<
double
>&
data
,
std
::
size_t
const
width
,
std
::
size_t
height
)
std
::
size_t
const
height
)
{
{
std
::
size_t
const
length
(
data
.
size
());
std
::
size_t
const
length
(
data
.
size
());
std
::
vector
<
double
>
tmp_vec
(
length
);
std
::
vector
<
double
>
tmp_vec
(
length
);
...
@@ -178,7 +181,7 @@ void flipRaster(std::vector<double>& data, std::size_t width,
...
@@ -178,7 +181,7 @@ void flipRaster(std::vector<double>& data, std::size_t width,
std
::
copy
(
tmp_vec
.
cbegin
(),
tmp_vec
.
cend
(),
data
.
begin
());
std
::
copy
(
tmp_vec
.
cbegin
(),
tmp_vec
.
cend
(),
data
.
begin
());
}
}
bool
canConvert
(
NcVar
const
&
var
)
static
bool
canConvert
(
NcVar
const
&
var
)
{
{
bool
ret
(
var
.
getDimCount
()
<
2
);
bool
ret
(
var
.
getDimCount
()
<
2
);
if
(
ret
)
if
(
ret
)
...
@@ -186,7 +189,7 @@ bool canConvert(NcVar const& var)
...
@@ -186,7 +189,7 @@ bool canConvert(NcVar const& var)
return
!
ret
;
return
!
ret
;
}
}
std
::
string
arraySelectionLoop
(
NcFile
const
&
dataset
)
static
std
::
string
arraySelectionLoop
(
NcFile
const
&
dataset
)
{
{
std
::
vector
<
std
::
string
>
const
&
names
=
getArrays
(
dataset
);
std
::
vector
<
std
::
string
>
const
&
names
=
getArrays
(
dataset
);
showArrays
(
dataset
);
showArrays
(
dataset
);
...
@@ -200,7 +203,7 @@ std::string arraySelectionLoop(NcFile const& dataset)
...
@@ -200,7 +203,7 @@ std::string arraySelectionLoop(NcFile const& dataset)
return
names
[
idx
];
return
names
[
idx
];
}
}
bool
dimensionSelectionLoop
(
NcVar
const
&
var
,
static
bool
dimensionSelectionLoop
(
NcVar
const
&
var
,
std
::
array
<
std
::
size_t
,
4
>&
dim_idx_map
)
std
::
array
<
std
::
size_t
,
4
>&
dim_idx_map
)
{
{
showArraysDims
(
var
);
showArraysDims
(
var
);
...
@@ -265,9 +268,8 @@ bool dimensionSelectionLoop(NcVar const& var,
...
@@ -265,9 +268,8 @@ bool dimensionSelectionLoop(NcVar const& var,
return
is_time_dep
;
return
is_time_dep
;
}
}
std
::
pair
<
std
::
size_t
,
std
::
size_t
>
timestepSelectionLoop
(
NcFile
const
&
dataset
,
static
std
::
pair
<
std
::
size_t
,
std
::
size_t
>
timestepSelectionLoop
(
NcVar
const
&
var
,
NcFile
const
&
dataset
,
NcVar
const
&
var
,
std
::
size_t
const
dim_idx
)
std
::
size_t
dim_idx
)
{
{
std
::
size_t
const
n_time_steps
=
var
.
getDim
(
dim_idx
).
getSize
();
std
::
size_t
const
n_time_steps
=
var
.
getDim
(
dim_idx
).
getSize
();
std
::
pair
<
std
::
size_t
,
std
::
size_t
>
bounds
(
std
::
pair
<
std
::
size_t
,
std
::
size_t
>
bounds
(
...
@@ -282,7 +284,7 @@ std::pair<std::size_t, std::size_t> timestepSelectionLoop(NcFile const& dataset,
...
@@ -282,7 +284,7 @@ std::pair<std::size_t, std::size_t> timestepSelectionLoop(NcFile const& dataset,
return
bounds
;
return
bounds
;
}
}
MeshLib
::
MeshElemType
elemSelectionLoop
(
std
::
size_t
const
dim
)
static
MeshLib
::
MeshElemType
elemSelectionLoop
(
std
::
size_t
const
dim
)
{
{
if
(
dim
==
1
)
if
(
dim
==
1
)
return
MeshLib
::
MeshElemType
::
LINE
;
return
MeshLib
::
MeshElemType
::
LINE
;
...
@@ -323,7 +325,7 @@ MeshLib::MeshElemType elemSelectionLoop(std::size_t const dim)
...
@@ -323,7 +325,7 @@ MeshLib::MeshElemType elemSelectionLoop(std::size_t const dim)
return
t
;
return
t
;
}
}
bool
multFilesSelectionLoop
(
static
bool
multFilesSelectionLoop
(
std
::
pair
<
std
::
size_t
,
std
::
size_t
>
const
&
time_bounds
)
std
::
pair
<
std
::
size_t
,
std
::
size_t
>
const
&
time_bounds
)
{
{
std
::
size_t
const
n_time_steps
(
time_bounds
.
second
-
time_bounds
.
first
+
1
);
std
::
size_t
const
n_time_steps
(
time_bounds
.
second
-
time_bounds
.
first
+
1
);
...
@@ -334,17 +336,17 @@ bool multFilesSelectionLoop(
...
@@ -334,17 +336,17 @@ bool multFilesSelectionLoop(
std
::
cout
<<
"1. Save data in one mesh file with "
<<
n_time_steps
std
::
cout
<<
"1. Save data in one mesh file with "
<<
n_time_steps
<<
" scalar arrays.
\n
"
;
<<
" scalar arrays.
\n
"
;
std
::
size_t
ret
=
parseInput
(
"Select preferred method: "
,
2
,
false
);
std
::
size_t
ret
=
parseInput
(
"Select preferred method: "
,
2
,
false
);
return
(
ret
=
=
0
);
return
(
ret
!
=
0
);
}
}
std
::
string
getIterationString
(
std
::
size_t
i
,
std
::
size_t
max
)
static
std
::
string
getIterationString
(
std
::
size_t
i
,
std
::
size_t
max
)
{
{
std
::
size_t
const
max_length
(
std
::
to_string
(
max
).
length
());
std
::
size_t
const
max_length
(
std
::
to_string
(
max
).
length
());
std
::
string
const
current_str
(
std
::
to_string
(
i
));
std
::
string
const
current_str
(
std
::
to_string
(
i
));
return
std
::
string
(
max_length
-
current_str
.
length
(),
'0'
)
+
current_str
;
return
std
::
string
(
max_length
-
current_str
.
length
(),
'0'
)
+
current_str
;
}
}
double
getResolution
(
NcFile
const
&
dataset
,
NcVar
const
&
var
)
static
double
getResolution
(
NcFile
const
&
dataset
,
NcVar
const
&
var
)
{
{
std
::
size_t
const
dim_idx
=
var
.
getDimCount
()
-
1
;
std
::
size_t
const
dim_idx
=
var
.
getDimCount
()
-
1
;
auto
const
bounds
=
getBoundaries
(
getDimVar
(
dataset
,
var
,
dim_idx
));
auto
const
bounds
=
getBoundaries
(
getDimVar
(
dataset
,
var
,
dim_idx
));
...
@@ -352,7 +354,7 @@ double getResolution(NcFile const& dataset, NcVar const& var)
...
@@ -352,7 +354,7 @@ double getResolution(NcFile const& dataset, NcVar const& var)
static_cast
<
double
>
(
var
.
getDim
(
dim_idx
).
getSize
());
static_cast
<
double
>
(
var
.
getDim
(
dim_idx
).
getSize
());
}
}
GeoLib
::
RasterHeader
createRasterHeader
(
static
GeoLib
::
RasterHeader
createRasterHeader
(
NcFile
const
&
dataset
,
NcVar
const
&
var
,
NcFile
const
&
dataset
,
NcVar
const
&
var
,
std
::
array
<
std
::
size_t
,
4
>
const
&
dim_idx_map
,
std
::
array
<
std
::
size_t
,
4
>
const
&
dim_idx_map
,
std
::
vector
<
std
::
size_t
>
const
&
length
,
bool
is_time_dep
)
std
::
vector
<
std
::
size_t
>
const
&
length
,
bool
is_time_dep
)
...
@@ -368,12 +370,12 @@ GeoLib::RasterHeader createRasterHeader(
...
@@ -368,12 +370,12 @@ GeoLib::RasterHeader createRasterHeader(
z_length
,
origin
,
res
,
no_data
};
z_length
,
origin
,
res
,
no_data
};
}
}
std
::
size_t
getLength
(
NcVar
const
&
var
,
bool
const
is_time_dep
,
static
std
::
size_t
getLength
(
NcVar
const
&
var
,
bool
const
is_time_dep
,
std
::
vector
<
std
::
size_t
>&
length
)
std
::
vector
<
std
::
size_t
>&
length
)
{
{
std
::
size_t
const
temp_offset
=
(
is_time_dep
)
?
1
:
0
;
std
::
size_t
const
temp_offset
=
(
is_time_dep
)
?
1
:
0
;
std
::
size_t
const
n_dims
=
(
var
.
getDimCount
());
std
::
size_t
const
n_dims
=
(
var
.
getDimCount
());
length
.
resize
(
4
,
1
);
length
.
resize
(
n_dims
,
1
);
std
::
size_t
array_length
=
1
;
std
::
size_t
array_length
=
1
;
for
(
std
::
size_t
i
=
temp_offset
;
i
<
n_dims
;
++
i
)
for
(
std
::
size_t
i
=
temp_offset
;
i
<
n_dims
;
++
i
)
{
{
...
@@ -383,8 +385,8 @@ std::size_t getLength(NcVar const& var, bool const is_time_dep,
...
@@ -383,8 +385,8 @@ std::size_t getLength(NcVar const& var, bool const is_time_dep,
return
array_length
;
return
array_length
;
}
}
std
::
vector
<
double
>
getData
(
NcFile
const
&
dataset
,
NcVar
const
&
var
,
static
std
::
vector
<
double
>
getData
(
NcFile
const
&
dataset
,
NcVar
const
&
var
,
std
::
size_t
total_length
,
std
::
size_t
const
total_length
,
std
::
size_t
const
time_step
,
std
::
size_t
const
time_step
,
std
::
vector
<
std
::
size_t
>
const
&
length
)
std
::
vector
<
std
::
size_t
>
const
&
length
)
{
{
...
@@ -404,7 +406,7 @@ std::vector<double> getData(NcFile const& dataset, NcVar const& var,
...
@@ -404,7 +406,7 @@ std::vector<double> getData(NcFile const& dataset, NcVar const& var,
return
data_vec
;
return
data_vec
;
}
}
bool
assignDimParams
(
NcVar
const
&
var
,
static
bool
assignDimParams
(
NcVar
const
&
var
,
std
::
array
<
std
::
size_t
,
4
>&
dim_idx_map
,
std
::
array
<
std
::
size_t
,
4
>&
dim_idx_map
,
TCLAP
::
ValueArg
<
std
::
size_t
>&
arg_dim_time
,
TCLAP
::
ValueArg
<
std
::
size_t
>&
arg_dim_time
,
TCLAP
::
ValueArg
<
std
::
size_t
>&
arg_dim1
,
TCLAP
::
ValueArg
<
std
::
size_t
>&
arg_dim1
,
...
@@ -442,9 +444,10 @@ bool assignDimParams(NcVar const& var,
...
@@ -442,9 +444,10 @@ bool assignDimParams(NcVar const& var,
return
true
;
return
true
;
}
}
std
::
pair
<
std
::
size_t
,
std
::
size_t
>
assignTimeBounds
(
NcVar
const
&
var
,
static
std
::
pair
<
std
::
size_t
,
std
::
size_t
>
assignTimeBounds
(
TCLAP
::
ValueArg
<
std
::
size_t
>&
arg_time_start
,
NcVar
const
&
var
,
TCLAP
::
ValueArg
<
std
::
size_t
>&
arg_time_end
)
TCLAP
::
ValueArg
<
std
::
size_t
>&
arg_time_start
,
TCLAP
::
ValueArg
<
std
::
size_t
>&
arg_time_end
)
{
{
auto
const
bounds
=
getBoundaries
(
var
);
auto
const
bounds
=
getBoundaries
(
var
);
if
(
arg_time_start
.
getValue
()
>
bounds
.
second
)
if
(
arg_time_start
.
getValue
()
>
bounds
.
second
)
...
@@ -471,7 +474,8 @@ std::pair<std::size_t, std::size_t> assignTimeBounds(NcVar const& var,
...
@@ -471,7 +474,8 @@ std::pair<std::size_t, std::size_t> assignTimeBounds(NcVar const& var,
return
{
arg_time_start
.
getValue
(),
arg_time_end
.
getValue
()};
return
{
arg_time_start
.
getValue
(),
arg_time_end
.
getValue
()};
}
}
MeshLib
::
MeshElemType
assignElemType
(
TCLAP
::
ValueArg
<
std
::
string
>&
arg_elem_type
)
static
MeshLib
::
MeshElemType
assignElemType
(
TCLAP
::
ValueArg
<
std
::
string
>&
arg_elem_type
)
{
{
if
(
arg_elem_type
.
getValue
()
==
"tri"
)
if
(
arg_elem_type
.
getValue
()
==
"tri"
)
return
MeshLib
::
MeshElemType
::
TRIANGLE
;
return
MeshLib
::
MeshElemType
::
TRIANGLE
;
...
@@ -485,7 +489,7 @@ MeshLib::MeshElemType assignElemType(TCLAP::ValueArg<std::string>& arg_elem_type
...
@@ -485,7 +489,7 @@ MeshLib::MeshElemType assignElemType(TCLAP::ValueArg<std::string>& arg_elem_type
return
MeshLib
::
MeshElemType
::
INVALID
;
return
MeshLib
::
MeshElemType
::
INVALID
;
}
}
bool
convert
(
NcFile
const
&
dataset
,
NcVar
const
&
var
,
static
bool
convert
(
NcFile
const
&
dataset
,
NcVar
const
&
var
,
std
::
string
const
&
output_name
,
std
::
string
const
&
output_name
,
std
::
array
<
std
::
size_t
,
4
>
const
&
dim_idx_map
,
std
::
array
<
std
::
size_t
,
4
>
const
&
dim_idx_map
,
bool
const
is_time_dep
,
bool
const
is_time_dep
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment