[UP]


Manual Reference Pages  - tostring (3)

NAME

tostring(3f) - [M_display] change numbers to a string

CONTENTS

Introduction
The Function Tostring
Author

INTRODUCTION

Many programming languages have built-in functions that change numbers to strings. It is possible to achieve a similar effect in Fortran using internal files and list-directed output:

      character(100) s
      real :: x = 1.5
      write(s, *) ’The square of’, x, ’is’, x*x
      print *, trim(s)

but this is cumbersome, and also there is the disadvantage that the result is compiler-dependent. M_display has a function, TOSTRING, which overcomes this disadvantage and offers additional flexibility. With x = 1.5 the following statement will produce the same output as Matlab and Java give:

      CALL DISP(’The square of ’//TOSTRING(X)//’ is ’//TOSTRING(X*X))

TOSTRING accepts integer, logical or real scalars or vectors. The subroutine TOSTRING_SET may be used to change settings for TOSTRING.

THE FUNCTION TOSTRING

Apart from the item to be turned into a string, an edit descriptor to use can optionally be supplied as the second argument to TOSTRING. The two ways to invoke TOSTRING are:

      TOSTRING(X)
      TOSTRING(X, FMT)

These invocations return a character string representing the value of the argument X. When X is a vector individual elements are separated by a string, with the original (or factory) default value ", ". By (original) default G editing is used to convert real numbers, I editing integers, and blanks are trimmed from (each element of) X, both from the left and the right. In addition trailing zeroes are trimmed from the fractional part of real X-elements, as well as a trailing decimal point. The separating string, trimming behavior, and default editing may be changed by calling TOSTRING_SET
X The item to be changed to a string. X may be a scalar or a vector (i.e. of rank 0 or 1) and of one of the following kinds:
        default integer
        default real (i.e. real(1.0), single precision)
        double precision real (i.e. real(1d0))
        default logical

FMT Character string with an edit descriptor used to format each element of X. The possible edit descriptors are given in section 3.1, except that A and Aw can of course not be used. When FMT is absent, a default edit descriptor is used. The default may be set by calling TOSTRING_SET but the original (or factory) defaults are I0 for integers, L1 for logicals and 1PG12.5 for reals.

AUTHOR

Based on dispmodule(3f), "A Fortran 95 module for pretty-printing matrices". Version number 1.02 6-Sept-2008, Kristjan Jonasson, Dept. of Computer Science, University of Iceland (jonasson@hi.is).


tostring (3) March 11, 2021
Generated by manServer 1.08 from ad16d9af-c381-4b71-ae04-3b5a5497c96c using man macros.