The first record of NAMELIST input data has the special symbol $ (dollar sign) in column two or beyond, followed by the NAMELIST group name. This is followed by a series of assignment statements, starting in or after column two, on the same or subsequent records, each assigning a value to a variable (or one or more values to array elements) of the specified group. The input data is terminated with another $ in or after column two, as in the pattern:
¤$group-name variable =value [,variable =value,] $[END]
You can alternatively use an ampersand (&) in place of each dollar sign, but the beginning and ending delimiters must match. END is an optional part of the last delimiter.
The input data assignment statements must be in one of the following forms:
variable=value |
array=value1[, value2,]... |
array(subscript)=value1[, value2,]... |
array(subscript,subscript)=value1[, value2,]... |
variable=character constant |
variable(index:index)=character constant |
If an array is subscripted, it must be subscripted with the appropriate number of subscripts: 1, 2, 3,...
Use quotes (either " or ') to delimit character constants. For more on character constants, see the next section.
The following is sample data to be read by the program segment above:
¤$case delta=0.05, mat( 2, 2 ) = 2.2, sample='Demo' $
The data could be on several records. Here NEW was not input, and the order is not the same as in the example NAMELIST statement:
¤$case ¤delta=0.05 ¤mat( 2, 2 ) = 2.2 ¤sample='Demo' ¤$
The following syntax rules apply for input data to be read by NAMELIST:
The variables of the named group can be in any order, and any can be omitted.
The data must start in or after column two. Column one is totally ignored.
There must be at least one comma, space, or tab between variables, and one or more spaces or tabs are the same as a single space. Consecutive commas are not permitted before a variable name. Spaces before or after a comma have no effect.
No spaces or tabs are allowed inside a group name or a variable name, except around the commas of a subscript, around the colon of a substring, and after the ( and before the ) marks. No name can be split over two records.
The end of a record acts like a space character.
Note an exception--in a character constant, it is ignored, and the character constant is continued with the next record. The last character of the current record is immediately followed by the second character of the next record. The first character of each record is ignored.
The equal sign of the assignment statement can have zero or more blanks or tabs on each side of it.
Only constant values can be used for subscripts, range indicators of substrings, and the values assigned to variables or arrays. You cannot use a symbolic constant (parameter) in the actual input data.
Hollerith, octal, and hexadecimal constants are not permitted.
Each constant assigned has the same form as the corresponding FORTRAN constant.
There must be at least one comma, space, or tab between constants. Zero or more spaces or tabs are the same as a single space. You can enter: 1,2,3, or 1 2 3, or 1, 2, 3, and so forth.
Inside a character constant, consecutive spaces or tabs are preserved, not compressed.
A character constant is delimited by apostrophes (') or quotes ("), but if you start with one of those, you must finish that character constant with the same one. If you use the apostrophe as the delimiter, then to get an apostrophe in a string, use two consecutive apostrophes.
¤sample='use "$" in 2' (Read as: use $ in 2) ¤sample='don''t' (Read as: don't) ¤sample="don''t" (Read as: don''t) ¤sample="don't" (Read as: don't)
A complex constant is a pair of real or integer constants separated by a comma and enclosed in parentheses. Spaces can occur only around the punctuation.
A logical constant is any form of true or false value, such as .TRUE. or .FALSE., or any value beginning with .T, .F, and so on.
A null data item is denoted by two consecutive commas, and it means the corresponding array element or complex variable value is not to be changed. Null data item can be used with array elements or complex variables only. One null data item represents an entire complex constant; you cannot use it for either part of a complex constant.
Example: NAMELIST input with some null data:
* nam2.f Namelist input with consecutive commas REAL ARRAY(4,4) NAMELIST /GRID/ ARRAY WRITE ( *, * ) 'Input?' READ ( *, GRID ) WRITE ( *, GRID ) END
¤$GRID ARRAY = 9,9,9,9,,,,,8,8,8,8 $
This code loads 9s into row 1, skips 4 elements, and loads 8s into row 3 of ARRAY.
The forms r*c and r* can be used only with an array.
The form r*c stores r copies of the constant c into an array, where r is a nonzero, unsigned integer constant, and c is any constant.
Example: NAMELIST with repeat-factor in data:
* nam3.f Namelist "r*c" and "r* " REAL PSI(10) NAMELIST /GRID/ PSI WRITE ( *, * ) 'Input?' READ ( *, GRID ) WRITE ( *, GRID ) END
¤$GRID PSI = 5*980 $
The program, nam3.f, reads the above input and loads 980.0 into the first 5 elements of the array PSI.
The form r* skips r elements of an array (that is, does not change them), where r is an unsigned integer constant.
Example: NAMELIST input with some skipped data.
¤$GRID PSI = 3* 5*980 $
The program, nam3.f, with the above input, skips the first 3 elements and loads 980.0 into elements 4,5,6,7,8 of PSI.