stuff(3f) - [M_calculator] directly store value into calculator dictionary for efficiency
(LICENSE:PD)
subroutine stuff(varnam,val,ioflag)
class(*),intent(in) :: varnam
character(len=*),intent(in) :: val
integer,intent(in),optional :: ioflag
breaking the rule of only accessing the calculator thru calculator(3f):
a direct deposit of a value into the calculator assumed to
be used only by friendly calls, for efficiency and to avoid
problems with recursion if a routine called by the calculator
in substitute_subroutine(3f) wants to store something back into the calculator
variable table
Normally values are stored or defined in the calculator module
M_calculator(3fm) using the calculator(3f) routine or the convenience
routines in the module M_calculator(3fm). For efficiency when
large numbers of values require being stored the stuff(3f) procedure
can be used to store numeric values by name in the calculator
dictionary.
breaking the rule of only accessing the calculator thru calculator(3f):
stuff(3f) is assumed to only be used when needed for efficiency and to
avoid problems with recursion if a routine called by the calculator
in substitute_subroutine(3f) wants to store something back into the
calculator variable table.
varnam name of calculator variable to define or replace val
numeric value to associate with the name VARNAME. May be
integer, real, or doubleprecision.
ioflag optional flag to use with journal logging. This string is
passed directly to M_framework__journal::journal(3f)
as the first parameter. The default is to not log the
definitions to the journal(3f) command if this parameter is
blank or not present.
Sample program:
program demo_stuff
use M_calculator, only : stuff, dnum0
implicit none
doubleprecision :: value
call stuff('A',10.0)
call stuff('PI',3.1415926535897932384626433832795)
value=dnum0('A*PI')
write(*,*)value
end program demo_stuff
Expected result:
31.415926535897931
John S. Urban
Public Domain
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | varnam | |||
class(*), | intent(in) | :: | value | |||
character(len=*), | intent(in), | optional | :: | ioflag |
subroutine stuff(varnam,value,ioflag) ! ident_14="@(#) M_calculator stuff(3fp) pass key value and integer|real|doubleprecision value to dictionary(3f) as doubleprecision" character(len=*),intent(in) :: varnam ! variable name to add or replace value of class(*),intent(in) :: value character(len=*),intent(in),optional :: ioflag real(kind=dp) :: val8 ! input value to store character(len=:),allocatable :: varnam_local ! some trouble with variable length character strings on some machines integer :: ierr integer :: index integer :: istart !----------------------------------------------------------------------------------------------------------------------------------- varnam_local=adjustl(trim(varnam))//' ' ! remove leading spaces but make sure at least one character long if(varnam_local(1:1).eq.'$')then ! add new variable to numeric value dictionary at specified location mssge='*stuff* numeric variable names must not start with a $' ierr=-1 return endif !----------------------------------------------------------------------------------------------------------------------------------- ierr=0 call locate(keyr_q,varnam_local,index,ierr) istart=iabs(index) if(index.le.0)then ! add entry to dictionary call insert(keyr_q,varnam_local,istart) call insert(values_d,0.0d0,istart) endif select type(value) type is (integer); val8=dble(value) type is (real); val8=dble(value) type is (doubleprecision); val8=value end select call replace(values_d,val8,istart) !----------------------------------------------------------------------------------------------------------------------------------- if(present(ioflag))then ! display values with an assumed variable length of 20 characters so get neat columns write(*,g)ioflag,varnam_local//'=',val8 endif !----------------------------------------------------------------------------------------------------------------------------------- end subroutine stuff