netCDF  4.2.1.1
 All Data Structures Files Functions Variables Typedefs Macros Groups Pages
dvar.c
Go to the documentation of this file.
1 
8 #include "ncdispatch.h"
9 #include "netcdf_f.h"
10 
206 int
207 nc_def_var(int ncid, const char *name, nc_type xtype,
208  int ndims, const int *dimidsp, int *varidp)
209 {
210  NC* ncp;
211  int stat = NC_NOERR;
212 
213  if ((stat = NC_check_id(ncid, &ncp)))
214  return stat;
215  return ncp->dispatch->def_var(ncid, name, xtype, ndims,
216  dimidsp, varidp);
217 }
279 int
280 nc_rename_var(int ncid, int varid, const char *name)
281 {
282  NC* ncp;
283  int stat = NC_check_id(ncid, &ncp);
284  if(stat != NC_NOERR) return stat;
285  return ncp->dispatch->rename_var(ncid, varid, name);
286 }
292 int
293 NC_is_recvar(int ncid, int varid, size_t* nrecs)
294 {
295  int status = NC_NOERR;
296  int unlimid;
297  int ndims;
298  int dimset[NC_MAX_VAR_DIMS];
299 
300  status = nc_inq_unlimdim(ncid,&unlimid);
301  if(status != NC_NOERR) return 0; /* no unlimited defined */
302  status = nc_inq_varndims(ncid,varid,&ndims);
303  if(status != NC_NOERR) return 0; /* no unlimited defined */
304  if(ndims == 0) return 0; /* scalar */
305  status = nc_inq_vardimid(ncid,varid,dimset);
306  if(status != NC_NOERR) return 0; /* no unlimited defined */
307  status = nc_inq_dim(ncid,dimset[0],NULL,nrecs);
308  if(status != NC_NOERR) return 0;
309  return (dimset[0] == unlimid ? 1: 0);
310 }
311 
312 /* Ok to use NC pointers because
313  all IOSP's will use that structure,
314  but not ok to use e.g. NC_Var pointers
315  because they may be different structure
316  entirely.
317 */
318 
327 int
328 nctypelen(nc_type type)
329 {
330  switch(type){
331  case NC_CHAR :
332  return((int)sizeof(char));
333  case NC_BYTE :
334  return((int)sizeof(signed char));
335  case NC_SHORT :
336  return(int)(sizeof(short));
337  case NC_INT :
338  return((int)sizeof(int));
339  case NC_FLOAT :
340  return((int)sizeof(float));
341  case NC_DOUBLE :
342  return((int)sizeof(double));
343 
344  /* These can occur in netcdf-3 code */
345  case NC_UBYTE :
346  return((int)sizeof(unsigned char));
347  case NC_USHORT :
348  return((int)(sizeof(unsigned short)));
349  case NC_UINT :
350  return((int)sizeof(unsigned int));
351  case NC_INT64 :
352  return((int)sizeof(signed long long));
353  case NC_UINT64 :
354  return((int)sizeof(unsigned long long));
355 #ifdef USE_NETCDF4
356  case NC_STRING :
357  return((int)sizeof(char*));
358 #endif /*USE_NETCDF4*/
359 
360  default:
361  return -1;
362  }
363 }
364 
368 int
369 NC_atomictypelen(nc_type xtype)
370 {
371  int sz = 0;
372  switch(xtype) {
373  case NC_NAT: sz = 0; break;
374  case NC_BYTE: sz = sizeof(signed char); break;
375  case NC_CHAR: sz = sizeof(char); break;
376  case NC_SHORT: sz = sizeof(short); break;
377  case NC_INT: sz = sizeof(int); break;
378  case NC_FLOAT: sz = sizeof(float); break;
379  case NC_DOUBLE: sz = sizeof(double); break;
380  case NC_INT64: sz = sizeof(signed long long); break;
381  case NC_UBYTE: sz = sizeof(unsigned char); break;
382  case NC_USHORT: sz = sizeof(unsigned short); break;
383  case NC_UINT: sz = sizeof(unsigned int); break;
384  case NC_UINT64: sz = sizeof(unsigned long long); break;
385 #ifdef USE_NETCDF4
386  case NC_STRING: sz = sizeof(char*); break;
387 #endif
388  default: break;
389  }
390  return sz;
391 }
392 
396 char *
397 NC_atomictypename(nc_type xtype)
398 {
399  char* nm = NULL;
400  switch(xtype) {
401  case NC_NAT: nm = "undefined"; break;
402  case NC_BYTE: nm = "byte"; break;
403  case NC_CHAR: nm = "char"; break;
404  case NC_SHORT: nm = "short"; break;
405  case NC_INT: nm = "int"; break;
406  case NC_FLOAT: nm = "float"; break;
407  case NC_DOUBLE: nm = "double"; break;
408  case NC_INT64: nm = "int64"; break;
409  case NC_UBYTE: nm = "ubyte"; break;
410  case NC_USHORT: nm = "ushort"; break;
411  case NC_UINT: nm = "uint"; break;
412  case NC_UINT64: nm = "uint64"; break;
413 #ifdef USE_NETCDF4
414  case NC_STRING: nm = "string"; break;
415 #endif
416  default: break;
417  }
418  return nm;
419 }
420 
425 int
426 NC_getshape(int ncid, int varid, int ndims, size_t* shape)
427 {
428  int dimids[NC_MAX_VAR_DIMS];
429  int i;
430  int status = NC_NOERR;
431 
432  if ((status = nc_inq_vardimid(ncid, varid, dimids)))
433  return status;
434  for(i = 0; i < ndims; i++)
435  if ((status = nc_inq_dimlen(ncid, dimids[i], &shape[i])))
436  break;
437 
438  return status;
439 }
440 
441 #ifdef USE_NETCDF4
442 
467 int
468 nc_set_var_chunk_cache(int ncid, int varid, size_t size, size_t nelems,
469  float preemption)
470 {
471  NC* ncp;
472  int stat = NC_check_id(ncid, &ncp);
473  if(stat != NC_NOERR) return stat;
474  return ncp->dispatch->set_var_chunk_cache(ncid, varid, size,
475  nelems, preemption);
476 }
477 
505 int
506 nc_get_var_chunk_cache(int ncid, int varid, size_t *sizep, size_t *nelemsp,
507  float *preemptionp)
508 {
509  NC* ncp;
510  int stat = NC_check_id(ncid, &ncp);
511  if(stat != NC_NOERR) return stat;
512  return ncp->dispatch->get_var_chunk_cache(ncid, varid, sizep,
513  nelemsp, preemptionp);
514 }
515 
529 int
530 nc_free_string(size_t len, char **data)
531 {
532  int i;
533  for (i = 0; i < len; i++)
534  free(data[i]);
535  return NC_NOERR;
536 }
537 
538 int
539 nc_def_var_deflate(int ncid, int varid, int shuffle, int deflate, int deflate_level)
540 {
541  NC* ncp;
542  int stat = NC_check_id(ncid,&ncp);
543  if(stat != NC_NOERR) return stat;
544  return ncp->dispatch->def_var_deflate(ncid,varid,shuffle,deflate,deflate_level);
545 }
546 
547 int
548 nc_def_var_fletcher32(int ncid, int varid, int fletcher32)
549 {
550  NC* ncp;
551  int stat = NC_check_id(ncid,&ncp);
552  if(stat != NC_NOERR) return stat;
553  return ncp->dispatch->def_var_fletcher32(ncid,varid,fletcher32);
554 }
555 
556 int
557 nc_def_var_chunking(int ncid, int varid, int storage,
558  const size_t *chunksizesp)
559 {
560  NC* ncp;
561  int stat = NC_check_id(ncid, &ncp);
562  if(stat != NC_NOERR) return stat;
563  return ncp->dispatch->def_var_chunking(ncid, varid, storage,
564  chunksizesp);
565 }
566 
567 int
568 nc_def_var_fill(int ncid, int varid, int no_fill, const void *fill_value)
569 {
570  NC* ncp;
571  int stat = NC_check_id(ncid,&ncp);
572  if(stat != NC_NOERR) return stat;
573  return ncp->dispatch->def_var_fill(ncid,varid,no_fill,fill_value);
574 }
575 
576 int
577 nc_def_var_endian(int ncid, int varid, int endian)
578 {
579  NC* ncp;
580  int stat = NC_check_id(ncid,&ncp);
581  if(stat != NC_NOERR) return stat;
582  return ncp->dispatch->def_var_endian(ncid,varid,endian);
583 }
584 
585 #endif /* USE_NETCDF4 */

Generated on Wed Aug 22 2012 14:39:39 for netCDF. NetCDF is a Unidata library.