printinfo.h 18.6 KB
Newer Older
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1
2
// This file is used in CDI and CDO !!!

3
4
5
#define DATE_FORMAT "%5.4d-%2.2d-%2.2d"
#define TIME_FORMAT "%2.2d:%2.2d:%2.2d"

6
void uuid2str(const unsigned char uuid[CDI_UUID_SIZE], char *uuidstr);
7

Uwe Schulzweida's avatar
Uwe Schulzweida committed
8
9
10
static inline
int cdiUUIDIsNull(const unsigned char uuid[CDI_UUID_SIZE])
{
11
12
13
14
  int isNull = 1;
  for (size_t i = 0; i < CDI_UUID_SIZE; ++i)
    isNull &= (uuid[i] == 0);
  return isNull;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
15
16
17
}


Uwe Schulzweida's avatar
Uwe Schulzweida committed
18
19
20
21
22
23
24
25
26
27
28
29
30
31
void datetime2str(int date, int time, char *datetimestr, int maxlen)
{
  int year, month, day;
  cdiDecodeDate(date, &year, &month, &day);
  int hour, minute, second;
  cdiDecodeTime(time, &hour, &minute, &second);

  int len = sprintf(datetimestr, DATE_FORMAT "T" TIME_FORMAT, year, month, day, hour, minute, second);
  if ( len > ( maxlen-1) )
    fprintf(stderr, "Internal problem (%s): sizeof input string is too small!\n", __func__);
}


void date2str(int date, char *datestr, int maxlen)
32
33
34
35
{
  int year, month, day;
  cdiDecodeDate(date, &year, &month, &day);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
36
  int len = sprintf(datestr, DATE_FORMAT, year, month, day);
37
  if ( len > ( maxlen-1) )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
38
    fprintf(stderr, "Internal problem (%s): sizeof input string is too small!\n", __func__);
39
40
41
}


Uwe Schulzweida's avatar
Uwe Schulzweida committed
42
void time2str(int time, char *timestr, int maxlen)
43
44
45
46
{
  int hour, minute, second;
  cdiDecodeTime(time, &hour, &minute, &second);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
47
  int len = sprintf(timestr, TIME_FORMAT, hour, minute, second);
48
  if ( len > ( maxlen-1) )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
49
    fprintf(stderr, "Internal problem (%s): sizeof input string is too small!\n", __func__);
50
51
52
}


Uwe Schulzweida's avatar
Uwe Schulzweida committed
53
void printFiletype(int streamID, int vlistID)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
54
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
55
  int filetype = streamInqFiletype(streamID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73

  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;
74
75
76
    case FILETYPE_NC4C:
      printf("netCDF4 classic");
      break;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
77
78
79
80
81
82
83
84
85
86
87
    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);
88
      break;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
    }

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

104
  if ( filetype == FILETYPE_GRB || filetype == FILETYPE_NC4 || filetype == FILETYPE_NC4C )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
105
106
    {
      int nvars, varID;
107
      int comptype;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
108
109
110
111
112

      nvars = vlistNvars(vlistID);

      for ( varID = 0; varID < nvars; varID++ )
	{
113
114
	  comptype = vlistInqVarCompType(vlistID, varID);
	  if ( comptype )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
115
	    {
116
	      if ( comptype == COMPRESS_SZIP )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
117
		printf(" SZIP");
118
	      else if ( comptype == COMPRESS_ZIP )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
119
120
121
122
123
124
125
		printf(" ZIP");

	      break;
	    }
	}
    }

126
127
  if ( filetype == FILETYPE_GRB2 )
    {
128
      int comptype;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
129
130
      int nvars = vlistNvars(vlistID);
      for ( int varID = 0; varID < nvars; varID++ )
131
	{
132
133
	  comptype = vlistInqVarCompType(vlistID, varID);
	  if ( comptype )
134
	    {
135
	      if ( comptype == COMPRESS_JPEG )
136
137
138
139
140
141
142
		printf(" JPEG");

	      break;
	    }
	}
    }

Uwe Schulzweida's avatar
Uwe Schulzweida committed
143
144
145
  printf("\n");
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
146
147
static
void printGridInfo(int vlistID)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
148
149
{
  int ngrids, index;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
150
  int gridID, gridtype, trunc, gridsize, xsize, ysize, xysize;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
151
  char xname[CDI_MAX_NAME], yname[CDI_MAX_NAME], xunits[CDI_MAX_NAME], yunits[CDI_MAX_NAME];
152
  unsigned char uuidOfHGrid[CDI_UUID_SIZE];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
153
154
155
156
157
158
159
160
161
162

  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
163
      xysize   = xsize*ysize;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
164
165
166
167
168
      gridInqXname(gridID, xname);
      gridInqYname(gridID, yname);
      gridInqXunits(gridID, xunits);
      gridInqYunits(gridID, yunits);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
169
      fprintf(stdout, "  %4d : %-24s", index+1, gridNamePtr(gridtype));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
170
171
172
173
174

      if ( gridtype == GRID_LONLAT   ||
	   gridtype == GRID_LCC2 ||
	   gridtype == GRID_LAEA ||
	   gridtype == GRID_SINUSOIDAL ||
175
	   gridtype == GRID_GENERIC ||
Uwe Schulzweida's avatar
Uwe Schulzweida committed
176
177
178
	   gridtype == GRID_GAUSSIAN ||
	   gridtype == GRID_GAUSSIAN_REDUCED )
	{
179
          int lxcoord = 1, lycoord = 1;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
180
181
182
	  double xfirst = 0.0, xlast = 0.0;
	  double yfirst = 0.0, ylast = 0.0;
	  double xinc = 0.0, yinc = 0.0;
183

Uwe Schulzweida's avatar
Uwe Schulzweida committed
184
185
186
	  yfirst = gridInqYval(gridID, 0);
	  ylast  = gridInqYval(gridID, ysize-1);
	  yinc   = gridInqYinc(gridID);
187

Uwe Schulzweida's avatar
Uwe Schulzweida committed
188
          fprintf(stdout, " : points=%d", gridsize);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
189
	  if ( gridtype == GRID_GAUSSIAN_REDUCED )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
190
191
192
	    fprintf(stdout, "  nlat=%d", ysize);
	  else if ( xysize )
	    fprintf(stdout, " (%dx%d)", xsize, ysize);
193

Uwe Schulzweida's avatar
Uwe Schulzweida committed
194
	  if ( gridtype == GRID_GAUSSIAN || gridtype == GRID_GAUSSIAN_REDUCED )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
195
	    fprintf(stdout, "  np=%d", gridInqNP(gridID));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
196
197

	  fprintf(stdout, "\n");
198

199
200
201
202
          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
203
	    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
204
205
206
207
208
209
210
211
212
213
214
215
216
              xfirst = gridInqXval(gridID, 0);
              xlast  = gridInqXval(gridID, xsize-1);
              xinc   = gridInqXinc(gridID);
              fprintf(stdout, "%33s : %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);
              if ( gridIsCircular(gridID) ) fprintf(stdout, "  circular");
              fprintf(stdout, "\n");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
217
	    }
218

219
	  if ( ysize > 0 && lycoord )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
220
	    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
221
	      fprintf(stdout, "%33s : %g", yname, yfirst);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
222
223
224
225
226
227
228
	      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
229
230
	      fprintf(stdout, "\n");
	    }
231

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
243
244
	  if ( gridInqXbounds(gridID, NULL) || gridInqYbounds(gridID, NULL) )
	    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
245
	      fprintf(stdout, "%33s :", "available");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
246
	      if ( gridInqXbounds(gridID, NULL) && gridInqYbounds(gridID, NULL) ) fprintf(stdout, " cellbounds");
247
	      if ( gridHasArea(gridID) )          fprintf(stdout, " area");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
248
	      if ( gridInqMask(gridID, NULL) )    fprintf(stdout, " mask");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
249
250
	      fprintf(stdout, "\n");
	    }
251

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

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

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

          fprintf(stdout, "\n");

          if ( gridtype == GRID_UNSTRUCTURED )
            {
298
299
300
              int number   = gridInqNumber(gridID);
              int position = gridInqPosition(gridID);

301
302
              if ( number > 0 )
                {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
303
                  fprintf(stdout, "%33s : number=%d  position=%d\n", "grid", number, position);
304
305
306
307
308
309
                }

              if ( gridInqReference(gridID, NULL) )
                {
                  char reference_link[8192];
                  gridInqReference(gridID, reference_link);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
310
                  fprintf(stdout, "%33s : %s\n", "uri", reference_link);
311
312
                }
            }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
313
314
315
316
317
318

	  if ( gridInqXvals(gridID, NULL) && gridInqYvals(gridID, NULL) )
	    {
	      int i;
	      double *xvals, *yvals;
	      double xfirst, xlast, yfirst, ylast;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
319
320
	      xvals = (double*) malloc((size_t)gridsize*sizeof(double));
	      yvals = (double*) malloc((size_t)gridsize*sizeof(double));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
321
322
323
324
325
326
327
328
329
330
331

	      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
332
		  if ( xvals[i] > xlast  ) xlast  = xvals[i];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
333
		  if ( yvals[i] < yfirst ) yfirst = yvals[i];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
334
		  if ( yvals[i] > ylast  ) ylast  = yvals[i];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
335
336
		}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
337
	      fprintf(stdout, "%33s : %g to %g %s", xname, xfirst, xlast, xunits);
338
	      if ( gridIsCircular(gridID) ) fprintf(stdout, "  circular");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
339
	      fprintf(stdout, "\n");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
340
	      fprintf(stdout, "%33s : %g to %g %s\n", yname, yfirst, ylast, yunits);
341

Uwe Schulzweida's avatar
Uwe Schulzweida committed
342
343
344
345
346
347
348
349
350
351
352
353
	      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
354
	  fprintf(stdout, " : points=%d (%dx%d)  ", gridsize, xsize, ysize);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
355
356
357
358
	  if ( (projflag&128) == 0 )
	    fprintf(stdout, "North Pole\n");
	  else
	    fprintf(stdout, "South Pole\n");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
359
360
361

	  fprintf(stdout, "%33s : originLon=%g  originLat=%g  lonParY=%g\n", " ", originLon, originLat, lonParY);
	  fprintf(stdout, "%33s : lat1=%g  lat2=%g  xinc=%g m  yinc=%g m\n", " ", lat1, lat2, xincm, yincm);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
362
363
364
365
	}
      else /* if ( gridtype == GRID_GENERIC ) */
	{
	  if ( ysize == 0 )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
366
	    fprintf(stdout, " : points=%d\n", gridsize);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
367
	  else
Uwe Schulzweida's avatar
Uwe Schulzweida committed
368
            fprintf(stdout, " : points=%d (%dx%d)\n", gridsize, xsize, ysize);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
369
370
	}

371
      if ( gridtype == GRID_CURVILINEAR || gridtype == GRID_UNSTRUCTURED || gridtype == GRID_LCC )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
372
	{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
373
	  if ( gridHasArea(gridID) ||
Uwe Schulzweida's avatar
Uwe Schulzweida committed
374
375
	       gridInqXbounds(gridID, NULL) || gridInqYbounds(gridID, NULL) )
	    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
376
	      fprintf(stdout, "%33s :", "available");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
377
	      if ( gridInqXbounds(gridID, NULL) && gridInqYbounds(gridID, NULL) ) fprintf(stdout, " cellbounds");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
378
	      if ( gridHasArea(gridID) )          fprintf(stdout, " area");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
379
	      if ( gridInqMask(gridID, NULL) )    fprintf(stdout, " mask");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
380
381
382
	      fprintf(stdout, "\n");
	    }
	}
383
384

      gridInqUUID(gridID, uuidOfHGrid);
Thomas Jahns's avatar
Thomas Jahns committed
385
      if ( !cdiUUIDIsNull(uuidOfHGrid) )
386
387
388
389
390
        {
          char uuidOfHGridStr[37];
          uuid2str(uuidOfHGrid, uuidOfHGridStr);
          if ( uuidOfHGridStr[0] != 0  && strlen(uuidOfHGridStr) == 36 )
            {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
391
392
393
394
395
396
397
398
399
400
401
402
403
404
	      fprintf(stdout, "%33s : %s\n", "uuid", uuidOfHGridStr);
            }
        }
    }
}

static
void printZaxisInfo(int vlistID)
{
  int zaxisID, zaxistype, levelsize, levelID;
  int ltype;
  double *levels = NULL;
  char zaxisname[CDI_MAX_NAME], zname[CDI_MAX_NAME], zunits[CDI_MAX_NAME];

405
406
  int nzaxis = vlistNzaxis(vlistID);
  for ( int index = 0; index < nzaxis; index++)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
    {
      double zfirst = 0, zlast = 0, zinc = 0;
      zaxisID   = vlistZaxis(vlistID, index);
      zaxistype = zaxisInqType(zaxisID);
      ltype     = zaxisInqLtype(zaxisID);
      levelsize = zaxisInqSize(zaxisID);
      zaxisName(zaxistype, zaxisname);
      zaxisInqName(zaxisID, zname);
      zaxisInqUnits(zaxisID, zunits);
      zunits[12] = 0;

      if ( zaxistype == ZAXIS_GENERIC && ltype != 0 )
        fprintf(stdout, "  %4d : %-12s (ltype=%3d) :", vlistZaxisIndex(vlistID, zaxisID)+1, zaxisname, ltype);
      else
        fprintf(stdout, "  %4d : %-24s :", vlistZaxisIndex(vlistID, zaxisID)+1, zaxisname);

      fprintf(stdout, " levels=%d", levelsize);
      fprintf(stdout, "\n");

Uwe Schulzweida's avatar
Uwe Schulzweida committed
426
      levels = (double*) malloc((size_t)levelsize*sizeof(double));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
      zaxisInqLevels(zaxisID, levels);

      if ( !(zaxistype == ZAXIS_SURFACE && levelsize == 1 && !(fabs(levels[0]) > 0)) )
        {
          zfirst = levels[0];
          zlast  = levels[levelsize-1];
          if ( levelsize > 2 )
            {
              zinc = (levels[levelsize-1] - levels[0]) / (levelsize-1);
              for ( levelID = 2; levelID < levelsize; ++levelID )
                if ( fabs(fabs(levels[levelID] - levels[levelID-1]) - zinc) > 0.001*zinc ) break;

              if ( levelID < levelsize ) zinc = 0;
            }

          fprintf(stdout, "%33s : %g", zname, zfirst);
          if ( levelsize > 1 )
            {
              fprintf(stdout, " to %g", zlast);
              if ( IS_NOT_EQUAL(zinc, 0) )
                fprintf(stdout, " by %g", zinc);
            }
          fprintf(stdout, " %s", zunits);
          fprintf(stdout, "\n");
        }

      free(levels);

      if ( zaxisInqLbounds(zaxisID, NULL) && zaxisInqUbounds(zaxisID, NULL) )
        {
          double level1, level2;
          fprintf(stdout, "%33s : ", "bounds");

          level1 = zaxisInqLbound(zaxisID, 0);
          level2 = zaxisInqUbound(zaxisID, 0);
          fprintf(stdout, "%.9g-%.9g", level1, level2);
          if ( levelsize > 1 )
            {
              level1 = zaxisInqLbound(zaxisID, levelsize-1);
              level2 = zaxisInqUbound(zaxisID, levelsize-1);
              fprintf(stdout, " to %.9g-%.9g", level1, level2);
              if ( IS_NOT_EQUAL(zinc, 0) )
                fprintf(stdout, " by %g", zinc);
470
            }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
471
472
          fprintf(stdout, " %s", zunits);
          fprintf(stdout, "\n");
473
        }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
474

Uwe Schulzweida's avatar
Uwe Schulzweida committed
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
      if ( zaxistype == ZAXIS_HYBRID )
        {
          char psname[CDI_MAX_NAME];
          psname[0] = 0;
          zaxisInqPsName(zaxisID, psname);
          int vctsize = zaxisInqVctSize(zaxisID);
          if ( vctsize || psname[0] )
            {
	      fprintf(stdout, "%33s :", "available");
              if ( vctsize   ) fprintf(stdout, " vct");
              if ( psname[0] ) fprintf(stdout, "  ps: %s", psname);
              fprintf(stdout, "\n");
            }
        }

Uwe Schulzweida's avatar
Uwe Schulzweida committed
490
491
492
493
494
495
496
497
498
499
      if ( zaxistype == ZAXIS_REFERENCE )
        {
          int number   = zaxisInqNumber(zaxisID);

          if ( number > 0 )
            {
              fprintf(stdout, "%33s : ", "zaxis");
              fprintf(stdout, "number = %d\n", number);
            }

500
          unsigned char uuidOfVGrid[CDI_UUID_SIZE];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
501
          zaxisInqUUID(zaxisID, uuidOfVGrid);
Thomas Jahns's avatar
Thomas Jahns committed
502
          if ( !cdiUUIDIsNull(uuidOfVGrid) )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
503
504
505
506
507
508
509
510
511
512
513
514
515
            {
              char uuidOfVGridStr[37];
              uuid2str(uuidOfVGrid, uuidOfVGridStr);
              if ( uuidOfVGridStr[0] != 0  && strlen(uuidOfVGridStr) == 36 )
                {
                  fprintf(stdout, "%33s : ", "uuid");
                  fprintf(stdout, "%s\n", uuidOfVGridStr);
                }
            }
        }
    }
}

516
517
518
519
520
521
522
523
524
525
526
527
528
529
static
void printSubtypeInfo(int vlistID)
{
  int nsubtypes = vlistNsubtypes(vlistID);
  for ( int index = 0; index < nsubtypes; index++)
    {
      int subtypeID = vlistSubtype(vlistID, index);
      int subtypesize = subtypeInqSize(subtypeID);
      // subtypePrint(subtypeID);
      fprintf(stdout, "  %4d : %-24s :", vlistSubtypeIndex(vlistID, subtypeID)+1, "tiles");
      fprintf(stdout, " ntiles=%d", subtypesize);
      fprintf(stdout, "\n");
    }
}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573

static
int printDateTime(int ntimeout, int vdate, int vtime)
{
  char vdatestr[32], vtimestr[32];

  if ( ntimeout == 4 )
    {
      ntimeout = 0;
      fprintf(stdout, "\n");
    }

  date2str(vdate, vdatestr, sizeof(vdatestr));
  time2str(vtime, vtimestr, sizeof(vtimestr));

  fprintf(stdout, " %s %s", vdatestr, vtimestr);

  return (++ntimeout);
}

#define NUM_TIMESTEP 60
#define MAX_DOTS     80

static
int printDot(int ndotout, int *nfact, int *ncout)
{
  //printf("ncout %d %d %d\n",*ncout, (*ncout)%(*nfact), *nfact);
  if ( (*ncout)%(*nfact) == 0 )
    {
      if ( ndotout == MAX_DOTS )
	{
	  *ncout = 0;
	  ndotout = 0;
	  fprintf(stdout, "\n   ");
	  (*nfact) *= 10;
	}

      fprintf(stdout, ".");
      fflush(stdout);
      ndotout++;
    }

  (*ncout)++;

Uwe Schulzweida's avatar
Uwe Schulzweida committed
574
  return ndotout;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
575
576
577
}

static
578
void printTimesteps(int streamID, int taxisID, int verbose)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
{
  int nrecs;
  int vdate, vtime;
  struct datetime {
    int vdate;
    int vtime;
    struct datetime *next;
  };
  struct datetime vdatetime[NUM_TIMESTEP];
  struct datetime *next_vdatetime = vdatetime;

  for ( int i = 0; i < NUM_TIMESTEP-1; ++i ) vdatetime[i].next = &vdatetime[i+1];
  vdatetime[NUM_TIMESTEP-1].next = &vdatetime[0];

  int ntimeout = 0;
  int ndotout = 0;
  int nvdatetime = 0;
  int ncout = 0;
  int nfact = 1;
  int tsID = 0;
599

Uwe Schulzweida's avatar
Uwe Schulzweida committed
600
601
602
603
604
  while ( (nrecs = streamInqTimestep(streamID, tsID)) )
    {
      vdate = taxisInqVdate(taxisID);
      vtime = taxisInqVtime(taxisID);

605
      if ( verbose || tsID < NUM_TIMESTEP )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
	{
	  ntimeout = printDateTime(ntimeout, vdate, vtime);
	}
      else
	{
	  if ( tsID == 2*NUM_TIMESTEP ) fprintf(stdout, "\n   ");
	  if ( tsID >= 2*NUM_TIMESTEP ) ndotout = printDot(ndotout, &nfact, &ncout);

	  if ( nvdatetime < NUM_TIMESTEP )
	    {
	      vdatetime[nvdatetime].vdate = vdate;
	      vdatetime[nvdatetime].vtime = vtime;
	      nvdatetime++;
	    }
	  else
	    {
	      next_vdatetime->vdate = vdate;
	      next_vdatetime->vtime = vtime;
	      next_vdatetime = next_vdatetime->next;
	    }
	}

      tsID++;
    }

  if ( nvdatetime )
    {
      fprintf(stdout, "\n");

      ntimeout = 0;
      int toff = tsID%4;
      if ( toff > 0 ) toff = 4 - toff;
      for ( int i = 0; i < toff; ++i ) next_vdatetime = next_vdatetime->next;

      for ( int i = toff; i < nvdatetime; ++i )
	{
	  vdate = next_vdatetime->vdate;
	  vtime = next_vdatetime->vtime;
	  ntimeout = printDateTime(ntimeout, vdate, vtime);
	  next_vdatetime = next_vdatetime->next;
	}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
647
648
    }
}
649
650
651
652
653
654
655
656
657
/*
 * Local Variables:
 * c-file-style: "Java"
 * c-basic-offset: 2
 * indent-tabs-mode: nil
 * show-trailing-whitespace: t
 * require-trailing-newline: t
 * End:
 */