Search code examples
fortranintel-fortran

how to use a variable in string part of "open(file='...')" command in Fortran?


for instance I'm running my CFD code with different mesh sizes. I want the name of my output file to be changed automatically with my variable for number of nodes; let's say "imax" that is equal to number “50”. it should be something like this :

open(44, file='Temperature-imax50.txt')

I want to use use both “variable name” and “value assigned to it” in my file name. Is there way to fix this? one way for other command's strings is to use <> marks, but it won't work here.


Solution

  • I am not sure I completely understand your question. So, depending on what you actually ask:

    1. Put the name of the variable into the file name

    There is no way to convert variable name to a string in Frotran. You have to do it manually. (Read about reflexions).

    1. Put the content of a string that contains "imax" into the file name.

    That is easy, just concatenate the strings "Temperature-"//imax.

    1. imax contains a number and you want that number in a file name

    That was discussed many many times here already: Convert integers to strings to create output filenames at run time