WSL/SLF GitLab Repository

StationData.cc 3.53 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/***********************************************************************************/
/*  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/>.
*/
#include <meteoio/StationData.h>

20
21
using namespace std;

22
23
24
namespace mio {

//Default constructor initializing every double attribute to nodata and strings to  ""
25
26
StationData::StationData() : position("NULL", "NULL"), stationID(""), stationName(""),
                             slope(IOUtils::nodata), azi(IOUtils::nodata) {}
27

28
StationData::StationData(const Coords& _position, const std::string& _id, const std::string& _name)
29
{
30
	setStationData(_position, _id, _name);
31
	setStationSlope(IOUtils::nodata, IOUtils::nodata);
32
33
}

34
void StationData::setStationData(const Coords& _position, const std::string& _id, const std::string& _name)
35
{
36
37
38
	position    = _position;
	stationID   = _id;
	stationName = _name;
39
40
}

41
42
43
44
45
46
47
48
49
50
51
52
53
void StationData::setStationSlope(const double& in_slope_angle, const double& in_azimuth)
{
	if(in_slope_angle!=IOUtils::nodata) {
		slope = fmod(in_slope_angle, 360.);
	} else
		slope = IOUtils::nodata;

	if(in_azimuth!=IOUtils::nodata)
		azi = fmod(in_azimuth, 360.);
	else
		azi =  IOUtils::nodata;
}

54
55
//Comparison operator
bool StationData::operator==(const StationData& in) const {
56
57
	return ( (position == in.position) && (stationID == in.stationID) &&
	         (slope==in.slope) && (azi==in.azi) );// && (stationName == in.stationName));
58
59
60
}

bool StationData::operator!=(const StationData& in) const {
61
62
63
64
65
66
67
68
69
70
	return !(*this==in);
}

//Specific Getter Functions for stationName, stationID and position
Coords StationData::getPosition() const {
	return position;
}

std::string StationData::getStationID() const {
	return stationID;
71
72
73
74
75
76
}

std::string StationData::getStationName() const {
	return stationName;
}

77
78
79
80
81
82
83
84
double StationData::getSlopeAngle() const {
	return slope;
}

double StationData::getAzimuth() const {
	return azi;
}

85
86
std::ostream& operator<<(std::ostream& os, const StationData& station) {

87
88
	os << "<station>" << endl
	   << std::setprecision(10) << station.position 
89
90
91
	   << "ID:    " << station.getStationID() << endl 
	   << "Name:  " << station.getStationName() << endl
	   << "Slope: " << station.getSlopeAngle() << " bearing: " << station.getAzimuth() << endl
92
	   << "</station>" << endl;
93
94
95
96
97
98
99
100
101
102
103
104
105

	return os;
}

} //end namespace

#ifdef _POPC_
#include "marshal_meteoio.h"
using namespace mio; //HACK for POPC
void StationData::Serialize(POPBuffer &buf, bool pack)
{
	if (pack){
		marshal_Coords(buf, position, 0, FLAG_MARSHAL, NULL);
106
		buf.Pack(&stationID, 1);
107
		buf.Pack(&stationName, 1);
108
109
		buf.Pack(&slope, 1);
		buf.Pack(&azi, 1);
110
111
	}else{
		marshal_Coords(buf, position, 0, !FLAG_MARSHAL, NULL);
112
		buf.UnPack(&stationID, 1);
113
		buf.UnPack(&stationName, 1);
114
115
		buf.UnPack(&slope, 1);
		buf.UnPack(&azi, 1);
116
117
118
119
120
	}
}
#endif

//} //namespace //HACK for POPC