Welcome to AE Resources
Converted document Converted document

FORTRAN 90+: USE OF VARIABLE NAMESS

Where and how variables are defined and the names they use can be lead to some problems in coding. Variable names can be used for different items in the same code, depending on how they are used and where they are defined. There are some basic guidelines:
  1. A variable name that is used for an intrinsic variable or program name should not be used again.
  2. A variable name is defined only in the program or function in which it is declared. If a variable is declared in a program or subroutine, then is it already valid in any function that the program or subroutine directly calls. However, the reverse is not true. A variable defined in the function is only known to itself and any subroutines or functions that it calls directly.
  3. A variable can be defined as a "global variable", and it will be available to all all code within the program. While not recommended, this does not prevent the reuse of the variable name for other purposed in functions or subprograms contained within the main program.
  4. If a variable name that is not defined as a global variable is used in different subroutines, the variables are distinct and are not associated with one another.If a variable is named ’density’ in the main program and is named 'density' again within a subroutine, each are distinct and the data contained by the variable are not shared nor destroyed.