/*! \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 "netcdf.h" #include "t_srcdir.h" #undef GENERATE #undef DEBUG /* Test (some) internal/external type conversions using following DAP dataset (test.02). Dataset { Byte b[DIMSIZE]; Int32 i32[DIMSIZE]; UInt32 ui32[DIMSIZE]; Int16 i16[DIMSIZE]; UInt16 ui16[DIMSIZE]; Float32 f32[DIMSIZE]; Float64 f64[DIMSIZE]; String s[DIMSIZE]; Url u[DIMSIZE]; } OneDimensionalSimpleArrays; */ #define NDIMS 1 #define DIMSIZE 25 #define STRLEN 64 #define CHECK(expr) check(expr,__FILE__,__LINE__); #define COMMA (i==0?"":",") #define COMPARE(t1,t2,v1,v2) compare(t1,t2,(void*)v1,(void*)v2,#v2,__FILE__,__LINE__) static int fail = 0; static void compare(nc_type,nc_type,void*,void*,char*,char*,int); static void report(const int i, const char* var, const int line) { fprintf(stdout,"%s mismatch: [%d] file: %s line: %d\n",var,i,__FILE__,line); fail = 1; } static void check(int ncstat, char* file, int line) { if(ncstat == NC_NOERR) return; fprintf(stderr,"*** FAIL: %d (%s) at %s:%d\n", ncstat,nc_strerror(ncstat),file,line); exit(1); } /* return 1 if |f1-f2| > 0.05 */ static int fdiff(double f1, double f2) { double delta = (f1 - f2); if(delta < 0) delta = - delta; if(delta > 0.05) { fprintf(stdout,"fdiff: %1.3f %1.3f delta=%1.3f\n",f1,f2,delta); } return (delta > 0.05?1:0); } static char ch_data[DIMSIZE]; static signed char int8_data[DIMSIZE]; static unsigned char uint8_data[DIMSIZE]; static int int8toint32_data[DIMSIZE]; static float int82float32_data[DIMSIZE]; static short int16_data[DIMSIZE]; static int int16toint32_data[DIMSIZE]; static float int162float32_data[DIMSIZE]; static int int32_data[DIMSIZE]; static float int32tofloat32_data[DIMSIZE]; static long int32toilong_data[DIMSIZE]; static float float32_data[DIMSIZE]; static double float64_data[DIMSIZE]; #ifndef USE_NETCDF4 static char string3_data[DIMSIZE][STRLEN]; #endif static char ch_tst[DIMSIZE]; static signed char int8_tst[DIMSIZE]; static unsigned char uint8_tst[DIMSIZE]; static short int16_tst[DIMSIZE]; static int int32_tst[DIMSIZE]; static float float32_tst[DIMSIZE]; static double float64_tst[DIMSIZE]; static long ilong_tst[DIMSIZE]; #ifndef USE_NETCDF4 static char string3_tst[DIMSIZE][STRLEN]; #endif int main() { int ncid, varid; int ncstat = NC_NOERR; char url[8192]; const char* topsrcdir; #ifndef USE_NETCDF4 int i,j; #endif /* location of our target url: use file// to avoid remote server downtime issues */ topsrcdir = gettopsrcdir(); url[0] = '\0'; #ifdef DEBUG strlcat(url,"[log][show=fetch]",sizeof(url)); #endif strlcat(url,"file://",sizeof(url)); strlcat(url,topsrcdir,sizeof(url)); strlcat(url,"/ncdap_test/testdata3/test.02",sizeof(url)); printf("*** Test: var conversions on URL: %s\n",url); /* open file, get varid */ CHECK(nc_open(url, NC_NOWRITE, &ncid)); /* extract the string case for netcdf-3*/ #ifndef USE_NETCDF4 CHECK(nc_inq_varid(ncid, "s", &varid)); CHECK(nc_get_var_text(ncid,varid,(char*)string3_tst)); #ifdef GENERATE printf("static %s string3_data[DIMSIZE][STRLEN]={","char"); for(i=0;i 0 && string3_tst[i][j] != '\n' && string3_tst[i][j] != '\r' && string3_tst[i][j] != '\t' &&(string3_tst[i][j] < ' ' || string3_tst[i][j] >= '\177')) string3_tst[i][j] = '?'; } printf("%s\"%s\"",COMMA,string3_tst[i]); } printf("};\n"); #else fprintf(stdout,"*** testing: %s\n","string3"); for(i=0;i