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

Share data between Fortan files

tatuna
Beginner
615 Views
Dear Friends,

I have a great request to you and hope you could help me.

I have written quite a big program in Fortran.My program consists of two fortran files. For example aa.f and bb.f .
First of all, I compile aa.f file and calculate a matrix. This calculated matrix I would like to put in the second file, bb.f.After running bb.f the final results is obtained.

Please, could you tell me what is themost convinient way toimport the calculated matrixby aa.f into different bb.f?

Thank you in advance.
Best wishes,
V.J.
0 Kudos
4 Replies
DavidWhite
Valued Contributor II
615 Views
Quoting - tatuna
Dear Friends,

I have a great request to you and hope you could help me.

I have written quite a big program in Fortran.My program consists of two fortran files. For example aa.f and bb.f .
First of all, I compile aa.f file and calculate a matrix. This calculated matrix I would like to put in the second file, bb.f.After running bb.f the final results is obtained.

Please, could you tell me what is themost convinient way toimport the calculated matrixby aa.f into different bb.f?

Thank you in advance.
Best wishes,
V.J.

I assume you mean that aa.f and bb.f are each compiled into a separate executable program. One possible way to change this so that you can work with the data is to make bb.f into a subroutine, call it from aa.f and pass the matrix as a argument to bb.
0 Kudos
tatuna
Beginner
615 Views
Quoting - David White

I assume you mean that aa.f and bb.f are each compiled into a separate executable program. One possible way to change this so that you can work with the data is to make bb.f into a subroutine, call it from aa.f and pass the matrix as a argument to bb.

Mr. David,

Thank you very much for your comment.

To be honest, I do not fully understand your comment. Would you please be so kind to explain it in more detail? Or, maybe some easier way to import data,from one fortran file to another, is possible? It isvery urgent and important for me.

Thank you in advance.
V.J.
0 Kudos
Les_Neilson
Valued Contributor II
615 Views
Quoting - tatuna
It isvery urgent and important for me.

Whenever I see that, I get the feeling thatit is a homework question.

Anyway either :
(a) whatever WRITE statements you have in aa.f (presumably you write to a file or pipe the output of aa to a file) then add a corresponding READ in bb.f (After OPENing the appropriate file of course)

(b) As David suggested : change the PROGRAM BBstatement inbb.fto a SUBROUTINE BBstatement and maybe add the name of the matrix as the dummy argument, unless it is available some other way (eg common, or module or ...)
perhaps remove the WRITE statement(s) from aa.f and add a CALL BB(matrix) instead.
You will need to add bb.f to the aa.f project

(c) copy the calculation code from bb.f into aa.f before the END statement. Again maybe remove the WRITE statement(s) from aa if they are no longer needed. (Make sure variable names from bb match/don't conflict with those in aa)

Les
0 Kudos
tatuna
Beginner
615 Views
Quoting - Les Neilson

Whenever I see that, I get the feeling thatit is a homework question.

Anyway either :
(a) whatever WRITE statements you have in aa.f (presumably you write to a file or pipe the output of aa to a file) then add a corresponding READ in bb.f (After OPENing the appropriate file of course)

(b) As David suggested : change the PROGRAM BBstatement inbb.fto a SUBROUTINE BBstatement and maybe add the name of the matrix as the dummy argument, unless it is available some other way (eg common, or module or ...)
perhaps remove the WRITE statement(s) from aa.f and add a CALL BB(matrix) instead.
You will need to add bb.f to the aa.f project

(c) copy the calculation code from bb.f into aa.f before the END statement. Again maybe remove the WRITE statement(s) from aa if they are no longer needed. (Make sure variable names from bb match/don't conflict with those in aa)

Les

Thank you very much.
Your comment is very helpful.

V.J.
0 Kudos
Reply