netCDF 4.2.1.1
/usr/src/RPM/BUILD/libnetcdf7-seq-4.2.1.1/libdispatch/dvar.c
Go to the documentation of this file.
00001 
00008 #include "ncdispatch.h"
00009 #include "netcdf_f.h"
00010 
00206 int
00207 nc_def_var(int ncid, const char *name, nc_type xtype, 
00208            int ndims,  const int *dimidsp, int *varidp)
00209 {
00210    NC* ncp;
00211    int stat = NC_NOERR;
00212 
00213    if ((stat = NC_check_id(ncid, &ncp)))
00214       return stat;
00215    return ncp->dispatch->def_var(ncid, name, xtype, ndims,
00216                                  dimidsp, varidp);
00217 }
00279 int
00280 nc_rename_var(int ncid, int varid, const char *name)
00281 {
00282    NC* ncp;
00283    int stat = NC_check_id(ncid, &ncp);
00284    if(stat != NC_NOERR) return stat;
00285    return ncp->dispatch->rename_var(ncid, varid, name);
00286 }
00292 int
00293 NC_is_recvar(int ncid, int varid, size_t* nrecs)
00294 {
00295    int status = NC_NOERR;
00296    int unlimid;
00297    int ndims;
00298    int dimset[NC_MAX_VAR_DIMS];
00299     
00300    status = nc_inq_unlimdim(ncid,&unlimid);
00301    if(status != NC_NOERR) return 0; /* no unlimited defined */
00302    status = nc_inq_varndims(ncid,varid,&ndims);
00303    if(status != NC_NOERR) return 0; /* no unlimited defined */
00304    if(ndims == 0) return 0; /* scalar */
00305    status = nc_inq_vardimid(ncid,varid,dimset);
00306    if(status != NC_NOERR) return 0; /* no unlimited defined */
00307    status = nc_inq_dim(ncid,dimset[0],NULL,nrecs);
00308    if(status != NC_NOERR) return 0;
00309    return (dimset[0] == unlimid ? 1: 0);
00310 }
00311 
00312 /* Ok to use NC pointers because
00313    all IOSP's will use that structure,
00314    but not ok to use e.g. NC_Var pointers
00315    because they may be different structure
00316    entirely.
00317 */
00318 
00327 int
00328 nctypelen(nc_type type) 
00329 {
00330    switch(type){
00331       case NC_CHAR :
00332          return((int)sizeof(char));
00333       case NC_BYTE :
00334          return((int)sizeof(signed char));
00335       case NC_SHORT :
00336          return(int)(sizeof(short));
00337       case NC_INT :
00338          return((int)sizeof(int));
00339       case NC_FLOAT :
00340          return((int)sizeof(float));
00341       case NC_DOUBLE : 
00342          return((int)sizeof(double));
00343 
00344          /* These can occur in netcdf-3 code */ 
00345       case NC_UBYTE :
00346          return((int)sizeof(unsigned char));
00347       case NC_USHORT :
00348          return((int)(sizeof(unsigned short)));
00349       case NC_UINT :
00350          return((int)sizeof(unsigned int));
00351       case NC_INT64 :
00352          return((int)sizeof(signed long long));
00353       case NC_UINT64 :
00354          return((int)sizeof(unsigned long long));
00355 #ifdef USE_NETCDF4
00356       case NC_STRING :
00357          return((int)sizeof(char*));
00358 #endif /*USE_NETCDF4*/
00359 
00360       default:
00361          return -1;
00362    }
00363 }
00364 
00368 int
00369 NC_atomictypelen(nc_type xtype)
00370 {
00371    int sz = 0;
00372    switch(xtype) {
00373       case NC_NAT: sz = 0; break;
00374       case NC_BYTE: sz = sizeof(signed char); break;
00375       case NC_CHAR: sz = sizeof(char); break;
00376       case NC_SHORT: sz = sizeof(short); break;
00377       case NC_INT: sz = sizeof(int); break;
00378       case NC_FLOAT: sz = sizeof(float); break;
00379       case NC_DOUBLE: sz = sizeof(double); break;
00380       case NC_INT64: sz = sizeof(signed long long); break;
00381       case NC_UBYTE: sz = sizeof(unsigned char); break;
00382       case NC_USHORT: sz = sizeof(unsigned short); break;
00383       case NC_UINT: sz = sizeof(unsigned int); break;
00384       case NC_UINT64: sz = sizeof(unsigned long long); break;
00385 #ifdef USE_NETCDF4
00386       case NC_STRING: sz = sizeof(char*); break;
00387 #endif
00388       default: break;
00389    }    
00390    return sz;
00391 }
00392 
00396 char *
00397 NC_atomictypename(nc_type xtype)
00398 {
00399    char* nm = NULL;
00400    switch(xtype) {
00401       case NC_NAT: nm = "undefined"; break;
00402       case NC_BYTE: nm = "byte"; break;
00403       case NC_CHAR: nm = "char"; break;
00404       case NC_SHORT: nm = "short"; break;
00405       case NC_INT: nm = "int"; break;
00406       case NC_FLOAT: nm = "float"; break;
00407       case NC_DOUBLE: nm = "double"; break;
00408       case NC_INT64: nm = "int64"; break;
00409       case NC_UBYTE: nm = "ubyte"; break;
00410       case NC_USHORT: nm = "ushort"; break;
00411       case NC_UINT: nm = "uint"; break;
00412       case NC_UINT64: nm = "uint64"; break;
00413 #ifdef USE_NETCDF4
00414       case NC_STRING: nm = "string"; break;
00415 #endif
00416       default: break;
00417    }    
00418    return nm;
00419 }
00420 
00425 int
00426 NC_getshape(int ncid, int varid, int ndims, size_t* shape)
00427 {
00428    int dimids[NC_MAX_VAR_DIMS];
00429    int i;
00430    int status = NC_NOERR;
00431 
00432    if ((status = nc_inq_vardimid(ncid, varid, dimids)))
00433       return status;
00434    for(i = 0; i < ndims; i++) 
00435       if ((status = nc_inq_dimlen(ncid, dimids[i], &shape[i])))
00436          break;
00437 
00438    return status;
00439 }
00440 
00441 #ifdef USE_NETCDF4
00442 
00467 int
00468 nc_set_var_chunk_cache(int ncid, int varid, size_t size, size_t nelems, 
00469                        float preemption)
00470 {
00471     NC* ncp;
00472     int stat = NC_check_id(ncid, &ncp);
00473     if(stat != NC_NOERR) return stat;
00474     return ncp->dispatch->set_var_chunk_cache(ncid, varid, size, 
00475                                               nelems, preemption);
00476 }
00477 
00505 int
00506 nc_get_var_chunk_cache(int ncid, int varid, size_t *sizep, size_t *nelemsp, 
00507                        float *preemptionp)
00508 {
00509     NC* ncp;
00510     int stat = NC_check_id(ncid, &ncp);
00511     if(stat != NC_NOERR) return stat;
00512     return ncp->dispatch->get_var_chunk_cache(ncid, varid, sizep,
00513                                               nelemsp, preemptionp);
00514 }
00515 
00529 int
00530 nc_free_string(size_t len, char **data)
00531 {
00532    int i;
00533    for (i = 0; i < len; i++)
00534       free(data[i]);
00535    return NC_NOERR;
00536 }
00537 
00538 int
00539 nc_def_var_deflate(int ncid, int varid, int shuffle, int deflate, int deflate_level)
00540 {
00541     NC* ncp;
00542     int stat = NC_check_id(ncid,&ncp);
00543     if(stat != NC_NOERR) return stat;
00544     return ncp->dispatch->def_var_deflate(ncid,varid,shuffle,deflate,deflate_level);
00545 }
00546 
00547 int
00548 nc_def_var_fletcher32(int ncid, int varid, int fletcher32)
00549 {
00550     NC* ncp;
00551     int stat = NC_check_id(ncid,&ncp);
00552     if(stat != NC_NOERR) return stat;
00553     return ncp->dispatch->def_var_fletcher32(ncid,varid,fletcher32);
00554 }
00555 
00556 int
00557 nc_def_var_chunking(int ncid, int varid, int storage, 
00558                     const size_t *chunksizesp)
00559 {
00560     NC* ncp;
00561     int stat = NC_check_id(ncid, &ncp);
00562     if(stat != NC_NOERR) return stat;
00563     return ncp->dispatch->def_var_chunking(ncid, varid, storage, 
00564                                            chunksizesp);
00565 }
00566 
00567 int
00568 nc_def_var_fill(int ncid, int varid, int no_fill, const void *fill_value)
00569 {
00570     NC* ncp;
00571     int stat = NC_check_id(ncid,&ncp);
00572     if(stat != NC_NOERR) return stat;
00573     return ncp->dispatch->def_var_fill(ncid,varid,no_fill,fill_value);
00574 }
00575 
00576 int
00577 nc_def_var_endian(int ncid, int varid, int endian)
00578 {
00579     NC* ncp;
00580     int stat = NC_check_id(ncid,&ncp);
00581     if(stat != NC_NOERR) return stat;
00582     return ncp->dispatch->def_var_endian(ncid,varid,endian);
00583 }
00584 
00585 #endif /* USE_NETCDF4 */
 All Data Structures Files Functions Variables Typedefs Defines

Generated on Tue Aug 6 2013 11:40:56 for netCDF. NetCDF is a Unidata library.