j3-fortran / fortran_proposals

Proposals for the Fortran Standard Committee
178 stars 15 forks source link

Ability to write part of a NAMELIST using NAMELIST group I/O #134

Open urbanjost opened 4 years ago

urbanjost commented 4 years ago

A useful extension to NAMELIST group I/O would be able to just print part of a NAMELIST, perhaps by giving the WRITE statement a string with a list of variables in a somewhat NAMELIST like format. Assuming a namelist like

namelist /big/a,b,c,d,e,f,g

existed with some of the elements of the group being large arrays, to just print a subset of the NAMELIST maybe something like write(,nml=big) 'a(30:40),c' or with less flexibilty (the list of names could not be changed at run-time) even write(,nml=big)a(i:j) would be useful, eIspecially if the output showed the subset being printed, as in &BIG A(10:20)=1,2,3,4,5,6,7,8,9.... which could still be read back in with existing NAMELIST groups and would let you selectively examine or extract small parts of a large array, for example.

FortranFan commented 4 years ago

This is a tough one!

The standard appears to have focused more on facilities on NAMELIST input but not as much with NAMELIST output. With what the standard calls null values, comments, etc., what can be done in NAMELIST output is somewhat limited relative to input. It may prove rather difficult to get much excitement and support to make NAMELIST output more functional.

Since the use case suggests the need with "large arrays", an alternative for coders might be to consider an OO approach and design 'classes' aka derived types to encapsulate such large arrays e.g., a roll-your-own derived type in Fortran to model something like 'vector' class from C++ STL as a container for the 'large' array. Users can then implement derived-type IO (DTIO) that includes NAMELIST support to output (and input) process the array section data in a variety of flexible ways. This might even be an option for the standard library effort.

sblionel commented 4 years ago

NAMELIST was largely dropped into F90 from IBM FORTRAN (and those who copied it) and hasn't been meaningfully extended since then. What is the real-world use case for such a feature, specifically in relation to NAMELIST? It seems like a "can of worms" for little payback.

I agree with @FortranFan that this seems more amenable to a "roll your own" approach. You can even mimic NAMELIST output without too much effort if the format is important.