C --- UVSPRD.FOR
C --- To read UVSP data files in IDL.
C --- R. Nakatsuka, 21 Dec 1993.
C
      INTEGER*4 FUNCTION UVSPRD (ARGC, ARGV)
      IMPLICIT INTEGER*4 (A-Z)
      PARAMETER (TYP_INT = 2)
      DIMENSION ARGV(*)
      CHARACTER FILENAME*80
C
      NUMPAR = %LOC(ARGC)
      CALL FOR_GETSTRING (%VAL(ARGV(1)), FILENAME, NUMCHAR)
C
      IF (NUMPAR .EQ. 1) THEN
         UVSPRD = UVSP (FILENAME(:NUMCHAR))
      ELSE
         UVSPRD = UVSP (FILENAME(:NUMCHAR), TEMPVAR)
         IF (UVSPRD .GT. 0)
     &      CALL COPYVAR (%VAL(TEMPVAR), %VAL(ARGV(2)))
      END IF
C
C --- Error handling
      IF (UVSPRD .LT. 1) THEN
C
         IF (UVSPRD .EQ. 0) THEN
            TYPE '('' %UVSPRD-F-UNKNOWNERR, unknown fatal error'')'
         ELSE IF (UVSPRD .EQ. -1) THEN
            TYPE '('' %UVSPRD-E-FNF, file not found - remember,'',
     &             '' default is UVSP$DATA:'')'
         ELSE IF (UVSPRD .EQ. -2) THEN
            TYPE '('' %UVSPRD-E-NOTUVSPFIL, not a UVSP data file'')'
         END IF
C
C ---    Return integer 0
         UVSPRD = FOR_GETTMP (TYP_INT)
         CALL FOR_STORE_SCALAR (%VAL(UVSPRD), TYP_INT, 0)
      END IF
C
      END
