value_to_string(3f) - [M_strings:TYPE] return numeric string from a numeric value (LICENSE:PD)
Synopsis
Description
Options
Returns
Examples
Author
License
subroutine value_to_string(value,chars[,lgth,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 :: lgth integer,optional :: ierr character(len=*),intent(in),optional :: fmt logical,intent(in) :: trimz
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.
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.
CHARS returned string representing input value, must be at least 23 characters long; or what is required by optional FMT if longer. LGTH position of last non-blank character in returned string; optional. IERR If not zero, error occurred; optional.
Sample program:
program demo_value_to_string use M_strings, only: value_to_string implicit none character(len=80) :: string integer :: lgth call value_to_string(3.0/4.0,string,lgth) write(*,*) The value is [,string(:lgth),]Expected outputcall value_to_string(3.0/4.0,string,lgth,fmt=) write(*,*) The value is [,string(:lgth),]
call value_to_string& &(3.0/4.0,string,lgth,fmt=("THE VALUE IS ",g0)) write(*,*) The value is [,string(:lgth),]
call value_to_string(1234,string,lgth) write(*,*) The value is [,string(:lgth),]
call value_to_string(1.0d0/3.0d0,string,lgth) write(*,*) The value is [,string(:lgth),]
end program demo_value_to_string
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]
John S. Urban
Public Domain
Nemo Release 3.1 | value_to_string (3m_strings) | January 10, 2025 |