Back to home page

MITgcm

 
 

    


File indexing completed on 2026-03-19 05:08:34 UTC

view on githubraw file Latest commit 69361556 on 2026-03-18 21:20:20 UTC
8f7d13d0c9 Jean*0001 #include "ECCO_OPTIONS.h"
93bee5c6a2 Jean*0002 #include "AD_CONFIG.h"
6b47d550f4 Mart*0003 #ifdef ALLOW_CTRL
                0004 # include "CTRL_OPTIONS.h"
                0005 #endif
5001c65f45 Patr*0006 
9f85ea262e Mart*0007       SUBROUTINE ECCO_COST_INIT_FIXED( myThid )
5001c65f45 Patr*0008 
                0009 c     ==================================================================
                0010 c     SUBROUTINE ecco_cost_init_fixed
                0011 c     ==================================================================
                0012 c
                0013 c     o Set contributions to the cost function and the cost function
                0014 c       itself to zero. The cost function and the individual contribu-
                0015 c       tions are defined in the header file "ecco_cost.h".
                0016 c
                0017 c     started: Christian Eckert eckert@mit.edu 30-Jun-1999
                0018 c
                0019 c     changed: Christian Eckert eckert@mit.edu 25-Feb-2000
                0020 c
                0021 c              - Restructured the code in order to create a package
                0022 c                for the MITgcmUV.
                0023 c
                0024 c     changed: Ralf Giering 18-Jan-2001
                0025 c
                0026 c              - move namelist reading to cost_readparms.F
                0027 c
                0028 c     ==================================================================
                0029 c     SUBROUTINE ecco_cost_init_fixed
                0030 c     ==================================================================
                0031 
d4b64b229a Jean*0032       IMPLICIT NONE
5001c65f45 Patr*0033 
                0034 c     == global variables ==
                0035 #include "EEPARAMS.h"
                0036 #include "SIZE.h"
                0037 #include "GRID.h"
                0038 #include "PARAMS.h"
                0039 
869864d4b6 Patr*0040 #ifdef ALLOW_CAL
35c4fdc74b Emma*0041 # include "cal.h"
49484c0542 Gael*0042 #endif
35c4fdc74b Emma*0043 #include "ECCO_SIZE.h"
                0044 #include "ECCO.h"
49484c0542 Gael*0045 #ifdef ALLOW_CTRL
65754df434 Mart*0046 # include "OPTIMCYCLE.h"
49484c0542 Gael*0047 #endif
5001c65f45 Patr*0048 
                0049 c     == routine arguments ==
6b47d550f4 Mart*0050       integer myThid
5001c65f45 Patr*0051 
9f85ea262e Mart*0052 c     == external functions ==
                0053       integer  ifnblnk
                0054       external ifnblnk
                0055       integer  ilnblnk
                0056       external ilnblnk
                0057 #ifdef ALLOW_CAL
                0058       integer  cal_IntYears
                0059       external cal_IntYears
                0060       integer  cal_IntMonths
                0061       external cal_IntMonths
                0062       integer  cal_IntDays
                0063       external cal_IntDays
                0064 #endif
5001c65f45 Patr*0065 
9f85ea262e Mart*0066 c     == local variables ==
5cce2b5d76 Gael*0067       integer k
                0068       logical exst
7484238bfd Patr*0069       _RL     missingObsFlag
                0070       PARAMETER ( missingObsFlag = 1. _d 23 )
cf705a6c8e Mart*0071 #ifdef ALLOW_GENCOST_1D
d4b64b229a Jean*0072       CHARACTER*(MAX_LEN_MBUF) msgBuf
9f5240b52a Jean*0073       integer ilo, ihi, irec, gwunit
                0074 #endif
5cce2b5d76 Gael*0075 #ifdef ALLOW_GENCOST_CONTRIBUTION
9f5240b52a Jean*0076       integer k2
5cce2b5d76 Gael*0077 #endif
35c4fdc74b Emma*0078 #ifndef ECCO_VARIABLE_AREAVOLGLOB
                0079       INTEGER i, j, bi, bj
                0080 #endif
5001c65f45 Patr*0081 c     == end of interface ==
                0082 
9f85ea262e Mart*0083       _BEGIN_MASTER(myThid)
49484c0542 Gael*0084 #ifdef ALLOW_CTRL
                0085       eccoiter=optimcycle
                0086 #else
                0087       eccoiter=0
                0088 #endif
