Debian Codegraph @

gctp/src/report.c

raw
1 /*******************************************************************************
2 NAME Projection support routines listed below
3
4 PURPOSE: The following functions are included in REPORT.C
5
6 INIT:
7 Initializes the output device for error messages and
8 report headings.
9
10 P_ERROR:
11 Reports errors to the terminal, a specified file, or
12 both.
13
14 PTITLE, RADIUS, RADIUS2, CENLON, CENLONMER, CENLAT, ORIGIN,
15 STANPARL, STPARL1, OFFSET, GENRPT, GENRPT_LONG, PBLANK:
16 Reports projection parameters to the terminal,
17 specified file, or both.
18
19
20 PROGRAMMER DATE REASON
21 ---------- ---- ------
22 D. Steinwand, EROS July, 1991 Initial development.
23 T. Mittan Mar, 1993 Adapted code to new "C" version of
24 GCTP library.
25 S. Nelson Jun, 1993 Added inline code.
26 Added error messages if no filename
27 was specified.
28 Carol S. W. Tsai Sep, 1997 Added code for p_errort, a function to report
29 error, to generate the status meassages that is
30 relative to the message file created for
31 PGS GCT tools if it is PGS_TOOLKIT_COMPILE
32
33 *******************************************************************************/
34 #ifdef PGS_TOOLKIT_COMPILE /* only TOOLKIT compilation */
35 #include <PGS_SMF.h>
36 #include <PGS_GCT_12.h>
37 #endif /* only TOOLKIT compilation */
38 #include <stdio.h>
39 #include <string.h>
40 #include "cproj.h"
41
42 #define TRUE 1
43 #ifndef FALSE
44 #define FALSE 0
45 #endif
46
47 static long terminal_p; /* flag for printing parameters to terminal */
48 static long terminal_e; /* flag for printing errors to terminal */
49 static long file_e; /* flag for printing errors to terminal */
50 static long file_p; /* flag for printing parameters to file */
51 static FILE *fptr_p=NULL;
52 static FILE *fptr_e=NULL;
53 static char parm_file[256];
54 static char err_file[256];
55
56 /* Function to report errors
57 -------------------------*/
58 void p_error(
59 char *what,
60 char *where)
61 {
62 #ifdef PGS_TOOLKIT_COMPILE
63 PGSt_SMF_status returnStatus = PGSGCT_E_GCTP_ERROR;
64
65 if(strcmp(what, "Too many iterations in inverse") == 0) returnStatus = PGSGCT_E_ITER_EXCEEDED;
66 else if(strncmp(what, "Point projects into a circle of radius", strlen("Point projects into a circle of radius")) == 0) returnStatus = PGSGCT_E_POINT_PROJECT;
67 else if(strcmp(what, "Input data error") == 0) returnStatus = PGSGCT_E_INPUT_DATA_ERROR;
68 else if(strcmp(what, "Point projects into infinity") == 0) returnStatus = PGSGCT_E_INFINITE;
69 else if(strcmp(what, "Iteration failed to converge") == 0) returnStatus = PGSGCT_E_ITER_FAILED;
70 else if(strcmp(what, "Point can not be projected") == 0) returnStatus = PGSGCT_E_PROJECT_FAILED;
71 else if(strcmp(what, "Point cannot be projected") == 0) returnStatus = PGSGCT_E_PROJECT_FAILED;
72 else if(strcmp(what, "Transformation cannot be computed at the poles") == 0) returnStatus = PGSGCT_E_POINTS_ON_POLES;
73 else if(strcmp(what, "50 iterations without conv") == 0) returnStatus = PGSGCT_E_ITER_SOM;
74 else if(strcmp(what, "50 iterations without convergence") == 0) returnStatus = PGSGCT_E_ITER_SOM;
75 PGS_SMF_SetDynamicMsg(returnStatus,what,where);
76 #else
77 if (terminal_e)
78 printf("[%s] %s\n",where,what);
79 if (file_e)
80 {
81 fptr_e = (FILE *)fopen(err_file,"a");
82 fprintf(fptr_e,"[%s] %s\n",where,what);
83 fclose(fptr_e);
84 fptr_e = NULL;
85 }
86 #endif
87 }
88
89 /* initialize output device
90 -------------------------*/
91 int init(
92 long ipr, /* flag for printing errors (0,1,or 2) */
93 long jpr, /* flag for printing parameters (0,1,or 2) */
94 char *efile, /* name of error file */
95 char *pfile) /* name of parameter file */
96
97 {
98 if (ipr == 0)
99 {
100 terminal_e = TRUE;
101 file_e = FALSE;
102 }
103 else
104 if (ipr == 1)
105 {
106 terminal_e = FALSE;
107 if (strlen(efile) == 0)
108 {
109 return(6);
110 }
111 file_e = TRUE;
112 strcpy(err_file,efile);
113 }
114 else
115 if (ipr == 2)
116 {
117 terminal_e = TRUE;
118 if (strlen(efile) == 0)
119 {
120 file_e = FALSE;
121 p_error("Output file name not specified","report-file");
122 return(6);
123 }
124 file_e = TRUE;
125 strcpy(err_file,efile);
126 }
127 else
128 {
129 terminal_e = FALSE;
130 file_e = FALSE;
131 }
132 if (jpr == 0)
133 {
134 terminal_p = TRUE;
135 file_p = FALSE;
136 }
137 else
138 if (jpr == 1)
139 {
140 terminal_p = FALSE;
141 if (strlen(pfile) == 0)
142 {
143 return(6);
144 }
145 file_p = TRUE;
146 strcpy(parm_file,pfile);
147 }
148 else
149 if (jpr == 2)
150 {
151 terminal_p = TRUE;
152 if (strlen(pfile) == 0)
153 {
154 file_p = FALSE;
155 p_error("Output file name not specified","report-file");
156 return(6);
157 }
158 file_p = TRUE;
159 strcpy(parm_file,pfile);
160 }
161 else
162 {
163 terminal_p = FALSE;
164 file_p = FALSE;
165 }
166 return(0);
167 }
168
169 void close_file()
170 {
171 if (fptr_e != NULL)
172 {
173 fclose(fptr_e);
174 fptr_e = NULL;
175 }
176 if (fptr_p != NULL)
177 {
178 fclose(fptr_p);
179 fptr_p = NULL;
180 }
181 }
182
183 /* Functions to report projection parameters
184 -----------------------------------------*/
185 void ptitle(char *A)
186 {
187 if (terminal_p)
188 printf("\n%s PROJECTION PARAMETERS:\n\n",A);
189 if (file_p)
190 {
191 fptr_p = (FILE *)fopen(parm_file,"a");
192 fprintf(fptr_p,"\n%s PROJECTION PARAMETERS:\n\n",A);
193 fclose(fptr_p);
194 }
195 }
196
197 void radius(double A)
198 {
199 if (terminal_p)
200 printf(" Radius of Sphere: %lf meters\n",A);
201 if (file_p)
202 {
203 fptr_p = (FILE *)fopen(parm_file,"a");
204 fprintf(fptr_p," Radius of Sphere: %lf meters\n",A);
205 fclose(fptr_p);
206 }
207 }
208
209 void radius2(double A, double B)
210 {
211 if (terminal_p)
212 {
213 printf(" Semi-Major Axis of Ellipsoid: %lf meters\n",A);
214 printf(" Semi-Minor Axis of Ellipsoid: %lf meters\n",B);
215 }
216 if (file_p)
217 {
218 fptr_p = (FILE *)fopen(parm_file,"a");
219 fprintf(fptr_p," Semi-Major Axis of Ellipsoid: %lf meters\n",A);
220 fprintf(fptr_p," Semi-Minor Axis of Ellipsoid: %lf meters\n",B);
221 fclose(fptr_p);
222 }
223 }
224
225 void cenlon(double A)
226 {
227 if (terminal_p)
228 printf(" Longitude of Center: %lf degrees\n",A*R2D);
229 if (file_p)
230 {
231 fptr_p = (FILE *)fopen(parm_file,"a");
232 fprintf(fptr_p," Longitude of Center: %lf degrees\n",A*R2D);
233 fclose(fptr_p);
234 }
235 }
236
237 void cenlonmer(double A)
238 {
239 if (terminal_p)
240 printf(" Longitude of Central Meridian: %lf degrees\n",A*R2D);
241 if (file_p)
242 {
243 fptr_p = (FILE *)fopen(parm_file,"a");
244 fprintf(fptr_p," Longitude of Central Meridian: %lf degrees\n",A*R2D);
245 fclose(fptr_p);
246 }
247 }
248
249 void cenlat(double A)
250 {
251 if (terminal_p)
252 printf(" Latitude of Center: %lf degrees\n",A*R2D);
253 if (file_p)
254 {
255 fptr_p = (FILE *)fopen(parm_file,"a");
256 fprintf(fptr_p," Latitude of Center: %lf degrees\n",A*R2D);
257 fclose(fptr_p);
258 }
259 }
260
261 void origin(double A)
262 {
263 if (terminal_p)
264 printf(" Latitude of Origin: %lf degrees\n",A*R2D);
265 if (file_p)
266 {
267 fptr_p = (FILE *)fopen(parm_file,"a");
268 fprintf(fptr_p," Latitude of Origin: %lf degrees\n",A*R2D);
269 fclose(fptr_p);
270 }
271 }
272 void true_scale(double A)
273 {
274 if (terminal_p)
275 printf(" Latitude of True Scale: %lf degrees\n",A*R2D);
276 if (file_p)
277 {
278 fptr_p = (FILE *)fopen(parm_file,"a");
279 fprintf(fptr_p," Latitude of True Scale: %lf degrees\n",A*R2D);
280 fclose(fptr_p);
281 }
282 return;
283 }
284 void stanparl(double A, double B)
285 {
286 if (terminal_p)
287 {
288 printf(" 1st Standard Parallel: %lf degrees\n",A*R2D);
289 printf(" 2nd Standard Parallel: %lf degrees\n",B*R2D);
290 }
291 if (file_p)
292 {
293 fptr_p = (FILE *)fopen(parm_file,"a");
294 fprintf(fptr_p," 1st Standard Parallel: %lf degrees\n",A*R2D);
295 fprintf(fptr_p," 2nd Standard Parallel: %lf degrees\n",B*R2D);
296 fclose(fptr_p);
297 }
298 }
299
300 void stparl1(double A)
301 {
302 if (terminal_p)
303 {
304 printf(" Standard Parallel: %lf degrees\n",A*R2D);
305 }
306 if (file_p)
307 {
308 fptr_p = (FILE *)fopen(parm_file,"a");
309 fprintf(fptr_p," Standard Parallel: %lf degrees\n",A*R2D);
310 fclose(fptr_p);
311 }
312 }
313
314 void offsetp(double A, double B)
315 {
316 if (terminal_p)
317 {
318 printf(" False Easting: %lf meters \n",A);
319 printf(" False Northing: %lf meters \n",B);
320 }
321 if (file_p)
322 {
323 fptr_p = (FILE *)fopen(parm_file,"a");
324 fprintf(fptr_p," False Easting: %lf meters \n",A);
325 fprintf(fptr_p," False Northing: %lf meters \n",B);
326 fclose(fptr_p);
327 }
328 }
329
330 void genrpt(double A, char *S)
331 {
332 if (terminal_p)
333 printf(" %s %lf\n", S, A);
334 if (file_p)
335 {
336 fptr_p = (FILE *)fopen(parm_file,"a");
337 fprintf(fptr_p," %s %lf\n", S, A);
338 fclose(fptr_p);
339 }
340 }
341 void genrpt_long(long A, char *S)
342 {
343 if (terminal_p)
344 printf(" %s %ld\n", S, A);
345 if (file_p)
346 {
347 fptr_p = (FILE *)fopen(parm_file,"a");
348 fprintf(fptr_p," %s %ld\n", S, A);
349 fclose(fptr_p);
350 }
351 }
352 void pblank()
353 {
354 if (terminal_p)
355 printf("\n");
356 if (file_p)
357 {
358 fptr_p = (FILE *)fopen(parm_file,"a");
359 fprintf(fptr_p,"\n");
360 fclose(fptr_p);
361 }
362 }
363