#include #include #include #include #include "netcdf.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 #ifndef USE_NETCDF4 #define NC_UBYTE 7 /* unsigned 1 byte int */ #define NC_USHORT 8 /* unsigned 2-byte int */ #define NC_UINT 9 /* unsigned 4-byte int */ #define NC_INT64 10 /* signed 8-byte int */ #define NC_UINT64 11 /* unsigned 8-byte int */ #define NC_STRING 12 /* string */ #endif #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[DIMSIZE]; static signed char int8[DIMSIZE]; static unsigned char uint8[DIMSIZE]; static short int16[DIMSIZE]; static int int32[DIMSIZE]; static float float32[DIMSIZE]; static double float64[DIMSIZE]; static long ilong[DIMSIZE]; #ifndef USE_NETCDF4 static char string3[DIMSIZE][STRLEN]; #endif int main() { int i,j; int ncid, varid; int ncstat = NC_NOERR; char* url; char* topsrcdir; size_t len; /* location of our target url: use file// to avoid remote server downtime issues */ /* Assume that TESTS_ENVIRONMENT was set */ topsrcdir = getenv("TOPSRCDIR"); if(topsrcdir == NULL) { fprintf(stderr,"*** FAIL: $abs_top_srcdir not defined: location= %s:%d\n",__FILE__,__LINE__); exit(1); } len = strlen("file://") + strlen(topsrcdir) + strlen("/ncdap_test/testdata3/test.02") + 1; #ifdef DEBUG len += strlen("[log][show=fetch]"); #endif url = (char*)malloc(len); url[0] = '\0'; #ifdef DEBUG strcat(url,"[log][show=fetch]"); #endif strcat(url,"file://"); strcat(url,topsrcdir); strcat(url,"/ncdap_test/testdata3/test.02"); 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)); #ifdef GENERATE printf("static %s string3_data[DIMSIZE][STRLEN]={","char"); for(i=0;i 0 && string3[i][j] != '\n' && string3[i][j] != '\r' && string3[i][j] != '\t' &&(string3[i][j] < ' ' || string3[i][j] >= '\177')) string3[i][j] = '?'; } printf("%s\"%s\"",COMMA,string3[i]); } printf("};\n"); #else fprintf(stdout,"*** testing: %s\n","string3"); for(i=0;i