/************************************************************************ * * * Extract slices in given (orthogonal) plane. */ void VolData::extract_planes(int orientation, int first, int last, int incr) { int i; char macrocmd[100]; int planelist[] = {front_plane, top_plane, side_plane}; char *planenames[] = {"xy", "xz", "yz"}; first = vdat->clip_slice(orientation, first); last = vdat->clip_slice(orientation, last); interrupt_begin(); if (Gframe::numFrames() == 0){ Gframe *gf = Gframe::big_gframe(); gf->select_frame(); } int nslices = 1 + (last - first) / incr; if (nslices > 1 && Gframe::numFrames() == 1){ // Split up our one frame to get enough to load all slices into. int nsplit = (int)sqrt((double)nslices); if (nslices > nsplit * nsplit){ nsplit++; } Gframe *gf = Gframe::get_frame_by_number(1); gf->select_frame(); gf->split(nsplit, nsplit); } for (i=first; i<=last && !interrupt(); i+=incr){ vdat->extract_plane(planelist[orientation], 1, &i); } interrupt_end(); sprintf(macrocmd,"vol_extract('%s', %d, %d, %d)\n", planenames[orientation], first, last, incr); macroexec->record(macrocmd); }
/************************************************************************ * * * Split each selected frame into multiple frames. * * [STATIC Function] * * */ void Frame_select::split(int row, int col) { Frame_select *ptr; Gframe *gf; if (selecthead->next == NULL) { if (!Gframe::get_first_frame()){ // No frames exist, make one and select it. gf = Gframe::big_gframe(); gf->mark(); selecthead->insert(gf); }else{ msgerr_print("split:No selected frame"); return; } } interrupt_begin(); for (ptr=selecthead->next; ptr; ptr=ptr->next) { if (interrupt()) { interrupt_msg("Interrupt at 'splitting' frame."); return; } ptr->frameptr->split(row, col); } interrupt_end(); macroexec->record("frame_split(%d, %d)\n", row, col); }
void sig_handler_common_tt(int sig, void *sc_ptr) { struct sigcontext *sc = sc_ptr; struct tt_regs save_regs, *r; struct signal_info *info; int save_errno = errno, is_user; unprotect_kernel_mem(); r = &TASK_REGS(get_current())->tt; save_regs = *r; is_user = user_context(SC_SP(sc)); r->sc = sc; if(sig != SIGUSR2) r->syscall = -1; change_sig(SIGUSR1, 1); info = &sig_info[sig]; if(!info->is_irq) unblock_signals(); (*info->handler)(sig, (union uml_pt_regs *) r); if(is_user){ interrupt_end(); block_signals(); change_sig(SIGUSR1, 0); set_user_mode(NULL); } *r = save_regs; errno = save_errno; if(is_user) protect_kernel_mem(); }
void new_thread_handler(int sig) { int (*fn)(void *), n; void *arg; fn = current->thread.request.u.thread.proc; arg = current->thread.request.u.thread.arg; change_sig(SIGUSR1, 1); thread_wait(¤t->thread.mode.skas.switch_buf, current->thread.mode.skas.fork_buf); if(current->thread.prev_sched != NULL) schedule_tail(current->thread.prev_sched); current->thread.prev_sched = NULL; /* The return value is 1 if the kernel thread execs a process, * 0 if it just exits */ n = run_kernel_thread(fn, arg, ¤t->thread.exec_buf); if(n == 1){ /* Handle any immediate reschedules or signals */ interrupt_end(); userspace(¤t->thread.regs.regs); } else do_exit(0); }
__externC void hal_interrupt_end( void ) { #ifdef CYGFUN_HAL_COMMON_KERNEL_SUPPORT cyg_scheduler_sched_lock++; #endif interrupt_end(0,0,0); }
void userspace(union uml_pt_regs *regs) { int err, status, op, pid = userspace_pid[0]; int local_using_sysemu; /*To prevent races if using_sysemu changes under us.*/ while(1){ restore_registers(pid, regs); /* Now we set local_using_sysemu to be used for one loop */ local_using_sysemu = get_using_sysemu(); op = SELECT_PTRACE_OPERATION(local_using_sysemu, singlestepping(NULL)); err = ptrace(op, pid, 0, 0); if(err) panic("userspace - could not resume userspace process, " "pid=%d, ptrace operation = %d, errno = %d\n", op, errno); CATCH_EINTR(err = waitpid(pid, &status, WUNTRACED)); if(err < 0) panic("userspace - waitpid failed, errno = %d\n", errno); regs->skas.is_user = 1; save_registers(pid, regs); UPT_SYSCALL_NR(regs) = -1; /* Assume: It's not a syscall */ if(WIFSTOPPED(status)){ switch(WSTOPSIG(status)){ case SIGSEGV: handle_segv(pid, regs); break; case SIGTRAP + 0x80: handle_trap(pid, regs, local_using_sysemu); break; case SIGTRAP: relay_signal(SIGTRAP, regs); break; case SIGIO: case SIGVTALRM: case SIGILL: case SIGBUS: case SIGFPE: case SIGWINCH: user_signal(WSTOPSIG(status), regs, pid); break; default: printk("userspace - child stopped with signal " "%d\n", WSTOPSIG(status)); } interrupt_end(); /* Avoid -ERESTARTSYS handling in host */ PT_SYSCALL_NR(regs->skas.regs) = -1; } } }
void userspace(union uml_pt_regs *regs) { int err, status, op, pid = userspace_pid[0]; restore_registers(regs); err = ptrace(PTRACE_SYSCALL, pid, 0, 0); if(err) panic("userspace - PTRACE_SYSCALL failed, errno = %d\n", errno); while(1){ CATCH_EINTR(err = waitpid(pid, &status, WUNTRACED)); if(err < 0) panic("userspace - waitpid failed, errno = %d\n", errno); regs->skas.is_user = 1; save_registers(regs); if(WIFSTOPPED(status)){ switch(WSTOPSIG(status)){ case SIGSEGV: handle_segv(pid); break; case SIGTRAP: handle_trap(pid, regs); break; case SIGIO: case SIGVTALRM: case SIGILL: case SIGBUS: case SIGFPE: case SIGWINCH: user_signal(WSTOPSIG(status), regs); break; default: printk("userspace - child stopped with signal " "%d\n", WSTOPSIG(status)); } interrupt_end(); } restore_registers(regs); op = singlestepping_skas() ? PTRACE_SINGLESTEP : PTRACE_SYSCALL; err = ptrace(op, pid, 0, 0); if(err) panic("userspace - PTRACE_SYSCALL failed, " "errno = %d\n", errno); } }
void fork_handler(int sig) { change_sig(SIGUSR1, 1); thread_wait(¤t->thread.mode.skas.switch_buf, current->thread.mode.skas.fork_buf); force_flush_all(); if(current->thread.prev_sched == NULL) panic("blech"); schedule_tail(current->thread.prev_sched); current->thread.prev_sched = NULL; /* Handle any immediate reschedules or signals */ interrupt_end(); userspace(¤t->thread.regs.regs); }
void sig_handler_common_tt(int sig, void *sc_ptr) { struct sigcontext *sc = sc_ptr; struct tt_regs save_regs, *r; struct signal_info *info; int save_errno = errno, is_user; unprotect_kernel_mem(); /* This is done because to allow SIGSEGV to be delivered inside a SEGV * handler. This can happen in copy_user, and if SEGV is disabled, * the process will die. */ if(sig == SIGSEGV) change_sig(SIGSEGV, 1); /* This is done because to allow SIGSEGV to be delivered inside a SEGV * handler. This can happen in copy_user, and if SEGV is disabled, * the process will die. */ if(sig == SIGSEGV) change_sig(SIGSEGV, 1); r = &TASK_REGS(get_current())->tt; save_regs = *r; is_user = user_context(SC_SP(sc)); r->sc = sc; if(sig != SIGUSR2) r->syscall = -1; info = &sig_info[sig]; if(!info->is_irq) unblock_signals(); (*info->handler)(sig, (union uml_pt_regs *) r); if(is_user){ interrupt_end(); block_signals(); set_user_mode(NULL); } *r = save_regs; errno = save_errno; if(is_user) protect_kernel_mem(); }
/* Called magically, see new_thread_handler above */ void fork_handler(void) { force_flush_all(); if(current->thread.prev_sched == NULL) panic("blech"); schedule_tail(current->thread.prev_sched); /* XXX: if interrupt_end() calls schedule, this call to * arch_switch_to_skas isn't needed. We could want to apply this to * improve performance. -bb */ arch_switch_to_skas(current->thread.prev_sched, current); current->thread.prev_sched = NULL; /* Handle any immediate reschedules or signals */ interrupt_end(); userspace(¤t->thread.regs.regs); }
/************************************************************************ * * * Extract a slice of data or the MIP of a list of slices. * A simple extraction is just a MIP over one slice. * Set "orientation" to front_plane, top_plane, or side_plane. * Set "slicelist" to the array of slice indices to do and "nslices" * to the number of slices in the array. * */ void VolData::extract_plane(int orientation, int nslices, int *slicelist) { int i; int j; int k; int k0; int k1; int nx; int ny; float *data; int slice; if (!vimage){ return; } // Make sure we are loading into a valid frame if ( targetframe == NULL || !framehead->exists(targetframe) ){ targetframe = framehead; Frame_routine::FindNextFreeFrame(); } gframe = targetframe; if (gframe == NULL){ msgerr_print("load_data: No Frames to load data into."); return; } selecthead->deselect(); gframe->mark(); selecthead->insert(gframe); int cursor = set_cursor_shape(IBCURS_BUSY); if (nslices > 1){ interrupt_begin(); } slice = *slicelist; // Prepare to get first slice if (orientation == front_plane){ float *buf = new float[nfast * nmedium]; // Attach a new Imginfo to the gframe detach_imginfo(gframe->imginfo); gframe->imginfo = new Imginfo(); gframe->imginfo->st = (DDLSymbolTable *)vimage->st->CloneList(FALSE); gframe->imginfo->InitializeSymTab(RANK_2D, BIT_32, TYPE_FLOAT, nfast, nmedium, 1, 1, 0); // Extract the first slice data = (float *)vimage->GetData() + slice * nfast * nmedium; for (i=0; i<nfast * nmedium; i++){ buf[i] = data[i]; } // Do the MIP of the data for (k=1; k<nslices && !interrupt(); k++){ slice = slicelist[k]; data = (float *)vimage->GetData() + slice * nfast * nmedium; for (i=0; i<nfast * nmedium; i++){ if (buf[i] < data[i]){ buf[i] = data[i]; } } } gframe->imginfo->st->SetData((char *)buf, sizeof(float) * nfast * nmedium); nx = nfast; ny = nmedium; delete[] buf; }else if (orientation == top_plane){ float *buf = new float[nfast * nslow]; // Attach a new Imginfo to the gframe detach_imginfo(gframe->imginfo); gframe->imginfo = new Imginfo(); gframe->imginfo->st = (DDLSymbolTable *)vimage->st->CloneList(FALSE); gframe->imginfo->InitializeSymTab(RANK_2D, BIT_32, TYPE_FLOAT, nfast, nslow, 1, 1, 0); // Extract the first slice data = (float *)vimage->GetData() + slice * nfast; for (j=0; j<nslow; j++){ k0 = j * nfast * nmedium; k1 = j * nfast; for (i=0; i<nfast; i++){ buf[i + k1] = data[i + k0]; } } // Do the MIP of the data for (k=1; k<nslices && !interrupt(); k++){ slice = slicelist[k]; data = (float *)vimage->GetData() + slice * nfast; for (j=0; j<nslow; j++){ k0 = j * nfast * nmedium; k1 = j * nfast; for (i=0; i<nfast; i++){ if (buf[i + k1] < data[i + k0]){ buf[i + k1] = data[i + k0]; } } } } gframe->imginfo->st->SetData((char *)buf, sizeof(float) * nfast * nslow); nx = nfast; ny = nslow; delete[] buf; }else if (orientation == side_plane){ float *buf = new float[nmedium * nslow]; // Attach a new Imginfo to the gframe detach_imginfo(gframe->imginfo); gframe->imginfo = new Imginfo(); gframe->imginfo->st = (DDLSymbolTable *)vimage->st->CloneList(FALSE); gframe->imginfo->InitializeSymTab(RANK_2D, BIT_32, TYPE_FLOAT, nmedium, nslow, 1, 1, 0); // Extract the first slice data = (float *)vimage->GetData() + slice; for (j=0; j<nslow; j++){ k0 = j * nfast * nmedium; k1 = j * nmedium; for (i=0; i<nmedium; i++){ buf[i + k1] = data[i*nfast + k0]; } } // Do the MIP of the data for (k=1; k<nslices && !interrupt(); k++){ slice = slicelist[k]; data = (float *)vimage->GetData() + slice; for (j=0; j<nslow; j++){ k0 = j * nfast * nmedium; k1 = j * nmedium; for (i=0; i<nmedium; i++){ if (buf[i + k1] < data[i*nfast + k0]){ buf[i + k1] = data[i*nfast + k0]; } } } } gframe->imginfo->st->SetData((char *)buf, sizeof(float) * nmedium * nslow); nx = nmedium; ny = nslow; delete[] buf; }else{ fprintf(stderr, "VolData::extract_plane(): Internal error %d\n", orientation); return; } extract_plane_header(gframe->imginfo, orientation, nslices, slicelist); gframe->imginfo->display_ood = gframe->imginfo->pixmap_ood = TRUE; Frame_data::display_data(gframe, 0, 0, nx, ny, gframe->imginfo->vs); Frame_routine::FindNextFreeFrame(); (void)set_cursor_shape(cursor); if (nslices > 1){ interrupt_end(); } }
void fit_images(FDFptr *in_object, int n_images, double *xvars, int nbr_xvars, double threshold, double chisq, double snThreshold, int width, int height, int depth, FDFptr *out_object, int n_out, int want_output(), int fit_type, int nparams, int use_prev_params, void function(), void jacobian(), int method(), int guess(), int parfix()) { int i; int j; int k; int okflag; int size; int threshok; int max_outfiles; int setuperr = 0; int prev_params_set = FALSE; double *prev_params; double resid; double *p_resid; double sosFit; // sum-of-squares deviation from fit for one pixel char msg[256]; double *covar; float **data; float **odata; double *params; double *y; data = (float **)getmem(n_images * sizeof(float *)); odata = (float **)getmem(n_out * sizeof(float *)); params = (double *)getmem(nparams * sizeof(double)); y = (double *)getmem(n_images * sizeof(double)); if (use_prev_params){ prev_params = (double *)getmem(nparams * sizeof(double)); } //p_resid = want_output(nparams) ? &resid : NULL; p_resid = &resid; max_outfiles = 2 * nparams + 1; /* params, rms residual, param sigmas */ // NB: Always calculate covariances covar = (double *)getmem((sizeof(double) * nparams * (nparams + 1)) / 2); for (i=0; i<n_images; i++){ data[i] = get_ddl_data(in_object[i]); } for (i=0; i<n_out; i++){ odata[i] = get_ddl_data(out_object[i]); } if (fit_type & (LINEAR_FIXED | LINEAR_RECALC_OFFSET)){ pixel_indx = 0; setuperr = linfit_setup(xvars, NULL, n_images, nparams, nbr_xvars, function); } interrupt_begin(); size = width * height * depth; for (pixel_indx=0; pixel_indx<size; pixel_indx++){ if (pixel_indx%width == 0){ sprintf(msg,"Math: image line #%d", pixel_indx/width); ib_msgline(msg); } if (!interrupt()){ // NB: Break out of loop over images as soon as we get threshok for (threshok=FALSE, j=0; j<n_images && !threshok; j++){ threshok = fabs(data[j][pixel_indx]) >= threshold; } } if (!threshok || interrupt() || setuperr){ /* Zero pixel in all output images */ for (j=0; j<n_out; j++){ if (want_output(j)){ odata[j][pixel_indx] = 0; } } }else{ for (j=0; j<n_images; j++){ y[j] = data[j][pixel_indx]; } if (fit_type & (LINEAR_FIXED | LINEAR_RECALC_OFFSET)){ okflag = linfit_go(xvars, y, n_images, nparams, nbr_xvars, fit_type==LINEAR_RECALC_OFFSET, function, params, p_resid, covar); }else if (fit_type & LINEAR_RECALC){ okflag = linfit(xvars, y, NULL, n_images, nparams, nbr_xvars, function, params, p_resid, covar); }else{ /* NONLINEAR */ if (prev_params_set){ okflag = TRUE; for (j=0; j<nparams; j++){ params[j] = prev_params[j]; } }else if (guess){ okflag = (*guess)(n_images, nparams, params, nbr_xvars, xvars, y, p_resid, covar); }else if (default_pars_set >= nparams){ for (j=0; j<nparams; j++){ params[j] = default_par_values[j]; } okflag = TRUE; }else{ okflag = FALSE; } if (okflag && method){ okflag = (*method)(n_images, y, nparams, params, nbr_xvars, xvars, function, jacobian, p_resid, covar); if (okflag <= 0 && prev_params_set){ /* Fit failed using previous params for guess. * Try another guess. */ if (guess){ okflag = (*guess)(n_images, nparams, params, nbr_xvars, xvars, y, p_resid, covar); }else if (default_pars_set >= nparams){ for (j=0; j<nparams; j++){ params[j] = default_par_values[j]; } okflag = TRUE; } okflag = (*method)(n_images, y, nparams, params, nbr_xvars, xvars, function, jacobian, p_resid, covar); } } } // NB: resid == p_resid // Calculate sum-of-squares deviation from fit // Convert RMS back into sum-of-squares sosFit = resid * resid * n_images; if (okflag <= 0){ /* Fit failed */ for (k=0; k<nparams; k++){ params[k] = 0; } resid = 0; if (covar){ for (k=0; k<(nparams * (nparams+1))/2; k++){ covar[k] = 0; } } }else{ if (use_prev_params){ /* Save starting params for next fit */ prev_params_set = TRUE; for (k=0; k<nparams; k++){ prev_params[k] = params[k]; } } if (parfix){ (*parfix)(nparams, params, covar); } } /* Write parameter info */ for (j=0; j<n_out && j<nparams; j++){ if (want_output(j)){ odata[j][pixel_indx] = (float)params[j]; } } // Calculate sum-of-squares deviation from average value double r0, sos0, avg; sos0 = 0; for (j=0; j<n_images; j++){ sos0 += data[j][pixel_indx]; } avg = sos0 / n_images; sos0 = 0; for (j = 0; j < n_images; j++) { r0 = data[j][pixel_indx] - avg; sos0 += r0 * r0; } /* Residual info, if requested */ if (want_output(nparams)) { odata[nparams][pixel_indx] = (float)resid; } /* Covariance info, if requested */ if (covar){ k = 0; for (j=nparams+1; j<n_out && j<max_outfiles; j++, k++){ if (want_output(j)){ /* Give sigma instead of variance. * "fabs" _should_ never be necessary. */ odata[j][pixel_indx] = (float)sqrt(fabs(TRI_ELEM(covar,k,k))); } } } // Check if parameter value is good enough if (sos0 / (resid * resid) < chisq) { // Overall fit is lousy by chisq test // Zero out all parameter data for this pixel for (j = 0; j < n_out && j < nparams; j++) { if (want_output(j)){ odata[j][pixel_indx] = 0; } } } else if (covar) { for (j = 0; j < n_out && j < nparams; j++) { if (want_output(j)) { double var = sqrt(fabs(TRI_ELEM(covar,j,j))); double val = fabs(odata[j][pixel_indx]); if (var > 0) { if (val / var < snThreshold) { // This parameter is badly estimated here // Zero out this parameter for this pixel odata[j][pixel_indx] = 0; } } } } } // Check if parameter values are within limits for (j = 0; j < n_out && j < nparams; j++) { if (want_output(j)) { double val = odata[j][pixel_indx]; if (val < pmin[j]) { odata[j][pixel_indx] = (float)pmin[j]; } else if (val > pmax[j]) { odata[j][pixel_indx] = (float)pmax[j]; } } } } } interrupt_end(); }
void userspace(union uml_pt_regs *regs) { int err, status, op, pt_syscall_parm, pid = userspace_pid[0]; int local_using_sysemu; /*To prevent races if using_sysemu changes under us.*/ restore_registers(regs); local_using_sysemu = get_using_sysemu(); pt_syscall_parm = local_using_sysemu ? PTRACE_SYSEMU : PTRACE_SYSCALL; err = ptrace(pt_syscall_parm, pid, 0, 0); if(err) panic("userspace - PTRACE_%s failed, errno = %d\n", local_using_sysemu ? "SYSEMU" : "SYSCALL", errno); while(1){ CATCH_EINTR(err = waitpid(pid, &status, WUNTRACED)); if(err < 0) panic("userspace - waitpid failed, errno = %d\n", errno); regs->skas.is_user = 1; save_registers(regs); if(WIFSTOPPED(status)){ switch(WSTOPSIG(status)){ case SIGSEGV: handle_segv(pid); break; case SIGTRAP: handle_trap(pid, regs, local_using_sysemu); break; case SIGIO: case SIGVTALRM: case SIGILL: case SIGBUS: case SIGFPE: case SIGWINCH: user_signal(WSTOPSIG(status), regs); break; default: printk("userspace - child stopped with signal " "%d\n", WSTOPSIG(status)); } interrupt_end(); } restore_registers(regs); /*Now we ended the syscall, so re-read local_using_sysemu.*/ local_using_sysemu = get_using_sysemu(); pt_syscall_parm = local_using_sysemu ? PTRACE_SYSEMU : PTRACE_SYSCALL; op = singlestepping(NULL) ? PTRACE_SINGLESTEP : pt_syscall_parm; err = ptrace(op, pid, 0, 0); if(err) panic("userspace - PTRACE_%s failed, " "errno = %d\n", local_using_sysemu ? "SYSEMU" : "SYSCALL", errno); } }
void fit_images(FDFptr *in_object, int n_images, float *xvars, int nbr_xvars, float threshold, int width, int height, int depth, FDFptr *out_object, int n_out, int want_output(), int fit_type, int nparams, int use_prev_params, void function(), void jacobian(), int method(), int guess(), int parfix()) { int nnn = 0;/*CMP*/ int i; int j; int k; int okflag; int size; int threshok; int max_outfiles; int setuperr = 0; int prev_params_set = FALSE; float *prev_params; float resid; float *p_resid; char msg[256]; float *covar; float **data; float **odata; float *params; float *y; data = (float **)getmem(n_images * sizeof(float *)); odata = (float **)getmem(n_out * sizeof(float *)); params = (float *)getmem(nparams * sizeof(float)); y = (float *)getmem(n_images * sizeof(float)); if (use_prev_params){ prev_params = (float *)getmem(nparams * sizeof(float)); } p_resid = want_output(nparams) ? &resid : NULL; max_outfiles = 2 * nparams + 1; /* params, rms residual, param sigmas */ if (n_out > nparams+1){ /* Covariance info required */ covar = (float *)getmem((sizeof(float) * nparams * (nparams + 1)) / 2); }else{ covar = NULL; } for (i=0; i<n_images; i++){ data[i] = get_ddl_data(in_object[i]); } for (i=0; i<n_out; i++){ odata[i] = get_ddl_data(out_object[i]); } if (fit_type & (LINEAR_FIXED | LINEAR_RECALC_OFFSET)){ pixel_indx = 0; setuperr = linfit_setup(xvars, NULL, n_images, nparams, nbr_xvars, function); /*fprintf(stderr,"linfit_setup rtns: %d\n", setuperr);/*CMP*/ } interrupt_begin(); size = width * height * depth; for (pixel_indx=0; pixel_indx<size; pixel_indx++){ if (pixel_indx%width == 0){ sprintf(msg,"Math: image line #%d", pixel_indx/width); ib_msgline(msg); } if (!interrupt()){ for (threshok=FALSE, j=0; j<n_images && !threshok; j++){ threshok = fabs(data[j][pixel_indx]) >= threshold; } } if (!threshok || interrupt() || setuperr){ /* Zero pixel in all output images */ for (j=0; j<n_out; j++){ if (want_output(j)){ odata[j][pixel_indx] = 0; } } }else{ for (j=0; j<n_images; j++){ y[j] = data[j][pixel_indx]; } if (fit_type & (LINEAR_FIXED | LINEAR_RECALC_OFFSET)){ okflag = linfit_go(xvars, y, n_images, nparams, nbr_xvars, fit_type==LINEAR_RECALC_OFFSET, function, params, p_resid, covar); }else if (fit_type & LINEAR_RECALC){ okflag = linfit(xvars, y, NULL, n_images, nparams, nbr_xvars, function, params, p_resid, covar); }else{ /* NONLINEAR */ if (prev_params_set){ okflag = TRUE; for (j=0; j<nparams; j++){ params[j] = prev_params[j]; } }else if (guess){ okflag = (*guess)(n_images, nparams, params, nbr_xvars, xvars, y, p_resid, covar); }else if (default_pars_set >= nparams){ for (j=0; j<nparams; j++){ params[j] = default_par_values[j]; } okflag = TRUE; }else{ okflag = FALSE; } if (okflag && method){ okflag = (*method)(n_images, y, nparams, params, nbr_xvars, xvars, function, jacobian, p_resid, covar); if (okflag <= 0 && prev_params_set){ /* Fit failed using previous params for guess. * Try another guess. */ if (guess){ okflag = (*guess)(n_images, nparams, params, nbr_xvars, xvars, y, p_resid, covar); }else if (default_pars_set >= nparams){ for (j=0; j<nparams; j++){ params[j] = default_par_values[j]; } okflag = TRUE; } okflag = (*method)(n_images, y, nparams, params, nbr_xvars, xvars, function, jacobian, p_resid, covar); } } } if (okflag <= 0){ /* Fit failed */ for (k=0; k<nparams; k++){ params[k] = 0; } resid = 0; if (covar){ for (k=0; k<(nparams * (nparams+1))/2; k++){ covar[k] = 0; } } }else{ if (use_prev_params){ /* Save starting params for next fit */ prev_params_set = TRUE; for (k=0; k<nparams; k++){ prev_params[k] = params[k]; } } if (parfix){ (*parfix)(nparams, params, covar); } } /* Write parameter info */ for (j=0; j<n_out && j<nparams; j++){ if (want_output(j)){ odata[j][pixel_indx] = params[j]; } } /* Residual info, if requested */ if (p_resid){ odata[nparams][pixel_indx] = resid; } /* Covariance info, if requested */ if (covar){ k = 0; for (j=nparams+1; j<n_out && j<max_outfiles; j++, k++){ if (want_output(j)){ /* Give sigma instead of variance. * "fabs" _should_ never be necessary. */ odata[j][pixel_indx] = sqrt(fabs(TRI_ELEM(covar,k,k))); } } } } } interrupt_end(); }
int mathexpr(ParmList inparms, ParmList *outparms) { float x, y, z; /* User variables */ float r[100]; /* Many user variables */ int ii, jj, kk; /* Integer user variables */ int n[100]; /* Many integer user variables */ int i, j, k; /* Pixel position in row, column, depth */ int width, height, depth; /* Size of all images */ int indx; /* Running pixel number */ char msg[128]; DDLSymbolTable *st; DDLSymbolTable *out; float **img; /* Vector of pointers to input data */ float *iout; /* Pointer to output data */ int nsrcs; /* Number of input images */ ParmList src_ddls; ParmList dst_ddls; /*fprintf(stderr,"mathexpr(0x%x, 0x%x)\n", inparms, outparms);/*CMP*/ /*printParm(inparms);/*CMP*/ /* Grab the input args */ src_ddls = findParm(inparms, "src_ddls"); if (!src_ddls){ ib_errmsg("MATH: \"src_ddls\" not passed"); return FALSE; } nsrcs = countParm(src_ddls); img = (float **)malloc(nsrcs * sizeof(float *)); fdfhandle = (DDLSymbolTable **)malloc(nsrcs * sizeof(DDLSymbolTable *)); if (!img || !fdfhandle){ ib_errmsg("MATH: out of memory"); return FALSE; } /* Check image sizes */ width = height = depth = 0; for (indx=0; indx<nsrcs; indx++){ getPtrParm(src_ddls, &st, indx); i = get_image_width(st); j = get_image_height(st); k = get_image_depth(st); if (!i || !j){ sprintf(msg,"MATH: image size is %dx%d\n", i, j); ib_errmsg(msg); return FALSE; } if ((width && i != width) || (height && j != height) || (depth && k != depth)) { ib_errmsg("MATH: images are different sizes\n"); return FALSE; } width = i; height = j; depth = k; /* Point the working source image pointers to the appropriate data */ img[indx] = get_ddl_data(st); fdfhandle[indx] = st; } /*fprintf(stderr,"MATH: width=%d, height=%d, depth=%d\n", width, height, depth);/*DBG*/ /* Copy the first input object (for storing the output image) */ getPtrParm(src_ddls, &st, 0); out = clone_ddl(st, 1); /*fprintf(stderr,"MATH: out width=%d, data=0x%x, *data=%g\n", get_image_width(out), get_ddl_data(out), *get_ddl_data(out));/*CMP*/ /*fprintf(stderr,"indata=0x%x, *indata=%g\n", img[0], img[0][0]);/*CMP*/ iout = get_ddl_data(out); /* * NOTE: IB_EXPRESSION will be expanded into something like * img[0][indx]+img[1][indx] */ interrupt_begin(); for (indx=k=0; k<depth; k++){ for (j=0; j<height; j++){ for (i=0; i<width && !interrupt(); i++, indx++){ iout[indx] = IB_EXPRESSION; } } } interrupt_end(); /*fprintf(stderr,"MATH: out width=%d, data=0x%x, *data=%g\n", get_image_width(out), get_ddl_data(out), *get_ddl_data(out));/*CMP*/ /* Pass back the output image */ *outparms = allocParm("dst_ddls", PL_PTR, 1); setPtrParm(*outparms, out, 0); return TRUE; }