C***********************************************************************
C***********************************************************************
C Beginning of User-Specified Subroutines for TRUXTON6
C Beginning of User-Specified Subroutines for TRUXTON6
C***********************************************************************
C***********************************************************************
      SUBROUTINE OUTPUTT6(MESHNAME,NOBS,XOBS,YOBS,TOBS,TOBSGMT0,IYEAR,
     &UBAROBS,VBAROBS,DOBSMIN,DOBSMAX,DOBSTOT,CINVTYPE,DATATYPE,
     &NF,NF1,NF2,FREQ,INFER,AMPRAT, 
     &NBC,LRVS,ZCAMP,STDERR,CV,CCOV,RMSE,RCOND,IRANK,MAXRANK,SINGVALS,
     &UBARLS,VBARLS,UERR,VERR,UPARTIAL,VPARTIAL)
C Include file for parameter statements
      INCLUDE 'DCMS.DIM' 
C Fixed global assignments
      CHARACTER*72 MESHNAME
      REAL XOBS(NOBSDIM),YOBS(NOBSDIM),TOBS(NOBSDIM),TOBSGMT0(NOBSDIM),
     &UBAROBS(NOBSDIM),VBAROBS(NOBSDIM),
     &DOBSMIN(NOBSDIM),DOBSMAX(NOBSDIM),DOBSTOT(NOBSDIM)
C
      CHARACTER*72 CINVTYPE,DATATYPE
      REAL FREQ(NFDIM)
      INTEGER INFER(NFDIM)
      COMPLEX AMPRAT(NFDIM)
C
      REAL UBARLS(NOBSDIM),VBARLS(NOBSDIM),UERR(NOBSDIM),VERR(NOBSDIM)
      REAL UPARTIAL(NOBSDIM,NFDIM),VPARTIAL(NOBSDIM,NFDIM)
C
      INTEGER LRVS(NNDIM)     
      COMPLEX ZCAMP(NBCDIM,NFDIM)
      COMPLEX CCOV(NBCDIM*NFDIM,NBCDIM*NFDIM)
      REAL SINGVALS(NCOLDIM)
      REAL STDERR(NBCDIM,NFDIM),CV(NBCDIM,NFDIM)
