/********************************************************************* * Copyright 1993, UCAR/Unidata * See netcdf/COPYRIGHT file for copying and redistribution conditions. *********************************************************************/ #include "config.h" #include "dapincludes.h" #ifdef _MSC_VER #include #endif NCerror dapconvert(nc_type srctype, nc_type dsttype, char* memory0, char* value0, size_t count) { NCerror ncstat = NC_NOERR; size_t i; char* memory = memory0; char* value = value0; /* In order to deal with the DAP upgrade problem, try to preserve the bit patterns */ /* Provide space and pointer casts for intermediate results */ signed char ncbyte; signed char* ncbytep; char ncchar; char* nccharp; short ncshort; short* ncshortp; int ncint; int* ncintp; float ncfloat; float* ncfloatp; double ncdouble; double* ncdoublep; unsigned char ncubyte; unsigned char* ncubytep; unsigned short ncushort; unsigned short* ncushortp; unsigned int ncuint; unsigned int* ncuintp; long long ncint64; long long* ncint64p; unsigned long long ncuint64; unsigned long long* ncuint64p; #define CASE(nc1,nc2) (nc1*256+nc2) #define CUT8(e) ((unsigned char)((e) & 0xff)) #define CUT16(e) ((unsigned short)((e) & 0xffff)) #define CUT32(e) ((unsigned int)((e) & 0xffffffff)) #define ARM(vs,ncs,ts,vd,ncd,td) \ case CASE(ncs,ncd):\ vs##p = (ts *)value;\ vs = *vs##p;\ vd##p = (td *)memory;\ *vd##p = (td)vs;\ break; for(i=0;i NC_MAX_BYTE) ok = 0; *p = (char)ival; #else ok = sscanf(s,"%hhu%n",p,&nread); #endif } break; case NC_CHAR: { signed char* p = (signed char*)dstmem; ok = sscanf(s,"%c%n",p,&nread); } break; case NC_SHORT: { short* p = (short*)dstmem; ok = sscanf(s,"%hd%n",p,&nread); } break; case NC_INT: { int* p = (int*)dstmem; ok = sscanf(s,"%d%n",p,&nread); } break; case NC_FLOAT: { float* p = (float*)dstmem; ok = sscanf(s,"%g%n",p,&nread); } break; case NC_DOUBLE: { double* p = (double*)dstmem; ok = sscanf(s,"%lg%n",p,&nread); } break; case NC_UBYTE: { unsigned char* p = (unsigned char*)dstmem; #ifdef _MSC_VER unsigned int uval; ok = sscanf(s,"%u%n",&uval,&nread); _ASSERTE(_CrtCheckMemory()); if(uval > NC_MAX_UBYTE) ok = 0; *p = (unsigned char)uval; #else ok = sscanf(s,"%hhu%n",p,&nread); #endif } break; case NC_USHORT: { unsigned short* p = (unsigned short*)dstmem; ok = sscanf(s,"%hu%n",p,&nread); } break; case NC_UINT: { unsigned int* p = (unsigned int*)dstmem; ok = sscanf(s,"%u%n",p,&nread); } break; case NC_INT64: { long long* p = (long long*)dstmem; #ifdef _MSC_VER ok = sscanf(s, "%I64d%n", p,&nread); #else ok = sscanf(s,"%lld%n",p,&nread); #endif } break; case NC_UINT64: { unsigned long long* p = (unsigned long long*)dstmem; ok = sscanf(s,"%llu%n",p,&nread); } break; case NC_STRING: case NC_URL: { char** p = (char**)dstmem; *p = nulldup(s); ok = 1; } break; default: PANIC1("unexpected nc_type: %d",(int)etype); } if(ok != 1 || nread != slen) {ncstat = NC_EINVAL; goto done;} dstmem += memsize; } done: return THROW(ncstat); }