WSL/SLF GitLab Repository

ARPSIO.h 3.77 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/***********************************************************************************/
/*  Copyright 2009 WSL Institute for Snow and Avalanche Research    SLF-DAVOS      */
/***********************************************************************************/
/* This file is part of MeteoIO.
    MeteoIO is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    MeteoIO is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with MeteoIO.  If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __ARPSIO_H__
#define __ARPSIO_H__

21
#include <meteoio/Config.h>
22
23
24
25
26
#include <meteoio/IOInterface.h>
#include <meteoio/IOUtils.h>
#include <meteoio/Coords.h>
#include <meteoio/IOExceptions.h>
#include <meteoio/Grid3DObject.h>
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

#include <string>
#include <sstream>
#include <iostream>
#include <cstring>

#define ARPS_MAX_LINE_LENGTH 6000
#define ARPS_MAX_STRING_LENGTH 256

namespace mio {

/**
 * @class ARPSIO
 * @brief This class enables the access to 2D grids stored in ARPS format
 *
42
 * @ingroup plugins
43
44
45
46
47
48
49
 * @author Mathias Bavay
 * @date   2009-12-04
 */
class ARPSIO : public IOInterface {
	public:
		ARPSIO(const std::string& configfile);
		ARPSIO(const ARPSIO&);
50
		ARPSIO(const Config& cfgreader);
51
52
53
		~ARPSIO() throw();

		virtual void read2DGrid(Grid2DObject& grid_out, const std::string& parameter="");
54
		virtual void read2DGrid(Grid2DObject& grid_out, const MeteoGrids::Parameters& parameter, const Date& date);
55
56
57
58
59
60
61

		virtual void readDEM(DEMObject& dem_out);
		virtual void readLanduse(Grid2DObject& landuse_out);

		virtual void readStationData(const Date& date, std::vector<StationData>& vecStation);
		virtual void readMeteoData(const Date& dateStart, const Date& dateEnd,
		                           std::vector< std::vector<MeteoData> >& vecMeteo,
62
		                           const size_t& stationindex=IOUtils::npos);
63

64
		virtual void writeMeteoData(const std::vector< std::vector<MeteoData> >& vecMeteo,
65
66
67
68
69
		                            const std::string& name="");

		virtual void readAssimilationData(const Date&, Grid2DObject& da_out);
		virtual void readSpecialPoints(std::vector<Coords>& pts);
		virtual void write2DGrid(const Grid2DObject& grid_in, const std::string& filename);
70
		virtual void write2DGrid(const Grid2DObject& grid_in, const MeteoGrids::Parameters& parameter, const Date& date);
71

72
		void read3DGrid(Grid3DObject& grid_out, const std::string& in_name); //HACK
73
74

	private:
75
		void setOptions();
76
77
78
		void cleanup() throw();
		void initializeGRIDARPS();
		void initializeTrueARPS(const char curr_line[ARPS_MAX_LINE_LENGTH]);
79
		void openGridFile(const std::string& in_filename);
80
81
82
		void readGridLayer(const std::string& parameter, const unsigned int& layer, Grid2DObject& grid);
		void moveToMarker(const std::string& marker);

83
		const Config& cfg;
84
85
86
87
88
		//std::ifstream fin; //Input file streams
		FILE *fin;
		std::ofstream fout;//Output file streams
		std::string filename;
		static const double plugin_nodata; //plugin specific nodata value, e.g. -999
89
		static const std::string default_ext;
90
		std::string coordin, coordinparam, coordout, coordoutparam; //projection parameters
91
92
		std::string grid2dpath_in; //where are input grids stored
		std::string ext; //file extension
93
94
95
		unsigned int dimx, dimy, dimz;
		double cellsize;
		double xcoord, ycoord;
96
		std::vector<double> zcoord;
97
98
99
100
101
		bool is_true_arps; //is it an original arps file or is it a truncated file?
};

} //namespace
#endif