C-----------------------------------------------------------------------
C User-defined output routine
C
C Arrays and constants:
C
C Character Strings
C   MESHNAME - Name of the finite element mesh used for simulation
C   CINVTYPE - Inverse type (WLS,SVD,FOURIER)
C   DATATYPE - Input data type (UXZ,UXV,UXZC,UXVC)
C
C Observations:
C   NOBS     - Number of space-time observational locations
C   IYEAR    - Year during which the observations occured
C   XOBS(I),YOBS(I) - Spatial locations of observations
C   TOBS(I)  - Time of observations (seconds since TOBSGMT0(1))
C   TOBSGMT0(I) - Time of observations (decimal days (ydutc0) in IYEAR)
C   UBAROBS(I),VBAROBS(I) - Amplitudes of observations
C   DOBSMAX(I),DOBSMIN(I) - Averaging depth interval observations
C   DOBSTOT(I)            - Bathymetric depth for observations
C
C Spectrum of tidal constituents
C   NF        - Number of constituents (NF = NF1+NF2)
C   NF1       - Number of primary constituents
C   NF2       - Number of additional constituents to be inferred
C   FREQ(K)   - Radian frequency, sec**(-1)
C   INFER(K)  - Inference frequency number
C                 INFER(K)  =  K    for K <= NF1
C                 INFER(K) <= NF1   for K >  NF1
C   AMPRAT(K) - Complex amplitude ratio for an inferred const.
C                 ZCAMP(J,K) = AMPRAT(K)*ZCAMP(J,INFER(K)) for  K > NF1
C
C Optimal BC's:
C   NBC         - Number of Boundary Nodes
C   LRVS(J)     - Global node number pointer BC's
C   ZCAMP(J,K)  - Complex BC amplitude
C   STDERR(J,K) - Standard Error (i.e. SQRT(diagonal of CCOV))
C   CV(J,K)     - Coefficient of variation for ZCAMP: 
C                   STDERR(J,K)/CABS(ZCAMP)
C   CCOV(JK,JK) - Complex covariance of the BC estimates 
C                   CCOV is normalized by the mean square error, RMSE**2
C                   CCOV is reported for all frequencies  
C                   The indices are numbered as follows:
C                      JK=(K-1)*NBC+1, K*NBC :BC's for nodes at freq K     
C
c Inversion:
C   RMSE        - Root mean square error, post-inversion
C   RCOND       - Condition number (an input parameter)
C   IRANK       - Actual rank used, based on RCOND
C   MAXRANK     - Maximum rank possible
C   SINGVALS(L) - Singular values from the SVD solver
C
C Model Results:
C   UBARLS(I),VBARLS(I)         - Amplitudes of model results
C   UERR(I), VERR(I)            - Amplitudes of model errors
C   UPARTIAL(I,K),VPARTIAL(I,K) - Amplitudes of model results by freq
C
C Index range:  I=1,NOBS, J=1,NBC, K=1,NF, L=1,IRANK
C   NOBS     - Number of space-time observational locations
C   NBC      - Number of dirichlet boundary nodes
C   NF       - Number of constituents used during inversion
C-----------------------------------------------------------------------
C
C Notes regarding how array contents vary for different input data types:
C
C   Arrays affected: TOBS,TOBSGMT0,UBAROBS,VBAROBS,
C                    DOBSMIN,DOBSMAX,DOBSTOT
C                    UBARLS,VBARLS,UERR,VERR,UPARTIAL,VPARTIAL
C
C   DATATYPE='UXZC' => Complex elevations are used for the inversion
C      T* - set to zero
C      U* - spatial amplitudes of elevation
C      V* - set to zero
C      D* - set to zero
C
C   DATATYPE='UXZ' => Time-domain elevations are used for the inversion
C      T* - temporal values for observations
C      U* - space-time values of elevation
C      V* - set to zero
C      D* - set to zero
C
C   DATATYPE='UXVC' => Complex velocities are used for the inversion
C      T* - set to zero
C      U* - spatial amplitudes of eastward/x component of velocity
C      V* - spatial amplitudes of northward/y component of velocity
C      D* - vertical averaging interval as input by user
C
C   DATATYPE='UXV' => Time-domain elevations are used for the inversion
C      T* - temporal values for observations
C      U* - space-time values of eastward/x component of velocity
C      V* - space-time values of northward/y component of velocity
C      D* - vertical averaging interval as input by user
C
C   DATATYPE='UXZC' or DATATYPE='UXVC' => program stops if NF>1
C
C-----------------------------------------------------------------------
C Warning: Unit (2) is the echo file for the run and is open 
C   during execution of TruxOut.  
C================Beginning-of-user-specified-instructions===============
C
C User-specified local assignments
C
      character*72 filename,begin
      begin='truxton6.5.2_simulation/'
      indxb=index(begin,' ')-1
      indxm=index(meshname,' ')-1
c
c Write tidal elevation bcs.s2c file
c
      print*,NBC, NF
      DO N = 1,NF
        DO I = 1,NBC
          print*,N,I,zcamp(i,n),phaselagd(zcamp(i,n))
        ENDDO
      ENDDO

      DO N = 1,NF
        write(*,*)'   Enter name of the elevation .bcs.s2c results file'
        write(*,*)'      (entering NO => no file will be created)'
        read(*,100)filename
        write(*,100)filename
        if(filename.NE.'NO')then
          OPEN (UNIT=7,FILE=filename,STATUS='NEW')
          write(7,100)meshname(1:indxm)
          write(7,101)IYEAR,TOBSGMT0(1),begin(1:indxb)//'tidal elev BCS'
          write(7,8000)FREQ(N)
          write(7,8002)(lrvs(i),cabs(zcamp(i,n)),
     &                 phaselagd(zcamp(i,n)),i=1,nbc)
         close(7)
        endif
      enddo

      write(*,*)' '
      write(*,*)'   Root Mean Square Velocity Error =',RMSV
      write(*,*)'   Condition Number                =',rcond
      write(*,*)'   Actual Rank                     =',irank
      write(*,*)'   Maximum Possible Rank           =',maxrank
      write(*,*)' '
c Format Statements
c
 100  format(a)
 101  format(i4,1x,f8.4,1x,a)
 8000 format(1e14.6)
 8002 format(i5,2e14.6)
C
C End of routine
C
      Return
      End
C***********************************************************************
C***********************************************************************
C End of User-Specified Subroutines for TRUXTON6
C End of User-Specified Subroutines for TRUXTON6
C***********************************************************************
C***********************************************************************
