cdf_int.c 17.7 KB
Newer Older
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#if defined (HAVE_CONFIG_H)
#  include "config.h"
#endif

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>

#include "cdi.h"
#include "stream_int.h"
#include "cdf_int.h"


extern int CDF_Fatal;
extern int CDF_Verbose;
extern int CDF_Debug;

#if  defined  (HAVE_LIBNETCDF)
20
/*
Uwe Schulzweida's avatar
Uwe Schulzweida committed
21
22
23
24
25
#if ! defined (MIN_BUF_SIZE)
#  define  MIN_BUF_SIZE  131072L
#endif

static size_t ChunkSizeMin = MIN_BUF_SIZE;
26
*/
Uwe Schulzweida's avatar
Uwe Schulzweida committed
27
28
29
30
31

void cdf_create(const char *path, int cmode, int *ncidp)
{
  int status;
  int oldfill;
32
33
  size_t initialsz = 0, chunksizehint = 0;
  /*
Uwe Schulzweida's avatar
Uwe Schulzweida committed
34
#if defined (HAVE_STRUCT_STAT_ST_BLKSIZE)
35
  struct stat filestat;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
36
37
38
39
40
41
42
43
  char basename[1024];
  char *pend;

  pend = strrchr(path, '/');
  if ( pend == 0 )
    strcpy(basename, "./");
  else
    {
44
      memcpy(basename, path, pend-path);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
45
46
47
48
      basename[pend-path] = 0;
    }

  if ( stat(basename, &filestat) != 0 )
49
    SysError(basename);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
50
51

  chunksizehint = (size_t) filestat.st_blksize * 4;
52
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
53

Uwe Schulzweida's avatar
Uwe Schulzweida committed
54
  if ( chunksizehint < ChunkSizeMin ) chunksizehint = ChunkSizeMin;
55
56
57
58
  */
#if defined(__SX__) || defined(ES)
  chunksizehint = 16777216; /* 16 MB */
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
59
60
61
62

  status = nc__create(path, cmode, initialsz, &chunksizehint, ncidp);

  if ( CDF_Debug || status != NC_NOERR )
63
    Message("ncid = %d  mode = %d  file = %s", *ncidp, cmode, path);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
64
65

  if ( CDF_Debug || status != NC_NOERR )
66
    Message("chunksizehint %d", chunksizehint);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
67
68

  if ( status != NC_NOERR )
69
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
70
71
72
73

  status = nc_set_fill(*ncidp, NC_NOFILL, &oldfill);

  if ( status != NC_NOERR )
74
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
75
76
77
}


