This page shows you how to integrate MeteoIO within your own aplication. Several of the basics calls are shown here below in the code examples. Finally, some tips are given in order to polish such integration.
Please keep in mind that the given examples are very simple, in order to keep them compact. For a real application, you will need to add some error checking code (as shown in the "tips" section).
Reading meteorological time series
Here is a simple exmaple showing how to get some meteorological data into the MeteoData vectors.
#include <iostream>
int main(
int argc,
char** argv) {
std::vector<MeteoData> vecMeteo;
io.getMeteoData(d1, vecMeteo);
std::cout << vecMeteo.size() <<
" stations with an average sampling rate of " << io.getAvgSamplingRate() <<
" or 1 point every " << 1./(io.getAvgSamplingRate()*60.+1
e-12) <<
" minutes\n";
for (unsigned int ii=0; ii < vecMeteo.size(); ii++) {
std::cout << "---------- Station: " << (ii+1) << " / " << vecMeteo.size() << std::endl;
std::cout << vecMeteo[ii].toString() << std::endl;
}
return 0;
}
A class that reads a key/value file. These files (typically named *.ini) follow the INI file format s...
Definition: Config.h:79
A class to handle timestamps. This class handles conversion between different time display formats (I...
Definition: Date.h:87
Definition: IOManager.h:34
int main(int argc, char **argv)
Definition: meteoio_timeseries.cc:424
static const double e
Definition: Meteoconst.h:68
bool convertString(Date &t, std::string str, const double &time_zone, std::ios_base &(*f)(std::ios_base &))
Convert a string to a date (template specialization of convertString)
Definition: IOUtils.cc:610
Reading Digital Elevation Models
Now, we can also read a Digital Elevation Model, print some information about it, write it back to disk with (potentially) another plugin as well as the slope and azimuth:
io.readDEM(dem);
std::cout << "DEM information: \n";
std::cout <<
"\tmin slope=" << dem.
min_slope <<
" max slope=" << dem.
max_slope << std::endl;
io.write2DGrid(azi,"azi.png");
return 0;
}
T getMin() const
returns the minimum value contained in the grid
Definition: Array2D.h:432
T getMax() const
returns the maximum value contained in the grid
Definition: Array2D.h:451
T getMean() const
returns the mean value contained in the grid
Definition: Array2D.h:470
A class to represent DEMs and automatically compute some properties. This class stores elevation grid...
Definition: DEMObject.h:40
double max_slope
Definition: DEMObject.h:47
@ SLOPE
update the slopes
Definition: DEMObject.h:62
Array2D< double > slope
Definition: DEMObject.h:42
double min_slope
Definition: DEMObject.h:46
void setUpdatePpt(const update_type &in_update_flag)
Set the properties that will be calculated by the object when updating The following properties can b...
Definition: DEMObject.cc:214
Array2D< double > azi
Definition: DEMObject.h:43
A class to represent 2D Grids. Typical application as DEM or Landuse Model.
Definition: Grid2DObject.h:42
double cellsize
dimension in meters of a cell (considered to be square)
Definition: Grid2DObject.h:220
Array2D< double > grid2D
the grid itself (simple 2D table containing the values for each point)
Definition: Grid2DObject.h:218
Coords llcorner
lower left corner of the grid
Definition: Grid2DObject.h:219
@ SLOPE
DEM slope angle.
Definition: MeteoData.h:81
@ DEM
Digital Elevation Model.
Definition: MeteoData.h:79
Programming Tips
First, more examples are provided in doc/examples (see the readme.txt file), alongside with an example io.ini as well as some data sets (7 weather stations as well as one DEM).
Then, for a real world application, the following would also be needed:
- wrapping up the MeteoIO calls in a try/catch block (at least for calls such as getMeteoData). This is particularly required for Windows and Mac platforms since uncaught exceptions on these plateforms won't print any error message on the screen.
- checking the data returned by getMeteoData against your application's minimum requirements. For example, you might want to check that there is at least one air temperature and one wind velocity at each time step. If your application's requirements are not fulfilled, then print an error message and exit (or throw an exception with a proper error message).
- if your application is written in another language (for example C or Fortran), then you need a wrapper that will wrap the call to MeteoIO and copy the returned data into your own data structures.
- finally, it might be a good idea to print the MeteoIO version information somewhere in your application's output. This could help with support and debugging. Such version information is returned by getLibVersion().