program imagereader implicit none integer, parameter :: maxsize=1000 integer, parameter :: maxchar=80 integer, parameter :: angle = 30 integer, parameter :: PI = 3.14159 real :: radians integer, dimension(maxsize,maxsize) :: image1 integer, dimension(maxsize,maxsize) :: image2 integer, dimension(100000) :: pixarray, newpixarray character(maxchar) :: line ! this is a string, with "dimension" ! it's a char array integer :: rows, cols integer :: row, col, newrow,newcol integer :: centerrow, centercol integer :: maxpixel integer :: totalpix, totallines ! this version: pixperline=1 ! save as pgm with gimp, ! automatically has one pixel per line integer :: linenum,i, start integer time_array_0(8), time_array_1(8) real start_time, finish_time open(10, file='tripod.pgm') open(20, file='rotatetest3.pgm') read(10,*) line ! format line read(10,*) line ! comment line read(10,*) cols, rows read(10,*) maxpixel write(*,*) 'Rows=', rows, "Cols=", cols, "Max pixel value=", maxpixel totallines = rows*cols write(*,*) "Totallines=", totallines do row=1,rows do col=1,cols read(10,*) image1(row,col) end do end do radians = (angle*PI)/180.0 centerrow = rows / 2 centercol = cols / 2 write(*,*) 'Starting image processing...' call date_and_time(values=time_array_0) start_time = time_array_0 (5) * 3600 + time_array_0 (6) * 60 & + time_array_0 (7) + 0.001 * time_array_0 (8) write (6, '(8x, 1a, 1f16.6)') 'begin (date_and_time): ', & start_time do row=1,rows do col=1,cols newrow = nint((row-centerrow)*cos(radians) - (col-centercol)*sin(radians)) newcol = nint((row-centerrow)*sin(radians) + (col-centercol)*cos(radians)) newrow = newrow + centerrow newcol = newcol + centercol if (newrow >= 1 .and. newrow <= rows .and. newcol >= 1 & .and. newcol <= cols) then image2(newrow,newcol)= image1(row,col) end if end do end do call date_and_time(values=time_array_1) finish_time = time_array_1 (5) * 3600 + time_array_1 (6) * 60 & + time_array_1 (7) + 0.001 * time_array_1 (8) write(*,*) 'End image processing' write (6, '(8x, 1a, 1f16.6)') 'end (date_and_time): ', & finish_time write(*,*) 'Total time=', finish_time - start_time write(20,*) "P2" write(20,*) "# Test file" write(20,*) cols,rows write(20,*) maxpixel do row = 1, rows do col = 1, cols write(20,*) image2(row,col) end do end do close(20) end program