Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Fortran - Read unformatted > Write formatted

  1. Oct 15, 2009 #1

    minger

    User Avatar
    Science Advisor

    I guess this is really a bug check. I'm having problems converting an unformatted CFD file to a formatted file so that I can manipulate the data, etc, etc. Below is what I'm doing, if anyone sees anything that jumps out I would REALLY appreciate it.
    Code (Text):
    PROGRAM unformattedConverter

    IMPLICIT NONE

    INTEGER :: i,j,k,n,m,nBlocks,type
    INTEGER,DIMENSION(:),ALLOCATABLE :: ni,nj,nk

    REAL :: mach,alpha,reyn,time
    REAL,DIMENSION(:,:,:,:),ALLOCATABLE   :: x,y,z
    REAL,DIMENSION(:,:,:,:,:),ALLOCATABLE :: q

    CHARACTER(len=24) :: filename

    WRITE(6,*) 'Enter the unformatted file to convert'
    READ*, filename

    WRITE(6,*) 'Enter 0 for grid file, or 1 for flow file'
    READ*, type


    OPEN(11,file=filename,form='unformatted')
    READ(11) nBlocks
    ALLOCATE( ni(nBlocks),nj(nBlocks),nk(nBlocks) )
    READ(11) (ni(n),nj(n),nk(n),n=1,nBlocks)

    IF (type .EQ. 0) THEN

      ALLOCATE( x(MAXVAL(ni),MAXVAL(nj),MAXVAL(nk),nBlocks),&
                y(MAXVAL(ni),MAXVAL(nj),MAXVAL(nk),nBlocks),&
                z(MAXVAL(ni),MAXVAL(nj),MAXVAL(nk),nBlocks) )
      DO n=1,nBlocks
        READ(11) (((x(i,j,k,n),i=1,ni(n)),j=1,nj(n)),k=1,nk(n)),&
                 (((y(i,j,k,n),i=1,ni(n)),j=1,nj(n)),k=1,nk(n)),&
                 (((z(i,j,k,n),i=1,ni(n)),j=1,nj(n)),k=1,nk(n))
      END DO

      OPEN(13,file='gridOutput.fast',form='formatted')
      WRITE(13,*) nBlocks
      WRITE(13,*) (ni(n),nj(n),nk(n),n=1,nBlocks)
      DO n=1,nBlocks
        WRITE(13,*) (((x(i,j,k,n),i=1,ni(n)),j=1,nj(n)),k=1,nk(n)),&
                    (((y(i,j,k,n),i=1,ni(n)),j=1,nj(n)),k=1,nk(n)),&
                    (((z(i,j,k,n),i=1,ni(n)),j=1,nj(n)),k=1,nk(n))
      END DO
      CLOSE(13)
      DEALLOCATE( x,y,z )

    ELSEIF (type .EQ. 1) THEN

      ALLOCATE( q(MAXVAL(ni),MAXVAL(nj),MAXVAL(nk),nBlocks,5) )
      DO n=1,nBlocks
        READ(11) mach,alpha,reyn,time
        READ(11) ((((q(i,j,k,n,m),i=1,ni(n)),j=1,nj(n)),k=1,nk(n)),m=1,5)
      END DO

      OPEN(14,file='flowOutput.fast',form='formatted')
      WRITE(14,*) nBlocks
      WRITE(14,*) (ni(n),nj(n),nk(n),n=1,nBlocks)
      DO n=1,nBlocks
        WRITE(14,*) mach,alpha,reyn,time
        WRITE(14,*) ((((q(i,j,k,n,m),i=1,ni(n)),j=1,nj(n)),k=1,nk(n)),m=1,5)
      END DO
      CLOSE(14)
      DEALLOCATE( q )

    END IF

    DEALLOCATE( ni,nj,nk )

    END PROGRAM
     
    In the output, it doesn't seems like its correctly reading nj, nk, or q (when I choose to read it).
     
  2. jcsd
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted



Similar Discussions: Fortran - Read unformatted > Write formatted
Loading...