Why is the output format different for two similar Fortran codes?

  • Fortran
  • Thread starter adishpatel
  • Start date
  • Tags
    Fortran
In summary: One of those two write statements comes from the first write statement in the do loop, which is the only write statement executed when K=1.
  • #1
adishpatel
22
0
So, when I execute my code which is at http://sysden.com/dufing.f

I get the results which are very well organized:
Code:
 PATH  ==========================================================================================

            N         INP       JCASE         JOB        JBIF        ILAM        IJAC          IW
            2           0           3           1           0           2           1         500


 ** ZPAR   **        EPSZ          HZ         ITZ       METHZ
               0.1000D-08  0.1000D-04          40           1


 ** GPAR   **        EPSG          HG         ITG
               0.1000D-04  0.5000D-03          15


 ** PPAR   **        HMIN          HP        HMAX      FACINC      FACDEC         ITP       NSTEP
               0.1000D-04  0.1000D-01  0.1000D-01  0.2300D+01  0.8000D+00          15          60


 ** EQSOL  **        IODE         LRW         TOL
                        2         100  0.1000D-09
 XBIFUR **** THE BIFURCATION POINT NOT BRACKETED
             AT C( 1) =    0.1498235665D+01   C( 2) =    0.1500000000D+01
             THE EIGENVALUE IS  LAMDA =    0.1018821933D+01    0.0000000000D+00

             AT C( 1) =    0.1498244342D+01   C( 2) =    0.1500000000D+01
             THE EIGENVALUE IS  LAMDA =    0.1018486738D+01    0.0000000000D+00

             AT C( 1) =    0.1500185162D+01   C( 2) =    0.1500000000D+01
             THE EIGENVALUE IS  LAMDA =    0.1075632960D+01    0.0000000000D+00


 PATH  ==========================================================================================


On the other hand, I have a very very similar code with simply some formulas modified, I get the following output (http://sysden.com/Trial.f) :

Code:
 T =  0.1230D+02    X(1) =   -0.6995969146D-16    X(2) =   -0.8397826270D-14
 T =  0.1232D+02    X(1) =   -0.1296208881D-15    X(2) =    0.4397024319D-15
 T =  0.1233D+02    X(1) =   -0.6896299146D-16    X(2) =    0.8521701466D-14
 T =  0.1234D+02    X(1) =    0.4941227263D-16    X(2) =    0.8977390468D-14
 T =  0.1235D+02    X(1) =    0.1241519258D-15    X(2) =    0.1634297191D-14
 T =  0.1237D+02    X(1) =    0.9342308194D-16    X(2) =   -0.6885493191D-14
 T =  0.1238D+02    X(1) =   -0.1172392094D-16    X(2) =   -0.9706719735D-14
 T =  0.1239D+02    X(1) =   -0.1099822134D-15    X(2) =   -0.4513322049D-14
 T =  0.1240D+02    X(1) =   -0.1183246126D-15    X(2) =    0.4526377004D-14
 T =  0.1242D+02    X(1) =   -0.2783645508D-16    X(2) =    0.1001609073D-13
 T =  0.1243D+02    X(1) =    0.8740604234D-16    X(2) =    0.7396635050D-14
 T =  0.1244D+02    X(1) =    0.1334446529D-15    X(2) =   -0.1576740606D-14
 T =  0.1245D+02    X(1) =    0.6687026721D-16    X(2) =   -0.9388969273D-14
 T =  0.1247D+02    X(1) =   -0.5655341949D-16    X(2) =   -0.9486228884D-14
 T =  0.1248D+02    X(1) =   -0.1362274125D-15    X(2) =   -0.1479291222D-14
 T =  0.1249D+02    X(1) =   -0.1012353469D-15    X(2) =    0.7942125660D-14
 T =  0.1250D+02    X(1) =    0.1776983651D-16    X(2) =    0.1091033964D-13
 T =  0.1252D+02    X(1) =    0.1269133235D-15    X(2) =    0.4786738462D-14
 T =  0.1253D+02    X(1) =    0.1303159882D-15    X(2) =   -0.5510440636D-14
 T =  0.1254D+02    X(1) =    0.2519319926D-16    X(2) =   -0.1117597369D-13
 T =  0.1255D+02    X(1) =   -0.9953672094D-16    X(2) =   -0.7583895225D-14
 T =  0.1257D+02    X(1) =   -0.1393567280D-15    X(2) =    0.2126730762D-14


I want my output to be the way it is for the 1st file. Don't understand why the format differs?

I even commented the format bit from the Trail code and it still wouldn't give me the nicely organized results?

Code:
      INDEX=1
      T=0.0D+00
   17 FORMAT(' T =',D12.4,'    X(1) =',D20.10,'    X(2) =',D20.10)
      DO 18,  K=1,1000
         TEND = K*TPER/500
         CALL ODE2(FCN,JAC,IJAC,N,T,X,TEND,INDEX,IER)
         IF (X(1).GT.1.0D+01) GOTO 18
         WRITE(6,17) T,X(11),X(12)
         WRITE(3,*) T,X(11),X(12)
   18 CONTINUE
      STOP
 
Technology news on Phys.org
  • #2
The computer will only do what you tell it to do. In the first case, it appears that subroutine PATH gives some output. In the second case, the output is coming from the write statements you wrote.
 
  • #3
In dufing.f it has

Code:
      lamda = (0.1000d+01, 0.0000d+00)                                                                                          
c                                                                       
      tq(1) = tp(1)                                                     
      tq(2) = tp(2)                                                     
      tq(3) = tp(3)                                                     
      tq(4) = tp(4)                                                     
c                                                                       
      tp(1) = 0.0000d+00                                                
      tp(2) = 0.0000d+00                                                
      tp(3) = 0.0000d+00                                                
      tp(4) = 0.1000d+01

And Trial.f has the following instead:

Code:
C
      DO J=1,N+2
         TQ(J) = TP(J)
      END DO
C
      DO J=1,N+1
         TP(J) = 0.0000d+00
      END DO
      TP(N+2) = 1.0000d+00
C

I even commented out the following from Trial.f to let call path do the job as it does in dufing.f and still the results come out in a different way?

Code:
      INDEX=1
      T=0.0D+00
   17 FORMAT(' T =',D12.4,'    X(1) =',D20.10,'    X(2) =',D20.10)
      DO 18,  K=1,1000
         TEND = K*TPER/500
         CALL ODE2(FCN,JAC,IJAC,N,T,X,TEND,INDEX,IER)
         IF (X(1).GT.1.0D+01) GOTO 18
         WRITE(6,17) T,X(11),X(12)
         WRITE(3,*) T,X(11),X(12)
   18 CONTINUE
      STOP

Subroutine path? There are two instances where we define subroutine in dufing.f and 3 instances where we have "call path". It is the same for Trial.f as well. Also the code is no different than what I mentioned? Am I overlooking something here :O
 
  • #4
adishpatel said:
In dufing.f it has

Code:
      lamda = (0.1000d+01, 0.0000d+00)                                                                                          
c                                                                       
      tq(1) = tp(1)                                                     
      tq(2) = tp(2)                                                     
      tq(3) = tp(3)                                                     
      tq(4) = tp(4)                                                     
c                                                                       
      tp(1) = 0.0000d+00                                                
      tp(2) = 0.0000d+00                                                
      tp(3) = 0.0000d+00                                                
      tp(4) = 0.1000d+01

And Trial.f has the following instead:

Code:
C
      DO J=1,N+2
         TQ(J) = TP(J)
      END DO
C
      DO J=1,N+1
         TP(J) = 0.0000d+00
      END DO
      TP(N+2) = 1.0000d+00
C
That's irrelevant. It doesn't concern output.

adishpatel said:
I even commented out the following from Trial.f to let call path do the job as it does in dufing.f and still the results come out in a different way?
I have no idea what the PATH subroutine is or does. It is possible that there is a certain variable passed to PATH that controls whether the subroutine produces any output. If you have the source file, you can check to see how PATH produces output. If it's in a library, you have to look at the documentation for that library.
 
  • #5
I don't think the code shown could have printed the first output. It seems clear that PATH printed the first output. But the "STOP" after the "18 CONTINUE" line stops the program before PATH is executed. There are two write statements before the "STOP" that print the second output.
 
  • Like
Likes 1 person

FAQ: Why is the output format different for two similar Fortran codes?

What is Fortran?

Fortran is a programming language commonly used in scientific and engineering applications. It stands for "Formula Translation" and was one of the first high-level programming languages developed in the 1950s.

How is Fortran used for organizing results?

Fortran is used for organizing results by allowing scientists to write code that can perform complex mathematical calculations and manipulate large amounts of data. This makes it easier to organize and analyze results from experiments or simulations.

Can Fortran handle large datasets?

Yes, Fortran is designed to handle large datasets and can efficiently process and store large amounts of data. This makes it a popular choice for scientific applications that require working with large datasets.

Are there any alternatives to Fortran for organizing results?

Yes, there are other programming languages such as Python and R that can also be used for organizing and analyzing results. However, Fortran is still widely used in the scientific community due to its efficiency and specialized features for numerical calculations.

Is Fortran still relevant in modern science?

Yes, Fortran is still relevant in modern science as it continues to be updated and improved upon. Many legacy codes and programs are written in Fortran, and it is still widely used in fields such as weather forecasting, computational physics, and high-performance computing.

Similar threads

Replies
8
Views
4K
Replies
1
Views
1K
Replies
4
Views
9K
Replies
4
Views
3K
Replies
4
Views
4K
Replies
1
Views
2K
Replies
16
Views
2K
Replies
4
Views
1K
Replies
2
Views
1K
Back
Top