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

  • Thread starter Thread starter miran.iran
  • Start date Start date
  • Tags Tags
    Fortran Variable
Click For Summary
The discussion centers around creating variable names dynamically in Fortran, specifically wanting to assign values to variables like a11, a12, etc., without using arrays. The user expresses a desire for a method similar to dynamic variable creation found in other languages, such as APL, but acknowledges that Fortran does not support this feature. Suggestions include generating source code programmatically to create the desired variables, though this approach is complex. The conversation also touches on the limitations of Fortran regarding dynamic variable names and the use of external processes for code generation and execution, referencing Visual Studio's CreateProcess() function. The user seeks guidance on what specific Fortran concepts to research, such as variable names and arrays, to better understand the capabilities and limitations of the language.
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
 
Technology 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.
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 8 ·
Replies
8
Views
18K
  • · Replies 7 ·
Replies
7
Views
43K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 6 ·
Replies
6
Views
5K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
4K