printinfo.h 12.3 KB
Newer Older
1
2
3
#define DATE_FORMAT "%5.4d-%2.2d-%2.2d"
#define TIME_FORMAT "%2.2d:%2.2d:%2.2d"

4
5
void uuid2str(const char *uuid, char *uuidstr);

6
7
8
9
10
11
12
13
14
15
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
16
    fprintf(stderr, "Internal problem (%s): sizeof input string is too small!\n", __func__);
17
18
19
20
21
22
23
24
25
26
27
28
29
}


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
30
    fprintf(stderr, "Internal problem (%s): sizeof input string is too small!\n", __func__);
31
32
33
}


Uwe Schulzweida's avatar
Uwe Schulzweida committed
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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;
57
58
59
    case FILETYPE_NC4C:
      printf("netCDF4 classic");
      break;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
60
61
62
63
64
65
66
67
68
69
70
    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);
71
      break;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
    }

  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;
	}
    }

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

      nvars = vlistNvars(vlistID);

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

	      break;
	    }
	}
    }

109
110
111
  if ( filetype == FILETYPE_GRB2 )
    {
      int nvars, varID;
112
      int comptype;
113
114
115
116
117

      nvars = vlistNvars(vlistID);

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

	      break;
	    }
	}
    }

Uwe Schulzweida's avatar
Uwe Schulzweida committed
129
130
131
  printf("\n");
}

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

  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);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
150
      xysize   = xsize*ysize;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
151
152
153
154
155
      gridInqXname(gridID, xname);
      gridInqYname(gridID, yname);
      gridInqXunits(gridID, xunits);
      gridInqYunits(gridID, yunits);

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

      if ( gridtype == GRID_LONLAT   ||
	   gridtype == GRID_LCC2 ||
	   gridtype == GRID_LAEA ||
	   gridtype == GRID_SINUSOIDAL ||
162
	   gridtype == GRID_GENERIC ||
Uwe Schulzweida's avatar
Uwe Schulzweida committed
163
164
165
	   gridtype == GRID_GAUSSIAN ||
	   gridtype == GRID_GAUSSIAN_REDUCED )
	{
166
          int lxcoord = 1, lycoord = 1;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
167
168
169
	  double xfirst = 0.0, xlast = 0.0;
	  double yfirst = 0.0, ylast = 0.0;
	  double xinc = 0.0, yinc = 0.0;
170

Uwe Schulzweida's avatar
Uwe Schulzweida committed
171
172
173
	  yfirst = gridInqYval(gridID, 0);
	  ylast  = gridInqYval(gridID, ysize-1);
	  yinc   = gridInqYinc(gridID);
174

Uwe Schulzweida's avatar
Uwe Schulzweida committed
175
          fprintf(stdout, "          : points=%d", gridsize);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
176
	  if ( gridtype == GRID_GAUSSIAN_REDUCED )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
177
178
179
	    fprintf(stdout, "  nlat=%d", ysize);
	  else if ( xysize )
	    fprintf(stdout, " (%dx%d)", xsize, ysize);
180

Uwe Schulzweida's avatar
Uwe Schulzweida committed
181
	  if ( gridtype == GRID_GAUSSIAN || gridtype == GRID_GAUSSIAN_REDUCED )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
182
	    fprintf(stdout, "  np=%d", gridInqNP(gridID));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
183
184

	  fprintf(stdout, "\n");
185

186
187
188
189
          if ( gridInqXvals(gridID, NULL) == 0 ) lxcoord = 0;
          if ( gridInqYvals(gridID, NULL) == 0 ) lycoord = 0;

	  if ( xsize > 0 && lxcoord )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
190
	    {
191
192
	      if ( gridtype == GRID_GAUSSIAN_REDUCED )
		{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
193
		  fprintf(stdout, "     : points=%d  nlat=%d\n", gridsize, ysize);
194
195
196
197
198
199
200
201
202
		  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, "");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
203
204
205
206
207
208
209
210
		  fprintf(stdout, "%-9s : %g", xname, xfirst);
		  if ( xsize > 1 )
                    {
                      fprintf(stdout, " to %g", xlast);
                      if ( IS_NOT_EQUAL(xinc, 0) )
                        fprintf(stdout, " by %g", xinc);
                    }
		  fprintf(stdout, " %s", xunits);
211
		  if ( gridIsCircular(gridID) ) fprintf(stdout, "  circular");
212
213
		  fprintf(stdout, "\n");
		}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
214
	    }
215

216
	  if ( ysize > 0 && lycoord )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
217
218
	    {
	      fprintf(stdout, "%*s", nbyte0, "");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
219
220
221
222
223
224
225
226
	      fprintf(stdout, "%-9s : %g", yname, yfirst);
	      if ( ysize > 1 )
                {
                  fprintf(stdout, " to %g", ylast);
                  if ( IS_NOT_EQUAL(yinc, 0) && gridtype != GRID_GAUSSIAN && gridtype != GRID_GAUSSIAN_REDUCED )
                    fprintf(stdout, " by %g", yinc);
                }
              fprintf(stdout, " %s", yunits);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
227
228
	      fprintf(stdout, "\n");
	    }
229

Uwe Schulzweida's avatar
Uwe Schulzweida committed
230
231
232
233
234
235
236
	  if ( gridIsRotated(gridID) )
	    {
	      double lonpole, latpole, angle;
	      lonpole = gridInqXpole(gridID);
	      latpole = gridInqYpole(gridID);
	      angle   = gridInqAngle(gridID);
	      fprintf(stdout, "%*s", nbyte0, "");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
237
238
	      fprintf(stdout, "northpole : lon=%g  lat=%g", lonpole, latpole);
	      if ( angle > 0 ) fprintf(stdout, "  angle=%g", angle);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
239
240
	      fprintf(stdout, "\n");
	    }
241

Uwe Schulzweida's avatar
Uwe Schulzweida committed
242
243
244
245
246
247
	  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");
248
	      if ( gridHasArea(gridID) )          fprintf(stdout, " area");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
249
	      if ( gridInqMask(gridID, NULL) )    fprintf(stdout, " mask");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
250
251
	      fprintf(stdout, "\n");
	    }
252

Uwe Schulzweida's avatar
Uwe Schulzweida committed
253
254
255
256
257
	  if ( gridtype == GRID_LAEA )
	    {
	      double a, lon_0, lat_0;
	      gridInqLaea(gridID, &a, &lon_0, &lat_0);
	      fprintf(stdout, "%*s", nbyte0, "");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
258
	      fprintf(stdout, "projpar   : a=%g  lon_0=%g  lat_0=%g\n", a, lon_0, lat_0);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
259
	    }
260

Uwe Schulzweida's avatar
Uwe Schulzweida committed
261
262
263
264
265
	  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, "");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
266
	      fprintf(stdout, "projpar   : a=%7.0f  lon_0=%g  lat_0=%g  lat_1=%g  lat_2=%g\n",
Uwe Schulzweida's avatar
Uwe Schulzweida committed
267
268
269
270
271
		      a, lon_0, lat_0, lat_1, lat_2);
	    }
	}
      else if ( gridtype == GRID_SPECTRAL )
	{
272
	  fprintf(stdout, "          : points=%d  nsp=%d  truncation=%d\n", gridsize, gridsize/2, trunc);
273
	  fprintf(stdout, "%*s", nbyte0, "");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
274
	  fprintf(stdout, "            complexPacking=%d\n", gridInqComplexPacking(gridID));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
275
	}
276
277
      else if ( gridtype == GRID_FOURIER )
	{
278
	  fprintf(stdout, "         : points=%d  nfc=%d  truncation=%d\n", gridsize, gridsize/2, trunc);
279
	}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
280
281
282
283
284
      else if ( gridtype == GRID_GME )
	{
	  int ni, nd;
	  ni = gridInqGMEni(gridID);
	  nd = gridInqGMEnd(gridID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
285
	  fprintf(stdout, "          : points=%d  nd=%d  ni=%d\n", gridsize, nd, ni);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
286
	}
287
      else if ( gridtype == GRID_CURVILINEAR || gridtype == GRID_UNSTRUCTURED )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
288
289
	{
	  if ( gridtype == GRID_CURVILINEAR )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
290
	    fprintf(stdout, "          : points=%d (%dx%d)", gridsize, xsize, ysize);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
291
	  else
Uwe Schulzweida's avatar
Uwe Schulzweida committed
292
	    fprintf(stdout, "          : points=%d", gridsize);
293
294

          if ( gridtype == GRID_UNSTRUCTURED && gridInqNvertex(gridID) > 0 )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
295
	    fprintf(stdout, "  nvertex=%d", gridInqNvertex(gridID));
296
297
298
299
300

          fprintf(stdout, "\n");

          if ( gridtype == GRID_UNSTRUCTURED )
            {
301
302
303
              int number   = gridInqNumber(gridID);
              int position = gridInqPosition(gridID);

304
305
306
              if ( number > 0 )
                {
                  fprintf(stdout, "%*s", nbyte0, "");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
307
                  fprintf(stdout, "grid      : number=%d  position=%d\n", number, position);
308
309
310
311
312
313
314
                }

              if ( gridInqReference(gridID, NULL) )
                {
                  char reference_link[8192];
                  gridInqReference(gridID, reference_link);
                  fprintf(stdout, "%*s", nbyte0, "");
315
                  fprintf(stdout, "uri       : %s\n", reference_link);
316
317
                }
            }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
318
319
320
321
322
323

	  if ( gridInqXvals(gridID, NULL) && gridInqYvals(gridID, NULL) )
	    {
	      int i;
	      double *xvals, *yvals;
	      double xfirst, xlast, yfirst, ylast;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
324
325
	      xvals = malloc(gridsize*sizeof(double));
	      yvals = malloc(gridsize*sizeof(double));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
326
327
328
329
330
331
332
333
334
335
336

	      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];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
337
		  if ( xvals[i] > xlast  ) xlast  = xvals[i];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
338
		  if ( yvals[i] < yfirst ) yfirst = yvals[i];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
339
		  if ( yvals[i] > ylast  ) ylast  = yvals[i];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
340
341
342
		}

	      fprintf(stdout, "%*s", nbyte0, "");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
343
	      fprintf(stdout, "%-9s : %g to %g %s", xname, xfirst, xlast, xunits);
344
	      if ( gridIsCircular(gridID) ) fprintf(stdout, "  circular");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
345
346
	      fprintf(stdout, "\n");
	      fprintf(stdout, "%*s", nbyte0, "");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
347
	      fprintf(stdout, "%-9s : %g to %g %s\n", yname, yfirst, ylast, yunits);
348

Uwe Schulzweida's avatar
Uwe Schulzweida committed
349
350
351
352
353
354
355
356
357
358
359
360
	      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);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
361
	  fprintf(stdout, "          : points=%d (%dx%d)  ", gridsize, xsize, ysize);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
362
363
364
365
	  if ( (projflag&128) == 0 )
	    fprintf(stdout, "North Pole\n");
	  else
	    fprintf(stdout, "South Pole\n");
366
	  fprintf(stdout, "%*s", nbyte0, "");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
367
	  fprintf(stdout, "            originLon=%g  originLat=%g  lonParY=%g\n",
Uwe Schulzweida's avatar
Uwe Schulzweida committed
368
		  originLon, originLat, lonParY);
369
	  fprintf(stdout, "%*s", nbyte0, "");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
370
	  fprintf(stdout, "            lat1=%g  lat2=%g  xinc=%g m  yinc=%g m\n",
Uwe Schulzweida's avatar
Uwe Schulzweida committed
371
372
373
374
375
		  lat1, lat2, xincm, yincm);
	}
      else /* if ( gridtype == GRID_GENERIC ) */
	{
	  if ( ysize == 0 )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
376
	    fprintf(stdout, "          : points=%d\n", gridsize);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
377
	  else
Uwe Schulzweida's avatar
Uwe Schulzweida committed
378
            fprintf(stdout, "          : points=%d (%dx%d)\n", gridsize, xsize, ysize);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
379
380
	}

381
      if ( gridtype == GRID_CURVILINEAR || gridtype == GRID_UNSTRUCTURED || gridtype == GRID_LCC )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
382
383
384
385
386
387
388
389
390
391
392
	{
	  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
393
	      if ( gridInqMask(gridID, NULL) )    fprintf(stdout, " mask");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
394
395
396
	      fprintf(stdout, "\n");
	    }
	}
397
398
399
400
401
402
403
404
405
406
407
408

      gridInqUUID(gridID, uuidOfHGrid);
      if ( uuidOfHGrid[0] != 0 )
        {
          char uuidOfHGridStr[37];
          uuid2str(uuidOfHGrid, uuidOfHGridStr);
          if ( uuidOfHGridStr[0] != 0  && strlen(uuidOfHGridStr) == 36 )
            {
	      fprintf(stdout, "%*s", nbyte0, "");
	      fprintf(stdout, "uuid      : %s\n", uuidOfHGridStr);
            }
        }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
409
410
    }
}
411
412
413
414
415
416
417
418
419
/*
 * Local Variables:
 * c-file-style: "Java"
 * c-basic-offset: 2
 * indent-tabs-mode: nil
 * show-trailing-whitespace: t
 * require-trailing-newline: t
 * End:
 */