      SUBROUTINE QUIKVIS1(IDTARG,TARGNAMES,KTARGTYP,TARGPARM,IERR)
      IMPLICIT REAL*8 (A-H,O-Z)
C
C THIS ROUTINE IS PART OF THE QUIKVIS PROGRAM.  IT LOADS THE
C IDTARG, TARGNAMES, AND TARGPARM ARRAYS VIA AN INTERNAL ALGORITHM(WHEN
C THE SURVEY OPTION IS ON) OR VIA THE TOSS TARGET CATALOGUE READER.
C
C
C VARIABLE      DIM       TYPE I/O DESCRIPTION
C --------      ---       ---- --- -----------
C
C IDTARG      MAXTARGS     I*4  I  DESCRIBED IN QUIKVIS(=MAIN) PROLOGUE.
C
C TARGNAMES   MAXTARGS    CH*16 I  DESCRIBED IN QUIKVIS(=MAIN) PROLOGUE.
C
C KTARGTYP    MAXTARGS     I*4  I  DESCRIBED IN QUIKVIS(=MAIN) PROLOGUE.
C
C TARGPARM NPARMS,MAXTARGS R*8  I  DESCRIBED IN QUIKVIS(=MAIN) PROLOGUE.
C
C IERR           1         I*4  O  ERROR RETURN FLAG
C                                  =0, NO ERROR
C                                  =OTHERWISE, ERROR.
C
C***********************************************************************
C
C BY C PETRUZZO/GFSC/742.   2/86.
C       MODIFIED....
C
C***********************************************************************
C
      INCLUDE 'QUIKVIS.INC'
C
      CHARACTER*16 TARGNAMES(MAXTARGS)
      INTEGER*4 IDTARG(MAXTARGS)
      INTEGER*4 KTARGTYP(MAXTARGS)
C
C    TARGPARM ARRAY DOES DOUBLE DUTY.  (1) ON THE CALL TO RDCAT, IT IS
C    THE ARRAY INTO WHICH ALL TARGET PARAMETERS ARE LOADED; HENCE, THE
C    FIRST DIMENSION MUST BE LARGE ENOUGH TO HOLD ALL PARAMETER VALUES
C    PRESENT IN THE CATALOGUE; (2) AFTER RDCAT RETURNS, THE 3RD, 4TH,
C    AND 5TH PARAMETER POSITIONS ARE LOADED WITH UNIT VECTORS(ZEROS IF
C    TARGET IS MOVING).
      REAL*8 TARGPARM(NPARMS,MAXTARGS)
C
      CHARACTER*18 DATETIME
C
C
      IERR = 0
C
C
      CALL QUIKVIS999(-1,R8DATA,I4DATA,L4DATA)
C
C
C ******************************************************
C * FOR SURVEY OPTION, DEFINE STAR NAMES AND LOCATIONS *
C ******************************************************
C
C
C IF THE SURVEY OPTION IS ON, THE TARGET CATALOGUE IS NOT READ.
C TARGNAMES, TARGPARM, AND KTARGTYP ARE SET HERE.
C
      IF(DOSURVEY) THEN
        DELRA = TWOPI/(NRASURVEY-1)
        DELDEC = PI/(NDECSURVEY-1)
        ITARG = 0
        DO IDEC=1,NDECSURVEY
          DEC = HALFPI - (IDEC-1)*DELDEC
          DO IRA=1,NRASURVEY
            RA = (IRA-1)*DELRA
            ITARG = ITARG + 1
            TARGNAMES(ITARG) = 'SURVEY OPTION'
            TARGPARM(1,ITARG) = RA
            TARGPARM(2,ITARG) = DEC
            CALL XYZSPH(1,RA,DEC,1.D0,TARGPARM(3,ITARG),1.D0)  !UNIT VEC
            KTARGTYP(ITARG) = 3  ! FIXED TARGET
            END DO
          END DO
        GO TO 9999
        END IF
C
C
C
C *******************************************************************
C *  IF SURVEY OPTION IS OFF, READ TARGET CATLG FOR SPECIFIC TARGS  *
C *******************************************************************
C
C
C  READ TARGET INFORMATION FROM THE CATALOGUE:
C
      WRITE(LUPROMPT,5) DATETIME(0)
    5 FORMAT(/,' READING CATALOGUE INFORMATION.   ',A/)
      CALL RDCAT(LUCATLG,MAXTARGS,IDTARG,TARGNAMES,KTARGTYP,NPARMS,
     *              TARGPARM,NFOUND,0,LUERR,IER1)
      WRITE(LUPROMPT,6) DATETIME(0)
    6 FORMAT(/,' END READING CATALOGUE INFORMATION.   ',A/)
C
      IF(IER1 .NE. 0) THEN
        IERR = 1
        WRITE(LUERR,*) ' QUIKVIS1. TARGET CATALOGUE ERROR.'
        GO TO 9999
        END IF
C
C ERROR CHECK. ALL TARGETS FOUND ?
C
      IF(NUMTARGS.NE.NFOUND) THEN
        IERR = 1
        WRITE(LUERR,*)
     *     ' QUIKVIS1. SOME TARGETS ARE ABSENT FROM THE CATALOGUE.'
        GO TO 9999
        END IF
C
C ERROR CHECK. ARE ALL ENTRIES FIXED CELESTIAL OR MOVING CELESTIAL ?
C
      DO I=1,NUMTARGS
        IF(KTARGTYP(I).NE.3 .AND. KTARGTYP(I).NE.1) THEN
          IERR = 1
          WRITE(LUERR,8001) IDTARG(I)
 8001     FORMAT(/,
     *      ' QUIKVIS1 ERROR. NON-CELESTIAL TARGET SPECIFIED.   ID=',I5)
          END IF
        END DO
      IF(IERR.NE.0) GO TO 9999
C
C ALL IS OK. PUT UNIT VECTOR IN TARGPARM IF THE TARGET IS FIXED, ZEROS
C IF MOVING. IF MOVING, SET THE NEEDTIME VARIABLE TO .TRUE.
C
        DO ITARG=1,NUMTARGS
          IF(KTARGTYP(ITARG).EQ.3) THEN
            CALL XYZSPH(1,TARGPARM(1,ITARG),TARGPARM(2,ITARG),1.D0,
     *           TARGPARM(3,ITARG),1.D0)
          ELSE
            NEEDTIME = .TRUE.
            DO I=1,5
              TARGPARM(I,ITARG) = 0.D0
              END DO
            END IF
          END DO
C
C
C WRAP UP. STORE NEEDTIME IN QUIKVIS999 ARRAYS FOR RETRIEVAL ELSEWHERE.
C
      CALL QUIKVIS999(1,R8DATA,I4DATA,L4DATA)
C
C
 9999 CONTINUE
      RETURN
      END
