int ex_comp_ws( int exoid ) { /*! * ex_comp_ws() returns 4 (i.e. sizeof(float)) or 8 (i.e. sizeof(double)), * depending on the value of floating point word size used to initialize * the conversion facility for this file id (exoid). * \param exoid integer which uniquely identifies the file of interest. */ char errmsg[MAX_ERR_LENGTH]; struct file_item* file; exerrval = 0; /* clear error code */ FIND_FILE( file, exoid ); if (!file ) { exerrval = EX_BADFILEID; sprintf(errmsg,"Error: unknown file id %d",exoid); ex_err("ex_comp_ws",errmsg,exerrval); return(EX_FATAL); } return file->user_compute_wordsize; }
nc_type nc_flt_code( int exoid ) { /* nc_flt_code() returns either NC_FLOAT or NC_DOUBLE, based on the parameters * with which ex_conv_ini() was called. nc_flt_code() is used as the nc_type * parameter on ncvardef() calls that define floating point variables. * * "exoid" is some integer which uniquely identifies the file of interest. */ char errmsg[MAX_ERR_LENGTH]; struct file_item* file; exerrval = 0; /* clear error code */ FIND_FILE( file, exoid ); if (!file ) { exerrval = EX_BADFILEID; sprintf(errmsg,"Error: unknown file id %d for nc_flt_code().",exoid); ex_err("nc_flt_code",errmsg,exerrval); return (nc_type) -1; } return file->netcdf_type_code; }
/* and store resulting name(s) in argv array */ static void vms_expand_wildcards( const char *prospective_filespec ) { char *p, spec_buf[255+1], res_buf[255+1], *strstr(); Dsc spec, result; void *context; register int len = strlen(prospective_filespec); if (len >= sizeof spec_buf) return; /* can't be valid--or at least we can't handle it */ strcpy(spec_buf, prospective_filespec); /* copy the arg */ p = strchr(spec_buf, '?'); if (p != NULL) /* change '?' single-char wildcard to '%' */ do *p++ = '%', p = strchr(p, '?'); while (p != NULL); else if (strchr(spec_buf, '*') == strchr(spec_buf, '%') /* => both NULL */ && strstr(spec_buf, "...") == NULL) return; /* no wildcards present; don't attempt file lookup */ spec.len = len, spec.adr = spec_buf; result.len = sizeof res_buf - 1, result.adr = res_buf; /* The filespec is already in v_argv[v_argc]; if we fail to match anything, we'll just leave it there (unlike most shells, where it would evaporate). */ len = -1; /* overload 'len' with flag value */ context = NULL; /* init */ while (vmswork(LIB$FIND_FILE(&spec, &result, &context))) { for (len = sizeof(res_buf)-1; len > 0 && res_buf[len-1] == ' '; len--) ; res_buf[len] = '\0'; /* terminate after discarding trailing blanks */ v_add_arg(v_argc++, strdup(res_buf)); /* store result */ } (void)LIB$FIND_FILE_END(&context); if (len >= 0) /* (still -1 => never entered loop) */ --v_argc; /* undo final post-increment */ return; }
//------------------------------------------------------------------------ const char *rlFindFile(const char *pattern, int *context) { static char freturn[512]; #ifdef RLUNIX static DIR *dirp; static struct dirent *dp; if(*context == 0) dirp = opendir("."); *context = 1; while((dp = readdir(dirp)) != NULL) { if(dp->d_name[0] == '.') ; else if(strstr(dp->d_name,pattern) != NULL) { strcpy(freturn,dp->d_name); return freturn; } else if(rlStrMatch(dp->d_name, pattern)) { strcpy(freturn,dp->d_name); return freturn; } } closedir(dirp); return NULL; #endif #ifdef __VMS int i,ret; static char file[512] = ""; static char wildcard[80]; struct dsc$descriptor_s dwildcard; struct dsc$descriptor_s dfreturn; strcpy(wildcard,pattern); dwildcard.dsc$w_length = strlen(wildcard); dwildcard.dsc$a_pointer = wildcard; dwildcard.dsc$b_dtype = DSC$K_DTYPE_T; dwildcard.dsc$b_class = DSC$K_CLASS_S; dfreturn.dsc$w_length = sizeof(freturn); dfreturn.dsc$a_pointer = &freturn[0]; dfreturn.dsc$b_dtype = DSC$K_DTYPE_T; dfreturn.dsc$b_class = DSC$K_CLASS_S; ret = LIB$FIND_FILE(&dwildcard,&dfreturn,context,0,0,0,0); if (ret == RMS$_NMF) return NULL; // no more files found else if(ret != RMS$_NORMAL) return NULL; else if(strcmp(freturn,file) == 0) { file[0] = '\0'; return NULL; } i=0; while(freturn[i] > ' ')i++; freturn[i] = '\0'; return freturn; #endif #ifdef RLWIN32 static WIN32_FIND_DATAA wfd; static HANDLE hFindFile; if(*context == 0) // find first { *context = 1; hFindFile = FindFirstFileA(pattern,&wfd); if(hFindFile == INVALID_HANDLE_VALUE) return NULL; else strcpy(freturn,(const char *) &wfd.cFileName); } else // subsequent find { if(FindNextFileA(hFindFile,&wfd) == TRUE) strcpy(freturn,(const char *) &wfd.cFileName); else { FindClose(hFindFile); return NULL; } } return freturn; #endif }
void* ex_conv_array( int exoid, convert_task task, const void* usr_array, int usr_length ) { /* ex_conv_array() actually performs the floating point size conversion. * * "exoid" is some integer which uniquely identifies the file of interest. * * for reads, in conjunction with ncvarget()/ncvarget1(), ex_conv_array() must * be called twice per read. the first call must be before ncvarget(), and * should be something like ex_conv_array( id, RTN_ADDRESS, usr_array, len ), * where "usr_array" is the address of the user's data array, and "len" is * the number of floating point values to convert. this call returns an * address which should be passed as a parameter in the subsequent ncvarget() * call. after ncvarget(), call ex_conv_array() again with something like * ex_conv_array( ID, READ_CONVERT, usr_array, len ). here ex_conv_array() * should return NULL. * * for writes, in conjunction with ncvarput()/ncvarput1(), ex_conv_array() need * only be called once, before the call to ncvarput(). the call should be * something like ex_conv_array( id, WRITE_CONVERT, usr_array, len ), and * returns an address that should be passed in the subsequent ncvarput() call. */ char errmsg[MAX_ERR_LENGTH]; /* static void* buffer_array = NULL; -- now global! */ struct file_item* file; int len_bytes; exerrval = 0; /* clear error code */ if (do_conversion == 0) { switch( task ) { case RTN_ADDRESS: return (void*)usr_array; break; case READ_CONVERT: return NULL; break; case WRITE_CONVERT: return (void*)usr_array; break; default: /* Fall through if other task is specified */ ; } } FIND_FILE( file, exoid ); if( !file ) { exerrval = EX_BADFILEID; sprintf(errmsg,"Error: unknown file id %d",exoid); ex_err("ex_conv_array",errmsg,exerrval); return (NULL); } switch( task ) { case RTN_ADDRESS: switch( file->rd_conv_action ) { case NO_CONVERSION: return (void*)usr_array; case CONVERT_UP: /* file ws: 4 byte, CPU ws: 8 byte */ len_bytes = usr_length * sizeof(float); buffer_array = resize_buffer( buffer_array, len_bytes ); return buffer_array; case CONVERT_DOWN: /* file ws: 8 byte, CPU ws: 4 byte */ len_bytes = usr_length * sizeof(double); buffer_array = resize_buffer( buffer_array, len_bytes ); return buffer_array; } break; case READ_CONVERT: switch( file->rd_conv_action ) { case NO_CONVERSION: break; case CONVERT_UP: flt_to_dbl( buffer_array, usr_length, (void*)usr_array ); break; case CONVERT_DOWN: dbl_to_flt( buffer_array, usr_length, (void*)usr_array ); break; } return NULL; case WRITE_CONVERT: switch( file->wr_conv_action ) { case NO_CONVERSION: return (void*)usr_array; case CONVERT_UP: len_bytes = usr_length * sizeof(double); buffer_array = resize_buffer( buffer_array, len_bytes ); flt_to_dbl( (void*)usr_array, usr_length, buffer_array ); return buffer_array; case CONVERT_DOWN: len_bytes = usr_length * sizeof(float); buffer_array = resize_buffer( buffer_array, len_bytes ); dbl_to_flt( (void*)usr_array, usr_length, buffer_array ); return buffer_array; } break; case WRITE_CONVERT_DOWN: len_bytes = usr_length * sizeof(float); buffer_array = resize_buffer( buffer_array, len_bytes ); dbl_to_flt( (void*)usr_array, usr_length, buffer_array ); return buffer_array; case WRITE_CONVERT_UP: len_bytes = usr_length * sizeof(double); buffer_array = resize_buffer( buffer_array, len_bytes ); flt_to_dbl( (void*)usr_array, usr_length, buffer_array ); return buffer_array; } exerrval = EX_FATAL; sprintf(errmsg, "Error: unknown task code %d specified for converting float array",task); ex_err("ex_conv_array",errmsg,exerrval); return NULL; }