Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28807 Discussions

OUTPUT FILE AS A INPUT FILE IN SAME FORTRAN PROGRAM

uddin__md
Beginner
610 Views

Hi, I am a new user of FORTRAN language.  I write a program for index calculation. My program contains with 10 subroutines. First  9 subroutines produced an output file. I want to use first output file as an input file for the last one subroutine in same program.

How can I write this input and read command. 

please, support me.

0 Kudos
1 Solution
Arjen_Markus
Honored Contributor I
610 Views

The simplest way to achieve this is:

  • Write all the output to the output file
  • Close the file when you are done (so when the ninth subroutine as finished)
  • Then open it again, now you can read it from the start

Something like:

real :: x
open( 10, file = 'result.out' )
write( 10, * )  cos(1.0)
close( 10 )

open( 10, file = 'result.out' )
read( 10, * )  x
close( 10 )
write( *, * ) 'The number that was produced is ', x

 

View solution in original post

0 Kudos
2 Replies
Arjen_Markus
Honored Contributor I
611 Views

The simplest way to achieve this is:

  • Write all the output to the output file
  • Close the file when you are done (so when the ninth subroutine as finished)
  • Then open it again, now you can read it from the start

Something like:

real :: x
open( 10, file = 'result.out' )
write( 10, * )  cos(1.0)
close( 10 )

open( 10, file = 'result.out' )
read( 10, * )  x
close( 10 )
write( *, * ) 'The number that was produced is ', x

 

0 Kudos
uddin__md
Beginner
610 Views

Many thanks @Arjen Markus. I have been solved my problems as per following your guidelines.

0 Kudos
Reply