Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2D array to graphics

Status
Not open for further replies.

radzio

Technical User
Aug 10, 2011
7
Hi All,

Imagine I have a 2D array like, lets say 1024 x 512 in size, filled with real or integer numbers. I would like to write it as some graphical format, for example TIFF or something. As a result I would like to have something like attached (the legend can be omitted). It is a readout from a detector after some modifications inside the Fortran program. How this could be done? Thanks in advance:)

Best wishes,

Radek
 
Hi radzio

You can do this in the following way. You just have to put your values (from your array) in some way into the "red", "green" and "blue" variables. The program makes a simple PPM graphic file. With red=0 and green=blue=255 you get a light blue solid area.

Code:
      program matrix

      implicit none
      integer hxres,hyres,hy,hx
      integer red,green,blue
      character*256 str

      hxres = 1024		! horizontal resolution
      hyres =  512		! vertical resolution

      open(unit=20,file='matrix.ppm',status='unknown',form='binary') 

      write(20) 'P6',char(10)
      write(str,'(a)')    '# Created by Matrix.for'
      write(20) str(1:32),char(10)
      write(str,'(i4,1x,i4,a)') hxres,hyres,char(10)
      write(20) str(1:10)
      write(20) '255',char(10)

      do hy=1,hyres
         do hx=1,hxres
            red = 0       ! Put in some value for this color value
            green = 255	  ! Put in some value for this color value
            blue = 255	  ! Put in some value for this color value
            write(20) char(red),char(green),char(blue)
         enddo
      enddo

      close(unit=20)
      end
 
Hi gullipe,

Thank you:) I will try and see if it works:)

Radek
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top