Subroutine VSTRNG for program GSAS2CIF

This subroutine is used to make sure that ASCII strings are valid for CIF -- this means only valid ASCII characters. In some cases one does not want to allow spaces in the string and/or in others one does not want a vertical bar (|) in the name. See the gsas2cif documentation for an explanation of this code.

link to documentation
      SUBROUTINE VSTRNG(STRING,LN,NOSPACE,NOBAR)
C subroutine to validate a string to insure there are only ASCII characters
C If NOSPACE is True, spaces are replaced with underscores (_)
C If NOBAR is True, illegal characters (| & slash characters) are replaced with underscores
      CHARACTER*(*) STRING
      INTEGER*4     LN
      LOGICAL*4     NOSPACE
      LOGICAL*4     NOBAR
      IF (NOSPACE) THEN
        DO I = 1,LN            
          IF (ICHAR(STRING(I:I)) .LE. 32 .OR.
     1      ICHAR(STRING(I:I)) .GT. 176) STRING(I:I) = '_'
          IF (NOBAR .AND. (STRING(I:I) .EQ. '|' .OR.
     1      STRING(I:I) .EQ. '/' .OR. STRING(I:I) .EQ. '\\'))
     1      STRING(I:I) = '_'
        END DO
      ELSE
        DO I = 1,LN            
          IF (ICHAR(STRING(I:I)) .LT. 32 .OR.
     1      ICHAR(STRING(I:I)) .GT. 176) STRING(I:I) = '_'
          IF (NOBAR .AND. (STRING(I:I) .EQ. '|' .OR.
     1      STRING(I:I) .EQ. '/' .OR. STRING(I:I) .EQ. '\\'))
     1      STRING(I:I) = '_'
        END DO
      END IF
      RETURN
      END