cdf_int.c 20.2 KB
Newer Older
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1
2
3
4
5
6
7
8
9
10
11
12
13
#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"

14
15
16
17
18
19
20
21
22
#ifdef USE_MPI
#include "namespace.h"
#include "pio.h"
#include "pio_comm.h"
#include "pio_util.h"
#ifdef HAVE_NETCDF_PAR_H
#include <netcdf_par.h>
#endif
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
23
24
25
26
27
28

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

#if  defined  (HAVE_LIBNETCDF)
29
/*
Uwe Schulzweida's avatar
Uwe Schulzweida committed
30
31
32
33
34
#if ! defined (MIN_BUF_SIZE)
#  define  MIN_BUF_SIZE  131072L
#endif

static size_t ChunkSizeMin = MIN_BUF_SIZE;
35
*/
36
37
38
39
40
#if USE_MPI && !defined (HAVE_PARALLEL_NC4)
/* When in PIO mode without a parallel netcdf library, each file is
 * actually opened on only one host */
extern int *cdiOpenFileMap, *cdiOpenFileCounts;
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
41
42
43
44
45

void cdf_create(const char *path, int cmode, int *ncidp)
{
  int status;
  int oldfill;
46
47
  size_t initialsz = 0, chunksizehint = 0;
  /*
Uwe Schulzweida's avatar
Uwe Schulzweida committed
48
#if defined (HAVE_STRUCT_STAT_ST_BLKSIZE)
49
  struct stat filestat;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
50
51
52
53
54
55
56
57
  char basename[1024];
  char *pend;

  pend = strrchr(path, '/');
  if ( pend == 0 )
    strcpy(basename, "./");
  else
    {
58
      memcpy(basename, path, pend-path);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
59
60
61
62
      basename[pend-path] = 0;
    }

  if ( stat(basename, &filestat) != 0 )
63
    SysError(basename);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
64
65

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
68
  if ( chunksizehint < ChunkSizeMin ) chunksizehint = ChunkSizeMin;
69
70
71
72
  */
#if defined(__SX__) || defined(ES)
  chunksizehint = 16777216; /* 16 MB */
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
73

74
75
  if ( cdiNcChunksizehint != CDI_UNDEFID ) chunksizehint = cdiNcChunksizehint;

76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#if USE_MPI
#if defined (HAVE_NETCDF4) && defined (HAVE_PARALLEL_NC4)
  if (cmode & NC_NETCDF4
      && namespaceHasLocalFile(namespaceGetActive())
      && commInqIOMode() != PIO_NONE)
    {
      cmode |= NC_MPIPOSIX;
      status = nc_create_par(path, cmode, commInqCommColl(),
                             MPI_INFO_NULL, ncidp);
    }
  else if (cmode & (NC_64BIT_OFFSET | NC_CLASSIC_MODEL)
           && namespaceHasLocalFile(namespaceGetActive())
           && commInqIOMode() != PIO_NONE)
    {
      /* FIXME: improve handling of pnetcdf here */
      abort();
    }
  else
    status = nc__create(path, cmode, initialsz, &chunksizehint, ncidp);
#else
  /* FIXME: Only open netcdf file on one task */
  status = nc__create(path, cmode, initialsz, &chunksizehint, ncidp);
#endif
#else
Uwe Schulzweida's avatar
Uwe Schulzweida committed
100
  status = nc__create(path, cmode, initialsz, &chunksizehint, ncidp);
101
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
102
103

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

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

109
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
110
111
112

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

113
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
114
115
116
}


Uwe Schulzweida's avatar
Uwe Schulzweida committed
117
int cdf_open(const char *path, int omode, int *ncidp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
118
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
119
  int status = 0;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
120
121
  int dapfile = FALSE;
  struct stat filestat;
122
  size_t chunksizehint = 0;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
123
124

#if  defined  (HAVE_LIBNC_DAP)
125
  if ( memcmp(path, "http:", 5) == 0 ) dapfile = TRUE;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
126
127
128
129
130
131
132
133
#endif

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

136
#if defined (HAVE_STRUCT_STAT_ST_BLKSIZE)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
137
      chunksizehint = (size_t) filestat.st_blksize * 4;
138
#endif
139
      /*
Uwe Schulzweida's avatar
Uwe Schulzweida committed
140
      if ( chunksizehint < ChunkSizeMin ) chunksizehint = ChunkSizeMin;
141
      */
142
143
      if ( cdiNcChunksizehint != CDI_UNDEFID ) chunksizehint = cdiNcChunksizehint;

144
      /* FIXME: parallel part missing */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
145
146
      status = nc__open(path, omode, &chunksizehint, ncidp);

147
      if ( CDF_Debug ) Message("chunksizehint %d", chunksizehint);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
148
149
    }

150
  if ( CDF_Debug )
151
    Message("ncid = %d  mode = %d  file = %s", *ncidp, omode, path);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
152

153
  if ( CDF_Debug && status != NC_NOERR ) Message("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
154
155

  return (status);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
156
157
158
159
160
161
162
163
164
165
}


void cdf_close(int ncid)
{
  int status;

  status = nc_close(ncid);

  if ( status != NC_NOERR )
166
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
167
168
169
170
171
172
173
174
175
176
}


void cdf_redef(int ncid)
{
  int status;

  status = nc_redef(ncid);

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


void cdf_enddef(int ncid)
{
  int status;

  status = nc_enddef(ncid);

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


Uwe Schulzweida's avatar
Uwe Schulzweida committed
192
193
194
195
196
197
198
void cdf_sync(int ncid)
{
  int status;

  status = nc_sync(ncid);

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


Uwe Schulzweida's avatar
Uwe Schulzweida committed
203
204
205
206
207
208
209
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 )
210
    Message("ncid = %d ndims = %d nvars = %d ngatts = %d unlimid = %d",
Uwe Schulzweida's avatar
Uwe Schulzweida committed
211
212
213
	    ncid, *ndimsp, *nvarsp, *ngattsp, *unlimdimidp);

  if ( status != NC_NOERR )
214
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
215
216
217
218
219
220
221
222
223
224
}


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 )
225
    Message("ncid = %d  name = %s  len = %d", ncid, name, len);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
226
227

  if ( status != NC_NOERR )
228
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
229
230
}

231
232

