io - Is there a way to use the namelist I/O feature to read in a derived type with allocatable components? -
is there way use namelist i/o feature read in derived type allocatable components?
the thing i've been able find https://software.intel.com/en-us/forums/intel-fortran-compiler-for-linux-and-mac-os-x/topic/269585 ended on unhelpful note.
edit:
i have user-defined derived types need filled information input file. so, i'm trying find convenient way of doing that. namelist seems route because succinct (basically 2 lines). 1 create namelist , namelist read. namelist seems choice because in text file forces show each value goes find highly preferable having list of values compiler knows exact order of. makes more work if or else needs know value corresponds variable, , more work keep clean when inevitably new value needed.
i'm trying of basic form:
!where mytype_t type has @ least 1 allocatable array in type(mytype_t) :: thing namelist /nmlthing/ thing open(1, file"input.txt") read(1, nml=nmlthing)
i may misunderstanding user-defined i/o procedures, don't seem generic solution. seems need write new 1 time need action, , don't seem natively support
&nmlthing thing%name = "thing1" thing%siblings(1) = "thing2" thing%siblings(2) = "thing3" thing%siblings(3) = "thing4" !siblings allocatable array /
syntax find desirable.
there few solutions i've found problem, none seem succinct or elegant. currently, have dummy user-defined type has arrays way large instead of allocatable , write function copy information dummy namelist friendly type allocatable field containing type. works fine, ugly , i'm 4 places need same type of operation in code.
hence trying find solution.
if want use allocatable components, need have accessible generic interface user defined derived type input/output procedure (typically type having generic binding such procedure). link thread example such procedure.
once invoked, user defined derived type input/output procedure responsible reading , writing data. can include invoking namelist input/output on components of derived type.
fortran 2003 offers derived types length parameters. these may offer solution without need user defined derived type input/output procedure. however, use of derived types length parameters, in combination namelist, put firmly in "highly experimental" category respect current compiler implementation.
Comments
Post a Comment