LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-28-2014, 04:49 PM   #1
AlexBB
Member
 
Registered: Mar 2014
Posts: 435

Rep: Reputation: Disabled
Gfortran's strange behavior


Hi there,

My environment is Oracle VM (Ubuntu)==>GFortran.

I have a problem with my GFortran. I have an input file (anglesV1.dat) with two columns of numbers:

Code:
  0.7439803D-01  0.1107149D+01         
  0.7321435D-01  0.1099019D+01         
  0.7203546D-01  0.1090621D+01         
  0.7086159D-01  0.1081944D+01        
  0.6969303D-01  0.1072974D+01        
  0.6853005D-01  0.1063698D+01         
  0.6737297D-01  0.1054101D+01        
  0.6622212D-01  0.1044169D+01
Then I run a subroutine that reads them and prints them on the screen:

Code:
     subroutine determinant                 
           real*8 :: phi,theta
           integer*4 :: counter
           open (unit=1,file='anglesV1.dat', status='old')
           counter = 0
10         FORMAT (2F12.5)
           do while (counter .lt. 20)
             counter = counter + 1
             read (1,10) theta,phi
             write (6,10) theta,phi
           enddo
           close(unit=1)
         end subroutine determinant
This is what I get in the terminal:
Code:
     0.74398   -10.11071
     0.73214   -10.10990
     0.72035   -10.10906
     0.70862   -10.10819
     0.69693   -10.10729
     0.68530   -10.10636
     0.67373   -10.10541
     0.66222   -10.10441
I don't understand the result. In the first column all exponents are -1. It means that the numbers (mantissas) must be multiplied by 10 to the power -1, meaning it is 1/10, correct? So when I use F12.6 format the numbers in the first column should come out like this:
Code:
     0.074398   
     0.073214 etc.,
In the second column the exponents are +1 meaning that the mantissas should be multiplied by 10.0, that is:
Code:
                 1.107149    
                 1.099019
Why do I have negative sign in the output for the second column?

Please help, thanks.

Last edited by AlexBB; 11-28-2014 at 04:52 PM.
 
Old 11-28-2014, 05:29 PM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,260

Rep: Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948
This

Code:
  0.7439803D-01  0.1107149D+01         
  0.7321435D-01  0.1099019D+01         
  0.7203546D-01  0.1090621D+01         
  0.7086159D-01  0.1081944D+01        
  0.6969303D-01  0.1072974D+01        
  0.6853005D-01  0.1063698D+01         
  0.6737297D-01  0.1054101D+01        
  0.6622212D-01  0.1044169D+01
Is not 2F12.5, it's 2D15.7, so when you tell it to parse it as 2F12.5 you'll get the wrong result.
Reading this line
Code:
  0.7439803D-01  0.1107149D+01
as 2F12.5, will see this
Code:
  0.7439803D
for the first number, and this
Code:
-01  0.11071
for the second number.

Either remove the format code from the read, or change it to match the format of the data you're reading.

Last edited by suicidaleggroll; 11-28-2014 at 05:34 PM.
 
1 members found this post helpful.
Old 11-28-2014, 06:35 PM   #3
AlexBB
Member
 
Registered: Mar 2014
Posts: 435

Original Poster
Rep: Reputation: Disabled
I am in AWE with you, suicidaleggroll. I will try it in a minute. Many thanks.
 
Old 11-28-2014, 06:36 PM   #4
AlexBB
Member
 
Registered: Mar 2014
Posts: 435

Original Poster
Rep: Reputation: Disabled
It's awesome! It worked. Another lesson for me. Thanks again.
 
  


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] Strange behavior battles Linux - Newbie 5 07-10-2014 09:59 AM
Very Strange Behavior raysr Mandriva 4 08-31-2004 03:06 PM
strange cups behavior realnubee Linux - Networking 0 04-27-2004 06:52 PM
Strange Behavior andrewb758 Linux - Hardware 5 08-31-2003 03:42 PM
strange behavior abhijit Linux - General 3 07-10-2003 12:25 AM


All times are GMT -5. The time now is 08:37 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