File: filePolygon.cpp

package info (click to toggle)
groops 0%2Bgit20250907%2Bds-1
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 11,140 kB
  • sloc: cpp: 135,607; fortran: 1,603; makefile: 20
file content (105 lines) | stat: -rw-r--r-- 2,634 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/***********************************************/
/**
* @file filePolygon.cpp
*
* @brief Polygons on Earth's surface.
*
* @author Torsten Mayer-Guerr
* @date 2005-01-14
*
*/
/***********************************************/

#define DOCSTRING_FILEFORMAT_Polygon

#include "base/import.h"
#include "inputOutput/fileArchive.h"
#include "files/fileFormatRegister.h"
#include "files/filePolygon.h"

GROOPS_REGISTER_FILEFORMAT(Polygon, FILE_POLYGON_TYPE)

/***********************************************/

template<> void save(OutArchive &ar, const std::vector<Polygon> &polygon)
{
  UInt polygonCount = polygon.size();
  ar<<nameValue("polygonCount", polygonCount);
  for(UInt i=0; i<polygonCount; i++)
  {
    ar<<beginGroup("polygon");
    UInt pointCount = polygon.at(i).L.rows();
    ar<<nameValue("pointCount", pointCount);
    ar.comment("longitude [deg]           latitude [deg]          ");
    ar.comment("==================================================");
    for(UInt k=0; k<pointCount; k++)
    {
      Angle L(polygon.at(i).L(k));
      Angle B(polygon.at(i).B(k));
      ar<<beginGroup("point");
      ar<<nameValue("longitude", L);
      ar<<nameValue("latitude",  B);
      ar<<endGroup("point");
    }
    ar<<endGroup("polygon");
  }
}

/***********************************************/

template<> void load(InArchive &ar, std::vector<Polygon> &polygon)
{
  UInt polygonCount;
  ar>>nameValue("polygonCount", polygonCount);
  polygon.resize(polygonCount);
  for(UInt i=0; i<polygonCount; i++)
  {
    ar>>beginGroup("polygon");
    UInt pointCount;
    ar>>nameValue("pointCount", pointCount);
    polygon.at(i) = Polygon(pointCount);
    for(UInt k=0; k<pointCount; k++)
    {
      Angle L,B;
      ar>>beginGroup("point");
      ar>>nameValue("longitude", L);
      ar>>nameValue("latitude",  B);
      ar>>endGroup("point");
      polygon.at(i).L(k) = L;
      polygon.at(i).B(k) = B;
    }
    ar>>endGroup("polygon");
  }
}

/***********************************************/

void writeFilePolygon(const FileName &fileName, const std::vector<Polygon> &x)
{
  try
  {
    OutFileArchive file(fileName, FILE_POLYGON_TYPE, FILE_POLYGON_VERSION);
    file<<nameValue("polygonList", x);
  }
  catch(std::exception &e)
  {
    GROOPS_RETHROW(e)
  }
}

/***********************************************/

void readFilePolygon(const FileName &fileName, std::vector<Polygon> &x)
{
  try
  {
    InFileArchive file(fileName, FILE_POLYGON_TYPE, FILE_POLYGON_VERSION);
    file>>nameValue("polygonList", x);
  }
  catch(std::exception &e)
  {
    GROOPS_RETHROW(e)
  }
}

/***********************************************/