/* * Test nc_open. * If in read-only section of tests, * Try to open a non-existent netCDF file, check error return. * Open a file that is not a netCDF file, check error return. * Open a netCDF file with a bad mode argument, check error return. * Open a netCDF file with NC_NOWRITE mode, try to write, check error. * Try to open a netcdf twice, check whether returned netcdf ids different. * If in writable section of tests, * Open a netCDF file with NC_WRITE mode, write something, close it. * On exit, any open netCDF files are closed. */ void test_nc_open(void) { int err; int ncid; int ncid2; /* Try to open a nonexistent file */ err = nc_open("tooth-fairy.nc", NC_NOWRITE, &ncid);/* should fail */ IF (err == NC_NOERR) error("nc_open of nonexistent file should have failed"); #ifndef USE_PARALLEL IF (! NC_ISSYSERR(err)) error("nc_open of nonexistent file should have returned system error"); #endif /* Open a file that is not a netCDF file. But need a portable * test that also works for cross-compiles ... */ /* err = nc_open("nc_test.o", NC_NOWRITE, &ncid);/\* should fail *\/ */ /* IF (err != NC_ENOTNC) */ /* error("nc_open of non-netCDF file: status = %d", err); */ /* Open a netCDF file in read-only mode, check that write fails */ err = nc_open(testfile, NC_NOWRITE, &ncid); IF (err) error("nc_open: %s", nc_strerror(err)); err = nc_redef(ncid); /* should fail */ IF (err != NC_EPERM) error("nc_redef of read-only file should fail"); /* Opened OK, see if can open again and get a different netCDF ID */ err = nc_open(testfile, NC_NOWRITE, &ncid2); IF (err) error("nc_open: %s", nc_strerror(err)); else {
/* * Test nc_strerror. * Try on a bad error status. * Test for each defined error status. */ void test_nc_strerror(void) { int i; const char *message; static const struct { int status; const char *msg; } ncerrs[] = { {NC_NOERR, "No error"}, {NC_EBADID, "NetCDF: Not a valid ID"}, {NC_ENFILE, "NetCDF: Too many files open"}, {NC_EEXIST, "NetCDF: File exists && NC_NOCLOBBER"}, {NC_EINVAL, "NetCDF: Invalid argument"}, {NC_EPERM, "NetCDF: Write to read only"}, {NC_ENOTINDEFINE, "NetCDF: Operation not allowed in data mode"}, {NC_EINDEFINE, "NetCDF: Operation not allowed in define mode"}, {NC_EINVALCOORDS, "NetCDF: Index exceeds dimension bound"}, {NC_EMAXDIMS, "NetCDF: NC_MAX_DIMS exceeded"}, {NC_ENAMEINUSE, "NetCDF: String match to name in use"}, {NC_ENOTATT, "NetCDF: Attribute not found"}, {NC_EMAXATTS, "NetCDF: NC_MAX_ATTRS exceeded"}, {NC_EBADTYPE, "NetCDF: Not a valid data type or _FillValue type mismatch"}, {NC_EBADDIM, "NetCDF: Invalid dimension ID or name"}, {NC_EUNLIMPOS, "NetCDF: NC_UNLIMITED in the wrong index"}, {NC_EMAXVARS, "NetCDF: NC_MAX_VARS exceeded"}, {NC_ENOTVAR, "NetCDF: Variable not found"}, {NC_EGLOBAL, "NetCDF: Action prohibited on NC_GLOBAL varid"}, {NC_ENOTNC, "NetCDF: Unknown file format"}, {NC_ESTS, "NetCDF: In Fortran, string too short"}, {NC_EMAXNAME, "NetCDF: NC_MAX_NAME exceeded"}, {NC_EUNLIMIT, "NetCDF: NC_UNLIMITED size already in use"}, {NC_ENORECVARS, "NetCDF: nc_rec op when there are no record vars"}, {NC_ECHAR, "NetCDF: Attempt to convert between text & numbers"}, {NC_EEDGE, "NetCDF: Start+count exceeds dimension bound"}, {NC_ESTRIDE, "NetCDF: Illegal stride"}, {NC_EBADNAME, "NetCDF: Name contains illegal characters"}, {NC_ERANGE, "NetCDF: Numeric conversion not representable"}, {NC_ENOMEM, "NetCDF: Memory allocation (malloc) failure"}, {NC_EVARSIZE, "NetCDF: One or more variable sizes violate format constraints"}, {NC_EDIMSIZE, "NetCDF: Invalid dimension size"} }; /* Try on a bad error status */ /* Dmh: allow trailing extra info */ message = nc_strerror(-666);/* should fail */ IF (strcmp(message, "Unknown Error") != 0) error("nc_strerror on bad error status returned: %s", message); /* Try on each legitimate error status */ /* Dmh: allow trailing extra info */ for (i=0; i<LEN_OF(ncerrs); i++) { const char *message = nc_strerror(ncerrs[i].status); IF (strcmp(message, ncerrs[i].msg) != 0) error("nc_strerror(%d) should return `%s', not `%s'", ncerrs[i].status, ncerrs[i].msg, message); } }
static int read_numeric_attribute(int ncid, int varid, const char *name, harp_data_type *data_type, harp_scalar *data) { nc_type netcdf_data_type; size_t netcdf_num_elements; int result; result = nc_inq_att(ncid, varid, name, &netcdf_data_type, &netcdf_num_elements); if (result != NC_NOERR) { harp_set_error(HARP_ERROR_NETCDF, "%s", nc_strerror(result)); return -1; } if (netcdf_num_elements != 1) { harp_set_error(HARP_ERROR_IMPORT, "attribute '%s' has invalid format", name); return -1; } if (get_harp_type(netcdf_data_type, data_type) != 0) { harp_add_error_message(" (attribute '%s')", name); return -1; } switch (netcdf_data_type) { case NC_BYTE: result = nc_get_att_schar(ncid, varid, name, &data->int8_data); break; case NC_SHORT: result = nc_get_att_short(ncid, varid, name, &data->int16_data); break; case NC_INT: result = nc_get_att_int(ncid, varid, name, &data->int32_data); break; case NC_FLOAT: result = nc_get_att_float(ncid, varid, name, &data->float_data); break; case NC_DOUBLE: result = nc_get_att_double(ncid, varid, name, &data->double_data); break; default: harp_set_error(HARP_ERROR_IMPORT, "attribute '%s' has invalid type", name); return -1; } if (result != NC_NOERR) { harp_set_error(HARP_ERROR_NETCDF, "%s", nc_strerror(result)); return -1; } return 0; }
int harp_import_netcdf(const char *filename, harp_product **product) { harp_product *new_product; netcdf_dimensions dimensions; int ncid; int result; if (filename == NULL) { harp_set_error(HARP_ERROR_INVALID_ARGUMENT, "filename is NULL (%s:%u)", __FILE__, __LINE__); return -1; } result = nc_open(filename, 0, &ncid); if (result != NC_NOERR) { harp_set_error(HARP_ERROR_NETCDF, "%s", nc_strerror(result)); return -1; } if (verify_product(ncid) != 0) { nc_close(ncid); return -1; } if (harp_product_new(&new_product) != 0) { nc_close(ncid); return -1; } dimensions_init(&dimensions); if (read_product(ncid, new_product, &dimensions) != 0) { dimensions_done(&dimensions); harp_product_delete(new_product); nc_close(ncid); return -1; } dimensions_done(&dimensions); result = nc_close(ncid); if (result != NC_NOERR) { harp_set_error(HARP_ERROR_NETCDF, "%s", nc_strerror(result)); harp_product_delete(new_product); return -1; } *product = new_product; return 0; }
/* byte_style is 1 for signed, 2 for unsigned */ void R_nc_get_vara_int( int *ncid, int *varid, int *start, int *count, int *byte_style, int *data, int *retval ) { int i, err, ndims; size_t s_start[MAX_NC_DIMS], s_count[MAX_NC_DIMS], tot_size, k; char vn[2048]; nc_type nct; err = nc_inq_varndims(*ncid, *varid, &ndims ); if( err != NC_NOERR ) REprintf( "Error in R_nc_get_vara_int while getting ndims: %s\n", nc_strerror(*retval) ); tot_size = 1L; for( i=0; i<ndims; i++ ) { s_start[i] = (size_t)start[i]; s_count[i] = (size_t)count[i]; tot_size *= s_count[i]; } *retval = nc_get_vara_int(*ncid, *varid, s_start, s_count, data ); if( *retval != NC_NOERR ) { nc_inq_varname( *ncid, *varid, vn ); REprintf( "Error in R_nc_get_vara_int: %s\n", nc_strerror(*retval) ); REprintf( "Var: %s Ndims: %d Start: ", vn, ndims ); for( i=0; i<ndims; i++ ) { REprintf( "%u", (unsigned int)s_start[i] ); if( i < ndims-1 ) REprintf( "," ); } REprintf( "Count: " ); for( i=0; i<ndims; i++ ) { REprintf( "%u", (unsigned int)s_count[i] ); if( i < ndims-1 ) REprintf( "," ); } } *retval = nc_inq_vartype( *ncid, *varid, &nct ); if( nct == NC_BYTE ) { /* netcdf library for reading from byte to int, as we do here, * is SIGNED. So, if user requests signed, we don't have to * do anything; only adjust if user asks for unsigned. */ if( *byte_style == 2 ) { /* unsigned */ for( k=0L; k<tot_size; k++ ) { if( data[k] < 0 ) data[k] += 256; } } } }
void check_err2(const int stat, const int cdlline, const int line, const char* file) { if (stat != NC_NOERR) { if(cdlline >= 0) fprintf(stderr, "ncgen: cdl line %d; %s\n", cdlline, nc_strerror(stat)); else fprintf(stderr, "ncgen: %s\n", nc_strerror(stat)); fprintf(stderr, "\t(%s:%d)\n", file,line); #ifdef USE_NETCDF4 H5Eprint1(stderr); #endif fflush(stderr); exit(1); } }
WrfGrid::Parameters DataFile::getGridParameters() { WrfGrid::Parameters parameters; std::map<const char *, int*> intParameters; intParameters["WEST-EAST_GRID_DIMENSION"] = ¶meters.nWestEast; intParameters["SOUTH-NORTH_GRID_DIMENSION"] = ¶meters.nSouthNorth; intParameters["BOTTOM-TOP_GRID_DIMENSION"] = ¶meters.nBottomTop; intParameters["MAP_PROJ"] = ¶meters.mapProj; std::map<const char *, int*>::iterator iterInt; for (iterInt = intParameters.begin(); iterInt != intParameters.end(); ++iterInt) { int status = nc_get_att_int (handle_, NC_GLOBAL, iterInt->first, iterInt->second); if (status != NC_NOERR) { throw NetCdfException (nc_strerror(status)); // FIXME throw NetCdfException ("error reading " + iterInt->first + " from #" + handle_ + ":\n" + nc_strerror(status)); } } std::map<const char *, float*> floatParameters; floatParameters["DX"] = ¶meters.dX; floatParameters["DY"] = ¶meters.dY; floatParameters["CEN_LAT"] = ¶meters.cenLat; floatParameters["CEN_LON"] = ¶meters.cenLon; floatParameters["TRUELAT1"] = ¶meters.trueLat1; floatParameters["TRUELAT2"] = ¶meters.trueLat2; floatParameters["MOAD_CEN_LAT"] = ¶meters.moadCenLat; floatParameters["STAND_LON"] = ¶meters.standLon; floatParameters["POLE_LAT"] = ¶meters.poleLat; floatParameters["POLE_LON"] = ¶meters.poleLon; std::map<const char *, float*>::iterator iterFloat; for (iterFloat = floatParameters.begin(); iterFloat != floatParameters.end(); ++iterFloat) { int status = nc_get_att_float (handle_, NC_GLOBAL, iterFloat->first, iterFloat->second); if (status != NC_NOERR) { throw NetCdfException (nc_strerror(status)); // FIXME throw NetCdfException ("error reading " + iterInt->first + " from #"+ handle_ +":\n" + nc_strerror(status)); } } return parameters; }
/* NOTE that NA's are handled through this vector. According to the * docs as of 2010-11-02, NA's have the value MIN_INT */ void R_nc4_put_att_logical( int *ncid, int *varid, char **attname, int *type_to_create, int *natts, int *attribute, int *retval ) { int R_NA_val; float C_NA_val_f; double C_NA_val_d; /* Rprintf( "in R_nc4_put_att_logical with val=%d\n", *attribute ); */ nc_type ttc; ttc = R_nc4_ttc_to_nctype( *type_to_create ); R_NA_val = -2147483648; /* From R docs */ if( *attribute == R_NA_val ) { /* Rprintf( "PUTTING a NA -- float \n" ); */ /* Put a NA */ if( ttc == NC_FLOAT ) { C_NA_val_f = 0./0.; *retval = nc_put_att_float(*ncid, *varid, attname[0], ttc, *natts, &C_NA_val_f ); if( *retval != NC_NOERR ) Rprintf( "Error in R_nc4_put_att_logical: %s\n", nc_strerror(*retval) ); } else if( ttc == NC_DOUBLE ) { /* Rprintf( "PUTTING a NA -- double \n" ); */ C_NA_val_d = 0./0.; *retval = nc_put_att_double(*ncid, *varid, attname[0], ttc, *natts, &C_NA_val_d ); if( *retval != NC_NOERR ) Rprintf( "Error in R_nc4_put_att_logical: %s\n", nc_strerror(*retval) ); } else { Rprintf( "Error in R_nc4_put_att_logical: asked to put a NA value, but the variable's type is not a double or float, which are the only two types that have a defined NaN value\n" ); *retval = -1; return; } } else *retval = nc_put_att_int(*ncid, *varid, attname[0], ttc, *natts, attribute ); if( *retval != NC_NOERR ) Rprintf( "Error in R_nc4_put_att_logical: %s\n", nc_strerror(*retval) ); }
int harp_export_netcdf(const char *filename, const harp_product *product) { netcdf_dimensions dimensions; int result; int ncid; if (filename == NULL) { harp_set_error(HARP_ERROR_INVALID_ARGUMENT, "filename is NULL"); return -1; } if (product == NULL) { harp_set_error(HARP_ERROR_INVALID_ARGUMENT, "product is NULL"); return -1; } result = nc_create(filename, 0, &ncid); if (result != NC_NOERR) { harp_set_error(HARP_ERROR_NETCDF, "%s", nc_strerror(result)); harp_add_error_message(" (%s)", filename); return -1; } dimensions_init(&dimensions); if (write_product(ncid, product, &dimensions) != 0) { harp_add_error_message(" (%s)", filename); nc_close(ncid); dimensions_done(&dimensions); return -1; } dimensions_done(&dimensions); result = nc_close(ncid); if (result != NC_NOERR) { harp_set_error(HARP_ERROR_NETCDF, "%s", nc_strerror(result)); harp_add_error_message(" (%s)", filename); return -1; } return 0; }
int main(int argc, char** argv) { int i; int ret = NC_NOERR; if(argc == 1) { fprintf(stderr,"usage: nc4printer <file> <file>...\n"); exit(1); } for(i=1;i<argc;i++) { int ncid; char* filename; NCbytes* buf; filename = argv[i]; buf = ncbytesnew(); if((ret = nc_open(filename,NC_NETCDF4,&ncid))) goto fail; ret = NC4print(buf,ncid); ncbytesnull(buf); fprintf(stderr,"========== %s ==========\n",filename); fprintf(stderr,"%s\n",ncbytescontents(buf)); ncbytesfree(buf); } exit(0); fail: fprintf(stderr,"***Fail: (%d) %s\n",ret,nc_strerror(ret)); exit(1); }
int _rsNcInqId( int paramType, int ncid, char *name, int **outId ) { int status; int myoutId = 0; switch ( paramType ) { case NC_VAR_T: status = nc_inq_varid( ncid, name, &myoutId ); break; case NC_DIM_T: status = nc_inq_dimid( ncid, name, &myoutId ); break; default: rodsLog( LOG_ERROR, "_rsNcInqId: Unknow paramType %d for %s ", paramType, name ); return ( NETCDF_INVALID_PARAM_TYPE ); } if ( status == NC_NOERR ) { *outId = ( int * ) malloc( sizeof( int ) ); *( *outId ) = myoutId; } else { rodsLog( LOG_ERROR, "_rsNcInqId: nc_inq error paramType %d for %s. %s ", paramType, name, nc_strerror( status ) ); status = NETCDF_INQ_ID_ERR + status; } return status; }
// NetcdfFile::checkNCerr() bool NetcdfFile::checkNCerr(int ncerr) { if ( ncerr != NC_NOERR ) { mprintf("%s\n", nc_strerror(ncerr)); return true; } return false; }
/* Note that space for returned value MUST already be declared! */ void R_nc_inq_varname( int *ncid, int *varid, char **varname, int *retval ) { *retval = nc_inq_varname(*ncid, *varid, varname[0] ); if( *retval != NC_NOERR ) REprintf( "Error in R_nc_inq_varname: %s\n", nc_strerror(*retval) ); }
void CTAI_ObsDescr_netcdf_Free( CTAI_ObsDescr_netcdf *descr, int *retval) { #if HAVE_LIBNETCDF int i, ierr; descr->database->nusers--; // printf("cta_obsdescr_free (netcdf): now %d users remaining of database %s \n",descr->database->nusers, descr->database->dbname); if (descr->database->nusers==0) { if ((ierr = nc_close(descr->database->ncid))){ printf("CTA_Sobs_netcdf_Free: cannot close netCDF-file: %d\n", nc_strerror(ierr)); } free(descr->database->dbname); free(descr->database); } for (i=0; i<descr->n_keys; i++){ CTA_String_Free(&(descr->Keys[i]));} free(descr->Keys); *retval = CTA_OK; #else printf("CTAI_ObsDescr_netcdf_Get_Properties :Version is compiled without NETCDF support.\n"); *retval=CTA_NOT_IMPLEMENTED; #endif }
int main() { int ncid,retval,pass; char** url; printf("Testing: Http Basic Authorization\n"); pass = 0; for(url=URLS;*url;url++) { retval = nc_open(*url, 0, &ncid); if(retval == NC_NOERR) { printf("URL: %s\n",*url); pass = 1; break; } printf("fail: %s: %s\n", nc_strerror(retval),*url); } if(pass) { retval = nc_close(ncid); printf("*** PASS: Http Basic Authorization\n"); return 0; } else { CHECK(retval,"*** Fail: Http Basic Authorization"); return 1; } }
static void nc_handle_error(int res) { if (res != NC_NOERR) (void) fprintf(stderr, "NetCDF error %d, \"%s\"\n", res, nc_strerror(res)); }
DataFile::DataFile (FileName const &fileName) { #ifdef DEBUG std::cout << "open NetCDF file : " << fileName << std::endl; #endif int status = nc_open(fileName.c_str(), NC_SHARE|NC_DISKLESS|NC_MMAP, &handle_); /* * NC_SHARE : from doc : Since the buffering scheme is optimized * for sequential access, programs that do not access data sequentially * may see some performance improvement by setting the NC_SHARE flag. * * NC_DISKLESS : for allowing NC_MMAP. Side effect : any changes * performed to the files won't be saved on exit. Not an issue for us. * * NC_MMAP : for mapping the file to virtual memory, and let the linux * kernel do the RAM cache management for us. See `man mmap`. * To use this flag, NetCDF must be compiled with ./configure --enable-mmap * Ubuntu's libnetcdf doesn't include mmap support. */ if (status != NC_NOERR) { throw NetCdfException ("error opening " + fileName + ":\n" + nc_strerror(status)); } #ifdef DEBUG std::cout << "handle : #" << handle_ << std::endl; #endif }
void R_nc_put_var_double( int *ncid, int *varid, double *data, int *retval ) { *retval = nc_put_var_double(*ncid, *varid, data ); if( *retval != NC_NOERR ) REprintf( "Error in R_nc_put_var_double: %s\n", nc_strerror(*retval) ); }
/* If returned value 'retval' is 0, then returned value 'type' will hold * the type of the named attribute, and returned value 'attlen' will * hold the length of the named attribute. If returned value 'retval' * is NOT 0, then the specified variable did not have an attribute * named 'attname'. */ void R_nc_inq_att( int *ncid, int *varid, char **attname, int *type, int *attlen, int *retval ) { size_t s_attlen; nc_type nctype; *retval = nc_inq_att(*ncid, *varid, attname[0], &nctype, &s_attlen ); if( (*retval != 0) && (*retval != NC_ENOTATT)) REprintf( "Error in R_nc_inq_att: while looking for attribute %s, got error %s\n", attname[0], nc_strerror(*retval) ); if( *retval == 0 ) { *type = R_nc_nctype_to_Rtypecode(nctype); if( *type == -1 ) { if( nctype == NC_BYTE ) REprintf( "Error in R_nc_inq_att: not set up to handle attributes of type \"BYTE\"! Netcdf type code: %d Attribute name: %s\n", nctype, attname[0] ); else { REprintf( "Error in R_nc_inq_att: not set up to handle attributes of this type! Netcdf type code: %d Attribute name: %s\n", nctype, attname[0] ); *retval = -1; } } *attlen = (int)s_attlen; } }
void R_nc_create( char **filename, int *cmode, int *ncid, int *retval ) { *retval = nc_create(R_ExpandFileName(filename[0]), *cmode, ncid); if( *retval != NC_NOERR ) REprintf( "Error in R_nc_create: %s\n", nc_strerror(*retval) ); }
void R_nc_inq_unlimdim( int *ncid, int *unlimdimid, int *retval ) { *retval = nc_inq_unlimdim(*ncid, unlimdimid ); if( *retval != NC_NOERR ) REprintf( "Error in R_nc_inq_unlimdim: %s\n", nc_strerror(*retval) ); }
void check_err(const int stat, const int line, const char *file) { if (stat != NC_NOERR) { (void) fprintf(stderr, "line %d of %s: %s\n", line, file, nc_strerror(stat)); exit(1); } }
static int write_numeric_attribute(int ncid, int varid, const char *name, harp_data_type data_type, harp_scalar data) { int result; result = NC_NOERR; switch (data_type) { case harp_type_int8: result = nc_put_att_schar(ncid, varid, name, NC_BYTE, 1, &data.int8_data); break; case harp_type_int16: result = nc_put_att_short(ncid, varid, name, NC_SHORT, 1, &data.int16_data); break; case harp_type_int32: result = nc_put_att_int(ncid, varid, name, NC_INT, 1, &data.int32_data); break; case harp_type_float: result = nc_put_att_float(ncid, varid, name, NC_FLOAT, 1, &data.float_data); break; case harp_type_double: result = nc_put_att_double(ncid, varid, name, NC_DOUBLE, 1, &data.double_data); break; default: assert(0); exit(1); } if (result != NC_NOERR) { harp_set_error(HARP_ERROR_NETCDF, "%s", nc_strerror(result)); return -1; } return 0; }
int main(int argc, char** argv) { int ret = NC_NOERR; char url[4096]; int ncid; /* Skip cmd name */ argc++; argv++; if(argc < 2) { fprintf(stderr, "too few arguments: t_dmrdata.c <infile> <outfile>\n"); fail(NC_NOERR); } /* build the url */ snprintf(url,sizeof(url),"file://%s#dap4&debug=copy&substratename=%s",argv[0],argv[1]); #ifdef DEBUG fprintf(stderr,"t_dmrbuild %s -> %s\n",url,outfile); #endif /* Use the open/close mechanism */ if((ret=nc_open(url,NC_NETCDF4,&ncid))) goto done; if((ret=nc_close(ncid))) goto done; done: #ifdef DEBUG fprintf(stderr,"code=%d %s\n",ret,nc_strerror(ret)); #endif return (ret ? 1 : 0); }
static void fail(int code) { if(code != NC_NOERR) fprintf(stderr,"***Fail: %s\n",nc_strerror(code)); exit((code==NC_NOERR?EXIT_SUCCESS:EXIT_FAILURE)); }
/*! This function queries the full name of a group given its id. \param [in] ncid Groupd id (or File Id) \param [in/out] grpFullName the full name of the group \return Status code */ int CNetCdfInterface::inqGrpFullName(int ncid, StdString& grpFullName) { StdSize strlen = 0; std::vector<char> buff; int status = nc_inq_grpname_full(ncid, &strlen, NULL); if (NC_NOERR == status) { buff.resize(strlen + 1); status = nc_inq_grpname_full(ncid, NULL, &buff[0]); } if (NC_NOERR != status) { StdString errormsg(nc_strerror(status)); StdStringStream sstr; sstr << "Error when calling function nc_inq_grpname_full(ncid, &strlen, &buff[0])" << std::endl << errormsg << std::endl << "Unable to get the full group name given its id: " << ncid << std::endl; StdString e = sstr.str(); throw CNetCdfException(e); } grpFullName.assign(buff.begin(), buff.end()); return status; }
void ne (int status) { if (status != NC_NOERR) { fprintf(stderr, "%s\n", nc_strerror(status)); nc_close(ncid); exit(EXIT_FAILURE); } }
void nc_advise(const char *routine_name, int err, const char *fmt,...) { va_list args; if(NC_ISSYSERR(err)) ncerr = NC_SYSERR; else ncerr = err; if( ncopts & NC_VERBOSE ) { (void) fprintf(stderr,"%s: ", routine_name); va_start(args ,fmt); (void) vfprintf(stderr,fmt,args); va_end(args); if(err != NC_NOERR) { (void) fprintf(stderr,": %s", nc_strerror(err)); } (void) fputc('\n',stderr); (void) fflush(stderr); /* to ensure log files are current */ } if( (ncopts & NC_FATAL) && err != NC_NOERR ) { exit(ncopts); } }
char * netcdfGetAttributeText( int ncid, int vid, char *attribute ) { int err; char *returnText; # ifdef MPI MPI_Offset ist; # else size_t ist; # endif err = nc_inq_attlen(ncid, vid, attribute, &ist); if (err == NC_NOERR) { returnText = (char *) safe_malloc(sizeof(char) * (ist+1)); err = nc_get_att_text(ncid, vid, attribute, returnText); if (err != NC_NOERR) { fprintf(stdout, "netcdfGetAttributeText: Could not get attribute (%s) from NetCDF file", attribute); safe_free(returnText); returnText = NULL; } } else fprintf(stdout, "netcdfGetAttributeText: Error grabbing attribute (%s): %s\n", attribute, nc_strerror(err)); return returnText; }
void R_nc_inq_varndims( int *ncid, int *varid, int *ndims, int *retval ) { *retval = nc_inq_varndims(*ncid, *varid, ndims ); if( *retval != NC_NOERR ) REprintf( "Error in R_nc_inq_varndims: %s\n", nc_strerror(*retval) ); }