introspection - fortran: Identify intrinsic type of a variable *after* the variable is in memory -



introspection - fortran: Identify intrinsic type of a variable *after* the variable is in memory -

i bit new fortran, coming python, r , sas. in of these languages, info type formatting embedded in output functions, fortran requires (among other things) explicit format indicator each variable beingness written. i'd dynamically build format string leveraging variable introspection have fortran tell me info type is, along applicable attributes (kind, len, etc). such introspection assist in construction of universally applicable programme subunits.

in oo world of python , r, trivial inquiry. example, testing whether value string in python just...

isinstance('foo',basestring)

there other methods of course. in event, can't shake thought such intrinsic enquiry must exist in fortran. date, have seen methods unable distinguish between whole real value , integers.

others have proposed using iostat parameter in read statement. have not yet figured out how leverage statement variables exist in memory. (at point, have encountered utilize of read statement in conjunction reading keyboard or file on hard drive.)

someone please tell me have made egregious oversight somewhere. sense capability has exist. thanks.

this capability not exist. know type variable working with. @ to the lowest degree declared type. polymorphic types must utilize select type actual type, 1 time again know type @ compile time then.

you can utilize gw.d or g0 descriptor universal formatting of intrinsic types. not need think type of number belongs to. user defined derived types there possibility define own i/o routines.

for simple i/o can utilize list-directed i/o, e.g.,

print *, x read(*,*) x write(*,*) x

there restrictions on when can utilize , don't have much command of behavior.

otherwise not think capability must nowadays in oo language. both languages mean (r, python) dynamically typed , hence have much larger need this. in c++98 there typeid() people not need it.

fortran introspection

Comments