      INCLUDE 'VICMAIN_FOR'

      SUBROUTINE MAIN44

C-----PROGRAM LABSWTCH                  LABSWTCH (A,B) C SIZE
C-----THIS PROGRAM WILL OUTPUT THE DATA OF THE 2ND INPUT WITH
C-----THE USER LABELS OF THE 1ST INPUT, AND THE SYSTEM LABEL
C-----DETERMINED BY THE 2ND INPUT OR THE SIZE FIELD.
C-----IF THE 1ST AND 2ND INPUTS ARE NOT THE SAME SIZE, THE SIZE
C-----FIELD MUST BE USED OR THE OUTPUT MUST BE PREALLOCATED.


C   REVISION HISTORY
C      3-87   SP  ADDED XVSIGNAL CALLS FOR ERROR CHECKING (FOR FR 14986).
C      9-94   AS  (CRI) MSTP S/W CONVERSION (VICAR PORTING)
C
      CHARACTER*32 FORMAT
      INTEGER*2 BUF(16000)
      INTEGER SL,SS,NLO,NSO,NLI,NSI,NL,NS,LASTLINE,STATUS
      INTEGER INUNIT(2),OUTUNIT
C
      CALL IFMESSAGE('LABSWTCH version 05-SEP-94')
      CALL XVEACTION('SA',' ')
C--Open input files
      DO I = 1,2
          CALL XVUNIT(INUNIT(I),'INP',I,STATUS,' ')
           CALL XVSIGNAL(INUNIT( I), STATUS, .TRUE.)
          CALL XVOPEN(INUNIT(I),STATUS,' ')
           CALL XVSIGNAL(INUNIT( I), STATUS, .TRUE.)
      END DO
C
C--Get SIZE values if specified and determine number of 
C--lines to be copied
      CALL XVSIZE(SL,SS,NLO,NSO,NLI,NSI)
C
C--Get system information from 2nd input
C--Get FORMAT, NL, and NS from internal control block
      CALL XVGET(INUNIT(2),STATUS,'FORMAT',FORMAT,'NL',NL,'NS',NS,' ')
       CALL XVSIGNAL(INUNIT( 2), STATUS, .TRUE.)
      IF (NLO .NE. NLI) NL = NLO
      IF (NSO .NE. NSI) NS = NSO
C
C--Now produce output file with system label of 2nd input and history
C--labels of the 1st input.
C
C--Open output with specified FORMAT, NL, and NS
      CALL XVUNIT(OUTUNIT,'OUT',1,STATUS,' ')
       CALL XVSIGNAL(OUTUNIT, STATUS, .TRUE.)
      CALL XVOPEN(OUTUNIT,STATUS,'OP','WRITE','U_NL',NL,'U_NS',NS,
     +            'U_FORMAT',FORMAT,'O_FORMAT',FORMAT,' ')
       CALL XVSIGNAL(OUTUNIT, STATUS, .TRUE.)
C
C--Copy dataset
      LASTLINE = SL + NL - 1
      DO LINE = SL, LASTLINE
          CALL XVREAD(INUNIT(2),BUF,STATUS,'LINE',LINE,'SAMP',SS,
     +                'NSAMPS',NS,' ')
            CALL XVSIGNAL(INUNIT( 2), STATUS, .TRUE.)
          CALL XVWRIT(OUTUNIT,BUF,STATUS,'LINE',LINE,'SAMP',SS,
     +                'NSAMPS',NS,' ')
            CALL XVSIGNAL(OUTUNIT, STATUS, .TRUE.)
      END DO
C
C--Close files and return
      CALL XVCLOSE(INUNIT(1),STATUS,' ')
       CALL XVSIGNAL(INUNIT(1), STATUS, .TRUE.)
      CALL XVCLOSE(INUNIT(2),STATUS,' ')
       CALL XVSIGNAL(INUNIT(2), STATUS, .TRUE.)
      CALL XVCLOSE(OUTUNIT,STATUS,' ')
       CALL XVSIGNAL(OUTUNIT, STATUS, .TRUE.)
      RETURN
      END
