printinfo.h 11.3 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
#define DATE_FORMAT "%5.4d-%2.2d-%2.2d"
#define TIME_FORMAT "%2.2d:%2.2d:%2.2d"

void date2str(int date, char *datestr, int maxlen)
{
  int year, month, day;
  int len;

  cdiDecodeDate(date, &year, &month, &day);

  len = sprintf(datestr, DATE_FORMAT, year, month, day);

  if ( len > ( maxlen-1) )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
14
    fprintf(stderr, "Internal problem (%s): sizeof input string is too small!\n", __func__);
15
16
17
18
19
20
21
22
23
24
25
26
27
}


void time2str(int time, char *timestr, int maxlen)
{
  int hour, minute, second;
  int len;

  cdiDecodeTime(time, &hour, &minute, &second);

  len = sprintf(timestr, TIME_FORMAT, hour, minute, second);

  if ( len > ( maxlen-1) )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
28
    fprintf(stderr, "Internal problem (%s): sizeof input string is too small!\n", __func__);
29
30
31
}


Uwe Schulzweida's avatar
Uwe Schulzweida committed
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
void printFiletype(int streamID, int vlistID)
{
  int filetype;

  filetype = streamInqFiletype(streamID);

  switch ( filetype )
    {
    case FILETYPE_GRB:
      printf("GRIB");
      break;
    case FILETYPE_GRB2:
      printf("GRIB2");
      break;
    case FILETYPE_NC:
      printf("netCDF");
      break;
    case FILETYPE_NC2:
      printf("netCDF2");
      break;
    case FILETYPE_NC4:
      printf("netCDF4");
      break;
55
56
57
    case FILETYPE_NC4C:
      printf("netCDF4 classic");
      break;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
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
    case FILETYPE_SRV:
      printf("SERVICE");
      break;
    case FILETYPE_EXT:
      printf("EXTRA");
      break;
    case FILETYPE_IEG:
      printf("IEG");
      break;
    default:
      printf("  File format: unsupported filetype %d" , filetype);
    }

  if ( filetype == FILETYPE_SRV || filetype == FILETYPE_EXT || filetype == FILETYPE_IEG )
    {
      switch ( streamInqByteorder(streamID) )
	{
	case CDI_BIGENDIAN:
	  printf("  BIGENDIAN"); break;
	case CDI_LITTLEENDIAN:
	  printf("  LITTLEENDIAN"); break;
	default:
	  printf("  byteorder: %d undefined", streamInqByteorder(streamID)); break;
	}
    }

84
  if ( filetype == FILETYPE_GRB || filetype == FILETYPE_NC4 || filetype == FILETYPE_NC4C )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
85
86
    {
      int nvars, varID;
87
      int comptype;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
88
89
90
91
92

      nvars = vlistNvars(vlistID);

      for ( varID = 0; varID < nvars; varID++ )
	{
93
94
	  comptype = vlistInqVarCompType(vlistID, varID);
	  if ( comptype )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
95
	    {
96
	      if ( comptype == COMPRESS_SZIP )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
97
		printf(" SZIP");
98
	      else if ( comptype == COMPRESS_ZIP )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
99
100
101
102
103
104
105
		printf(" ZIP");

	      break;
	    }
	}
    }

106
107
108
  if ( filetype == FILETYPE_GRB2 )
    {
      int nvars, varID;
109
      int comptype;
110
111
112
113
114

      nvars = vlistNvars(vlistID);

      for ( varID = 0; varID < nvars; varID++ )
	{
115
116
	  comptype = vlistInqVarCompType(vlistID, varID);
	  if ( comptype )
117
	    {
118
	      if ( comptype == COMPRESS_JPEG )
119
120
121
122
123
124
125
		printf(" JPEG");

	      break;
	    }
	}
    }

Uwe Schulzweida's avatar
Uwe Schulzweida committed
126
127
128
  printf("\n");
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
129
130
static
void printGridInfo(int vlistID)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
131
132
133
134
{
  int ngrids, index;
  int gridID, gridtype, trunc, gridsize, xsize, ysize;
  int nbyte0;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
135
  char xname[CDI_MAX_NAME], yname[CDI_MAX_NAME], xunits[CDI_MAX_NAME], yunits[CDI_MAX_NAME];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150

  ngrids = vlistNgrids(vlistID);
  for ( index = 0; index < ngrids; index++ )
    {
      gridID   = vlistGrid(vlistID, index);
      gridtype = gridInqType(gridID);
      trunc    = gridInqTrunc(gridID);
      gridsize = gridInqSize(gridID);
      xsize    = gridInqXsize(gridID);
      ysize    = gridInqYsize(gridID);
      gridInqXname(gridID, xname);
      gridInqYname(gridID, yname);
      gridInqXunits(gridID, xunits);
      gridInqYunits(gridID, yunits);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
151
      nbyte0   = fprintf(stdout, "  %4d : %-12s > ", index+1, gridNamePtr(gridtype));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
152
153
154
155
156
157
158
159
160
161
162

      if ( gridtype == GRID_LONLAT   ||
	   gridtype == GRID_LCC2 ||
	   gridtype == GRID_LAEA ||
	   gridtype == GRID_SINUSOIDAL ||
	   gridtype == GRID_GAUSSIAN ||
	   gridtype == GRID_GAUSSIAN_REDUCED )
	{
	  double xfirst = 0.0, xlast = 0.0;
	  double yfirst = 0.0, ylast = 0.0;
	  double xinc = 0.0, yinc = 0.0;
163

Uwe Schulzweida's avatar
Uwe Schulzweida committed
164
165
166
	  yfirst = gridInqYval(gridID, 0);
	  ylast  = gridInqYval(gridID, ysize-1);
	  yinc   = gridInqYinc(gridID);
167

Uwe Schulzweida's avatar
Uwe Schulzweida committed
168
	  if ( gridtype == GRID_GAUSSIAN_REDUCED )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
169
	    fprintf(stdout, "size : dim = %d  nlat = %d", gridsize, ysize);
170
	  else
Uwe Schulzweida's avatar
Uwe Schulzweida committed
171
172
173
174
175
176
	    fprintf(stdout, "size      : dim = %d  nlon = %d  nlat = %d", gridsize, xsize, ysize);
	  
	  if ( gridtype == GRID_GAUSSIAN || gridtype == GRID_GAUSSIAN_REDUCED )
	    fprintf(stdout, "  np = %d", gridInqNP(gridID));

	  fprintf(stdout, "\n");
177
178

	  if ( xsize > 0 )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
179
	    {
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
	      if ( gridtype == GRID_GAUSSIAN_REDUCED )
		{
		  fprintf(stdout, "size : dim = %d  nlat = %d\n", gridsize, ysize);
		  fprintf(stdout, "%*s", nbyte0, "");
		  fprintf(stdout, "longitude : reduced\n");
		}
	      else
		{
		  xfirst = gridInqXval(gridID, 0);
		  xlast  = gridInqXval(gridID, xsize-1);
		  xinc   = gridInqXinc(gridID);
		  fprintf(stdout, "%*s", nbyte0, "");
		  fprintf(stdout, "%-9s : first = %.9g", xname, xfirst);
		  if ( xsize > 1 ) fprintf(stdout, "  last = %.9g", xlast);
		  if ( IS_NOT_EQUAL(xinc, 0) )
		    fprintf(stdout, "  inc = %.9g", xinc);
		  fprintf(stdout, "  %s", xunits);
		  if ( gridIsCircular(gridID) )
		    fprintf(stdout, "  circular");
		  fprintf(stdout, "\n");
		}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
201
	    }
202
203

	  if ( ysize > 0 )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
204
205
	    {
	      fprintf(stdout, "%*s", nbyte0, "");
206
	      fprintf(stdout, "%-9s : first = %.9g", yname, yfirst);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
207
	      if ( ysize > 1 ) fprintf(stdout, "  last = %.9g", ylast);
208
209
210
211
212
	      if ( IS_NOT_EQUAL(yinc, 0) && 
		   (gridtype == GRID_LONLAT || gridtype == GRID_SINUSOIDAL || 
		    gridtype == GRID_LCC2 || gridtype == GRID_LAEA) )
		fprintf(stdout, "  inc = %.9g", yinc);
	      fprintf(stdout, "  %s", yunits);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
213
214
	      fprintf(stdout, "\n");
	    }
215

Uwe Schulzweida's avatar
Uwe Schulzweida committed
216
217
218
219
220
221
222
223
224
225
226
	  if ( gridIsRotated(gridID) )
	    {
	      double lonpole, latpole, angle;
	      lonpole = gridInqXpole(gridID);
	      latpole = gridInqYpole(gridID);
	      angle   = gridInqAngle(gridID);
	      fprintf(stdout, "%*s", nbyte0, "");
	      fprintf(stdout, "northpole : lon = %.9g  lat = %.9g", lonpole, latpole);
	      if ( angle > 0 ) fprintf(stdout, "  angle = %.9g", angle);
	      fprintf(stdout, "\n");
	    }
227

Uwe Schulzweida's avatar
Uwe Schulzweida committed
228
229
230
231
232
233
	  if ( gridInqXbounds(gridID, NULL) || gridInqYbounds(gridID, NULL) )
	    {
	      fprintf(stdout, "%*s", nbyte0, "");
	      fprintf(stdout, "available :");
	      if ( gridInqXbounds(gridID, NULL) ) fprintf(stdout, " xbounds");
	      if ( gridInqYbounds(gridID, NULL) ) fprintf(stdout, " ybounds");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
234
	      if ( gridInqMask(gridID, NULL) )    fprintf(stdout, " mask");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
235
236
	      fprintf(stdout, "\n");
	    }
237

Uwe Schulzweida's avatar
Uwe Schulzweida committed
238
239
240
241
242
243
244
	  if ( gridtype == GRID_LAEA )
	    {
	      double a, lon_0, lat_0;
	      gridInqLaea(gridID, &a, &lon_0, &lat_0);
	      fprintf(stdout, "%*s", nbyte0, "");
	      fprintf(stdout, "projpar   : a = %g  lon_0 = %g  lat_0 = %g\n", a, lon_0, lat_0);
	    }
245

Uwe Schulzweida's avatar
Uwe Schulzweida committed
246
247
248
249
250
251
252
253
254
255
256
	  if ( gridtype == GRID_LCC2 )
	    {
	      double a, lon_0, lat_0, lat_1, lat_2;
	      gridInqLcc2(gridID, &a, &lon_0, &lat_0, &lat_1, &lat_2);
	      fprintf(stdout, "%*s", nbyte0, "");
	      fprintf(stdout, "projpar   : a = %7.0f  lon_0 = %g  lat_0 = %g  lat_1 = %g  lat_2 = %g\n",
		      a, lon_0, lat_0, lat_1, lat_2);
	    }
	}
      else if ( gridtype == GRID_SPECTRAL )
	{
257
	  fprintf(stdout, "size      : dim = %d  nsp = %d  truncation = %d\n", gridsize, gridsize/2, trunc);
258
259
	  fprintf(stdout, "%*s", nbyte0, "");
	  fprintf(stdout, "            complexPacking = %d\n", gridInqComplexPacking(gridID));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
260
	}
261
262
      else if ( gridtype == GRID_FOURIER )
	{
263
	  fprintf(stdout, "size      : dim = %d  nfc = %d  truncation = %d\n", gridsize, gridsize/2, trunc);
264
	}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
265
266
267
268
269
270
271
      else if ( gridtype == GRID_GME )
	{
	  int ni, nd;
	  ni = gridInqGMEni(gridID);
	  nd = gridInqGMEnd(gridID);
	  fprintf(stdout, "size      : dim = %d  nd = %d  ni = %d\n", gridsize, nd, ni);
	}
272
      else if ( gridtype == GRID_REFERENCE )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
273
274
275
276
277
278
279
	{
	  int number, position;
	  number   = gridInqNumber(gridID);
	  position = gridInqPosition(gridID);
	  fprintf(stdout, "size      : dim = %d\n", gridsize);
	  fprintf(stdout, "%*s", nbyte0, "");
	  fprintf(stdout, "grid      : number = %d  position = %d\n", number, position);
280
281
282
283
284
285
286
	  if ( gridInqReference(gridID, NULL) )
	    {
	      char reference_link[8192];
	      gridInqReference(gridID, reference_link);
	      fprintf(stdout, "%*s", nbyte0, "");
	      fprintf(stdout, "path      : %s\n", reference_link);
	    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
287
	}
288
      else if ( gridtype == GRID_CURVILINEAR || gridtype == GRID_UNSTRUCTURED )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
	{
	  if ( gridtype == GRID_CURVILINEAR )
	    fprintf(stdout, "size      : dim = %d  nx = %d  ny = %d\n", gridsize, xsize, ysize);
	  else
	    fprintf(stdout, "size      : dim = %d  nvertex = %d\n", gridsize, gridInqNvertex(gridID));

	  if ( gridInqXvals(gridID, NULL) && gridInqYvals(gridID, NULL) )
	    {
	      int i;
	      double *xvals, *yvals;
	      double xfirst, xlast, yfirst, ylast;
	      xvals = (double *) malloc(gridsize*sizeof(double));
	      yvals = (double *) malloc(gridsize*sizeof(double));

	      gridInqXvals(gridID, xvals);
	      gridInqYvals(gridID, yvals);

	      xfirst = xvals[0];
	      xlast  = xvals[0];
	      yfirst = yvals[0];
	      ylast  = yvals[0];
	      for ( i = 1; i < gridsize; i++ )
		{
		  if ( xvals[i] < xfirst ) xfirst = xvals[i];
		  if ( xvals[i] > xlast )  xlast  = xvals[i];
		  if ( yvals[i] < yfirst ) yfirst = yvals[i];
		  if ( yvals[i] > ylast )  ylast  = yvals[i];
		}

	      fprintf(stdout, "%*s", nbyte0, "");
	      fprintf(stdout, "%-9s : min = %.9g  max = %.9g  %s", xname, xfirst, xlast, xunits);
	      if ( gridIsCircular(gridID) )
		fprintf(stdout, "  circular");
	      fprintf(stdout, "\n");
	      fprintf(stdout, "%*s", nbyte0, "");
	      fprintf(stdout, "%-9s : min = %.9g  max = %.9g  %s\n", yname, yfirst, ylast, yunits);
325
 
Uwe Schulzweida's avatar
Uwe Schulzweida committed
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
	      free(xvals);
	      free(yvals);
	    }
	}
      else if ( gridtype == GRID_LCC )
	{
	  double originLon, originLat, lonParY, lat1, lat2, xincm, yincm;
	  int projflag, scanflag;

	  gridInqLCC(gridID, &originLon, &originLat, &lonParY, &lat1, &lat2, &xincm, &yincm,
		     &projflag, &scanflag);

	  fprintf(stdout, "size      : dim = %d  nx = %d  ny = %d  ", gridsize, xsize, ysize);
	  if ( (projflag&128) == 0 )
	    fprintf(stdout, "North Pole\n");
	  else
	    fprintf(stdout, "South Pole\n");
343
	  fprintf(stdout, "%*s", nbyte0, "");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
344
345
	  fprintf(stdout, "            originLon = %g  originLat = %g  lonParY = %g\n",
		  originLon, originLat, lonParY);
346
347
	  fprintf(stdout, "%*s", nbyte0, "");
	  fprintf(stdout, "            lat1 = %g  lat2 = %g  xinc = %g m  yinc = %g m\n",
Uwe Schulzweida's avatar
Uwe Schulzweida committed
348
349
350
351
352
353
354
355
356
357
358
		  lat1, lat2, xincm, yincm);
	}
      else /* if ( gridtype == GRID_GENERIC ) */
	{
	  if ( ysize == 0 )
	    fprintf(stdout, "size      : dim = %d\n", gridsize);
	  else
	    {
	      fprintf(stdout, "size      : dim = %d  nx = %d  ny = %d\n", gridsize, xsize, ysize);
	      if ( gridIsCircular(gridID) )
		{
359
		  fprintf(stdout, "%*s", nbyte0, "");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
360
361
362
363
364
		  fprintf(stdout, "longitude :  circular\n");
		}
	    }
	}

365
      if ( gridtype == GRID_CURVILINEAR || gridtype == GRID_UNSTRUCTURED ||
Uwe Schulzweida's avatar
Uwe Schulzweida committed
366
367
368
369
370
371
372
373
374
375
376
377
	   gridtype == GRID_GENERIC || gridtype == GRID_LCC )
	{
	  if ( gridInqXvals(gridID, NULL) || gridInqYvals(gridID, NULL) || gridHasArea(gridID) ||
	       gridInqXbounds(gridID, NULL) || gridInqYbounds(gridID, NULL) )
	    {
	      fprintf(stdout, "%*s", nbyte0, "");
	      fprintf(stdout, "available :");
	      if ( gridInqXvals(gridID, NULL) )   fprintf(stdout, " xvals");
	      if ( gridInqYvals(gridID, NULL) )   fprintf(stdout, " yvals");
	      if ( gridInqXbounds(gridID, NULL) ) fprintf(stdout, " xbounds");
	      if ( gridInqYbounds(gridID, NULL) ) fprintf(stdout, " ybounds");
	      if ( gridHasArea(gridID) )          fprintf(stdout, " area");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
378
	      if ( gridInqMask(gridID, NULL) )    fprintf(stdout, " mask");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
379
380
381
382
383
	      fprintf(stdout, "\n");
	    }
	}
    }
}