>  Docs Center  >  Libraries  >  ASTROLIB  >  STRN

STRN

STRN

Name


STRN

Purpose


Convert a number to a string and remove padded blanks.

Explanation


The main and original purpose of this procedure is to convert a number
to an unpadded string (i.e. with no blanks around it.) However, it
has been expanded to be a multi-purpose formatting tool. You may
specify a length for the output string; the returned string is either
set to that length or padded to be that length. You may specify
characters to be used in padding and which side to be padded. Finally,
you may also specify a format for the number. NOTE that the input
"number" need not be a number; it may be a string, or anything. It is
converted to string.
  CALLING SEQEUNCE:
tmp = STRN( number, [ LENGTH=, PADTYPE=, PADCHAR=, FORMAT = ] )

Input


NUMBER This is the input variable to be operated on. Traditionally,
it was a number, but it may be any scalar type.

Optional Input


LENGTH This KEYWORD specifies the length of the returned string.
If the output would have been longer, it is truncated. If
the output would have been shorter, it is padded to the right
length.
PADTYPE This KEYWORD specifies the type of padding to be used, if any.
0=Padded at End, 1=Padded at front, 2=Centered (pad front/end)
IF not specified, PADTYPE=1
PADCHAR This KEYWORD specifies the character to be used when padding.
The default is a space (' ').
FORMAT This keyword allows the FORTRAN type formatting of the input
number (e.g. '(f6.2)')

Output


tmp The formatted string
  USEFUL EXAMPLES:
print,'Used ',strn(stars),' stars.' ==> 'Used 22 stars.'
print,'Attempted ',strn(ret,leng=6,padt=1,padch='0'),' retries.'
==> 'Attempted 000043 retries.'
print,strn('M81 Star List',length=80,padtype=2)
==> an 80 character line with 'M81 Star List' centered.
print,'Error: ',strn(err,format='(f15.2)')
==> 'Error: 3.24' or ==> 'Error: 323535.22'

History


03-JUL-90 Version 1 written by Eric W. Deutsch
10-JUL-90 Trimming and padding options added (E. Deutsch)
29-JUL-91 Changed to keywords and header spiffed up (E. Deutsch)
Ma7 92 Work correctly for byte values (W. Landsman)
19-NOV-92 Added Patch to work around IDL 2.4.0 bug which caused an
error when STRN('(123)') was encountered. (E. Deutsch)
; Handles array input, M. Sullivan March 2014
      Use V6.0 notation W. Landsman April 2014
      Fix problem with vector strings of different length WL Aug 2014



© 2019 Harris Geospatial Solutions, Inc. |  Legal
My Account    |    Store    |    Contact Us