int main(void) { MainInit(); I2C1init(); RtcInit(); LcdInit(); DataLogInit(); StringInit(); Mct485Init(); FieldInit(); Ads1115Init(); Ads1244Init(); USBInit(); RtuInit(); AdcInit(); TC74Init(); // enable multi-vector interrupts INTEnableSystemMultiVectoredInt(); MainDelay(50); DataLogDateTime(DLOG_SFC_POWERUP); // init param after interrupts are enabled ParamInit(); // wait to init desiccant until after ParamInit DesiccantInit(); string[0].mct[0].chan[4] = 0x7FFF; // // Begin Main Loop // for (;;) { if (test == 1) { test = 0; FieldNewState((FIELD_STATE_m)t1); } USBUpdate(); // called as often as possible //sysTickEvent every ms if (sysTickEvent) { sysTickEvent = 0; sysTicks++; UsbTimeoutUpdate(); LcdUpdate(); // fill time before dropping LCD_E if (sysTicks >= 1000) { sysSec++; sysTicks = 0; mPORTDToggleBits(PD_LED_HEARTBEAT); // These Updates are // called once a second //TODO if any of these are long, we could split them on separate milliseconds. DesiccantUpdate(); AdcUpdate(); TC74Update(); }// end 1 Hz else if (sysTicks == 250) { mPORTDToggleBits(PD_LED_HEARTBEAT); } else if (sysTicks == 500) { mPORTDToggleBits(PD_LED_HEARTBEAT); } else if (sysTicks == 750) { mPORTDToggleBits(PD_LED_HEARTBEAT); } // Complete LcdUpdate() by dropping LCD_E) PORTClearBits(IOPORT_G, PG_LCD_E); // These Updates called once each millisecond RtcUpdate(); I2C1update(); StringUpdate(); Mct485Update(); FieldUpdate(); RtuUpdate(); DessicantFanPWMupdate(); } // if (sysTickEvent) } // for (;;) } // main()
double OneSim(param_ param, FILE *pipe, arr_info_ arr_info_0, lattice_point_ **nghb, gsl_complex **K, gsl_complex *W, gsl_complex *CW, gsl_complex *dW, gsl_complex *complex_rot, double *argW, double *absW, double *rec, double *prec, pr_max_ *pr_max){ int i; double t = 0.; double *p_levl, *r_levl; abs_info_ abs_info; arr_info_ arr_info; pr_ *rW = NULL, *pW = NULL, *eW = NULL; /* * Zero-ing the pr_max array */ for(i=0;i<param.pr_range;i++){ pr_max[i].rec = 0.; pr_max[i].prec = 0.; } /* * Need to allocate the int_total array * of abs_info. */ abs_info.int_total = (int *)malloc(param.pr_range*sizeof(int)); arr_info.nghb_N = arr_info_0.nghb_N; arr_info.r_N = 0; arr_info.p_N = 0; arr_info.e_N = 0; /* * Clutter needs to be started first */ InitZeros(param, CW); InitAmoeba(param, &arr_info, CW, &rW, &pW, &eW); InitClutter(param, CW); /* * Reset the important arrays before * generating the real amoeba. */ free(rW); rW = NULL; free(pW); pW = NULL; free(eW); eW = NULL; arr_info.r_N = 0; arr_info.p_N = 0; arr_info.e_N = 0; InitZeros(param, W); InitAmoeba(param, &arr_info, W, &rW, &pW, &eW); /* * Reserve memory of the levl arrays */ p_levl = (double *)malloc(arr_info.p_N*sizeof(double)); r_levl = (double *)malloc(arr_info.r_N*sizeof(double)); /* * Check the exclusion zone */ ChckExcl(param, arr_info, CW, eW); /* * Time to add the clutter to the amoeba */ for(i=0;i<param.L*param.L;i++) if(gsl_complex_abs2(W[i]) < EPS) W[i] = CW[i]; AbsArg(param, &abs_info, W, absW, argW, complex_rot); while(t<param.T){ t+=param.dt; Quiver(param,pipe,absW,argW,abs_info.max,t); FieldUpdate(param, arr_info, K, W, dW, absW, complex_rot, nghb); #pragma omp parallel for for(i=0;i<param.L*param.L;i++) W[i]=gsl_complex_add(W[i],gsl_complex_mul_real(dW[i],param.dt)); AbsArg(param, &abs_info, W, absW, argW, complex_rot); FieldRedux(param, W, absW, abs_info); CalculateRecall(param, rec, arr_info, absW, argW, rW, r_levl); CalculatePrecision(param, prec, abs_info, arr_info, absW, argW, pW, p_levl); /* * Time to calculate max precision * and recall for all threshold values. * We use that to evaluate the performance * of the current choice of parameters. */ for(i=0;i<param.pr_range;i++) if(rec[i]+prec[i] > pr_max[i].rec + pr_max[i].prec){ pr_max[i].rec = rec[i]; pr_max[i].prec = prec[i]; } } free(rW); free(pW); free(eW); free(p_levl); free(r_levl); free(abs_info.int_total); return t; }