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

OUTPUT FILE AS A INPUT FILE IN SAME FORTRAN PROGRAM

uddin__md
Beginner
213 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
213 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

2 Replies
Arjen_Markus
Honored Contributor I
214 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

 

uddin__md
Beginner
213 Views

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

Reply