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
#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"
11
#include "cdi_int.h"
Uwe Schulzweida's avatar
Uwe Schulzweida committed
12
#include "cdf_int.h"
13
#include "namespace.h"
Uwe Schulzweida's avatar
Uwe Schulzweida committed
14
15
16
17
18
19

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

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

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

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

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

59
60
  if ( cdiNcChunksizehint != CDI_UNDEFID )
    chunksizehint = (size_t)cdiNcChunksizehint;
61

62
  cdi_nc__create_funcp my_nc__create =
63
    (cdi_nc__create_funcp)namespaceSwitchGet(NSSWITCH_NC__CREATE).func;
64
  status = my_nc__create(path, cmode, initialsz, &chunksizehint, ncidp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
65
66

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

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

72
  if ( status != NC_NOERR ) Error("%s: %s", path, nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
73
74
75

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

76
  if ( status != NC_NOERR ) Error("%s: %s", path, nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
77
78
79
}


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

#if  defined  (HAVE_LIBNC_DAP)
88
  if ( strncmp(path, "http:", 5) == 0 || strncmp(path, "https:", 6) == 0 ) dapfile = TRUE;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
89
90
91
92
93
94
95
96
#endif

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

99
#if defined (HAVE_STRUCT_STAT_ST_BLKSIZE)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
100
      chunksizehint = (size_t) filestat.st_blksize * 4;
101
#endif
102
      /*
Uwe Schulzweida's avatar
Uwe Schulzweida committed
103
      if ( chunksizehint < ChunkSizeMin ) chunksizehint = ChunkSizeMin;
104
      */
105
106
      if ( cdiNcChunksizehint != CDI_UNDEFID ) chunksizehint = cdiNcChunksizehint;

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

110
      if ( CDF_Debug ) Message("chunksizehint %d", chunksizehint);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
111
112
    }

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

116
  if ( CDF_Debug && status != NC_NOERR ) Message("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
117
118

  return (status);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
119
120
121
122
123
124
125
126
127
}


void cdf_close(int ncid)
{
  int status;

  status = nc_close(ncid);

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


void cdf_redef(int ncid)
{
  int status;

  status = nc_redef(ncid);

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


void cdf_enddef(int ncid)
{
  int status;

  status = nc_enddef(ncid);

148
  if ( status != NC_NOERR ) 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
159
160
161
162
163
164
165
void cdf__enddef(const int ncid, const size_t hdr_pad)
{
  int status;
  const size_t v_align   = 4UL; /* [B] Alignment of beginning of data section for fixed variables */
  const size_t v_minfree = 0UL; /* [B] Pad at end of data section for fixed size variables */
  const size_t r_align   = 4UL; /* [B] Alignment of beginning of data section for record variables */

  /* nc_enddef(ncid) is equivalent to nc__enddef(ncid, 0, 4, 0, 4) */
  status = nc__enddef(ncid, hdr_pad, v_align, v_minfree, r_align);

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


Uwe Schulzweida's avatar
Uwe Schulzweida committed
166
167
168
169
170
171
void cdf_sync(int ncid)
{
  int status;

  status = nc_sync(ncid);

172
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
173
174
175
}


Uwe Schulzweida's avatar
Uwe Schulzweida committed
176
177
178
179
180
181
182
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 )
183
    Message("ncid = %d ndims = %d nvars = %d ngatts = %d unlimid = %d",
Uwe Schulzweida's avatar
Uwe Schulzweida committed
184
185
	    ncid, *ndimsp, *nvarsp, *ngattsp, *unlimdimidp);

186
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
187
188
189
190
191
192
193
194
195
196
}


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

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

202
203

void cdf_inq_dimid(int ncid, const char *name, int *dimidp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
204
205
206
207
208
{
  int status;

  status = nc_inq_dimid(ncid, name, dimidp);

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

212
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
213
214
}

215
216

void cdf_inq_dim(int ncid, int dimid, char *name, size_t * lengthp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
217
218
219
220
221
222
{
  int status;

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

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

225
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
226
227
}

228
229

void cdf_inq_dimname(int ncid, int dimid, char *name)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
230
231
232
233
234
235
{
  int status;

  status = nc_inq_dimname(ncid, dimid, name);

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

238
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
239
240
}

241
242

void cdf_inq_dimlen(int ncid, int dimid, size_t * lengthp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
243
244
245
246
247
248
{
  int status;

  status = nc_inq_dimlen(ncid, dimid, lengthp);

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

251
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
252
253
}

254
255

void cdf_def_var(int ncid, const char *name, nc_type xtype, int ndims,
256
                 const int dimids[], int *varidp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
257
{
258
  cdi_cdf_def_var_funcp my_cdf_def_var
259
    = (cdi_cdf_def_var_funcp)namespaceSwitchGet(NSSWITCH_CDF_DEF_VAR).func;
260
261
  my_cdf_def_var(ncid, name, xtype, ndims, dimids, varidp);
}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
262

263
264
265
266
267
void
cdf_def_var_serial(int ncid, const char *name, nc_type xtype, int ndims,
                   const int dimids[], int *varidp)
{
  int status = nc_def_var(ncid, name, xtype, ndims, dimids, varidp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
268
269

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

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

276

277

Uwe Schulzweida's avatar
Uwe Schulzweida committed
278
279
280
281
282
283
284
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 )
285
    Message("ncid = %d  name = %s  varid = %d ", ncid, name, *varidp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
286

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


void cdf_inq_nvars(int ncid, int *nvarsp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
292
293
294
295
296
297
{
  int status;

  status = nc_inq_nvars(ncid, nvarsp);

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

300
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
301
302
}

303
304
305

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
306
307
308
309
310
311
{
  int status;

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

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

315
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
316
317
}

318
319

void cdf_inq_varname(int ncid, int varid, char *name)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
320
321
322
323
324
325
{
  int status;

  status = nc_inq_varname(ncid, varid, name);

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

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

331
332

void cdf_inq_vartype(int ncid, int varid, nc_type *xtypep)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
333
334
335
336
337
338
{
  int status;

  status = nc_inq_vartype(ncid, varid, xtypep);

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

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

344
345

void cdf_inq_varndims(int ncid, int varid, int *ndimsp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
346
347
348
349
350
351
{
  int status;

  status = nc_inq_varndims(ncid, varid, ndimsp);

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

354
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
355
356
}

357
358

void cdf_inq_vardimid(int ncid, int varid, int dimids[])
Uwe Schulzweida's avatar
Uwe Schulzweida committed
359
360
361
362
363
364
{
  int status;

  status = nc_inq_vardimid(ncid, varid, dimids);

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

367
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
368
369
}

370
371

void cdf_inq_varnatts(int ncid, int varid, int *nattsp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
372
373
374
375
376
{
  int status;

  status = nc_inq_varnatts(ncid, varid, nattsp);

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

380
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
381
382
}

383
384

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

  status = nc_put_var_text(ncid, varid, tp);

390
391
  if ( CDF_Debug || status != NC_NOERR )
    Message("%d %d %s", ncid, varid, tp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
392

393
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
394
395
396
}


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

  status = nc_put_var_short(ncid, varid, sp);

403
404
  if ( CDF_Debug || status != NC_NOERR )
    Message("%d %d %hd", ncid, varid, *sp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
405

406
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
407
408
}

409
410

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

  status = nc_put_var_int(ncid, varid, ip);

416
417
  if ( CDF_Debug || status != NC_NOERR )
    Message("%d %d %d", ncid, varid, *ip);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
418

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

422
423

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

  status = nc_put_var_long(ncid, varid, lp);

429
430
  if ( CDF_Debug || status != NC_NOERR )
    Message("%d %d %ld", ncid, varid, *lp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
431

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

435
436

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

  status = nc_put_var_float(ncid, varid, fp);

442
443
  if ( CDF_Debug || status != NC_NOERR )
    Message("%d %d %f", ncid, varid, *fp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
444

445
  if ( status != NC_NOERR ) 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
461
462
463
464
465
466
    {
      char name[256];
      nc_inq_varname(ncid, varid, name);
      Message("varname = %s", name);
    }

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

469

470
471
472
473
474
475
476
477
478
479
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);

480
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
481
482
483
484
485
}


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
486
487
488
489
490
491
{
  int status;

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

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

494
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
495
496
}

497

498
499
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
500
501
502
503
504
505
{
  int status;

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

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

508
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
509
510
511
}


512
513
514
515
516
517
518
519
520
521
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);

522
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
523
524
525
}


526
527
528
529
530
531
532
533
534
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
535

536
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
537
538
}

539

540
541
542
543
544
545
546
547
548
549
550
551
552
void  cdf_get_vara_uchar(int ncid, int varid, const size_t start[], const size_t count[], unsigned char *tp)
{
  int status;

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

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

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


553
void cdf_put_var_double(int ncid, int varid, const double *dp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
554
555
556
557
558
559
{
  int status;

  status = nc_put_var_double(ncid, varid, dp);

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

562
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
563
564
565
566
567
568
569
570
571
572
573
}


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
574

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

578
579

void cdf_get_var1_double(int ncid, int varid, const size_t index[], double *dp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
580
581
582
583
584
585
{
  int status;

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

  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 ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
589
590
}

591
592

void cdf_put_var1_double(int ncid, int varid, const size_t index[], const double *dp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
593
594
595
596
597
598
{
  int status;

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

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

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

604
605

void cdf_get_var_text(int ncid, int varid, char *tp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
606
607
608
609
610
611
{
  int status;

  status = nc_get_var_text(ncid, varid, tp);

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

614
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
615
616
}

617
618

void cdf_get_var_short(int ncid, int varid, short *sp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
619
620
621
622
623
624
{
  int status;

  status = nc_get_var_short(ncid, varid, sp);

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

627
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
628
629
}

630
631

void cdf_get_var_int(int ncid, int varid, int *ip)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
632
633
634
635
636
637
{
  int status;

  status = nc_get_var_int(ncid, varid, ip);

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

640
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
641
642
}

643
644

void cdf_get_var_long(int ncid, int varid, long *lp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
645
646
647
648
649
650
{
  int status;

  status = nc_get_var_long(ncid, varid, lp);

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

653
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
654
655
}

656
657

void cdf_get_var_float(int ncid, int varid, float *fp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
658
659
660
661
662
663
{
  int status;

  status = nc_get_var_float(ncid, varid, fp);

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

666
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
667
668
}

669
670

void cdf_get_var_double(int ncid, int varid, double *dp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
671
672
673
674
675
{
  int status;

  status = nc_get_var_double(ncid, varid, dp);

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

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

682
683
684

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
685
686
687
688
689
{
  int status;

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

690
691
  if ( CDF_Debug || status != NC_NOERR )
    Message("%d %d %s %d %d", ncid_in, varid_out, name, ncid_out, varid_out);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
692

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

696
697
698

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
699
700
701
702
703
{
  int status;

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

704
  if ( CDF_Debug || status != NC_NOERR )
705
    Message("ncid = %d varid = %d att = %s text = %s",
Uwe Schulzweida's avatar
Uwe Schulzweida committed
706
707
	    ncid, varid, name, tp);

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

711
712
713

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
714
715
716
717
718
{
  int status;

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

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

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

725
726
727

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
728
729
730
731
732
{
  int status;

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

733
734
  if ( CDF_Debug || status != NC_NOERR )
    Message("%d %d %f", ncid, varid, *dp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
735

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

739

740
void cdf_get_att_text(int ncid, int varid, const char *name, char *tp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
741
742
743
744
745
{
  int status;

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

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

749
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
750
751
}

752
753
754
755
756
757
758
759
760
761
762
763
764
765
void cdf_get_att_string(int ncid, int varid, const char *name, char **tp)
{
#if  defined  (HAVE_NETCDF4)
  int status;

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

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

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

766

767
void cdf_get_att_int(int ncid, int varid, const char *name, int *ip)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
768
769
770
771
772
{
  int status;

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

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

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

779

780
void cdf_get_att_double(int ncid, int varid, const char *name, double *dp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
781
782
783
784
785
786
{
  int status;

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

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

790
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
791
792
}

793

Uwe Schulzweida's avatar
Uwe Schulzweida committed
794
void cdf_inq_att(int ncid, int varid, const char *name, nc_type *xtypep,
795
		 size_t *lenp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
796
797
798
799
800
801
{
  int status;

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

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

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

807
808

void cdf_inq_atttype(int ncid, int varid, const char *name, nc_type * xtypep)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
809
810
811
812
813
814
{
  int status;

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

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

817
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
818
819
}

820
821

void cdf_inq_attlen(int ncid, int varid, const char *name, size_t * lenp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
822
823
824
825
826
{
  int status;

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

827
828
  if ( CDF_Debug || status != NC_NOERR )
    Message("ncid = %d varid = %d name = %s len = %d", ncid, varid, name, *lenp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
829

830
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
831
832
}

833
834

void cdf_inq_attname(int ncid, int varid, int attnum, char *name)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
835
836
837
838
839
{
  int status;

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

840
841
  if ( CDF_Debug || status != NC_NOERR )
    Message("ncid = %d varid = %d attnum = %d name = %s", ncid, varid, attnum, name);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
842

843
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
844
845
}

846
847

void cdf_inq_attid(int ncid, int varid, const char *name, int *attnump)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
848
849
850
851
852
853
{
  int status;

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

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

856
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
857
858
859
}

#endif
860
861
862
863
864
865
866
867
868
/*
 * Local Variables:
 * c-file-style: "Java"
 * c-basic-offset: 2
 * indent-tabs-mode: nil
 * show-trailing-whitespace: t
 * require-trailing-newline: t
 * End:
 */