static void fpe_reset(Sigfunc *handler) { /* Reset the exception handling machinery, and reset the signal * handler for SIGFPE to the given handler. */ /*-- IRIX -----------------------------------------------------------------*/ #if defined(sgi) /* See man page on handle_sigfpes -- must link with -lfpe * My usage doesn't follow the man page exactly. Maybe somebody * else can explain handle_sigfpes to me.... * cc -c -I/usr/local/python/include fpectlmodule.c * ld -shared -o fpectlmodule.so fpectlmodule.o -lfpe */ #include <sigfpe.h> typedef void user_routine (unsigned[5], int[2]); typedef void abort_routine (unsigned long); handle_sigfpes(_OFF, 0, (user_routine *)0, _TURN_OFF_HANDLER_ON_ERROR, NULL); handle_sigfpes(_ON, _EN_OVERFL | _EN_DIVZERO | _EN_INVALID, (user_routine *)0, _ABORT_ON_ERROR, NULL); PyOS_setsig(SIGFPE, handler); /*-- SunOS and Solaris ----------------------------------------------------*/ #elif defined(sun) /* References: ieee_handler, ieee_sun, ieee_functions, and ieee_flags man pages (SunOS or Solaris) cc -c -I/usr/local/python/include fpectlmodule.c ld -G -o fpectlmodule.so -L/opt/SUNWspro/lib fpectlmodule.o -lsunmath -lm */ #include <math.h> #ifndef _SUNMATH_H extern void nonstandard_arithmetic(void); extern int ieee_flags(const char*, const char*, const char*, char **); extern long ieee_handler(const char*, const char*, sigfpe_handler_type); #endif char *mode="exception", *in="all", *out; (void) nonstandard_arithmetic(); (void) ieee_flags("clearall",mode,in,&out); (void) ieee_handler("set","common",(sigfpe_handler_type)handler); PyOS_setsig(SIGFPE, handler); /*-- HPUX -----------------------------------------------------------------*/ #elif defined(__hppa) || defined(hppa) /* References: fpsetmask man page */ /* cc -Aa +z -c -I/usr/local/python/include fpectlmodule.c */ /* ld -b -o fpectlmodule.sl fpectlmodule.o -lm */ #include <math.h> fpsetdefaults(); PyOS_setsig(SIGFPE, handler); /*-- IBM AIX --------------------------------------------------------------*/ #elif defined(__AIX) || defined(_AIX) /* References: fp_trap, fp_enable man pages */ #include <fptrap.h> fp_trap(FP_TRAP_SYNC); fp_enable(TRP_INVALID | TRP_DIV_BY_ZERO | TRP_OVERFLOW); PyOS_setsig(SIGFPE, handler); /*-- DEC ALPHA OSF --------------------------------------------------------*/ #elif defined(__alpha) && defined(__osf__) /* References: exception_intro, ieee man pages */ /* cc -c -I/usr/local/python/include fpectlmodule.c */ /* ld -shared -o fpectlmodule.so fpectlmodule.o */ #include <machine/fpu.h> unsigned long fp_control = IEEE_TRAP_ENABLE_INV | IEEE_TRAP_ENABLE_DZE | IEEE_TRAP_ENABLE_OVF; ieee_set_fp_control(fp_control); PyOS_setsig(SIGFPE, handler); /*-- DEC ALPHA LINUX ------------------------------------------------------*/ #elif defined(__alpha) && defined(linux) #include <asm/fpu.h> unsigned long fp_control = IEEE_TRAP_ENABLE_INV | IEEE_TRAP_ENABLE_DZE | IEEE_TRAP_ENABLE_OVF; ieee_set_fp_control(fp_control); PyOS_setsig(SIGFPE, handler); /*-- DEC ALPHA VMS --------------------------------------------------------*/ #elif defined(__ALPHA) && defined(__VMS) IEEE clrmsk; IEEE setmsk; clrmsk.ieee$q_flags = IEEE$M_TRAP_ENABLE_UNF | IEEE$M_TRAP_ENABLE_INE | IEEE$M_MAP_UMZ; setmsk.ieee$q_flags = IEEE$M_TRAP_ENABLE_INV | IEEE$M_TRAP_ENABLE_DZE | IEEE$M_TRAP_ENABLE_OVF; sys$ieee_set_fp_control(&clrmsk, &setmsk, 0); PyOS_setsig(SIGFPE, handler); /*-- HP IA64 VMS --------------------------------------------------------*/ #elif defined(__ia64) && defined(__VMS) PyOS_setsig(SIGFPE, handler); /*-- Cray Unicos ----------------------------------------------------------*/ #elif defined(cray) /* UNICOS delivers SIGFPE by default, but no matherr */ #ifdef HAS_LIBMSET libmset(-1); #endif PyOS_setsig(SIGFPE, handler); /*-- FreeBSD ----------------------------------------------------------------*/ #elif defined(__FreeBSD__) fpresetsticky(fpgetsticky()); fpsetmask(FP_X_INV | FP_X_DZ | FP_X_OFL); PyOS_setsig(SIGFPE, handler); /*-- Linux ----------------------------------------------------------------*/ #elif defined(linux) #ifdef __GLIBC__ #include <fpu_control.h> #else #include <i386/fpu_control.h> #endif #ifdef _FPU_SETCW { fpu_control_t cw = 0x1372; _FPU_SETCW(cw); } #else __setfpucw(0x1372); #endif PyOS_setsig(SIGFPE, handler); /*-- Microsoft Windows, NT ------------------------------------------------*/ #elif defined(_MSC_VER) /* Reference: Visual C++ Books Online 4.2, Run-Time Library Reference, _control87, _controlfp */ #include <float.h> unsigned int cw = _EM_INVALID | _EM_ZERODIVIDE | _EM_OVERFLOW; (void)_controlfp(0, cw); PyOS_setsig(SIGFPE, handler); /*-- Give Up --------------------------------------------------------------*/ #else fputs("Operation not implemented\n", stderr); #endif }
static void fpe_reset(Sigfunc *handler) { /* Reset the exception handling machinery, and reset the signal * handler for SIGFPE to the given handler. */ /*-- SunOS and Solaris ----------------------------------------------------*/ #if defined(sun) /* References: ieee_handler, ieee_sun, ieee_functions, and ieee_flags man pages (SunOS or Solaris) cc -c -I/usr/local/python/include fpectlmodule.c ld -G -o fpectlmodule.so -L/opt/SUNWspro/lib fpectlmodule.o -lsunmath -lm */ #include <math.h> #ifndef _SUNMATH_H extern void nonstandard_arithmetic(void); extern int ieee_flags(const char*, const char*, const char*, char **); extern long ieee_handler(const char*, const char*, sigfpe_handler_type); #endif char *mode="exception", *in="all", *out; (void) nonstandard_arithmetic(); (void) ieee_flags("clearall",mode,in,&out); (void) ieee_handler("set","common",(sigfpe_handler_type)handler); PyOS_setsig(SIGFPE, handler); /*-- HPUX -----------------------------------------------------------------*/ #elif defined(__hppa) || defined(hppa) /* References: fpsetmask man page */ /* cc -Aa +z -c -I/usr/local/python/include fpectlmodule.c */ /* ld -b -o fpectlmodule.sl fpectlmodule.o -lm */ #include <math.h> fpsetdefaults(); PyOS_setsig(SIGFPE, handler); /*-- IBM AIX --------------------------------------------------------------*/ #elif defined(__AIX) || defined(_AIX) /* References: fp_trap, fp_enable man pages */ #include <fptrap.h> fp_trap(FP_TRAP_SYNC); fp_enable(TRP_INVALID | TRP_DIV_BY_ZERO | TRP_OVERFLOW); PyOS_setsig(SIGFPE, handler); /*-- DEC ALPHA LINUX ------------------------------------------------------*/ #elif defined(__alpha) && defined(linux) #include <asm/fpu.h> unsigned long fp_control = IEEE_TRAP_ENABLE_INV | IEEE_TRAP_ENABLE_DZE | IEEE_TRAP_ENABLE_OVF; ieee_set_fp_control(fp_control); PyOS_setsig(SIGFPE, handler); /*-- Cray Unicos ----------------------------------------------------------*/ #elif defined(cray) /* UNICOS delivers SIGFPE by default, but no matherr */ #ifdef HAS_LIBMSET libmset(-1); #endif PyOS_setsig(SIGFPE, handler); /*-- FreeBSD ----------------------------------------------------------------*/ #elif defined(__FreeBSD__) fpresetsticky(fpgetsticky()); fpsetmask(FP_X_INV | FP_X_DZ | FP_X_OFL); PyOS_setsig(SIGFPE, handler); /*-- Linux ----------------------------------------------------------------*/ #elif defined(linux) #ifdef __GLIBC__ #include <fpu_control.h> #else #include <i386/fpu_control.h> #endif #ifdef _FPU_SETCW { fpu_control_t cw = 0x1372; _FPU_SETCW(cw); } #else __setfpucw(0x1372); #endif PyOS_setsig(SIGFPE, handler); /*-- Microsoft Windows, NT ------------------------------------------------*/ #elif defined(_MSC_VER) /* Reference: Visual C++ Books Online 4.2, Run-Time Library Reference, _control87, _controlfp */ #include <float.h> unsigned int cw = _EM_INVALID | _EM_ZERODIVIDE | _EM_OVERFLOW; (void)_controlfp(0, cw); PyOS_setsig(SIGFPE, handler); /*-- Give Up --------------------------------------------------------------*/ #else fputs("Operation not implemented\n", stderr); #endif }
PUBLIC float vrna_pf(vrna_fold_compound_t *vc, char *structure){ int n; FLT_OR_DBL Q; double free_energy; vrna_md_t *md; vrna_exp_param_t *params; vrna_mx_pf_t *matrices; free_energy = (float)(INF/100.); if(vc){ /* make sure, everything is set up properly to start partition function computations */ if(!vrna_fold_compound_prepare(vc, VRNA_OPTION_PF)){ vrna_message_warning("vrna_pf@part_func.c: Failed to prepare vrna_fold_compound"); return free_energy; } n = vc->length; params = vc->exp_params; matrices = vc->exp_matrices; md = &(params->model_details); #ifdef _OPENMP /* Explicitly turn off dynamic threads */ omp_set_dynamic(0); #endif #ifdef SUN4 nonstandard_arithmetic(); #else #ifdef HP9 fpsetfastmode(1); #endif #endif /* call user-defined recursion status callback function */ if(vc->stat_cb) vc->stat_cb(VRNA_STATUS_PF_PRE, vc->auxdata); switch(vc->type){ case VRNA_FC_TYPE_SINGLE: /* do the linear pf fold and fill all matrices */ pf_linear(vc); if(md->circ) pf_circ(vc); /* do post processing step for circular RNAs */ break; case VRNA_FC_TYPE_COMPARATIVE: /* do the linear pf fold and fill all matrices */ alipf_linear(vc); /* calculate post processing step for circular */ /* RNAs */ if(md->circ) wrap_alipf_circ(vc, structure); break; default: vrna_message_warning("vrna_pf@part_func.c: Unrecognized fold compound type"); return free_energy; break; } /* call user-defined recursion status callback function */ if(vc->stat_cb) vc->stat_cb(VRNA_STATUS_PF_POST, vc->auxdata); /* calculate base pairing probability matrix (bppm) */ if(md->compute_bpp){ vrna_pairing_probs(vc, structure); #ifdef VRNA_BACKWARD_COMPAT /* * Backward compatibility: * This block may be removed if deprecated functions * relying on the global variable "pr" vanish from within the package! */ pr = matrices->probs; /* { if(pr) free(pr); pr = (FLT_OR_DBL *) vrna_alloc(sizeof(FLT_OR_DBL) * ((n+1)*(n+2)/2)); memcpy(pr, probs, sizeof(FLT_OR_DBL) * ((n+1)*(n+2)/2)); } */ #endif } if (md->backtrack_type=='C') Q = matrices->qb[vc->iindx[1]-n]; else if (md->backtrack_type=='M') Q = matrices->qm[vc->iindx[1]-n]; else Q = (md->circ) ? matrices->qo : matrices->q[vc->iindx[1]-n]; /* ensemble free energy in Kcal/mol */ if (Q<=FLT_MIN) vrna_message_warning("pf_scale too large"); switch(vc->type){ case VRNA_FC_TYPE_COMPARATIVE: free_energy = (-log(Q)-n*log(params->pf_scale))*params->kT/(1000.0 * vc->n_seq); break; case VRNA_FC_TYPE_SINGLE: /* fall through */ default: free_energy = (-log(Q)-n*log(params->pf_scale))*params->kT/1000.0; break; } #ifdef SUN4 standard_arithmetic(); #else #ifdef HP9 fpsetfastmode(0); #endif #endif } return free_energy; }