void _convolve(QSP_ARG_DECL Data_Obj *dpto,Data_Obj *dpfr,Data_Obj *dpfilt) { dimension_t i,j; float val, *frptr; dimension_t yos, offset; // where is the other error checking done??? INSIST_RAM_OBJ(dpto,convolve) INSIST_RAM_OBJ(dpfr,convolve) INSIST_RAM_OBJ(dpfilt,convolve) img_clear(dpto); frptr = (float *) OBJ_DATA_PTR(dpfr); j=OBJ_ROWS(dpto); while(j--){ yos = j * OBJ_ROW_INC(dpfr); i=OBJ_COLS(dpfr); while(i--){ offset = yos+i*OBJ_PXL_INC(dpfr); val = *(frptr+offset); add_impulse(val,dpto,dpfilt,i,j); } } }
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); } }
static COMMAND_FUNC( do_pipe_obj ) { Data_Obj *dp; Pipe *pp; char cmdbuf[LLEN]; dp=PICK_OBJ(""); pp=PICK_PIPE("readable pipe"); if( dp == NO_OBJ ) return; if( pp == NO_PIPE ) return; // reading is tricker for non-ram, because // we must create the copy, then read into // the copy, then xfer to the device... INSIST_RAM_OBJ(dp,"pipe_read_obj") sprintf(cmdbuf,"Pipe: %s",pp->p_cmd); read_ascii_data(QSP_ARG dp,pp->p_fp,cmdbuf,expect_exact_count); /* If there was just enough data, then the pipe * will have been closed already... */ /* BUG we should check qlevel to make sure that the pipe was popped... */ pp->p_fp = NULL; }
static COMMAND_FUNC( do_load_fb ) { Data_Obj *dp; int x,y; dp=PICK_OBJ(""); x=(int)HOW_MANY("x origin"); y=(int)HOW_MANY("y origin"); if( dp == NO_OBJ ) return; INSIST_RAM_OBJ(dp,"load_fb") fb_load(QSP_ARG dp,x,y); }
static COMMAND_FUNC( do_yplot ) { Data_Obj *dp; u_long i,j,k; std_type x,y,dx,*p; std_type x0; dp=PICK_OBJ("data vector"); if( bad_plot_vec(QSP_ARG dp,1,"yplot") ) return; INSIST_RAM_OBJ(dp,"yplot") dx=1; XYPLOT_LOOP( std_type, x0=0, y = *p; x = x0; x0+=dx ) }
static COMMAND_FUNC( do_xplot ) { Data_Obj *dp; u_long i,j,k; std_type x,y,y0,dy,*p; dp=PICK_OBJ("data vector"); if( bad_plot_vec(QSP_ARG dp,1,"xplot") ) return; INSIST_RAM_OBJ(dp,"xplot") dy=1; XYPLOT_LOOP( std_type, y0=0, x = (std_type)*p; y = y0; y0+=dy ) }
void vinterp(QSP_ARG_DECL Data_Obj *target,Data_Obj *source,Data_Obj *control) { float *to, *fr, *c; dimension_t i; int32_t n_to_interpolate=0; float *interp_dest; int32_t start_index=(-1); assert( target != NULL ); assert( source != NULL ); assert( control != NULL ); INSIST_RAM_OBJ(target,vinterp) INSIST_RAM_OBJ(source,vinterp) INSIST_RAM_OBJ(control,vinterp) if( not_prec(target,PREC_SP) ) return; if( not_prec(source,PREC_SP) ) return; if( not_prec(control,PREC_SP) ) return; if( !dp_same_size(target,source,"vinterp") ){ warn("vinterp: target/source length mismatch"); return; } if( !dp_same_size(target,control,"vinterp") ){ warn("vinterp: target/control length mismatch"); return; } if( OBJ_COMPS(source) != 1 || OBJ_COMPS(target) != 1 ){ warn("vinterp: component dimensions must be 1"); return; } /* could check that they are all vectors... */ to=(float *)OBJ_DATA_PTR(target); fr=(float *)OBJ_DATA_PTR(source); c=(float *)OBJ_DATA_PTR(control); interp_dest=to; for(i=0;i<OBJ_COLS(target);i++){ if( *c == 1.0 ){ /* copy data */ if( n_to_interpolate > 0 ){ /* end of gap? */ int j; float start_val, end_val; end_val = get_end_val(source,control,i); /* if we haven't seen any good values yet, * just fill in with the first good value. */ if( start_index < 0 ) start_val=end_val; /* * Otherwise, use a starting value which * is an average of the last N good values... */ else start_val = get_start_val(source,control,start_index); #ifdef DEBUG if( debug ){ sprintf(ERROR_STRING, "vinterp: %d values at index %d (start_i = %d), start = %f end = %f", n_to_interpolate,i,start_index,start_val,end_val); advise(ERROR_STRING); } #endif /* DEBUG */ for(j=0;j<n_to_interpolate;j++){ float factor; factor=((float)j+1)/((float)n_to_interpolate+1); *interp_dest = factor*end_val + (1-factor)*start_val; interp_dest += OBJ_PXL_INC(target); } } *to = *fr; start_index = i; /* always the last good one seen */ n_to_interpolate=0; } else { /* control is 0 */ if( n_to_interpolate == 0 ) /* remember start */ interp_dest = to; n_to_interpolate++; } to += OBJ_PXL_INC(target); c += OBJ_PXL_INC(control); fr += OBJ_PXL_INC(source); } if( n_to_interpolate > 0 ){ /* fill in at end? */ float fill_val; int j; if( start_index < 0 ){ warn("vinterp: no valid data!?"); fill_val=0.0; } else fill_val = get_start_val(source,control,start_index); for(j=0;j<n_to_interpolate;j++){ *interp_dest = fill_val; interp_dest += OBJ_PXL_INC(target); } } }
void multivariate_histo(QSP_ARG_DECL Data_Obj *histo_dp,Data_Obj *data_dp,float *width_array,float *min_array) { dimension_t n_dimensions; dimension_t i,j,k; unsigned int l; float *fbase, *fptr, *f; float *histbuf; incr_t index[MAX_DIMENSIONS]; int n_bins[MAX_DIMENSIONS]; int n_under[MAX_DIMENSIONS], n_over[MAX_DIMENSIONS]; INSIST_RAM_OBJ(histo_dp,compute_histo); INSIST_RAM_OBJ(data_dp,compute_histo); if( OBJ_PREC(histo_dp) != PREC_SP ){ NWARN("2D histogram precision must be float"); return; } if( OBJ_COMPS(histo_dp) != 1 ){ NWARN("2D histogram data must be real"); return; } if( OBJ_PXL_INC(histo_dp) != 1 ){ NWARN("2D histogram data must be contiguous"); return; } n_dimensions = OBJ_COMPS(data_dp); if( n_dimensions > MAX_DIMENSIONS ){ NWARN("Too many 2D histogram dimensions"); return; } if( OBJ_PREC(data_dp) != PREC_SP ){ NWARN("2D data precision must be float"); return; } fbase = (float *) OBJ_DATA_PTR(data_dp); for(l=0;l<n_dimensions;l++){ n_over[l]=0; n_under[l]=0; n_bins[l] = OBJ_TYPE_DIM(histo_dp,l+1); } histbuf = (float *) OBJ_DATA_PTR(histo_dp); zero_dimension(histo_dp,(float *)OBJ_DATA_PTR(histo_dp),n_dimensions,0L); for(l=0;l<MAX_DIMENSIONS;l++) index[l]=0; for(i=0;i<OBJ_FRAMES(data_dp);i++){ fptr = fbase; for(j=0;j<OBJ_ROWS(data_dp);j++){ f=fptr; for(k=0;k<OBJ_COLS(data_dp);k++){ float num[MAX_DIMENSIONS]; for(l=0;l<n_dimensions;l++){ num[l] = f[l]; /* assume cinc=1 */ num[l] -= min_array[l]; num[l] /= width_array[l]; num[l] += 0.5; index[l] = (incr_t)num[l]; /* cast to int */ if( index[l] < 0 ){ index[l]=0; n_under[l]++; } else if( index[l] >= n_bins[l] ){ index[l] = n_bins[l]-1; n_over[l]++; } } histbuf[ index[0] + index[1] * OBJ_ROW_INC(histo_dp) + index[2] * OBJ_FRM_INC(histo_dp) ] += 1.0; f += OBJ_PXL_INC(data_dp); } fptr += OBJ_ROW_INC(data_dp); } fbase += OBJ_FRM_INC(data_dp); } for(l=0;l<n_dimensions;l++){ if( (n_under[l] > 0) || (n_over[l] > 0) ){ sprintf(ERROR_STRING, "Histogram for %s had %d underflows and %d overflows in dimension %d", OBJ_NAME(data_dp),n_under[l],n_over[l],l); advise(ERROR_STRING); } } }
static COMMAND_FUNC( do_cyplot ) { Data_Obj *dp; Data_Obj *cdp; u_long i, np; /* number of points */ long inc; long cinc; std_type x,y,dx,*yp; char *cp; dp=PICK_OBJ("data vector"); cdp=PICK_OBJ("color vector"); if( dp==NO_OBJ ) return; if( cdp==NO_OBJ ) return; INSIST_RAM_OBJ(dp,"cyplot") INSIST_RAM_OBJ(cdp,"cyplot") if( OBJ_PREC(dp) != PREC_SP ) { WARN("do_cyplot: data vector should be float"); return; } if( OBJ_PREC(cdp) != PREC_BY ) { WARN("color vector should be byte"); return; } if( !dp_same_size(QSP_ARG dp,cdp,"do_cyplot") ) { sprintf(ERROR_STRING,"data vector %s and color vector %s must have identical sizes", OBJ_NAME(dp),OBJ_NAME(cdp)); WARN(ERROR_STRING); return; } if( OBJ_COLS(dp)==1 ) { /* maybe this is a column vector? */ np=OBJ_ROWS(dp); inc = OBJ_ROW_INC(dp); cinc = OBJ_ROW_INC(cdp); } else { np=OBJ_COLS(dp); inc = OBJ_PXL_INC(dp); cinc = OBJ_PXL_INC(cdp); } x=0; dx=1; i=np-1; yp = (std_type *) OBJ_DATA_PTR(dp); cp = (char *) OBJ_DATA_PTR(cdp); xp_fmove(x,*yp); xp_select(*cp); xp_fcont(x,*yp); while(i--) { yp += inc; cp += cinc; x += dx; y = *yp; xp_select(*cp); xp_fcont(x,y); } }