Selective file copy: Difference between revisions

→‎{{header|Fortran}}: More details...
(→‎{{header|Fortran}}: More details...)
Line 310:
WRITE (6,*) IS !Reveal the result.
END</lang>
This produces a file in a standard format, with some extra spaces that occasionally help readability. All output starts with a space in column one (in case this output were to be sent to a lineprinter, for which that would be the carriage control character), and begins the block of output with a special line that gives the name of the NAMELIST prefixed with an ampersand, and ends it with a slash. Each line starts with the name of a variable followed by an equals, then comes its value in anthe appropriatesame formatstyle as would be used in free-form output, justusing a field large enough for its largest value. Some extra spaces are supplied before the = according to name length to improve readability. The whole line looks much as if it were an assignment statement in Fortran. There is special provision for listing the values of arrays also,which andnormally are shown one after another in the standard order. A sequencesrun of equal values will be shown with a repetition count as in ... ,6*0T, ... for six zero"true" values in a row, alas not using an @ symbol. CHARACTER variables will be shown with all their characters and even if they are all blank, they will not be shown as "" though that is acceptable for input. There is a default record length of 133 (again for lineprinters) and a variable may require multiple lines; CHARACTER variables split across lines include the content of the first character of the next line, but otherwise the line break is after a comma. Structure names alas use % instead of a full stop, but a full stop may be accepted as input. Before F90, such data aggregates were not available, so only ordinary variables could be named.
<pre>
&STUFF
Line 325:
/
</pre>
This is suitable for input also. Variables can be named in any order, and,overwriting notany earlier appearances. Not all need be named -, also, the same variable may appear in multiple NAMELIST lists. Those named in the NAMELIST but not named in the specific input will not be changed by the READ statement. A <code>READ(F,STUFF)</code> will skip through input blocks until it finds an &STUFF, thus an input file may contain stuff for different NAMELIST collections (- thereby directly meeting the specification for a "selective file copy" in its own way. For arrays (and CHARACTER variables) still further selectivity is available whereby only a portion may be altered as in <code>A(6) = 3</code>, and if inputvalues isfor an array are being obtainedlisted live(as fromwith <code>6*T</code> above) then a sequence <code>6*</code> means that the keyboard,corresponding onesix canvalues enterof "?"the array are to beremain advisedunchanged. Thus, given an array MANY in the NAMELIST, an assignment <code>MANY(2:13) = 1,2,3,4,6*,11,12</code> would leave MANY(6:11) unchanged, thus demonstrating another sort of selectivity. On the nameother hand the use of * precludes arithmetic expressions (just as with the NAMELISTDATA beingstatement) sought...- values must be actual constants.
 
If input is being obtained live from the keyboard, some Fortrans allow you to enter " ?" (note the leading space) to be advised of the name of the NAMELIST being sought and " =?" will list the current values of the NAMELIST collection, after which you may make your selection...
This style of input is useful when a large number of different parameters are to be read in, and on a given occasion, many of them may be omitted. It is thus more flexible than having some defined format for all of them, or, reading them all in free-format. Obviously, the names will have mnemonic value.
 
This style of input is useful when a large number of different parameters are to be read in, and on a given occasion, many of them may be omitted. It is thus more flexible than having some defined format for all of them, or, reading them all in free-format. Obviously,Good mnemonics for the names will havebe mnemonicvery valuehelpful.
To revert to the specific task, obviously the input could contain only values for variables of interest, or, if values for all variables are supplied (as in the example), after the READ only those of interest would be copied to other variables to be going on with. In the example, because there is no <code>IS = HERE, BY NAME</code> facility offered by Fortran so that only the elements of HERE that have the same name as elements of IS (in perhaps a different order) will be copied, as in pl/i and others, the copy must be done element-by-element. If however the desired elements had been grouped into a substructure (say, called LOCATION) and both type PLACE and type HOME had used that substructure, then a single assignment could have been used, as when HERE is copied to THERE.
 
To revert to the specific task, obviously the input could contain only values for variables of interest, or, if values for all variables are supplied (as in the example), after the READ only those of interest would be copied to other variables to be going on with. In the example, because thereFortran isoffers no <code>IS = HERE, BY NAME</code> facility offered by Fortran so that only the elements of HERE that have the same name as elements of IS (in perhaps a different order) will be copied, (as in pl/i and others), the copy must be done element-by-element. If however the desired elements had been grouped into a substructure (say, called LOCATION) and both type PLACE and type HOME had used that substructure, then a single assignment could have been used, as when HERE is copied to THERE.
 
Output:<pre> Mt. Cook trig. (-41.29980,174.7763)</pre>
1,220

edits