Ice Sheet System Model  4.18
Code documentation
KML_Point.cpp
Go to the documentation of this file.
1 
5 /*Headers:*/
6 /*{{{*/
7 #ifdef HAVE_CONFIG_H
8  #include <config.h>
9 #else
10 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
11 #endif
12 
13 #include "./KML_Point.h"
14 #include "./KMLFileReadUtils.h"
15 #include "../shared/shared.h"
16 /*}}}*/
17 
18 /*Constructors/destructor/copy*/
20 
21  extrude =false;
22  memcpy(altmode,"clampToGround",(strlen("clampToGround")+1)*sizeof(char));
23 
24  coords[0] = 0.;
25  coords[1] = 0.;
26  coords[2] = 0.;
27 
28 }
29 /*}}}*/
31 
32  ;
33 
34 }
35 /*}}}*/
36 
37 /*Other*/
38 void KML_Point::Echo(){/*{{{*/
39 
40  bool flag=true;
41 
42  if(flag) _printf0_("KML_Point:\n");
44 
45  if(flag) _printf0_(" extrude: " << (extrude ? "true" : "false") << "\n");
46  if(flag) _printf0_(" altmode: \"" << altmode << "\"\n");
47  if(flag) _printf0_(" coords: (" << coords[0] << "," << coords[1] << "," << coords[2] << ")\n");
48 
49  return;
50 }
51 /*}}}*/
52 void KML_Point::DeepEcho(){/*{{{*/
53 
54  char indent[81]="";
55 
56  KML_Point::DeepEcho(indent);
57 
58  return;
59 }
60 /*}}}*/
61 void KML_Point::DeepEcho(const char* indent){/*{{{*/
62 
63  bool flag=true;
64 
65  if(flag) _printf0_(indent << "KML_Point:\n");
66  KML_Geometry::DeepEcho(indent);
67 
68  if(flag) _printf0_(indent << " extrude: " << (extrude ? "true" : "false") << "\n");
69  if(flag) _printf0_(indent << " altmode: \"" << altmode << "\"\n");
70  if(flag) _printf0_(indent << " coords: (" << coords[0] << "," << coords[1] << "," << coords[2] << ")\n");
71 
72  return;
73 }
74 /*}}}*/
75 void KML_Point::Write(FILE* filout,const char* indent){/*{{{*/
76 
77  fprintf(filout,"%s<Point",indent);
78  WriteAttrib(filout," ");
79  fprintf(filout,">\n");
80  WriteCommnt(filout,indent);
81 
82  KML_Geometry::Write(filout,indent);
83 
84  fprintf(filout,"%s <extrude>%d</extrude>\n",indent,(extrude ? 1 : 0));
85  fprintf(filout,"%s <altitudeMode>%s</altitudeMode>\n",indent,altmode);
86  fprintf(filout,"%s <coordinates>%0.16g,%0.16g,%0.16g</coordinates>\n",
87  indent,coords[0],coords[1],coords[2]);
88 
89  fprintf(filout,"%s</Point>\n",indent);
90 
91  return;
92 }
93 /*}}}*/
94 void KML_Point::Read(FILE* fid,char* kstr){/*{{{*/
95 
96  double* pcoords=&coords[0];
97  char* kstri;
98  int ncom=0;
99  char** pcom=NULL;
100 
101 /* get object attributes and check for solo tag */
102 
103  if (KMLFileTagAttrib(this,
104  kstr))
105  return;
106 
107 /* loop over and process fields within opening and closing tags */
108 
109  while((kstri=KMLFileToken(fid, &ncom,&pcom))){
110  if (!strncmp(kstri,"</Point", 7)) {
111  xDelete<char>(kstri);
112  break;
113  }
114  else if (!strncmp(kstri,"</",2))
115  {_error_("KML_Point::Read -- Unexpected closing tag " << kstri << ".\n");}
116  else if (strncmp(kstri,"<",1))
117  {_error_("KML_Point::Read -- Unexpected field \"" << kstri << "\".\n");}
118 
119  else if (!strcmp(kstri,"<extrude>"))
120  KMLFileTokenParse(&extrude , kstri, fid);
121  else if (!strcmp(kstri,"<altitudeMode>"))
123  else if (!strcmp(kstri,"<coordinates>"))
124  KMLFileTokenParse(&pcoords ,NULL,3, kstri, fid);
125 
126  else if (!strncmp(kstri,"<",1))
127  KML_Geometry::Read(fid,kstri);
128 
129  xDelete<char>(kstri);
130  }
131 
132  this->AddCommnt(ncom,pcom);
133 
134  for(ncom=ncom; ncom>0; ncom--)
135  xDelete<char>(pcom[ncom-1]);
136  xDelete<char*>(pcom);
137 
138  return;
139 }
140 /*}}}*/
141 void KML_Point::WriteExp(FILE* fid,const char* nstr,int sgn,double cm,double sp){/*{{{*/
142 
143  int i;
144  double lat,lon,x,y;
145  char nstr2[81];
146 
147 /* extract latitude and longitude */
148 
149  lon=coords[0];
150  lat=coords[1];
151 
152 /* convert latitude and longitude to x and y */
153 
154  if (sgn) {
155  Ll2xyx(&x,&y,&lat,&lon,1,sgn,cm,sp);
156  }
157  else {
158  memcpy(&x,&lon,1*sizeof(IssmDouble));
159  memcpy(&y,&lat,1*sizeof(IssmDouble));
160  }
161 
162 /* write header */
163 
164  memcpy(nstr2,nstr,(strlen(nstr)+1)*sizeof(char));
165 
166  for (i=0; i<strlen(nstr2); i++)
167  if ((nstr2[i] == ' ') || (nstr2[i] == '\t'))
168  nstr2[i]='_';
169  fprintf(fid,"## Name:%s\n",nstr2);
170  fprintf(fid,"## Icon:0\n");
171  fprintf(fid,"# Points Count Value\n");
172  fprintf(fid,"%u %s\n",1,"1.");
173  fprintf(fid,"# X pos Y pos\n");
174 
175 /* write vertex */
176 
177  fprintf(fid,"%lf\t%lf\n",x,y);
178 
179 /* write blank line */
180 
181  fprintf(fid,"\n");
182 
183  return;
184 }
185 /*}}}*/
Ll2xyx
int Ll2xyx(double *x, double *y, double *lat, double *lon, int ncoord, int sgn)
Definition: Ll2xyx.cpp:8
KML_Point::KML_Point
KML_Point()
Definition: KML_Point.cpp:19
IssmDouble
double IssmDouble
Definition: types.h:37
_printf0_
#define _printf0_(StreamArgs)
Definition: Print.h:29
KML_Object::WriteAttrib
virtual void WriteAttrib(FILE *fid, const char *indent)
Definition: KML_Object.cpp:288
KML_Geometry::Write
void Write(FILE *fid, const char *indent)
Definition: KML_Geometry.cpp:56
KML_Point::Echo
void Echo()
Definition: KML_Point.cpp:38
KML_Point::extrude
bool extrude
Definition: KML_Point.h:20
KMLFileReadUtils.h
: header file for kml file reading utilities.
KMLFileTagAttrib
int KMLFileTagAttrib(KML_Object *kobj, char *ktag)
Definition: KMLFileReadUtils.cpp:287
KML_Point::coords
double coords[3]
Definition: KML_Point.h:22
KML_POINT_ALTMODE_LENGTH
#define KML_POINT_ALTMODE_LENGTH
Definition: KML_Point.h:8
KML_Point::DeepEcho
void DeepEcho()
Definition: KML_Point.cpp:52
KML_Point::altmode
char altmode[KML_POINT_ALTMODE_LENGTH+1]
Definition: KML_Point.h:21
KMLFileToken
char * KMLFileToken(FILE *fid, int *pncom=NULL, char ***ppcom=NULL)
Definition: KMLFileReadUtils.cpp:18
KML_Geometry::DeepEcho
void DeepEcho()
Definition: KML_Geometry.cpp:40
KML_Point::Read
void Read(FILE *fid, char *kstr)
Definition: KML_Point.cpp:94
KMLFileTokenParse
int KMLFileTokenParse(int *pival, char *ktag, FILE *fid)
Definition: KMLFileReadUtils.cpp:335
KML_Point::Write
void Write(FILE *fid, const char *indent)
Definition: KML_Point.cpp:75
_error_
#define _error_(StreamArgs)
Definition: exceptions.h:49
KML_Point.h
: header file for kml_point object
KML_Point::~KML_Point
~KML_Point()
Definition: KML_Point.cpp:30
KML_Object::AddCommnt
virtual void AddCommnt(int ncom, char **pcom)
Definition: KML_Object.cpp:301
KML_Object::WriteCommnt
virtual void WriteCommnt(FILE *fid, const char *indent)
Definition: KML_Object.cpp:326
KML_Point::WriteExp
void WriteExp(FILE *fid, const char *nstr, int sgn, double cm, double sp)
Definition: KML_Point.cpp:141
KML_Geometry::Echo
void Echo()
Definition: KML_Geometry.cpp:33
KML_Geometry::Read
void Read(FILE *fid, char *kstr)
Definition: KML_Geometry.cpp:63