fortran - Check the input data type and whether it is empty or null -
i asking user give value @ run time calculations.
- i want test if user entered value real/integer number, , if not give warning program expecting real/integer number here.
- in addition, know how check if particular variable @ moment null or empty. i.e. have declared variable if @ time of calculation value null or empty or not yet set, in case, program shouldn't crash instead give warning provide correct value.
both these operations more easier in c++ , c#, couldn't find way in fortran.
i guess "null or empty" mean whether variable has been initialized: "not yet set". "null" has particular meaning fortran pointer variables, suppose not question. fortran doesn't automatically give variables special value before intentionally initialized there no easy way check whether variable has been initialized. 1 approach initialize variable declaration special value. means need know special value never obtain in operation of program. 1 possibility use huge
intrinsic:
program testvar real :: avar = huge (1.0) if ( avar < huge (1.0) ) write (*, *) "test 1: good" else write (*, *) "test 1: bad" end if avar = 2.2 if ( avar < huge (1.0) ) write (*, *) "test 2: good" else write (*, *) "test 2: bad" end if end program testvar
as warned @arbautjc, works once, in subroutine. in procedure, initialization declaration done first call. also, if change variable type example, sure understand how huge
works (e.g., long ints in fortran).
Comments
Post a Comment