void cdf_inq_dimid(int ncid, const char *name, int *dimidp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
233
234
235
236
237
238
{
  int status;

  status = nc_inq_dimid(ncid, name, dimidp);

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

  if (status != NC_NOERR)
242
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
243
244
}

245
246

void cdf_inq_dim(int ncid, int dimid, char *name, size_t * lengthp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
247
248
249
250
251
252
{
  int status;

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

  if ( CDF_Debug || status != NC_NOERR )
253
    Message("ncid = %d  dimid = %d  length = %d name = %s",
Uwe Schulzweida's avatar
Uwe Schulzweida committed
254
255
256
	    ncid, dimid, *lengthp, name);

  if ( status != NC_NOERR )
257
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
258
259
}

260
261

void cdf_inq_dimname(int ncid, int dimid, char *name)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
262
263
264
265
266
267
{
  int status;

  status = nc_inq_dimname(ncid, dimid, name);

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

  if ( status != NC_NOERR )
271
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
272
273
}

274
275

void cdf_inq_dimlen(int ncid, int dimid, size_t * lengthp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
276
277
278
279
280
281
{
  int status;

  status = nc_inq_dimlen(ncid, dimid, lengthp);

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

  if ( status != NC_NOERR )
285
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
286
287
}

288
289

void cdf_def_var(int ncid, const char *name, nc_type xtype, int ndims,
Uwe Schulzweida's avatar
Uwe Schulzweida committed
290
291
292
293
294
295
296
	    const int dimids[], int *varidp)
{
  int status;

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

  if ( CDF_Debug || status != NC_NOERR )
297
    Message("ncid = %d  name = %s  xtype = %d  ndims = %d  varid = %d",
Uwe Schulzweida's avatar
Uwe Schulzweida committed
298
299
300
	    ncid, name, xtype, ndims, *varidp);

  if ( status != NC_NOERR )
301
    Error("%s", nc_strerror(status));
302
303
304
305
306
307
308
309
310
311
312
313
314
315

#if USE_MPI
#if defined (HAVE_NETCDF4) && defined (HAVE_PARALLEL_NC4)
  if (namespaceHasLocalFile(namespaceGetActive())
      && commInqIOMode() != PIO_NONE)
    {
      xdebug("%s", "calling nc_var_par_access");
      status = nc_var_par_access(ncid, *varidp, NC_COLLECTIVE);
      if ( status != NC_NOERR )
        Error("%s", nc_strerror(status));
    }
#endif
#endif

Uwe Schulzweida's avatar
Uwe Schulzweida committed
316
317
}

318

Uwe Schulzweida's avatar
Uwe Schulzweida committed
319
320
321
322
323
324
325
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 )
326
    Message("ncid = %d  name = %s  varid = %d ", ncid, name, *varidp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
327
328

  if ( status != NC_NOERR )
329
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
330
}
331
332
333


void cdf_inq_nvars(int ncid, int *nvarsp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
334
335
336
337
338
339
{
  int status;

  status = nc_inq_nvars(ncid, nvarsp);

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

  if ( status != NC_NOERR )
343
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
344
345
}

346
347
348

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
349
350
351
352
353
354
{
  int status;

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

  if ( CDF_Debug || status != NC_NOERR )
355
    Message("ncid = %d varid = %d ndims = %d xtype = %d natts = %d name = %s",
Uwe Schulzweida's avatar
Uwe Schulzweida committed
356
357
358
	    ncid, varid, *ndimsp, *xtypep, *nattsp, name);

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

362
363

void cdf_inq_varname(int ncid, int varid, char *name)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
364
365
366
367
368
369
{
  int status;

  status = nc_inq_varname(ncid, varid, name);

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

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

376
377

void cdf_inq_vartype(int ncid, int varid, nc_type *xtypep)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
378
379
380
381
382
383
{
  int status;

  status = nc_inq_vartype(ncid, varid, xtypep);

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

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

390
391

void cdf_inq_varndims(int ncid, int varid, int *ndimsp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
392
393
394
395
396
397
{
  int status;

  status = nc_inq_varndims(ncid, varid, ndimsp);

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

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

404
405

void cdf_inq_vardimid(int ncid, int varid, int dimids[])
Uwe Schulzweida's avatar
Uwe Schulzweida committed
406
407
408
409
410
411
{
  int status;

  status = nc_inq_vardimid(ncid, varid, dimids);

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

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

418
419

void cdf_inq_varnatts(int ncid, int varid, int *nattsp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
420
421
422
423
424
425
{
  int status;

  status = nc_inq_varnatts(ncid, varid, nattsp);

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

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

432
433

void cdf_put_var_text(int ncid, int varid, const char *tp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
434
435
436
437
438
439
440
441
442
{
  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 )
443
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
444
445
446
}


447
void cdf_put_var_short(int ncid, int varid, const short *sp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
448
449
450
451
452
453
454
455
456
{
  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)
457
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
458
459
}

460
461

void cdf_put_var_int(int ncid, int varid, const int *ip)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
462
463
464
465
466
467
468
469
470
{
  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 )
471
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
472
473
}

474
475

void cdf_put_var_long(int ncid, int varid, const long *lp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
476
477
478
479
480
481
482
483
484
{
  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 )
485
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
486
487
}

488
489

void cdf_put_var_float(int ncid, int varid, const float *fp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
490
491
492
493
494
495
496
497
498
{
  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 )
499
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
500
501
}

502

503
504
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
505
506
507
508
509
510
{
  int status;

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

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

  if ( status != NC_NOERR )
514
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
515
516
}

517

518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
void  cdf_put_vara_float(int ncid, int varid, const size_t start[],
                         const size_t count[], const float *fp)
{
  int status;

  status = nc_put_vara_float(ncid, varid, start, count, fp);

  if ( CDF_Debug || status != NC_NOERR )
    Message("ncid = %d varid = %d val0 = %f", ncid, varid, *fp);

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


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
535
536
537
538
539
540
{
  int status;

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

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

  if ( status != NC_NOERR )
544
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
545
546
}

547

548
549
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
550
551
552
553
554
555
{
  int status;

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

  if ( CDF_Debug || status != NC_NOERR )
556
557
558
559
560
561
562
    Message("ncid = %d varid = %d", ncid, varid);

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


563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
void  cdf_get_vara_float(int ncid, int varid, const size_t start[],
                         const size_t count[], float *fp)
{
  int status;

  status = nc_get_vara_float(ncid, varid, start, count, fp);

  if ( CDF_Debug || status != NC_NOERR )
    Message("ncid = %d varid = %d", ncid, varid);

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


578
579
580
581
582
583
584
585
586
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
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_put_var_double (int ncid, int varid, const double *dp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
594
595
596
597
598
599
{
  int status;

  status = nc_put_var_double(ncid, varid, dp);

  if ( CDF_Debug || status != NC_NOERR )
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
    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
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_var1_double(int ncid, int varid, const size_t index[], double *dp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
622
623
624
625
626
627
{
  int status;

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

  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_put_var1_double(int ncid, int varid, const size_t index[], const double *dp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
636
637
638
639
640
641
{
  int status;

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

  if ( CDF_Debug || status != NC_NOERR )
642
    Message("ncid = %d varid = %d val = %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

void cdf_get_var_text(int ncid, int varid, char *tp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
650
651
652
653
654
655
{
  int status;

  status = nc_get_var_text(ncid, varid, tp);

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

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

662
663

void cdf_get_var_short(int ncid, int varid, short *sp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
664
665
666
667
668
669
{
  int status;

  status = nc_get_var_short(ncid, varid, sp);

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

  if ( status != NC_NOERR )
673
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
674
675
}

676
677

void cdf_get_var_int(int ncid, int varid, int *ip)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
678
679
680
681
682
683
{
  int status;

  status = nc_get_var_int(ncid, varid, ip);

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

  if ( status != NC_NOERR )
687
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
688
689
}

690
691

void cdf_get_var_long(int ncid, int varid, long *lp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
692
693
694
695
696
697
{
  int status;

  status = nc_get_var_long(ncid, varid, lp);

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

  if ( status != NC_NOERR )
701
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
702
703
}

704
705

void cdf_get_var_float(int ncid, int varid, float *fp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
706
707
708
709
710
711
{
  int status;

  status = nc_get_var_float(ncid, varid, fp);

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

  if ( status != NC_NOERR )
715
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
716
717
}

718
719

void cdf_get_var_double(int ncid, int varid, double *dp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
720
721
722
723
724
725
{
  int status;

  status = nc_get_var_double(ncid, varid, dp);

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

  if ( status != NC_NOERR )
729
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
730
731
}

732
733
734

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
735
736
737
738
739
740
741
742
743
744
{
  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 )
745
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
746
747
}

748
749
750

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
751
752
753
754
755
756
{
  int status;

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

  if (CDF_Debug || status != NC_NOERR)
757
    Message("ncid = %d varid = %d att = %s text = %s",
Uwe Schulzweida's avatar
Uwe Schulzweida committed
758
759
760
	    ncid, varid, name, tp);

  if ( status != NC_NOERR )
761
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
762
763
}

764
765
766

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
767
768
769
770
771
772
{
  int status;

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

  if (CDF_Debug || status != NC_NOERR)
773
    Message("ncid = %d varid = %d att = %s val = %d",
Uwe Schulzweida's avatar
Uwe Schulzweida committed
774
775
776
	    ncid, varid, name, *ip);

  if ( status != NC_NOERR )
777
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
778
779
}

780
781
782

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
783
784
785
786
787
788
789
790
791
{
  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 )
792
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
793
794
}

795
796

void cdf_get_att_text(int ncid, int varid, char *name, char *tp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
797
798
799
800
801
802
{
  int status;

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

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

  if ( status != NC_NOERR )
806
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
807
808
}

809
810

void cdf_get_att_int(int ncid, int varid, char *name, int *ip)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
811
812
813
814
815
816
{
  int status;

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

  if (CDF_Debug || status != NC_NOERR)
817
    Message("ncid = %d varid = %d att = %s val = %d",
Uwe Schulzweida's avatar
Uwe Schulzweida committed
818
819
820
	    ncid, varid, name, *ip);

  if ( status != NC_NOERR )
821
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
822
823
}

824

Uwe Schulzweida's avatar
Uwe Schulzweida committed
825
826
827
828
829
830
831
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 )
832
    Message("ncid = %d varid = %d att = %s val = %.9g",
Uwe Schulzweida's avatar
Uwe Schulzweida committed
833
834
835
	    ncid, varid, name, *dp);

  if ( status != NC_NOERR )
836
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
837
838
}

839

Uwe Schulzweida's avatar
Uwe Schulzweida committed
840
void cdf_inq_att(int ncid, int varid, const char *name, nc_type *xtypep,
841
		 size_t *lenp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
842
843
844
845
846
847
{
  int status;

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

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

  if ( status != NC_NOERR )
851
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
852
853
}

854
855

void cdf_inq_atttype(int ncid, int varid, const char *name, nc_type * xtypep)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
856
857
858
859
860
861
{
  int status;

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

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

  if ( status != NC_NOERR )
865
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
866
867
}

868
869

void cdf_inq_attlen(int ncid, int varid, const char *name, size_t * lenp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
870
871
872
873
874
875
{
  int status;

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

  if (CDF_Debug || status != NC_NOERR)
876
    Message("ncid = %d varid = %d name = %s len = %d",
Uwe Schulzweida's avatar
Uwe Schulzweida committed
877
878
879
	    ncid, varid, name, *lenp);

  if ( status != NC_NOERR )
880
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
881
882
}

883
884

void cdf_inq_attname(int ncid, int varid, int attnum, char *name)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
885
886
887
888
889
890
{
  int status;

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

  if (CDF_Debug || status != NC_NOERR)
891
    Message("ncid = %d varid = %d attnum = %d name = %s",
Uwe Schulzweida's avatar
Uwe Schulzweida committed
892
893
894
	    ncid, varid, attnum, name);

  if ( status != NC_NOERR )
895
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
896
897
}

898
899

void cdf_inq_attid(int ncid, int varid, const char *name, int *attnump)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
900
901
902
903
904
905
{
  int status;

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

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

  if ( status != NC_NOERR )
909
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
910
911
912
}

#endif
913
914
915
916
917
918
919
920
921
/*
 * Local Variables:
 * c-file-style: "Java"
 * c-basic-offset: 2
 * indent-tabs-mode: nil
 * show-trailing-whitespace: t
 * require-trailing-newline: t
 * End:
 */