Find the answer to your Linux question:
Results 1 to 4 of 4
Hi, I am facing problem in reading a binary file (Thermodynamic properties of water, created in 2001, I don't know how it is created) through gfortran compiler. The same is ...
  1. #1
    Just Joined!
    Join Date
    Sep 2009
    Posts
    4

    Question Problem to Read Binary File with gfortran

    Hi,
    I am facing problem in reading a binary file (Thermodynamic properties of water, created in 2001, I don't know how it is created) through gfortran compiler. The same is working fine in Windows with Intel Fortran Compiler. The typical code is mentioned below. The gfortran is opening the file, but exiting with the end of the file error. If anyone has similar experience, kindly share with me. Thank you-
    !!! Program begins here
    Program forbin

    implicit none
    integer u
    real*8 a(2000)
    integer n,nuse
    character*80 record(2)
    include 'stcom.h'
    integer i,ios,ntot
    u=10
    rewind u;
    open(Unit=u, IOSTAT=ios, FILE='tpfh20', STATUS='old',
    * FORM='binary')
    c--get thermodynamic properties file title, and information about the

    read (UNIT=u,end=10,err=20,iostat=ios) record(1)

    write(*,*), record(1)
    write(*,*), ios

    read (UNIT=u,end=10,err=20,iostat=ios) record(2)
    write(*,*), record(2)
    write(*,*), ios
    c
    c--get triple point and critical point data, minimum and maximum
    c--temperatures and pressures, table statistics, and table pointers
    c
    read (UNIT=u,end=10,err=20,iostat=ios) ttrip,ptrip,vtrip,tcrit,
    * pcrit,vcrit,
    * tmin,pmin,tmax,pmax,
    * nt,np,nst,nsp,
    * it3bp,it4bp,it5bp,nprpnt,it3p0
    c
    c--get number of words in steam tables
    c
    read (UNIT=u,end=10,err=20,iostat=ios) ntot
    c
    c--check number of words in steam tables against number of words
    c--available for steam tables storage
    c
    if (ntot .gt. nuse) go to 30
    nuse = ntot
    c
    c--get steam tables
    c
    read (u,end=10,err=20,iostat=ios) (a(i),i=1,ntot)
    go to 50
    c
    c--premature end of data encountered
    c
    10 write (*,1001)
    go to 40
    c
    c--error reading steam table data
    c
    20 write (*,1002) ios
    go to 40
    c
    c--insufficient space
    c
    30 write (*,1003)

    1001 format ('0***** end of data encountered reading thermodynamic ',
    * 'property file')
    1002 format ('0***** read error encountered reading thermodynamic ',
    * 'property file, iostat =',i4)
    1003 format ('0***** insufficient space furnished for thermodynamic ',
    * 'property file')
    c
    c
    50 write(*,*), 'Successful'
    40 write(*,*), 'Failure'
    nuse = -1

    close(u)
    end
    !!!Program ends here

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    Egads - been a zillion years since I did any Fortran programming (early 80's). However, it is possible that you have an integer size problem. Since you don't show the contents of 'stcom.h' where some of the variables you are reading are likely defined I cannot say for sure, though if your Linux is a 64bit version and the variables are long integers, then you might be hitting this problem since in a 64bit Linux these are probably 64bit variables, not 32bit ones.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Just Joined!
    Join Date
    Sep 2009
    Posts
    4

    Question

    Hi,
    Thank you for the reply. My program is running on 32 bit processors only. I guess it is not problem with the 32 bit Vs 64 bit as I did not attempt it on 64 bit processors.
    The project is mixed language (C++ and FOrtran). The c++ gets the data using old fortran code. In the example, I mentioned, it is only small part of the Fortran code opening an old binary file. The problem could be compatability of binary file with gfortran. The same binary file has been successfully opened with MS Visual Studio c++ and intel fortran compilers. My aim is to bring it on to Linux system. I could bring the whole project code compile, link, and run on linux with g++ and gfortran. But the problem is with opening the binary input file. I am not sure if I can get that old binary file in text format.
    Please clarify if you have experience with such problems. Thank you.


    The contents of the header file is mentioned below:

    Stcom.h
    *define win32dvf
    *define erf
    *define fourbyt
    *define hconden
    *define impnon
    *define in32
    *define newnrc
    *define ploc
    *define sphaccm
    *define unix
    *define noselap
    *define noextvol
    *define noextv20
    *define noextsys
    *define noextjun
    *define noextj20
    *define nonpa
    *define nomap
    *comdeck stcom
    integer lstcom
    cblh $if -def,in32,1
    *if -def,in32
    * parameter ( lstcom = 19 )
    *endif
    cblh $if def,in32,1
    *if def,in32
    parameter ( lstcom = 15 )
    *endif
    common /stcom/ ttrip,ptrip,vtrip,tcrit,pcrit,vcrit,tmin,pmin,
    & tmax,pmax,nt,np,nst,nsp,it3bp,it4bp,it5bp,nprpnt,i t3p0

    real*8 ttrip,ptrip,vtrip,tcrit,pcrit,vcrit,tmin,pmin,tmax ,pmax
    integer nt,np,nst,nsp,it3bp,it4bp,it5bp,nprpnt,it3p0

  4. #4
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    Instead of gfortran and gcc you might want to try g77 and gcc34 instead. gfortran is a Fortran 95 compiler whereas g77 is a Fortran 77 compiler which should be more compatible with old code like yours.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...