static void Draw_Pixel_Init(SDL_Surface *super, Sint16 x, Sint16 y, Uint32 color) { Draw_Init(); Draw_Pixel(super, x, y, color); }
void Surface::UpdatePixel( PIXDIFF &pixel ) { Uint32 color = (pixel.color.r << 24) | (pixel.color.g << 16) | (pixel.color.b << 8 ) | 0xff; Draw_Pixel( sdlSurface, pixel.x - source.x, pixel.y - source.y, color ); }
void Draw_AALine(SDL_Surface* screen, float x0, float y0, float x1, float y1, float thick, uint8_t r, uint8_t g, uint8_t b, uint8_t a){ float lower, upper; float delta; //Thickness less than screen diagonal delta = sqrtf(screen->w*screen->w + screen->h*screen->h) + 1.0f; if(thick > delta){ thick = delta; } //Cap ends off, X dimension lower = 0.0f - thick; upper = screen->w + thick; x0 = std::min(upper, std::max(lower, x0)); x1 = std::min(upper, std::max(lower, x1)); //Cap ends off, Y dimension lower = 0.0f - thick; upper = screen->h + thick; y0 = std::min(upper, std::max(lower, y0)); y1 = std::min(upper, std::max(lower, y1)); //Steeper than shallow? if(abs(y1-y0) > abs(x1-x0)){ //Re-order to go bottom to top if(y0 > y1){ std::swap(x0, x1); std::swap(y0, y1); } //Adjust thickness by slope factor thick = thick * sqrtf(float(x1-x0)*(x1-x0) + float(y1-y0)*(y1-y0)) / float(y1-y0); //Calculate lower/upper/delta wrt X delta = float(x1-x0) / float(y1-y0); lower = x0 - thick*0.5f; upper = x0 + thick*0.5f; //Loop over each scanline, draw for(int y=y0; y<=y1; y++){ int rl = int(lower); int ru = int(upper); float pl = 1.0f - (lower - rl); float pu = upper - ru; //Plot edge then interior pixels Draw_Pixel(screen, rl, y, r, g, b, a*pl); Draw_Pixel(screen, ru, y, r, g, b, a*pu); for(int x=rl+1; x<ru; x++){ Draw_Pixel(screen, x, y, r, g, b, a); } //Update bounds lower += delta; upper += delta; } //Draw caps if(x0 != x1){ float deltal, deltau; //Reset bounds lower = x1 - thick*0.5f; upper = x1 + thick*0.5f; //Choose which gets different delta if(x0 < x1){ deltal = delta; deltau = -1.0f / delta; } else{ deltal = -1.0f / delta; deltau = delta; } //Update bounds lower += deltal; upper += deltau; //Draw end cap for(int y=y1+1; lower<upper; y++){ int rl = int(lower); int ru = int(upper); float pl = 1.0f - (lower - rl); float pu = upper - ru; //Plot edge then interior pixels Draw_Pixel(screen, rl, y, r, g, b, a*pl); Draw_Pixel(screen, ru+1, y, r, g, b, a*pu); for(int x=rl+1; x<=ru; x++){ Draw_Pixel(screen, x, y, r, g, b, a); } //Update bounds lower += deltal; upper += deltau; } //Reset bounds lower = x0 - thick*0.5f; upper = x0 + thick*0.5f; //Update bounds std::swap(deltal, deltau); lower -= deltal; upper -= deltau; //Draw start cap for(int y=y0-1; lower<upper; y--){ int rl = int(lower); int ru = int(upper); float pl = 1.0f - (lower - rl); float pu = upper - ru; //Plot edge then interior pixels Draw_Pixel(screen, rl, y, r, g, b, a*pl); Draw_Pixel(screen, ru+1, y, r, g, b, a*pu); for(int x=rl+1; x<=ru; x++){ Draw_Pixel(screen, x, y, r, g, b, a); } //Update bounds lower -= deltal; upper -= deltau; } } return; } //Must have been more shallow //Reorder left to right if(x0 > x1){ std::swap(x0, x1); std::swap(y0, y1); } //Adjust thickness by slope factor thick = thick * sqrtf(float(x1-x0)*(x1-x0) + float(y1-y0)*(y1-y0)) / float(x1-x0); //Calculate lower/upper/delta wrt Y delta = float(y1-y0) / float(x1-x0); lower = y0 - thick*0.5f; upper = y0 + thick*0.5f; //Loop over each scanline, draw for(int x=x0; x<=x1; x++){ int rl = int(lower); int ru = int(upper); float pl = 1.0f - (lower - rl); float pu = upper - ru; //Plot edge pixels Draw_Pixel(screen, x, rl, r, g, b, a*pl); Draw_Pixel(screen, x, ru+1, r, g, b, a*pu); for(int y=rl+1; y<=ru; y++){ Draw_Pixel(screen, x, y, r, g, b, a); } //Update bounds lower += delta; upper += delta; } //Draw caps if(y0 != y1){ float deltal, deltau; //Reset bounds lower = y1 - thick*0.5f; upper = y1 + thick*0.5f; //Choose which gets different delta if(y0 < y1){ deltal = delta; deltau = -1.0f / delta; } else{ deltal = -1.0f / delta; deltau = delta; } //Update bounds lower += deltal; upper += deltau; //Draw end cap for(int x=x1+1; lower<upper; x++){ int rl = int(lower); int ru = int(upper); float pl = 1.0f - (lower - rl); float pu = upper - ru; //Plot edge then interior pixels Draw_Pixel(screen, x, rl, r, g, b, a*pl); Draw_Pixel(screen, x, ru+1, r, g, b, a*pu); for(int y=rl+1; y<=ru; y++){ Draw_Pixel(screen, x, y, r, g, b, a); } //Update bounds lower += deltal; upper += deltau; } //Reset bounds lower = y0 - thick*0.5f; upper = y0 + thick*0.5f; //Update bounds std::swap(deltal, deltau); lower -= deltal; upper -= deltau; //Draw start cap for(int x=x0-1; lower<upper; x--){ int rl = int(lower); int ru = int(upper); float pl = 1.0f - (lower - rl); float pu = upper - ru; //Plot edge then interior pixels Draw_Pixel(screen, x, rl, r, g, b, a*pl); Draw_Pixel(screen, x, ru+1, r, g, b, a*pu); for(int y=rl+1; y<=ru; y++){ Draw_Pixel(screen, x, y, r, g, b, a); } //Update bounds lower -= deltal; upper -= deltau; } } return; }
/*----------------------------------------------------------------------*/ int main(int argc, char *argv[]) { SDL_Surface *screen; int width, height; Uint8 video_bpp; Uint32 videoflags; int done; SDL_Event event; Uint32 then, now, frames; if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "SDL_Init problem: %s", SDL_GetError()); exit(1); } atexit(SDL_Quit); videoflags = SDL_SWSURFACE | SDL_ANYFORMAT; width = 640; height = 480; video_bpp = 0; while ( argc > 1 ) { --argc; if ( strcmp(argv[argc-1], "-width") == 0 ) { width = atoi(argv[argc]); --argc; } else if ( strcmp(argv[argc-1], "-height") == 0 ) { height = atoi(argv[argc]); --argc; } else if ( strcmp(argv[argc-1], "-bpp") == 0 ) { video_bpp = atoi(argv[argc]); videoflags &= ~SDL_ANYFORMAT; --argc; } else if ( strcmp(argv[argc], "-fast") == 0 ) { videoflags = FastestFlags(videoflags, width, height, video_bpp); } else if ( strcmp(argv[argc], "-hw") == 0 ) { videoflags ^= SDL_HWSURFACE; } else if ( strcmp(argv[argc], "-flip") == 0 ) { videoflags ^= SDL_DOUBLEBUF; } else if ( strcmp(argv[argc], "-fullscreen") == 0 ) { videoflags ^= SDL_FULLSCREEN; } else { fprintf(stderr, "Use: %s [-bpp N] [-hw] [-flip] [-fast] [-fullscreen]\n", argv[0]); exit(1); } }/*while*/ /*Video mode activation*/ screen = SDL_SetVideoMode(width, height, video_bpp, videoflags); if (!screen) { fprintf(stderr, "I can not activate video mode: %dx%d: %s\n", width, height, SDL_GetError()); exit(2); } {/*BEGIN*/ Uint32 c_white = SDL_MapRGB(screen->format, 255,255,255); Uint32 c_gray = SDL_MapRGB(screen->format, 200,200,200); Uint32 c_dgray= SDL_MapRGB(screen->format, 64,64,64); Uint32 c_cyan = SDL_MapRGB(screen->format, 32,255,255); //SDL_Rect r = {100,300,50,50}; //SDL_SetClipRect(screen, &r); //Test of clipping code frames = 0; then = SDL_GetTicks(); done = 0; while( !done ) { Draw_Line(screen, 100,100, 30,0, c_white); Draw_Line(screen, 30,0, 100,100, c_white); Draw_Line(screen, 100,100, 30,0, c_white); Draw_Line(screen, 30,0, 100,100, c_white); Draw_Line(screen, 0,0, 100,100, c_white); Draw_Line(screen, 100,100, 300,200, c_white); Draw_Line(screen, 200,300, 250,400, SDL_MapRGB(screen->format, 128,128,255)); Draw_Line(screen, 500,50, 600,70, SDL_MapRGB(screen->format, 128,255,128)); Draw_Line(screen, 500,50, 600,70, SDL_MapRGB(screen->format, 128,255,128)); //Draw_Circle(screen, 100+frames%200, 100, 50, c_white); Draw_Circle(screen, 100+(frames/3)%200, 100+(frames/2)%173, 50, SDL_MapRGB(screen->format, 128+frames,255+frames,68+frames)); /*-------------*/ Draw_Circle(screen, 150,150, 5, c_white); Draw_Circle(screen, 150,150, 4, SDL_MapRGB(screen->format, 64,64,64)); Draw_Circle(screen, 150,150, 3, SDL_MapRGB(screen->format, 255,0,0)); Draw_Circle(screen, 150,150, 2, SDL_MapRGB(screen->format, 0,255,0)); Draw_Circle(screen, 150,150, 1, SDL_MapRGB(screen->format, 0,0,255)); /*-------------*/ Draw_Line(screen, 500,100, 600,120, SDL_MapRGB(screen->format, 128,255,128)); Draw_Circle(screen, 601,121, 2, c_white); Draw_Circle(screen, 400,200, 2, c_white); Draw_Line(screen, 400,200, 409,200, c_white); Draw_Circle(screen, 409,200, 2, c_white); Draw_Line(screen, 400,200, 400,250, c_white); Draw_Circle(screen, 400,250, 2, c_white); Draw_Line(screen, 409,200, 400,250, c_white); Draw_Line(screen, 400,300, 409,300, c_gray); Draw_Line(screen, 400,300, 400,350, c_gray); Draw_Line(screen, 409,300, 400,350, c_dgray); Draw_Rect(screen, 398,298, 4,4, c_cyan); Draw_Rect(screen, 407,298, 4,4, c_cyan); Draw_Rect(screen, 398,348, 4,4, c_cyan); Draw_HLine(screen, 10,400, 50, c_white); Draw_VLine(screen, 60,400, 360, c_white); Draw_Rect(screen, 500,400, 50,50, c_white); Draw_Pixel(screen, 510,410, c_white); Draw_Pixel(screen, 520,420, SDL_MapRGB(screen->format, 255,0,0)); Draw_Pixel(screen, 530,430, SDL_MapRGB(screen->format, 0,255,0)); Draw_Pixel(screen, 540,440, SDL_MapRGB(screen->format, 0,0,255)); Draw_Ellipse(screen, 100,300, 60,30, c_white); Draw_FillEllipse(screen, 300,300, 30,60, SDL_MapRGB(screen->format, 64,64,200)); Draw_Ellipse(screen, 300,300, 30,60, SDL_MapRGB(screen->format, 255,0,0)); Draw_Round(screen, 200,20, 70,50, 10, c_white); Draw_Round(screen, 300,20, 70,50, 20, SDL_MapRGB(screen->format, 255,0,0)); Draw_FillRound(screen, 390,20, 70,50, 20, SDL_MapRGB(screen->format, 255,0,0)); Draw_Round(screen, 390,20, 70,50, 20, c_cyan); /*Draw_Round(screen, 500,400, 5,3, 4, c_cyan);*/ Draw_Rect(screen, 499,199, 52,72, SDL_MapRGB(screen->format, 255,255,0)); //Draw_FillRect(screen, 500,200, 50,70, // SDL_MapRGB(screen->format, 64,200,64)); Draw_FillCircle(screen, 500,330, 30, c_cyan); SDL_UpdateRect(screen, 0, 0, 0, 0); ++frames; while ( SDL_PollEvent(&event) ) { switch (event.type) { case SDL_KEYDOWN: /*break;*/ case SDL_QUIT: done = 1; break; default: break; } }/*while*/ }/*while(!done)*/ }/*END*/ now = SDL_GetTicks(); if ( now > then ) { printf("%2.2f frames per second\n", ((double)frames*1000)/(now-then)); } fprintf(stderr, "[END]\n"); return 0; }/*main*/
int Game_Main(void *parms, int num_parms) { // this is the workhorse of your game it will be called // continuously in real-time this is like main() in C // all the calls for you game go here! int index; // looping var // check of user is trying to exit if (KEY_DOWN(VK_ESCAPE) || KEY_DOWN(VK_SPACE)) PostMessage(main_window_handle, WM_DESTROY,0,0); // start the timing clock Start_Clock(); // clear the drawing surface DDraw_Fill_Surface(lpddsback, 0); // get the input from the mouse lpdimouse->GetDeviceState(sizeof(DIMOUSESTATE), (LPVOID)&mouse_state); // move the mouse cursor mouse_x+=(mouse_state.lX); mouse_y+=(mouse_state.lY); // test bounds // first x boundaries if (mouse_x >= screen_width) mouse_x = screen_width-1; else if (mouse_x < 0) mouse_x = 0; // now the y boundaries if (mouse_y >= screen_height) mouse_y= screen_height-1; else if (mouse_y < 0) mouse_y = 0; // position the pointer bob to the mouse coords pointer.x = mouse_x - 16; pointer.y = mouse_y - 16; // test what the user is doing with the mouse if ((mouse_x > 3) && (mouse_x < 500-3) && (mouse_y > 3) && (mouse_y < SCREEN_HEIGHT-3)) { // mouse is within canvas region // if left button is down then draw if (mouse_state.rgbButtons[0]) { // test drawing mode if (buttons_state[BUTTON_PENCIL]) { // draw a pixel Draw_Pixel(mouse_x, mouse_y, mouse_color, canvas.buffer, canvas.width); Draw_Pixel(mouse_x+1, mouse_y, mouse_color, canvas.buffer, canvas.width); Draw_Pixel(mouse_x, mouse_y+1, mouse_color, canvas.buffer, canvas.width); Draw_Pixel(mouse_x+1, mouse_y+1, mouse_color, canvas.buffer, canvas.width); } else { // draw spray for (index=0; index<10; index++) { // get next particle int sx=mouse_x-8+rand()%16; int sy=mouse_y-8+rand()%16; // make sure particle is in bounds if (sx > 0 && sx < 500 && sy > 0 && sy < screen_height) Draw_Pixel(sx, sy, mouse_color, canvas.buffer, canvas.width); } // end for index } // end else } // end if left button else // right button is eraser if (mouse_state.rgbButtons[1]) { // test drawing mode if (buttons_state[BUTTON_PENCIL]) { // erase a pixel Draw_Pixel(mouse_x, mouse_y, 0, canvas.buffer, canvas.width); Draw_Pixel(mouse_x+1, mouse_y, 0, canvas.buffer, canvas.width); Draw_Pixel(mouse_x, mouse_y+1, 0, canvas.buffer, canvas.width); Draw_Pixel(mouse_x+1, mouse_y+1, 0, canvas.buffer, canvas.width); } // end if else { // erase spray for (index=0; index<20; index++) { // get next particle int sx=mouse_x-8+rand()%16; int sy=mouse_y-8+rand()%16; // make sure particle is in bounds if (sx > 0 && sx < 500 && sy > 0 && sy < screen_height) Draw_Pixel(sx, sy, 0, canvas.buffer, canvas.width); } // end for index } // end else } // end if left button } // end if else if ( (mouse_x > 500+16) && (mouse_x < 500+16+8*9) && (mouse_y > 8) && (mouse_y < 8+32*9)) { // within palette // test if button left button is down if (mouse_state.rgbButtons[0]) { // see what color cell user is pointing to int cell_x = (mouse_x - (500+16))/9; int cell_y = (mouse_y - (8))/9; // change color mouse_color = cell_x + cell_y*8; } // end if } // end if else if ((mouse_x > 500) && (mouse_x < (500+100)) && (mouse_y > 344) && (mouse_y < (383+34)) ) { // within button area // test for each button for (index=0; index<4; index++) { if ((mouse_x > buttons_x[index]) && (mouse_x < (buttons_x[index]+32)) && (mouse_y > buttons_y[index]) && (mouse_y < (buttons_y[index]+34)) ) break; } // end for // at this point we know where the user is, now determine what he // is doing with the buttons switch(index) { case BUTTON_SPRAY: { // if left button is down simply activate spray mode if (mouse_state.rgbButtons[0]) { // depress button buttons_state[index] = 1; // de-activate pencil mode buttons_state[BUTTON_PENCIL] = 0; } // end if else { // make sure button is up // buttons_state[index] = 0; } // end else } break; case BUTTON_PENCIL: { // if left button is down activate spray mode if (mouse_state.rgbButtons[0]) { // depress button buttons_state[index] = 1; // de-activate spray mode buttons_state[BUTTON_SPRAY] = 0; } // end if else { // make sure button is up // buttons_state[index] = 0; } // end else } break; case BUTTON_ERASE: { // test if left button is down, if so clear screen if (mouse_state.rgbButtons[0]) { // clear memory memset(canvas.buffer,0,canvas.width*canvas.height); // depress button buttons_state[index] = 1; } // end if else { // make sure button is up buttons_state[index] = 0; } // end else } break; case BUTTON_EXIT: { // test if left button down, if so bail if (mouse_state.rgbButtons[0]) PostMessage(main_window_handle, WM_DESTROY,0,0); } break; } // end switch } // end if else { // no mans land } // end else // lock back buffer DDraw_Lock_Back_Surface(); // draw the canvas Draw_Bitmap(&canvas, back_buffer, back_lpitch,0); // draw control panel Draw_Bitmap(&cpanel,back_buffer,back_lpitch,0); // unlock back buffer DDraw_Unlock_Back_Surface(); // draw the color palette for (int col=0; col < 256; col++) { Draw_Rectangle(500+16+(col%8)*9, 8+(col/8)*9, 500+16+(col%8)*9+8, 8+(col/8)*9+8, col,lpddsback); } // end for col // draw the current color selected Draw_Rectangle(533,306,533+34,306+34,mouse_color,lpddsback); // draw the buttons for (index=0; index<4; index++) { // set position of button bob buttons.x = buttons_x[index]; buttons.y = buttons_y[index]; // now select the on/off frame based on if the // button is off if (buttons_state[index]==0) buttons.curr_frame = index; else // button is on buttons.curr_frame = index+4; // draw the button Draw_BOB(&buttons, lpddsback); } // end for index static int green = 0; // display coords sprintf(buffer,"Pointer (%d,%d)",mouse_x,mouse_y); Draw_Text_GDI(buffer, 8,screen_height - 16,RGB(0,255,0),lpddsback); Draw_Text_GDI("T3D Paint Version 2.0 - Press <ESC> to Exit.",0,0,RGB(0,(green & 255),0),lpddsback); // a little animation ++green; // draw the cursor last Draw_BOB(&pointer,lpddsback); // flip the surfaces DDraw_Flip(); // sync to 30 fps Wait_Clock(30); // return success return(1); } // end Game_Main
/* Main program */ int main(){ /* not Locals */ lapack_complex_double *a, *temp, * u, *vt; lapack_int m = M, n = N, lda = LDA, ldu = LDU, ldvt = LDVT, info; /* Local arrays */ //void prtdat(); double *s; double *superb; int svd_count=0; int i, j ,ix ,iy, index, ii, jj ; double x_min, x_max, y_min, y_max, stepx, /* step size for finding gridpoints coordinates in x and y dimension.*/ stepy; double e=0.1; /* Array used for the ploting of * grid, as an input to the * draw_pseudospectra function. */ double *plot; //double plot[n][n]; COLOUR colour; BITMAP4 col,grey = {128,128,128,0}; /* Memory alocations*/ temp = malloc((lda*m)*sizeof(lapack_complex_double)); a = malloc((lda*m)*sizeof(lapack_complex_double)); u = malloc((ldu*m)*sizeof(lapack_complex_double)); vt = malloc((ldvt*n)*sizeof(lapack_complex_double)); s = malloc(m*sizeof(double)); superb = malloc(min(m,n)*sizeof(double)); plot = malloc((NGRID*NGRID)*sizeof(double)); z = malloc((NGRID*NGRID)*sizeof(double _Complex)); //allocating the 2D array data. if ((data = malloc(SCALE*NGRID*sizeof(double *))) == NULL) { fprintf(stderr,"Failed to malloc space for the data\n"); exit(-1); } for (i=0;i<SCALE*NGRID;i++) { if ((data[i] = malloc(SCALE*NGRID*sizeof(double))) == NULL) { fprintf(stderr,"Failed to malloc space for the data\n"); exit(-1); } } for (i=0;i<SCALE*NGRID;i++){ for (j=0;j<SCALE*NGRID;j++){ data[i][j] = 0; // printf("%f\t",data[i][j]); } } /* printf("-------------------------------------------------\n"); printf(" --------------------------------- \n"); printf ("Starting Computing Pseudopsecta of grcar Matrix\n"); printf("Give the doundaries of the 2-dimenional domain\n"); printf("Insert the minimum value of x-axis\n"); clearerr(stdin); scanf("%lf",&x_min); //getchar(); printf("Insert the maximum value of x-axis\n"); scanf("%lf",&x_max); printf("Insert the minimum value of y-axis\n"); scanf("%lf",&y_min); printf("Insert the maximun value of y-axis\n"); scanf("%lf",&y_max); //printf("Give the grid size you want:\n"); //scanf("%d",&n); */ /*if (x_min==0.0)*/ x_min=XMIN; /*if (x_max==0.0)*/ x_max=XMAX; /*if (y_min==0.0)*/ y_min=YMIN; /*if (y_max==0.0)*/ y_max=YMAX; /* Initialize grid */ printf("The size of the domain is: X=[%f-%f] Y=[%f-%f] \n",x_min,x_max,y_min,y_max); stepx=(double)abs(x_max-x_min)/(NGRID-1); stepy=(double)abs(y_max-y_min)/(NGRID-1); printf("To stepx einai %f\n",stepx); printf("To stepy einai %f\n",stepy); for (i =0; i <NGRID*NGRID; i++){ z[i]=x_min+(i/n * stepx)+(y_min + (i%n * stepy))*I; // z[i]=lapack_make_complex_double( i/n,i%n); just for testing //** printf( " (%6.2f,%6.2f)", lapack_complex_double_real(z[i]), lapack_complex_double_imag(z[i]) ); } memset(temp,0,(lda*m)*sizeof(*temp)); memset(a,0,(lda*m)*sizeof(*a)); memset(u,0,(ldu*m)*sizeof(*u)); memset(vt,0,(ldvt*m)*sizeof(*vt)); j=0; for (i = 0; i < lda*m ; i=i+n ){ if(i==0){ a[i]=lapack_make_complex_double( 1,0); a[i+1]=lapack_make_complex_double( 1,0); a[i+2]=lapack_make_complex_double( 1,0); a[i+3]=lapack_make_complex_double( 1,0); } else if(i == (n-3)*n ){ a[i+j]=lapack_make_complex_double( -1,0); a[i+(j+1)]=lapack_make_complex_double( 1,0); a[i+(j+2)]=lapack_make_complex_double( 1,0); a[i+(j+3)]=lapack_make_complex_double( 1,0); j++; } else if(i == (n-2)*n ){ a[i+j]=lapack_make_complex_double( -1,0); a[i+(j+1)]=lapack_make_complex_double( 1,0); a[i+(j+2)]=lapack_make_complex_double( 1,0); j++; } else if(i == (n-1)*n ){ a[i+j]=lapack_make_complex_double( -1,0); a[i+(j+1)]=lapack_make_complex_double( 1,0); j++; } else{ a[i+j]=lapack_make_complex_double( -1,0); a[i+(j+1)]=lapack_make_complex_double( 1,0); a[i+(j+2)]=lapack_make_complex_double( 1,0); a[i+(j+3)]=lapack_make_complex_double( 1,0); a[i+(j+4)]=lapack_make_complex_double( 1,0); j++; } } //print_matrix("Entry Matrix A", m, n, a, lda ); for (iy = 0; iy < NGRID*NGRID; iy++){ //printf("temp size %d, a size %d",(lda*m)*sizeof(*temp),(lda*m)*sizeof(*a)); memcpy(temp, a ,(lda*m)*sizeof(*temp)); //~ print_matrix( "Entry Matrix Temp just after memcopy", m, n, temp, lda ); //~ print_matrix( "Entry Matrix A just after memcopy", m, n, a, lda ); // printf( "To z[%d](%6.4f,%6.4f)\n",iy,lapack_complex_double_real(z[iy]),lapack_complex_double_imag(z[iy]) ); for (i = 0; i < lda*m ; i=i+(n+1)){ //~ printf("%d",i); //~ printf( "To a[%d](%6.2f,%6.2f)\t",i, lapack_complex_double_real(a[i]), lapack_complex_double_imag(a[i]) ); //~ printf( "To z[%d](%6.2f,%6.2f)\n",iy,lapack_complex_double_real(z[iy]),lapack_complex_double_imag(z[iy]) ); temp[i]=a[i]-z[iy]; //~ temp[index] = lapack_make_complex_double(lapack_complex_double_real(a[index])-lapack_complex_double_real(z[iy]), lapack_complex_double_imag(a[index])-lapack_complex_double_imag(z[iy]) ); //~ printf( " temp[%d](%6.2f,%6.2f)", i,lapack_complex_double_real(temp[i]), lapack_complex_double_imag(temp[i]) ); //~ printf( "\n"); } //printf("GRCAR MATRIX AFTER SUBSTRACTION (%d,%d)\n",iy/n,iy%n); //~ print_matrix( "Entry Matrix Temp just before", m, n, temp, lda ); /* Executable statements */ //~ print_matrix( "AT THE BEGINING OF THE FOR LOOP", m, n, a, lda ); printf( "LAPACKE_zgesvd (row-major, high-level) Example Program Results(%d,%d)\n",iy/NGRID,iy%NGRID); /* Compute SVD */ info = LAPACKE_zgesvd( LAPACK_ROW_MAJOR, 'N', 'N', m, n, temp, lda, s, NULL, ldu, NULL, ldvt, superb ); svd_count++; //~ //~ print_matrix( "IN THE MIDDLE OF THE FOR LOOP", m, n, a, lda ); //~ print_matrix( "IN THE MIDDLE OF THE FOR LOOP-TEMP", m, n, temp, lda ); /* Check for convergence */ if( info > 0 ) { printf( "The algorithm computing SVD failed to converge.\n" ); exit( 1 ); } /* Print singular values */ if( info == 0){ // printf("Solution\n"); for ( i= 0; i< m; i++ ) { // printf(" s[ %d ] = %f\n", i, s[ i ] ); } } if(s[m-1] <= e){ printf("THIS ELEMENT BELONGS TO PSEUDOSPECTRA (%d,%d):%6.10f\n",(iy/NGRID+1),(iy%NGRID+1),s[m-1]); /*to index tis parapanw ektupwshs anaferetai sto index tou antistoixou mhtrwou apo thn synarthsh ths matlab grcar_example.m*/ //~ plot[iy/n][iy%n]=s[m-1]; plot[iy]=s[m-1]; } //~ else plot[iy/n][iy%n]=0; else plot[iy]=0; //~ print_rmatrix( "Singular values", 1, m, s, 1 ); /* Print left singular vectors */ // print_matrix( "Left singular vectors (stored columnwise)", m, m, u, ldu ); /* Print right singular vectors */ // print_matrix( "Right singular vectors (stored rowwise)", m, n, vt, ldvt ); } prtdat(NGRID, NGRID, plot, "svd.data"); printf("Total number of svd evaluations in the %d,%d grid is:\t %d\n",NGRID,NGRID,svd_count); //giving values to data from plot for (i = 0; i<NGRID*NGRID; i++) data[SCALE*(i/NGRID)][SCALE*(i%NGRID)] = plot[i]; ///////////////// BITMAP4 black = {0,0,0,0}; Draw_Line(image,NGRID,NGRID,x_min,y_min,x_max,y_min,black); ////////////////// //~ contours[0] = 0.1; //~ contours[1] = 0.01; //~ contours[2] = 0.001; //~ contours[3] = 0.0001; //~ contours[4] = 0.00001; if ((image = Create_Bitmap(SCALE*NGRID,SCALE*NGRID)) == NULL) { fprintf(stderr,"Malloc of bitmap failed\n"); exit(-1); } Erase_Bitmap(image,SCALE*NGRID,SCALE*NGRID,grey); /* Not strictly necessary */ for (j=0;j<SCALE*NGRID;j++) { for (i=0;i<SCALE*NGRID;i++) { colour = GetColour(data[i][j],0,0.1,1); ///////////////////////////////////////////// col.r = colour.r * 255; // col.b = colour.b * 255; // Draw_Pixel(image,SCALE*NGRID,SCALE*NGRID,(double)i,(double)j,col); // colour = GetColour(data[i][j],0,0.0001,1); ///////////////////////////////////////////// // col.g = colour.g * 255; Draw_Pixel(image,SCALE*NGRID,SCALE*NGRID,(double)i,(double)j,col); } } /* Finally do the contouring */ CONREC(data,0,SCALE*NGRID-1,0,SCALE*NGRID-1, z,NCONTOUR,contours,drawline); fprintf(stderr,"Drew %d vectors\n",vectorsdrawn); /* Write the image as a TGA file See bitmaplib.c for more details, or write "image" in your own prefered format. */ if ((fp = fopen("image.tga","w")) == NULL) { fprintf(stderr,"Failed to open output image\n"); exit(-1); } Write_Bitmap(fp,image,SCALE*NGRID,SCALE*NGRID,12); fclose(fp); exit(0); } /* End of LAPACKE_zgesvd Example */