C Library Functions  - cpad (3)

NAME

cpad(3f) - [M_strings:LENGTH] convert to a cropped string and then centers the string to specified length (LICENSE:PD)

CONTENTS

Synopsis
Description
Options
Returns
Example
Author
License

SYNOPSIS

function cpad(valuein,length) result(strout)

    class*,intent(in)       :: valuein(..)
    integer,intent(in)      :: length

DESCRIPTION

cpad(3f) converts a scalar value to a cropped string and then pads it with spaces to center it to at least the specified length. If the trimmed input is longer than the requested length the string is returned trimmed of leading and trailing spaces.

OPTIONS

str The input may be scalar or a vector. the input value to return as a string, padded with spaces to center it at the the specified length if shorter than length. The input may be any intrinsic scalar which is converted to a cropped string much as if written with list-directed output.
length The minimum string length to return

RETURNS

strout The input string center-padded to the requested length with spaces.

EXAMPLE

Sample Program:

     program demo_cpad
      use M_strings, only : cpad
      implicit none
         write(*,’("[",a,"]")’) cpad( ’my string’, 20)
         write(*,’("[",a,"]")’) cpad( ’my string   ’, 20)
         write(*,’("[",a,"]")’) cpad( ’   my string’, 20)
         write(*,’("[",a,"]")’) cpad( ’   my string   ’, 20)
         write(*,’("[",a,"]")’) cpad( valuein=42 , length=7)
         write(*,’("[",a,"]")’) cpad( valuein=1.0/9.0 , length=20)
     end program demo_cpad

AUTHOR

John S. Urban

LICENSE

Public Domain


Nemo Release 3.1 cpad (3) July 22, 2023
Generated by manServer 1.08 from ac57bc4f-fbff-42fc-88cf-3923112454c3 using man macros.