trap_version TRAPENTRY TrapInit( char *parm, char *err, bool remote ) { trap_version ver; out( "in TrapInit\r\n" ); out( " checking environment:\r\n" ); CPUType = X86CPUType(); Flags.Is386 = ( CPUType >= X86_386 ); if( parm[0] == 'D' || parm[0] == 'd' ) { Flags.DRsOn = FALSE; ++parm; } else if( out0( " CPU type\r\n" ) || ( Flags.Is386 == 0 ) ) { Flags.DRsOn = FALSE; } else if( out0( " WinEnh\r\n" ) || ( EnhancedWinCheck() & 0x7f ) ) { /* Enhanced Windows 3.0 VM kernel messes up handling of debug regs */ Flags.DRsOn = FALSE; } else if( out0( " DOSEMU\r\n" ) || DOSEMUCheck() ) { /* no fiddling with debug regs in Linux DOSEMU either */ Flags.DRsOn = FALSE; } else { Flags.DRsOn = TRUE; } if( parm[0] == 'O' || parm[0] == 'o' ) { Flags.NoOvlMgr = TRUE; } out( " done checking environment\r\n" ); err[0] = '\0'; /* all ok */ Flags.IsMMX = ( ( CPUType & X86_MMX ) != 0 ); Flags.IsXMM = ( ( CPUType & X86_XMM ) != 0 ); /* NPXType initializes '87, so check for it before a program starts using the thing */ RealNPXType = NPXType(); InitVectors(); if( DOS_major >= 20 ) { /* In an OS/2 2.0 DOS box. It doesn't let us fiddle the debug registers. The check is done here because InitVectors is the routine that sets up DOS_major */ Flags.DRsOn = FALSE; } Null87Emu(); NullOvlHdlr(); TrapTypeInit(); RedirectInit(); ExceptNum = -1; WatchCount = 0; ver.major = TRAP_MAJOR_VERSION; ver.minor = TRAP_MINOR_VERSION; ver.remote = FALSE; out( "done TrapInit\r\n" ); return( ver ); }
/* Creates a new bacteria and fills the aminoacids arrays */ Bacteria::Bacteria(char *filename) { FILE * bacteria_file = fopen(filename,"r"); InitVectors(); /* This part is the same */ char ch; while ((ch = fgetc(bacteria_file)) != EOF) { if (ch == '>') { while (fgetc(bacteria_file) != '\n'); // skip rest of line char buffer[LEN-1]; fread(buffer, sizeof(char), LEN-1, bacteria_file); init_buffer(buffer); } else if (ch != '\n' && ch != '\r') cont_buffer(ch); } fclose (bacteria_file); }
/* Changed A LOT */ Bacteria(char* filename) { FILE * bacteria_file = fopen(filename,"r"); InitVectors(); /* This part is the same */ char ch; while ((ch = fgetc(bacteria_file)) != EOF) { if (ch == '>') { while (fgetc(bacteria_file) != '\n'); // skip rest of line char buffer[LEN-1]; fread(buffer, sizeof(char), LEN-1, bacteria_file); init_buffer(buffer); } else if (ch != '\n' && ch != '\r') cont_buffer(ch); } // keeping some calculations stored long total_plus_complement = total + complement; double total_div_2 = total * 0.5; int i_mod_aa_number = 0; int i_div_aa_number = 0; long i_mod_M1 = 0; long i_div_M1 = 0; double one_l_div_total[AA_NUMBER]; for (int i=0; i<AA_NUMBER; i++) one_l_div_total[i] = (double)one_l[i] / total_l; double* second_div_total = new double[M1]; for (int i=0; i<M1; i++) second_div_total[i] = (double)second[i] / total_plus_complement; // this is the stochastic processing for comparison. Computes everything and // stores. Need to understand better. count = 0; double* t = new double[M]; for(long i=0; i<M; i++) { double p1 = second_div_total[i_div_aa_number]; double p2 = one_l_div_total[i_mod_aa_number]; double p3 = second_div_total[i_mod_M1]; double p4 = one_l_div_total[i_div_M1]; double stochastic = (p1 * p2 + p3 * p4) * total_div_2; if (i_mod_aa_number == AA_NUMBER-1) { i_mod_aa_number = 0; i_div_aa_number++; } else i_mod_aa_number++; if (i_mod_M1 == M1-1) { i_mod_M1 = 0; i_div_M1++; } else i_mod_M1++; if (stochastic > EPSILON) { t[i] = (vector[i] - stochastic) / stochastic; count++; } else t[i] = 0; } delete second_div_total; delete vector; delete second; tv = new double[count]; ti = new long[count]; int pos = 0; for (long i=0; i<M; i++) { if (t[i] != 0) { tv[pos] = t[i]; ti[pos] = i; pos++; } } delete t; fclose (bacteria_file); }
static void KIM_Malloc(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { int status; mxArray *mx_in[3], *mx_out[2]; int mxiter, msbset, msbsetsub, etachoice, mxnbcf; double eta, egamma, ealpha, mxnewtstep, relfunc, fnormtol, scsteptol; booleantype verbose, noInitSetup, noMinEps; double *constraints; N_Vector NVconstraints; int ptype; int mudq, mldq, mupper, mlower; int maxl, maxrs; double dqrely; /* * ----------------------------- * Find out the vector type and * then pass it to the vector * library. * ----------------------------- */ /* Send vec_type and mx_comm */ InitVectors(); /* * ----------------------------- * Extract stuff from arguments: * - SYS function * - problem dimension * - solver options * - user data * ----------------------------- */ /* Matlab user-provided function */ mxDestroyArray(mx_SYSfct); mx_SYSfct = mxDuplicateArray(prhs[0]); /* problem dimension */ N = (int) mxGetScalar(prhs[1]); /* Solver Options -- optional argument */ status = get_SolverOptions(prhs[2], &verbose, &mxiter, &msbset, &msbsetsub, &etachoice, &mxnbcf, &eta, &egamma, &ealpha, &mxnewtstep, &relfunc, &fnormtol, &scsteptol, &constraints, &noInitSetup, &noMinEps); /* User data -- optional argument */ mxDestroyArray(mx_data); mx_data = mxDuplicateArray(prhs[3]); /* * ----------------------------------------------------- * Set solution vector (used as a template to KINMAlloc) * ----------------------------------------------------- */ y = NewVector(N); /* * ---------------------------------------- * Create kinsol object and allocate memory * ---------------------------------------- */ kin_mem = KINCreate(); /* attach error handler function */ status = KINSetErrHandlerFn(kin_mem, mtlb_KINErrHandler, NULL); if (verbose) { status = KINSetPrintLevel(kin_mem,3); /* attach info handler function */ status = KINSetInfoHandlerFn(kin_mem, mtlb_KINInfoHandler, NULL); /* initialize the output window */ mx_in[0] = mxCreateScalarDouble(0); mx_in[1] = mxCreateScalarDouble(0); /* ignored */ mx_in[2] = mxCreateScalarDouble(0); /* ignored */ mexCallMATLAB(1,mx_out,3,mx_in,"kim_info"); fig_handle = (int)*mxGetPr(mx_out[0]); } /* Call KINMalloc */ status = KINMalloc(kin_mem, mtlb_KINSys, y); /* Redirect output */ status = KINSetErrFile(kin_mem, stdout); /* Optional inputs */ status = KINSetNumMaxIters(kin_mem,mxiter); status = KINSetNoInitSetup(kin_mem,noInitSetup); status = KINSetNoMinEps(kin_mem,noMinEps); status = KINSetMaxSetupCalls(kin_mem,msbset); status = KINSetMaxSubSetupCalls(kin_mem,msbsetsub); status = KINSetMaxBetaFails(kin_mem,mxnbcf); status = KINSetEtaForm(kin_mem,etachoice); status = KINSetEtaConstValue(kin_mem,eta); status = KINSetEtaParams(kin_mem,egamma,ealpha); status = KINSetMaxNewtonStep(kin_mem,mxnewtstep); status = KINSetRelErrFunc(kin_mem,relfunc); status = KINSetFuncNormTol(kin_mem,fnormtol); status = KINSetScaledStepTol(kin_mem,scsteptol); if (constraints != NULL) { NVconstraints = N_VCloneEmpty(y); N_VSetArrayPointer(constraints, NVconstraints); status = KINSetConstraints(kin_mem,NVconstraints); N_VDestroy(NVconstraints); } status = get_LinSolvOptions(prhs[2], &mupper, &mlower, &mudq, &mldq, &dqrely, &ptype, &maxrs, &maxl); switch (ls) { case LS_NONE: mexErrMsgTxt("KINMalloc:: no linear solver specified."); break; case LS_DENSE: status = KINDense(kin_mem, N); if (!mxIsEmpty(mx_JACfct)) status = KINDenseSetJacFn(kin_mem, mtlb_KINDenseJac, NULL); break; case LS_BAND: status = KINBand(kin_mem, N, mupper, mlower); if (!mxIsEmpty(mx_JACfct)) status = KINBandSetJacFn(kin_mem, mtlb_KINBandJac, NULL); break; case LS_SPGMR: switch(pm) { case PM_NONE: status = KINSpgmr(kin_mem, maxl); if (!mxIsEmpty(mx_PSOLfct)) { if (!mxIsEmpty(mx_PSETfct)) status = KINSpilsSetPreconditioner(kin_mem, mtlb_KINSpilsPset, mtlb_KINSpilsPsol, NULL); else status = KINSpilsSetPreconditioner(kin_mem, NULL, mtlb_KINSpilsPsol, NULL); } break; case PM_BBDPRE: if (!mxIsEmpty(mx_GCOMfct)) bbd_data = KINBBDPrecAlloc(kin_mem, N, mudq, mldq, mupper, mlower, dqrely, mtlb_KINGloc, mtlb_KINGcom); else bbd_data = KINBBDPrecAlloc(kin_mem, N, mudq, mldq, mupper, mlower, dqrely, mtlb_KINGloc, NULL); status = KINBBDSpgmr(kin_mem, maxl, bbd_data); break; } status = KINSpilsSetMaxRestarts(kin_mem, maxrs); if (!mxIsEmpty(mx_JACfct)) status = KINSpilsSetJacTimesVecFn(kin_mem, mtlb_KINSpilsJac, NULL); break; case LS_SPBCG: switch(pm) { case PM_NONE: status = KINSpbcg(kin_mem, maxl); if (!mxIsEmpty(mx_PSOLfct)) { if (!mxIsEmpty(mx_PSETfct)) status = KINSpilsSetPreconditioner(kin_mem, mtlb_KINSpilsPset, mtlb_KINSpilsPsol, NULL); else status = KINSpilsSetPreconditioner(kin_mem, NULL, mtlb_KINSpilsPsol, NULL); } break; case PM_BBDPRE: if (!mxIsEmpty(mx_GCOMfct)) bbd_data = KINBBDPrecAlloc(kin_mem, N, mudq, mldq, mupper, mlower, dqrely, mtlb_KINGloc, mtlb_KINGcom); else bbd_data = KINBBDPrecAlloc(kin_mem, N, mudq, mldq, mupper, mlower, dqrely, mtlb_KINGloc, NULL); status = KINBBDSpbcg(kin_mem, maxl, bbd_data); break; } if (!mxIsEmpty(mx_JACfct)) status = KINSpilsSetJacTimesVecFn(kin_mem, mtlb_KINSpilsJac, NULL); break; case LS_SPTFQMR: switch(pm) { case PM_NONE: status = KINSptfqmr(kin_mem, maxl); if (!mxIsEmpty(mx_PSOLfct)) { if (!mxIsEmpty(mx_PSETfct)) status = KINSpilsSetPreconditioner(kin_mem, mtlb_KINSpilsPset, mtlb_KINSpilsPsol, NULL); else status = KINSpilsSetPreconditioner(kin_mem, NULL, mtlb_KINSpilsPsol, NULL); } break; case PM_BBDPRE: if (!mxIsEmpty(mx_GCOMfct)) bbd_data = KINBBDPrecAlloc(kin_mem, N, mudq, mldq, mupper, mlower, dqrely, mtlb_KINGloc, mtlb_KINGcom); else bbd_data = KINBBDPrecAlloc(kin_mem, N, mudq, mldq, mupper, mlower, dqrely, mtlb_KINGloc, NULL); status = KINBBDSptfqmr(kin_mem, maxl, bbd_data); break; } if (!mxIsEmpty(mx_JACfct)) status = KINSpilsSetJacTimesVecFn(kin_mem, mtlb_KINSpilsJac, NULL); break; } return; }