The assign statement allows one to assign a statement label to an integer variable. This power will then allow a programmer to use the integer variable in an assigned go to or as a format identifier in a read, write or print statement. This statement is now considered obsolete (it is formally declared obsolete in the Fortran 90 standard) and should be replaced by more recent branching structures or the use of character strings for Format statements. Its use will result in an undesirable lack of clarity in your program. If you are crazy enough to use this statement remember two things. First, the statement label that the integer variable references can be changed an unlimited number of times in the program. Second, when an integer variable is used to reference a statement label, the variable can not be used in mathematical expressions. The reason for this is that the label number is not represented as an integer constant inside the computer.
The first use of the assign statement is to store a statement label inside the variable such that it can be used in an assigned go to statement. The format would be similar to the following:
assign 200 to label imax = 56 go to label 200 print *, imax
It can be seen from this example number that appears after the assign statement is the label number that will be stored inside the integer variable. The integer variable, which is named label in this example, then appears after the word to in the assign statement. Please note that this example would be exactly equivalent to these lines of code.
imax = 56 go to 200 200 print *, imax
Now, remember that the assign statement can be used to reference format statements as well. This would be done in the following manner.
assign 2001 to ifrmt do i=1,45 write ( 37, ifrmt ) array1(i) end do 2001 format(1x,f5.2)
Most Fortran programmers would not use the Assign statements to accomplish either of the above tasks. First of all, instead of the assigned GO TO, it is clearer and simpler to use IF,THEN,ELSE or CASE Structures. When it comes to using it to reference format statements, one simple replacement is to place optional formats in a character array and then set the index of the array element that you currently want to use (see example multiform.f).
Written by Jason Wehr : email@example.com and Maintained by John Mahaffy : firstname.lastname@example.org