int main(){ double dt = 0.1; double *time; double t_start, t_end; int time_steps, Nsamples; Matrix *xSaved, *zSaved; double z; t_start = 0; t_end = 10; time_steps =(int)((double)(t_end - t_start)/dt + 0.5); //arredonda para cima o resultado da divisão time = (double *)aloca(time_steps*sizeof(double)); int i; for(i = 0; i < time_steps; i++){ time[i] = i*dt; } Nsamples = time_steps; xSaved = new_M(Nsamples, 3); zSaved = new_M(Nsamples, 2); for(i = 0; i < Nsamples; i++) { z = getVel(); Matrix *X = NULL; X = intKalman(z); xSaved->a[i][0] = time[i]; xSaved->a[i][1] = X->a[0][0]; xSaved->a[i][2] = X->a[1][0]; zSaved->a[i][0] = time[i]; zSaved->a[i][1] = z; kill_M(&X); } const char fileX[] = "../data/X.dat"; const char fileZ[] = "../data/Z.dat"; MatrixPrint2File(xSaved, fileX); MatrixPrint2File(zSaved, fileZ); kill_M(&xSaved); kill_M(&zSaved); libera(time); KalmanFilter_End(); EndProgram(); reportGood("O programa chegou ao fim!"); return(0); }
static LRESULT CALLBACK WndProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { switch (uMsg) { case WM_CLOSE: { EndProgram( hwnd ); DestroyWindow( hwnd ); break; } case WM_DESTROY: { EndProgram( hwnd ); PostQuitMessage( 0 ); break; } //...I forget why this is here, windows opengl magic I think... case WM_ERASEBKGND: { return 666; } case WM_KEYDOWN: { char keyCharValue = 0; if( wParam >= 0x30 && wParam <= 0x39 ) { keyCharValue = ( wParam - 0x30 ) + '0'; } else if( wParam >= 0x41 && wParam <= 0x5A ) { bool isShiftHeld = ( GetAsyncKeyState( VK_SHIFT ) & ( 1 << 16 ) ); keyCharValue = ( wParam - 0x41 ) + 'a'; keyCharValue += ( ( (int)isShiftHeld ) * ( 'A' - 'a' ) ); } else if ( wParam == VK_SPACE ) { keyCharValue = ' '; } else if ( wParam == VK_OEM_2 ) { //TODO: this is U.S. only, make more general keyCharValue = '/'; } else if ( wParam == VK_OEM_PERIOD ) { keyCharValue = '.'; } else if ( wParam == VK_OEM_MINUS ) { keyCharValue = '-'; } keypressHistory[ keypressHistoryIndex++ ] = keyCharValue; break; } } // Pass All Unhandled Messages To DefWindowProc return DefWindowProc(hwnd,uMsg,wParam,lParam); }
int main(){ Matrix *A, *b, *x, *E; Matrix *S, *L, *U, *I; A = new_M_from_string(2,2, "1 1 2 3"); printf("detA = %.3lf \n", determinante(A)); kill_M(&A); EndProgram(); return(0); }
void Compiler::TranslationUnit() { // 始初化寄存器 SetupRegisters(); //开始 BeginProgram(); //全局变量部分 Data_Segment(); EmitGlobals(); //代码函部分 Text_Segment(); EmitFunctions(); //结束, 刷新缓冲区 EndProgram(); fclose(ASMFile); }
int main() { app.window.create(sf::VideoMode(800,600,32),"Window"); app.window.setFramerateLimit(60); void ProcessInput(); void EndProgram(); void DrawBullet(int numOfBullets); void MoveBullet(int numOfBullets); while (app.window.isOpen()) { app.window.clear(); //Clear the screen app.window.draw(player.sprite); //Draw the player DrawBullet(app.totalBullets); //Draw the existing bullets app.window.display(); //Display the sprites ProcessInput(); //Process the user's input MoveBullet(app.totalBullets); //Move the existing bullets if (player.canShoot == false) app.CheckBulletClock(); //The player cannot shoot at any given time. There should EndProgram(); //Check if the user wishes to exit (it's separated from ProcessInput } return 0; }
int main() { Matrix **A, **B; Matrix *X1, *X2, *X3, *X5, *X10; char file[] = "./../data/tab1.dat"; A = (Matrix **)aloca(3 * sizeof(Matrix *)); B = (Matrix **)aloca(2 * sizeof(Matrix *)); X1 = PolynomialFitting(file, 17, 1); X2 = PolynomialFitting(file, 17, 2); X3 = PolynomialFitting(file, 17, 3); X5 = PolynomialFitting(file, 17, 5); X10 = PolynomialFitting(file, 17, 10); //exemplo pg 230 : resultado ok! A[0] = X1; A[1] = X2; A[2] = X3; B[0] = X5; B[1] = X10; MakeGnuplotMultPlotScript("plot1-a.GNU", \ "./../data/tab1.dat", A, 3, "./../LaTeX/graph/quest1-a"); MakeGnuplotMultPlotScript("plot1-b.GNU", \ "./../data/tab1.dat", B, 2, "./../LaTeX/graph/quest1-b"); printf("O erro da aproximação com n = 1 é : %.6lf\n",\ FindFittingError(X1, file, 17)); printf("O erro da aproximação com n = 2 é : %.6lf\n",\ FindFittingError(X2, file, 17)); printf("O erro da aproximação com n = 3 é : %.6lf\n",\ FindFittingError(X3, file, 17)); printf("O erro da aproximação com n = 5 é : %.6lf\n",\ FindFittingError(X5, file, 17)); printf("O erro da aproximação com n = 10 é : %.6lf\n",\ FindFittingError(X10, file, 17)); print_coeff_table(X1, "tab-quest1-X1.tab"); print_coeff_table(X2, "tab-quest1-X2.tab"); print_coeff_table(X3, "tab-quest1-X3.tab"); print_coeff_table(X5, "tab-quest1-X5.tab"); print_coeff_table(X10, "tab-quest1-X10.tab"); kill_M(&X1); kill_M(&X2); kill_M(&X3); kill_M(&X5); kill_M(&X10); libera(A); libera(B); EndProgram(); return(0); }
void ShutDownYepp(void){ EndProgram(); exit(1); }
int radium_main(char *arg){ struct Tracker_Windows *window; #if 0 // Seems to be some kind of problem when running givertcap? Try to uncomment and // see if you can start radium without segfaulting. I can't. -Kjetil. system("/usr/bin/givertcap"); #endif x11_display=XOpenDisplay(NULL); if(x11_display==NULL){ fprintf(stderr, "Unable to open display \"%s\"\n",XDisplayName(NULL)); return 1; } XSetIOErrorHandler (MySysErrorHandler); x11_screen=DefaultScreen(x11_display); printf("arg: -%s-\n",arg); printf("Width/Height: %d/%d\n",DisplayWidth(x11_display,x11_screen),DisplayHeight(x11_display,x11_screen)); X11_init_keyboard(); X11_StartBlockSelector(); X11_StartMidiProperties(); StartGuiThread(); posix_InitPlayer(); if(InitProgram()==true){ /* Here: More inits, receive events, other things. */ bool notend=true; printf("Inited\n"); XFlush(x11_display); // DrawUpTrackerWindow(root->song->tracker_windows); //XFlush(x11_display); window=root->song->tracker_windows; //GFX_StartFileRequester(); X11_StartQtStuff(); BS_UpdateBlockList(); BS_UpdatePlayList(); BS_SelectBlock(root->song->blocks); BS_SelectPlaylistPos(0); if(strlen(arg)>0) Load(arg); lockGUI(); while(notend==true){ int fd; fd_set fdset; XFlush(x11_display); fd=ConnectionNumber(x11_display); FD_ZERO(&fdset); FD_SET(fd,&fdset); unlockGUI(); while((fd=select(fd+1,&fdset,NULL,NULL,NULL)==-1)){ if(errno!=EINTR) break; } lockGUI(); while(XPending(x11_display)) { XEvent event; XNextEvent(x11_display, &event); //XNextEvent (x11_display, &event); window=root->song->tracker_windows; //P2MUpdateSongPosCallBack(); switch(event.type){ case KeyPress: if(X11_KeyPress((XKeyEvent *)&event,window)==1){ notend=false; } break; case KeyRelease: X11_KeyRelease((XKeyEvent *)&event,window); break; case ButtonPress: //printf("%d %d %d\n",((XButtonEvent *)&event)->x,((XButtonEvent *)&event)->y,((XButtonEvent *)&event)->button); switch(((XButtonEvent *)&event)->button){ case 1: tevent.ID=TR_LEFTMOUSEDOWN; break; case 2: tevent.ID=TR_MIDDLEMOUSEDOWN; break; case 3: tevent.ID=TR_RIGHTMOUSEDOWN; break; case 4: tevent.ID=TR_KEYBOARD; tevent.SubID=EVENT_UPARROW; break; case 5: tevent.ID=TR_KEYBOARD; tevent.SubID=EVENT_DOWNARROW; break; default: tevent.ID=TR_LEFTMOUSEDOWN; } tevent.x=((XButtonEvent *)&event)->x; tevent.y=((XButtonEvent *)&event)->y; EventReciever(&tevent,window); break; case ButtonRelease: //printf("%d %d %d\n",((XButtonEvent *)&event)->x,((XButtonEvent *)&event)->y,((XButtonEvent *)&event)->button); switch(((XButtonEvent *)&event)->button){ case 1: tevent.ID=TR_LEFTMOUSEUP; break; case 2: tevent.ID=TR_MIDDLEMOUSEUP; break; case 3: tevent.ID=TR_RIGHTMOUSEUP; break; default: tevent.ID=TR_LEFTMOUSEUP; } tevent.x=((XButtonEvent *)&event)->x; tevent.y=((XButtonEvent *)&event)->y; EventReciever(&tevent,window); break; case EnterNotify: case LeaveNotify: X11_ResetKeysUpDowns(); break; case MotionNotify: // printf("%d %d %d\n",((XMotionEvent *)&event)->x,((XMotionEvent *)&event)->y,((XMotionEvent *)&event)->state); tevent.ID=TR_MOUSEMOVE; tevent.x=((XButtonEvent *)&event)->x; tevent.y=((XButtonEvent *)&event)->y; EventReciever(&tevent,window); break; //case VisibilityNotify: // case ConfigureNotify: case ConfigureNotify: if( window->width!=((XConfigureEvent *)&event)->width || window->height!=((XConfigureEvent *)&event)->height ) { #if 0 fprintf(stderr,"Resized %d %d\n", ((XConfigureEvent *)&event)->width, ((XConfigureEvent *)&event)->height ); #endif XFreePixmap( x11_display, window->os_visual->pixmap ); XFreePixmap( x11_display, window->os_visual->cursorpixmap ); window->os_visual->pixmap=XCreatePixmap(x11_display, window->os_visual->window, ((XConfigureEvent *)&event)->width, ((XConfigureEvent *)&event)->height, (unsigned int)(DefaultDepth(x11_display,x11_screen)) ); XFillRectangle( x11_display, window->os_visual->pixmap, window->os_visual->gcs[0], 0, 0, ((XConfigureEvent *)&event)->width,((XConfigureEvent *)&event)->height ); window->os_visual->cursorpixmap=XCreatePixmap(x11_display, window->os_visual->window, ((XConfigureEvent *)&event)->width, ((XConfigureEvent *)&event)->height, (unsigned int)(DefaultDepth(x11_display,x11_screen)) ); XFillRectangle( x11_display, window->os_visual->cursorpixmap, window->os_visual->gcs[0], 0, 0, ((XConfigureEvent *)&event)->width, ((XConfigureEvent *)&event)->height ); Resize_resized( window, ((XConfigureEvent *)&event)->width-1, ((XConfigureEvent *)&event)->height-1, true ); } break; case Expose: printf("Expose\n"); //GFX_FilledBox(window,0,0,0,window->width,window->height); //DrawUpTrackerWindow(root->song->tracker_windows); Resize_resized(window,window->width,window->height,false); //XFlush(x11_display); break; case NoExpose: break; case GraphicsExpose: printf("GRaphicsExpose event.\n"); break; case ClientMessage: X11Event_ClientMessage((XClientMessageEvent *)&event,window); // printf("Received \"%s\"\n",((XClientMessageEvent *)&event)->data.b); break; default: printf("Unknown xevent %d\n",event.type); break; } } } EndProgram(); } posix_EndPlayer(); unlockGUI(); EndGuiThread(); XCloseDisplay(x11_display); return 0; }
static bool Load(const wchar_t *filename){ struct Root *newroot; dc.success=true; curr_disk_line = 0; dc.file=DISK_open_for_reading(filename); if(dc.file==NULL){ GFX_Message(NULL,"Could not open \"%s\" for loading\n",STRING_get_chars(filename)); return false; } DC_fgets(); if (dc.success==false) return false; if(strcmp("RADIUM SONG",dc.ls)){ GFX_Message(NULL,"First line in song was not 'RADIUM SONG', but '%s'. Last: %d\n",dc.ls,dc.ls[strlen(dc.ls)-1]); DISK_close_and_delete(dc.file); return false; } disk_load_version=DC_LoadF(); if (dc.success==false) return false; if(disk_load_version>0.4201 && disk_load_version<0.50){ disk_load_version=0.51; dc.colorize=true; dc.startcolor=5; }else{ dc.colorize=false; } #if 0 if (disk_load_version < 0.75){ GFX_Message(NULL, "<p>Note! The portamento behavior for polyphonic tracks changed in Radium V3.4.9" "</p>" "<p>" "Before Radium V3.4.9, the default final portamento value was the pitch value of the next note after the <i>start</i> of the note. " "Now, the default final portamento value is the pitch value of the next note after the <i>end</i> of the note." "</p>" "<p>" "Old songs with portamento in polyphonic tracks might not sound the same." "</p>" ); } #endif if(disk_load_version>DISKVERSION+0.0001){ GFX_Message(NULL,"Need a newer version of Radium to load this song. The song version is %f, while this program only supports %f.\n",disk_load_version,DISKVERSION); return false; }else{ printf("Song diskVersion: %f\n",disk_load_version); } dc.filename=filename; dc.playlist=NULL; DC_Next(); if (dc.success==false) return false; if(strcmp(dc.ls,"OSSTUFF")){ GFX_Message(NULL, "OSSTUFF not found, but: '%s'. File: '%s'\n",dc.ls,STRING_get_chars(filename)); DISK_close_and_delete(dc.file); EndProgram(); exit(4); } LoadOsStuff(); printf("dc.ls: -%s-\n",dc.ls); if(strcmp(dc.ls,"ROOT")){ GFX_Message(NULL, "ROOT not found. Found '%s' instead.\n", dc.ls); DISK_close_and_delete(dc.file); EndProgram(); exit(5); } newroot=LoadRoot(); DISK_close_and_delete(dc.file); if(!dc.success){ GFX_Message(NULL, "Loading failed.\n"); EndProgram(); exit(6); } ResetUndo(); #ifdef _AMIGA CloseHelpWindow(); CloseCPPWindowWindow(); CloseBlockSelectWindow(); #endif CloseAllTrackerWindows(); GL_lock();{ GL_pause_gl_thread_a_short_while(); }GL_unlock(); //GL_draw_lock();{ PLAYER_lock();{ //<-- Locks within locks are dangerous. But it doesn't matter since the player isn't playing now anyway. root=newroot; //BANG! }PLAYER_unlock(); //}GL_draw_unlock(); Undo_start_ignoring_undo_operations();{ DLoadRoot(newroot); }Undo_stop_ignoring_undo_operations(); GL_create_all(root->song->tracker_windows); if(COMMENT_show_after_loading()) COMMENTDIALOG_open(); #ifdef _AMIGA currpatch=-1; #endif ResetUndo(); return true; }