shortcuts:
fmt set stderr str wrt


 INDEX


Manual Reference Pages  - fmt (3m_msg)

NAME

fmt(3f) - [M_msg] convert any intrinsic to a string using specified format (LICENSE:PD)

CONTENTS

Synopsis
Description
Options
Returns
Examples
Author
License

SYNOPSIS

function fmt(value,format) result(string)

    class(*),intent(in),optional :: value
    character(len=*),intent(in),optional  :: format
    character(len=:),allocatable :: string

DESCRIPTION

FMT(3f) converts any standard intrinsic value to a string using the specified format.

OPTIONS

value value to print the value of. May be of type INTEGER, LOGICAL, REAL, DOUBLEPRECISION, COMPLEX, or CHARACTER.
format format to use to print value. It is up to the user to use an appropriate format. The format does not require being surrounded by parenthesis. If not present a default is selected similar to what would be produced with free format.

RETURNS

string A string value

EXAMPLES

Sample program:

    program demo_fmt
    use :: M_msg, only : fmt
    implicit none
    character(len=:),allocatable :: output

output=fmt(10,"’[’,i0,’]’") write(*,*)’result is ’,output

output=fmt(10.0/3.0,"’[’,g0.5,’]’") write(*,*)’result is ’,output

output=fmt(.true.,"’The final answer is [’,g0,’]’") write(*,*)’result is ’,output

end program demo_fmt

Results:

    result is [10]
    result is [3.3333]
    result is The final answer is [T]

AUTHOR

John S. Urban

LICENSE

Public Domain





 INDEX


Manual Reference Pages  - set (3m_msg)

NAME

set(3f) - [M_msg] set scalars from an array (LICENSE:PD)

CONTENTS

Synopsis
Description
Options
Examples
Author
License

SYNOPSIS

Syntax:

     function set(g0,g1,g2,g3,g4,g5,g6,g7,g8,g9,&
     & ga,gb,gc,gd,ge,gf,gg,gh,gi,gj,gk)
     class(*),intent(in)           :: g0
     class(*),intent(out),optional  :: g1,g2,g3,g4,g5,g6,g7,g8,g9,ga
     class(*),intent(out),optional  :: gb,gc,gd,ge,gf,gg,gh,gi,gj,gk

DESCRIPTION

set(3f) sets up to twenty scalars to elements from an array. Sort of like an equivalence.

OPTIONS

g0(:) array to read values from. Can be of type INTEGER or REAL
g[1-9a-k]
  optional values to set to an array element. Can be of type INTEGER or REAL

EXAMPLES

Sample program:

   program demo_set
   use,intrinsic :: iso_fortran_env, only : int8, int16, int32, int64
   use,intrinsic :: iso_fortran_env, only : real32, real64, real128
   use M_msg, only : set
   implicit none
   real(kind=real32)    :: a; namelist /all/a
   real(kind=real64)    :: b; namelist /all/b
   real(kind=real128)   :: c; namelist /all/c
   integer(kind=int8)   :: i; namelist /all/i
   integer(kind=int16)  :: j; namelist /all/j
   integer(kind=int32)  :: k; namelist /all/k
   integer(kind=int64)  :: l; namelist /all/l
   integer              :: iarr(7)=[1,2,3,4,5,6,7]
      call set(iarr,a,b,c,i,j,k,l)
      write(*,nml=all)
      call set(10,a)
      call set(100,l)
      write(*,nml=all)
   end program demo_set

Results:

    &ALL
    A       =   1.000000    ,
    B       =   2.00000000000000     ,
    C       =   3.00000000000000000000000000000000      ,
    I       =    4,
    J       =      5,
    K       =           6,
    L       =                     7
    /
    &ALL
    A       =   10.00000    ,
    B       =   2.00000000000000     ,
    C       =   3.00000000000000000000000000000000      ,
    I       =    4,
    J       =      5,
    K       =           6,
    L       =                   100
    /

AUTHOR

John S. Urban

LICENSE

Public Domain





 INDEX


Manual Reference Pages  - stderr (3m_msg)

NAME

stderr(3f) - [M_msg] write message to stderr (LICENSE:PD)

CONTENTS

Synopsis
Description
Options
Examples
Author
License

SYNOPSIS

