Viewing contents of file '../idllib/contrib/mallozzi/create_string.pro'
;+
; NAME:
;	CREATE_STRING
;
; PURPOSE:
;       Create a STRING of a requested byte length, and optionally 
;       initialize the string.
;
; CATEGORY:
;       Arrays 
;
; CALLING SEQUENCE:
;       myString = CREATE_STRING (nBytes [, value, REPLICATE = replicate])
;
; INPUTS:
;       nBytes (INTEGER) : number of bytes in the string (the string length)
;       value  (STRING)  : optional initial value for the string
;
; INPUT PARAMETERS:
;       NONE
; 
; KEYWORD PARAMETERS:
;       REPLICATE (INTEGER): Create an array of STRINGS of length REPLICATE
;
; OUTPUTS:
;       myString (STRING) : string of the requested length
;
; COMMON BLOCKS:
;	NONE
;
; SIDE EFFECTS:
;       NONE
;
; RESTRICTIONS:
;       If value is set, its length must be LE to nBytes 
;
; MODIFICATION HISTORY:
;
;	RSM, 1998 August, added REPLICATE keyword.
;	Written, Robert.Mallozzi@msfc.nasa.gov, 1998 July.
;-
FUNCTION CREATE_STRING, nBytes, value, REPLICATE = replicate


    IF (nBytes LE 0) THEN BEGIN

       MESSAGE, /CONTINUE, 'Requested length must be > 0.'
       RETURN, ''

    ENDIF

    
    retString = STRING (REPLICATE (32B, nBytes))
    
    IF (N_ELEMENTS (value) NE 0) THEN BEGIN
    
       IF (STRLEN (value) GT STRLEN (retString)) THEN BEGIN
       
	  MESSAGE, /CONTINUE, $
	      'Initial string length (' + $
              STRTRIM (STRLEN (value), 2) + ') ' + $
              'must be <= requested length (' + $
              STRTRIM (STRLEN (retString), 2) + ').'
	  RETURN, ''
       
       ENDIF

       STRPUT, retString, value
              
    ENDIF

    IF (N_ELEMENTS (replicate) NE 0) THEN $
       retString = REPLICATE (retString, replicate)
    
    
    RETURN, retString
    
    
END