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
AI Thread 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.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...

Similar threads

Replies
6
Views
2K
Replies
6
Views
2K
Replies
4
Views
3K
Replies
6
Views
2K
Replies
8
Views
18K
Replies
7
Views
43K
Replies
1
Views
2K
Back
Top