9f85ea262e Mart*0089       _END_MASTER(myThid)
49484c0542 Gael*0090 
35c4fdc74b Emma*0091 #ifndef ECCO_VARIABLE_AREAVOLGLOB
                0092       DO bj=myByLo(myThid),myByHi(myThid)
                0093         DO bi=myBxLo(myThid),myBxHi(myThid)
                0094           DO k = 1,Nr
                0095             DO j = 1-OLy,sNy+OLy
                0096               DO i = 1-OLx,sNx+OLx
                0097                 eccoVol_0(i,j,k,bi,bj)=
                0098      &          hFacC(i,j,k,bi,bj)*drF(k)*rA(i,j,bi,bj)
                0099               ENDDO
                0100             ENDDO
                0101           ENDDO
                0102         ENDDO
                0103       ENDDO
                0104 #endif
                0105 
5001c65f45 Patr*0106 #ifdef ALLOW_CAL
                0107 
                0108 c--   The number of monthly and daily averages generated by the
                0109 c--   current model integration.
6b47d550f4 Mart*0110       nyearsrec = cal_IntYears( myThid )
                0111       nmonsrec = cal_IntMonths( myThid )
                0112       ndaysrec = cal_IntDays( myThid )
5001c65f45 Patr*0113 
7acc326976 Gael*0114 #ifdef ALLOW_GENCOST_CONTRIBUTION
                0115       do k = 1, NGENCOST
49484c0542 Gael*0116 
6b47d550f4 Mart*0117 c--    skip averaging when several cost terms use the
9eaee0f935 Gael*0118 c      same barfile or when barfile is undefined
                0119        gencost_barskip(k)=.FALSE.
6b47d550f4 Mart*0120        if ( gencost_barfile(k).EQ.' ' )
9eaee0f935 Gael*0121      &      gencost_barskip(k)=.TRUE.
                0122        do k2 = 1,k-1
                0123          if ( gencost_barfile(k2).EQ.gencost_barfile(k) )
                0124      &      gencost_barskip(k)=.TRUE.
                0125        enddo
                0126 
5cce2b5d76 Gael*0127 c--    set time averaging parameters
49484c0542 Gael*0128        if ( (using_gencost(k)).AND.( (gencost_flag(k).GE.1).OR.
                0129      &         (gencost_avgperiod(k).NE.'     ') ) ) then
7acc326976 Gael*0130          if ( gencost_avgperiod(k) .EQ. 'day' .OR.
                0131      &        gencost_avgperiod(k) .EQ. 'DAY' ) then
                0132             gencost_nrec(k)   = ndaysrec
                0133             gencost_period(k) = 86400.
                0134          else if ( gencost_avgperiod(k) .EQ. 'month' .OR.
                0135      &        gencost_avgperiod(k) .EQ. 'MONTH' ) then
                0136             gencost_nrec(k)   =nmonsrec
                0137             gencost_period(k) = 0.
e7d9258ace Gael*0138          else if ( gencost_avgperiod(k) .EQ. 'step' .OR.
                0139      &        gencost_avgperiod(k) .EQ. 'STEP' ) then
                0140             gencost_nrec(k)   =nTimeSteps+1
                0141             gencost_period(k) = dTtracerLev(1)
985662a3b3 Gael*0142          else if ( gencost_avgperiod(k) .EQ. 'const' .OR.
                0143      &        gencost_avgperiod(k) .EQ. 'CONST' ) then
                0144             gencost_nrec(k)   =1
                0145             gencost_period(k) = dTtracerLev(1)
7acc326976 Gael*0146          else if ( gencost_avgperiod(k) .EQ. 'year' .OR.
                0147      &        gencost_avgperiod(k) .EQ. 'YEAR' ) then
f80d27073f Patr*0148            STOP
                0149      &      'ecco_cost_init_fixed: yearly data not yet implemented'
7acc326976 Gael*0150          else
8f7d13d0c9 Jean*0151            STOP
f80d27073f Patr*0152      &      'ecco_cost_init_fixed: gencost_avgperiod wrongly specified'
7acc326976 Gael*0153          endif
f80d27073f Patr*0154        endif
49484c0542 Gael*0155 
5cce2b5d76 Gael*0156 c--    set observation start/enddate
49484c0542 Gael*0157        if (gencost_startdate1(k).GT.0) then
                0158          call cal_FullDate(
                0159      &     gencost_startdate1(k), gencost_startdate2(k),
6b47d550f4 Mart*0160      &     gencost_startdate(1,k), myThid )
49484c0542 Gael*0161        else
                0162          call cal_CopyDate(modelStartDate,
6b47d550f4 Mart*0163      &     gencost_startdate(1,k),myThid)
94b7e5468a Gael*0164          gencost_startdate1(k)=startdate_1
                0165          gencost_startdate2(k)=startdate_2
