Back to home page

MITgcm

 
 

    


File indexing completed on 2024-06-04 05:10:22 UTC

view on githubraw file Latest commit 54f5c8e3 on 2024-06-03 18:10:07 UTC
6d54cf9ca1 Ed H*0001 #include "AUTODIFF_OPTIONS.h"
7fd2fa3bc2 Patr*0002 #ifdef ALLOW_OPENAD
                0003 # include "OPENAD_OPTIONS.h"
                0004 #endif
bead363026 Jean*0005 #ifdef ALLOW_CTRL
                0006 # include "CTRL_OPTIONS.h"
                0007 #endif
94a8024bbe Jean*0008 #ifdef ALLOW_GMREDI
                0009 # include "GMREDI_OPTIONS.h"
                0010 #endif
a10c595eb6 Timo*0011 #ifdef ALLOW_GGL90
                0012 # include "GGL90_OPTIONS.h"
                0013 #endif
7b8b86ab99 Timo*0014 #ifdef ALLOW_SHELFICE
                0015 # include "SHELFICE_OPTIONS.h"
                0016 #endif
00f81e6785 Ou W*0017 #ifdef ALLOW_STEEP_ICECAVITY
                0018 # include "STIC_OPTIONS.h"
                0019 #endif
735a3220ac Jean*0020 #include "AD_CONFIG.h"
2dcaa8b9a5 Patr*0021 
d151781088 Patr*0022 CBOP
898ddfe4b1 Jean*0023 C     !ROUTINE: ADDUMMY_IN_STEPPING
d151781088 Patr*0024 C     !INTERFACE:
898ddfe4b1 Jean*0025       SUBROUTINE ADDUMMY_IN_STEPPING( myTime, myIter, myThid )
d151781088 Patr*0026 
                0027 C     !DESCRIPTION: \bv
                0028 C     *==========================================================*
898ddfe4b1 Jean*0029 C     | SUBROUTINE ADDUMMY_IN_STEPPING                           |
d151781088 Patr*0030 C     *==========================================================*
                0031 C     Extract adjoint variable from TAMC/TAF-generated
                0032 C     adjoint common blocks, contained in adcommon.h
                0033 C     and write fields to file;
                0034 C     Make sure common blocks in adcommon.h are up-to-date
                0035 C     w.r.t. current adjoint code.
                0036 C     *==========================================================*
898ddfe4b1 Jean*0037 C     | SUBROUTINE ADDUMMY_IN_STEPPING                           |
d151781088 Patr*0038 C     *==========================================================*
                0039 C     \ev
                0040 
                0041 C     !USES:
                0042       IMPLICIT NONE
2dcaa8b9a5 Patr*0043 
d151781088 Patr*0044 C     == Global variables ===
7fd2fa3bc2 Patr*0045 #ifdef ALLOW_OPENAD
                0046       use OAD_active
                0047       use OAD_rev
                0048       use OAD_tape
                0049       use OAD_cp
                0050 #endif
2dcaa8b9a5 Patr*0051 #include "SIZE.h"
                0052 #include "EEPARAMS.h"
                0053 #include "PARAMS.h"
d2b824a660 Patr*0054 #ifdef ALLOW_AUTODIFF_MONITOR
a10c595eb6 Timo*0055 # ifdef ALLOW_OPENAD
                0056 C- Note: Since OpenAD uses modules, the ordering of included headers matters
                0057 #  include "DYNVARS.h"
                0058 #  include "FFIELDS.h"
94a8024bbe Jean*0059 #  ifdef ALLOW_GMREDI
                0060 #   include "GMREDI.h"
                0061 #  endif
a10c595eb6 Timo*0062 #  ifdef ALLOW_GGL90
                0063 #   include "GGL90.h"
                0064 #  endif
                0065 # endif /* ALLOW_OPENAD */
                0066 # include "AUTODIFF_PARAMS.h"
816e6857b6 Gael*0067 # include "AUTODIFF.h"
7fd2fa3bc2 Patr*0068 # ifndef ALLOW_OPENAD
                0069 #  include "adcommon.h"
                0070 # endif /* ALLOW_OPENAD */
a5ec81ed49 Timo*0071 # ifdef ALLOW_MNC
                0072 #  include "MNC_PARAMS.h"
                0073 # endif
                0074 # ifdef ALLOW_DIAGNOSTICS
41c4545f8f Jean*0075 #  include "DIAGNOSTICS_P2SHARE.h"
a5ec81ed49 Timo*0076 # endif
7fd2fa3bc2 Patr*0077 #endif /* ALLOW_AUTODIFF_MONITOR */
2dcaa8b9a5 Patr*0078 
d151781088 Patr*0079 C     !INPUT/OUTPUT PARAMETERS:
2dcaa8b9a5 Patr*0080 C     == Routine arguments ==
898ddfe4b1 Jean*0081 C     myTime  :: time counter for this thread
                0082 C     myIter  :: iteration counter for this thread
                0083 C     myThid  :: Thread number for this instance of the routine.
                0084       _RL     myTime
                0085       INTEGER myIter
                0086       INTEGER myThid
d151781088 Patr*0087 
698b67672f Patr*0088 #if (defined (ALLOW_ADJOINT_RUN) || defined (ALLOW_ADMTLM))
d2b824a660 Patr*0089 #ifdef ALLOW_AUTODIFF_MONITOR
                0090 
