File indexing completed on 2023-11-05 05:11:21 UTC
view on githubraw file Latest commit 65754df4 on 2023-11-04 17:55:24 UTC
be017afa44 Jean*0001 #include "CTRL_OPTIONS.h"
0002 #ifdef ALLOW_AUTODIFF
0003 # include "AUTODIFF_OPTIONS.h"
0004 #endif
0005
0006
0007
0008
0009 SUBROUTINE CTRL_MAP_INI_GENTIM2D( myThid )
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 IMPLICIT NONE
0023
0024
0025 #include "SIZE.h"
0026 #include "EEPARAMS.h"
0027 #include "PARAMS.h"
0028 #include "GRID.h"
0029 #include "DYNVARS.h"
0030 #include "FFIELDS.h"
0031 #include "CTRL_SIZE.h"
4d72283393 Mart*0032 #include "CTRL.h"
65754df434 Mart*0033 #include "OPTIMCYCLE.h"
edcd27be69 Mart*0034 #include "CTRL_DUMMY.h"
be017afa44 Jean*0035 #include "CTRL_GENARR.h"
0036 #ifdef ALLOW_PTRACERS
0037 # include "PTRACERS_SIZE.h"
0038 # include "PTRACERS_FIELDS.h"
0039 #endif
0040 #ifdef ALLOW_AUTODIFF_TAMC
0041 # include "tamc.h"
0042 #endif
0043
0044
0045
0046 INTEGER myThid
0047
0048 #ifdef ALLOW_GENTIM2D_CONTROL
0049
0050 INTEGER ILNBLNK
0051 EXTERNAL ILNBLNK
0052
0053
0054
0055 integer iarr
0056 integer numsmo
0057 CHARACTER*(80) fnamegenIn
0058 CHARACTER*(80) fnamegenOut
0059 CHARACTER*(80) fnamegenTmp
0060 CHARACTER*(80) fnamebase
0061 integer startrec
0062 integer endrec
0063 integer diffrec
0064 integer iRec, jrec, kRec, lRec
0065 integer replicated_nrec
0066 integer replicated_ntimes
0067 logical doglobalread
0068 logical ladinit
0069 logical dowc01
0070 logical dosmooth
0071 logical doscaling
0072 _RL xx_gen(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
0073 _RS mask2D(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
0074 #ifdef ALLOW_ECCO
0075 _RL xx_gen_tmp(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
0076 integer nyearsINT
0077 _RL recip_nyearsRL
0078 #endif
0079 integer bi,bj
0080 integer i,j,k2
0081 integer ilgen
0082 integer ilDir
0083
0084
0085 #ifdef ALLOW_DEBUG
0086 IF (debugMode) CALL DEBUG_ENTER('CTRL_MAP_INI_GENTIM2D',myThid)
0087 #endif /* ALLOW_DEBUG */
0088
0089
0090 doglobalread = .false.
0091 ladinit = .false.
0092
0093
0094 ilDir = ilnblnk(ctrlDir)
0095
0096 DO bj=myByLo(myThid), myByHi(myThid)
0097 DO bi=myBxLo(myThid), myBxHi(myThid)
0098 DO j = 1-OLy,sNy+OLy
0099 DO i = 1-OLx,sNx+OLx
0100 xx_gen(i,j,bi,bj)=0. _d 0
0101 #ifdef ALLOW_ECCO
0102 xx_gen_tmp(i,j,bi,bj)=0. _d 0
0103 #endif
0104 ENDDO
0105 ENDDO
0106 ENDDO
0107 ENDDO
0108
0109
0110 DO iarr = 1, maxCtrlTim2D
0111
0112 diffrec=0
0113 startrec=0
0114 endrec=0
0115
0116 #ifndef ALLOW_OPENAD
0117 if (xx_gentim2d_weight(iarr).NE.' ') then
0118 #endif
0119
0120 ilgen=ilnblnk( xx_gentim2d_file(iarr) )
0121 fnamebase = xx_gentim2d_file(iarr)(1:ilgen)
0122 call ctrl_init_rec ( fnamebase,
0123 I xx_gentim2d_startdate1(iarr),
0124 I xx_gentim2d_startdate2(iarr),
0125 I xx_gentim2d_period(iarr),
0126 I 1,
0127 O xx_gentim2d_startdate(1,iarr),
0128 O diffrec, startrec, endrec,
0129 I myThid )
0130
0131
0132
0133
0134
0135
0136 #ifdef ALLOW_CTRL_DEBUG
0137
0138
0139 write(*,*) 'AA: iarr,xx_gentim2d_startdate(1,iarr): ',
0140 & iarr,xx_gentim2d_startdate(1,iarr)
0141 #endif
0142 dosmooth=.false.
0143 dowc01 = .false.
0144 doscaling=.true.
0145
0146 numsmo=1
0147 do k2 = 1, maxCtrlProc
0148 if (xx_gentim2d_preproc(k2,iarr).EQ.'WC01') then
0149 dowc01=.TRUE.
0150 if (xx_gentim2d_preproc_i(k2,iarr).NE.0)
0151 & numsmo=xx_gentim2d_preproc_i(k2,iarr)
0152 endif
0153 if ((.NOT.dowc01).AND.
0154 & (xx_gentim2d_preproc(k2,iarr).EQ.'smooth')) then
0155 dosmooth=.TRUE.
0156 if (xx_gentim2d_preproc_i(k2,iarr).NE.0)
0157 & numsmo=xx_gentim2d_preproc_i(k2,iarr)
0158 endif
0159 if (xx_gentim2d_preproc(k2,iarr).EQ.'noscaling') then
0160 doscaling=.FALSE.
0161 endif
0162 enddo
0163
0164 ilgen=ilnblnk( xx_gentim2d_file(iarr) )
0165 fnamebase = xx_gentim2d_file(iarr)(1:ilgen)
0166 write(fnamegenIn(1:80),'(2a,i10.10)')
0167 & ctrlDir(1:ilDir)//fnamebase(1:ilgen),'.',optimcycle
0168 write(fnamegenOut(1:80),'(2a,i10.10)')
0169 & ctrlDir(1:ilDir)//fnamebase(1:ilgen),'.effective.',optimcycle
0170 write(fnamegenTmp(1:80),'(2a,i10.10)')
0171 & ctrlDir(1:ilDir)//fnamebase(1:ilgen),'.tmp.',optimcycle
0172
0173
0174
0175 replicated_nrec=diffrec
0176 replicated_ntimes=0
0177 do k2 = 1, maxCtrlProc
0178 if (xx_gentim2d_preproc(k2,iarr).EQ.'docycle') then
0179 if (xx_gentim2d_preproc_i(k2,iarr).NE.0) then
0180 replicated_nrec=min(diffrec,xx_gentim2d_preproc_i(k2,iarr))
0181 replicated_ntimes=
0182 & int(float(diffrec)/float(replicated_nrec))
0183 if (replicated_ntimes*replicated_nrec.LT.diffrec)
0184 & replicated_ntimes=replicated_ntimes+1
0185 if (replicated_ntimes*replicated_nrec.GT.diffrec)
0186 & replicated_ntimes=replicated_ntimes-1
0187 endif
0188 endif
0189 enddo
0190
0191 #ifdef ALLOW_CTRL_DEBUG
0192 write(*,'(A,1x,5I6)')
0193 & 'AD:[start,end,diff]rec, replicated_[nrec,ntimes]: ',
0194 & startrec, endrec, diffrec,
0195 & replicated_nrec,replicated_ntimes
0196 #endif
0197 DO jrec = 1, replicated_ntimes+1
0198 DO iRec = 1, replicated_nrec
0199 #ifdef ALLOW_AUTODIFF_TAMC
0200
0201 #endif
0202 kRec=replicated_nrec*(jrec-1)+iRec
0203 lRec=startrec+iRec-1
0204 IF (kRec.LE.endrec) THEN
0205 #ifdef ALLOW_CTRL_DEBUG
0206 ilgen=ilnblnk( fnamegenIn )
0207 write(*,*) 'AE: iarr,[i,j,k,l]rec: ',iarr,iRec,jrec,lRec
0208 write(*,*) 'AF: fnamegenIn: ', fnamegenIn(1:ilgen)
0209 #endif
0210
0211
0212
0213
0214
0215
0216
0217 #ifdef ALLOW_AUTODIFF
0218 CALL ACTIVE_READ_XY( fnamegenIn, xx_gen, lRec,
0219 & doglobalread, ladinit, optimcycle,
0220 & myThid, xx_gentim2d_dummy(iarr) )
0221 #else
0222 CALL READ_REC_XY_RL( fnamegenIn, xx_gen, lRec, 1, myThid )
0223 #endif
0224
0225 #ifdef ALLOW_AUTODIFF
0226 #ifdef ALLOW_CTRL_DEBUG
0227 ilgen=ilnblnk( fnamegenOut )
0228 write(*,*) 'AG: iarr,[i,j,k]rec: ',iarr,iRec,jrec,kRec
0229 write(*,*) 'AH: fnamegenOut: ', fnamegenOut(1:ilgen)
0230 #endif
0231 CALL ACTIVE_WRITE_XY( fnamegenOut, xx_gen, kRec, optimcycle,
0232 & myThid, xx_gentim2d_dummy(iarr) )
0233 #else
0234 CALL WRITE_REC_XY_RL( fnamegenOut, xx_gen, kRec, 1, myThid )
0235 #endif
0236 ENDIF
0237 ENDDO
0238 ENDDO
0239
0240
0241 #ifdef ALLOW_ECCO
0242 replicated_nrec=diffrec
0243 replicated_ntimes=0
0244 do k2 = 1, maxCtrlProc
0245 if (xx_gentim2d_preproc(k2,iarr).EQ.'rmcycle') then
0246 if (xx_gentim2d_preproc_i(k2,iarr).NE.0) then
0247 replicated_nrec=min(diffrec,xx_gentim2d_preproc_i(k2,iarr))
0248 replicated_ntimes=
0249 & int(float(diffrec)/float(replicated_nrec))
0250 if (replicated_ntimes*replicated_nrec.LT.diffrec)
0251 & replicated_ntimes=replicated_ntimes+1
0252 if (replicated_ntimes*replicated_nrec.GT.diffrec)
0253 & replicated_ntimes=replicated_ntimes-1
0254 endif
0255 endif
0256 enddo
0257
0258 #ifdef ALLOW_CTRL_DEBUG
0259 write(*,'(A,1x,5I6)')
0260 & 'AI:[start,end,diff]rec, replicated_[nrec,ntimes]: ',
0261 & startrec,endrec,diffrec,replicated_nrec,replicated_ntimes
0262 #endif
0263
0264 IF (replicated_ntimes.GT.0) THEN
0265
0266
0267
0268 nyearsINT=1+int((diffrec-replicated_nrec)/replicated_nrec)
0269 recip_nyearsRL=1. _d 0/float(nyearsINT)
0270
0271 #ifdef ALLOW_CTRL_DEBUG
0272 write(*,*) 'AJ: nyears[INT,RL]: ',nyearsINT,recip_nyearsRL
0273 #endif
0274
0275 DO iRec = 1, replicated_nrec
0276
0277 DO bj=myByLo(myThid),myByHi(myThid)
0278 DO bi=myBxLo(myThid),myBxHi(myThid)
0279 DO j = 1-OLy,sNy+OLy
0280 DO i = 1-OLx,sNx+OLx
0281 xx_gen(i,j,bi,bj) = zeroRL
0282 ENDDO
0283 ENDDO
0284 ENDDO
0285 ENDDO
0286
0287 DO jrec=1,nyearsINT
0288 #ifdef ALLOW_AUTODIFF_TAMC
0289
0290 #endif
0291 kRec=iRec+(jrec-1)*replicated_nrec
0292 #ifdef ALLOW_CTRL_DEBUG
0293 write(*,*) 'AK: iarr,[i,j,k]rec: ',iarr,iRec,jrec,kRec
0294 ilgen=ilnblnk( fnamegenOut )
0295 write(*,*) 'AL: fnamegenOut: ',fnamegenOut(1:ilgen)
0296 #endif
0297 #ifdef ALLOW_AUTODIFF
0298 CALL ACTIVE_READ_XY( fnamegenOut, xx_gen_tmp, kRec,
0299 & doglobalread, ladinit, optimcycle,
0300 & myThid, xx_gentim2d_dummy(iarr) )
0301 #else
0302 CALL READ_REC_XY_RL( fnamegenOut, xx_gen_tmp, kRec,
0303 & 1, myThid )
0304 #endif
0305 DO bj=myByLo(myThid),myByHi(myThid)
0306 DO bi=myBxLo(myThid),myBxHi(myThid)
0307 DO j = 1,sNy
0308 DO i = 1,sNx
0309 xx_gen(i,j,bi,bj) = xx_gen(i,j,bi,bj)
0310 & +xx_gen_tmp(i,j,bi,bj)
0311 ENDDO
0312 ENDDO
0313 ENDDO
0314 ENDDO
0315
0316 ENDDO
0317
0318 DO bj=myByLo(myThid),myByHi(myThid)
0319 DO bi=myBxLo(myThid),myBxHi(myThid)
0320 DO j = 1,sNy
0321 DO i = 1,sNx
0322 xx_gen(i,j,bi,bj) = xx_gen(i,j,bi,bj) * recip_nyearsRL
0323 ENDDO
0324 ENDDO
0325 ENDDO
0326 ENDDO
0327
0328 #ifdef ALLOW_AUTODIFF_TAMC
0329
0330 #endif
0331
0332 #ifdef ALLOW_AUTODIFF
0333 CALL ACTIVE_WRITE_XY( fnamegenTmp, xx_gen, iRec, optimcycle,
0334 & myThid, xx_gentim2d_dummy(iarr) )
0335 #else
0336 CALL WRITE_REC_XY_RL( fnamegenTmp, xx_gen, iRec, 1, myThid )
0337 #endif
0338
0339 ENDDO
0340
0341
0342 DO jrec = 1, replicated_ntimes+1
0343 DO iRec = 1, replicated_nrec
0344 #ifdef ALLOW_AUTODIFF_TAMC
0345
0346 #endif
0347 kRec=replicated_nrec*(jrec-1)+iRec
0348 #ifdef ALLOW_CTRL_DEBUG
0349 write(*,*) 'AM: iarr,[i,j,k]rec: ',iarr,iRec,jrec,kRec
0350 ilgen=ilnblnk( fnamegenOut )
0351 write(*,*) 'AN: fnamegenOut: ',fnamegenOut(1:ilgen)
0352 #endif
0353 IF (kRec.LE.diffrec) THEN
0354 #ifdef ALLOW_AUTODIFF
0355 CALL ACTIVE_READ_XY( fnamegenOut, xx_gen, kRec,
0356 & doglobalread, ladinit, optimcycle,
0357 & myThid, xx_gentim2d_dummy(iarr) )
0358 #else
0359 CALL READ_REC_XY_RL( fnamegenOut, xx_gen, kRec, 1, myThid )
0360 #endif
0361 #ifdef ALLOW_AUTODIFF
0362 CALL ACTIVE_READ_XY( fnamegenTmp, xx_gen_tmp, iRec,
0363 & doglobalread, ladinit, optimcycle,
0364 & myThid, xx_gentim2d_dummy(iarr) )
0365 #else
0366 CALL READ_REC_XY_RL( fnamegenTmp, xx_gen_tmp, iRec, 1,
0367 & myThid )
0368 #endif
0369 DO bj=myByLo(myThid),myByHi(myThid)
0370 DO bi=myBxLo(myThid),myBxHi(myThid)
0371 DO j = 1,sNy
0372 DO i = 1,sNx
0373 xx_gen(i,j,bi,bj)=xx_gen(i,j,bi,bj)
0374 & -xx_gen_tmp(i,j,bi,bj)
0375 ENDDO
0376 ENDDO
0377 ENDDO
0378 ENDDO
0379 #ifdef ALLOW_AUTODIFF
0380 CALL ACTIVE_WRITE_XY( fnamegenOut, xx_gen, kRec,
0381 & optimcycle, myThid, xx_gentim2d_dummy(iarr) )
0382 #else
0383 CALL WRITE_REC_XY_RL( fnamegenOut, xx_gen, kRec, 1,
0384 & myThid )
0385 #endif
0386 ENDIF
0387 ENDDO
0388 ENDDO
0389
0390 ENDIF
0391 #endif /* ifdef ALLOW_ECCO */
0392
0393
0394
0395
0396
0397
0398 DO iRec = 1, diffrec
0399 #ifdef ALLOW_AUTODIFF_TAMC
0400
0401 #endif
0402
0403 #ifdef ALLOW_CTRL_DEBUG
0404 ilgen=ilnblnk( fnamegenOut )
0405 lRec=startrec+iRec-1
0406 write(*,'(A,1x,A,1x,2I6)') 'AO: fnamegenOut, iRec,lRec ',
0407 & fnamegenOut(1:ilgen),iRec,lRec
0408 #endif
0409 #ifdef ALLOW_AUTODIFF
0410 CALL ACTIVE_READ_XY( fnamegenOut, xx_gen, iRec,
0411 & doglobalread, ladinit, optimcycle,
0412 & myThid, xx_gentim2d_dummy(iarr) )
0413 #else
0414 CALL READ_REC_XY_RL( fnamegenOut, xx_gen, iRec, 1, myThid )
0415 #endif
0416
0417 #ifndef ALLOW_OPENAD
0418 jrec=1
0419
0420
0421 do k2 = 1, maxCtrlProc
0422 if (xx_gentim2d_preproc(k2,iarr).EQ.'variaweight') then
0423 jrec=startrec+iRec-1
0424 endif
0425 enddo
0426 CALL READ_REC_3D_RL( xx_gentim2d_weight(iarr), ctrlprec, 1,
0427 & wgentim2d(1-OLx,1-OLy,1,1,iarr), jrec, 1, myThid )
0428
0429
0430 call ctrl_get_mask2D(xx_gentim2d_file(iarr), mask2D, myThid)
0431
0432 #ifdef ALLOW_SMOOTH
0433 IF (useSMOOTH) THEN
0434 IF (dowc01) call smooth_correl2d(xx_gen,mask2D,numsmo,myThid)
0435 IF (dosmooth) call smooth2d(xx_gen,mask2D,numsmo,myThid)
0436 ENDIF
0437 #endif /* ALLOW_SMOOTH */
0438
0439 DO bj=myByLo(myThid), myByHi(myThid)
0440 DO bi=myBxLo(myThid), myBxHi(myThid)
0441 DO j = 1,sNy
0442 DO i = 1,sNx
0443 if ((mask2D(i,j,bi,bj).NE.0.).AND.
0444 & (wgentim2d(i,j,bi,bj,iarr).GT.0.)) then
0445 IF (doscaling) then
0446 xx_gen(i,j,bi,bj)=xx_gen(i,j,bi,bj)
0447 & /sqrt(wgentim2d(i,j,bi,bj,iarr))
0448 ENDIF
0449 else
0450 xx_gen(i,j,bi,bj)=0. _d 0
0451 endif
0452 ENDDO
0453 ENDDO
0454 ENDDO
0455 ENDDO
0456 #endif /* ALLOW_OPENAD */
0457
0458 CALL CTRL_BOUND_2D(xx_gen,mask2D,
0459 & xx_gentim2d_bounds(1,iarr),myThid)
0460
0461 CALL EXCH_XY_RL ( xx_gen , myThid )
0462
0463 #ifdef ALLOW_CTRL_DEBUG
0464 ilgen=ilnblnk( fnamegenOut )
0465 write(*,'(A,1x,I6,1x,A)')
0466 & 'AQ: iRec,fnamegenOut: ',iRec,fnamegenOut(1:ilgen)
0467 #endif
0468 #ifdef ALLOW_AUTODIFF
0469 CALL ACTIVE_WRITE_XY( fnamegenOut, xx_gen, iRec, optimcycle,
0470 & myThid, xx_gentim2d_dummy(iarr) )
0471 #else
0472 CALL WRITE_REC_XY_RL( fnamegenOut, xx_gen, iRec, 1, myThid )
0473 #endif
0474
0475 ENDDO
0476
0477 #ifndef ALLOW_OPENAD
0478 endif
0479 #endif
0480
0481
0482 ENDDO
0483
0484 #ifdef ALLOW_DEBUG
0485 IF (debugMode) CALL DEBUG_LEAVE('CTRL_MAP_INI_GENTIM2D',myThid)
0486 #endif /* ALLOW_DEBUG */
0487 #endif /* ALLOW_GENTIM2D_CONTROL */
0488
0489 RETURN
0490 END