* Last processed by NICE on 12-Jun-2000 15:53:00
* Customized for :  IEEE, LINUX, UNIX, MOTIF, F77
C     $Header: /scisoft/gildas/sou/nic/main/nic_load.for,v 1.65 2000/02/17 17:21:05 neri Exp $
C     $Log: nic_load.for,v $
C     Revision 1.65  2000/02/17 17:21:05  neri
C     *** empty log message ***
C
C Revision 1.64  2000/02/10  11:24:38  11:24:38  broguier (Dominique Broguiere)
C new options for CHECK and SOLVE commands
C
C Revision 1.63  2000/01/07  09:25:40  09:25:40  broguier ()
C modify SIC_LOAD call :
C CALL SIC_LOAD('NIC','GAG_HELP_NIC',MCOM1,CCOM,VERS)
C to solve pb with command HELP
C
C Revision 1.62  98/12/10  12:42:38  12:42:38  neri (Roberto Neri)
C *** empty log message ***
C
C Revision 1.61  98/11/27  16:44:43  16:44:43  broguier ()
C add option for command SOLVE
C
C Revision 1.59  98/03/09  11:17:03  11:17:03  neri (Roberto Neri)
C icode = 0 / solve /all
C
C Revision 1.58  98/03/04  11:39:54  11:39:54  perrigou (Alain  Perrigouard)
C 3rd argument added to thelp()
C
C Revision 1.57  98/01/29  04:06:53  04:06:53  broguier (Dominique Broguiere)
C new commands POWER and VERSION
C
C Revision 1.56  98/01/20  18:16:44  18:16:44  broguier ()
C add option /GAUSS
C
C Revision 1.55  97/12/18  15:32:40  15:32:40  broguier (Dominique Broguiere)
C  add CALPOW variables
C
C Revision 1.47  96/11/29  02:46:00  02:46:00  gildas (Gildas manager)
C *** empty log message ***
C
C Revision 1.43  96/07/09  10:04:44  10:04:44  neri (Roberto Neri)
C *** empty log message ***
C
C Revision 1.39  96/03/19  15:33:00  15:33:00  gildas (Gildas manager)
C nic_version.f replaced by nic_version.inc . Sorry but needed on MAC.
C
C Revision 1.38  1996/03/19  14:59:07  broguier
C SAVE_GAINS before RUN_NIC
C
*
      SUBROUTINE LOAD_NIC
*
      LOGICAL   ERROR
      INTEGER MCOM1
      PARAMETER (MCOM1=78)
*
      CHARACTER VERS*50
      INCLUDE 'nic_version.inc'
      CHARACTER*12 CCOM(MCOM1)
      CHARACTER BACKSLASH*1
      BACKSLASH = CHAR(92)
*
* Language initialisation
*
      DATA CCOM/
     $' CHECK','/REPAIR',
     $' BASELINE','/CHANNEL','/ORDER','/NOISE',
     $'/BYSUBSCAN','/SUPPORT','/FILE','/CORR','/PENCIL',
     $' DESPIKE','/CHANNEL','/FUNCTION','/XRMS','/WINDOW',
     $'/ITERATION','/INTERPOLATE',
     $' FIELD','/SMEAR','/DECL','/SIZE','/HOUR',
     $'/NOFRAME','/SKEW','/NMB','/NOISE',
     $' FILE',
     $' FIND','/SCAN','/EXTEN','/FILE','/TYPE','/SOURCE','/WAIT',
     $'/APPEND',
     $' FLAG','/CHANNEL','/RESET','/SUBSCAN',
     $' FIT','/CHANNEL','/INPUT','/FUNCTION','/FILE','/LEVEL',
     $' GET',
     $' HEADER','/FILE',
     $' LIST','/SUBSCAN',
     $' POWER','/SCAN',
     $' SET','/CHANNEL','/DEFAULT',
     $' SHOW',
     $' SIMULATE','/SCAN','/INPUT','/GAUSS',
     $' SOLVE','/CHANNEL','/FILE','/ALL','/BEAM','/TRUNCATE','/ITER',
     $'/RADIUS','/BAND',
     $' SUPPORT','/CURSOR','/FILE','/INPUT','/CHANNEL','/DELETE',
     $' VARIABLES',
     $' VERSION'/