Uwe Schulzweida's avatar
Uwe Schulzweida committed
78
int cdf_open(const char *path, int omode, int *ncidp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
79
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
80
  int status = 0;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
81
82
  int dapfile = FALSE;
  struct stat filestat;
83
  size_t chunksizehint = 0;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
84
85

#if  defined  (HAVE_LIBNC_DAP)
86
  if ( memcmp(path, "http:", 5) == 0 ) dapfile = TRUE;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
87
88
89
90
91
92
93
94
#endif

  if ( dapfile )
    {
      status = nc_open(path, omode, ncidp);
    }
  else
    {
95
      if ( stat(path, &filestat) != 0 ) SysError(path);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
96

97
#if defined (HAVE_STRUCT_STAT_ST_BLKSIZE)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
98
      chunksizehint = (size_t) filestat.st_blksize * 4;
99
#endif
100
      /*
Uwe Schulzweida's avatar
Uwe Schulzweida committed
101
      if ( chunksizehint < ChunkSizeMin ) chunksizehint = ChunkSizeMin;
102
      */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
103
104
      status = nc__open(path, omode, &chunksizehint, ncidp);

105
      if ( CDF_Debug )
106
	Message("chunksizehint %d", chunksizehint);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
107
108
    }

109
  if ( CDF_Debug )
110
    Message("ncid = %d  mode = %d  file = %s", *ncidp, omode, path);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
111
112

  if ( CDF_Debug && status != NC_NOERR )
113
    Message("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
114
115

  return (status);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
116
117
118
119
120
121
122
123
124
125
}


void cdf_close(int ncid)
{
  int status;

  status = nc_close(ncid);

  if ( status != NC_NOERR )
126
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
127
128
129
130
131
132
133
134
135
136
}


void cdf_redef(int ncid)
{
  int status;

  status = nc_redef(ncid);

  if ( status != NC_NOERR )
137
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
138
139
140
141
142
143
144
145
146
147
}


void cdf_enddef(int ncid)
{
  int status;

  status = nc_enddef(ncid);

  if ( status != NC_NOERR )
148
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
149
150
151
}


Uwe Schulzweida's avatar
Uwe Schulzweida committed
152
153
154
155
156
157
158
void cdf_sync(int ncid)
{
  int status;

  status = nc_sync(ncid);

  if ( status != NC_NOERR )
159
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
160
161
162
}


Uwe Schulzweida's avatar
Uwe Schulzweida committed
163
164
165
166
167
168
169
void cdf_inq(int ncid, int *ndimsp, int *nvarsp, int *ngattsp, int *unlimdimidp)
{
  int status;

  status = nc_inq(ncid, ndimsp, nvarsp, ngattsp, unlimdimidp);

  if ( CDF_Debug || status != NC_NOERR )
170
    Message("ncid = %d ndims = %d nvars = %d ngatts = %d unlimid = %d",
Uwe Schulzweida's avatar
Uwe Schulzweida committed
171
172
173
	    ncid, *ndimsp, *nvarsp, *ngattsp, *unlimdimidp);

  if ( status != NC_NOERR )
174
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
175
176
177
178
179
180
181
182
183
184
}


void cdf_def_dim(int ncid, const char *name, size_t len, int *dimidp)
{
  int status;

  status = nc_def_dim(ncid, name, len, dimidp);

  if ( CDF_Debug || status != NC_NOERR )
185
    Message("ncid = %d  name = %s  len = %d", ncid, name, len);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
186
187

  if ( status != NC_NOERR )
188
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
189
190
}

191
192

void cdf_inq_dimid(int ncid, const char *name, int *dimidp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
193
194
195
196
197
198
{
  int status;

  status = nc_inq_dimid(ncid, name, dimidp);

  if (CDF_Debug || status != NC_NOERR)
199
    Message("ncid = %d  name = %s  dimid= %d", ncid, name, *dimidp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
200
201

  if (status != NC_NOERR)
202
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
203
204
}

205
206

void cdf_inq_dim(int ncid, int dimid, char *name, size_t * lengthp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
207
208
209
210
211
212
{
  int status;

  status = nc_inq_dim(ncid, dimid, name, lengthp);

  if ( CDF_Debug || status != NC_NOERR )
213
    Message("ncid = %d  dimid = %d  length = %d name = %s",
Uwe Schulzweida's avatar
Uwe Schulzweida committed
214
215
216
	    ncid, dimid, *lengthp, name);

  if ( status != NC_NOERR )
217
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
218
219
}

220
221

void cdf_inq_dimname(int ncid, int dimid, char *name)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
222
223
224
225
226
227
{
  int status;

  status = nc_inq_dimname(ncid, dimid, name);

  if ( CDF_Debug || status != NC_NOERR )
228
    Message("ncid = %d  dimid = %d  name = %s", ncid, dimid, name);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
229
230

  if ( status != NC_NOERR )
231
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
232
233
}

234
235

void cdf_inq_dimlen(int ncid, int dimid, size_t * lengthp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
236
237
238
239
240
241
{
  int status;

  status = nc_inq_dimlen(ncid, dimid, lengthp);

  if ( CDF_Debug || status != NC_NOERR )
242
    Message("ncid = %d dimid = %d length = %d", ncid, dimid, *lengthp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
243
244

  if ( status != NC_NOERR )
245
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
246
247
}

248
249

void cdf_def_var(int ncid, const char *name, nc_type xtype, int ndims,
Uwe Schulzweida's avatar
Uwe Schulzweida committed
250
251
252
253
254
255
256
	    const int dimids[], int *varidp)
{
  int status;

  status = nc_def_var(ncid, name, xtype, ndims, dimids, varidp);

  if ( CDF_Debug || status != NC_NOERR )
257
    Message("ncid = %d  name = %s  xtype = %d  ndims = %d  varid = %d",
Uwe Schulzweida's avatar
Uwe Schulzweida committed
258
259
260
	    ncid, name, xtype, ndims, *varidp);

  if ( status != NC_NOERR )
261
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
262
263
}

264

Uwe Schulzweida's avatar
Uwe Schulzweida committed
265
266
267
268
269
270
271
void cdf_inq_varid(int ncid, const char *name, int *varidp)
{
  int status;

  status = nc_inq_varid(ncid, name, varidp);

  if ( CDF_Debug || status != NC_NOERR )
272
    Message("ncid = %d  name = %s  varid = %d ", ncid, name, *varidp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
273
274

  if ( status != NC_NOERR )
275
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
276
}
277
278
279


void cdf_inq_nvars(int ncid, int *nvarsp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
280
281
282
283
284
285
{
  int status;

  status = nc_inq_nvars(ncid, nvarsp);

  if ( CDF_Debug || status != NC_NOERR )
286
    Message("ncid = %d  nvars = %d", ncid, *nvarsp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
287
288

  if ( status != NC_NOERR )
289
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
290
291
}

292
293
294

void cdf_inq_var(int ncid, int varid, char *name, nc_type *xtypep, int *ndimsp,
		 int dimids[], int *nattsp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
295
296
297
298
299
300
{
  int status;

  status = nc_inq_var(ncid, varid, name, xtypep, ndimsp, dimids, nattsp);

  if ( CDF_Debug || status != NC_NOERR )
301
    Message("ncid = %d varid = %d ndims = %d xtype = %d natts = %d name = %s",
Uwe Schulzweida's avatar
Uwe Schulzweida committed
302
303
304
	    ncid, varid, *ndimsp, *xtypep, *nattsp, name);

  if ( status != NC_NOERR )
305
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
306
307
}

308
309

void cdf_inq_varname(int ncid, int varid, char *name)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
310
311
312
313
314
315
{
  int status;

  status = nc_inq_varname(ncid, varid, name);

  if ( CDF_Debug || status != NC_NOERR )
316
    Message("ncid = %d varid = %d name = %s", ncid, varid, name);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
317
318

  if ( status != NC_NOERR )
319
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
320
321
}

322
323

void cdf_inq_vartype(int ncid, int varid, nc_type *xtypep)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
324
325
326
327
328
329
{
  int status;

  status = nc_inq_vartype(ncid, varid, xtypep);

  if ( CDF_Debug || status != NC_NOERR )
330
    Message("ncid = %d varid = %d xtype = %s", ncid, varid, *xtypep);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
331
332

  if ( status != NC_NOERR )
333
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
334
335
}

336
337

void cdf_inq_varndims(int ncid, int varid, int *ndimsp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
338
339
340
341
342
343
{
  int status;

  status = nc_inq_varndims(ncid, varid, ndimsp);

  if ( CDF_Debug || status != NC_NOERR )
344
    Message("ncid = %d varid = %d", ncid, varid);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
345
346

  if ( status != NC_NOERR )
347
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
348
349
}

350
351

void cdf_inq_vardimid(int ncid, int varid, int dimids[])
Uwe Schulzweida's avatar
Uwe Schulzweida committed
352
353
354
355
356
357
{
  int status;

  status = nc_inq_vardimid(ncid, varid, dimids);

  if ( CDF_Debug || status != NC_NOERR )
358
    Message("ncid = %d varid = %d", ncid, varid);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
359
360

  if ( status != NC_NOERR )
361
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
362
363
}

364
365

void cdf_inq_varnatts(int ncid, int varid, int *nattsp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
366
367
368
369
370
371
{
  int status;

  status = nc_inq_varnatts(ncid, varid, nattsp);

  if (CDF_Debug || status != NC_NOERR)
372
    Message("ncid = %d varid = %d nattsp = %d", ncid, varid, *nattsp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
373
374

  if ( status != NC_NOERR )
375
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
376
377
}

378
379

void cdf_put_var_text(int ncid, int varid, const char *tp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
380
381
382
383
384
385
386
387
388
{
  int status;

  status = nc_put_var_text(ncid, varid, tp);

  if (CDF_Debug || status != NC_NOERR)
    fprintf (stderr, "cdf_put_var_text : %d %d %s \n", ncid, varid, tp);

  if ( status != NC_NOERR )
389
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
390
391
392
}


393
void cdf_put_var_short(int ncid, int varid, const short *sp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
394
395
396
397
398
399
400
401
402
{
  int status;

  status = nc_put_var_short(ncid, varid, sp);

  if (CDF_Debug || status != NC_NOERR)
    fprintf (stderr, "cdf_put_var_short : %d %d %hd \n", ncid, varid, *sp);

  if (status != NC_NOERR)
403
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
404
405
}

406
407

void cdf_put_var_int(int ncid, int varid, const int *ip)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
408
409
410
411
412
413
414
415
416
{
  int status;

  status = nc_put_var_int(ncid, varid, ip);

  if (CDF_Debug || status != NC_NOERR)
    fprintf (stderr, "cdf_put_var_int : %d %d %d \n", ncid, varid, *ip);

  if ( status != NC_NOERR )
417
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
418
419
}

420
421

void cdf_put_var_long(int ncid, int varid, const long *lp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
422
423
424
425
426
427
428
429
430
{
  int status;

  status = nc_put_var_long(ncid, varid, lp);

  if (CDF_Debug || status != NC_NOERR)
    fprintf (stderr, "cdf_put_var_long : %d %d %ld \n", ncid, varid, *lp);

  if ( status != NC_NOERR )
431
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
432
433
}

434
435

void cdf_put_var_float(int ncid, int varid, const float *fp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
436
437
438
439
440
441
442
443
444
{
  int status;

  status = nc_put_var_float(ncid, varid, fp);

  if (CDF_Debug || status != NC_NOERR)
    fprintf (stderr, "cdf_put_var_float : %d %d %f \n", ncid, varid, *fp);

  if ( status != NC_NOERR )
445
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
446
447
}

448
449
450

void  cdf_put_vara_double (int ncid, int varid, const size_t start[],
			   const size_t count[], const double *dp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
451
452
453
454
455
456
{
  int status;

  status = nc_put_vara_double(ncid, varid, start, count, dp);

  if ( CDF_Debug || status != NC_NOERR )
457
    Message("ncid = %d varid = %d val0 = %f", ncid, varid, *dp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
458
459

  if ( status != NC_NOERR )
460
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
461
462
}

463
464
465

void  cdf_get_vara_int (int ncid, int varid, const size_t start[],
			const size_t count[], int *dp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
466
467
468
469
470
471
{
  int status;

  status = nc_get_vara_int(ncid, varid, start, count, dp);

  if ( CDF_Debug || status != NC_NOERR )
472
    Message("ncid = %d varid = %d", ncid, varid);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
473
474

  if ( status != NC_NOERR )
475
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
476
477
}

478
479
480

void  cdf_get_vara_double (int ncid, int varid, const size_t start[],
			   const size_t count[], double *dp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
481
482
483
484
485
486
{
  int status;

  status = nc_get_vara_double(ncid, varid, start, count, dp);

  if ( CDF_Debug || status != NC_NOERR )
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
    Message("ncid = %d varid = %d", ncid, varid);

  if ( status != NC_NOERR )
    Error("%s", nc_strerror(status));
}


void  cdf_get_vara_text(int ncid, int varid, const size_t start[],
			const size_t count[], char *tp)
{
  int status;

  status = nc_get_vara_text(ncid, varid, start, count, tp);

  if ( CDF_Debug || status != NC_NOERR )
    Message("ncid = %d varid = %d", ncid, varid);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
503
504

  if ( status != NC_NOERR )
505
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
506
507
}

508
509

void cdf_put_var_double (int ncid, int varid, const double *dp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
510
511
512
513
514
515
{
  int status;

  status = nc_put_var_double(ncid, varid, dp);

  if ( CDF_Debug || status != NC_NOERR )
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
    Message("ncid = %d varid = %d val0 = %f", ncid, varid, *dp);

  if ( status != NC_NOERR )
    Error("%s", nc_strerror(status));
}


void cdf_get_var1_text(int ncid, int varid, const size_t index[], char *tp)
{
  int status;

  status = nc_get_var1_text(ncid, varid, index, tp);

  if ( CDF_Debug || status != NC_NOERR )
    Message("ncid = %d varid = %d", ncid, varid);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
531
532

  if ( status != NC_NOERR )
533
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
534
535
}

536
537

void cdf_get_var1_double(int ncid, int varid, const size_t index[], double *dp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
538
539
540
541
542
543
{
  int status;

  status = nc_get_var1_double(ncid, varid, index, dp);

  if ( CDF_Debug || status != NC_NOERR )
544
    Message("ncid = %d varid = %d", ncid, varid);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
545
546

  if ( status != NC_NOERR )
547
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
548
549
}

550
551

void cdf_put_var1_double(int ncid, int varid, const size_t index[], const double *dp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
552
553
554
555
556
557
{
  int status;

  status = nc_put_var1_double(ncid, varid, index, dp);

  if ( CDF_Debug || status != NC_NOERR )
558
    Message("ncid = %d varid = %d val = %f", ncid, varid, *dp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
559
560

  if ( status != NC_NOERR )
561
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
562
563
}

564
565

void cdf_get_var_text(int ncid, int varid, char *tp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
566
567
568
569
570
571
{
  int status;

  status = nc_get_var_text(ncid, varid, tp);

  if ( CDF_Debug || status != NC_NOERR )
572
    Message("ncid = %d varid = %d", ncid, varid);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
573
574

  if (status != NC_NOERR)
575
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
576
577
}

578
579

void cdf_get_var_short(int ncid, int varid, short *sp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
580
581
582
583
584
585
{
  int status;

  status = nc_get_var_short(ncid, varid, sp);

  if ( CDF_Debug || status != NC_NOERR )
586
    Message("ncid = %d varid = %d", ncid, varid);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
587
588

  if ( status != NC_NOERR )
589
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
590
591
}

592
593

void cdf_get_var_int(int ncid, int varid, int *ip)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
594
595
596
597
598
599
{
  int status;

  status = nc_get_var_int(ncid, varid, ip);

  if ( CDF_Debug || status != NC_NOERR )
600
    Message("ncid = %d varid = %d", ncid, varid);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
601
602

  if ( status != NC_NOERR )
603
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
604
605
}

606
607

void cdf_get_var_long(int ncid, int varid, long *lp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
608
609
610
611
612
613
{
  int status;

  status = nc_get_var_long(ncid, varid, lp);

  if ( CDF_Debug || status != NC_NOERR )
614
    Message("ncid = %d varid = %d", ncid, varid);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
615
616

  if ( status != NC_NOERR )
617
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
618
619
}

620
621

void cdf_get_var_float(int ncid, int varid, float *fp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
622
623
624
625
626
627
{
  int status;

  status = nc_get_var_float(ncid, varid, fp);

  if ( CDF_Debug || status != NC_NOERR )
628
    Message("ncid = %d varid = %d", ncid, varid);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
629
630

  if ( status != NC_NOERR )
631
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
632
633
}

634
635

void cdf_get_var_double(int ncid, int varid, double *dp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
636
637
638
639
640
641
{
  int status;

  status = nc_get_var_double(ncid, varid, dp);

  if (CDF_Debug || status != NC_NOERR)
642
    Message("ncid = %d varid = %d val[0] = %f", ncid, varid, *dp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
643
644

  if ( status != NC_NOERR )
645
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
646
647
}

648
649
650

void cdf_copy_att(int ncid_in, int varid_in, const char *name, int ncid_out,
		  int varid_out)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
651
652
653
654
655
656
657
658
659
660
{
  int status;

  status = nc_copy_att(ncid_in, varid_in, name, ncid_out, varid_out);

  if (CDF_Debug || status != NC_NOERR)
    fprintf (stderr, "cdf_copy_att : %d %d %s %d %d\n", ncid_in, varid_out,
	     name, ncid_out, varid_out);

  if ( status != NC_NOERR )
661
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
662
663
}

664
665
666

void cdf_put_att_text(int ncid, int varid, const char *name, size_t len,
		      const char *tp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
667
668
669
670
671
672
{
  int status;

  status = nc_put_att_text(ncid, varid, name, len, tp);

  if (CDF_Debug || status != NC_NOERR)
673
    Message("ncid = %d varid = %d att = %s text = %s",
Uwe Schulzweida's avatar
Uwe Schulzweida committed
674
675
676
	    ncid, varid, name, tp);

  if ( status != NC_NOERR )
677
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
678
679
}

680
681
682

void cdf_put_att_int(int ncid, int varid, const char *name, nc_type xtype,
		     size_t len, const int *ip)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
683
684
685
686
687
688
{
  int status;

  status = nc_put_att_int(ncid, varid, name, xtype, len, ip);

  if (CDF_Debug || status != NC_NOERR)
689
    Message("ncid = %d varid = %d att = %s val = %d",
Uwe Schulzweida's avatar
Uwe Schulzweida committed
690
691
692
	    ncid, varid, name, *ip);

  if ( status != NC_NOERR )
693
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
694
695
}

696
697
698

void cdf_put_att_double(int ncid, int varid, const char *name, nc_type xtype,
			size_t len, const double *dp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
699
700
701
702
703
704
705
706
707
{
  int status;

  status = nc_put_att_double(ncid, varid, name, xtype, len, dp);

  if (CDF_Debug || status != NC_NOERR)
    fprintf (stderr, "cdf_put_att_double : %d %d %f \n", ncid, varid, *dp);

  if ( status != NC_NOERR )
708
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
709
710
}

711
712

void cdf_get_att_text(int ncid, int varid, char *name, char *tp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
713
714
715
716
717
718
{
  int status;

  status = nc_get_att_text(ncid, varid, name, tp);

  if (CDF_Debug || status != NC_NOERR)
719
    Message("ncid = %d varid = %d name = %s", ncid, varid, name);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
720
721

  if ( status != NC_NOERR )
722
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
723
724
}

725
726

void cdf_get_att_int(int ncid, int varid, char *name, int *ip)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
727
728
729
730
731
732
{
  int status;

  status = nc_get_att_int(ncid, varid, name, ip);

  if (CDF_Debug || status != NC_NOERR)
733
    Message("ncid = %d varid = %d att = %s val = %d",
Uwe Schulzweida's avatar
Uwe Schulzweida committed
734
735
736
	    ncid, varid, name, *ip);

  if ( status != NC_NOERR )
737
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
738
739
}

740

Uwe Schulzweida's avatar
Uwe Schulzweida committed
741
742
743
744
745
746
747
void cdf_get_att_double(int ncid, int varid, char *name, double *dp)
{
  int status;

  status = nc_get_att_double(ncid, varid, name, dp);

  if ( CDF_Debug || status != NC_NOERR )
748
    Message("ncid = %d varid = %d att = %s val = %.9g",
Uwe Schulzweida's avatar
Uwe Schulzweida committed
749
750
751
	    ncid, varid, name, *dp);

  if ( status != NC_NOERR )
752
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
753
754
}

755

Uwe Schulzweida's avatar
Uwe Schulzweida committed
756
void cdf_inq_att(int ncid, int varid, const char *name, nc_type *xtypep,
757
		 size_t *lenp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
758
759
760
761
762
763
{
  int status;

  status = nc_inq_att(ncid, varid, name, xtypep, lenp);

  if ( CDF_Debug || status != NC_NOERR )
764
    Message("ncid = %d varid = %d", ncid, varid);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
765
766

  if ( status != NC_NOERR )
767
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
768
769
}

770
771

void cdf_inq_atttype(int ncid, int varid, const char *name, nc_type * xtypep)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
772
773
774
775
776
777
{
  int status;

  status = nc_inq_atttype(ncid, varid, name, xtypep);

  if ( CDF_Debug || status != NC_NOERR )
778
    Message("ncid = %d varid = %d", ncid, varid);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
779
780

  if ( status != NC_NOERR )
781
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
782
783
}

784
785

void cdf_inq_attlen(int ncid, int varid, const char *name, size_t * lenp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
786
787
788
789
790
791
{
  int status;

  status = nc_inq_attlen(ncid, varid, name, lenp);

  if (CDF_Debug || status != NC_NOERR)
792
    Message("ncid = %d varid = %d name = %s len = %d",
Uwe Schulzweida's avatar
Uwe Schulzweida committed
793
794
795
	    ncid, varid, name, *lenp);

  if ( status != NC_NOERR )
796
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
797
798
}

799
800

void cdf_inq_attname(int ncid, int varid, int attnum, char *name)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
801
802
803
804
805
806
{
  int status;

  status = nc_inq_attname(ncid, varid, attnum, name);

  if (CDF_Debug || status != NC_NOERR)
807
    Message("ncid = %d varid = %d attnum = %d name = %s",
Uwe Schulzweida's avatar
Uwe Schulzweida committed
808
809
810
	    ncid, varid, attnum, name);

  if ( status != NC_NOERR )
811
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
812
813
}

814
815

void cdf_inq_attid(int ncid, int varid, const char *name, int *attnump)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
816
817
818
819
820
821
{
  int status;

  status = nc_inq_attid(ncid, varid, name, attnump);

  if ( CDF_Debug || status != NC_NOERR )
822
    Message("ncid = %d varid = %d", ncid, varid);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
823
824

  if ( status != NC_NOERR )
825
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
826
827
828
}

#endif
829
830
831
832
833
834
835
836
837
/*
 * Local Variables:
 * c-file-style: "Java"
 * c-basic-offset: 2
 * indent-tabs-mode: nil
 * show-trailing-whitespace: t
 * require-trailing-newline: t
 * End:
 */