Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Variable name in fortran

  1. Jul 22, 2011 #1
    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
     
  2. jcsd
  3. Jul 22, 2011 #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?
     
  4. Jul 22, 2011 #3

    rcgldr

    User Avatar
    Homework Helper

    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.
     
  5. Jul 23, 2011 #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()
     
  6. Jul 23, 2011 #5

    rcgldr

    User Avatar
    Homework Helper

    CreateProcess() is a library function in Visual Studio. I'm not sure what the equivalent would be with the Fortran tools you use.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Variable name in fortran
Loading...