subroutine stderr(msg,[generic])

    class(*),intent(in),optional :: msg
    class(*),intent(in),optional :: generic0,generic1,generic2,generic3,generic4
    class(*),intent(in),optional :: generic5,generic6,generic7,generic8,generic9

DESCRIPTION

STDERR(3f) writes a message to standard error using a standard f2003 method. Up to ten generic options are available.

OPTIONS

msg - description to print
generic[0-9]
  - optional value to print the value of after the message. May be of type INTEGER, LOGICAL, REAL, DOUBLEPRECISION, COMPLEX, or CHARACTER.

EXAMPLES

Sample program:

   program demo_stderr
   use,intrinsic :: iso_fortran_env, only : int8, int16, int32, int64
   use,intrinsic :: iso_fortran_env, only : real32, real64, real128
   use,intrinsic :: iso_fortran_env, only : real=> real32, integer=> int32
   use M_msg, only: stderr
   implicit none

call stderr(’A simple message’) call stderr(’error: RVALUE=’,3.0/4.0) call stderr(’error: IVALUE=’,123456789) call stderr(’error: LVALUE=’,.true.)

SEVERAL: block integer :: least=10, most=999, ival=-10 call stderr(’error: value’,ival,’should be between’,least,’and’,most) endblock SEVERAL

call stderr(’real32 :’,huge(0.0_real32),0.0_real32,12345.6789_real32,tiny(0.0_real32)) call stderr(’real64 :’,huge(0.0_real64),0.0_real64,12345.6789_real64,tiny(0.0_real64)) !#ifdef __NVCOMPILER !#else call stderr(’real128 :’,huge(0.0_real128),0.0_real128,12345.6789_real128,tiny(0.0_real128)) !#endif call stderr(’complex :’,cmplx(huge(0.0_real),tiny(0.0_real)))

call stderr(’error: program will now stop’) stop 1

end program demo_stderr

Results: A simple message error: RVALUE= 0.750000000 error: IVALUE= 123456789 error: LVALUE= T error: value -10 should be between 10 and 999
real32 : 3.40282347E+38 ... 0.00000000 ... 12345.6787 ... 1.17549435E-38
real64 : 1.7976931348623157E+308 ... 0.0000000000000000 ... 12345.678900000001 ... 2.2250738585072014E-308 real128 : 1.18973149535723176508575932662800702E+4932 ...
0.00000000000000000000000000000000000
  ... 12345.6789000000000000000000000000002 ... 3.36210314311209350626267781732175260E-4932 complex : (3.40282347E+38,1.17549435E-38) error: program will now stop STOP 1

AUTHOR

John S. Urban

LICENSE

Public Domain





 INDEX


Manual Reference Pages  - str (3m_msg)

NAME

str(3f) - [M_msg] converts up to twenty standard scalar type values to a string (LICENSE:PD)

CONTENTS

Synopsis
Description
Options
Returns
Examples
Author
License

SYNOPSIS

Syntax:

     pure function str(g0,g1,g2,g3,g4,g5,g6,g7,g8,g9,&
     & ga,gb,gc,gd,ge,gf,gg,gh,gi,gj,sep)
     class(*),intent(in),optional  :: g0,g1,g2,g3,g4,g5,g6,g7,g8,g9
     class(*),intent(in),optional  :: ga,gb,gc,gd,ge,gf,gg,gh,gi,gj
     character(len=*),intent(in),optional :: sep
     character,len=(:),allocatable :: str

DESCRIPTION

str(3f) builds a space-separated string from up to twenty scalar values.

OPTIONS

g[0-9a-j]
  optional value to print the value of after the message. May be of type INTEGER, LOGICAL, REAL, DOUBLEPRECISION, COMPLEX, or CHARACTER.

Optionally, all the generic values can be single-dimensioned arrays. Currently, mixing scalar arguments and array arguments is not supported.

sep separator string used between values. Defaults to a space.

RETURNS

str description to print

EXAMPLES

Sample program:

   program demo_str
   use M_msg, only : str
   implicit none
   character(len=:),allocatable :: pr
   character(len=:),allocatable :: frmt
   integer                      :: biggest

pr=str(’HUGE(3f) integers’,huge(0),& &’and real’,huge(0.0),’and double’,huge(0.0d0)) write(*,’(a)’)pr pr=str(’real :’,huge(0.0),0.0,12345.6789,tiny(0.0) ) write(*,’(a)’)pr pr=str(’doubleprecision :’,huge(0.0d0),0.0d0,12345.6789d0,tiny(0.0d0) ) write(*,’(a)’)pr pr=str(’complex :’,cmplx(huge(0.0),tiny(0.0)) ) write(*,’(a)’)pr

! create a format on the fly biggest=huge(0) frmt=str(’(*(i’,int(log10(real(biggest))),’:,1x))’,sep=’’) write(*,*)’format=’,frmt

! although it will often work, using str(3f) ! in an I/O statement is not recommended ! because if an error occurs str(3f) will try ! to write while part of an I/O statement ! which not all compilers can handle and is currently non-standard write(*,*)str(’program will now stop’)

end program demo_str

Output

   HUGE(3f) integers 2147483647 and real 3.40282347E+38 and double 1.7976931348623157E+308
   real            : 3.40282347E+38 0.00000000 12345.6787 1.17549435E-38
   doubleprecision : 1.7976931348623157E+308 0.0000000000000000 12345.678900000001 2.2250738585072014E-308
   complex         : (3.40282347E+38,1.17549435E-38)
    format=(*(i9:,1x))
    program will now stop

AUTHOR

John S. Urban

LICENSE

Public Domain





 INDEX


Manual Reference Pages  - wrt (3m_msg)

NAME

wrt(3f) - [M_msg] write multiple scalar values to any number of files (LICENSE:PD)

CONTENTS

Synopsis
Description
Options
Returns
Examples
Author
License

SYNOPSIS

subroutine wrt(luns,generic(s),iostat)

    integer,intent(in)           :: luns(:)
    class(*),intent(in),optional :: generic0,generic1,generic2,generic3,generic4
    class(*),intent(in),optional :: generic5,generic6,generic7,generic8,generic9
    class(*),intent(in),optional :: generica,genericb,genericc,genericd,generice
    class(*),intent(in),optional :: genericf,genericg,generich,generici,genericj
    integer,intent(out),optional :: ios

DESCRIPTION

WRT(3f) writes a list of scalar values
  to the list of unit numbers in LUNS(:).

OPTIONS

LUNS Unit numbers to write to. If of size zero no output is generated
generic[1-20]
  optional value to print the value of after the message. May be of type INTEGER, LOGICAL, REAL, DOUBLEPRECISION, COMPLEX, or CHARACTER.

RETURNS

IOSTAT The value of the last non-zero IOSTAT value. Returns zero if no errors occurred.

EXAMPLES

Sample program:

   program demo_wrt
   use, intrinsic :: iso_fortran_env, only : &
    & stdin=>input_unit, &
    & stdout=>output_unit, &
    & stderr=>error_unit
   use M_msg, only: wrt, fmt
   implicit none
   integer,allocatable :: luns(:)
   integer :: iostat=0
   integer,parameter :: ints(3)=[1,2,3]

! a null list allows for turning off verbose or debug mode output luns=[integer ::] call wrt(luns,’NULL LIST:’,huge(0),’PI=’,asin(1.0d0)*2.0d0,iostat=iostat) write(*,*)’IOSTAT=’,iostat

! multiple files can be used to create a log file, for example luns=[stderr,stdout] call wrt(luns,’TWO FILES:’,huge(0),’PI=’,asin(1.0d0)*2.0d0,iostat=iostat) write(*,*)’IOSTAT=’,iostat

! using fmt call wrt([stdout,stdout,stdout],’USING FMT :’, & & huge(0),’PI=’,asin(1.0d0)*2.0d0,fmt(ints(2),’i0.4’),iostat=iostat)

end program demo_wrt

TWO FILES: 2147483647 PI= 3.1415926535897931 TWO FILES: 2147483647 PI= 3.1415926535897931
IOSTAT=
  USING FMT : 2147483647 PI= 3.1415926535897931 0002 USING FMT : 2147483647 PI= 3.1415926535897931 0002 USING FMT : 2147483647 PI= 3.1415926535897931 0002
IOSTAT=
 

AUTHOR

John S. Urban

LICENSE

Public Domain




Themes: