How Can I Create a Variable Name with a Variable in Fortran?

  • Context: Fortran 
  • Thread starter Thread starter miran.iran
  • Start date Start date
  • Tags Tags
    Fortran Variable
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
4 replies · 3K views
miran.iran
Messages
2
Reaction score
0
Hi,

How could I make a variable name with a variable in it in fortran?
For example I want to use a loop to assign values to a11, a12, a13, a14, a15 and a21, a22, a23

I DO NOT WANT TO USE ARRAY FOR THIS


Real X1,x2,x3,x4,x5
Do I=1,5
Xi(i=1 to5)=i
Enddo

( How should I get through to the fortran that “i “ in the” Xi” is variable.

(((The same thing we do NORMALLY FOR FILE NAMES(characters) but for other type of variables:

character(80) fn
DO N=1,NVIV
WRITE(FN,'(A,A,I2.2,A)') TRIM(WORK_DIR),'WOW',N,'.DAT' )))

Regards

miran
 
Physics news on Phys.org
I'm trying to sort out what you're asking. You want

X1 = 1
X2 = 2
X3 = 3
X4 = 4
X5 = 5

But you do not want X(i) in the sense of an array?
 
Some interpretive languages have the ability to create a string (or function) dynamically and then execute that string (or function), such as APL. I'm not aware of a version of Fortran that does this. You could create a program to generate the source code for yet another program that would have the variable names. The master program could go so far as to create the source code, then invoke the compiler to compile the source code, then invoke the compiled program.

In the case of Visual Studio and Windows, this can be done using CreateProcess(). Note that the initial information passed to the spawned process is normally included in the command line string used to spawn the process including items such as the handle value for the creating process, and any handle values to be used by DuplicateHandle() in order to share information between the processes.
 
@swartzism: yes.thats it. I want to see how can I create a real variable name which part of it is variable. I know how to do this in APL.but you can not do the same in Fortran.
I have asked some others. they did not know too!

@ rcgldr:Could you please tell me what should I search exactly?
I do not know which parts of the fortran commands needs to be checked . I tried some hand book but I really do not know what should I looking for? " Variable names? arrays? OR CreateProcess()
 
CreateProcess() is a library function in Visual Studio. I'm not sure what the equivalent would be with the Fortran tools you use.