WSL/SLF GitLab Repository
Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
snow-models
meteoio
Commits
999f298c
Commit
999f298c
authored
May 08, 2014
by
Thomas Egger
Browse files
Deleting trailing whitespaces in plugins
parent
09403357
Changes
4
Hide whitespace changes
Inline
Side-by-side
meteoio/plugins/NetCDFIO.cc
View file @
999f298c
...
...
@@ -233,8 +233,8 @@ void NetCDFIO::copy_grid(const size_t& latlen, const size_t& lonlen, const doubl
/* The Grid2DObject holds data and meta data for quadratic cells. However the NetCDF file
* stores the grid as discrete latitude and longitude values. It is necessary to calculate
* the distance between the edges of the grid and determine the cellsize. This cellsize may
* be different for X and Y directions. We then choose one cellsize for our grid and
* determine a factor that will be used for resampling the grid to likewise consist of
* be different for X and Y directions. We then choose one cellsize for our grid and
* determine a factor that will be used for resampling the grid to likewise consist of
* quadratic cells.
*/
double
NetCDFIO
::
calculate_cellsize
(
const
size_t
&
latlen
,
const
size_t
&
lonlen
,
const
double
*
const
lat
,
const
double
*
const
lon
,
...
...
@@ -247,16 +247,16 @@ double NetCDFIO::calculate_cellsize(const size_t& latlen, const size_t& lonlen,
urcorner
.
setLatLon
(
lat
[
latlen
-
1
],
lon
[
lonlen
-
1
],
IOUtils
::
nodata
);
double
ll_easting
=
llcorner
.
getEasting
(),
ll_northing
=
llcorner
.
getNorthing
();
double
ur_easting
=
urcorner
.
getEasting
(),
ur_northing
=
urcorner
.
getNorthing
();
double
ur_easting
=
urcorner
.
getEasting
(),
ur_northing
=
urcorner
.
getNorthing
();
double
distanceX
=
ur_easting
-
ll_easting
;
double
distanceY
=
ur_northing
-
ll_northing
;
// lonlen, latlen are decremented by 1; n linearly connected points have (n-1) connections
double
cellsize_x
=
distanceX
/
(
lonlen
-
1
);
double
cellsize_x
=
distanceX
/
(
lonlen
-
1
);
double
cellsize_y
=
distanceY
/
(
latlen
-
1
);
// We're using a precision for the cellsize that is equal to 1cm, more
// We're using a precision for the cellsize that is equal to 1cm, more
// precision makes ensuing calculations numerically instable
double
value
=
max
(
cellsize_x
,
cellsize_y
)
*
100.0
;
double
cellsize
=
floor
(
value
)
/
100.0
;
...
...
@@ -522,9 +522,9 @@ void NetCDFIO::copy_data(const int& ncid, const std::map<std::string, size_t>& m
}
// Go through all known CNRM parameters defined in the map paramname and check which ones are present
// in the current NetCDF dataset. A map called map_parameters will associate all parameters present
// with MeteoData parameters or IOUtils::npos). If the CNRM parameter does not have a corresponding
// parameter in the meteo_data object we can add a new parameter (e.g. cnrm_theorsw) or if the situation
// in the current NetCDF dataset. A map called map_parameters will associate all parameters present
// with MeteoData parameters or IOUtils::npos). If the CNRM parameter does not have a corresponding
// parameter in the meteo_data object we can add a new parameter (e.g. cnrm_theorsw) or if the situation
// is more complex (e.g. rainfall is measured with two parameters) we deal with the situation in copy_data().
// Furthermore the dimensions of each present parameter are checked.
void
NetCDFIO
::
get_parameters
(
const
int
&
ncid
,
std
::
map
<
std
::
string
,
size_t
>&
map_parameters
,
MeteoData
&
meteo_data
)
...
...
@@ -795,9 +795,9 @@ void NetCDFIO::create_parameters(const int& ncid, const int& did_time, const int
}
// Retrieve the parameters in use (parameters, that are different from nodata
// for at least one timestamp for at least one station) and store them in
// for at least one timestamp for at least one station) and store them in
// map_param_name. map_param_name associates a MeteoData parameter index with a
// string name, that is the CNRM name for the parameter to use in the NetCDF
// string name, that is the CNRM name for the parameter to use in the NetCDF
// file. Furthermore this method copies the meta data into the appropriate C
// arrays. The timestep interval is also calculated and added to the map_data_1D
void
NetCDFIO
::
get_parameters
(
const
std
::
vector
<
std
::
vector
<
MeteoData
>
>&
vecMeteo
,
std
::
map
<
size_t
,
std
::
string
>&
map_param_name
,
...
...
@@ -905,14 +905,14 @@ void NetCDFIO::write2DGrid_internal(const Grid2DObject& grid_in, const std::stri
if
(
exists
)
{
open_file
(
filename
,
NC_WRITE
,
ncid
);
//check of lat/lon are defined and consistent
if
(
check_dim_var
(
ncid
,
cf_latitude
)
&&
check_dim_var
(
ncid
,
cf_longitude
))
{
check_consistency
(
ncid
,
grid_in
,
lat_array
,
lon_array
,
did_lat
,
did_lon
,
vid_lat
,
vid_lon
);
}
else
{
create_dimensions
=
true
;
}
if
(
is_record
)
{
//check if a time dimension/variable already exists
if
(
check_dim_var
(
ncid
,
NetCDFIO
::
cf_time
))
{
...
...
@@ -922,16 +922,16 @@ void NetCDFIO::write2DGrid_internal(const Grid2DObject& grid_in, const std::stri
create_time
=
true
;
}
}
if
(
check_variable
(
ncid
,
varname
))
{
// variable exists
get_variable
(
ncid
,
varname
,
vid_var
);
vector
<
int
>
dimid
,
dim_varid
;
vector
<
string
>
dimname
;
vector
<
size_t
>
dimlen
;
get_dimension
(
ncid
,
varname
,
vid_var
,
dimid
,
dim_varid
,
dimname
,
dimlen
);
if
(
is_record
)
{
if
((
dimname
.
size
()
!=
3
)
||
(
dimname
[
0
]
!=
cf_time
)
||
(
dimname
[
1
]
!=
cf_latitude
)
||
(
dimname
[
2
]
!=
cf_longitude
)
||
(
dimlen
[
1
]
!=
grid_in
.
nrows
)
||
(
dimlen
[
2
]
!=
grid_in
.
ncols
))
throw
IOException
(
"Variable '"
+
varname
+
"' already defined with different dimensions in file '"
+
filename
+
"'"
,
AT
);
...
...
@@ -947,7 +947,7 @@ void NetCDFIO::write2DGrid_internal(const Grid2DObject& grid_in, const std::stri
}
else
{
create_file
(
filename
,
NC_CLASSIC_MODEL
,
ncid
);
add_attribute
(
ncid
,
NC_GLOBAL
,
"Conventions"
,
"CF-1.3"
);
create_variable
=
create_dimensions
=
true
;
if
(
is_record
)
create_time
=
true
;
...
...
@@ -1112,11 +1112,11 @@ void NetCDFIO::calculate_dimensions(const Grid2DObject& grid, double*& lat_array
Coords
urcorner
(
grid
.
llcorner
);
urcorner
.
setGridIndex
(
grid
.
ncols
-
1
,
grid
.
nrows
-
1
,
IOUtils
::
nodata
,
true
);
grid
.
gridify
(
urcorner
);
double
lat_interval
=
(
urcorner
.
getLat
()
-
lat_array
[
0
])
/
(
grid
.
nrows
-
1
);
double
lon_interval
=
(
urcorner
.
getLon
()
-
lon_array
[
0
])
/
(
grid
.
ncols
-
1
);
// The method to use interval*ii is consistent with the corresponding
// The method to use interval*ii is consistent with the corresponding
// calculation of the Grid2DObject::gridify method -> numerical stability
for
(
size_t
ii
=
1
;
ii
<
grid
.
nrows
;
ii
++
)
{
lat_array
[
ii
]
=
lat_array
[
0
]
+
lat_interval
*
ii
;
...
...
@@ -1379,7 +1379,7 @@ void NetCDFIO::write_data(const int& ncid, const std::string& varname, const int
}
// Adding a record value (e.g. timestamp), in case it doesn't already exist and
// that the value is greater than the last record variable value. For example,
// that the value is greater than the last record variable value. For example,
// timestamps have to be strictly monotonically increasing or already existent.
size_t
NetCDFIO
::
add_record
(
const
int
&
ncid
,
const
std
::
string
&
varname
,
const
int
&
varid
,
const
double
&
data
)
{
...
...
@@ -1438,7 +1438,7 @@ size_t NetCDFIO::find_record(const int& ncid, const std::string& varname, const
}
// In case the dimension length of the record variable is less than start_pos
// values will be added (containing the _FillValue) until a length of start_pos-1
// values will be added (containing the _FillValue) until a length of start_pos-1
// has been reached. Finally the length amount elements from start_pos and on
// will be added.
void
NetCDFIO
::
write_record
(
const
int
&
ncid
,
const
std
::
string
&
varname
,
const
int
&
varid
,
const
size_t
&
start_pos
,
const
size_t
&
length
,
const
double
*
const
data
)
...
...
meteoio/plugins/NetCDFIO.h
View file @
999f298c
...
...
@@ -78,7 +78,7 @@ class NetCDFIO : public IOInterface {
size_t
get_dates
(
const
std
::
vector
<
std
::
vector
<
MeteoData
>
>&
vecMeteo
,
double
*&
dates
);
void
copy_data
(
const
size_t
&
number_of_stations
,
const
size_t
&
number_of_records
,
const
std
::
vector
<
std
::
vector
<
MeteoData
>
>&
vecMeteo
,
const
std
::
map
<
size_t
,
std
::
string
>&
map_param_name
,
std
::
map
<
std
::
string
,
double
*>&
map_data_2D
);
void
copy_data
(
const
int
&
ncid
,
const
std
::
map
<
std
::
string
,
size_t
>&
map_parameters
,
const
std
::
map
<
std
::
string
,
double
*>
map_data
,
void
copy_data
(
const
int
&
ncid
,
const
std
::
map
<
std
::
string
,
size_t
>&
map_parameters
,
const
std
::
map
<
std
::
string
,
double
*>
map_data
,
const
size_t
&
number_of_stations
,
const
size_t
&
number_of_records
,
std
::
vector
<
std
::
vector
<
MeteoData
>
>&
vecMeteo
);
void
readData
(
const
int
&
ncid
,
const
size_t
&
index_start
,
const
std
::
vector
<
Date
>&
vec_date
,
const
std
::
map
<
std
::
string
,
size_t
>&
map_parameters
,
const
MeteoData
&
meteo_data
,
std
::
vector
<
std
::
vector
<
MeteoData
>
>&
vecMeteo
);
...
...
@@ -155,7 +155,7 @@ class NetCDFIO : public IOInterface {
void
check_dimensions
(
const
int
&
ncid
,
const
std
::
string
&
varname
,
const
int
&
varid
,
const
std
::
vector
<
std
::
string
>&
names
);
void
get_dimension
(
const
int
&
ncid
,
const
std
::
string
&
dimname
,
int
&
dimid
);
void
get_dimension
(
const
int
&
ncid
,
const
std
::
string
&
dimname
,
int
&
dimid
,
size_t
&
dimlen
);
void
get_dimension
(
const
int
&
ncid
,
const
std
::
string
&
varname
,
const
int
&
varid
,
void
get_dimension
(
const
int
&
ncid
,
const
std
::
string
&
varname
,
const
int
&
varid
,
std
::
vector
<
int
>&
dimid
,
std
::
vector
<
int
>&
dim_varid
,
std
::
vector
<
std
::
string
>&
dimname
,
std
::
vector
<
size_t
>&
dimlen
);
...
...
meteoio/plugins/PSQLIO.cc
View file @
999f298c
...
...
@@ -40,7 +40,7 @@ namespace mio {
const
double
PSQLIO
::
plugin_nodata
=
-
999.
;
//plugin specific nodata value. It can also be read by the plugin (depending on what is appropriate)
PSQLIO
::
PSQLIO
(
const
std
::
string
&
configfile
)
:
cfg
(
configfile
),
coordin
(),
coordinparam
(),
coordout
(),
coordoutparam
(),
endpoint
(),
port
(),
PSQLIO
::
PSQLIO
(
const
std
::
string
&
configfile
)
:
cfg
(
configfile
),
coordin
(),
coordinparam
(),
coordout
(),
coordoutparam
(),
endpoint
(),
port
(),
dbname
(),
userid
(),
passwd
(),
psql
(
NULL
),
default_timezone
(
1.
),
vecMeta
(),
multiplier
(),
offset
(),
vecFixedStationID
(),
vecMobileStationID
(),
sql_meta
(),
sql_data
(),
shadowed_parameters
()
{
...
...
@@ -48,7 +48,7 @@ PSQLIO::PSQLIO(const std::string& configfile) : cfg(configfile), coordin(), coor
getParameters
();
}
PSQLIO
::
PSQLIO
(
const
Config
&
cfgreader
)
:
cfg
(
cfgreader
),
coordin
(),
coordinparam
(),
coordout
(),
coordoutparam
(),
endpoint
(),
port
(),
PSQLIO
::
PSQLIO
(
const
Config
&
cfgreader
)
:
cfg
(
cfgreader
),
coordin
(),
coordinparam
(),
coordout
(),
coordoutparam
(),
endpoint
(),
port
(),
dbname
(),
userid
(),
passwd
(),
psql
(
NULL
),
default_timezone
(
1.
),
vecMeta
(),
multiplier
(),
offset
(),
vecFixedStationID
(),
vecMobileStationID
(),
sql_meta
(),
sql_data
(),
shadowed_parameters
()
{
...
...
@@ -56,10 +56,10 @@ PSQLIO::PSQLIO(const Config& cfgreader) : cfg(cfgreader), coordin(), coordinpara
getParameters
();
}
PSQLIO
::
PSQLIO
(
const
PSQLIO
&
in
)
:
cfg
(
in
.
cfg
),
coordin
(
in
.
coordin
),
coordinparam
(
in
.
coordinparam
),
coordout
(
in
.
coordout
),
coordoutparam
(
in
.
coordoutparam
),
endpoint
(
in
.
endpoint
),
port
(
in
.
port
),
dbname
(
in
.
dbname
),
userid
(
in
.
userid
),
passwd
(
in
.
passwd
),
psql
(
NULL
),
default_timezone
(
1.
),
vecMeta
(
in
.
vecMeta
),
multiplier
(
in
.
multiplier
),
offset
(
in
.
offset
),
vecFixedStationID
(
in
.
vecFixedStationID
),
vecMobileStationID
(
in
.
vecMobileStationID
),
PSQLIO
::
PSQLIO
(
const
PSQLIO
&
in
)
:
cfg
(
in
.
cfg
),
coordin
(
in
.
coordin
),
coordinparam
(
in
.
coordinparam
),
coordout
(
in
.
coordout
),
coordoutparam
(
in
.
coordoutparam
),
endpoint
(
in
.
endpoint
),
port
(
in
.
port
),
dbname
(
in
.
dbname
),
userid
(
in
.
userid
),
passwd
(
in
.
passwd
),
psql
(
NULL
),
default_timezone
(
1.
),
vecMeta
(
in
.
vecMeta
),
multiplier
(
in
.
multiplier
),
offset
(
in
.
offset
),
vecFixedStationID
(
in
.
vecFixedStationID
),
vecMobileStationID
(
in
.
vecMobileStationID
),
sql_meta
(
in
.
sql_meta
),
sql_data
(
in
.
sql_data
),
shadowed_parameters
(
in
.
shadowed_parameters
)
{}
PSQLIO
&
PSQLIO
::
operator
=
(
const
PSQLIO
&
in
)
...
...
@@ -129,10 +129,10 @@ void PSQLIO::create_shadow_map(const std::string& exclude_file)
try
{
char
eoln
=
IOUtils
::
getEoln
(
fin
);
//get the end of line character for the file
vector
<
string
>
tmpvec
;
string
line
(
""
);
while
(
!
fin
.
eof
())
{
//Go through file
getline
(
fin
,
line
,
eoln
);
//read complete line meta information
IOUtils
::
stripComments
(
line
);
...
...
@@ -319,7 +319,7 @@ void PSQLIO::readData(const Date& dateStart, const Date& dateEnd, std::vector<Me
if
(
result
)
{
int
rows
=
PQntuples
(
result
);
int
columns
=
PQnfields
(
result
);
vector
<
size_t
>
index
;
MeteoData
tmpmeteo
;
tmpmeteo
.
meta
=
vecMeta
.
at
(
stationindex
);
...
...
@@ -347,7 +347,7 @@ void PSQLIO::parse_row(PGresult* result, const int& row, const int& cols, MeteoD
}
}
convertUnits
(
tmp
);
convertUnits
(
tmp
);
vecMeteo
.
push_back
(
tmp
);
}
...
...
@@ -435,7 +435,7 @@ void PSQLIO::writeMeteoData(const std::vector< std::vector<MeteoData> >& vecMete
const
bool
isConsistent
=
checkConsistency
(
vecMeteo
.
at
(
ii
),
sd
);
// sd will hold valid meta info
if
(
isConsistent
)
{
//static station
}
else
{
//mobile station
}
...
...
@@ -538,7 +538,7 @@ PGresult *PSQLIO::get_data(const string& sql_command)
// options.align = 1; /* Pad short columns for alignment */
// options.fieldSep = "|"; /* Use a pipe as the field separator */
// PQprint(stdout, result, &options);
}
else
{
//cout << "BAD SELECT: " << PQresStatus(status) << endl;
PQclear
(
result
);
...
...
meteoio/plugins/PSQLIO.h
View file @
999f298c
...
...
@@ -31,7 +31,7 @@ namespace mio {
/**
* @class PSQLIO
* @brief
* @brief
*
* @ingroup plugins
* @author Thomas Egger
...
...
@@ -72,7 +72,7 @@ class PSQLIO : public IOInterface {
bool
replace
(
std
::
string
&
str
,
const
std
::
string
&
from
,
const
std
::
string
&
to
);
void
readData
(
const
Date
&
dateStart
,
const
Date
&
dateEnd
,
std
::
vector
<
MeteoData
>&
vecMeteo
,
const
size_t
&
stationindex
);
void
map_parameters
(
PGresult
*
result
,
MeteoData
&
md
,
std
::
vector
<
size_t
>&
index
);
void
parse_row
(
PGresult
*
result
,
const
int
&
row
,
const
int
&
cols
,
void
parse_row
(
PGresult
*
result
,
const
int
&
row
,
const
int
&
cols
,
MeteoData
&
md
,
std
::
vector
<
size_t
>&
index
,
std
::
vector
<
mio
::
MeteoData
>&
vecMeteo
);
void
close_connection
(
PGconn
*
conn
);
bool
checkConsistency
(
const
std
::
vector
<
MeteoData
>&
vecMeteo
,
StationData
&
sd
);
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment