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

3
#if defined (HAVE_CONFIG_H)
4
#include "../src/config.h"
5
6
7
8
#endif

#include <stdio.h>

9
10
11
12
13
14
#ifdef CDO
#define  streamInqFiletype        pstreamInqFiletype
#define  streamInqByteorder       pstreamInqByteorder
#define  streamInqTimestep        pstreamInqTimestep
#endif

15
16
17
#define DATE_FORMAT "%5.4d-%2.2d-%2.2d"
#define TIME_FORMAT "%2.2d:%2.2d:%2.2d"

Uwe Schulzweida's avatar
Uwe Schulzweida committed
18
19
void my_reset_text_color(FILE *fp)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
20
  (void)fp;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
21
22
23
24
25
#ifdef CDO
  reset_text_color(fp);
#endif
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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)
40
41
42
43
{
  int year, month, day;
  cdiDecodeDate(date, &year, &month, &day);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
44
  int len = sprintf(datestr, DATE_FORMAT, year, month, day);
45
  if ( len > ( maxlen-1) )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
46
    fprintf(stderr, "Internal problem (%s): sizeof input string is too small!\n", __func__);
47
48
49
}


Uwe Schulzweida's avatar
Uwe Schulzweida committed
50
void time2str(int time, char *timestr, int maxlen)
51
52
53
54
{
  int hour, minute, second;
  cdiDecodeTime(time, &hour, &minute, &second);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
55
  int len = sprintf(timestr, TIME_FORMAT, hour, minute, second);
56
  if ( len > ( maxlen-1) )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
57
    fprintf(stderr, "Internal problem (%s): sizeof input string is too small!\n", __func__);
58
59
60
}


Uwe Schulzweida's avatar
Uwe Schulzweida committed
61
void printFiletype(int streamID, int vlistID)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
62
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
63
  int filetype = streamInqFiletype(streamID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
64
65
66

  switch ( filetype )
    {
67
    case CDI_FILETYPE_GRB:
Uwe Schulzweida's avatar
Uwe Schulzweida committed
68
69
      printf("GRIB");
      break;
70
    case CDI_FILETYPE_GRB2:
Uwe Schulzweida's avatar
Uwe Schulzweida committed
71
72
      printf("GRIB2");
      break;
73
    case CDI_FILETYPE_NC:
74
      printf("NetCDF");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
75
      break;
76
    case CDI_FILETYPE_NC2:
77
      printf("NetCDF2");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
78
      break;
79
    case CDI_FILETYPE_NC4:
80
      printf("NetCDF4");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
81
      break;
82
    case CDI_FILETYPE_NC4C:
83
      printf("NetCDF4 classic");
84
      break;
85
    case CDI_FILETYPE_SRV:
Uwe Schulzweida's avatar
Uwe Schulzweida committed
86
87
      printf("SERVICE");
      break;
88
    case CDI_FILETYPE_EXT:
Uwe Schulzweida's avatar
Uwe Schulzweida committed
89
90
      printf("EXTRA");
      break;
91
    case CDI_FILETYPE_IEG:
Uwe Schulzweida's avatar
Uwe Schulzweida committed
92
93
94
95
      printf("IEG");
      break;
    default:
      printf("  File format: unsupported filetype %d" , filetype);
96
      break;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
97
98
    }

99
  if ( filetype == CDI_FILETYPE_SRV || filetype == CDI_FILETYPE_EXT || filetype == CDI_FILETYPE_IEG )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
100
101
102
103
104
105
106
107
108
109
110
111
    {
      switch ( streamInqByteorder(streamID) )
	{
	case CDI_BIGENDIAN:
	  printf("  BIGENDIAN"); break;
	case CDI_LITTLEENDIAN:
	  printf("  LITTLEENDIAN"); break;
	default:
	  printf("  byteorder: %d undefined", streamInqByteorder(streamID)); break;
	}
    }

112
  if ( filetype == CDI_FILETYPE_GRB || filetype == CDI_FILETYPE_NC4 || filetype == CDI_FILETYPE_NC4C )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
113
    {
114
115
      int nvars = vlistNvars(vlistID);
      for ( int varID = 0; varID < nvars; varID++ )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
116
	{
117
	  int comptype = vlistInqVarCompType(vlistID, varID);
118
	  if ( comptype )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
119
	    {
120
121
	      if      ( comptype == CDI_COMPRESS_SZIP ) printf(" SZIP");
	      else if ( comptype == CDI_COMPRESS_ZIP  ) printf(" ZIP");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
122
123
124
125
126
127

	      break;
	    }
	}
    }

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

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

145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
static
void print_xvals(int gridID, int dig)
{
  int xsize = gridInqXsize(gridID);
  if ( xsize > 0 && gridInqXvals(gridID, NULL) )
    {
      char xname[CDI_MAX_NAME], xunits[CDI_MAX_NAME];
      gridInqXname(gridID, xname);
      gridInqXunits(gridID, xunits);

      double xfirst = gridInqXval(gridID, 0);
      double xlast  = gridInqXval(gridID, xsize-1);
      double xinc   = gridInqXinc(gridID);
      fprintf(stdout, "%33s : %.*g", xname, dig, xfirst);
      if ( xsize > 1 )
        {
          fprintf(stdout, " to %.*g", dig, xlast);
          if ( IS_NOT_EQUAL(xinc, 0) )
            fprintf(stdout, " by %.*g", dig, xinc);
        }
      fprintf(stdout, " %s", xunits);
      if ( gridIsCircular(gridID) ) fprintf(stdout, "  circular");
      fprintf(stdout, "\n");
    }
}

static
void print_yvals(int gridID, int dig)
{
  int ysize = gridInqYsize(gridID);
  if ( ysize > 0 && gridInqYvals(gridID, NULL) )
    {
      char yname[CDI_MAX_NAME], yunits[CDI_MAX_NAME];
      gridInqYname(gridID, yname);
      gridInqYunits(gridID, yunits);

      double yfirst = gridInqYval(gridID, 0);
      double ylast  = gridInqYval(gridID, ysize-1);
      double yinc   = gridInqYinc(gridID);
      fprintf(stdout, "%33s : %.*g", yname, dig, yfirst);
      if ( ysize > 1 )
        {
          int gridtype = gridInqType(gridID);
          fprintf(stdout, " to %.*g", dig, ylast);
          if ( IS_NOT_EQUAL(yinc, 0) && gridtype != GRID_GAUSSIAN && gridtype != GRID_GAUSSIAN_REDUCED )
            fprintf(stdout, " by %.*g", dig, yinc);
        }
      fprintf(stdout, " %s", yunits);
      fprintf(stdout, "\n");
    }
}

static
void print_xyvals2D(int gridID, int dig)
{
  if ( gridInqXvals(gridID, NULL) && gridInqYvals(gridID, NULL) )
    {
      char xname[CDI_MAX_NAME], yname[CDI_MAX_NAME], xunits[CDI_MAX_NAME], yunits[CDI_MAX_NAME];
      gridInqXname(gridID, xname);
      gridInqYname(gridID, yname);
      gridInqXunits(gridID, xunits);
      gridInqYunits(gridID, yunits);

208
209
210
      size_t gridsize = gridInqSize(gridID);
      double *xvals2D = (double*) malloc(gridsize*sizeof(double));
      double *yvals2D = (double*) malloc(gridsize*sizeof(double));
211
212
213
214
215
216
217
218

      gridInqXvals(gridID, xvals2D);
      gridInqYvals(gridID, yvals2D);

      double xfirst = xvals2D[0];
      double xlast  = xvals2D[0];
      double yfirst = yvals2D[0];
      double ylast  = yvals2D[0];
219
      for ( size_t i = 1; i < gridsize; i++ )
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
        {
          if ( xvals2D[i] < xfirst ) xfirst = xvals2D[i];
          if ( xvals2D[i] > xlast  ) xlast  = xvals2D[i];
          if ( yvals2D[i] < yfirst ) yfirst = yvals2D[i];
          if ( yvals2D[i] > ylast  ) ylast  = yvals2D[i];
        }

      double xinc = 0;
      double yinc = 0;
      int gridtype = gridInqType(gridID);
      if ( gridtype == GRID_CURVILINEAR )
        {
          int xsize = gridInqXsize(gridID);
          if ( xsize > 1 )
            {
Thomas Jahns's avatar
Thomas Jahns committed
235
              double *xvals = (double*) malloc((size_t)xsize*sizeof(double));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
236
              for ( int i = 0; i < xsize; ++i ) xvals[i] = xvals2D[i];
237
238
239
              xinc = fabs(xvals[xsize-1] - xvals[0])/(xsize-1);
              for ( int i = 2; i < xsize; i++ )
                if ( fabs(fabs(xvals[i-1] - xvals[i]) - xinc) > 0.01*xinc ) { xinc = 0; break; }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
240
              free(xvals);
241
            }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
242
          int ysize = gridInqYsize(gridID);
243
244
          if ( ysize > 1 )
            {
Thomas Jahns's avatar
Thomas Jahns committed
245
              double *yvals = (double*) malloc((size_t)ysize*sizeof(double));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
246
              for ( int i = 0; i < ysize; ++i ) yvals[i] = yvals2D[i*xsize];
247
248
249
              yinc = fabs(yvals[ysize-1] - yvals[0])/(ysize-1);
              for ( int i = 2; i < ysize; i++ )
                if ( fabs(fabs(yvals[i-1] - yvals[i]) - yinc) > 0.01*yinc ) { yinc = 0; break; }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
250
              free(yvals);
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
            }
        }

      fprintf(stdout, "%33s : %.*g to %.*g", xname, dig, xfirst, dig, xlast);
      if ( IS_NOT_EQUAL(xinc, 0) )
        fprintf(stdout, " by %.*g", dig, xinc);
      fprintf(stdout, " %s", xunits);
      if ( gridIsCircular(gridID) ) fprintf(stdout, "  circular");
      fprintf(stdout, "\n");
      fprintf(stdout, "%33s : %.*g to %.*g", yname, dig, yfirst, dig, ylast);
      if ( IS_NOT_EQUAL(yinc, 0) )
        fprintf(stdout, " by %.*g", dig, yinc);
      fprintf(stdout, " %s", xunits);
      fprintf(stdout, "\n");

      free(xvals2D);
      free(yvals2D);
    }
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
271
static
Uwe Schulzweida's avatar
Uwe Schulzweida committed
272
void printGridInfoKernel(int gridID, int index, bool lproj)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
273
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
274
275
276
277
278
279
  int gridtype = gridInqType(gridID);

  if ( lproj && gridtype != GRID_PROJECTION )
    fprintf(stderr, "Internal problem (%s): sub grid not equal GRID_PROJECTION!\n", __func__);

  int trunc    = gridInqTrunc(gridID);
280
281
282
283
  size_t gridsize = gridInqSize(gridID);
  size_t xsize    = gridInqXsize(gridID);
  size_t ysize    = gridInqYsize(gridID);
  size_t xysize   = xsize*ysize;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
284

Uwe Schulzweida's avatar
Uwe Schulzweida committed
285
  // int prec     = gridInqPrec(gridID);
286
  // int dig = (prec == CDI_DATATYPE_FLT64) ? 15 : 7;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
287
  int dig = 7;
288
289
290
291
#ifdef CDO
  extern int CDO_flt_digits;
  dig = CDO_flt_digits;
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
292

Uwe Schulzweida's avatar
Uwe Schulzweida committed
293
  if ( !lproj )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
294
295
    {
      fprintf(stdout, "  %4d : ", index+1);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
296
297
298
#ifdef CDO
      set_text_color(stdout, RESET, BLUE);
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
299
300
301
302
      fprintf(stdout, "%-24s", gridNamePtr(gridtype));
      my_reset_text_color(stdout);
      fprintf(stdout, " : ");
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
303

Uwe Schulzweida's avatar
Uwe Schulzweida committed
304
305
306
  if ( gridtype == GRID_LONLAT     ||
       gridtype == GRID_PROJECTION ||
       gridtype == GRID_GENERIC    ||
307
       gridtype == GRID_CHARXY    ||
Uwe Schulzweida's avatar
Uwe Schulzweida committed
308
       gridtype == GRID_GAUSSIAN   ||
Uwe Schulzweida's avatar
Uwe Schulzweida committed
309
       gridtype == GRID_GAUSSIAN_REDUCED )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
310
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
311
312
      if ( !lproj )
        {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
313
314
315
#ifdef CDO
          set_text_color(stdout, RESET, GREEN);
#endif
316
          fprintf(stdout, "points=%zu", gridsize);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
317
          if ( gridtype == GRID_GAUSSIAN_REDUCED )
318
            fprintf(stdout, "  nlat=%zu", ysize);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
319
          else if ( xysize )
320
            fprintf(stdout, " (%zux%zu)", xsize, ysize);
321

Uwe Schulzweida's avatar
Uwe Schulzweida committed
322
323
          if ( gridtype == GRID_GAUSSIAN || gridtype == GRID_GAUSSIAN_REDUCED )
            fprintf(stdout, "  np=%d", gridInqNP(gridID));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
324
          my_reset_text_color(stdout);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
325

Uwe Schulzweida's avatar
Uwe Schulzweida committed
326
327
328
329
          fprintf(stdout, "\n");
        }

      char name[CDI_MAX_NAME]; name[0] = 0;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
330
      cdiGridInqKeyStr(gridID, CDI_KEY_MAPNAME, CDI_MAX_NAME, name);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
331
332
333
      if ( gridtype == GRID_PROJECTION || name[0] )
        {
          if ( name[0] == 0 ) strcpy(name, "undefined");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
334
335
336
#ifdef CDO
          set_text_color(stdout, RESET, BLUE);
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
337
          fprintf(stdout, "         %24s", "mapping");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
338
339
          my_reset_text_color(stdout);
          fprintf(stdout, " : ");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
340
341
342
#ifdef CDO
          set_text_color(stdout, RESET, GREEN);
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
343
344
          fprintf(stdout, "%s\n", name);
          my_reset_text_color(stdout);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
345
        }
346

Uwe Schulzweida's avatar
Uwe Schulzweida committed
347
348
      print_xvals(gridID, dig);
      print_yvals(gridID, dig);
349

Uwe Schulzweida's avatar
Uwe Schulzweida committed
350
351
352
353
354
355
356
357
358
359
360
      if ( gridInqXbounds(gridID, NULL) || gridInqYbounds(gridID, NULL) )
        {
          fprintf(stdout, "%33s :", "available");
          if ( gridInqXbounds(gridID, NULL) && gridInqYbounds(gridID, NULL) ) fprintf(stdout, " cellbounds");
          if ( gridHasArea(gridID) )          fprintf(stdout, " area");
          if ( gridInqMask(gridID, NULL) )    fprintf(stdout, " mask");
          fprintf(stdout, "\n");
        }
    }
  else if ( gridtype == GRID_SPECTRAL )
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
361
362
363
#ifdef CDO
      set_text_color(stdout, RESET, GREEN);
#endif
364
      fprintf(stdout, "points=%zu  nsp=%zu  truncation=%d", gridsize, gridsize/2, trunc);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
365
      if ( gridInqComplexPacking(gridID) ) fprintf(stdout, "  complexPacking");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
366
      my_reset_text_color(stdout);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
367
368
369
370
      fprintf(stdout, "\n");
    }
  else if ( gridtype == GRID_FOURIER )
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
371
372
373
#ifdef CDO
      set_text_color(stdout, RESET, GREEN);
#endif
374
      fprintf(stdout, "points=%zu  nfc=%zu  truncation=%d\n", gridsize, gridsize/2, trunc);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
375
      my_reset_text_color(stdout);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
376
377
378
    }
  else if ( gridtype == GRID_GME )
    {
379
380
      int nd, ni, ni2, ni3;
      gridInqParamGME(gridID, &nd, &ni, &ni2, &ni3);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
381
382
383
#ifdef CDO
      set_text_color(stdout, RESET, GREEN);
#endif
384
      fprintf(stdout, "points=%zu  nd=%d  ni=%d\n", gridsize, nd, ni);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
385
      my_reset_text_color(stdout);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
386
387
388
    }
  else if ( gridtype == GRID_CURVILINEAR || gridtype == GRID_UNSTRUCTURED )
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
389
390
391
#ifdef CDO
      set_text_color(stdout, RESET, GREEN);
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
392
      if ( gridtype == GRID_CURVILINEAR )
393
        fprintf(stdout, "points=%zu (%zux%zu)", gridsize, xsize, ysize);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
394
      else
395
        fprintf(stdout, "points=%zu", gridsize);
396

Uwe Schulzweida's avatar
Uwe Schulzweida committed
397
398
      if ( gridtype == GRID_UNSTRUCTURED && gridInqNvertex(gridID) > 0 )
        fprintf(stdout, "  nvertex=%d", gridInqNvertex(gridID));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
399
      my_reset_text_color(stdout);
400

Uwe Schulzweida's avatar
Uwe Schulzweida committed
401
      fprintf(stdout, "\n");
402

Uwe Schulzweida's avatar
Uwe Schulzweida committed
403
404
405
406
407
408
409
410
      if ( gridtype == GRID_UNSTRUCTURED )
        {
          int number   = gridInqNumber(gridID);
          int position = gridInqPosition(gridID);
          if ( number > 0 )
            fprintf(stdout, "%33s : number=%d  position=%d\n", "grid", number, position);

          if ( gridInqReference(gridID, NULL) )
411
            {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
412
413
414
              char reference_link[8192];
              gridInqReference(gridID, reference_link);
              fprintf(stdout, "%33s : %s\n", "uri", reference_link);
415
            }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
416
        }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
417

Uwe Schulzweida's avatar
Uwe Schulzweida committed
418
419
420
421
      print_xyvals2D(gridID, dig);
    }
  else /* if ( gridtype == GRID_GENERIC ) */
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
422
423
424
#ifdef CDO
      set_text_color(stdout, RESET, GREEN);
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
425
      if ( ysize == 0 )
426
        fprintf(stdout, "points=%zu\n", gridsize);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
427
      else
428
        fprintf(stdout, "points=%zu (%zux%zu)\n", gridsize, xsize, ysize);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
429
      my_reset_text_color(stdout);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
430
    }
431

Uwe Schulzweida's avatar
Uwe Schulzweida committed
432
  if ( gridtype == GRID_CURVILINEAR || gridtype == GRID_UNSTRUCTURED )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
433
434
435
    {
      if ( gridHasArea(gridID) ||
           gridInqXbounds(gridID, NULL) || gridInqYbounds(gridID, NULL) )
436
        {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
          fprintf(stdout, "%33s :", "available");
          if ( gridInqXbounds(gridID, NULL) && gridInqYbounds(gridID, NULL) ) fprintf(stdout, " cellbounds");
          if ( gridHasArea(gridID) )          fprintf(stdout, " area");
          if ( gridInqMask(gridID, NULL) )    fprintf(stdout, " mask");
          fprintf(stdout, "\n");
        }
    }

  unsigned char uuidOfHGrid[CDI_UUID_SIZE];
  gridInqUUID(gridID, uuidOfHGrid);
  if ( !cdiUUIDIsNull(uuidOfHGrid) )
    {
      char uuidOfHGridStr[37];
      cdiUUID2Str(uuidOfHGrid, uuidOfHGridStr);
      if ( uuidOfHGridStr[0] != 0  && strlen(uuidOfHGridStr) == 36 )
        {
          fprintf(stdout, "%33s : %s\n", "uuid", uuidOfHGridStr);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
454
455
456
457
        }
    }
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
458
459
460
461
462
463
464
465
466
467
468
469
470
471
static
void printGridInfo(int vlistID)
{
  int ngrids = vlistNgrids(vlistID);
  for ( int index = 0; index < ngrids; index++ )
    {
      int gridID = vlistGrid(vlistID, index);
      printGridInfoKernel(gridID, index, false);
      int projID = gridInqProj(gridID);
      if ( projID != CDI_UNDEFID )
        printGridInfoKernel(projID, index, true);
    }
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
472
473
474
475
476
static
void printZaxisInfo(int vlistID)
{
  char zaxisname[CDI_MAX_NAME], zname[CDI_MAX_NAME], zunits[CDI_MAX_NAME];

477
  int nzaxis = vlistNzaxis(vlistID);
478
  for ( int index = 0; index < nzaxis; index++ )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
479
    {
480
481
482
483
484
      double zinc = 0;
      int zaxisID   = vlistZaxis(vlistID, index);
      int zaxistype = zaxisInqType(zaxisID);
      int ltype     = zaxisInqLtype(zaxisID);
      int levelsize = zaxisInqSize(zaxisID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
485
      // int prec      = zaxisInqPrec(zaxisID);
486
      // int dig = (prec == CDI_DATATYPE_FLT64) ? 15 : 7;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
487
      int dig = 7;
488
489
490
491
#ifdef CDO
      extern int CDO_flt_digits;
      dig = CDO_flt_digits;
#endif
492

Uwe Schulzweida's avatar
Uwe Schulzweida committed
493
494
495
496
497
      zaxisName(zaxistype, zaxisname);
      zaxisInqName(zaxisID, zname);
      zaxisInqUnits(zaxisID, zunits);
      zunits[12] = 0;

Uwe Schulzweida's avatar
Uwe Schulzweida committed
498
      fprintf(stdout, "  %4d : ", vlistZaxisIndex(vlistID, zaxisID)+1);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
499
500
501
#ifdef CDO
      set_text_color(stdout, RESET, BLUE);
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
502
      if ( zaxistype == ZAXIS_GENERIC && ltype != 0 )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
503
        fprintf(stdout, "%-12s (ltype=%3d)", zaxisname, ltype);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
504
      else
Uwe Schulzweida's avatar
Uwe Schulzweida committed
505
506
507
508
        fprintf(stdout, "%-24s", zaxisname);
      my_reset_text_color(stdout);

      fprintf(stdout, " :");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
509

Uwe Schulzweida's avatar
Uwe Schulzweida committed
510
511
512
#ifdef CDO
      set_text_color(stdout, RESET, GREEN);
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
513
      fprintf(stdout, " levels=%d", levelsize);
514
515
      bool zscalar = (levelsize == 1) ? zaxisInqScalar(zaxisID) : false;
      if ( zscalar ) fprintf(stdout, "  scalar");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
516
      my_reset_text_color(stdout);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
517
518
      fprintf(stdout, "\n");

519
      if ( zaxisInqLevels(zaxisID, NULL) )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
520
        {
521
522
          double *levels = (double*) malloc((size_t)levelsize*sizeof(double));
          zaxisInqLevels(zaxisID, levels);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
523

524
          if ( !(zaxistype == ZAXIS_SURFACE && levelsize == 1 && !(fabs(levels[0]) > 0)) )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
525
            {
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
              double zfirst = levels[0];
              double zlast  = levels[levelsize-1];
              if ( levelsize > 2 )
                {
                  zinc = (levels[levelsize-1] - levels[0]) / (levelsize-1);
                  for ( int levelID = 2; levelID < levelsize; ++levelID )
                    if ( fabs(fabs(levels[levelID] - levels[levelID-1]) - zinc) > 0.001*zinc )
                      {
                        zinc = 0;
                        break;
                      }
                }

              fprintf(stdout, "%33s : %.*g", zname, dig, zfirst);
              if ( levelsize > 1 )
                {
                  fprintf(stdout, " to %.*g", dig, zlast);
                  if ( IS_NOT_EQUAL(zinc, 0) )
                    fprintf(stdout, " by %.*g", dig, zinc);
                }
              fprintf(stdout, " %s", zunits);
              fprintf(stdout, "\n");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
548
549
            }

550
551
          free(levels);
        }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
552
553
554
555
556
557
558
559

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

          level1 = zaxisInqLbound(zaxisID, 0);
          level2 = zaxisInqUbound(zaxisID, 0);
560
          fprintf(stdout, "%.*g-%.*g", dig, level1, dig, level2);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
561
562
563
564
          if ( levelsize > 1 )
            {
              level1 = zaxisInqLbound(zaxisID, levelsize-1);
              level2 = zaxisInqUbound(zaxisID, levelsize-1);
565
              fprintf(stdout, " to %.*g-%.*g", dig, level1, dig, level2);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
566
              if ( IS_NOT_EQUAL(zinc, 0) )
567
                fprintf(stdout, " by %.*g", dig, zinc);
568
            }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
569
570
          fprintf(stdout, " %s", zunits);
          fprintf(stdout, "\n");
571
        }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
572

Uwe Schulzweida's avatar
Uwe Schulzweida committed
573
574
      if ( zaxistype == ZAXIS_HYBRID )
        {
575
576
          char psname[CDI_MAX_NAME]; psname[0] = 0;
          cdiZaxisInqKeyStr(zaxisID, CDI_KEY_PSNAME, CDI_MAX_NAME, psname);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
577
578
579
580
581
582
583
584
585
586
          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
587
588
589
590
591
592
593
594
595
596
      if ( zaxistype == ZAXIS_REFERENCE )
        {
          int number   = zaxisInqNumber(zaxisID);

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

597
          unsigned char uuidOfVGrid[CDI_UUID_SIZE];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
598
          zaxisInqUUID(zaxisID, uuidOfVGrid);
Thomas Jahns's avatar
Thomas Jahns committed
599
          if ( !cdiUUIDIsNull(uuidOfVGrid) )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
600
601
            {
              char uuidOfVGridStr[37];
602
              cdiUUID2Str(uuidOfVGrid, uuidOfVGridStr);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
603
604
605
606
607
608
609
610
611
612
              if ( uuidOfVGridStr[0] != 0  && strlen(uuidOfVGridStr) == 36 )
                {
                  fprintf(stdout, "%33s : ", "uuid");
                  fprintf(stdout, "%s\n", uuidOfVGridStr);
                }
            }
        }
    }
}

613
614
615
616
617
618
619
620
621
622
623
624
625
626
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
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
644
  return ++ntimeout;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
}

#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
671
  return ndotout;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
672
673
674
}

static
675
void printTimesteps(int streamID, int taxisID, int verbose)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
{
  int nrecs;
  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;
695

696
697
698
#ifdef CDO
  dtlist_type *dtlist = dtlist_new();
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
699
700
  while ( (nrecs = streamInqTimestep(streamID, tsID)) )
    {
701
702
703
704
705
706
707
708
#ifdef CDO
      dtlist_taxisInqTimestep(dtlist, taxisID, 0);
      int vdate = dtlist_get_vdate(dtlist, 0);
      int vtime = dtlist_get_vtime(dtlist, 0);
#else
      int vdate = taxisInqVdate(taxisID);
      int vtime = taxisInqVtime(taxisID);
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
709

710
      if ( verbose || tsID < NUM_TIMESTEP )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
	{
	  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++;
    }

736
737
738
#ifdef CDO
  dtlist_delete(dtlist);
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
739
740
741
742
743
  if ( nvdatetime )
    {
      fprintf(stdout, "\n");

      ntimeout = 0;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
744
745
746
747
748
749
750
      int toff = 0;
      if ( tsID > 2*NUM_TIMESTEP )
        {
          toff = tsID%4;
          if ( toff > 0 ) toff = 4 - toff;
          for ( int i = 0; i < toff; ++i ) next_vdatetime = next_vdatetime->next;
        }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
751
752
      for ( int i = toff; i < nvdatetime; ++i )
	{
753
754
	  int vdate = next_vdatetime->vdate;
	  int vtime = next_vdatetime->vtime;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
755
756
757
	  ntimeout = printDateTime(ntimeout, vdate, vtime);
	  next_vdatetime = next_vdatetime->next;
	}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
758
759
    }
}
760
761
762
763
764
765
766
767
768
/*
 * Local Variables:
 * c-file-style: "Java"
 * c-basic-offset: 2
 * indent-tabs-mode: nil
 * show-trailing-whitespace: t
 * require-trailing-newline: t
 * End:
 */