898ddfe4b1 Jean*0091 C     !FUNCTIONS:
                0092       LOGICAL  DIFFERENT_MULTIPLE
                0093       EXTERNAL DIFFERENT_MULTIPLE
                0094 
d151781088 Patr*0095 C     !LOCAL VARIABLES:
a10c595eb6 Timo*0096 C     == local variables ==
898ddfe4b1 Jean*0097 C     suff    :: Hold suffix part of a filename
                0098 C     msgBuf  :: Error message buffer
a10c595eb6 Timo*0099 c     CHARACTER*(10) suff
a5ec81ed49 Timo*0100 c     CHARACTER*(MAX_LEN_MBUF) msgBuf
a10c595eb6 Timo*0101 #ifdef ALLOW_MNC
898ddfe4b1 Jean*0102       _RL var2Du(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
                0103       _RL var2Dv(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
                0104       _RL var3Du(1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr,nSx,nSy)
                0105       _RL var3Dv(1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr,nSx,nSy)
a10c595eb6 Timo*0106 #endif
898ddfe4b1 Jean*0107       _RS dumRS(1)
                0108       _RL dumRL(1)
a5ec81ed49 Timo*0109       LOGICAL doExch
a10c595eb6 Timo*0110       LOGICAL doDump
d151781088 Patr*0111 CEOP
                0112 
a10c595eb6 Timo*0113 C--- Do dump?
                0114       doDump = DIFFERENT_MULTIPLE( adjDumpFreq, myTime, deltaTClock )
                0115 
a5ec81ed49 Timo*0116 C--- Test for adexch based on dumpAdVarExch flag
a10c595eb6 Timo*0117       doExch = doDump
a5ec81ed49 Timo*0118 #ifdef ALLOW_DIAGNOSTICS
a10c595eb6 Timo*0119       doExch = doDump .OR. useDiag4AdjOutp
a5ec81ed49 Timo*0120 #endif
                0121       doExch = doExch .AND. ( dumpAdVarExch.EQ.1 )
816e6857b6 Gael*0122 
a5ec81ed49 Timo*0123 C--- If necessary, do the exchanges
                0124       IF ( doExch ) THEN
bead363026 Jean*0125 #ifdef ALLOW_OPENAD
                0126 C--   need to all the correct OpenAD EXCH S/R ; left empty for now
                0127 #else /* ALLOW_OPENAD */
                0128 
0a92c8c20d Patr*0129 #ifdef AUTODIFF_TAMC_COMPATIBILITY
a5ec81ed49 Timo*0130         call adexch_xyz_rl( myThid,adTheta)
                0131         call adexch_xyz_rl( myThid,adSalt)
                0132         call adexch_xyz_rl( myThid,adwVel )
                0133         call adexch_uv_xyz_rl(  .true. ,myThid,aduVel,advVel )
                0134 
                0135         call adexch_uv_xy_rs( .true., myThid, adfu, adfv )
                0136         call adexch_xy_rs( myThid,adqnet )
                0137         call adexch_xy_rs( myThid,adempmr )
0a92c8c20d Patr*0138 # ifdef ALLOW_EDDYPSI_CONTROL
a5ec81ed49 Timo*0139         call adexch_uv_xyz_rs(  .true. ,myThid,adeddypsix,adeddypsiy )
0a92c8c20d Patr*0140 # endif
                0141 # ifdef ALLOW_DIFFKR_CONTROL
a5ec81ed49 Timo*0142         call adexch_xyz_rl( myThid,addiffkr )
0a92c8c20d Patr*0143 # endif
                0144 # ifdef ALLOW_KAPGM_CONTROL
94a8024bbe Jean*0145         call adexch_xyz_rl( myThid, adKapGM )
0a92c8c20d Patr*0146 # endif
                0147 # ifdef ALLOW_KAPREDI_CONTROL
94a8024bbe Jean*0148         call adexch_xyz_rl( myThid, adKapRedi )
0a92c8c20d Patr*0149 # endif
85fd6a387e An T*0150 # ifdef ALLOW_BOTTOMDRAG_CONTROL
a5ec81ed49 Timo*0151         call adexch_xy_rl( myThid,adbottomdragfld)
0a92c8c20d Patr*0152 # endif
                0153 # else /* ndfef AUTODIFF_TAMC_COMPATIBILITY */
898ddfe4b1 Jean*0154 
d31dc5d323 Jean*0155 #  ifndef ALLOW_BULK_OFFLINE
a5ec81ed49 Timo*0156         CALL ADEXCH_3D_RL( adTheta,Nr, myThid )
                0157         CALL ADEXCH_3D_RL( adSalt, Nr, myThid )
                0158         CALL ADEXCH_3D_RL( adwVel, Nr, myThid )
                0159         CALL ADEXCH_UV_3D_RL( aduVel,advVel, .TRUE., Nr, myThid )
898ddfe4b1 Jean*0160 #  endif
3c775cbf98 Mart*0161 C     There are rare cases when adexch_uv_xy_rs and adexch_xy_rs are not
                0162 C     generated by TAF and then the following lines will lead to an
                0163 C     error in the link step, for example, when there are no 2D forcing
                0164 C     fields controls. We should have a cpp flag for that that is
                0165 C     automatically defined if any 2D forcing controls are defined. As a
                0166 C     hack we use an excluding cpp-flag that needs to be defined if this
                0167 C     problem occurs
                0168 #ifndef AUTODIFF_EXCLUDE_ADEXCH_RS
a5ec81ed49 Timo*0169         CALL ADEXCH_UV_XY_RS( adFu, adFv, .TRUE., myThid )
                0170         CALL ADEXCH_XY_RS( adQnet, myThid )
                0171         CALL ADEXCH_XY_RS( adEmPmR, myThid )
3c775cbf98 Mart*0172 #endif
0a92c8c20d Patr*0173 # ifdef ALLOW_EDDYPSI_CONTROL
a5ec81ed49 Timo*0174         CALL ADEXCH_UV_XYZ_RS( adEddyPsiX, adEddyPsiY, .TRUE., myThid )
0a92c8c20d Patr*0175 # endif
                0176 # ifdef ALLOW_DIFFKR_CONTROL
a5ec81ed49 Timo*0177         CALL ADEXCH_3D_RL( adDiffKr, Nr, myThid )
0a92c8c20d Patr*0178 # endif
                0179 # ifdef ALLOW_KAPGM_CONTROL
a5ec81ed49 Timo*0180         CALL ADEXCH_3D_RL( adKapGM, Nr, myThid )
0a92c8c20d Patr*0181 # endif
                0182 # ifdef ALLOW_KAPREDI_CONTROL
a5ec81ed49 Timo*0183         CALL ADEXCH_3D_RL( adKapRedi, Nr, myThid )
0a92c8c20d Patr*0184 # endif
85fd6a387e An T*0185 # ifdef ALLOW_BOTTOMDRAG_CONTROL
a5ec81ed49 Timo*0186         CALL ADEXCH_3D_RL( adBottomDragFld, 1 , myThid )
0a92c8c20d Patr*0187 # endif
00f81e6785 Ou W*0188 # if (defined ALLOW_SHELFICE && !defined ALLOW_SHITRANSCOEFF_3D)
7b8b86ab99 Timo*0189 #  ifndef SHI_ALLOW_GAMMAFRICT
                0190         CALL ADEXCH_XY_RL( adshiTransCoeffT, myThid )
                0191         CALL ADEXCH_XY_RL( adshiTransCoeffS, myThid )
                0192 #  else
                0193         CALL ADEXCH_XY_RL( adshiCDragFld, myThid )
                0194 #  endif
                0195 # endif
00f81e6785 Ou W*0196 # if ( defined ALLOW_SHELFICE && defined ALLOW_SHITRANSCOEFF_3D )
54f5c8e380 Jean*0197         CALL ADEXCH_3D_RL( adshiTransCoeffT3d, Nr, myThid )
                0198         CALL ADEXCH_3D_RL( adshiTransCoeffS3d, Nr, myThid )
00f81e6785 Ou W*0199 # endif
898ddfe4b1 Jean*0200 
0a92c8c20d Patr*0201 #endif /* AUTODIFF_TAMC_COMPATIBILITY */
bead363026 Jean*0202 #endif /* ALLOW_OPENAD */
a5ec81ed49 Timo*0203       ENDIF
                0204 
a10c595eb6 Timo*0205 C=======================================================================
                0206 C--  Dump AD-variable to binary files and fill diagnostics
                0207 C=======================================================================
                0208       IF ( doDump ) THEN
                0209 C     Increment ad dump record number (used only if dumpAdByRec is true)
                0210         dumpAdRecMn = dumpAdRecMn + 1
                0211         CALL TIMER_START('I/O (WRITE)        [ADJOINT LOOP]', myThid )
                0212       ENDIF
                0213 
                0214 #ifndef ALLOW_OPENAD
                0215 C========================
                0216 C--  TAF AD-variables:
                0217 C========================
a5ec81ed49 Timo*0218 C-----------------------------------------------------------------------
a10c595eb6 Timo*0219 C--- State variables
a5ec81ed49 Timo*0220 C-----------------------------------------------------------------------
a10c595eb6 Timo*0221       CALL DUMP_ADJ_XYZ(dumRS, adTheta, 'ADJtheta', 'ADJtheta.',
                0222      &                  12, doDump, dumpAdRecMn, myTime, myIter,myThid)
a5ec81ed49 Timo*0223 
a10c595eb6 Timo*0224       CALL DUMP_ADJ_XYZ(dumRS, adSalt, 'ADJsalt ', 'ADJsalt.',
                0225      &                  12, doDump, dumpAdRecMn, myTime, myIter,myThid)
a5ec81ed49 Timo*0226 
a10c595eb6 Timo*0227       CALL DUMP_ADJ_XYZ(dumRS, adWvel, 'ADJwvel ', 'ADJwvel.',
                0228      &                  12, doDump, dumpAdRecMn, myTime, myIter,myThid)
a5ec81ed49 Timo*0229 
a10c595eb6 Timo*0230       CALL DUMP_ADJ_XYZ_UV(
                0231      &     dumRS, adUvel, 'ADJuvel ', 'ADJuvel.',
                0232      &     dumRS, adVvel, 'ADJvvel ', 'ADJvvel.',
                0233      &     34, doDump, dumpAdRecMn, myTime, myIter,myThid)
a5ec81ed49 Timo*0234 
a10c595eb6 Timo*0235 C-----------------------------------------------------------------------
                0236 C--- Surface Forcing
                0237 C-----------------------------------------------------------------------
                0238       IF ( .NOT. useSEAICE .AND. .NOT. useEXF ) THEN
                0239        CALL DUMP_ADJ_XY_UV(
                0240      &      adFu, dumRL, 'ADJtaux ', 'ADJtaux.',
                0241      &      adFv, dumRL, 'ADJtauy ', 'ADJtauy.',
                0242      &      33, doDump, dumpAdRecMn, myTime, myIter,myThid)
                0243         CALL DUMP_ADJ_XY(adQnet, dumRL, 'ADJqnet ', 'ADJqnet.',
                0244      &                   11, doDump, dumpAdRecMn, myTime, myIter,myThid)
                0245         CALL DUMP_ADJ_XY(adEmPmR, dumRL, 'ADJempmr', 'ADJempr.',
                0246      &                   11, doDump, dumpAdRecMn, myTime, myIter,myThid)
                0247 
                0248 # ifdef SHORTWAVE_HEATING
                0249         CALL DUMP_ADJ_XY(adQsw, dumRL, 'ADJqsw  ', 'ADJqsw.',
                0250      &                   11, doDump, dumpAdRecMn, myTime, myIter,myThid)
a5ec81ed49 Timo*0251 # endif
                0252       ENDIF
                0253 
                0254 C-----------------------------------------------------------------------
a10c595eb6 Timo*0255 C---Various packages and parameters
                0256 C-----------------------------------------------------------------------
                0257 # ifdef ALLOW_BOTTOMDRAG_CONTROL
                0258       CALL DUMP_ADJ_XY(dumRS, adBottomDragFld,
                0259      &                 'ADJbtdrg','ADJbottomdrag.',
                0260      &                 12, doDump, dumpAdRecMn, myTime, myIter,myThid)
                0261 # endif
                0262 # ifdef ALLOW_GGL90
                0263       CALL DUMP_ADJ_XYZ(dumRS, adGGL90TKE, 'ADJtke90', 'ADJggl90tke.',
                0264      &                  12, doDump, dumpAdRecMn, myTime, myIter,myThid)
                0265 # endif
                0266 # ifdef ALLOW_DIFFKR_CONTROL
                0267       CALL DUMP_ADJ_XYZ(dumRS, adDiffKr, 'ADJdifkr', 'ADJdiffkr.',
                0268      &                  12, doDump, dumpAdRecMn, myTime, myIter,myThid)
                0269 # endif
                0270 # ifdef ALLOW_KAPGM_CONTROL
                0271       CALL DUMP_ADJ_XYZ(dumRS, adKapGM, 'ADJkapgm', 'ADJkapgm.',
                0272      &                  12, doDump, dumpAdRecMn, myTime, myIter,myThid)
                0273 # endif
                0274 # ifdef ALLOW_KAPREDI_CONTROL
                0275       CALL DUMP_ADJ_XYZ(dumRS, adKapRedi, 'ADJkapre', 'ADJkapredi.',
                0276      &                  12, doDump, dumpAdRecMn, myTime, myIter,myThid)
                0277 # endif
a5ec81ed49 Timo*0278 
a10c595eb6 Timo*0279 # ifdef ALLOW_EDDYPSI_CONTROL
                0280       CALL DUMP_ADJ_XYZ_UV(
                0281      &     adEddyPsiX,dumRL,'ADJepsix','ADJeddipsix.',
                0282      &     adEddyPsiY,dumRL,'ADJepsiy','ADJeddipsiy.',
aecc8b0f47 Mart*0283      &     33, doDump, dumpAdRecMn, myTime, myIter, myThid)
a10c595eb6 Timo*0284 # endif
00f81e6785 Ou W*0285 # if (defined ALLOW_SHELFICE && !defined ALLOW_SHITRANSCOEFF_3D)
7b8b86ab99 Timo*0286 #  ifndef SHI_ALLOW_GAMMAFRICT
                0287       CALL DUMP_ADJ_XY(dumRS, adshiTransCoeffT,
                0288      &                 'ADJshict','ADJshict.',
                0289      &                 12, doDump, dumpAdRecMn, myTime, myIter,myThid)
                0290       CALL DUMP_ADJ_XY(dumRS, adshiTransCoeffS,
85c224e862 Ou W*0291      &                 'ADJshics','ADJshics.',
7b8b86ab99 Timo*0292      &                 12, doDump, dumpAdRecMn, myTime, myIter,myThid)
                0293 #  else
                0294       CALL DUMP_ADJ_XY(dumRS, adshiCDragFld,
                0295      &                 'ADJshicd','ADJshicd.',
                0296      &                 12, doDump, dumpAdRecMn, myTime, myIter,myThid)
                0297 #  endif
                0298 # endif
00f81e6785 Ou W*0299 # if ( defined ALLOW_SHELFICE && defined ALLOW_SHITRANSCOEFF_3D )
                0300       CALL DUMP_ADJ_XYZ(dumRS, adshiTransCoeffT3d,
                0301      &                 'ADJshict','ADJshict.',
                0302      &                 12, doDump, dumpAdRecMn, myTime, myIter,myThid)
                0303       CALL DUMP_ADJ_XYZ(dumRS, adshiTransCoeffS3d,
                0304      &                 'ADJshics','ADJshics.',
                0305      &                 12, doDump, dumpAdRecMn, myTime, myIter,myThid)
                0306 # endif
2dcaa8b9a5 Patr*0307 
aecc8b0f47 Mart*0308 # ifdef ALLOW_DEPTH_CONTROL
                0309       CALL DUMP_ADJ_XYZ(
                0310      &     adhfacc,dumRL,'ADJhFacC','ADJhFacC.',
                0311      &     11, doDump, dumpAdRecMn, myTime, myIter, myThid)
                0312       CALL DUMP_ADJ_XYZ_UV(
                0313      &     adhfacw,dumRL,'ADJhFacW','ADJhFacW.',
                0314      &     adhfacs,dumRL,'ADJhFacS','ADJhFacS.',
                0315      &     33, doDump, dumpAdRecMn, myTime, myIter, myThid)
                0316       CALL DUMP_ADJ_XYZ(
                0317      &     adrecip_hfacc,dumRL,'ADJrhFcC','ADJrecip_hFacC.',
                0318      &     11, doDump, dumpAdRecMn, myTime, myIter, myThid)
                0319       CALL DUMP_ADJ_XYZ_UV(
                0320      &     adrecip_hfacw,dumRL,'ADJrhFcW','ADJrecip_hFacW.',
                0321      &     adrecip_hfacs,dumRL,'ADJrhFcS','ADJrecip_hFacS.',
                0322      &     33, doDump, dumpAdRecMn, myTime, myIter, myThid)
                0323 # endif /* ALLOW_DEPTH_CONTROL */
                0324 
a10c595eb6 Timo*0325 #else /* ALLOW_OPENAD */
                0326 C========================
                0327 C--  OpenAD AD-variable:
                0328 C========================
7fd2fa3bc2 Patr*0329 C-----------------------------------------------------------------------
a10c595eb6 Timo*0330 C--- State variables
7fd2fa3bc2 Patr*0331 C-----------------------------------------------------------------------
a10c595eb6 Timo*0332       CALL DUMP_ADJ_XYZ(dumRS, theta%d, 'ADJtheta', 'ADJtheta.',
                0333      &                  12, doDump, dumpAdRecMn, myTime, myIter,myThid)
7fd2fa3bc2 Patr*0334 
a10c595eb6 Timo*0335       CALL DUMP_ADJ_XYZ(dumRS, salt%d, 'ADJsalt ', 'ADJsalt.',
                0336      &                  12, doDump, dumpAdRecMn, myTime, myIter,myThid)
2dcaa8b9a5 Patr*0337 
a10c595eb6 Timo*0338       CALL DUMP_ADJ_XYZ(dumRS, wvel%d, 'ADJwvel ', 'ADJwvel.',
                0339      &                  12, doDump, dumpAdRecMn, myTime, myIter,myThid)
816e6857b6 Gael*0340 
a10c595eb6 Timo*0341       CALL DUMP_ADJ_XYZ_UV(
                0342      &     dumRS, uvel%d, 'ADJuvel ', 'ADJuvel.',
                0343      &     dumRS, vvel%d, 'ADJvvel ', 'ADJvvel.',
                0344      &     34, doDump, dumpAdRecMn, myTime, myIter,myThid)
497a20ca68 Patr*0345 
7fd2fa3bc2 Patr*0346 C-----------------------------------------------------------------------
a10c595eb6 Timo*0347 C--- Surface Forcing
7fd2fa3bc2 Patr*0348 C-----------------------------------------------------------------------
a10c595eb6 Timo*0349       IF ( .NOT. useSEAICE .AND. .NOT. useEXF ) THEN
                0350        CALL DUMP_ADJ_XY_UV(
                0351      &      Fu%d, dumRL, 'ADJtaux ', 'ADJtaux.',
                0352      &      Fv%d, dumRL, 'ADJtauy ', 'ADJtauy.',
                0353      &      33, doDump, dumpAdRecMn, myTime, myIter,myThid)
                0354         CALL DUMP_ADJ_XY(Qnet%d, dumRL, 'ADJqnet ', 'ADJqnet.',
                0355      &                   11, doDump, dumpAdRecMn, myTime, myIter,myThid)
                0356         CALL DUMP_ADJ_XY(EmPmR%d, dumRL, 'ADJempmr', 'ADJempr.',
                0357      &                   11, doDump, dumpAdRecMn, myTime, myIter,myThid)
                0358 
                0359 # ifdef SHORTWAVE_HEATING
                0360 C     Commented out since only works when Qsw is active
                0361 c       CALL DUMP_ADJ_XY(Qsw%d, dumRL, 'ADJqsw  ', 'ADJqsw.',
                0362 c    &                   11, doDump, dumpAdRecMn, myTime, myIter,myThid)
                0363 # endif
                0364       ENDIF
7fd2fa3bc2 Patr*0365 
                0366 C-----------------------------------------------------------------------
a10c595eb6 Timo*0367 C---Various packages and parameters
7fd2fa3bc2 Patr*0368 C-----------------------------------------------------------------------
a10c595eb6 Timo*0369 # ifdef ALLOW_BOTTOMDRAG_CONTROL
                0370       CALL DUMP_ADJ_XY(dumRS, BottomDragFld%d,
                0371      &                 'ADJbtdrg','ADJbottomdrag.',
                0372      &                 11, doDump, dumpAdRecMn, myTime, myIter,myThid)
                0373 # endif
                0374 # ifdef ALLOW_GGL90
                0375       CALL DUMP_ADJ_XYZ(dumRS, GGL90TKE%d, 'ADJtke90', 'ADJggl90tke.',
                0376      &                  12, doDump, dumpAdRecMn, myTime, myIter,myThid)
                0377 # endif
                0378 # ifdef ALLOW_DIFFKR_CONTROL
                0379       CALL DUMP_ADJ_XYZ(dumRS, DiffKr%d, 'ADJdifkr', 'ADJdiffkr.',
                0380      &                  12, doDump, dumpAdRecMn, myTime, myIter,myThid)
                0381 # endif
94a8024bbe Jean*0382 # if ( defined ALLOW_KAPGM_CONTROL && defined GM_READ_K3D_GM )
                0383       CALL DUMP_ADJ_XYZ(dumRS, GM_inpK3dGM%d, 'ADJkapgm', 'ADJkapgm.',
a10c595eb6 Timo*0384      &                  12, doDump, dumpAdRecMn, myTime, myIter,myThid)
                0385 # endif
94a8024bbe Jean*0386 # if ( defined ALLOW_KAPREDI_CONTROL && defined GM_READ_K3D_REDI )
                0387       CALL DUMP_ADJ_XYZ(dumRS, GM_inpK3dRedi%d, 'ADJkapre',
                0388      &                  'ADJkapredi.',
a10c595eb6 Timo*0389      &                  12, doDump, dumpAdRecMn, myTime, myIter,myThid)
                0390 # endif
7fd2fa3bc2 Patr*0391 
a10c595eb6 Timo*0392 # ifdef ALLOW_EDDYPSI_CONTROL
                0393       CALL DUMP_ADJ_XYZ_UV(
                0394      &     EddyPsiX%d,dumRL,'ADJepsix','ADJeddipsix.',
                0395      &     EddyPsiY%d,dumRL,'ADJepsiy','ADJeddipsiy.',
                0396      &     33, doDump, dumpAdRecMn, myTime, myIter,myThid)
                0397 # endif
00f81e6785 Ou W*0398 # if (defined ALLOW_SHELFICE && !defined ALLOW_SHITRANSCOEFF_3D)
7b8b86ab99 Timo*0399 #  ifndef SHI_ALLOW_GAMMAFRICT
                0400       CALL DUMP_ADJ_XY(dumRS, shiTransCoeffT%d,
                0401      &                 'ADJshict','ADJshict.',
                0402      &                 12, doDump, dumpAdRecMn, myTime, myIter,myThid)
                0403       CALL DUMP_ADJ_XY(dumRS, shiTransCoeffS%d,
85c224e862 Ou W*0404      &                 'ADJshics','ADJshics.',
7b8b86ab99 Timo*0405      &                 12, doDump, dumpAdRecMn, myTime, myIter,myThid)
                0406 #  else
                0407       CALL DUMP_ADJ_XY(dumRS, shiCDragFld%d,
                0408      &                 'ADJshicd','ADJshicd.',
                0409      &                 12, doDump, dumpAdRecMn, myTime, myIter,myThid)
                0410 #  endif
                0411 # endif
00f81e6785 Ou W*0412 # if (defined ALLOW_SHELFICE && defined ALLOW_SHITRANSCOEFF_3D)
                0413       CALL DUMP_ADJ_XYZ(dumRS, shiTransCoeffT3d%d,
                0414      &                 'ADJshict','ADJshict.',
                0415      &                 12, doDump, dumpAdRecMn, myTime, myIter,myThid)
                0416       CALL DUMP_ADJ_XYZ(dumRS, shiTransCoeffS3d%d,
                0417      &                 'ADJshics','ADJshics.',
                0418      &                 12, doDump, dumpAdRecMn, myTime, myIter,myThid)
                0419 # endif
aecc8b0f47 Mart*0420 
                0421 # ifdef ALLOW_DEPTH_CONTROL
                0422       CALL DUMP_ADJ_XYZ(
                0423      &     hFacC%d,dumRL,'ADJhFacC','ADJhFacC.',
                0424      &     11, doDump, dumpAdRecMn, myTime, myIter, myThid)
                0425       CALL DUMP_ADJ_XYZ_UV(
                0426      &     hFacW%d,dumRL,'ADJhFacW','ADJhFacW.',
                0427      &     hFacS%d,dumRL,'ADJhFacS','ADJhFacS.',
                0428      &     33, doDump, dumpAdRecMn, myTime, myIter, myThid)
                0429       CALL DUMP_ADJ_XYZ(
                0430      &     recip_hFacC%d,dumRL,'ADJrhFcC','ADJrecip_hFacC.',
                0431      &     11, doDump, dumpAdRecMn, myTime, myIter, myThid)
                0432       CALL DUMP_ADJ_XYZ_UV(
                0433      &     recip_hFacW%d,dumRL,'ADJrhFcW','ADJrecip_hFacW.',
                0434      &     recip_hFacS%d,dumRL,'ADJrhFcS','ADJrecip_hFacS.',
                0435      &     33, doDump, dumpAdRecMn, myTime, myIter, myThid)
                0436 # endif /* ALLOW_DEPTH_CONTROL */
                0437 
a10c595eb6 Timo*0438 #endif /* ALLOW_OPENAD */
7fd2fa3bc2 Patr*0439 
a10c595eb6 Timo*0440 C=======================================================================
                0441 C--  Dump TAF AD-variable to NetCdF files
                0442 C=======================================================================
                0443       IF ( doDump ) THEN
7fd2fa3bc2 Patr*0444 #ifndef ALLOW_OPENAD
6bd3b6b067 Patr*0445 #ifdef ALLOW_MNC
                0446         IF (useMNC .AND. autodiff_mnc) THEN
aa753c2639 Mart*0447          CALL MNC_CW_SET_UDIM('adstate', -1, myThid)
                0448          CALL MNC_CW_RL_W_S('D','adstate',0,0,'T',myTime,myThid)
                0449          CALL MNC_CW_SET_UDIM('adstate', 0, myThid)
                0450          CALL MNC_CW_I_W_S('I','adstate',0,0,'iter',myIter,myThid)
                0451          CALL MNC_CW_RL_W_S('D','adstate',0,0,'model_time',myTime,
                0452      &        myThid)
                0453 
                0454          IF ( dumpAdVarExch.EQ.2 ) THEN
                0455           CALL COPY_AD_UV_OUTP( dumRS, dumRS, aduVel, advVel,
                0456      &                          var3Du, var3Dv, Nr, 34, myThid )
                0457           CALL MNC_CW_RL_W('D','adstate',0,0,'adU', var3Du, myThid)
                0458           CALL MNC_CW_RL_W('D','adstate',0,0,'adV', var3Dv, myThid)
                0459           CALL COPY_ADVAR_OUTP( dumRS, adTheta,var3Du, Nr, 12, myThid )
                0460           CALL MNC_CW_RL_W('D','adstate',0,0,'adT', var3Du, myThid)
                0461           CALL COPY_ADVAR_OUTP( dumRS, adSalt,var3Du, Nr, 12, myThid )
                0462           CALL MNC_CW_RL_W('D','adstate',0,0,'adS', var3Du, myThid)
                0463           CALL COPY_ADVAR_OUTP( dumRS, adwVel, var3Du, Nr, 12, myThid )
                0464           CALL MNC_CW_RL_W('D','adstate',0,0,'adW', var3Du, myThid)
898ddfe4b1 Jean*0465 
aa753c2639 Mart*0466           CALL COPY_ADVAR_OUTP( adQnet, dumRL, var2Du, 1, 11, myThid )
5b0f0973d0 Jean*0467           CALL MNC_CW_RL_W('D','adstate',0,0,'adQnet', var2Du, myThid)
aa753c2639 Mart*0468           CALL COPY_ADVAR_OUTP( adEmPmR,dumRL, var2Du, 1, 11, myThid )
5b0f0973d0 Jean*0469           CALL MNC_CW_RL_W('D','adstate',0,0,'adEmpmr', var2Du, myThid)
aa753c2639 Mart*0470           CALL COPY_AD_UV_OUTP( adFu, adFv, dumRL, dumRL,
                0471      &                          var2Du, var2Dv, 1, 33, myThid )
5b0f0973d0 Jean*0472           CALL MNC_CW_RL_W('D','adstate',0,0,'adFu', var2Du, myThid)
                0473           CALL MNC_CW_RL_W('D','adstate',0,0,'adFv', var2Dv, myThid)
aa753c2639 Mart*0474 
85fd6a387e An T*0475 #ifdef ALLOW_BOTTOMDRAG_CONTROL
aa753c2639 Mart*0476           CALL COPY_ADVAR_OUTP( dumRS, adBottomDragFld,
                0477      &                                        var2Du, 1, 12, myThid )
                0478           CALL MNC_CW_RL_W('D','adstate',0,0,
                0479      &                     'adBottomDrag', var2Du, myThid)
                0480 #endif
                0481 #ifdef ALLOW_DIFFKR_CONTROL
                0482           CALL COPY_ADVAR_OUTP( dumRS, adDiffKr,var3Du, Nr, 12,myThid )
                0483           CALL MNC_CW_RL_W('D','adstate',0,0,
                0484      &                     'adDiffkr', var3Du, myThid)
                0485 #endif
                0486 #ifdef ALLOW_KAPGM_CONTROL
                0487           CALL COPY_ADVAR_OUTP( dumRS, adKapGM, var3Du, Nr, 12,myThid )
                0488           CALL MNC_CW_RL_W('D','adstate',0,0,
                0489      &                     'adkapgm', var3Du, myThid)
                0490 #endif
                0491 #ifdef ALLOW_KAPREDI_CONTROL
                0492           CALL COPY_ADVAR_OUTP( dumRS,adKapRedi,var3Du, Nr, 12,myThid )
                0493           CALL MNC_CW_RL_W('D','adstate',0,0,
                0494      &                     'adkapredi', var3Du, myThid)
                0495 #endif
                0496          ELSE
                0497 C     dumpAdVarExch.NE.2
6bd3b6b067 Patr*0498           CALL MNC_CW_RL_W('D','adstate',0,0,'adU', aduVel, myThid)
                0499           CALL MNC_CW_RL_W('D','adstate',0,0,'adV', advVel, myThid)
a5ec81ed49 Timo*0500           CALL MNC_CW_RL_W('D','adstate',0,0,'adT', adTheta, myThid)
                0501           CALL MNC_CW_RL_W('D','adstate',0,0,'adS', adSalt, myThid)
6bd3b6b067 Patr*0502           CALL MNC_CW_RL_W('D','adstate',0,0,'adW', adwVel, myThid)
8f0b59c61c Patr*0503 
954561c446 Jean*0504           CALL MNC_CW_RS_W('D','adstate',0,0,'adQnet', adQnet, myThid)
f4b7d73d77 Jean*0505           CALL MNC_CW_RS_W('D','adstate',0,0,'adEmpmr',adEmpmr, myThid)
954561c446 Jean*0506           CALL MNC_CW_RS_W('D','adstate',0,0,'adFu', adfu, myThid)
                0507           CALL MNC_CW_RS_W('D','adstate',0,0,'adFv', adfv, myThid)
77c6107d5a Patr*0508 
85fd6a387e An T*0509 #ifdef ALLOW_BOTTOMDRAG_CONTROL
954561c446 Jean*0510           CALL MNC_CW_RL_W('D','adstate',0,0,
                0511      &                     'adBottomDrag', adbottomdragfld, myThid)
98e4a16c0b Mart*0512 #endif
dd9d2cc2bf Patr*0513 #ifdef ALLOW_DIFFKR_CONTROL
                0514           CALL MNC_CW_RL_W('D','adstate',0,0,
954561c446 Jean*0515      &                     'adDiffkr', addiffkr, myThid)
dd9d2cc2bf Patr*0516 #endif
5116830959 Patr*0517 #ifdef ALLOW_KAPGM_CONTROL
                0518           CALL MNC_CW_RL_W('D','adstate',0,0,
94a8024bbe Jean*0519      &                     'adkapgm', adKapGM, myThid)
5116830959 Patr*0520 #endif
7e2482cabc Gael*0521 #ifdef ALLOW_KAPREDI_CONTROL
                0522           CALL MNC_CW_RL_W('D','adstate',0,0,
94a8024bbe Jean*0523      &                     'adkapredi', adKapRedi, myThid)
7e2482cabc Gael*0524 #endif
7b8b86ab99 Timo*0525 #ifdef ALLOW_SHELFICE
                0526 # ifndef SHI_ALLOW_GAMMAFRICT
00f81e6785 Ou W*0527 #  ifdef ALLOW_SHITRANSCOEFF_3D
                0528           CALL MNC_CW_RL_W('D','adstate',0,0,
                0529      &                     'adshict', adshiTransCoeffT3d, myThid)
                0530           CALL MNC_CW_RL_W('D','adstate',0,0,
                0531      &                     'adshics', adshiTransCoeffS3d, myThid)
                0532 #  else
7b8b86ab99 Timo*0533           CALL MNC_CW_RL_W('D','adstate',0,0,
                0534      &                     'adshict', adshiTransCoeffT, myThid)
                0535           CALL MNC_CW_RL_W('D','adstate',0,0,
                0536      &                     'adshics', adshiTransCoeffS, myThid)
00f81e6785 Ou W*0537 #  endif
7b8b86ab99 Timo*0538 # else
                0539           CALL MNC_CW_RL_W('D','adstate',0,0,
                0540      &                     'adshicd', adshiCDragFld, myThid)
                0541 # endif
                0542 #endif
aa753c2639 Mart*0543          ENDIF
                0544 C     endif mnc
6bd3b6b067 Patr*0545         ENDIF
                0546 #endif /* ALLOW_MNC */
7fd2fa3bc2 Patr*0547 #endif /* ALLOW_OPENAD */
6bd3b6b067 Patr*0548 
a10c595eb6 Timo*0549         CALL TIMER_STOP( 'I/O (WRITE)        [ADJOINT LOOP]', myThid )
898ddfe4b1 Jean*0550 
a10c595eb6 Timo*0551       ENDIF
                0552 
                0553 C=======================================================================
                0554 C--  Output AD-variable & fill Diagnostics with pkg specific interface
                0555 C=======================================================================
898ddfe4b1 Jean*0556 #ifdef ALLOW_SEAICE
                0557         IF ( useSEAICE )
                0558      &   CALL SEAICE_AD_DUMP( myTime, myIter, myThid )
                0559 #endif
ec48404f58 Patr*0560 
898ddfe4b1 Jean*0561 #ifdef ALLOW_PTRACERS
                0562         IF ( usePTRACERS )
                0563      &   CALL PTRACERS_AD_DUMP( myTime, myIter, myThid )
                0564 #endif
                0565 
d2b824a660 Patr*0566 #endif /* ALLOW_AUTODIFF_MONITOR */
ea0f79f160 Patr*0567 #endif /* ALLOW_ADJOINT_RUN */
d2b824a660 Patr*0568 
d31dc5d323 Jean*0569       RETURN
                0570       END