      SUBROUTINE SECOND (IUO,B,G,NX,LNWORK)

*** READ DATA AND WRITE FIRST OBSERVATION EQUATIONS

      IMPLICIT DOUBLE PRECISION (A-H,O-Z)
      IMPLICIT INTEGER (I-N)
      LOGICAL LDIR,LANG,LZEN,LDIS,LAZI,LGPS
      LOGICAL LMSL,LSS,LUP
      LOGICAL FATAL
      DIMENSION B(*),G(*),NX(*)
      COMMON /BYPASS/ LDIR,LANG,LZEN,LDIS,LAZI,LGPS
      COMMON /OPT/ AX,E2,DMSL,DGH,VM,VP,CTOL,ITMAX,ITMIN,IMODE,
     &             LMSL,LSS,LUP
      COMMON /STRUCT/ NSTA,NAUX,NUNK,IDIM,NSTAS,NOBS,NCON,NZ,NCD

      IOBS = 0
      FATAL = .FALSE.

*** INITIALIZE CONNECTION MATRIX

      N = NUNK
      CALL OPENG (N,NX,LNWORK)

*** ADJUSTMENT FILE CONSTRAINTS

      IUNIT = 1
      OPEN (IUNIT,ERR = 1,STATUS='OLD',FILE='AFILE',IOSTAT=IOS,
     &      BLANK='ZERO')
      CALL SECADJ (IUNIT,IUO,IOBS,B,NX,FATAL)
      CLOSE (IUNIT)

*** BLUE-BOOK OBSERVATIONS

    1 IUNIT=2
      OPEN (IUNIT,STATUS='OLD',FILE='BBOOK',BLANK='ZERO')
      CALL SECBB (IUNIT,IUO,IOBS,B,NX,FATAL)
      CLOSE (IUNIT)

*** G-FILE OBSERVATIONS

      IF (.NOT.LGPS) THEN
        IUNIT = 3
        OPEN (IUNIT,ERR=2,STATUS='OLD',FILE='GFILE',IOSTAT=IOS,
     &        BLANK='ZERO')
        CALL SECGPS (IUNIT,IUO,IOBS,B,NX,G,FATAL)
        CLOSE (IUNIT)
      ENDIF

*** ABORT DUE TO LARGE MISCLOSURES

    2 IF (FATAL) THEN
        CALL LINE (3)
        WRITE (6,3) VM
    3   FORMAT ('0ERROR - TERMINATED DUE TO MISCLOSURES (C-O)/SD',
     &          ' EXCEEDING ' ,F7.1,/)
        CALL ABORT2
      ENDIF

*** REORDER THE UNKNOWNS

      CALL REORDR (NX)

      RETURN
      END
