/*! \file Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 University Corporation for Atmospheric Research/Unidata. See \ref copyright file for more info. */ #include #include #include #include #include #if defined (_WIN32) || defined (_WIN64) || defined _MSC_VER #include #else #include #endif #include #include "netcdf.h" #include "netcdf_mem.h" #undef MEM #undef DISKLESS #define USEINT #undef DUMP #undef DEBUG #ifdef MEM static int mem = 1; #else static int mem = 0; #endif #ifdef DISKLESS #define MODE NC_DISKLESS static int diskless = 1; #else #define MODE 0 static int diskless = 0; #endif #define PATH "tst_diskless5.nc" #ifdef USEINT #define T int #define NC_GET_VARA nc_get_vara_int static const char* type = "int"; #else #define T float #define NC_GET_VARA nc_get_vara_float static const char* type = "float"; #endif #define HRAPY 200 #define HRAPX 333 static T amountofprecip[HRAPY*HRAPX]; #ifdef DEBUG static void fill(); #endif static size_t value_count[] = {HRAPY, HRAPX}; static size_t start[] = {0, 0}; int main(int argc, const char* argv[]) { int status; int ncid; int rh_id; T rh_vals[HRAPY*HRAPX]; int i; #ifdef MEM int fd; char buffer[1000000]; size_t count; off_t off; #endif fprintf(stderr,"PATH: %s\n",PATH); fprintf(stderr,"FLAGS: MEM=%d DISKLESS=%d TYPE=%s\n",mem,diskless,type); #ifdef DEBUG fill(); #endif #ifdef MEM fd = NCopen2(PATH,O_RDONLY); if(fd < 0) { fprintf(stderr,"could not open foo.nc\n"); assert(0); } off = lseek(fd,0,SEEK_END); lseek(fd,0,SEEK_SET); fprintf(stderr,"off=%lld\n",off); count = (size_t)read(fd, buffer, sizeof(buffer)); fprintf(stderr,"count=%u |rh_vals|=%u\n",count,sizeof(rh_vals)); close(fd); #endif #ifdef MEM status = nc_open_mem(PATH, MODE, count, buffer, &ncid); #else status = nc_open(PATH, MODE, &ncid); #endif if(status != NC_NOERR) { fprintf(stderr,"%s\n",nc_strerror(status)); assert(0); } status = nc_inq_varid(ncid, "amountofprecip", &rh_id); if(status != NC_NOERR) { fprintf(stderr,"%s\n", nc_strerror(status)); assert(0); } status = NC_GET_VARA(ncid, rh_id, start, value_count, rh_vals); if(status != NC_NOERR) { fprintf(stderr,"%s", nc_strerror(status)); assert(0); } nc_close(ncid); fprintf(stderr,"|amountofprecip|=%d\n",HRAPY*HRAPX); for(i=0;i