} void oracle_send(int i) { Value v; set_int(&v, i); oracle_send(&v); } List spycaValues; CA_DEFINE_FUNCTION(spy, "test_spy(any)" "'For internal testing. This function will save every inputs to a static list, " "and the contents of this list can be checked from C++ code.") { copy(INPUT(0), spycaValues.append()); } void spy_clear() { spycaValues.clear(); } List* spy_results() { return &spycaValues; } bool g_initializedHandleType; Type g_testHandleType; const int g_testHandleSlots = 100; bool g_testHandleAllocated[g_testHandleSlots];
int main(int argc, char * argv[]){ cout<<"****************************** FILES OPENING ***************************************"<<endl; string INPUT(argv[1]); string OUTPUT(argv[2]); FileSaver finalHistos; FileSaver Plots; finalHistos.setName(INPUT.c_str()); Plots.setName(OUTPUT.c_str()); bool checkfile = finalHistos.CheckFile(); cout<<"****************************** BINS ***************************************"<<endl; SetBins(); PRB.Print(); cout<<"**TOF**"<<endl; ToFDB.Print(); cout<<"**NaF**"<<endl; NaFDB.Print(); cout<<"**Agl**"<<endl; AglDB.Print(); ToFDB.UseBetaEdges(); NaFDB.UseBetaEdges(); AglDB.UseBetaEdges(); PRB.UseREdges(); cout<<endl; cout<<"**************************** PLOTTING ***************************************"<<endl; EffCorrTemplate* DistCorr_TOF = new EffCorrTemplate(finalHistos,"DistanceCorrTOF","Quality Eff. Corr",ToFDB,"ControlSample","ControlSample&DistanceCut","",""); EffCorrTemplate* DistCorr_NaF = new EffCorrTemplate(finalHistos,"DistanceCorrNaF","Quality Eff. Corr",NaFDB,"ControlSample&IsFromNaF","ControlSample&IsFromNaF&DistanceCut","","",true); EffCorrTemplate* DistCorr_Agl = new EffCorrTemplate(finalHistos,"DistanceCorrAgl","Quality Eff. Corr",AglDB,"ControlSample&IsFromAgl","ControlSample&IsFromAgl&DistanceCut","","",true); EffCorrTemplate* LikCorr_TOF = new EffCorrTemplate(finalHistos,"LikelihoodCorrTOF","Quality Eff. Corr",ToFDB,"ControlSample&DistanceCut","ControlSample&DistanceCut&LikelihoodCut","",""); EffCorrTemplate* LikCorr_NaF = new EffCorrTemplate(finalHistos,"LikelihoodCorrNaF","Quality Eff. Corr",NaFDB,"ControlSample&DistanceCut&IsFromNaF","ControlSample&IsFromNaF&DistanceCut&LikelihoodCut","","",true); EffCorrTemplate* LikCorr_Agl = new EffCorrTemplate(finalHistos,"LikelihoodCorrAgl","Quality Eff. Corr",AglDB,"ControlSample&DistanceCut&IsFromAgl","ControlSample&IsFromAgl&DistanceCut&LikelihoodCut","","",true); PlotCorrection(Plots,DistCorr_TOF,ToFDB); PlotCorrection(Plots,DistCorr_NaF,NaFDB); PlotCorrection(Plots,DistCorr_Agl,AglDB); PlotCorrection(Plots,LikCorr_TOF,ToFDB); PlotCorrection(Plots,LikCorr_NaF,NaFDB); PlotCorrection(Plots,LikCorr_Agl,AglDB); PlotFitLatitudes(finalHistos,Plots,DistCorr_TOF,ToFDB,"Glob"); PlotFitLatitudes(finalHistos,Plots,DistCorr_NaF,NaFDB,"Glob"); PlotFitLatitudes(finalHistos,Plots,DistCorr_Agl,AglDB,"Glob"); PlotFitLatitudes(finalHistos,Plots,LikCorr_TOF,ToFDB,"Glob"); PlotFitLatitudes(finalHistos,Plots,LikCorr_NaF,NaFDB,"Glob"); PlotFitLatitudes(finalHistos,Plots,LikCorr_Agl,AglDB,"Glob"); return 0; }
static cb_ret_t panel_listing_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data) { WDialog *h = DIALOG (w); switch (msg) { case MSG_KEY: if (parm == '\n') { Widget *wi; wi = dlg_find_by_id (h, panel_listing_types_id); if (widget_is_active (wi)) { WInput *in; in = INPUT (dlg_find_by_id (h, mini_user_format_id)); input_assign_text (in, status_format[RADIO (wi)->sel]); dlg_stop (h); return MSG_HANDLED; } wi = dlg_find_by_id (h, panel_user_format_id); if (widget_is_active (wi)) { h->ret_value = B_USER + 6; dlg_stop (h); return MSG_HANDLED; } wi = dlg_find_by_id (h, mini_user_format_id); if (widget_is_active (wi)) { h->ret_value = B_USER + 7; dlg_stop (h); return MSG_HANDLED; } } if (g_ascii_tolower (parm) == listing_user_hotkey) { Widget *wi; wi = dlg_find_by_id (h, panel_user_format_id); if (widget_is_active (wi)) { wi = dlg_find_by_id (h, mini_user_format_id); if (widget_is_active (wi)) { WRadio *r; r = RADIO (dlg_find_by_id (h, panel_listing_types_id)); r->pos = r->sel = panel_listing_user_idx; dlg_select_widget (WIDGET (r)); /* force redraw */ send_message (h, r, MSG_ACTION, 0, NULL); return MSG_HANDLED; } } } return MSG_NOT_HANDLED; case MSG_ACTION: if (sender != NULL && sender->id == panel_listing_types_id) { WCheck *ch; WInput *in1, *in2, *in3; in1 = INPUT (dlg_find_by_id (h, panel_user_format_id)); in2 = INPUT (dlg_find_by_id (h, panel_brief_cols_id)); ch = CHECK (dlg_find_by_id (h, mini_user_status_id)); in3 = INPUT (dlg_find_by_id (h, mini_user_format_id)); if (!(ch->state & C_BOOL)) input_assign_text (in3, status_format[RADIO (sender)->sel]); input_update (in1, FALSE); input_update (in2, FALSE); input_update (in3, FALSE); widget_disable (WIDGET (in1), RADIO (sender)->sel != panel_listing_user_idx); widget_disable (WIDGET (in2), RADIO (sender)->sel != panel_listing_brief_idx); return MSG_HANDLED; } if (sender != NULL && sender->id == mini_user_status_id) { WInput *in; in = INPUT (dlg_find_by_id (h, mini_user_format_id)); if (CHECK (sender)->state & C_BOOL) { widget_disable (WIDGET (in), FALSE); input_assign_text (in, status_format[3]); } else { WRadio *r; r = RADIO (dlg_find_by_id (h, panel_listing_types_id)); widget_disable (WIDGET (in), TRUE); input_assign_text (in, status_format[r->sel]); } /* input_update (in, FALSE); */ return MSG_HANDLED; } return MSG_NOT_HANDLED; default: return dlg_default_callback (w, sender, msg, parm, data); } }
#include "imageoutput.h" #include "videooutput.h" #include "timedoutput.h" #include "roundrobin.h" #include "randompick.h" #include "beatdetect.h" #define INPUT(__name__, __class__) inputMap.insert(make_pair(__name__, new __class__())); #define OUTPUT(__name__, __class__) outputMap.insert(make_pair(__name__, new __class__())); //-------------------------------------------------------------- void SceneFactory::createInputMap() { INPUT("timer", TimerInput) INPUT("audio", AudioInput) } //-------------------------------------------------------------- void SceneFactory::createOutputMap() { OUTPUT("background", BackgroundOutput) OUTPUT("rectangle", RectangleOutput) OUTPUT("ellipse", EllipseOutput) OUTPUT("image", ImageOutput) OUTPUT("video", VideoOutput) OUTPUT("timed", TimedOutput) OUTPUT("roundrobin", RoundRobin) OUTPUT("randompick", RandomPick) OUTPUT("beatdetect", BeatDetect)
void CloseBoundaries_cpu(Field *Vy, Field *Vz){ //<USER_DEFINED> INPUT(Vy); INPUT(Vz); OUTPUT(Vy); OUTPUT(Vz); //<\USER_DEFINED> //<EXTERNAL> real* vy = Vy->field_cpu; real* vz = Vz->field_cpu; int pitch = Pitch_cpu; int stride = Stride_cpu; int size_x = Nx; int size_y = Ny+2*NGHY; int size_z = Nz+2*NGHZ; real dx = Dx; int ncpuy = Gridd.NJ; int ncpuz = Gridd.NK; int jcpu = J; int kcpu = K; //<\EXTERNAL> //<INTERNAL> int i; int j; int k; //<\INTERNAL> //<MAIN_LOOP> i = j = k = 0; #ifdef Z for (k=0; k<size_z; k++) { #endif #ifdef Y for (j=0; j<size_y; j++) { #endif #ifdef X for (i=0; i<size_x; i++) { #endif //<#> #ifdef YMINCLOSED if ((jcpu == 0) && (j == NGHY)) vy[l] = 0.0; #endif #ifdef YMAXCLOSED if ((jcpu == ncpuy-1) && (j == size_y-NGHY-1)) vy[l] = 0.0; #endif #ifdef ZMINCLOSED if ((kcpu == 0) && (k == NGHZ)) { vz[l] = 0.0; } #endif #ifdef ZMAXCLOSED if ((kcpu == ncpuz-1) && (k == size_z-NGHZ-1)) vz[l] = 0.0; #endif //<\#> #ifdef X } #endif #ifdef Y } #endif #ifdef Z } #endif //<\MAIN_LOOP> }
real total_torque_cpu () { //<USER_DEFINED> INPUT(Density); real rplanet = sqrt(Xplanet*Xplanet+Yplanet*Yplanet+Zplanet*Zplanet); real rsmoothing = THICKNESSSMOOTHING*ASPECTRATIO*pow(rplanet/R0,FLARINGINDEX)*rplanet; //<\USER_DEFINED> //<EXTERNAL> real* dens = Density->field_cpu; int pitch = Pitch_cpu; int stride = Stride_cpu; int size_x = Nx+2*NGHX; int size_y = Ny+2*NGHY; int size_z = Nz+2*NGHZ; real rsm2 = rsmoothing*rsmoothing; //<\EXTERNAL> //<INTERNAL> int i; int j; int k; int ll; real dx; real dy; real dz=0.0; real InvDist3; real cellmass; real dist2; real distance; real fxi; real fyi; real tottorq; real Gtottorq; //<\INTERNAL> //<CONSTANT> // real Xplanet(1); // real Yplanet(1); // real Zplanet(1); // real VXplanet(1); // real VYplanet(1); // real VZplanet(1); // real MplanetVirtual(1); // real Syk(Nz+2*NGHZ); // real InvVj(Ny+2*NGHY); // real xmin(Nx+2*NGHX+1); // real ymin(Ny+2*NGHY+1); // real zmin(Nz+2*NGHZ+1); //<\CONSTANT> //<MAIN_LOOP> i = j = k = 0; tottorq = 0; #ifdef Z for (k=0; k<size_z; k++) { #endif #ifdef Y for (j=0; j<size_y; j++) { #endif #ifdef X for (i=0; i<size_x; i++ ) { #endif //<#> ll = l; cellmass = Vol(j,k)*dens[ll]; #ifdef CARTESIAN dx = xmed(i)-Xplanet; dy = ymed(j)-Yplanet; #ifdef Z dz = zmed(k)-Zplanet; #endif #endif #ifdef CYLINDRICAL dx = ymed(j)*cos(xmed(i))-Xplanet; dy = ymed(j)*sin(xmed(i))-Yplanet; #ifdef Z dz = zmed(k)-Zplanet; #endif #endif #ifdef SPHERICAL dx = ymed(j)*cos(xmed(i))*sin(zmed(k))-Xplanet; dy = ymed(j)*sin(xmed(i))*sin(zmed(k))-Yplanet; #ifdef Z dz = ymed(j)*cos(zmed(k))-Zplanet; #endif #endif dist2 = dx*dx+dy*dy+dz*dz; dist2 += rsm2; distance = sqrt(dist2); InvDist3 = 1.0/(dist2*distance); InvDist3 *= G*cellmass; fxi = dx*InvDist3; fyi = dy*InvDist3; tottorq += Xplanet*fyi-Yplanet*fxi; //<\#> #ifdef X } #endif #ifdef Y } #endif #ifdef Z } #endif //<\MAIN_LOOP> MPI_Reduce (tottorq, Gtottorq, 1,MPI_DOUBLE,MPI_SUM,0,MPI_COMM_WORLD); return Gtottorq; }
#define BUTTON 0x9 #define PHYSICAL 0x0 PROGMEM const char usbHidReportDescriptor[USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH] = { USAGE_PAGE(GENERIC_DESKTOP) USAGE(GAME_PAD) COLLECTION(APPLICATION) COLLECTION(PHYSICAL) USAGE_PAGE(BUTTON) USAGE_MINIMUM(1) USAGE_MAXIMUM(31) LOGICAL_MINIMUM(0) LOGICAL_MAXIMUM(1) REPORT_COUNT(31) REPORT_SIZE(1) INPUT(DATA_VAR_ABS) REPORT_COUNT(1) REPORT_SIZE(1) INPUT(CNST_VAR_ABS) END_COLLECTION END_COLLECTION }; typedef struct { uint8_t buttons0; uint8_t buttons1; uint8_t buttons2; uint8_t buttons3; } gamepad_report_t;
main() { double A[10][11], B[10], X[10], Y[10], X1[10], RMM[4], XK1[4][10] ; double H; int N,I,J,K,OK,FLAG,N1,KK; FILE *OUP[1]; double F(int, double *); double P(int, int, double *); void INPUT(int *, int *, int *, double *); void OUTPUT(FILE **, int *); INPUT(&OK, &N, &N1, X1); if (OK) { OUTPUT(OUP, &FLAG); /* STEP 1 */ H = 1.0/N1; RMM[0] = 0.5; RMM[1] = 0.5; RMM[2] = 1.0; RMM[3] = 0.0; for (I=1; I<=N; I++) { X[I-1] = X1[I-1]; } for (I=1; I<=N; I++) { B[I-1] = -H*F(I,X); } K = 1; /* STEP 2 */ while (OK && (K <= N1)) { /* STEPS 3 - 6 */ for (I=1; I<=N; I++) { X[I-1] = X1[I-1]; } KK = 1; while (OK && (KK <= 4)) { for (I=1; I<=N; I++) { for (J=1; J<=N; J++) A[I-1][J-1] = P(I, J, X); A[I-1][N] = B[I-1]; } LINSYS(N, &OK, A, Y); if (OK) { for (I=1; I<=N; I++) { XK1[KK-1][I-1] = Y[I-1]; X[I-1] = X1[I-1] + RMM[KK-1]*XK1[KK-1][I-1]; } KK=KK+1; } } /* STEP 7 */ if (OK) { for (I=1; I<=N; I++) X1[I-1]=X1[I-1]+(XK1[0][I-1]+2*XK1[1][I-1]+2*XK1[2][I-1]+XK1[3][I-1])/6; /* STEP 8 */ fprintf(*OUP," %2d", K); for (I=1; I<=N; I++) fprintf(*OUP," %11.8f",X1[I-1]); fprintf(*OUP," \n"); } K=K+1; } fclose(*OUP); } return 0; }
uint8_t * USBMouseKeyboard::reportDesc() { if (mouse_type == REL_MOUSE) { static uint8_t reportDescriptor[] = { // Keyboard USAGE_PAGE(1), 0x01, USAGE(1), 0x06, COLLECTION(1), 0x01, REPORT_ID(1), REPORT_ID_KEYBOARD, USAGE_PAGE(1), 0x07, USAGE_MINIMUM(1), 0xE0, USAGE_MAXIMUM(1), 0xE7, LOGICAL_MINIMUM(1), 0x00, LOGICAL_MAXIMUM(1), 0x01, REPORT_SIZE(1), 0x01, REPORT_COUNT(1), 0x08, INPUT(1), 0x02, REPORT_COUNT(1), 0x01, REPORT_SIZE(1), 0x08, INPUT(1), 0x01, REPORT_COUNT(1), 0x05, REPORT_SIZE(1), 0x01, USAGE_PAGE(1), 0x08, USAGE_MINIMUM(1), 0x01, USAGE_MAXIMUM(1), 0x05, OUTPUT(1), 0x02, REPORT_COUNT(1), 0x01, REPORT_SIZE(1), 0x03, OUTPUT(1), 0x01, REPORT_COUNT(1), 0x06, REPORT_SIZE(1), 0x08, LOGICAL_MINIMUM(1), 0x00, LOGICAL_MAXIMUM(2), 0xff, 0x00, USAGE_PAGE(1), 0x07, USAGE_MINIMUM(1), 0x00, USAGE_MAXIMUM(2), 0xff, 0x00, INPUT(1), 0x00, END_COLLECTION(0), // Mouse USAGE_PAGE(1), 0x01, // Generic Desktop USAGE(1), 0x02, // Mouse COLLECTION(1), 0x01, // Application USAGE(1), 0x01, // Pointer COLLECTION(1), 0x00, // Physical REPORT_ID(1), REPORT_ID_MOUSE, REPORT_COUNT(1), 0x03, REPORT_SIZE(1), 0x01, USAGE_PAGE(1), 0x09, // Buttons USAGE_MINIMUM(1), 0x1, USAGE_MAXIMUM(1), 0x3, LOGICAL_MINIMUM(1), 0x00, LOGICAL_MAXIMUM(1), 0x01, INPUT(1), 0x02, REPORT_COUNT(1), 0x01, REPORT_SIZE(1), 0x05, INPUT(1), 0x01, REPORT_COUNT(1), 0x03, REPORT_SIZE(1), 0x08, USAGE_PAGE(1), 0x01, USAGE(1), 0x30, // X USAGE(1), 0x31, // Y USAGE(1), 0x38, // scroll LOGICAL_MINIMUM(1), 0x81, LOGICAL_MAXIMUM(1), 0x7f, INPUT(1), 0x06, END_COLLECTION(0), END_COLLECTION(0), // Media Control USAGE_PAGE(1), 0x0C, USAGE(1), 0x01, COLLECTION(1), 0x01, REPORT_ID(1), REPORT_ID_VOLUME, USAGE_PAGE(1), 0x0C, LOGICAL_MINIMUM(1), 0x00, LOGICAL_MAXIMUM(1), 0x01, REPORT_SIZE(1), 0x01, REPORT_COUNT(1), 0x07, USAGE(1), 0xB5, // Next Track USAGE(1), 0xB6, // Previous Track USAGE(1), 0xB7, // Stop USAGE(1), 0xCD, // Play / Pause USAGE(1), 0xE2, // Mute USAGE(1), 0xE9, // Volume Up USAGE(1), 0xEA, // Volume Down INPUT(1), 0x02, // Input (Data, Variable, Absolute) REPORT_COUNT(1), 0x01, INPUT(1), 0x01, END_COLLECTION(0), }; reportLength = sizeof(reportDescriptor); return reportDescriptor; } else if (mouse_type == ABS_MOUSE) { static uint8_t reportDescriptor[] = { // Keyboard USAGE_PAGE(1), 0x01, USAGE(1), 0x06, COLLECTION(1), 0x01, REPORT_ID(1), REPORT_ID_KEYBOARD, USAGE_PAGE(1), 0x07, USAGE_MINIMUM(1), 0xE0, USAGE_MAXIMUM(1), 0xE7, LOGICAL_MINIMUM(1), 0x00, LOGICAL_MAXIMUM(1), 0x01, REPORT_SIZE(1), 0x01, REPORT_COUNT(1), 0x08, INPUT(1), 0x02, REPORT_COUNT(1), 0x01, REPORT_SIZE(1), 0x08, INPUT(1), 0x01, REPORT_COUNT(1), 0x05, REPORT_SIZE(1), 0x01, USAGE_PAGE(1), 0x08, USAGE_MINIMUM(1), 0x01, USAGE_MAXIMUM(1), 0x05, OUTPUT(1), 0x02, REPORT_COUNT(1), 0x01, REPORT_SIZE(1), 0x03, OUTPUT(1), 0x01, REPORT_COUNT(1), 0x06, REPORT_SIZE(1), 0x08, LOGICAL_MINIMUM(1), 0x00, LOGICAL_MAXIMUM(2), 0xff, 0x00, USAGE_PAGE(1), 0x07, USAGE_MINIMUM(1), 0x00, USAGE_MAXIMUM(2), 0xff, 0x00, INPUT(1), 0x00, END_COLLECTION(0), // Mouse USAGE_PAGE(1), 0x01, // Generic Desktop USAGE(1), 0x02, // Mouse COLLECTION(1), 0x01, // Application USAGE(1), 0x01, // Pointer COLLECTION(1), 0x00, // Physical REPORT_ID(1), REPORT_ID_MOUSE, USAGE_PAGE(1), 0x01, // Generic Desktop USAGE(1), 0x30, // X USAGE(1), 0x31, // Y LOGICAL_MINIMUM(1), 0x00, // 0 LOGICAL_MAXIMUM(2), 0xff, 0x7f, // 32767 REPORT_SIZE(1), 0x10, REPORT_COUNT(1), 0x02, INPUT(1), 0x02, // Data, Variable, Absolute USAGE_PAGE(1), 0x01, // Generic Desktop USAGE(1), 0x38, // scroll LOGICAL_MINIMUM(1), 0x81, // -127 LOGICAL_MAXIMUM(1), 0x7f, // 127 REPORT_SIZE(1), 0x08, REPORT_COUNT(1), 0x01, INPUT(1), 0x06, // Data, Variable, Relative USAGE_PAGE(1), 0x09, // Buttons USAGE_MINIMUM(1), 0x01, USAGE_MAXIMUM(1), 0x03, LOGICAL_MINIMUM(1), 0x00, // 0 LOGICAL_MAXIMUM(1), 0x01, // 1 REPORT_COUNT(1), 0x03, REPORT_SIZE(1), 0x01, INPUT(1), 0x02, // Data, Variable, Absolute REPORT_COUNT(1), 0x01, REPORT_SIZE(1), 0x05, INPUT(1), 0x01, // Constant END_COLLECTION(0), END_COLLECTION(0), // Media Control USAGE_PAGE(1), 0x0C, USAGE(1), 0x01, COLLECTION(1), 0x01, REPORT_ID(1), REPORT_ID_VOLUME, USAGE_PAGE(1), 0x0C, LOGICAL_MINIMUM(1), 0x00, LOGICAL_MAXIMUM(1), 0x01, REPORT_SIZE(1), 0x01, REPORT_COUNT(1), 0x07, USAGE(1), 0xB5, // Next Track USAGE(1), 0xB6, // Previous Track USAGE(1), 0xB7, // Stop USAGE(1), 0xCD, // Play / Pause USAGE(1), 0xE2, // Mute USAGE(1), 0xE9, // Volume Up USAGE(1), 0xEA, // Volume Down INPUT(1), 0x02, // Input (Data, Variable, Absolute) REPORT_COUNT(1), 0x01, INPUT(1), 0x01, END_COLLECTION(0), }; reportLength = sizeof(reportDescriptor); return reportDescriptor; } return NULL; }
void SubStep3_cpu (real dt) { //<USER_DEFINED> INPUT(Energy); #ifdef X INPUT(Vx_temp); #endif #ifdef Y INPUT(Vy_temp); #endif #ifdef Z INPUT(Vz_temp); #endif OUTPUT(Energy); //<\USER_DEFINED> //<EXTERNAL> real* e = Energy->field_cpu; #ifdef X real* vx = Vx_temp->field_cpu; #endif #ifdef Y real* vy = Vy_temp->field_cpu; #endif #ifdef Z real* vz = Vz_temp->field_cpu; #endif int pitch = Pitch_cpu; int stride = Stride_cpu; int size_x = XIP; int size_y = Ny+2*NGHY-1; int size_z = Nz+2*NGHZ-1; //<\EXTERNAL> //<INTERNAL> int i; //Variables reserved int j; //for the topology int k; //of the kernels int ll; #ifdef X int llxp; #endif #ifdef Y int llyp; #endif #ifdef Z int llzp; #endif real term; real div_v; //<\INTERNAL> //<CONSTANT> // real GAMMA(1); // real Sxj(Ny+2*NGHY); // real Syj(Ny+2*NGHY); // real Szj(Ny+2*NGHY); // real Sxk(Nz+2*NGHZ); // real Syk(Nz+2*NGHZ); // real Szk(Nz+2*NGHZ); // real InvVj(Ny+2*NGHY); //<\CONSTANT> //<MAIN_LOOP> i = j = k = 0; #ifdef Z for(k=0; k<size_z; k++) { #endif #ifdef Y for(j=0; j<size_y; j++) { #endif #ifdef X for(i=0; i<size_x; i++) { #endif //<#> ll = l; #ifdef X llxp = lxp; #endif #ifdef Y llyp = lyp; #endif #ifdef Z llzp = lzp; #endif div_v = 0.0; #ifdef X div_v += (vx[llxp]-vx[ll])*SurfX(j,k); #endif #ifdef Y div_v += (vy[llyp]*SurfY(j+1,k)-vy[ll]*SurfY(j,k)); #endif #ifdef Z div_v += (vz[llzp]*SurfZ(j,k+1)-vz[ll]*SurfZ(j,k)); #endif term = 0.5 * dt * (GAMMA - 1.) * div_v * InvVol(j,k); e[ll] *= (1.0-term)/(1.0+term); //<\#> #ifdef X } #endif #ifdef Y } #endif #ifdef Z } #endif //<\MAIN_LOOP> }
int main() { int cTotal = 0; int cState = STATE_READ; char toggleOut = FALSE; Signal motor1; Signal motor2; Signal estop; Signal rcMode; init_coridium(); setbaud(0, 17); statusMessage[0] = '#'; statusMessage[1] = '%'; statusMessage[2] = 0x82; INPUT(RC1); motor1.pin = RC1; INPUT(RC2); motor2.pin = RC2; INPUT(RC3); estop.pin = RC3; INPUT(RC4); rcMode.pin = RC4; OUTPUT(TX); OUTPUT(ESTOP); LOW(ESTOP); OUTPUT(RCMode); OUTPUT(FreqPin); OUTPUT(LIGHT); motor1.state = STATE_WAIT; motor1.duty = 0; motor1.valid = 0; motor2.state = STATE_WAIT; motor2.duty = 0; motor2.valid = 0; estop.state = STATE_WAIT; estop.duty = 0; estop.valid = 0; rcMode.state = STATE_WAIT; rcMode.duty = 0; rcMode.valid = 0; SLEEP(2); while (TRUE) { switch (cState) { case STATE_READ: if (toggleOut) { toggleOut = FALSE; HIGH(FreqPin); } else { toggleOut = TRUE; LOW(FreqPin); } cTotal += getDuty(&motor1); cTotal += getDuty(&motor2); cTotal += getDuty(&estop); cTotal += getDuty(&rcMode); if (cTotal > 8) { cState = STATE_SERIAL; cTotal = 0; } break; case STATE_SERIAL: if (estop.lastVal > 0) { sendESTOP(0); gESTOP = FALSE; if (rcMode.lastVal > 0) { HIGH(LIGHT); HIGH(RCMode); // 11 == Manual (teleop) Mode statusMessage[3] = 0x00; statusMessage[4] = 0xFF; statusMessage[5] = 0xFF; statusMessage[6] = 0xFF; calcSum(); //statusMessage[7] = 0x84; //SEROUT(TXD0,9600, 1, 3, statusMessage); TXD0(statusMessage[0]); TXD0(statusMessage[1]); TXD0(statusMessage[2]); TXD0(statusMessage[3]); TXD0(statusMessage[4]); TXD0(statusMessage[5]); TXD0(statusMessage[6]); TXD0(statusMessage[7]); } else { if (flashcount > 0) { HIGH(LIGHT); } else { LOW(LIGHT); } if (flashcount > LIGHTDUTY) { flashcount = -LIGHTDUTY; } LOW(RCMode); // 00 == Autonomous Mode statusMessage[3] = 0x00; statusMessage[4] = 0x00; statusMessage[5] = 0x00; statusMessage[6] = 0x00; calcSum(); //statusMessage[7] = 0x84; //SEROUT(TXD0,9600, 1, 3, statusMessage); TXD0(statusMessage[0]); TXD0(statusMessage[1]); TXD0(statusMessage[2]); TXD0(statusMessage[3]); TXD0(statusMessage[4]); TXD0(statusMessage[5]); TXD0(statusMessage[6]); TXD0(statusMessage[7]); } } else { HIGH(LIGHT); HIGH(RCMode); sendESTOP(1); gESTOP = TRUE; // 11 == Manual (teleop) Mode statusMessage[3] = 0x00; statusMessage[4] = 0xFF; statusMessage[5] = 0xFF; statusMessage[6] = 0xFF; calcSum(); //statusMessage[7] = 0x84; //SEROUT(TXD0,9600, 1, 3, statusMessage); TXD0(statusMessage[0]); TXD0(statusMessage[1]); TXD0(statusMessage[2]); TXD0(statusMessage[3]); TXD0(statusMessage[4]); TXD0(statusMessage[5]); TXD0(statusMessage[6]); TXD0(statusMessage[7]); } #ifdef DEBUG putchar( binToHexstr((char)((motor1.lastVal >> 4) & 0x0F)) ); putchar( binToHexstr((char)(motor1.lastVal & 0x0F)) ); putchar(' '); putchar( binToHexstr((char)((motor2.lastVal >> 4) & 0x0F)) ); putchar( binToHexstr((char)(motor2.lastVal & 0x0F)) ); putchar('\n'); //printf("%d\n", estop.lastVal); #endif // motor1 == forward value // motor2 == left/right value int left_motor = motor1.lastVal/2 - motor2.lastVal/2; int right_motor = motor1.lastVal/2 + motor2.lastVal/2; sendSerial(right_motor, 1); sendSerial(left_motor, 0); cState = STATE_READ; break; } flashcount++; } return 0; }
void VanLeerX_PPA_steep_cpu(Field *Q){ //<USER_DEFINED> INPUT(Q); INPUT(Slope); INPUT(LapPPA); OUTPUT(QL); OUTPUT(QR); //<\USER_DEFINED> //<EXTERNAL> real* slope = Slope->field_cpu; real* lapla = LapPPA->field_cpu; real* q = Q->field_cpu; real* qL = QL->field_cpu; real* qR = QR->field_cpu; int pitch = Pitch_cpu; int stride = Stride_cpu; int size_x = XIP; int size_y = Ny+2*NGHY; int size_z = Nz+2*NGHZ; //<\EXTERNAL> //<INTERNAL> int i; int j; int k; int ll; int llxp; int llxm; real eta; real etatilde; real aL; real aR; //<\INTERNAL> //<MAIN_LOOP> i = j = k = 0; #ifdef Z for (k=0; k<size_z; k++) { #endif #ifdef Y for (j=0; j<size_y; j++) { #endif for (i=XIM; i<size_x; i++) {// Now we compute q_j+1/2 //<#> ll = l; llxp = lxp; llxm = lxm; if (lapla[llxp]*lapla[llxm] < 0.0) { if ((fabs(q[llxp]-q[llxm]) > EPS*fabs(q[llxp])) && \ (fabs(q[llxp]-q[llxm]) > EPS*fabs(q[llxm]))) { /* Do we have a discontinuity ? */ etatilde = - (lapla[llxp]-lapla[llxm])/(q[llxp]-q[llxm]); eta = ETA1*(etatilde-ETA2); if (eta > 1.0) eta=1.0; if (eta < 0.0) eta=0.0; aL = q[llxm]+.5*slope[llxm]; aR = q[llxp]-.5*slope[llxp]; qL[ll] = qL[ll]*(1.0-eta) + aL*eta; qR[ll] = qR[ll]*(1.0-eta) + aR*eta; } } //<\#> } #ifdef Y } #endif #ifdef Z } #endif //<\MAIN_LOOP> }
void shift_register_init() { OUTPUT(SHIFT_PL_PIN); OUTPUT(SHIFT_CP_PIN); INPUT(SHIFT_Q7_PIN); }
/*f c_memory::c_memory */ c_memory::c_memory( class c_engine *eng, void *eng_handle, int size, int width, int clocks, int byte_enables, int shared_ports, int read_ports, int write_ports ) { int i; engine = eng; engine_handle = eng_handle; /*b Determine configuration */ debug = 0; for (i=0; i<32; i++) { if (size<=(1<<i)) break; } memory_size = size; memory_log_size = i; memory_width = width; memory_byte_width = (width+7)/8; memory_int_width = (width+sizeof(int)*8-1)/(sizeof(int)*8); memory_has_byte_enables = byte_enables; this->shared_ports = shared_ports; this->read_ports = read_ports; this->write_ports = write_ports; this->filename = engine->get_option_string( engine_handle, "filename", "" ); debug = engine->get_option_int( engine_handle, "debug", 0 ); if (debug) { fprintf(stderr,"c_memory::c_memory debug instantiate width %d bits (%d bytes) size %d filename %s\n", memory_width, memory_byte_width, memory_size, filename ); } /*b Instantiate module */ engine->register_delete_function( engine_handle, (void *)this, memory_delete_fn ); engine->register_reset_function( engine_handle, (void *)this, memory_reset_fn ); if (clocks<2) { engine->register_clock_fns( engine_handle, (void *)this, "sram_clock", memory_preclock_posedge_int_clock_fn, memory_clock_posedge_int_clock_fn ); INPUT( sram_read, 1, sram_clock ); INPUT( sram_write, 1, sram_clock ); if (memory_has_byte_enables) { INPUT( sram_byte_enables, memory_byte_width, sram_clock ); } if (shared_ports) { INPUT( sram_address, memory_log_size, sram_clock ); } else { INPUT( sram_write_address, memory_log_size, sram_clock ); INPUT( sram_read_address, memory_log_size, sram_clock ); } INPUT( sram_write_data, memory_width, sram_clock ); STATE_OUTPUT( sram_read_data, 0, memory_width, sram_clock ); } else { engine->register_clock_fns( engine_handle, (void *)this, "sram_read_clock", memory_preclock_posedge_int_read_clock_fn, memory_clock_posedge_int_read_clock_fn ); engine->register_clock_fns( engine_handle, (void *)this, "sram_write_clock", memory_preclock_posedge_int_write_clock_fn, memory_clock_posedge_int_write_clock_fn ); INPUT( sram_read, 1, sram_read_clock ); INPUT( sram_read_address, memory_log_size, sram_read_clock ); STATE_OUTPUT( sram_read_data, 0, memory_width, sram_read_clock ); INPUT( sram_write, 1, sram_write_clock ); if (memory_has_byte_enables) { INPUT( sram_byte_enables, memory_byte_width, sram_write_clock ); } INPUT( sram_write_address, memory_log_size, sram_write_clock ); INPUT( sram_write_data, memory_width, sram_write_clock ); } /*b Register state then reset */ //engine->register_state_desc( engine_handle, 1, state_desc_memory_posedge_int_clock, &posedge_int_clock_state, NULL ); reset( 0 ); /*b Done */ }
//----------------------------------------------------------------------------- // FUNCTION: D4DTCHHW_PinCtl_S08_adc // SCOPE: Low Level Driver API function // DESCRIPTION: allows control GPIO pins for touch screen purposes // // PARAMETERS: D4DTCHHW_PINS pinId - Pin identification // D4DHW_PIN_STATE setState - Pin action // RETURNS: for Get action retuns the pin value //----------------------------------------------------------------------------- static unsigned char D4DTCHHW_PinCtl_S08_adc(D4DTCHHW_PINS pinId, D4DHW_PIN_STATE setState) { switch(pinId) { case D4DTCH_X_PLUS_PIN: switch(setState) { case D4DHW_PIN_OUT: OUTPUT(D4DTCH_X_PLUS); break; case D4DHW_PIN_IN: INPUT(D4DTCH_X_PLUS); break; case D4DHW_PIN_SET_1: D4DTCH_SET_X_PLUS break; case D4DHW_PIN_SET_0: D4DTCH_RESET_X_PLUS; break; case D4DHW_PIN_ADC_ON: D4DTCH_X_PLUS_ADCH_PIN_ENABLE; break; case D4DHW_PIN_ADC_OFF: D4DTCH_X_PLUS_ADCH_PIN_DISABLE; break; } break; case D4DTCH_X_MINUS_PIN: switch(setState) { case D4DHW_PIN_OUT: OUTPUT(D4DTCH_X_MINUS); break; case D4DHW_PIN_IN: INPUT(D4DTCH_X_MINUS); break; case D4DHW_PIN_SET_1: D4DTCH_SET_X_MINUS break; case D4DHW_PIN_SET_0: D4DTCH_RESET_X_MINUS; break; } break; case D4DTCH_Y_PLUS_PIN: switch(setState) { case D4DHW_PIN_OUT: OUTPUT(D4DTCH_Y_PLUS); break; case D4DHW_PIN_IN: INPUT(D4DTCH_Y_PLUS); break; case D4DHW_PIN_SET_1: D4DTCH_SET_Y_PLUS break; case D4DHW_PIN_SET_0: D4DTCH_RESET_Y_PLUS; break; case D4DHW_PIN_ADC_ON: D4DTCH_Y_PLUS_ADCH_PIN_ENABLE; break; case D4DHW_PIN_ADC_OFF: D4DTCH_Y_PLUS_ADCH_PIN_DISABLE; break; } break; case D4DTCH_Y_MINUS_PIN: switch(setState) { case D4DHW_PIN_OUT: OUTPUT(D4DTCH_Y_MINUS); break; case D4DHW_PIN_IN: INPUT(D4DTCH_Y_MINUS); break; case D4DHW_PIN_SET_1: D4DTCH_SET_Y_MINUS break; case D4DHW_PIN_SET_0: D4DTCH_RESET_Y_MINUS; break; } break; } return 0; }
/* MAIN PROGRAM */ int main(int argc, char** argv) { int next_event; char keytoclose = 'p'; if(!startup_check(0)) return -1; /* Initialize csiglib and simulation */ while (initialize(argc, (const char * *)argv)) {; /* Schedule beginning of simulation */ event_time = current_time; event_type = RUN_event; schedule_event(); /* Schedule end of simulation */ event_time = stop_time; event_type = run_end_event; event_priority = 9999; schedule_event(); /* EVENT EXECUTION CONTROL LOOP */ while (!run_error && !done) { /* Pull next event from event list */ next_event = c_timing(); /* increment the event count for this event */ event_count[next_event]++; /* Call appropriate event routine */ switch ( next_event ) { case run_end_event: run_end(); break; case RUN_event: RUN(); event_trace("RUN",event_count[next_event]); break; case CUSTM_event: CUSTM(); event_trace("CUSTM",event_count[next_event]); break; case RENT_event: RENT(); event_trace("RENT",event_count[next_event]); break; case RETURN_event: RETURN(); event_trace("RETURN",event_count[next_event]); break; case FAIL_event: FAIL(); event_trace("FAIL",event_count[next_event]); break; case FIX_event: FIX(); event_trace("FIX",event_count[next_event]); break; case INPUT_event: INPUT(); event_trace("INPUT",event_count[next_event]); break; case WALKIN_event: WALKIN(); event_trace("WALKIN",event_count[next_event]); break; case RETIRE_event: RETIRE(); event_trace("RETIRE",event_count[next_event]); break; case LVE_event: LVE(); event_trace("LVE",event_count[next_event]); break; case RESERV_event: RESERV(); event_trace("RESERV",event_count[next_event]); break; case RSVP_event: RSVP(); event_trace("RSVP",event_count[next_event]); break; case costs_event: costs(); event_trace("costs",event_count[next_event]); break; } } } // experiments terminated printf("Experiments ended! If runs end early: \n\r1. check fields in *.exp file. \n\r2. check if output file was already open. \n\r"); return 0; }
void init_dht11() { INPUT(DHT_PIN); // use internal 20k pullup (lazy!) HIGH(DHT_PIN); }
main() { double A[21][22], CO[21][4][4], DCO[21][4][3], X[21], C[21], AF[20], BF[20]; double CF[20], DF[20], AP[20], BP[20], CP[20], DP[20], AQ[20], BQ[20]; double CQ[20], DQ[20]; double T,H, XU, XL, A1, B1, C1, D1, A2, B2, C2, D2; double A3, B3, C3, D3, A4, B4, C4, D4, CC, S, SS; double FPL,FPR,PPL,PPR,QPL,QPR; int N, N1, N2, N3, I, J, K, II, JJ, J0, J1, J2,KK, K2, K3, JJ1, JJ2, OK; FILE *OUP[1]; void INPUT(int *, int *, double *, double *, double *, double *, double *, double *); void OUTPUT(FILE **); double F(double); double P(double); double Q(double); int MINO(int, int); int MAXO(int, int); int INTE(int, int); void DPHICO(int, int, double *, double *, double *, double, int); void PHICO(int, int, double *, double *, double *, double *, double, int); double XINT(double, double, double, double, double, double, double, double, double, double, double, double, double, double); void COEF(int, int, int, double, double, double *, double *, double *, double *, double *, double); INPUT(&OK, &N, &FPL, &FPR, &PPL, &PPR, &QPL, &QPR); if (OK) { OUTPUT(OUP); /* STEP 1 */ H = 1.0/(N+1.0); N1 = N+1; N2 = N+2; N3 = N+3; /* Initialize matrix A at zero, note that A[I, N+3] = B[I] */ for (I=1; I<=N2; I++) for (J=1; J<=N3; J++) A[I-1][J-1] = 0.0; /* STEP 2 */ /* X[1]=0,...,X[I] = (I-1)*H,...,X[N+1] = 1 - H, X[N+2] = 1 */ for (I=1; I<=N2; I++) X[I-1] = (I-1.0)*H; /* STEPS 3 and 4 are implemented in what follows. Initialize coefficients CO[I,J,K], DCO[I,J,K] */ for (I=1; I<=N2; I++) for (J=1; J<=4; J++) { for (K=1; K<=4; K++) { CO[I-1][J-1][K-1] = 0.0; if (K != 4) DCO[I-1][J-1][K-1] = 0.0; } /* JJ corresponds the coefficients of phi and phi' to the proper interval involving J */ JJ = I+J-3; PHICO(I, JJ, &CO[I-1][J-1][0], &CO[I-1][J-1][1], &CO[I-1][J-1][2], &CO[I-1][J-1][3], H, N); DPHICO(I, JJ, &DCO[I-1][J-1][0], &DCO[I-1][J-1][1], &DCO[I-1][J-1][2], H, N); } /* Output the basis functions. */ fprintf(*OUP, "Basis Function: A + B*X + C*X**2 + D*X**3\n\n"); fprintf(*OUP, " A B C D\n\n"); for (I=1; I<=N2; I++) { fprintf(*OUP, "phi( %d )\n\n", I); for (J=1; J<=4; J++) if ((I != 1) || ((J != 1) && (J != 2))) if ((I != 2) || (J != 2)) if ((I != N1) || (J != 4)) if ((I != N2) || ((J != 3) && (J != 4))) { JJ1 = I+J-3; JJ2 = I+J-2; fprintf(*OUP, "On (X( %d ), X( %d ) ", JJ1, JJ2); for (K=1; K<=4; K++) fprintf(*OUP, " %12.8f ", CO[I-1][J-1][K-1]); fprintf(*OUP, "\n\n"); } } /* Obtain coefficients for F, P, Q - NOTE _ the fourth and fifth arguements in COEF are the derivatives of F, P, or Q evaluated at 0 and 1 respectively. */ COEF(1, N2, N1, FPL, FPR, AF, BF, CF, DF, X, H); COEF(2, N2, N1, PPL, PPR, AP, BP, CP, DP, X, H); COEF(3, N2, N1, QPL, QPR, AQ, BQ, CQ, DQ, X, H); /* STEPS 5 - 9 are implemented in what follows */ for (I=1; I<=N2; I++) { /* indices for limits of integration for A[I,I] and B[I] */ J1 = MINO(I+2,N+2); J0 = MAXO(I-2,1); J2 = J1 - 1; /* integrate over each subinterval where phi(I) nonzero */ for (JJ=J0; JJ<=J2; JJ++) { /* limits of integration for each call */ XU = X[JJ]; XL = X[JJ-1]; /* coefficients of bases */ K = INTE(I,JJ); A1 = DCO[I-1][K-1][0]; B1 = DCO[I-1][K-1][1]; C1 = DCO[I-1][K-1][2]; D1 = 0.0; A2 = CO[I-1][K-1][0]; B2 = CO[I-1][K-1][1]; C2 = CO[I-1][K-1][2]; D2 = CO[I-1][K-1][3]; /* call subprogram for integrations */ A[I-1][I-1] = A[I-1][I-1]+ XINT(XU,XL,AP[JJ-1],BP[JJ-1],CP[JJ-1],DP[JJ-1], A1,B1,C1,D1,A1,B1,C1,D1)+ XINT(XU,XL,AQ[JJ-1],BQ[JJ-1],CQ[JJ-1],DQ[JJ-1], A2,B2,C2,D2,A2,B2,C2,D2); A[I-1][N+2] = A[I-1][N+2] + XINT(XU,XL,AF[JJ-1],BF[JJ-1],CF[JJ-1],DF[JJ-1], A2,B2,C2,D2,1.0,0.0,0.0,0.0); } /* compute A[I,J] for J = I+1, ..., Min(I+3,N+2) */ K3 = I+1; if (K3 <= N2) { K2 = MINO(I+3,N+2); for (J=K3; J<=K2; J++) { J0 = MAXO(J-2,1); for (JJ=J0; JJ<=J2; JJ++) { XU = X[JJ]; XL = X[JJ-1]; K = INTE(I,JJ); A1 = DCO[I-1][K-1][0]; B1 = DCO[I-1][K-1][1]; C1 = DCO[I-1][K-1][2]; D1 = 0.0; A2 = CO[I-1][K-1][0]; B2 = CO[I-1][K-1][1]; C2 = CO[I-1][K-1][2]; D2 = CO[I-1][K-1][3]; K = INTE(J,JJ); A3 = DCO[J-1][K-1][0]; B3 = DCO[J-1][K-1][1]; C3 = DCO[J-1][K-1][2]; D3 = 0.0; A4 = CO[J-1][K-1][0]; B4 = CO[J-1][K-1][1]; C4 = CO[J-1][K-1][2]; D4 = CO[J-1][K-1][3]; A[I-1][J-1] = A[I-1][J-1] + XINT(XU,XL,AP[JJ-1],BP[JJ-1], CP[JJ-1],DP[JJ-1],A1,B1,C1,D1, A3,B3,C3,D3)+ XINT(XU,XL,AQ[JJ-1],BQ[JJ-1], CQ[JJ-1],DQ[JJ-1],A2,B2,C2,D2, A4,B4,C4,D4); } A[J-1][I-1] = A[I-1][J-1]; } } } /* STEP 10 */ for (I=1; I<=N1; I++) { for (J=I+1; J<=N2; J++) { CC = A[J-1][I-1]/A[I-1][I-1]; for (K=I+1; K<=N3; K++) A[J-1][K-1] = A[J-1][K-1]-CC*A[I-1][K-1]; A[J-1][I-1] = 0.0; } } C[N2-1] = A[N2-1][N3-1]/A[N2-1][N2-1]; for (I=1; I<=N1; I++) { J = N1-I+1; C[J-1] = A[J-1][N3-1]; for (KK=J+1; KK<=N2; KK++) C[J-1] = C[J-1]-A[J-1][KK-1]*C[KK-1]; C[J-1] = C[J-1]/A[J-1][J-1]; } /* STEP 11 */ /* output coefficients */ fprintf(*OUP, "\nCoefficients: c(1), c(2), ... , c(n)\n\n"); for (I=1; I<=N2; I++) fprintf(*OUP, " %12.6e \n", C[I-1]); fprintf(*OUP, "\n"); /* compute and output value of the approximation at the nodes */ fprintf(*OUP, "The approximation evaluated at the nodes:\n\n"); fprintf(*OUP, " Node Value\n\n"); for (I=1; I<=N2; I++) { S = 0.0; for (J=1; J<=N2; J++) { J0 = MAXO(J-2,1); J1 = MINO(J+2,N+2); SS = 0.0; if ((I < J0) || (I >= J1)) S = S + C[J-1]*SS; else { K = INTE(J,I); SS = ((CO[J-1][K-1][3]*X[I-1]+CO[J-1][K-1][2])*X[I-1]+ CO[J-1][K-1][1])*X[I-1]+CO[J-1][K-1][0]; S = S + C[J-1]*SS; } } fprintf(*OUP, "%12.8f %12.8f\n", X[I-1], S); } /* STEP 12 */ fclose(*OUP); } return 0; }
uint8_t * USBMouse::reportDesc() { if (mouse_type == REL_MOUSE) { static uint8_t reportDescriptor[] = { USAGE_PAGE(1), 0x01, // Genric Desktop USAGE(1), 0x02, // Mouse COLLECTION(1), 0x01, // Application USAGE(1), 0x01, // Pointer COLLECTION(1), 0x00, // Physical REPORT_COUNT(1), 0x03, REPORT_SIZE(1), 0x01, USAGE_PAGE(1), 0x09, // Buttons USAGE_MINIMUM(1), 0x1, USAGE_MAXIMUM(1), 0x3, LOGICAL_MINIMUM(1), 0x00, LOGICAL_MAXIMUM(1), 0x01, INPUT(1), 0x02, REPORT_COUNT(1), 0x01, REPORT_SIZE(1), 0x05, INPUT(1), 0x01, REPORT_COUNT(1), 0x03, REPORT_SIZE(1), 0x08, USAGE_PAGE(1), 0x01, USAGE(1), 0x30, // X USAGE(1), 0x31, // Y USAGE(1), 0x38, // scroll LOGICAL_MINIMUM(1), 0x81, LOGICAL_MAXIMUM(1), 0x7f, INPUT(1), 0x06, // Relative data END_COLLECTION(0), END_COLLECTION(0), }; reportLength = sizeof(reportDescriptor); return reportDescriptor; } else if (mouse_type == ABS_MOUSE) { static uint8_t reportDescriptor[] = { USAGE_PAGE(1), 0x01, // Generic Desktop USAGE(1), 0x02, // Mouse COLLECTION(1), 0x01, // Application USAGE(1), 0x01, // Pointer COLLECTION(1), 0x00, // Physical USAGE_PAGE(1), 0x01, // Generic Desktop USAGE(1), 0x30, // X USAGE(1), 0x31, // Y LOGICAL_MINIMUM(1), 0x00, // 0 LOGICAL_MAXIMUM(2), 0xff, 0x7f, // 32767 REPORT_SIZE(1), 0x10, REPORT_COUNT(1), 0x02, INPUT(1), 0x02, // Data, Variable, Absolute USAGE_PAGE(1), 0x01, // Generic Desktop USAGE(1), 0x38, // scroll LOGICAL_MINIMUM(1), 0x81, // -127 LOGICAL_MAXIMUM(1), 0x7f, // 127 REPORT_SIZE(1), 0x08, REPORT_COUNT(1), 0x01, INPUT(1), 0x06, // Data, Variable, Relative USAGE_PAGE(1), 0x09, // Buttons USAGE_MINIMUM(1), 0x01, USAGE_MAXIMUM(1), 0x03, LOGICAL_MINIMUM(1), 0x00, // 0 LOGICAL_MAXIMUM(1), 0x01, // 1 REPORT_COUNT(1), 0x03, REPORT_SIZE(1), 0x01, INPUT(1), 0x02, // Data, Variable, Absolute REPORT_COUNT(1), 0x01, REPORT_SIZE(1), 0x05, INPUT(1), 0x01, // Constant END_COLLECTION(0), END_COLLECTION(0) }; reportLength = sizeof(reportDescriptor); return reportDescriptor; } return NULL; }
void NewVelocity_z_cpu () { //<USER_DEFINED> INPUT(Density); #ifdef Z INPUT(Mmz); INPUT(Mpz); OUTPUT(Vz); #endif //<\USER_DEFINED> //<EXTERNAL> real* rho = Density->field_cpu; #ifdef Z real* vz = Vz -> field_cpu; real* mmz = Mmz->field_cpu; real* mpz = Mpz->field_cpu; #endif int pitch = Pitch_cpu; int stride = Stride_cpu; int size_x = Nx+2*NGHX; int size_y = Ny+2*NGHY; int size_z = Nz+2*NGHZ; //<\EXTERNAL> //<INTERNAL> int i; //Variables reserved int j; //for the topology int k; //of the kernels int ll; int llzm; //<\INTERNAL> //<CONSTANT> // real ymin(Ny+2*NGHY+1); //<\CONSTANT> //<MAIN_LOOP> i = j = k = 0; #ifdef Z for (k=1; k<size_z; k++) { #endif #ifdef Y for (j=1; j<size_y; j++) { #endif #ifdef X for (i=XIM; i<size_x; i++) { #endif //<#> #ifdef Z ll = l; llzm = lzm; vz[ll] = (mmz[ll]+mpz[llzm])/(rho[ll]+rho[llzm]); #ifdef SPHERICAL vz[ll] /= ymed(j); #endif #endif //<\#> #ifdef X } #endif #ifdef Y } #endif #ifdef Z } #endif //<\MAIN_LOOP> }
main() { double A[10][11], X[10]; double AMAX,XM,SUM; int NROW[10]; int N,M,ICHG,I,NN,IMAX,J,JJ,IP,JP,NCOPY,I1,J1,N1,K,N2,LL,KK,OK; INPUT(&OK, A, &N); if (OK) { M = N + 1; /* STEP 1 */ for (I=1; I<=N; I++) NROW[I-1] = I; /* initialize row pointer */ NN = N - 1; ICHG = 0; I = 1; /* STEP 2 */ while ((OK) && (I <= NN)) { /* STEP 3 */ IMAX = NROW[I-1]; AMAX = absval(A[IMAX-1][I-1]); IMAX = I; JJ = I + 1; for (IP=JJ; IP<=N; IP++) { JP = NROW[IP-1]; if (absval(A[JP-1][I-1]) > AMAX) { AMAX = absval(A[JP-1][I-1]); IMAX = IP; } } /* STEP 4 */ if (AMAX <= ZERO) OK = false; else { /* STEP 5 */ /* simulate row interchange */ if ( NROW[I-1] != NROW[IMAX-1]) { ICHG = ICHG + 1; NCOPY = NROW[I-1]; NROW[I-1] = NROW[IMAX-1]; NROW[IMAX-1] = NCOPY; } I1 = NROW[I-1]; /* STEP 6 */ for (J=JJ; J<=N; J++) { J1 = NROW[J-1]; /* STEP 7 */ XM = A[J1-1][I-1] / A[I1-1][I-1]; /* STEP 8 */ for (K=JJ; K<=M; K++) A[J1-1][K-1] = A[J1-1][K-1] - XM * A[I1-1][K-1]; /* Multiplier XM could be saved in A[J1-1,I-1] */ A[J1-1][I-1] = 0.0; } } I++; } if (OK) { /* STEP 9 */ N1 = NROW[N-1]; if (absval(A[N1-1][N-1]) <= ZERO) OK = false; /* system has no unique solution */ else { /* STEP 10 */ /* start backward substitution */ X[N-1] = A[N1-1][M-1] / A[N1-1][N-1]; /* STEP 11 */ for (K=1; K<=NN; K++) { I = NN - K + 1; JJ = I + 1; N2 = NROW[I-1]; SUM = 0.0; for (KK=JJ; KK<=N; KK++) { SUM = SUM - A[N2-1][KK-1] * X[KK-1]; } X[I-1] = (A[N2-1][N] + SUM) / A[N2-1][I-1]; } /* STEP 12 */ /* procedure completed successfully */ OUTPUT(N, M, ICHG, NROW, X, A); } } if (!OK) printf("System has no unique solution\n"); } return 0; }
void phaseControl() { /* switch(noOfPeople) { case 0 : OUTPUT_HIGH(PIN_B7); break; default : if(INPUT(PIN_B6) && pin_changed == 1) { pin_changed = 0; if(0<=temperature && temperature<20) { OUTPUT_HIGH(PIN_B7); } else if(temperature>=20&& temperature<35) { delay_ms(5); OUTPUT_HIGH(PIN_B7); delay_ms(5); OUTPUT_LOW(PIN_B7); } else if(temperature>=35) { OUTPUT_LOW(PIN_B7); } } //else if(!INPUT(PIN_B6) && pin_changed==0) pin_changed = 1; if(!INPUT(PIN_B6)) pin_changed = 1; }*/ if(noOfPeople<1) { OUTPUT_HIGH(PIN_B7); //OUTPUT_LOW(PIN_B7); } else { // OUTPUT_LOW(PIN_B7); if(INPUT(PIN_B6) && pin_changed == 1) { if(0<=temperature && temperature<20) { OUTPUT_HIGH(PIN_B7); } else if(temperature>=20&& temperature<25) { delay_us(7000); OUTPUT_LOW(PIN_B7); delay_us(500); OUTPUT_HIGH(PIN_B7); } else if(temperature>=25&& temperature<28) { delay_us(6000); OUTPUT_LOW(PIN_B7); delay_us(500); OUTPUT_HIGH(PIN_B7); } else if(temperature>=28&& temperature<35) { delay_us(5000); OUTPUT_LOW(PIN_B7); delay_us(500); OUTPUT_HIGH(PIN_B7); } else if(temperature>=35) { OUTPUT_LOW(PIN_B7); } pin_changed = 0; } if(!INPUT(PIN_B6)) { pin_changed = 1; } } }
void SubStep1_y_cpu (real dt) { //<USER_DEFINED> INPUT(Pressure); INPUT(Density); INPUT(Pot); #ifdef X INPUT(Vx); #endif #ifdef Y INPUT(Vy); OUTPUT(Vy_temp); #endif #ifdef Z INPUT(Vz); #endif #ifdef MHD INPUT(Bx); INPUT(Bz); #endif //<\USER_DEFINED> //<EXTERNAL> real* p = Pressure->field_cpu; real* pot = Pot->field_cpu; real* rho = Density->field_cpu; #ifdef X real* vx = Vx->field_cpu; real* vx_temp = Vx_temp->field_cpu; #endif #ifdef Y real* vy = Vy->field_cpu; real* vy_temp = Vy_temp->field_cpu; #endif #ifdef Z real* vz = Vz->field_cpu; real* vz_temp = Vz_temp->field_cpu; #endif #ifdef MHD real* bx = Bx->field_cpu; real* bz = Bz->field_cpu; #endif int pitch = Pitch_cpu; int stride = Stride_cpu; int size_x = XIP; int size_y = Ny+2*NGHY-1; int size_z = Nz+2*NGHZ-1; //<\EXTERNAL> //<INTERNAL> int i; //Variables reserved int j; //for the topology int k; //of the kernels int ll; real dtOVERrhom; #ifdef X int llxp; #endif #ifdef Y int llym; #endif #ifdef Z int llzp; #endif #ifdef MHD real db1; real db2; real bmeanm; real bmean; #endif #ifndef CARTESIAN real vphi; #endif #ifdef SHEARINGBOX real vm1, vm2; #endif #ifdef SPHERICAL real vzz; #endif //<\INTERNAL> //<CONSTANT> // real xmin(Nx+2*NGHX+1); // real ymin(Ny+2*NGHY+1); // real zmin(Nz+2*NGHZ+1); // real OMEGAFRAME(1); // real OORTA(1); // real VERTICALDAMPING(1); //<\CONSTANT> //<MAIN_LOOP> i = j = k = 0; #ifdef Z for(k=1; k<size_z; k++) { #endif #ifdef Y for(j=1; j<size_y; j++) { #endif #ifdef X for(i=XIM; i<size_x; i++) { #endif //<#> #ifdef Y ll = l; #ifdef X llxp = lxp; #endif //ENDIF X llym = lym; #ifdef Z llzp = lzp; #endif //ENDIF Z dtOVERrhom = 2.0*dt/(rho[ll]+rho[llym]); #ifdef CARTESIAN vy_temp[ll] = vy[ll] - dtOVERrhom*(p[ll]-p[llym])/(ymed(j)-ymed(j-1)); #ifdef SHEARINGBOX vm1 = vx[ll]+vx[llxp]; vm2 = vx[llym]+vx[llxp-pitch]; vy_temp[l] += dt*(.5*OMEGAFRAME*(vm1+vm2) - 4.0*OORTA*OMEGAFRAME*ymin(j)); #endif //ENDIF SHEARINGBOX #ifdef MHD #ifndef PASSIVEMHD bmean = 0.5*(bx[ll] + bx[llxp]); bmeanm = 0.5*(bx[llym] + bx[llxp-pitch]); db1 = (bmean*bmean-bmeanm*bmeanm); bmean = 0.5*(bz[ll] + bz[llzp]); bmeanm = 0.5*(bz[llym] + bz[llym+stride]); db2 = (bmean*bmean-bmeanm*bmeanm); //grad(b^2/2) vy_temp[ll] -= .5*dtOVERrhom*(db1 + db2)/((ymed(j)-ymed(j-1))*MU0); #endif //ENDIF !PASSIVEMHD #endif //ENDIF MHD #endif //ENDIF CARTESIAN #ifdef CYLINDRICAL vphi = .25*(vx[ll] + vx[llxp] + vx[llym] + vx[llxp-pitch]); vphi += ymin(j)*OMEGAFRAME; vy_temp[ll] = vy[ll] - dtOVERrhom*(p[ll]-p[llym])/(ymed(j)-ymed(j-1)); vy_temp[ll] += vphi*vphi/ymin(j)*dt; vy_temp[ll] /= (1.+VERTICALDAMPING*dt); #ifdef MHD #ifndef PASSIVEMHD bmean = 0.5*(bx[ll] + bx[llxp]); bmeanm = 0.5*(bx[llym] + bx[llxp-pitch]); vy_temp[ll] -= dtOVERrhom*.25*(bmean+bmeanm)*(bmean+bmeanm)/(MU0*ymin(j)); db1 = (bmean*bmean-bmeanm*bmeanm); bmean = 0.5*(bz[ll] + bz[llzp]); bmeanm = 0.5*(bz[llym] + bz[llym+stride]); db2 = (bmean*bmean-bmeanm*bmeanm); //-grad((bphi^2+bz^2)/2) vy_temp[ll] -= .5*dtOVERrhom*(db1 + db2)/((ymed(j)-ymed(j-1))*MU0); #endif //END !PASSIVEMHD #endif //END MHD #endif //END CYLINDRICAL #ifdef SPHERICAL vphi = .25*(vx[ll] + vx[llxp] + vx[llym] + vx[llxp-pitch]); vphi += ymin(j)*sin(zmed(k))*OMEGAFRAME; vy_temp[ll] = vy[ll] - dtOVERrhom*(p[ll]-p[llym])/(ymed(j)-ymed(j-1)); vzz = .25*(vz[ll] + vz[llzp] + vz[llym] + vz[llzp-pitch]); vy_temp[ll] += (vphi*vphi + vzz*vzz)/ymin(j)*dt; #ifdef MHD #ifndef PASSIVEMHD bmean = 0.5*(bx[ll] + bx[llxp]); bmeanm = 0.5*(bx[llym] + bx[llxp-pitch]); vy_temp[ll] -= dtOVERrhom*.25*(bmean+bmeanm)*(bmean+bmeanm)/(MU0*ymin(j));//Source term -B_phi^2/(mu_0\rho r) db1 = (bmean*bmean-bmeanm*bmeanm); bmean = 0.5*(bz[ll] + bz[llzp]); bmeanm = 0.5*(bz[llym] + bz[llym+stride]); vy_temp[ll] -= dtOVERrhom*.25*(bmean+bmeanm)*(bmean+bmeanm)/(MU0*ymin(j));//Source term -B_\theta^2/(mu_0\rho r) db2 = (bmean*bmean-bmeanm*bmeanm); //-grad((bphi^2+btheta^2)/2) vy_temp[ll] -= .5*dtOVERrhom*(db1 + db2)/((ymed(j)-ymed(j-1))*MU0); #endif //END !PASSIVEMHD #endif //END MHD #endif //END SPHERICAL #ifdef POTENTIAL vy_temp[ll] -= (pot[ll]-pot[llym])*dt/(ymed(j)-ymed(j-1)); #endif //ENDIF POTENTIAL #endif //ENDIF Y //<\#> #ifdef X } #endif #ifdef Y } #endif #ifdef Z } #endif //<\MAIN_LOOP> }
main() { double X[27],H[27],A[25],B[25],ALPHA[25],BETA[25],ZETA[25],Z[25],C[25]; double Q[6][26]; double HQ,HC; int N1,J1,FN,N,J,OK; void INPUT(int *, double *, double *, int *, double *); void OUTPUT(int, double *, double *); double P(double); double QQ(double); double F(double); double SIMPSON(int, double, double); INPUT(&OK, X, H, &N, &HC); /* Step 1 is done within the input procedure */ if (OK) { N1 = N - 1; /* STEP 3 */ for (J=1; J<=N1; J++) { Q[0][J-1] = SIMPSON( 1, X[J], X[J+1] ) / (( H[J] ) * ( H[J] )); Q[1][J-1] = SIMPSON( 2, X[J-1], X[J] ) / (( H[J-1] ) * ( H[J-1] )); Q[2][J-1] = SIMPSON( 3, X[J], X[J+1] ) / (( H[J] ) * ( H[J] )); Q[3][J-1] = SIMPSON( 4, X[J-1], X[J] ) / (( H[J-1] ) * ( H[J-1] )); Q[4][J-1] = SIMPSON( 5, X[J-1], X[J] ) / H[J-1] ; Q[5][J-1] = SIMPSON( 6, X[J], X[J+1] ) / H[J]; } Q[1][N-1] = SIMPSON( 2, X[N-1], X[N] ) / (( H[N-1] ) * ( H[N-1] )); Q[2][N-1] = SIMPSON( 3, X[N], X[N+1] ) / (( H[N] ) * ( H[N] )); Q[3][N-1] = SIMPSON( 4, X[N-1], X[N] ) / (( H[N-1] ) * ( H[N-1] )); Q[3][N] = SIMPSON( 4, X[N], X[N+1] ) / (( H[N] ) * ( H[N] )); Q[4][N-1] = SIMPSON( 5, X[N-1], X[N] ) / H[N-1]; Q[5][N-1] = SIMPSON( 6, X[N], X[N+1] ) / H[N]; /* STEP 4 */ for (J=1; J<=N1; J++) { ALPHA[J-1] = Q[3][J-1]+Q[3][J]+Q[1][J-1]+Q[2][J-1]; BETA[J-1] = Q[0][J-1]-Q[3][J]; B[J-1] = Q[4][J-1]+Q[5][J-1]; } /* STEP 5 */ ALPHA[N-1] = Q[3][N-1]+Q[3][N]+Q[1][N-1]+Q[2][N-1]; B[N-1] = Q[4][N-1]+Q[5][N-1]; /* STEPS 6-10 solve a symmtric tridiagonal linear system using Algorithm 6.7. */ /* STEP 6 */ A[0] = ALPHA[0]; ZETA[0] = BETA[0] / ALPHA[0]; Z[0] = B[0] / A[0]; /* STEP 7 */ for (J=2; J<=N1; J++) { A[J-1] = ALPHA[J-1] - BETA[J-2] * ZETA[J-2]; ZETA[J-1] = BETA[J-1] / A[J-1]; Z[J-1] = (B[J-1]-BETA[J-2]*Z[J-2])/A[J-1]; } /* STEP 8 */ A[N-1] = ALPHA[N-1] - BETA[N-2] * ZETA[N-2]; Z[N-1] = (B[N-1]-BETA[N-2]*Z[N-2])/A[N-1]; /* STEP 9 */ C[N-1] = Z[N-1]; for (J=1; J<=N1; J++) { J1 = N - J; C[J1-1] = Z[J1-1] - ZETA[J1-1] * C[J1]; } OUTPUT(N, X, C); } /* STEP 10 */ return 0; }
int main(int argc, char * argv[]){ cout<<"****************************** FILES OPENING ***************************************"<<endl; string INPUT(argv[1]); string OUTPUT(argv[2]); FileSaver finalHistos; FileSaver Plots; finalHistos.setName(INPUT.c_str()); Plots.setName(OUTPUT.c_str()); bool checkfile = finalHistos.CheckFile(); cout<<"****************************** BINS ***************************************"<<endl; SetBins(); PRB.Print(); cout<<"**TOF**"<<endl; ToFDB.Print(); cout<<"**NaF**"<<endl; NaFDB.Print(); cout<<"**Agl**"<<endl; AglDB.Print(); ToFDB.UseBetaEdges(); NaFDB.UseBetaEdges(); AglDB.UseBetaEdges(); PRB.UseREdges(); cout<<endl; cout<<"****************************** PLOTTING FITS ***************************************"<<endl; TemplateFIT * ToFfits= new TemplateFIT(finalHistos,"TOFfits",ToFDB); TemplateFIT * NaFfits= new TemplateFIT(finalHistos,"NaFfits",NaFDB); TemplateFIT * Aglfits= new TemplateFIT(finalHistos,"Aglfits",AglDB); DrawFits(ToFfits,finalHistos,Plots); DrawFits(NaFfits,finalHistos,Plots); DrawFits(Aglfits,finalHistos,Plots); cout<<"****************************** RESULTS ***************************************"<<endl; TCanvas * c4 = new TCanvas("Deuteron Counts"); c4->SetCanvasSize(2000,1500); std::string pathresTOF = (ToFfits->GetName() + "/Fit Results/"); std::string pathresNaF = (NaFfits->GetName() + "/Fit Results/"); std::string pathresAgl = (Aglfits->GetName() + "/Fit Results/"); TH1F * DCountsTOF = (TH1F*) finalHistos.Get((pathresTOF+"Deuteron Counts").c_str()); TH1F * DCountsNaF = (TH1F*) finalHistos.Get((pathresNaF+"Deuteron Counts").c_str()); TH1F * DCountsAgl = (TH1F*) finalHistos.Get((pathresAgl+"Deuteron Counts").c_str()); TH1F * PCountsTOF = (TH1F*) finalHistos.Get((pathresTOF+"Proton Counts").c_str()); TH1F * PCountsNaF = (TH1F*) finalHistos.Get((pathresNaF+"Proton Counts").c_str()); TH1F * PCountsAgl = (TH1F*) finalHistos.Get((pathresAgl+"Proton Counts").c_str()); TH1F * DCountsPrimTOF = (TH1F*) finalHistos.Get((pathresTOF+"Primary Deuteron Counts").c_str()); TH1F * DCountsPrimNaF = (TH1F*) finalHistos.Get((pathresNaF+"Primary Deuteron Counts").c_str()); TH1F * DCountsPrimAgl = (TH1F*) finalHistos.Get((pathresAgl+"Primary Deuteron Counts").c_str()); PlotTH1FintoGraph(gPad,ToFDB, DCountsTOF,"Kinetic Energy [GeV/nucl.]", "Counts",4,true,"Psame",0.1,10,10,7e4,"Deuteron Counts (TOF)",8); PlotTH1FintoGraph(gPad,NaFDB, DCountsNaF,"Kinetic Energy [GeV/nucl.]", "Counts",4,true,"Psame",0.1,10,10,7e4,"Deuteron Counts (NaF)",22); PlotTH1FintoGraph(gPad,AglDB, DCountsAgl,"Kinetic Energy [GeV/nucl.]", "Counts",4,true,"Psame",0.1,10,10,7e4,"Deuteron Counts (Agl)",29); PlotTH1FintoGraph(gPad,ToFDB, DCountsPrimTOF,"Kinetic Energy [GeV/nucl.]", "Counts",4,true,"Psame",0.1,10,10,7e4,"Primary Counts (TOF)",4); PlotTH1FintoGraph(gPad,NaFDB, DCountsPrimNaF,"Kinetic Energy [GeV/nucl.]", "Counts",4,true,"Psame",0.1,10,10,7e4,"Primary Counts (NaF)",26); PlotTH1FintoGraph(gPad,AglDB, DCountsPrimAgl,"Kinetic Energy [GeV/nucl.]", "Counts",4,true,"Psame",0.1,10,10,7e4,"Primary Counts (Agl)",30); Plots.Add(c4); Plots.writeObjsInFolder("Results"); TCanvas * c5 = new TCanvas("D/P Raw Counts ratio"); c5->SetCanvasSize(2000,1500); TH1F * RatioTOF = (TH1F*)DCountsTOF->Clone(); RatioTOF->Divide(PCountsTOF); TH1F * RatioNaF = (TH1F*)DCountsNaF->Clone(); RatioNaF->Divide(PCountsNaF); TH1F * RatioAgl = (TH1F*)DCountsAgl->Clone(); RatioAgl->Divide(PCountsAgl); PlotTH1FintoGraph(gPad,ToFDB, RatioTOF,"Kinetic Energy [GeV/nucl.]", "Counts ratio",2,true,"Psame",0.1,10,1e-3,1e-1,"d/P Counts ratio (TOF)",8); PlotTH1FintoGraph(gPad,NaFDB, RatioNaF,"Kinetic Energy [GeV/nucl.]", "Counts ratio",2,true,"Psame",0.1,10,1e-3,1e-1,"d/P Counts ratio (NaF)",22); PlotTH1FintoGraph(gPad,AglDB, RatioAgl,"Kinetic Energy [GeV/nucl.]", "Counts ratio",2,true,"Psame",0.1,10,1e-3,1e-1,"d/P Counts ratio (Agl)",29); Plots.Add(c5); Plots.writeObjsInFolder("Results"); TCanvas * c6 = new TCanvas("Uncertainty Break-down"); c6->SetCanvasSize(5000,1000); c6->Divide(3,1); TH1F * StatErrTOF = (TH1F*) finalHistos.Get((pathresTOF+"StatError").c_str()); TH1F * SystErrTOF = (TH1F*) finalHistos.Get((pathresTOF+"SystError").c_str()); TH1F * HeCoErrTOF = (TH1F*) finalHistos.Get((pathresTOF+"HeContTOF_Eff").c_str()); TH1F * StatErrNaF = (TH1F*) finalHistos.Get((pathresNaF+"StatError").c_str()); TH1F * SystErrNaF = (TH1F*) finalHistos.Get((pathresNaF+"SystError").c_str()); TH1F * HeCoErrNaF = (TH1F*) finalHistos.Get((pathresNaF+"HeContNaF_Eff").c_str()); TH1F * StatErrAgl = (TH1F*) finalHistos.Get((pathresAgl+"StatError").c_str()); TH1F * SystErrAgl = (TH1F*) finalHistos.Get((pathresAgl+"SystError").c_str()); TH1F * HeCoErrAgl = (TH1F*) finalHistos.Get((pathresAgl+"HeContAgl_Eff").c_str()); TH1F * TotErrTOF = (TH1F *)StatErrTOF->Clone(); TH1F * TotErrNaF = (TH1F *)StatErrNaF->Clone(); TH1F * TotErrAgl = (TH1F *)StatErrAgl->Clone(); for(int bin=0;bin<DCountsTOF->GetNbinsX();bin++) { if(DCountsTOF->GetBinContent(bin+1)>0){ TotErrTOF->SetBinContent(bin+1,DCountsTOF->GetBinError(bin+1)/DCountsTOF->GetBinContent(bin+1)); TotErrTOF->SetBinError(bin+1,0); } if(DCountsNaF->GetBinContent(bin+1)>0){ TotErrNaF->SetBinContent(bin+1,DCountsNaF->GetBinError(bin+1)/DCountsNaF->GetBinContent(bin+1)); TotErrNaF->SetBinError(bin+1,0); } if(DCountsAgl->GetBinContent(bin+1)>0){ TotErrAgl->SetBinContent(bin+1,DCountsAgl->GetBinError(bin+1)/DCountsAgl->GetBinContent(bin+1)); TotErrAgl->SetBinError(bin+1,0); } } c6->cd(1); PlotDistribution(gPad,TotErrTOF ,"TOF Range Bin","Relative error",2,"same",1e-4,1.1,10,"T. Fit Total Error"); PlotDistribution(gPad,SystErrTOF,"TOF Range Bin","Relative error",4,"same",1e-4,1.1,4,"T. Fit Systematic Error"); PlotDistribution(gPad,StatErrTOF,"TOF Range Bin","Relative error",1,"same",1e-4,1.1,4,"T. Fit Statistical Error"); PlotDistribution(gPad,HeCoErrTOF,"TOF Range Bin","Relative error",3,"same",1e-4,1.1,4,"Helium Fragm. Error"); c6->cd(2); PlotDistribution(gPad,TotErrNaF ,"NaF Range Bin","Relative error",2,"same",1e-4,1.1,10,"T. Fit Total Error"); PlotDistribution(gPad,SystErrNaF,"NaF Range Bin","Relative error",4,"same",1e-4,1.1,4,"T. Fit Systematic Error"); PlotDistribution(gPad,StatErrNaF,"NaF Range Bin","Relative error",1,"same",1e-4,1.1,4,"T. Fit Statistical Error"); PlotDistribution(gPad,HeCoErrNaF,"NaF Range Bin","Relative error",3,"same",1e-4,1.1,4,"Helium Fragm. Error"); c6->cd(3); PlotDistribution(gPad,TotErrAgl ,"Agl Range Bin","Relative error",2,"same",1e-4,1.1,10,"T. Fit Total Error"); PlotDistribution(gPad,SystErrAgl,"Agl Range Bin","Relative error",4,"same",1e-4,1.1,4,"T. Fit Systematic Error"); PlotDistribution(gPad,StatErrAgl,"Agl Range Bin","Relative error",1,"same",1e-4,1.1,4,"T. Fit Statistical Error"); PlotDistribution(gPad,HeCoErrAgl,"Agl Range Bin","Relative error",3,"same",1e-4,1.1,4,"Helium Fragm. Error"); Plots.Add(c6); Plots.writeObjsInFolder("Results"); TCanvas * c7 = new TCanvas("Chi Square"); c7->SetCanvasSize(5000,1000); c7->Divide(3,1); TH1F * BestChiSquareTOF = (TH1F*) finalHistos.Get((pathresTOF+"Best ChiSquare").c_str()); TH1F * OriginalChiSquareTOF = (TH1F*) finalHistos.Get((pathresTOF+"Original ChiSquare").c_str()); TH1F * BestChiSquareNaF = (TH1F*) finalHistos.Get((pathresNaF+"Best ChiSquare").c_str()); TH1F * OriginalChiSquareNaF = (TH1F*) finalHistos.Get((pathresNaF+"Original ChiSquare").c_str()); TH1F * BestChiSquareAgl = (TH1F*) finalHistos.Get((pathresAgl+"Best ChiSquare").c_str()); TH1F * OriginalChiSquareAgl = (TH1F*) finalHistos.Get((pathresAgl+"Original ChiSquare").c_str()); c7->cd(1); PlotDistribution(gPad,BestChiSquareTOF ,"TOF Range Bin","#chi^2 of T. Fit",2,"Psame",1e-1,30,3,"Best #chi^{2} mod. Template"); PlotDistribution(gPad,OriginalChiSquareTOF,"TOF Range Bin","#chi^2 of T. Fit",4,"Psame",1e-1,30,3,"Original MC Templates"); c7->cd(2); PlotDistribution(gPad,BestChiSquareNaF ,"NaF Range Bin","#chi^2 of T. Fit",2,"Psame",1e-1,35,3,"Best #chi^{2} mod. Template"); PlotDistribution(gPad,OriginalChiSquareNaF,"NaF Range Bin","#chi^2 of T. Fit",4,"Psame",1e-1,35,3,"Original MC Templates"); c7->cd(3); PlotDistribution(gPad,BestChiSquareAgl ,"Agl Range Bin","#chi^2 of T. Fit",2,"Psame",1e-1,35,3,"Best #chi^{2} mod. Template"); PlotDistribution(gPad,OriginalChiSquareAgl,"Agl Range Bin","#chi^2 of T. Fit",4,"Psame",1e-1,35,3,"Original MC Templates"); Plots.Add(c7); Plots.writeObjsInFolder("Results"); DrawParameters(finalHistos,Plots,pathresTOF,ToFDB,"Parameters TOF","[ps]",0.45,0.9,-100,100,-40,180); DrawParameters(finalHistos,Plots,pathresNaF,NaFDB,"Parameters NaF","[rad/10^{4}]",0.7,0.98,-1000,1000,-1000,2000); DrawParameters(finalHistos,Plots,pathresAgl,AglDB,"Parameters Agl","[rad/10^{4}]",0.95,1.005,-230,230,-150,400); return 0; }
void VanLeerX_PPA_d_cpu(real dt, Field *Q, Field *Qs, Field *Vx_t){ //<USER_DEFINED> INPUT(Q); INPUT(QL); INPUT(QR); INPUT(Vx_t); OUTPUT(Qs); //<\USER_DEFINED> //<EXTERNAL> real* vx = Vx_t->field_cpu; real* q = Q->field_cpu ; real* qs = Qs->field_cpu ; real* qL = QL->field_cpu ; real* qR = QR->field_cpu ; int pitch = Pitch_cpu; int stride = Stride_cpu; int size_x = Nx+2*NGHX; int size_y = Ny+2*NGHY; int size_z = Nz+2*NGHZ; real dx = Dx; //<\EXTERNAL> //<INTERNAL> int i; int j; int k; int ll; int llxm; real ksi; //<\INTERNAL> //Parsed as copytosymbol, to a _d variable allocated on the gpu by the user. //<CONSTANT> // real ymin(Ny+2*NGHY+1); // real zmin(Nz+2*NGHZ+1); //<\CONSTANT> //<MAIN_LOOP> i = j = k = 0; #ifdef Z for (k=0; k<size_z; k++) { #endif #ifdef Y for (j=0; j<size_y; j++) { #endif for (i=XIM; i<size_x; i++) { //<#> ll = l; llxm = lxm; if (vx[ll] > 0.0) { ksi = vx[ll]*dt/zone_size_x(j,k); qs[ll] = qR[llxm]+ksi*(q[llxm]-qR[llxm]); qs[ll]+= ksi*(1.0-ksi)*(2.0*q[llxm]-qR[llxm]-qL[llxm]); } else { ksi = -vx[ll]*dt/zone_size_x(j,k); qs[ll] = qL[ll]+ksi*(q[ll]-qL[ll]); qs[ll]+= ksi*(1.0-ksi)*(2.0*q[ll]-qR[ll]-qL[ll]); } //<\#> } #ifdef Y } #endif #ifdef Z } #endif //<\MAIN_LOOP> }
static void bilateral_filter (GeglBuffer *src, const GeglRectangle *src_rect, GeglBuffer *dst, const GeglRectangle *dst_rect, gint s_sigma, gfloat r_sigma) { gint c, x, y, z, k, i; const gint padding_xy = 2; const gint padding_z = 2; const gint width = src_rect->width; const gint height = src_rect->height; const gint channels = 4; const gint sw = (width -1) / s_sigma + 1 + (2 * padding_xy); const gint sh = (height-1) / s_sigma + 1 + (2 * padding_xy); const gint depth = (int)(1.0f / r_sigma) + 1 + (2 * padding_z); /* down-sampling */ gfloat *grid = g_new0 (gfloat, sw * sh * depth * channels * 2); gfloat *blurx = g_new0 (gfloat, sw * sh * depth * channels * 2); gfloat *blury = g_new0 (gfloat, sw * sh * depth * channels * 2); gfloat *blurz = g_new0 (gfloat, sw * sh * depth * channels * 2); gfloat *input = g_new0 (gfloat, width * height * channels); gfloat *smoothed = g_new0 (gfloat, width * height * channels); #define INPUT(x,y,c) input[c+channels*(x + width * y)] #define GRID(x,y,z,c,i) grid [i+2*(c+channels*(x+sw*(y+z*sh)))] #define BLURX(x,y,z,c,i) blurx[i+2*(c+channels*(x+sw*(y+z*sh)))] #define BLURY(x,y,z,c,i) blury[i+2*(c+channels*(x+sw*(y+z*sh)))] #define BLURZ(x,y,z,c,i) blurz[i+2*(c+channels*(x+sw*(y+z*sh)))] gegl_buffer_get (src, src_rect, 1.0, babl_format ("RGBA float"), input, GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE); for (k=0; k < (sw * sh * depth * channels * 2); k++) { grid [k] = 0.0f; blurx[k] = 0.0f; blury[k] = 0.0f; blurz[k] = 0.0f; } #if 0 /* in case we want to normalize the color space */ gfloat input_min[4] = { FLT_MAX, FLT_MAX, FLT_MAX}; gfloat input_max[4] = {-FLT_MAX, -FLT_MAX, -FLT_MAX}; for(y = 0; y < height; y++) for(x = 0; x < width; x++) for(c = 0; c < channels; c++) { input_min[c] = MIN(input_min[c], INPUT(x,y,c)); input_max[c] = MAX(input_max[c], INPUT(x,y,c)); } #endif /* downsampling */ for(y = 0; y < height; y++) for(x = 0; x < width; x++) for(c = 0; c < channels; c++) { const float z = INPUT(x,y,c); // - input_min[c]; const int small_x = (int)((float)(x) / s_sigma + 0.5f) + padding_xy; const int small_y = (int)((float)(y) / s_sigma + 0.5f) + padding_xy; const int small_z = (int)((float)(z) / r_sigma + 0.5f) + padding_z; g_assert(small_x >= 0 && small_x < sw); g_assert(small_y >= 0 && small_y < sh); g_assert(small_z >= 0 && small_z < depth); GRID(small_x, small_y, small_z, c, 0) += INPUT(x, y, c); GRID(small_x, small_y, small_z, c, 1) += 1.0f; } /* blur in x, y and z */ /* XXX: we could use less memory, but at expense of code readability */ for (z = 1; z < depth-1; z++) for (y = 1; y < sh-1; y++) for (x = 1; x < sw-1; x++) for(c = 0; c < channels; c++) for (i=0; i<2; i++) BLURX(x, y, z, c, i) = (GRID (x-1, y, z, c, i) + 2.0f * GRID (x, y, z, c, i) + GRID (x+1, y, z, c, i)) / 4.0f; for (z = 1; z < depth-1; z++) for (y = 1; y < sh-1; y++) for (x = 1; x < sw-1; x++) for(c = 0; c < channels; c++) for (i=0; i<2; i++) BLURY(x, y, z, c, i) = (BLURX (x, y-1, z, c, i) + 2.0f * BLURX (x, y, z, c, i) + BLURX (x, y+1, z, c, i)) / 4.0f; for (z = 1; z < depth-1; z++) for (y = 1; y < sh-1; y++) for (x = 1; x < sw-1; x++) for(c = 0; c < channels; c++) for (i=0; i<2; i++) BLURZ(x, y, z, c, i) = (BLURY (x, y-1, z, c, i) + 2.0f * BLURY (x, y, z, c, i) + BLURY (x, y+1, z, c, i)) / 4.0f; /* trilinear filtering */ for (y=0; y < height; y++) for (x=0; x < width; x++) for(c = 0; c < channels; c++) { float xf = (float)(x) / s_sigma + padding_xy; float yf = (float)(y) / s_sigma + padding_xy; float zf = INPUT(x,y,c) / r_sigma + padding_z; int x1 = CLAMP((int)xf, 0, sw-1); int y1 = CLAMP((int)yf, 0, sh-1); int z1 = CLAMP((int)zf, 0, depth-1); int x2 = CLAMP(x1+1, 0, sw-1); int y2 = CLAMP(y1+1, 0, sh-1); int z2 = CLAMP(z1+1, 0, depth-1); float x_alpha = xf - x1; float y_alpha = yf - y1; float z_alpha = zf - z1; float interpolated[2]; g_assert(xf >= 0 && xf < sw); g_assert(yf >= 0 && yf < sh); g_assert(zf >= 0 && zf < depth); for (i=0; i<2; i++) interpolated[i] = lerp(lerp(lerp(BLURZ(x1, y1, z1, c, i), BLURZ(x2, y1, z1, c, i), x_alpha), lerp(BLURZ(x1, y2, z1, c, i), BLURZ(x2, y2, z1, c, i), x_alpha), y_alpha), lerp(lerp(BLURZ(x1, y1, z2, c, i), BLURZ(x2, y1, z2, c, i), x_alpha), lerp(BLURZ(x1, y2, z2, c, i), BLURZ(x2, y2, z2, c, i), x_alpha), y_alpha), z_alpha); smoothed[channels*(y*width+x)+c] = interpolated[0] / interpolated[1]; } gegl_buffer_set (dst, dst_rect, 0, babl_format ("RGBA float"), smoothed, GEGL_AUTO_ROWSTRIDE); g_free (grid); g_free (blurx); g_free (blury); g_free (blurz); g_free (input); g_free (smoothed); }
main() { double A[11][12],AA[11],P[7],Q[7]; double AMAX,XM,SUM; int NROW[11]; int LM,LN,BN,OK; int PP,FLAG,N,M,I,NN,IMAX,J,JJ,IP,JP,NCOPY,I1,J1,N1,K,N2,LL,KK; INPUT(&OK, &BN, &LM, &LN, AA); if (OK) { /* STEP 1 */ N = BN; M = N + 1; /* STEP 2 - performed in input */ for (I=0; I<=N; I++) NROW[I] = I; /* initialize row pointer */ NN = N - 1; /* STEP 3 */ Q[0] = 1.0; /* STEP 4 */ /* set up a linear system with matrix A instead of B */ for (I=0; I<=N; I++) { /* STEP 5 */ for (J=0; J<=I; J++) if (J <= LN) A[I][J] = 0.0; /* STEP 6 */ if (I <= LN) A[I][I] = 1.0; /* STEP 7 */ for (J=I+1; J<=LN; J++) A[I][J] = 0.0; /* STEP 8 */ for (J=LN+1; J<=N; J++) { if (I != 0) { PP = I-J+LN; if (PP < 0) PP = -PP; A[I][J] = -(AA[I+J-LN]+AA[PP])/2.0; } else A[I][J] = -AA[J-LN]/2.0; } A[I][N+1] = AA[I]; } /* STEP 9 */ A[0][N+1] = A[0][N+1]/2.0; /* STEPS 10-21 solve the linear system using partial pivoting */ I = LN+1; /* STEP 10 */ while (OK && (I <= NN)) { /* STEP 11 */ IMAX = NROW[I]; AMAX = absval(A[IMAX][I]); IMAX = I; JJ = I + 1; for (IP=JJ; IP<=N; IP++) { JP = NROW[IP]; if (absval(A[JP][I]) > AMAX) { AMAX = absval(A[JP][I]); IMAX = IP; } } /* STEP 12 */ if (AMAX <= ZERO) OK = false; else { /* STEP 13 */ /* simulate row interchange */ if (NROW[I] != NROW[IMAX]) { NCOPY = NROW[I]; NROW[I] = NROW[IMAX]; NROW[IMAX] = NCOPY; } I1 = NROW[I]; /* STEP 14 */ /* Perform elimination. */ for (J=JJ; J<=M; J++) { J1 = NROW[J]; /* STEP 15 */ XM = A[J1][I] / A[I1][I]; /* STEP 16 */ for (K=JJ; K<=M; K++) A[J1][K] = A[J1][K] - XM * A[I1][K]; /* STEP 17 */ A[J1][I] = 0.0; } } I++; } if (OK) { /* STEP 18 */ N1 = NROW[N]; if (absval(A[N1][N]) <= ZERO) OK = false; /* system has no unique solution */ else { /* STEP 19 */ /* start backward substitution */ if (LM > 0) { Q[LM] = A[N1][M] / A[N1][N]; A[N1][M] = Q[LM]; } PP = 1; /* STEP 20 */ for (K=LN+1; K<=NN; K++) { I = NN - K + LN+1; JJ = I + 1; N2 = NROW[I]; SUM = A[N2][N+1]; for (KK=JJ; KK<=N; KK++) { LL = NROW[KK]; SUM = SUM - A[N2][KK] * A[LL][M]; } A[N2][M] = SUM / A[N2][I]; Q[LM-PP] = A[N2][M]; PP++; } /* STEP 21 */ for (K=0; K<=LN; K++) { I = LN - K; N2 = NROW[I]; SUM = A[N2][N+1]; for (KK=LN+1; KK<=N; KK++) { LL = NROW[KK]; SUM = SUM - A[N2][KK] * A[LL][M]; } A[N2][M] = SUM; P[LN-K] = A[N2][M]; } /* STEP 22 */ /* procedure completed successfully */ OUTPUT(Q, P, LN, LM); } } if (!OK) printf("System has no unique solution\n"); } return 0; }
void _Resist_cpu (int idx, int idy, int idz, int idx1, int idy1, int idz1, int idx2, int idy2, int idz2, Field *B1, Field *B2, Field *Emf, Field2D *Eta) { //<USER_DEFINED> INPUT(B1); INPUT(B2); INPUT(Emf); INPUT2D(Eta); OUTPUT(Emf); //<\USER_DEFINED> //<EXTERNAL> real* b1 = B1->field_cpu; real* b2 = B2->field_cpu; real* emf = Emf->field_cpu; real* eta = Eta->field_cpu; real dx = Dx; int pitch = Pitch_cpu; int pitch2d = Pitch2D; int stride = Stride_cpu; int size_x = XIP; int size_y = Ny+2*NGHY-1; int size_z = Nz+2*NGHZ-1; //<\EXTERNAL> //<INTERNAL> int i; int j; int k; int l1m; int l2m; int ll; real diff1; real diff2; //<\INTERNAL> //<CONSTANT> // real ymin(Ny+2*NGHY+1); // real zmin(Nz+2*NGHZ+1); //<\CONSTANT> //<MAIN_LOOP> for (k=1; k<size_z; k++) { for (j=1; j<size_y; j++) { for (i=XIM; i<size_x; i++) { //<#> ll = l; l1m = lxm*idx1+lym*idy1+lzm*idz1; l2m = lxm*idx2+lym*idy2+lzm*idz2; /* Ideally it should not be the zone size but the distance between zone centers. The different is very minute here and does not matter */ diff1 = zone_size_x(j,k)*idx1+zone_size_y(j,k)*idy1+zone_size_z(j,k)*idz1; diff2 = zone_size_x(j,k)*idx2+zone_size_y(j,k)*idy2+zone_size_z(j,k)*idz2; emf[ll] += eta[l2D]*((b2[ll]-b2[l1m])/diff1-(b1[ll]-b1[l2m])/diff2); #ifdef CYLINDRICAL if (idz1+idz2 == 0) // Considering vertical component of Emf emf[ll] -= eta[l2D]*(b1[ll]+b1[l2m])*.5/ymin(j); //Note that (phi,r,z) has a left-handed orientation. #endif #ifdef SPHERICAL if (idy1+idy2 == 0) // Considering radial component of Emf emf[ll] += eta[l2D]*(b2[ll]+b2[l1m])*.5/ymed(j)*cos(zmin(k))/sin(zmin(k)); if (idz1+idz2 == 0) // Considering colatitude component of Emf emf[ll] -= eta[l2D]*(b1[ll]+b1[l2m])*.5/ymin(j); if (idx1+idx2 == 0) // Considering azimuthal component of Emf emf[ll] += eta[l2D]*(b2[ll]+b2[l1m])*.5/ymin(j); #endif //<\#> } } } //<\MAIN_LOOP> }
#include "../report.h" uint8_t report_descriptor[] = { STD_USAGE_PAGE(USB_HIDUT_PAGE_GENERIC_DESKTOP), USAGE1(USB_HIDUT_USAGE_GENERIC_DESKTOP_KEYBOARD), START_COLLECTION(COLLECTION_APPLICATION), STD_USAGE_PAGE(USB_HIDUT_PAGE_KEYBOARD), USAGE_MINIMUM1(224), USAGE_MAXIMUM1(231), LOGICAL_MINIMUM1(0), LOGICAL_MAXIMUM1(1), REPORT_SIZE1(1), REPORT_COUNT1(8), /* Modifiers */ INPUT(IOF_DATA | IOF_VARIABLE | IOF_ABSOLUTE), REPORT_COUNT1(1), REPORT_SIZE1(8), /* Reserved */ INPUT(IOF_CONSTANT), REPORT_COUNT1(5), REPORT_SIZE1(1), STD_USAGE_PAGE(USB_HIDUT_PAGE_LED), USAGE_MINIMUM1(1), USAGE_MAXIMUM1(5), /* LED states */ OUTPUT(IOF_DATA | IOF_VARIABLE | IOF_ABSOLUTE), REPORT_COUNT1(1), REPORT_SIZE1(3), /* LED states padding */ OUTPUT(IOF_CONSTANT),