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
Click For Summary

Discussion Overview

The discussion revolves around the challenge of dynamically creating variable names in Fortran, specifically how to assign values to variables like a11, a12, a13, etc., without using arrays. Participants explore the limitations of Fortran in this regard and compare it to capabilities in other programming languages.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant seeks to assign values to individual variables (X1, X2, etc.) using a loop without employing arrays.
  • Another participant clarifies the request, confirming the desire to avoid array notation while assigning values to separate variables.
  • A third participant mentions that some languages allow dynamic variable creation, but notes that Fortran does not support this feature directly.
  • One participant suggests generating source code dynamically to create the desired variables, although this approach may be complex and involves external processes.
  • Another participant asks for guidance on what specific Fortran commands or concepts to investigate further, indicating uncertainty about the relevant topics.

Areas of Agreement / Disagreement

Participants generally agree that Fortran does not support dynamic variable naming as some other languages do. However, there is no consensus on a practical solution to the original question posed.

Contextual Notes

Participants express uncertainty about the limitations of Fortran regarding variable naming and the potential need for external processes to achieve similar functionality found in other programming languages.

Who May Find This Useful

Programmers and developers working with Fortran who are interested in variable management and dynamic programming techniques, as well as those familiar with other languages that support dynamic variable creation.

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.
 

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 1 ·
Replies
1
Views
2K
  • · Replies 6 ·
Replies
6
Views
5K
  • · Replies 4 ·
Replies
4
Views
4K