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

OPEN in MODULE: is it possible?

atru
Beginner
535 Views

Can you give me a hint on how to open a file in the MODULE in order to share a content of the file as the constants through the USE?

0 Kudos
4 Replies
Steven_L_Intel1
Employee
535 Views

I am not sure what you want to do - would you please try to explain it a different way or in more detail? Feel free to show a fake program that tries to do what you want.

You can open a file in a module procedure and perhaps read the contents into a module variable that can be made available by USE, but you would have to write the procedure that does this - there isn't a way to automatically turn file contents into variables or especially constants.

0 Kudos
atru
Beginner
535 Views

I know that the following code is not correct. But it’s as an example of what I want. I am looking for a hint on how to do something like that. I would not like to use the COMMON blocks and the OPEN statements in the subroutines. I was trying to make my question clear.

MODULE BIO_CONSTANTS
  OPEN(UNIT=10 ...) BIO ...
  ...
END MODULE BIO_CONSTANTS

PROGRAM BIOTA
  SUBROUTINE ABIOTA (...)
    USE BIO_CONSTANTS
    ...
  SUBROUTINE BBIOTA (...)
    USE BIO_CONSTANTS
    ...
  SUBROUTINE CBIOTA (...)
    USE BIO_CONSTANTS
    ...
  SUBROUTINE DBIOTA (...)
    USE BIO_CONSTANTS
    ...
  ...
END PROGRAM BIOTA

0 Kudos
Steven_L_Intel1
Employee
535 Views

You would have to write a procedure in the module that opens the file and reads the values into module variables. Then the subroutines could USE the module and access the variables. You would also have to add a call to the new procedure at the start of the program. Note that these would not be "constants" - they would be ordinary variables. You could give the variables the PROTECTED attribute that would make it difficult for the subroutines to modify the data.

0 Kudos
atru
Beginner
535 Views

Thank you. I will try to do it.

0 Kudos
Reply