LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Gfortran's strange behavior (https://www.linuxquestions.org/questions/linux-newbie-8/gfortrans-strange-behavior-4175526767/)

AlexBB 11-28-2014 03:49 PM

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.

suicidaleggroll 11-28-2014 04:29 PM

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.

AlexBB 11-28-2014 05:35 PM

I am in AWE with you, suicidaleggroll. I will try it in a minute. Many thanks.

AlexBB 11-28-2014 05:36 PM

It's awesome! It worked. Another lesson for me. Thanks again.


All times are GMT -5. The time now is 04:44 AM.