cdf_int.c 20.6 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

extern int CDF_Debug;

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

static size_t ChunkSizeMin = MIN_BUF_SIZE;
24
*/
Uwe Schulzweida's avatar
Uwe Schulzweida committed
25
26
27
28
void cdf_create(const char *path, int cmode, int *ncidp)
{
  int status;
  int oldfill;
29
30
  size_t initialsz = 0, chunksizehint = 0;
  /*
Uwe Schulzweida's avatar
Uwe Schulzweida committed
31
#if defined (HAVE_STRUCT_STAT_ST_BLKSIZE)
32
  struct stat filestat;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
33
34
35
36
37
38
39
40
  char basename[1024];
  char *pend;

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

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

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

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

57
58
  if ( cdiNcChunksizehint != CDI_UNDEFID )
    chunksizehint = (size_t)cdiNcChunksizehint;
59

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

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

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

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

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

74
  if ( status != NC_NOERR ) Error("%s: %s", path, 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 ( strncmp(path, "http:", 5) == 0 || strncmp(path, "https:", 6) == 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
      */
103
104
      if ( cdiNcChunksizehint != CDI_UNDEFID )
        chunksizehint = (size_t)cdiNcChunksizehint;
105

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

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

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

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

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


void cdf_close(int ncid)
{
  int status;

  status = nc_close(ncid);

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


void cdf_redef(int ncid)
{
  int status;

  status = nc_redef(ncid);

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


void cdf_enddef(int ncid)
{
  int status;

  status = nc_enddef(ncid);

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


Uwe Schulzweida's avatar
Uwe Schulzweida committed
151
152
153
154
155
156
157
158
159
160
161
162
163
164
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
165
166
167
168
169
170
void cdf_sync(int ncid)
{
  int status;

  status = nc_sync(ncid);

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


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

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


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

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

201
202

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

  status = nc_inq_dimid(ncid, name, dimidp);

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

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

214
215

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

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

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

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

227
228

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

  status = nc_inq_dimname(ncid, dimid, name);

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

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

240
241

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

  status = nc_inq_dimlen(ncid, dimid, lengthp);

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

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

253
254

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

262
263
264
265
266
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
267
268

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

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

275

276

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

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


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

  status = nc_inq_nvars(ncid, nvarsp);

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

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

302
303
304

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

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

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

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

317
318

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

  status = nc_inq_varname(ncid, varid, name);

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

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

330
331

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

  status = nc_inq_vartype(ncid, varid, xtypep);

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

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

343
344

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

  status = nc_inq_varndims(ncid, varid, ndimsp);

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

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

356
357

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

  status = nc_inq_vardimid(ncid, varid, dimids);

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

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

369
370

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

  status = nc_inq_varnatts(ncid, varid, nattsp);

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

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

382
383

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

  status = nc_put_var_text(ncid, varid, tp);

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

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


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

  status = nc_put_var_short(ncid, varid, sp);

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

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

408
409

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

  status = nc_put_var_int(ncid, varid, ip);

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

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

421
422

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

  status = nc_put_var_long(ncid, varid, lp);

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

431
  if ( status != NC_NOERR ) 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
{
  int status;

  status = nc_put_var_float(ncid, varid, fp);

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

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

447

448
449
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
450
451
452
453
454
455
{
  int status;

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

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

  if ( status != NC_NOERR )
459
460
461
462
463
464
465
    {
      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
466
467
}

468

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

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


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

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

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

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

496

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

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

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

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


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

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


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

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

538

539
540
541
542
543
544
545
546
547
548
549
550
551
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));
}


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

  status = nc_put_var_double(ncid, varid, dp);

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

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


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
573

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

577
578

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

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

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

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

590
591

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

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

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

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

603
604

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

  status = nc_get_var_text(ncid, varid, tp);

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

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

616
617

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

  status = nc_get_var_short(ncid, varid, sp);

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

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

629
630

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

  status = nc_get_var_int(ncid, varid, ip);

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

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

642
643

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

  status = nc_get_var_long(ncid, varid, lp);

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

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

655
656

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

  status = nc_get_var_float(ncid, varid, fp);

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

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

668
669

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

  status = nc_get_var_double(ncid, varid, dp);

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

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

681
682
683

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

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

689
690
  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
691

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

695
696
697

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

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

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

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

709
710
711

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
712
713
714
715
716
{
  int status;

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

717
718
  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
719

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

723

724
725
726
727
728
729
730
731
732
733
734
735
736
737
void cdf_put_att_float(int ncid, int varid, const char *name, nc_type xtype,
                       size_t len, const float *dp)
{
  int status;

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

  if ( CDF_Debug || status != NC_NOERR )
    Message("ncid = %d varid = %d att = %s val = %g", ncid, varid, name, *dp);

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


738
739
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
740
741
742
743
744
{
  int status;

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

745
  if ( CDF_Debug || status != NC_NOERR )
746
    Message("ncid = %d varid = %d att = %s val = %g", ncid, varid, name, *dp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
747

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

751

752
void cdf_get_att_text(int ncid, int varid, const char *name, char *tp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
753
754
755
756
757
{
  int status;

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

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

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

764
765
766
767
768
769
770
771
772
773
774
775
776
777
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
}

778

779
void cdf_get_att_int(int ncid, int varid, const char *name, int *ip)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
780
781
782
783
784
{
  int status;

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

785
786
  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
787

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

791

792
void cdf_get_att_double(int ncid, int varid, const char *name, double *dp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
793
794
795
796
797
798
{
  int status;

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

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

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

804

Uwe Schulzweida's avatar
Uwe Schulzweida committed
805
void cdf_inq_att(int ncid, int varid, const char *name, nc_type *xtypep,
806
		 size_t *lenp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
807
808
809
810
811
812
{
  int status;

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

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

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

818
819

void cdf_inq_atttype(int ncid, int varid, const char *name, nc_type * xtypep)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
820
821
822
823
824
825
{
  int status;

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

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

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

831
832

void cdf_inq_attlen(int ncid, int varid, const char *name, size_t * lenp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
833
834
835
836
837
{
  int status;

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

838
839
  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
840

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

844
845

void cdf_inq_attname(int ncid, int varid, int attnum, char *name)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
846
847
848
849
850
{
  int status;

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

851
852
  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
853

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

857
858

void cdf_inq_attid(int ncid, int varid, const char *name, int *attnump)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
859
860
861
862
863
864
{
  int status;

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

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

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

#endif
871
872
873
874
875
876
877
878
879
/*
 * Local Variables:
 * c-file-style: "Java"
 * c-basic-offset: 2
 * indent-tabs-mode: nil
 * show-trailing-whitespace: t
 * require-trailing-newline: t
 * End:
 */