Is there a way to call the field of a derived type via string argument in fortran?
subroutine set(car, fieldName, value) type(Car_T) :: car character*(*) :: fieldName character*(*) :: value car%[fieldName] = value end subroutine set
You can do something similar with namelists but it is for items known to the program: not new items.
integer:: inin real:: rere namelist /info/ inin, rere inin = 0 ! default rere = 20.4 ! default read (*, nml=info) print *, 'inin=', inin print *, 'rere=', rere stop end
On the input
&info inin=2 rere=40.0 /
Or if you wish to input one value only
&info rere=3.162 /