I have defined an enum UNIT as below in fortran and want to print the values as strings instead of numbers.
public :: UNIT,E_TIME_STEP,E_DAY,E_WEEK,E_MONTH,E_YEAR
ENUM , BIND(C)
ENUMERATOR :: UNIT=0
ENUMERATOR :: E_TIME_STEP
ENUMERATOR :: E_DAY
ENUMERATOR :: E_WEEK
ENUMERATOR :: E_MONTH
ENUMERATOR :: E_YEAR
END ENUM
I have a function which reads a string value ("TIME_STEP", "DAY", etc) from a file and returns the corresponding enum value (E_TIME_STEP, E_DAY, etc).
This works properly without any issues during the read. However I don't store the string value anywhere while reading, and after reading I have only the enum value (E_TIME_STEP, E_DAY, etc). While printing it to the console I need to print the string instead of the number. Is it possible to get the string without storing it in the fist place.?
I have added two functions of which one takes the input string ("TIME_STEP, "DAY, etc) and returns the enum name (UNIT) and the second function which takes enum name and enum value (UNIT, 1 to 5) and returns the enum string ("TIME_STEP", "DAY", etc) which doesn't make sense as I am again storing enum name in a local variable. Is it possible to get the string without storing it even locally?