49484c0542 Gael*0166        endif
                0167 
                0168        if (gencost_enddate1(k).GT.0) then
                0169          call cal_FullDate(
                0170      &     gencost_enddate1(k), gencost_enddate2(k),
6b47d550f4 Mart*0171      &     gencost_enddate(1,k), myThid )
49484c0542 Gael*0172        else
                0173          call cal_CopyDate(modelEndDate,
6b47d550f4 Mart*0174      &     gencost_enddate(1,k),myThid)
49484c0542 Gael*0175        endif
                0176 
6b2230d510 Ou W*0177 #ifdef ALLOW_GENCOST_1D
                0178       if ( (gencost_name(k).EQ.'gmbp') .OR.
                0179      &     (gencost_name(k).EQ.'gmsl')) then
                0180        if(gencost_nrec(k).GT.N1DDATA)then
                0181         WRITE(msgBuf,'(2A,2i8)') 'ecco_cost_init_fixed: ',
                0182      &   'Increase N1DDATA', N1DDATA, gencost_nrec(k)
                0183         CALL PRINT_ERROR( msgBuf, myThid)
                0184        endif
                0185 
                0186       do irec = 1, N1DDATA
                0187        gencost_1DDATA(irec,k) = 0. _d 0
                0188       enddo
                0189 
                0190       if(gencost_wei1d(k).NE.0. _d 0)then
                0191         gencost_wei1d(k) = 1. _d 0 / gencost_wei1d(k)
                0192      &      /gencost_wei1d(k)
                0193       endif
                0194 
                0195       if ( gencost_datafile(k) .NE. ' ' ) then
                0196       ilo = ifnblnk(gencost_datafile(k))
                0197       ihi = ilnblnk(gencost_datafile(k))
                0198 
                0199       CALL OPEN_COPY_DATA_FILE(
                0200      I                          gencost_datafile(k)(ilo:ihi),
                0201      I                          'ECCO_COST_INIT_FIXED: ',
                0202      O                          gwunit,
                0203      I                          myThid )
                0204       do irec = 1, gencost_nrec(k)
                0205          read(gwunit,*) gencost_1DDATA(irec,k)
                0206       enddo
                0207       close(gwunit)
                0208       endif
                0209 
                0210       endif
                0211 #endif /* ALLOW_GENCOST_1D */
                0212 
5cce2b5d76 Gael*0213       enddo !do k = 1, NGENCOST
7acc326976 Gael*0214 #endif /* ALLOW_GENCOST_CONTRIBUTION */
                0215 
5001c65f45 Patr*0216 #endif /* ALLOW_CAL */
                0217 
d4b64b229a Jean*0218 C-    ECCO_CHECK is now called from packages_check.F
                0219 c     call ecco_check( myThid )
cc9899cf30 Patr*0220 
5001c65f45 Patr*0221 c--   Get the weights that are to be used for the individual cost
                0222 c--   function contributions.
69361556c2 Mart*0223 c     Now done from s/r obcs_init_fixed, because this function only
                0224 c     contains obcs-related weights.
                0225 c     call ecco_cost_weights( myThid )
5001c65f45 Patr*0226 
                0227 c--   Initialise adjoint of monthly mean files calculated
                0228 c--   in cost_averagesfields (and their ad...).
                0229 cph(
                0230 cph   The following init. shoud not be applied if in the middle
                0231 cph   of a divided adjoint run
                0232 cph)
                0233 #ifndef ALLOW_TANGENTLINEAR_RUN
                0234 cph!!! and I think it needs to be seen by TAF
                0235 cph!!! for repeated TLM runs
                0236 cph!!!
                0237       inquire( file='costfinal', exist=exst )
                0238       if ( .NOT. exst) then
6b47d550f4 Mart*0239          call ecco_cost_init_barfiles( myThid )
5001c65f45 Patr*0240       endif
                0241 #endif
                0242 
d4b64b229a Jean*0243 c--   Summarize the cost function setup. <-- now called at the end of ECCO_CHECK
                0244 c     call ecco_summary( myThid )
5001c65f45 Patr*0245 
                0246       _BARRIER
                0247 
6b47d550f4 Mart*0248       RETURN
                0249       END