*
      CALL SIC_LOAD('NIC','GAG_HELP_NIC',MCOM1,CCOM,VERS)
      CALL SIC_SETSYMBOL('INFO','type news',ERROR)
      CALL SIC_SETSYMBOL('SET','NIC'//BACKSLASH//'SET',ERROR)
      CALL SIC_SETSYMBOL('SH','NIC'//BACKSLASH//'SHOW',ERROR)
      CALL SIC_SETSYMBOL('SHO','NIC'//BACKSLASH//'SHOW',ERROR)
      CALL SIC_SETSYMBOL('SHOW','NIC'//BACKSLASH//'SHOW',ERROR)
      RETURN
      END
*<FF>
      SUBROUTINE EXEC_NIC(BUFFER)
      INCLUDE 'nic.inc'
      INCLUDE 'parameter.inc'
      INCLUDE 'par.inc'
*
      CHARACTER LINE*255,COMM*12,LANG*12
      CHARACTER*(*) BUFFER
      INTEGER ICODE, OCODE
      LOGICAL ERROR,GTERRTST
*
      LINE = BUFFER
      ICODE = -1
      GOTO 10
*
      ENTRY PLAY_NIC(BUFFER)
      LINE = BUFFER
      ICODE = 2
      GOTO 10
*
      ENTRY ENTER_NIC
      ICODE = 1
*
10    CALL SIC_RUN (LINE,LANG,COMM,ERROR,ICODE,OCODE)
      IF (OCODE.EQ.-1) RETURN
      IF (OCODE.EQ.1) THEN
         CALL GTVIEW('Append')
         RETURN
      ENDIF
      ICODE = 0
      CALL CHECK_RUN(.FALSE.)
      IF (LANG.EQ.'GREG1') THEN
         CALL RUN_GREG1(LINE,COMM,ERROR)
      ELSEIF (LANG.EQ.'GREG2') THEN
         CALL RUN_GREG2(LINE,COMM,ERROR)
      ELSEIF (LANG.EQ.'NIC') THEN
         CALL SAVE_GAINS                 ! apply gain before any NIC command
         CALL RUN_NIC(LINE,COMM,ERROR)
         CALL SAVE_GAINS                 ! useful only for command SET
      ELSEIF (LANG.EQ.'VECTOR') THEN
         CALL RUN_VECTOR(LINE,COMM,ERROR)
      ELSEIF (LANG.EQ.'GTVL') THEN
         CALL RUN_GTVL(LINE,COMM,ERROR)
      ELSEIF (LANG.EQ.'TASK') THEN
         IF (COMM.EQ.'HELP') THEN
            CALL THELP(LINE,ERROR,0)     ! task help
         ELSE
            WRITE(6,'(a)') 'E-NIC,   Command invalid in this context'
            ERROR = .TRUE.
         ENDIF
      ELSE
         WRITE(6,'(a)') 'E-NIC,  Unknown language '//LANG
         ERROR = .TRUE.
      ENDIF
      ERROR = ERROR .OR. GTERRTST()
      CALL CHECK_RUN(.TRUE.)
c      IF ((INDEX(LINE(1:LENC(LINE)),'SHOW').NE.0).OR.
c     $(INDEX(LINE(1:LENC(LINE)),'SET').NE.0)) THEN
c         ERROR = .FALSE.                 ! to avoid problems rn 21-jan-94
c      ENDIF
      GOTO 10
      END
*<FF>
      SUBROUTINE EXEC_ALL(BUFFER)
      INCLUDE 'nic.inc'
      INCLUDE 'parameter.inc'
      INCLUDE 'par.inc'
*
      CHARACTER LINE*255,COMM*12,LANG*12
      CHARACTER*(*) BUFFER
      INTEGER ICODE, OCODE
      LOGICAL ERROR,GTERRTST
*
      LINE = BUFFER
      ICODE = -1
*
      CALL SIC_RUN (LINE,LANG,COMM,ERROR,ICODE,OCODE)
      IF (OCODE.EQ.-1) RETURN
      IF (OCODE.EQ.1) THEN
         CALL GTVIEW('Append')
         RETURN
      ENDIF
      CALL CHECK_RUN(.FALSE.)
      IF (COMM.EQ.'FILE') THEN
         CALL FILE (LINE,ERROR)
         ICODE = 0
         CALL SIC_RUN (LINE,LANG,COMM,ERROR,ICODE,OCODE)
      ENDIF
      ERROR = ERROR .OR. GTERRTST()
      CALL CHECK_RUN(.TRUE.)
      END
*<FF>
      SUBROUTINE SAVE_GAINS
      INCLUDE 'nic.inc'
      INCLUDE 'parameter.inc'
      INCLUDE 'par.inc'
*
      LOGICAL NEW_GAIN, COMPARE
*
      IF (IADDRRECORD.NE.0) THEN
         IF (FIRST_SAVE) THEN
            CALL R4TOR4 (MEMORY(IP_GAIN),BEAM_GAIN(1),NCHAN)
            FIRST_SAVE = .FALSE.
         ENDIF
         NEW_GAIN = COMPARE (MEMORY(IP_GAIN),BEAM_GAIN(1))
         IF (GAIN_RECEIVER_FLAG.AND.NEW_GAIN) THEN
            CALL MESSAGE (2,1,'GAIN',
     $      'Modified channel gain corrections enabled ..')
            IF (JY_TO_COUNTS.NE.0) CALL MESSAGE (2,1,'JANSKY',
     $      'Beware: The counts/Jy factor might have changed...')
            GAIN_REC = .TRUE.
            CALL DO_GR (MEMORY(IP_SIGNAL),BEAM_GAIN(1))
            CALL R4TOR4 (MEMORY(IP_GAIN),BEAM_GAIN(1),NCHAN)
            GAIN_REC = .FALSE.
            CALL DO_GR (MEMORY(IP_SIGNAL),BEAM_GAIN(1))
         ELSE
            CALL R4TOR4 (MEMORY(IP_GAIN),BEAM_GAIN(1),NCHAN)
         ENDIF
      ENDIF
      RETURN
      END
*<FF>
      FUNCTION COMPARE (BUF1, BUF2)
      INCLUDE 'nic.inc'
      INCLUDE 'parameter.inc'
      INCLUDE 'par.inc'
      LOGICAL COMPARE
      INTEGER I
      REAL*4  BUF1(1), BUF2(1)
*
      COMPARE = .FALSE.
      DO I=1,NCHAN
         IF (BUF1(I).NE.BUF2(I)) COMPARE = .TRUE.
      ENDDO
      RETURN
      END
