LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 11-04-2014, 09:33 PM   #1
AlexBB
Member
 
Registered: Mar 2014
Posts: 464

Rep: Reputation: Disabled
READ statement in GFortran does not work.


Hi there. My environment is Oracle VB==>Ubuntu==>GFortran. The task I have is to read a row of five numbers from a file, do some elementary arithmetic and write a result into another file. Here is the input data and the gfortran code file:

Code:
File gray_h_20.dat:

0       1956.353271     1957.88532      1958.421583     242.7323189
1       3041.603197     3044.183214     3044.777652     577.2555817
2       3144.126342     3147.268738     3147.371598     593.6402392
3       2621.753866     2625.135851     2624.548747     382.6601984
4       1805.758859     1809.07078      1808.02618      156.2339457
..      ...........     ..........      ..........      ...........


program main
   real :: val1,val2,val3,val4,diff1,diff2,dcent1,dcent2
   integer :: reason = 0, ii = 0, jj = 75
   100 format (I4,f15.6,f15.6,f15.6,f15.6)   ! for reading from unit 1 file
   200 format ("reason = ",I10," jj = ",I10)
   700 format (f8.3)                   ! for writing into the unit 3 file
   500 format (I3,". val1= ",f11.7," val2= ",f11.7," diff1 = ", f8.3," or ",f6.2,"%", " diff2 = ",f8.3," or ", f6.3,"%")                ! for writing into stdout; unit 6
   open (unit=1, file = "gray_h_20.dat", status = 'old')
   open (unit=3, file = "diff_h_20.dat", status = 'old')
   DO WHILE (reason .eq. 0)
     ii = ii + 1
     read (1,100,IOSTAT=reason) jj,val1,val2,val3,val4
     write (6,200) reason,jj
     diff1 = val1 - val2
     diff2 = val1 - val3
     dcent1 = diff1 / val1 * 100
     dcent2 = diff2 / val1 * 100
     write (3,700) dcent1
     write (6,500) ii, val1, val2, diff1, diff2, dcent1,dcent2
   enddo
   close (unit=1)
   close (unit=3)
end
I initiated jj as 75 to find out if the first number (Integer) was read. The rest of the numbers on each line are real.

I get this error, and also one line of "output" which is no output at all:

Quote:
reason = 5010 jj = 75
1. val1= -0.0000142 val2= 0.0000000 diff1 = -0.000 or -0.00% diff2 = 100.000 or 0.553%
The error code is:

Quote:
5010 LIBERROR_READ_VALUE
What do I do wrong?

Thanks, - A.

Last edited by AlexBB; 11-05-2014 at 10:22 AM.
 
Old 11-05-2014, 03:56 PM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: CentOS 6 & 7
Posts: 3,023

Rep: Reputation: 804Reputation: 804Reputation: 804Reputation: 804Reputation: 804Reputation: 804Reputation: 804
The "I" format specifier is for right-justified integers. Yours appear to be left-justified.
 
Old 11-05-2014, 08:18 PM   #3
AlexBB
Member
 
Registered: Mar 2014
Posts: 464

Original Poster
Rep: Reputation: Disabled
This is what I just did, a minute ago:

Code:
read (1,*,IOSTAT=reason) jj,val1,val2,val3,val4
Now everything is working!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] Gfortran statement does not compile AlexBB Linux - Newbie 38 12-05-2016 08:19 PM
read and if statement in bash casperdaghost Linux - Newbie 11 10-13-2011 09:30 AM
gfortran: Syntax error in DATA statement at (1) science_guy Programming 1 10-16-2009 01:10 AM
Problem to Read Binary File with gfortran kdurgarao Programming 1 10-12-2009 03:26 AM

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

All times are GMT -5. The time now is 11:44 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration