cdf_int.c 20 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"
12
#include "cdf.h"
Uwe Schulzweida's avatar
Uwe Schulzweida committed
13
#include "cdf_int.h"
14
#include "namespace.h"
Uwe Schulzweida's avatar
Uwe Schulzweida committed
15
16

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

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

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

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

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

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

55
56
  if ( cdiNcChunksizehint != CDI_UNDEFID )
    chunksizehint = (size_t)cdiNcChunksizehint;
57

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

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

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

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

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

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


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

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

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

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

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

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

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

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

115
  return status;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
116
117
118
119
120
}


void cdf_close(int ncid)
{
121
  int status = nc_close(ncid);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
122

123
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
124
125
126
127
128
}


void cdf_redef(int ncid)
{
129
  int status = nc_redef(ncid);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
130

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


void cdf_enddef(int ncid)
{
137
  int status = nc_enddef(ncid);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
138

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


Uwe Schulzweida's avatar
Uwe Schulzweida committed
143
144
145
146
147
148
149
void cdf__enddef(const int ncid, const size_t hdr_pad)
{
  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) */
150
  int status = nc__enddef(ncid, hdr_pad, v_align, v_minfree, r_align);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
151
152
153
154
155

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


Uwe Schulzweida's avatar
Uwe Schulzweida committed
156
157
void cdf_sync(int ncid)
{
158
  int status = nc_sync(ncid);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
159

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


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

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

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


void cdf_def_dim(int ncid, const char *name, size_t len, int *dimidp)
{
178
  int status = nc_def_dim(ncid, name, len, dimidp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
179
180

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

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

186
187

void cdf_inq_dimid(int ncid, const char *name, int *dimidp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
188
{
189
  int status = nc_inq_dimid(ncid, name, dimidp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
190

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

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

197
198

void cdf_inq_dim(int ncid, int dimid, char *name, size_t * lengthp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
199
{
200
  int status = nc_inq_dim(ncid, dimid, name, lengthp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
201
202

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

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

208
209

void cdf_inq_dimname(int ncid, int dimid, char *name)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
210
{
211
  int status = nc_inq_dimname(ncid, dimid, name);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
212
213

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

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

219
220

void cdf_inq_dimlen(int ncid, int dimid, size_t * lengthp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
221
{
222
  int status = nc_inq_dimlen(ncid, dimid, lengthp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
223
224

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

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

230
231

void cdf_def_var(int ncid, const char *name, nc_type xtype, int ndims,
232
                 const int dimids[], int *varidp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
233
{
234
  cdi_cdf_def_var_funcp my_cdf_def_var
235
    = (cdi_cdf_def_var_funcp)namespaceSwitchGet(NSSWITCH_CDF_DEF_VAR).func;
236
237
  my_cdf_def_var(ncid, name, xtype, ndims, dimids, varidp);
}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
238

239
240
241
242
243
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
244
245

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

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

252

253

Uwe Schulzweida's avatar
Uwe Schulzweida committed
254
255
void cdf_inq_varid(int ncid, const char *name, int *varidp)
{
256
  int status = nc_inq_varid(ncid, name, varidp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
257
258

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

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


void cdf_inq_nvars(int ncid, int *nvarsp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
266
{
267
  int status = nc_inq_nvars(ncid, nvarsp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
268
269

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

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

275
276
277

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
278
{
279
  int status = nc_inq_var(ncid, varid, name, xtypep, ndimsp, dimids, nattsp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
280
281

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

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

288
289

void cdf_inq_varname(int ncid, int varid, char *name)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
290
{
291
  int status = nc_inq_varname(ncid, varid, name);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
292
293

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

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

299
300

void cdf_inq_vartype(int ncid, int varid, nc_type *xtypep)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
301
{
302
  int status = nc_inq_vartype(ncid, varid, xtypep);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
303
304

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

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

310
311

void cdf_inq_varndims(int ncid, int varid, int *ndimsp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
312
{
313
  int status = nc_inq_varndims(ncid, varid, ndimsp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
314
315

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

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

321
322

void cdf_inq_vardimid(int ncid, int varid, int dimids[])
Uwe Schulzweida's avatar
Uwe Schulzweida committed
323
{
324
  int status = nc_inq_vardimid(ncid, varid, dimids);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
325
326

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

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

332
333

void cdf_inq_varnatts(int ncid, int varid, int *nattsp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
334
{
335
  int status = nc_inq_varnatts(ncid, varid, nattsp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
336

337
  if ( CDF_Debug || status != NC_NOERR )
338
    Message("ncid = %d varid = %d nattsp = %d", ncid, varid, *nattsp);
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_put_var_text(int ncid, int varid, const char *tp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
345
{
346
  int status = nc_put_var_text(ncid, varid, tp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
347

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

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


355
void cdf_put_var_short(int ncid, int varid, const short *sp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
356
{
357
  int status = nc_put_var_short(ncid, varid, sp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
358

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

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

365
366

void cdf_put_var_int(int ncid, int varid, const int *ip)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
367
{
368
  int status = nc_put_var_int(ncid, varid, ip);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
369

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

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

376
377

void cdf_put_var_long(int ncid, int varid, const long *lp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
378
{
379
  int status = nc_put_var_long(ncid, varid, lp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
380

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

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

387
388

void cdf_put_var_float(int ncid, int varid, const float *fp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
389
{
390
  int status = nc_put_var_float(ncid, varid, fp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
391

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

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

398

399
400
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
401
{
402
  int status = nc_put_vara_double(ncid, varid, start, count, dp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
403
404

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

  if ( status != NC_NOERR )
408
409
410
411
412
413
414
    {
      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
415
416
}

417

418
419
420
void  cdf_put_vara_float(int ncid, int varid, const size_t start[],
                         const size_t count[], const float *fp)
{
421
  int status = nc_put_vara_float(ncid, varid, start, count, fp);
422
423
424
425

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

426
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
427
428
429
430
431
}


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
432
{
433
  int status = nc_get_vara_int(ncid, varid, start, count, dp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
434
435

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

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

441

442
443
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
444
{
445
  int status = nc_get_vara_double(ncid, varid, start, count, dp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
446
447

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

450
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
451
452
453
}


454
455
456
void  cdf_get_vara_float(int ncid, int varid, const size_t start[],
                         const size_t count[], float *fp)
{
457
  int status = nc_get_vara_float(ncid, varid, start, count, fp);
458
459
460
461

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

462
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
463
464
465
}


466
467
468
void  cdf_get_vara_text(int ncid, int varid, const size_t start[],
			const size_t count[], char *tp)
{
469
  int status = nc_get_vara_text(ncid, varid, start, count, tp);
470
471
472

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

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

477

478
479
void  cdf_get_vara_uchar(int ncid, int varid, const size_t start[], const size_t count[], unsigned char *tp)
{
480
  int status = nc_get_vara_uchar(ncid, varid, start, count, tp);
481
482
483
484
485
486
487
488

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

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


489
void cdf_put_var_double(int ncid, int varid, const double *dp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
490
{
491
  int status = nc_put_var_double(ncid, varid, dp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
492
493

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

496
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
497
498
499
500
501
}


void cdf_get_var1_text(int ncid, int varid, const size_t index[], char *tp)
{
502
  int status = nc_get_var1_text(ncid, varid, index, tp);
503
504
505

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

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

510
511

void cdf_get_var1_double(int ncid, int varid, const size_t index[], double *dp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
512
{
513
  int status = nc_get_var1_double(ncid, varid, index, dp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
514
515

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

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

521
522

void cdf_put_var1_double(int ncid, int varid, const size_t index[], const double *dp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
523
{
524
  int status = nc_put_var1_double(ncid, varid, index, dp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
525
526

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

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

532
533

void cdf_get_var_text(int ncid, int varid, char *tp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
534
{
535
  int status = nc_get_var_text(ncid, varid, tp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
536
537

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

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

543
544

void cdf_get_var_short(int ncid, int varid, short *sp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
545
{
546
  int status = nc_get_var_short(ncid, varid, sp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
547
548

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

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

554
555

void cdf_get_var_int(int ncid, int varid, int *ip)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
556
{
557
  int status = nc_get_var_int(ncid, varid, ip);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
558
559

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

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

565
566

void cdf_get_var_long(int ncid, int varid, long *lp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
567
{
568
  int status = nc_get_var_long(ncid, varid, lp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
569
570

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

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

576
577

void cdf_get_var_float(int ncid, int varid, float *fp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
578
{
579
  int status = nc_get_var_float(ncid, varid, fp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
580
581

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

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

587
588

void cdf_get_var_double(int ncid, int varid, double *dp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
589
{
590
  int status = nc_get_var_double(ncid, varid, dp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
591

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

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

598
599
600

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
601
{
602
  int status = nc_copy_att(ncid_in, varid_in, name, ncid_out, varid_out);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
603

604
605
  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
606

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

610
611
612

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
613
{
614
  int status = nc_put_att_text(ncid, varid, name, len, tp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
615

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

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

622
623
624

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
625
{
626
  int status = nc_put_att_int(ncid, varid, name, xtype, len, ip);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
627

628
629
  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
630

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

634

635
636
637
void cdf_put_att_float(int ncid, int varid, const char *name, nc_type xtype,
                       size_t len, const float *dp)
{
638
  int status = nc_put_att_float(ncid, varid, name, xtype, len, dp);
639
640
641
642
643
644
645
646

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


647
648
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
649
{
650
  int status = nc_put_att_double(ncid, varid, name, xtype, len, dp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
651

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

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

658

659
void cdf_get_att_text(int ncid, int varid, const char *name, char *tp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
660
{
661
  int status = nc_get_att_text(ncid, varid, name, tp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
662

663
  if ( CDF_Debug || status != NC_NOERR )
664
    Message("ncid = %d varid = %d name = %s", ncid, varid, name);
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
671
void cdf_get_att_string(int ncid, int varid, const char *name, char **tp)
{
#if  defined  (HAVE_NETCDF4)
672
  int status = nc_get_att_string(ncid, varid, name, tp);
673
674
675
676
677
678
679
680

  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
}

681

682
void cdf_get_att_int(int ncid, int varid, const char *name, int *ip)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
683
{
684
  int status = nc_get_att_int(ncid, varid, name, ip);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
685

686
687
  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
688

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

692

693
void cdf_get_att_double(int ncid, int varid, const char *name, double *dp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
694
695
696
697
698
699
{
  int status;

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

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

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

705

Uwe Schulzweida's avatar
Uwe Schulzweida committed
706
void cdf_inq_att(int ncid, int varid, const char *name, nc_type *xtypep,
707
		 size_t *lenp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
708
{
709
  int status = nc_inq_att(ncid, varid, name, xtypep, lenp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
710
711

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

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

717
718

void cdf_inq_atttype(int ncid, int varid, const char *name, nc_type * xtypep)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
719
{
720
  int status = nc_inq_atttype(ncid, varid, name, xtypep);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
721
722

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

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

728
729

void cdf_inq_attlen(int ncid, int varid, const char *name, size_t * lenp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
730
{
731
  int status = nc_inq_attlen(ncid, varid, name, lenp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
732

733
  if ( CDF_Debug || status != NC_NOERR )
734
    Message("ncid = %d varid = %d att = %s len = %d", ncid, varid, name, *lenp);
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_inq_attname(int ncid, int varid, int attnum, char *name)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
741
{
742
  int status = nc_inq_attname(ncid, varid, attnum, name);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
743

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

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

750
751

void cdf_inq_attid(int ncid, int varid, const char *name, int *attnump)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
752
{
753
  int status = nc_inq_attid(ncid, varid, name, attnump);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
754
755

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

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

#endif
762
763
764
765
766
767
768
769
770
/*
 * Local Variables:
 * c-file-style: "Java"
 * c-basic-offset: 2
 * indent-tabs-mode: nil
 * show-trailing-whitespace: t
 * require-trailing-newline: t
 * End:
 */