static int is_good_for_inner(Data_Obj *dp,const char *func_name) { int retval=1; //#ifdef CAUTIOUS // if( dp == NO_OBJ ){ // NWARN("CAUTIOUS: is_good_for_inner passed null object pointer!?"); // return(0); // } //#endif /* CAUTIOUS */ assert( dp != NO_OBJ ); if( OBJ_COMPS(dp) > 1 ){ sprintf(DEFAULT_ERROR_STRING,"%s: object %s has %d components (should be 1)", func_name,OBJ_NAME(dp),OBJ_COMPS(dp)); NWARN(DEFAULT_ERROR_STRING); retval=0; } if( OBJ_MACH_PREC(dp) != PREC_SP && OBJ_MACH_PREC(dp) != PREC_DP ){ sprintf(DEFAULT_ERROR_STRING,"%s: object %s has machine prec %s (should be float or double)", func_name,OBJ_NAME(dp),OBJ_MACH_PREC_NAME(dp) ); NWARN(DEFAULT_ERROR_STRING); retval=0; } return(retval); }
static Visual *GetSpecifiedVisual( Disp_Obj * dop, int depth ) { XVisualInfo * vip; int visualsMatched; int i; const char * name; vip = get_depth_list(dop,depth,&visualsMatched); if( visualsMatched == 0 ) return(NULL); /* We need something more here, for openGL we have multiple visuals w/ 24 bit truecolor, * but not all have a Z buffer... * As a hack, we pass the desired visualID through the environment... */ { char *s; s=getenv("PREFERRED_VISUAL_ID"); if( s != NULL ){ int preferred_id; sprintf(DEFAULT_ERROR_STRING,"Checking for PREFERRED_VISUAL_ID %s",s); NADVISE(DEFAULT_ERROR_STRING); preferred_id = atoi(s); /* BUG decimal only, should parse hex too */ i=find_visual_by_id(vip,visualsMatched,preferred_id); if( i >= 0 ){ sprintf(DEFAULT_ERROR_STRING,"preferred visual id %d FOUND at index %d",preferred_id,i); NADVISE(DEFAULT_ERROR_STRING); return(vip[i].visual); } sprintf(DEFAULT_ERROR_STRING,"Unable to find requested visual id %d",preferred_id); NWARN(DEFAULT_ERROR_STRING); } } i=find_visual(vip,visualsMatched,PREFERRED_MODE,depth); if( i < 0 ){ sprintf(DEFAULT_ERROR_STRING,"no %s visual found with depth %d!?", PREFERRED_NAME,depth); NWARN(DEFAULT_ERROR_STRING); i=find_visual(vip,visualsMatched,ALTERNATE_MODE,depth); if( i < 0 ){ sprintf(DEFAULT_ERROR_STRING,"no %s visual found with depth %d!?", ALTERNATE_NAME,depth); NWARN(DEFAULT_ERROR_STRING); return(vip[0].visual); } else { name = ALTERNATE_NAME; } } else { name = PREFERRED_NAME; } if( verbose ){ sprintf(DEFAULT_ERROR_STRING,"i=%d, using visual %ld (%s, depth = %d)", i, vip[i].visualid,name,depth); NADVISE(DEFAULT_ERROR_STRING); } return(vip[i].visual); }
void g_fwdfft(QSP_ARG_DECL Data_Obj *dst_dp, Data_Obj *src1_dp) { //Variable declarations int NX = 256; //int BATCH = 10; int BATCH = 1; cufftResult_t status; //Declare plan for FFT cufftHandle plan; //cufftComplex *data; //cufftComplex *result; void *data; void *result; cudaError_t drv_err; //Allocate RAM //cutilSafeCall(cudaMalloc(&data, sizeof(cufftComplex)*NX*BATCH)); //cutilSafeCall(cudaMalloc(&result, sizeof(cufftComplex)*NX*BATCH)); drv_err = cudaMalloc(&data, sizeof(cufftComplex)*NX*BATCH); if( drv_err != cudaSuccess ){ WARN("error allocating cuda data buffer for fft!?"); return; } drv_err = cudaMalloc(&result, sizeof(cufftComplex)*NX*BATCH); if( drv_err != cudaSuccess ){ WARN("error allocating cuda result buffer for fft!?"); // BUG clean up previous malloc... return; } //Create plan for FFT status = cufftPlan1d(&plan, NX, CUFFT_C2C, BATCH); if (status != CUFFT_SUCCESS) { sprintf(ERROR_STRING, "Error in cufftPlan1d: %s\n", getCUFFTError(status)); NWARN(ERROR_STRING); } //Run forward fft on data status = cufftExecC2C(plan, (cufftComplex *)data, (cufftComplex *)result, CUFFT_FORWARD); if (status != CUFFT_SUCCESS) { sprintf(ERROR_STRING, "Error in cufftExecC2C: %s\n", getCUFFTError(status)); NWARN(ERROR_STRING); } //Run inverse fft on data /*status = cufftExecC2C(plan, data, result, CUFFT_INVERSE); if (status != CUFFT_SUCCESS) { sprintf(ERROR_STRING, "Error in cufftExecC2C: %s\n", getCUFFTError(status)); NWARN(ERROR_STRING); }*/ //Free resources cufftDestroy(plan); cudaFree(data); }
void dp_jacobi(QSP_ARG_DECL Data_Obj *v_dp, Data_Obj *d_dp, Data_Obj *a_dp, int *nrotp) { void *a_rowlist[MAX_DIM], *v_rowlist[MAX_DIM]; int n; if( OBJ_COLS(a_dp) != OBJ_ROWS(a_dp) ){ sprintf(DEFAULT_ERROR_STRING,"dp_jacobi: matrix %s must be square for jacobi",OBJ_NAME(a_dp)); NWARN(DEFAULT_ERROR_STRING); return; } if( OBJ_COLS(v_dp) != OBJ_ROWS(v_dp) ){ sprintf(DEFAULT_ERROR_STRING,"dp_jacobi: matrix %s must be square for jacobi",OBJ_NAME(v_dp)); NWARN(DEFAULT_ERROR_STRING); return; } if( OBJ_COLS(v_dp) != OBJ_COLS(a_dp) ){ sprintf(DEFAULT_ERROR_STRING,"dp_jacobi: size of eigenvector matrix %s must match input matrix %s for jacobi", OBJ_NAME(v_dp),OBJ_NAME(a_dp)); NWARN(DEFAULT_ERROR_STRING); return; } if( OBJ_COLS(d_dp) != OBJ_COLS(a_dp) ){ sprintf(DEFAULT_ERROR_STRING,"dp_jacobi: size of eigenvalue vector %s must match input matrix %s for jacobi", OBJ_NAME(d_dp),OBJ_NAME(a_dp)); NWARN(DEFAULT_ERROR_STRING); return; } if( ! IS_CONTIGUOUS(a_dp) ){ sprintf(DEFAULT_ERROR_STRING,"dp_jacobi: Object %s must be contiguous for jacobi",OBJ_NAME(a_dp)); NWARN(DEFAULT_ERROR_STRING); return; } if( ! IS_CONTIGUOUS(d_dp) ){ sprintf(DEFAULT_ERROR_STRING,"dp_jacobi: Object %s must be contiguous for jacobi",OBJ_NAME(d_dp)); NWARN(DEFAULT_ERROR_STRING); return; } if( ! IS_CONTIGUOUS(v_dp) ){ sprintf(DEFAULT_ERROR_STRING,"dp_jacobi: Object %s must be contiguous for jacobi",OBJ_NAME(v_dp)); NWARN(DEFAULT_ERROR_STRING); return; } n = OBJ_COLS(a_dp); /* BUG make sure types match */ if( OBJ_MACH_PREC(a_dp) == PREC_SP ){ float_init_rowlist((float **)(void *)a_rowlist,a_dp); float_init_rowlist((float **)(void *)v_rowlist,v_dp); float_jacobi(((float **)(void *)a_rowlist)-1,n,((float *)(OBJ_DATA_PTR(d_dp)))-1,((float **)(void *)v_rowlist)-1,nrotp); } else if( OBJ_MACH_PREC(a_dp) == PREC_DP ){ double_init_rowlist((double **)(void *)a_rowlist,a_dp); double_init_rowlist((double **)(void *)v_rowlist,v_dp); double_jacobi(((double **)(void *)a_rowlist)-1,n,((double *)(OBJ_DATA_PTR(d_dp)))-1,((double **)(void *)v_rowlist)-1,nrotp); } else { NWARN("bad precision in dp_jacobi"); } }
void dp_zroots(Data_Obj *r_dp, Data_Obj *a_dp, int polish ) { int m,n; n=OBJ_COLS(a_dp); /* polynomial degree + 1 */ m=OBJ_COLS(r_dp); if( m != n-1 ){ sprintf(DEFAULT_ERROR_STRING, "dp_zroots: len of root vector %s (%d) inconsistent with coefficients vector %s (%d)", OBJ_NAME(r_dp),OBJ_COLS(r_dp),OBJ_NAME(a_dp),OBJ_COLS(a_dp)); NWARN(DEFAULT_ERROR_STRING); return; } /* BUG make sure are row vectors */ if(OBJ_ROWS(a_dp) != 1 ){ sprintf(DEFAULT_ERROR_STRING,"dp_zroots: coefficient vector %s should be a row vector, (rows = %d)!?", OBJ_NAME(a_dp),OBJ_ROWS(a_dp)); NWARN(DEFAULT_ERROR_STRING); return; } if( OBJ_ROWS(r_dp) != 1 ){ sprintf(DEFAULT_ERROR_STRING,"dp_zroots: root vector %s should be a row vector, (rows = %d)!?", OBJ_NAME(r_dp),OBJ_ROWS(r_dp)); NWARN(DEFAULT_ERROR_STRING); return; } /* BUG make sure all vectors have same precision */ if( OBJ_MACH_PREC(a_dp) == PREC_SP ){ /* Why do we subtract 1 from the address of the roots, but not * the coefficients!? */ float_zroots( ((fcomplex *)OBJ_DATA_PTR(a_dp))/*-1*/, m, ((fcomplex *)OBJ_DATA_PTR(r_dp))-1, polish); } else if( OBJ_MACH_PREC(a_dp) == PREC_DP ){ double_zroots( ((dcomplex *)OBJ_DATA_PTR(a_dp))-1,m,((dcomplex *)OBJ_DATA_PTR(r_dp))-1,polish); } else { NWARN("bad machine precision in dp_zroots"); } }
void PF_FUNC_NAME(set_device)( QSP_ARG_DECL Platform_Device *pdp ) { #ifdef HAVE_CUDA cudaError_t e; #endif // HAVE_CUDA if( curr_pdp == pdp ){ sprintf(DEFAULT_ERROR_STRING,"%s: current device is already %s!?", STRINGIFY(HOST_CALL_NAME(set_device)),PFDEV_NAME(pdp)); NWARN(DEFAULT_ERROR_STRING); return; } if( PFDEV_PLATFORM_TYPE(pdp) != PLATFORM_CUDA ){ sprintf(ERROR_STRING,"%s: device %s is not a CUDA device!?", STRINGIFY(HOST_CALL_NAME(set_device)),PFDEV_NAME(pdp)); WARN(ERROR_STRING); return; } #ifdef HAVE_CUDA e = cudaSetDevice( PFDEV_CUDA_DEV_INDEX(pdp) ); if( e != cudaSuccess ) describe_cuda_driver_error2(STRINGIFY(HOST_CALL_NAME(set_device)),"cudaSetDevice",e); else curr_pdp = pdp; #else // ! HAVE_CUDA NO_CUDA_MSG(set_device) #endif // ! HAVE_CUDA }
static XVisualInfo *get_depth_list( Disp_Obj * dop, int depth, int *np ) { XVisualInfo vTemplate; /* try to get an 8 bit psuedocolor visual */ /* taken from Xlib prog manual p. 215 */ vTemplate.depth=depth; vTemplate.screen=dop->do_screen; if( visualList != NULL ) XFree(visualList); visualList = XGetVisualInfo(dop->do_dpy,VisualScreenMask|VisualDepthMask, &vTemplate,np); if( visualList == NULL ){ sprintf(DEFAULT_ERROR_STRING, "get_depth_list(%d) got NULL from XGetVisualInfo!?",depth); NWARN(DEFAULT_ERROR_STRING); } #ifdef QUIP_DEBUG if( debug & xdebug ){ sprintf(DEFAULT_ERROR_STRING,"%d visuals found with depth %d",*np,depth); NADVISE(DEFAULT_ERROR_STRING); } #endif /* QUIP_DEBUG */ return(visualList); }
Disp_Obj *open_display(QSP_ARG_DECL const char *name,int desired_depth) { Disp_Obj *dop; static int siz_done=0; dop = new_disp_obj(QSP_ARG name); if( dop == NO_DISP_OBJ ){ sprintf(ERROR_STRING, "Couldn't create object for display %s", name); NWARN(ERROR_STRING); return(NO_DISP_OBJ); } if( dop_open(QSP_ARG dop) < 0 ){ return(NO_DISP_OBJ); } if( dop_setup(QSP_ARG dop,desired_depth) < 0 ){ /* Bug - XCloseDisplay?? */ /* need to destroy object here */ del_disp_obj(QSP_ARG dop); rls_str((char *)dop->do_name); return(NO_DISP_OBJ); } set_display(dop); if( ! siz_done ){ siz_done++; add_sizable(QSP_ARG disp_obj_itp,&dpy_sf, NULL ); } return(dop); }
static Visual *GetEightBitVisual( Disp_Obj * dop) { int visualsMatched=0; Visual *vis; XVisualInfo *vip; int i; vip = get_depth_list(dop,8,&visualsMatched); if( visualsMatched == 0 ) return(NULL); i=find_visual(vip,visualsMatched,PseudoColor,8); if( i < 0 ){ NWARN("no pseudocolor visual found!?"); return(vip[0].visual); } #ifdef QUIP_DEBUG if( debug & xdebug ){ sprintf(DEFAULT_ERROR_STRING,"using visual %ld",vip[i].visualid); NADVISE(DEFAULT_ERROR_STRING); vis=DefaultVisual(dop->do_dpy,dop->do_screen); sprintf(DEFAULT_ERROR_STRING,"default visual is %ld",vis->visualid); NADVISE(DEFAULT_ERROR_STRING); } #endif /* QUIP_DEBUG */ return(vip[i].visual); }
void insure_cu2_device( QSP_ARG_DECL Data_Obj *dp ) { Platform_Device *pdp; if( AREA_FLAGS(OBJ_AREA(dp)) & DA_RAM ){ sprintf(DEFAULT_ERROR_STRING, "insure_cu2_device: Object %s is a host RAM object!?",OBJ_NAME(dp)); NWARN(DEFAULT_ERROR_STRING); return; } pdp = AREA_PFDEV(OBJ_AREA(dp)); #ifdef CAUTIOUS if( pdp == NULL ) NERROR1("CAUTIOUS: null cuda device ptr in data area!?"); #endif /* CAUTIOUS */ if( curr_pdp != pdp ){ sprintf(DEFAULT_ERROR_STRING,"insure_cu2_device: curr_pdp = 0x%lx pdp = 0x%lx", (int_for_addr)curr_pdp,(int_for_addr)pdp); NADVISE(DEFAULT_ERROR_STRING); sprintf(DEFAULT_ERROR_STRING,"insure_cu2_device: current device is %s, want %s", PFDEV_NAME(curr_pdp),PFDEV_NAME(pdp)); NADVISE(DEFAULT_ERROR_STRING); PF_FUNC_NAME(set_device)(QSP_ARG pdp); } }
void dp_moment(QSP_ARG_DECL Data_Obj *d_dp) { /* std_type *d_rowlist[MAX_DIM]; */ int n; if( ! IS_CONTIGUOUS(d_dp) ){ sprintf(DEFAULT_ERROR_STRING,"dp_moment: Object %s must be contiguous for eigsrt",OBJ_NAME(d_dp)); NWARN(DEFAULT_ERROR_STRING); return; } n = OBJ_COLS(d_dp); if( OBJ_MACH_PREC(d_dp) == PREC_SP ){ float adev, var, skew, curt; float ave, sdev; /* BUG - the results don't get passed out anywhere!? */ float_moment(((float *)(OBJ_DATA_PTR(d_dp))),n,&ave,&adev,&sdev,&var,&skew,&curt); } else if( OBJ_MACH_PREC(d_dp) == PREC_DP ){ double adev, var, skew, curt; double ave, sdev; double_moment(((double *)(OBJ_DATA_PTR(d_dp))),n,&ave,&adev,&sdev,&var,&skew,&curt); } }
static void init_pf_viewer_subsystem(void) { const char *pn; int n; pn = tell_progname(); if( pf_viewer_subsystem_inited ){ NWARN("Platform viewer subsystem already initialized!?"); return; } // First initialize OpenGL context, so we can properly set // the GL for CUDA. // This is necessary in order to achieve optimal performance // with OpenGL/CUDA interop. //glutInit( &argc, argv); /* BUG? where should this be done? */ n=1; #ifdef HAVE_GLUT glutInit( &n, (char **)&pn); /* BUG? where should this be done? */ glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE); #endif // HAVE_GLUT pf_viewer_subsystem_inited=1; }
void set_ncomps(int n) { char str[256]; if( n > MAX_COMPS ) { sprintf(str, "too many image components specified, using %d", MAX_COMPS); NWARN(str); n = MAX_COMPS; } else if( n < 2 ){ NWARN("must be at least two components, set to 2"); n = 2; } n_comps = n; }
static void text_func(Widget textID, XtPointer app_data, XtPointer widget_data ) { Screen_Obj *sop; const char *s; sop=find_object(DEFAULT_QSP_ARG textID); #ifdef CAUTIOUS if( sop == NO_SCREEN_OBJ ){ NWARN("CAUTIOUS: text_func: couldn't locate text widget"); return; } #endif /* CAUTIOUS */ s = get_text(sop); if( s == NULL ) assign_reserved_var( SOB_QSP_ARG "input_string","(null)"); else { assign_reserved_var( SOB_QSP_ARG "input_string",s); free((void *)s); } /* We should chew the text when a return is typed, or something? */ NADVISE("text_func calling chew_text..."); chew_text(DEFAULT_QSP_ARG sop->so_action_text,"(text event)"); } // text_func
static void float_sort_svd_eigenvectors(Data_Obj *u_dp, Data_Obj *w_dp, Data_Obj *v_dp) { //SORT_EIGENVECTORS(float) dimension_t i,n; u_long *index_data; n = OBJ_COLS(w_dp); index_dp = mkvec("svd_tmp_indices",n,1,PREC_UDI); if( index_dp == NULL ){ NWARN("Unable to create index object for sorting SVD eigenvalues"); return; } sort_indices(index_dp,w_dp); /* sorting is done from smallest to largest */ j=0; index_data = OBJ_DATA_PTR(index_dp); /* We should only have to have 1 column of storage to permute things, * but life is simplified if we copy the data... */ for(i=n-1;i>=0;i--){ k= *(index_data+i); } }
void set_comp_amps(QSP_ARG_DECL float *amps) { int i; float minc; if( n_comps < 0 ){ NWARN("must specify number of components"); return; } /* set up multipliers */ minc = (float)(2.0 / ((float)lvls_per_comp-1.0)); mult[0] = (float)-1.0; for(i=1;i<lvls_per_comp;i++) mult[i] = mult[i-1] + minc; amplist = amps; /* count base n */ push_cm_state(); CLR_CM_STATE(IMMEDIATE); count(QSP_ARG n_comps-1,base_index); pop_cm_state(); update_if(); }
const char *tell_progname(void) { if( _progname == NULL ){ NWARN("tell_progname(): progname not set!?"); return(""); } return(_progname); }
static Disp_Obj * default_x_display(SINGLE_QSP_ARG_DECL) { const char *dname; Disp_Obj *dop; int which_depth; char *s; dname = check_display(SINGLE_QSP_ARG); /* these two lines added so this can be called more than once */ dop = disp_obj_of(QSP_ARG dname); if( dop != NO_DISP_OBJ ) return(dop); s=getenv("DESIRED_DEPTH"); if( s != NULL ){ int desired_depth; desired_depth=atoi(s); sprintf(ERROR_STRING,"Desired depth %d obtained from environment",desired_depth); advise(ERROR_STRING); dop = open_display(QSP_ARG dname,desired_depth); if( dop != NO_DISP_OBJ ) return(dop); sprintf(ERROR_STRING,"Unable to open display %s with $DESIRED_DEPTH (%d)", dname,desired_depth); NWARN(ERROR_STRING); } for(which_depth=0;which_depth<MAX_DISPLAY_DEPTHS;which_depth++){ dop = open_display(QSP_ARG dname,possible_depths[which_depth]); if( dop != NO_DISP_OBJ ){ if( verbose ){ sprintf(ERROR_STRING, "Using depth %d on display %s", possible_depths[which_depth],dname); advise(ERROR_STRING); } return(dop); } else { if( verbose && which_depth<(MAX_DISPLAY_DEPTHS-1) ){ sprintf(ERROR_STRING, "Couldn't get %d bit visual on device %s, trying %d", possible_depths[which_depth],dname, possible_depths[which_depth+1]); advise(ERROR_STRING); } } } if( verbose ){ sprintf(ERROR_STRING, "Couldn't get %d bit visual on device %s, giving up", possible_depths[MAX_DISPLAY_DEPTHS-1],dname); advise(ERROR_STRING); } return(dop); } /* end default_x_display */
void set_base_index(int i) { if( i<0 || i>DACMAX ) { NWARN("base value out of range, using 0"); base_index=0; return; } base_index=i; }
void w_set_error_rate(double er) { if( er < 0 ){ NWARN("error rate must be non-negative"); return; } else if( er >= 1 ){ NWARN("error rate cannot be >= 1"); return; } else if( er < MIN_DELTA ){ if( verbose ){ sprintf(DEFAULT_ERROR_STRING, "Setting error rate to minimum permissable value: %g", MIN_DELTA); NADVISE(DEFAULT_ERROR_STRING); } er = MIN_DELTA; } error_rate=er; }
void dp_choldc(Data_Obj *a_dp, Data_Obj *p_dp) { unsigned m, n; void *a_rowlist[MAX_DIM]; /* n=OBJ_ROWS(a_dp); if( n > MAX_DIM ){ NWARN("Sorry, MAX dimension exceeded in dp_choldc"); sprintf(DEFAULT_ERROR_STRING,"dp_choldc: MAX_DIM = %d, n = %d", MAX_DIM,n); NADVISE(DEFAULT_ERROR_STRING); return; } */ n=OBJ_COLS(a_dp); m=OBJ_ROWS(a_dp); if( n > MAX_DIM || m > MAX_DIM ){ NWARN("Sorry, MAX dimension exceeded in dp_choldc"); sprintf(DEFAULT_ERROR_STRING,"dp_choldc: MAX_DIM = %d, n = %d, m = %d", MAX_DIM,n,m); NADVISE(DEFAULT_ERROR_STRING); return; } printf("nrmenu:numrec.c data %f\n", *((float *)OBJ_DATA_PTR(a_dp))); if( OBJ_MACH_PREC(a_dp) == PREC_SP ){ float_init_rowlist((float **)(void *)a_rowlist,a_dp); float_choldc(((float **)(void *)a_rowlist)-1,n,((float *)OBJ_DATA_PTR(p_dp))-1); } else if( OBJ_MACH_PREC(a_dp) == PREC_DP ){ double_init_rowlist((double **)(void *)a_rowlist,a_dp); double_choldc(((double **)(void *)a_rowlist)-1,n,((double *)OBJ_DATA_PTR(p_dp))-1); } else { NWARN("bad machine precision in dp_choldc"); } }
static int prec_and_type_match(Data_Obj *dp1,Data_Obj *dp2,const char *func_name) { if( OBJ_PREC(dp1) != OBJ_PREC(dp2) ){ sprintf(DEFAULT_ERROR_STRING,"Function %s: precisions of objects %s (%s) and %s (%s) do not match!?", func_name,OBJ_NAME(dp1),OBJ_PREC_NAME(dp1),OBJ_NAME(dp2),OBJ_PREC_NAME(dp2)); NWARN(DEFAULT_ERROR_STRING); return(0); } return(1); }
void set_lvls_per_comp(int n) { char str[256]; if( n < 2 || n > MAX_LEVELS ){ sprintf(str, "bad number of bits per component, using %d", MAX_LEVELS); NWARN(str); n = MAX_LEVELS; } lvls_per_comp = n ; }
static int same_pixel_type(QSP_ARG_DECL Data_Obj *dp1,Data_Obj *dp2) /* BUG? needed or redundant? */ { if( !dp_same_prec(QSP_ARG dp1,dp2,"same_pixel_type") ) return(0); if( OBJ_MACH_DIM(dp1,0) != OBJ_MACH_DIM(dp2,0) ){ sprintf(DEFAULT_ERROR_STRING,"component count mismatch: %s (%d), %s (%d)", OBJ_NAME(dp1),OBJ_MACH_DIM(dp2,0), OBJ_NAME(dp2),OBJ_MACH_DIM(dp2,0)); NWARN(DEFAULT_ERROR_STRING); return(0); } return(1); }
u_long simulate_lut_mapping(Viewer *vp, u_long color) { int index; int r,g,b; /* need to get the color map for this viewer */ if( VW_CMAP_OBJ(vp) == NO_OBJ ){ NWARN("simulate_lut_mapping: no colormap!?"); return(color); } index = color; if( index < 0 || index >= N_COLORS ){ sprintf(DEFAULT_ERROR_STRING,"simulate_lut_mapping: index %d (0x%x) must be in the range 0-%d", index,index,N_COLORS); NWARN(DEFAULT_ERROR_STRING); return(0); } r = CM_DATA(VW_CMAP_OBJ(vp),0,index); g = CM_DATA(VW_CMAP_OBJ(vp),1,index); b = CM_DATA(VW_CMAP_OBJ(vp),2,index); /* This is the 24 bit case */ if( vp->vw_depth == 24 ){ color = r; color <<= 8; color |= g; color <<= 8; color |= b; /* no alpha for now */ } else if( vp->vw_depth == 16 ){ color = ((r>>3)&0x1f)<<11; color |= ((g>>2)&0x3f)<<5; color |= ((b>>2)&0x1f); }
void set_bit_vecs( float veclist[MAX_COMPS][3] ) { int i; if( n_comps < 0 ){ NWARN("must set number of components before specifing vectors"); return; } for(i=0;i<n_comps;i++){ vector_table[i][0] = veclist[i][0]; vector_table[i][1] = veclist[i][1]; vector_table[i][2] = veclist[i][2]; } SET_CM_FLAG( SETBITVECS ); }
void compute_histo(QSP_ARG_DECL Data_Obj *histo_dp,Data_Obj *data_dp,double bin_width,double min_limit) { dimension_t i,j,k; float num; float *histbuf; incr_t index; dimension_t n_bins; int n_under=0, n_over=0; INSIST_RAM_OBJ(histo_dp,compute_histo); INSIST_RAM_OBJ(data_dp,compute_histo); if( OBJ_PREC(histo_dp) != PREC_SP ){ WARN("histogram precision must be float"); return; } if( OBJ_COMPS(histo_dp) != 1 ){ WARN("histogram data must be real"); return; } if( OBJ_ROWS(histo_dp) > 1 || OBJ_FRAMES(histo_dp) > 1 ){ WARN("only using first row of histogram image"); } if( OBJ_COMPS(data_dp) != 1 ){ WARN("input data must be real"); return; } switch( OBJ_PREC(data_dp) ){ case PREC_SP: HISTOGRAM(float) break; case PREC_DP: HISTOGRAM(double) break; case PREC_UBY: HISTOGRAM(u_char) break; case PREC_BY: HISTOGRAM(char) break; case PREC_UIN: HISTOGRAM(u_short) break; case PREC_IN: HISTOGRAM(short) break; case PREC_UDI: HISTOGRAM(u_long) break; case PREC_DI: HISTOGRAM(long) break; default: NWARN("unhandled source precision in histogram"); return; } if( (n_under > 0) || (n_over > 0) ){ sprintf(ERROR_STRING, "Histogram for %s had %d underflows and %d overflows", OBJ_NAME(data_dp),n_under,n_over); advise(ERROR_STRING); } }
double determinant(Data_Obj *dp) { /* switch(OBJ_MACH_PREC(dp)){ case PREC_SP: return sp_obj_determinant(dp); case PREC_DP: return dp_obj_determinant(dp); default: sprintf(DEFAULT_ERROR_STRING,"determinant: object %s has unsupported precision %s", OBJ_NAME(dp),OBJ_MACH_PREC_NAME(dp)); NWARN(DEFAULT_ERROR_STRING); return(0.0); } */ NWARN("Need to implement sp_obj_determinant..."); /* NOTREACHED */ return(0.0); }
// not used? int cu2_dispatch( QSP_ARG_DECL Vector_Function *vfp, Vec_Obj_Args *oap ) { int i; i = vfp->vf_code; if( cu2_func_tbl[i].cu2_func == NULL){ sprintf(DEFAULT_ERROR_STRING,"Sorry, function %s has not yet been implemented for the cuda2 platform.",VF_NAME(vfp)); NWARN(DEFAULT_ERROR_STRING); return(-1); } // BUG? why not typtbl??? //fprintf(stderr,"cu2_dispatch calling tabled function %d at 0x%lx\n", //i,(u_long)vec_func_tbl[i].cu2_func); //fprintf(stderr,"cu2_dispatch calling function %s\n", //VF_NAME(&vec_func_tbl[i])); (*cu2_func_tbl[i].cu2_func)(VF_CODE(vfp),oap); return(0); }
static const char *show_unprintable(QSP_ARG_DECL const char* s) { char *to; const char *fr; fr=s; to=printable_str; //fprintf(stderr,"show_unprintable: string len is %d, printable_len is %d\n", //strlen(s),PRINTABLE_LEN); if( strlen(s) >= PRINTABLE_LEN ){ sprintf(DEFAULT_ERROR_STRING, "show_unprintable: input string length (%ld) is greater than buffer size (%d)!?", (long) strlen(s), PRINTABLE_LEN ); NWARN(DEFAULT_ERROR_STRING); //return(s); /* print a warning here? */ return("<string too long>"); } /* BUG we aren't making sure that we don't overrun printable_str!? */ while(*fr){ if( isascii(*fr) ){ if( isprint(*fr) || isspace(*fr) ){ /* Don't escape backslashes */ /* if( *fr == '\\' ) *to++ = '\\'; */ *to++ = *fr; } else { //ADVISE("show_unprintable expanding a non-printing char..."); *to++ = '\\'; *to++ = '0' + (((*fr)>>6)&0x3); *to++ = '0' + (((*fr)>>3)&0x7); *to++ = '0' + (((*fr)>>0)&0x7); } } else { // assume UTF8??? // are there any unprintable UTF8 characters??? *to++ = *fr; } fr++; }