OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
proj_report.c
Go to the documentation of this file.
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 
29  *******************************************************************************/
30 #include <stdio.h>
31 #include <stdint.h>
32 #include <string.h>
33 #include "proj_cproj.h"
34 
35 #define TRUE 1
36 #define FALSE 0
37 
38 static int32_t terminal_p; /* flag for printing parameters to terminal */
39 static int32_t terminal_e; /* flag for printing errors to terminal */
40 static int32_t file_p; /* flag for printing parameters to file */
41 static int32_t file_e; /* flag for printing errors to terminal */
42 static FILE *fptr_p;
43 static FILE *fptr_e;
44 static char parm_file[256];
45 static char err_file[256];
46 
47 void p_error(char *what, char *where);
48 
49 /* initialize output device
50 -------------------------*/
51 int init(ipr, jpr, efile, pfile)
52 
53 int32_t ipr; /* flag for printing errors (0,1,or 2) */
54 int32_t jpr; /* flag for printing parameters (0,1,or 2) */
55 char *efile; /* name of error file */
56 char *pfile; /* name of parameter file */
57 
58 {
59  if (ipr == 0) {
60  terminal_e = TRUE;
61  file_e = FALSE;
62  } else
63  if (ipr == 1) {
64  terminal_e = FALSE;
65  if (strlen(efile) == 0) {
66  return (6);
67  }
68  file_e = TRUE;
69  strcpy(err_file, efile);
70  } else
71  if (ipr == 2) {
72  terminal_e = TRUE;
73  if (strlen(efile) == 0) {
74  file_e = FALSE;
75  p_error("Output file name not specified", "report-file");
76  return (6);
77  }
78  file_e = TRUE;
79  strcpy(err_file, efile);
80  } else {
81  terminal_e = FALSE;
82  file_e = FALSE;
83  }
84  if (jpr == 0) {
85  terminal_p = TRUE;
86  file_p = FALSE;
87  } else
88  if (jpr == 1) {
89  terminal_p = FALSE;
90  if (strlen(pfile) == 0) {
91  return (6);
92  }
93  file_p = TRUE;
94  strcpy(parm_file, pfile);
95  } else
96  if (jpr == 2) {
97  terminal_p = TRUE;
98  if (strlen(pfile) == 0) {
99  file_p = FALSE;
100  p_error("Output file name not specified", "report-file");
101  return (6);
102  }
103  file_p = TRUE;
104  strcpy(parm_file, pfile);
105  } else {
106  terminal_p = FALSE;
107  file_p = FALSE;
108  }
109  return (0);
110 }
111 
112 void close_file() {
113  if (fptr_e != NULL)
114  fclose(fptr_e);
115  if (fptr_p != NULL)
116  fclose(fptr_p);
117 }
118 
119 /* Functions to report projection parameters
120  -----------------------------------------*/
121 void ptitle(A) char *A;
122 {
123  if (terminal_p)
124  printf("\n%s PROJECTION PARAMETERS:\n\n", A);
125  if (file_p) {
126  fptr_p = (FILE *) fopen(parm_file, "a");
127  fprintf(fptr_p, "\n%s PROJECTION PARAMETERS:\n\n", A);
128  fclose(fptr_p);
129  }
130 }
131 
132 void radius(A) double A;
133 {
134  if (terminal_p)
135  printf(" Radius of Sphere: %lf meters\n", A);
136  if (file_p) {
137  fptr_p = (FILE *) fopen(parm_file, "a");
138  fprintf(fptr_p, " Radius of Sphere: %lf meters\n", A);
139  fclose(fptr_p);
140  }
141 }
142 
143 void radius2(A, B) double A, B;
144 {
145  if (terminal_p) {
146  printf(" Semi-Major Axis of Ellipsoid: %lf meters\n", A);
147  printf(" Semi-Minor Axis of Ellipsoid: %lf meters\n", B);
148  }
149  if (file_p) {
150  fptr_p = (FILE *) fopen(parm_file, "a");
151  fprintf(fptr_p, " Semi-Major Axis of Ellipsoid: %lf meters\n", A);
152  fprintf(fptr_p, " Semi-Minor Axis of Ellipsoid: %lf meters\n", B);
153  fclose(fptr_p);
154  }
155 }
156 
157 void cenlon(A) double A;
158 {
159  if (terminal_p)
160  printf(" Longitude of Center: %lf degrees\n", A * R2D);
161  if (file_p) {
162  fptr_p = (FILE *) fopen(parm_file, "a");
163  fprintf(fptr_p, " Longitude of Center: %lf degrees\n", A * R2D);
164  fclose(fptr_p);
165  }
166 }
167 
168 void cenlonmer(A) double A;
169 {
170  if (terminal_p)
171  printf(" Longitude of Central Meridian: %lf degrees\n", A * R2D);
172  if (file_p) {
173  fptr_p = (FILE *) fopen(parm_file, "a");
174  fprintf(fptr_p, " Longitude of Central Meridian: %lf degrees\n", A * R2D);
175  fclose(fptr_p);
176  }
177 }
178 
179 void cenlat(A) double A;
180 {
181  if (terminal_p)
182  printf(" Latitude of Center: %lf degrees\n", A * R2D);
183  if (file_p) {
184  fptr_p = (FILE *) fopen(parm_file, "a");
185  fprintf(fptr_p, " Latitude of Center: %lf degrees\n", A * R2D);
186  fclose(fptr_p);
187  }
188 }
189 
190 void origin(A) double A;
191 {
192  if (terminal_p)
193  printf(" Latitude of Origin: %lf degrees\n", A * R2D);
194  if (file_p) {
195  fptr_p = (FILE *) fopen(parm_file, "a");
196  fprintf(fptr_p, " Latitude of Origin: %lf degrees\n", A * R2D);
197  fclose(fptr_p);
198  }
199 }
200 
201 void stanparl(A, B) double A, B;
202 {
203  if (terminal_p) {
204  printf(" 1st Standard Parallel: %lf degrees\n", A * R2D);
205  printf(" 2nd Standard Parallel: %lf degrees\n", B * R2D);
206  }
207  if (file_p) {
208  fptr_p = (FILE *) fopen(parm_file, "a");
209  fprintf(fptr_p, " 1st Standard Parallel: %lf degrees\n", A * R2D);
210  fprintf(fptr_p, " 2nd Standard Parallel: %lf degrees\n", B * R2D);
211  fclose(fptr_p);
212  }
213 }
214 
215 void stparl1(A) double A;
216 {
217  if (terminal_p) {
218  printf(" Standard Parallel: %lf degrees\n", A * R2D);
219  }
220  if (file_p) {
221  fptr_p = (FILE *) fopen(parm_file, "a");
222  fprintf(fptr_p, " Standard Parallel: %lf degrees\n", A * R2D);
223  fclose(fptr_p);
224  }
225 }
226 
227 void offsetp(A, B) double A, B;
228 {
229  if (terminal_p) {
230  printf(" False Easting: %lf meters \n", A);
231  printf(" False Northing: %lf meters \n", B);
232  }
233  if (file_p) {
234  fptr_p = (FILE *) fopen(parm_file, "a");
235  fprintf(fptr_p, " False Easting: %lf meters \n", A);
236  fprintf(fptr_p, " False Northing: %lf meters \n", B);
237  fclose(fptr_p);
238  }
239 }
240 
241 void genrpt(A, S) double A;
242 char *S;
243 {
244  if (terminal_p)
245  printf(" %s %lf\n", S, A);
246  if (file_p) {
247  fptr_p = (FILE *) fopen(parm_file, "a");
248  fprintf(fptr_p, " %s %lf\n", S, A);
249  fclose(fptr_p);
250  }
251 }
252 
253 void genrpt_long(A, S) int32_t A;
254 char *S;
255 {
256  if (terminal_p)
257  printf(" %s %d\n", S, A);
258  if (file_p) {
259  fptr_p = (FILE *) fopen(parm_file, "a");
260  fprintf(fptr_p, " %s %d\n", S, A);
261  fclose(fptr_p);
262  }
263 }
264 
265 void pblank() {
266  if (terminal_p)
267  printf("\n");
268  if (file_p) {
269  fptr_p = (FILE *) fopen(parm_file, "a");
270  fprintf(fptr_p, "\n");
271  fclose(fptr_p);
272  }
273 }
274 
275 /* Function to report errors
276  -------------------------*/
277 void p_error(what, where)
278 char *what;
279 char *where;
280 {
281  if (terminal_e)
282  printf("[%s] %s\n", where, what);
283  if (file_e) {
284  fptr_e = (FILE *) fopen(err_file, "a");
285  fprintf(fptr_e, "[%s] %s\n", where, what);
286  fclose(fptr_e);
287  }
288 }
void close_file()
Definition: proj_report.c:112
#define NULL
Definition: decode_rs.h:63
void cenlat(double A)
Definition: proj_report.c:179
#define FALSE
Definition: proj_report.c:36
void p_error(char *what, char *where)
Definition: proj_report.c:277
void cenlon(double A)
Definition: proj_report.c:157
void offsetp(double A, double B)
Definition: proj_report.c:227
#define TRUE
Definition: proj_report.c:35
int init(int32_t ipr, int32_t jpr, char *efile, char *pfile)
Definition: proj_report.c:51
void radius2(double A, double B)
Definition: proj_report.c:143
void genrpt_long(int32_t A, char *S)
Definition: proj_report.c:253
void origin(double A)
Definition: proj_report.c:190
void ptitle(char *A)
Definition: proj_report.c:121
void cenlonmer(double A)
Definition: proj_report.c:168
void stparl1(double A)
Definition: proj_report.c:215
void pblank()
Definition: proj_report.c:265
#define R2D
Definition: proj_define.h:87
void radius(double A)
Definition: proj_report.c:132
How many dimensions is the output array Default is Not sure if anything above will work correctly strcpy(l2prod->title, "no title yet")
void genrpt(double A, char *S)
Definition: proj_report.c:241
void stanparl(double A, double B)
Definition: proj_report.c:201