New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
make_dmp_file.F90 in NEMO/branches/UKMO/tools_r4.0-HEAD_dev_DMP_TOOLS/DMP_TOOLS/src – NEMO

source: NEMO/branches/UKMO/tools_r4.0-HEAD_dev_DMP_TOOLS/DMP_TOOLS/src/make_dmp_file.F90 @ 15745

Last change on this file since 15745 was 15745, checked in by dbruciaferri, 2 years ago

modifications for restoring upper 300 m to EN4

File size: 4.8 KB
Line 
1PROGRAM make_dmp_file
2  !================================================================================
3  !               *** PROGRAM make_dmp_file ****
4  !================================================================================
5  !
6  !  Purpose: Create a file containing a spacially varying
7  !           restoration coefficient to be used by TRADMP
8  !
9  !  Method:  1) Read in tmask from mesh_mask file to use as a template
10  !           2) Calculate restoration coefficients according to options
11  !           specified in the namelist. The user may modify custom.F90 to
12  !           specify specific damping options e.g. to mask certain regions only).
13  !           3) Write the array to output file
14  !
15  !  History: Original code: Tim Graham (Jul 2014) - some code moved from
16  !                            old tradmp.F90 module to this tool (as part of NEMO
17  !                            simplification process).
18  !-------------------------------------------------------------------------------
19
20  ! Declare variables
21  USE netcdf 
22  USE utils
23  USE coastdist
24  USE med_red_seas
25  USE zoom
26  USE custom
27
28  IMPLICIT NONE
29  INTEGER  :: ji, jj, jk                         ! dummpy loop variables
30  REAL(wp) :: zsdmp, zbdmp                     ! Surface and bottom damping coeff
31  CHARACTER(LEN=200) :: meshfile = 'mesh_mask.nc'   ! mesh file
32  CHARACTER(LEN=200) :: outfile = 'resto.nc'     ! output file
33  REAL(wp) :: zlat, zlat2, zlat0
34
35  ! Read namelist
36  OPEN( UNIT=numnam, FILE='namelist', FORM='FORMATTED', STATUS='OLD' )
37  READ( numnam, nam_dmp_create )
38  CLOSE( numnam )
39 
40  IF ( ln_full_field .AND. lzoom ) THEN
41    WRITE(numerr,*) 'Only one of ln_full_field and lzoom can be .true.'
42    STOP
43  ENDIF
44
45  CALL grid_info(meshfile)
46  WRITE(numout, *) 'jpi = ',jpi
47  WRITE(numout, *) 'jpj = ',jpj
48  WRITE(numout, *) 'jpk = ',jpk
49
50  ALLOCATE( resto(jpi, jpj) )
51  ALLOCATE( dcst(jpi, jpj) )
52
53  !Create output file
54  CALL make_outfile( outfile )
55 
56  CALL check_nf90( nf90_get_var( ncin, gphit_id, gphit, (/ 1,1 /), (/ jpi, jpj /) ) )
57
58  !Calculate surface and bottom damping coefficients
59  zsdmp = 1._wp / ( pn_surf * rday )
60  IF (pn_bot > 0.) THEN
61     zbdmp = 1._wp / ( pn_bot  * rday )
62  ELSE
63     zbdmp = 0.
64  ENDIF
65
66  ! Calculate distance from the coast
67  IF (ln_coast) CALL cofdis( dcst ) 
68
69  !Loop through levels and read in tmask for each level as starting point for
70  !coefficient array
71  DO jk = 1, jpk-1
72     resto(:,:) = 0._wp
73     
74     IF (.NOT. (jk == 1 .AND. ln_zero_top_layer) ) THEN 
75        !Read in tmask depth for this level
76        CALL check_nf90( nf90_get_var( ncin, tmask_id, tmask, (/ 1,1,jk /), (/ jpi, jpj,1 /) ) )
77        CALL check_nf90( nf90_get_var( ncin, gdept_id, gdept, (/ 1,1,jk /), (/ jpi, jpj,1 /) ) )
78     
79
80        IF ( ln_full_field ) THEN
81           !Set basic value of resto
82           DO jj = 1, jpj
83              DO ji = 1, jpi
84                 IF ( ln_exp ) THEN
85                    resto(ji,jj) = tmask(ji, jj) * (zbdmp + (zsdmp-zbdmp) * EXP(-gdept(ji,jj)/pn_dep))
86                 ELSE
87                    resto(ji,jj) = tmask(ji, jj) * (zbdmp + (zsdmp-zbdmp) / &
88                       &           (1._wp + EXP(rn_k * (gdept(ji,jj) - pn_dep) / 100._wp)))
89                 ENDIF
90              END DO
91           END DO
92           IF ((nn_hdmp > 0)) THEN
93              zlat0 = 10. !width of latitude strip where resto decreases
94              zlat2 = nn_hdmp + zlat0
95              DO jj = 1, jpj
96                 DO ji = 1, jpi
97                    zlat = ABS(gphit(ji,jj))
98                    IF ( nn_hdmp <= zlat .AND. zlat <= zlat2 ) THEN
99                       resto(ji,jj) = resto(ji,jj) * 0.5_wp * (  1._wp - COS( rpi*(zlat-nn_hdmp)/zlat0 ) )
100                    ELSE IF ( zlat < nn_hdmp ) THEN
101                       resto(ji,jj) = 0._wp
102                    ENDIF
103                 END DO
104              END DO
105           ENDIF
106   
107           IF (ln_coast) THEN
108              ! Reduce damping in vicinity of coastlines
109              CALL coast_dist_weight(resto, dcst)
110           ENDIF
111        ENDIF
112
113        ! Damping in Med/Red Seas (or local modifications if full field is set)
114        IF (ln_med_red_seas .AND. (cp_cfg == 'orca') .AND. (.NOT. lzoom)) THEN
115           CALL med_red_dmp(resto, jk, ln_old_31_lev_code)
116        ENDIF
117
118        IF ( lzoom ) THEN
119              CALL dtacof_zoom(resto, tmask)
120        ENDIF
121       
122        !Any user modifications can be added in the custom module
123        IF ( ln_custom ) THEN
124              WHERE (resto(:,:) <= 1.e-07) resto(:,:) = 0._wp
125              !CALL custom_resto( resto )
126        ENDIF
127     ENDIF
128
129     ! Write out resto for this level
130     CALL check_nf90( nf90_put_var( ncout, resto_id, resto, (/ 1,1,jk /), (/ jpi, jpj,1 /) ) )
131
132  END DO
133 
134  ! Close the output file
135  CALL check_nf90( nf90_close(ncout) )
136
137END PROGRAM make_dmp_file
Note: See TracBrowser for help on using the repository browser.