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

In summary: The idea is to create a program to create source code for another program, then run that program. This 2nd program would then use the values created by the first program.In summary, the individual is looking for a way to create a variable name with a variable in it in Fortran, without using an array. They have asked for help from others, but have not found a solution. One potential solution suggested is to use CreateProcess() in Visual Studio to create a program that generates source code for another program, which would then use the desired variable names.
  • #1
miran.iran
2
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
  • #2
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?
 
  • #3
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.
 
  • #4
@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()
 
  • #5
CreateProcess() is a library function in Visual Studio. I'm not sure what the equivalent would be with the Fortran tools you use.
 

1. What is a variable name in Fortran?

A variable name in Fortran is a symbolic name used to represent a value or data location in the program. It is used to store and manipulate data during the execution of the program.

2. What are the rules for naming variables in Fortran?

Variable names in Fortran must start with a letter, followed by zero or more letters, digits, or underscores. The name cannot be longer than 31 characters and must be unique within the program. Fortran is case insensitive, so variable names with different cases are considered the same.

3. Can I use keywords as variable names in Fortran?

No, keywords such as IF, DO, and END cannot be used as variable names in Fortran as they have predefined meanings in the language. Using them as variable names will result in errors in the program.

4. Is there a limit on the number of variables I can declare in Fortran?

There is no specific limit on the number of variables that can be declared in Fortran. However, it is good practice to minimize the number of variables used in a program to improve readability and avoid potential errors.

5. Can I change the value of a variable in Fortran?

Yes, the value of a variable can be changed during the execution of the program by assigning a new value to it. However, some variables may be declared as constants, which means their value cannot be changed once assigned.

Similar threads

  • Linear and Abstract Algebra
Replies
4
Views
1K
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
8
Views
17K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Programming and Computer Science
Replies
4
Views
4K
  • Programming and Computer Science
Replies
2
Views
3K
  • Programming and Computer Science
Replies
7
Views
42K
  • Programming and Computer Science
2
Replies
54
Views
4K
Back
Top