rnum0(3f) - [M_calculator] returns real number from string expression using CALCULATOR(3f)
(LICENSE:PD)
real function rnum0(inline)
character(len=*), intent=(in) :: inline
integer,intent(out),optional :: ierr
RNUM0() is used to return a REAL value from a CHARACTER string representing
a numeric expression. It uses the M_calculator(3fp) module.
inline INLINE is a CHARACTER variable up to (iclen_calc=512) characters long
that is similar to a FORTRAN 77 numeric expression.
ierr error code. If zero, no error occurred
o User-supplied routines:
All programs that call the calculator routine can supply their
own substitute_subroutine(3f) and substitute_C(3f) procedures. See
the example program for samples.
Sample program
program demo_rnum0
use M_calculator, only : rnum0
implicit none
real :: x, y, z
x=rnum0('20/3.4')
y=rnum0('CI = 10 * sin(3.1416/4)')
z=rnum0('CI')
write(*,*)x,y,z
end program demo_rnum0
o The syntax of an expression is as described in the main documentation
of the Calculator Library.
o See EXPRESSION(3f), CALCULATOR(3f), INUM0(3f), DNUM0(3f), SNUM0(3f).
John S. Urban
Public Domain
AUTHOR John S. Urban
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | inline | |||
integer, | intent(out), | optional | :: | ierr |
real function rnum0(inline,ierr) ! ident_17="@(#) M_calculator rnum0(3f) resolve a calculator string into a real number" !----------------------------------------------------------------------------------------------------------------------------------- character(len=*),intent(in) :: inline integer,optional,intent(out) :: ierr !----------------------------------------------------------------------------------------------------------------------------------- character(len=iclen_calc) :: cdum20 doubleprecision :: d_answer integer :: ierr_local integer :: ilen integer :: iend !----------------------------------------------------------------------------------------------------------------------------------- ierr_local=0 if(inline.eq.' ')then d_answer=0.0d0 elseif(inline.eq.'*')then ! the special string '*' returns -99999.0 d_answer=-99999.0d0 else iend=len(inline) call expression(inline(:iend),d_answer,cdum20,ierr_local,ilen) if(ierr_local.ne.0)then d_answer=0.0d0 endif endif if(present(ierr))then ierr=ierr_local endif rnum0=real(d_answer) !----------------------------------------------------------------------------------------------------------------------------------- end function rnum0