ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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
I gather the source is a text file transferred from Windows. Have you converted the line endings yet?
Code:
$ dos2unix (filename)
And if it is reading a data file that is (1) a text file and (2) has been transferred from Windows, convert that file also, in the same way.
If the data file is binary, I hope it wasn't transferred from Windows to Linux in any way other than as a binary file (Windows distinguishes between text and binary). If it was transferred in one of several ways that treat it as text, this may have corrupted it. A way to verify the correctness of the data file is to get an MD5 checksum on the Windows platform for this file, and compare that with a Linux md5sum result.
If the checksums don't agree, transfer the file again, this time more carefully.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.