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) {
Date d1;
std::vector<MeteoData> vecMeteo;
Config cfg("io.ini");
IOManager io(cfg);
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;
}
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:597
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:
DEMObject dem;
Config cfg("io.ini");
IOManager io(cfg);
io.readDEM(dem);
std::cout << "DEM information: \n";
std::cout << "\tmin=" << dem.grid2D.getMin() << " max=" << dem.grid2D.getMax() << " mean=" << dem.grid2D.getMean() << "\n";
std::cout << "\tmin slope=" << dem.min_slope << " max slope=" << dem.max_slope << std::endl;
Grid2DObject slope(dem.cellsize, dem.llcorner, dem.slope);
Grid2DObject azi(dem.cellsize, dem.llcorner, dem.azi);
io.write2DGrid(azi,"azi.png");
return 0;
}
@ SLOPE
update the slopes
Definition: DEMObject.h:62
@ 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().