LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-12-2009, 02:00 AM   #1
kdurgarao
LQ Newbie
 
Registered: Oct 2009
Posts: 1

Rep: Reputation: 0
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
 
Old 10-12-2009, 02:26 AM   #2
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 102Reputation: 102
Quote:
Originally Posted by kdurgarao View Post
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
C, howto read binary file into buffer Scrag Programming 24 11-27-2014 05:32 PM
C++ Cross Platform Compatible Binary File Open Read Problem MatrixNAN Programming 6 09-18-2009 02:37 AM
Java read binary file in as string for RegEx mulciber Programming 1 12-18-2005 12:36 PM
read & write binary file error in redhat xcmore Programming 11 06-17-2005 07:48 AM
binary file problem lf412 Linux - General 3 02-05-2003 02:18 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:20 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration