[UP]


Manual Reference Pages  - value_to_string (3)

NAME

value_to_string(3f) - [M_strings:NUMERIC] return numeric string from a numeric value (LICENSE:PD)

CONTENTS

Synopsis
Description
Options
Returns
Example
Author
License

SYNOPSIS

subroutine value_to_string(value,chars[,ilen,ierr,fmt,trimz])

    character(len=*) :: chars  ! minimum of 23 characters required
    !--------
    ! VALUE may be any <em>one</em> of the following types:
    doubleprecision,intent(in)               :: value
    real,intent(in)                          :: value
    integer,intent(in)                       :: value
    logical,intent(in)                       :: value
    !--------
    character(len=*),intent(out)             :: chars
    integer,intent(out),optional             :: ilen
    integer,optional                         :: ierr
    character(len=*),intent(in),optional     :: fmt
    logical,intent(in)                       :: trimz

DESCRIPTION

value_to_string(3f) returns a numeric representation of a numeric value in a string given a numeric value of type REAL, DOUBLEPRECISION, INTEGER or LOGICAL. It creates the string using internal writes. It then removes trailing zeros from non-zero values, and left-justifies the string.

OPTIONS

VALUE input value to be converted to a string
FMT You may specify a specific format that produces a string up to the length of CHARS; optional.
TRIMZ If a format is supplied the default is not to try to trim trailing zeros. Set TRIMZ to .true. to trim zeros from a string assumed to represent a simple numeric value.

RETURNS

CHARS returned string representing input value, must be at least 23 characters long; or what is required by optional FMT if longer.
ILEN position of last non-blank character in returned string; optional.
IERR If not zero, error occurred; optional.

EXAMPLE

Sample program:

     program demo_value_to_string
     use M_strings, only: value_to_string
     implicit none
     character(len=80) :: string
     integer           :: ilen
        call value_to_string(3.0/4.0,string,ilen)
        write(*,*) ’The value is [’,string(:ilen),’]’

call value_to_string(3.0/4.0,string,ilen,fmt=’’) write(*,*) ’The value is [’,string(:ilen),’]’

call value_to_string(3.0/4.0,string,ilen,fmt=’("THE VALUE IS ",g0)’) write(*,*) ’The value is [’,string(:ilen),’]’

call value_to_string(1234,string,ilen) write(*,*) ’The value is [’,string(:ilen),’]’

call value_to_string(1.0d0/3.0d0,string,ilen) write(*,*) ’The value is [’,string(:ilen),’]’

end program demo_value_to_string

Expected output

    The value is [0.75]
    The value is [      0.7500000000]
    The value is [THE VALUE IS .750000000]
    The value is [1234]
    The value is [0.33333333333333331]

AUTHOR

John S. Urban

LICENSE

Public Domain


value_to_string (3) October 17, 2020
Generated by manServer 1.08 from 5f9985c3-46e3-49f1-a936-60109d2cb059 using man macros.