/* Diskless test in support of https://github.com/Unidata/netcdf-c/issues/400 */ #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 #define DISKLESS #define USEINT #undef DUMP #undef DEBUG #ifdef MEM static int mem = 1; #else static int mem = 0; #endif #ifdef DISKLESS #define MODE NC_NOCLOBBER|NC_DISKLESS static int diskless = 1; #else #define MODE NC_NOCLOBBER 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 = open(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