GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: phylmd/phyredem.F90 Lines: 151 177 85.3 %
Date: 2023-06-30 12:51:15 Branches: 48 106 45.3 %

Line Branch Exec Source
1
!
2
! $Id: phyredem.F90 4551 2023-05-28 06:35:02Z fhourdin $
3
!
4
24
SUBROUTINE phyredem (fichnom)
5
!
6
!-------------------------------------------------------------------------------
7
! Author: Z.X. Li (LMD/CNRS), 1993/08/18
8
!-------------------------------------------------------------------------------
9
! Purpose: Write restart state for physics.
10
!-------------------------------------------------------------------------------
11
  USE dimphy, ONLY: klon, klev
12
  USE fonte_neige_mod,  ONLY : fonte_neige_final
13
  USE pbl_surface_mod,  ONLY : pbl_surface_final
14
  USE phys_state_var_mod, ONLY: radpas, zmasq, pctsrf,                       &
15
                                ftsol, beta_aridity, delta_tsurf, falb_dir,  &
16
                                falb_dif, qsol, fevap, radsol, solsw, sollw, &
17
                                sollwdown, rain_fall, snow_fall, bs_fall, z0m, z0h, &
18
                                agesno, zmea, zstd, zsig, zgam, zthe, zpic,  &
19
                                zval, rugoro, t_ancien, q_ancien,            &
20
                                prw_ancien, prlw_ancien, prsw_ancien, prbsw_ancien,      &
21
                                ql_ancien, qs_ancien, qbs_ancien, rneb_ancien, u_ancien, &
22
                                v_ancien, clwcon, rnebcon, ratqs, pbl_tke,   &
23
                                wake_delta_pbl_tke, zmax0, f0, sig1, w01,    &
24
                                wake_deltat, wake_deltaq, wake_s, wake_dens, &
25
                                awake_dens, cv_gen,                          &
26
                                wake_cstar,                                  &
27
                                wake_pe, wake_fip, fm_therm, entr_therm,     &
28
                                detr_therm, ale_bl, ale_bl_trig, alp_bl,     &
29
                                ale_wake, ale_bl_stat,                       &
30
                                du_gwd_rando, du_gwd_front, u10m, v10m, &
31
                                treedrg, solswfdiff, delta_sal, ds_ns, dt_ns, &
32
                                delta_sst, ratqs_inter, dter, dser, dt_ds
33
34
  USE geometry_mod, ONLY : longitude_deg, latitude_deg
35
  USE iostart, ONLY: open_restartphy, close_restartphy, enddef_restartphy, put_field, put_var
36
  USE traclmdz_mod, ONLY : traclmdz_to_restart
37
  USE infotrac_phy, ONLY: type_trac, nqtot, tracers, nbtr
38
  USE carbon_cycle_mod, ONLY : carbon_cycle_cpl, co2_send, carbon_cycle_rad, RCO2_glo
39
  USE indice_sol_mod, ONLY: nbsrf, is_oce, is_sic, is_ter, is_lic, epsfra
40
  USE surface_data, ONLY: type_ocean, version_ocean
41
  USE ocean_slab_mod, ONLY : nslay, tslab, seaice, tice, fsic
42
  USE time_phylmdz_mod, ONLY: annee_ref, day_end, itau_phy, pdtphys
43
  use config_ocean_skin_m, only: activate_ocean_skin
44
45
  IMPLICIT none
46
47
  include "dimsoil.h"
48
  include "clesphys.h"
49
  include "alpale.h"
50
  include "compbl.h"
51
  !======================================================================
52
  CHARACTER*(*) fichnom
53
54
  ! les variables globales ecrites dans le fichier restart
55
56
2
  REAL tsoil(klon, nsoilmx, nbsrf)
57
2
  REAL qsurf(klon, nbsrf)
58
2
  REAL snow(klon, nbsrf)
59
2
  real fder(klon)
60
2
  REAL run_off_lic_0(klon)
61
2
  REAL trs(klon, nbtr)
62
63
  INTEGER nid, nvarid, idim1, idim2, idim3
64
  INTEGER ierr
65
  INTEGER length
66
  PARAMETER (length=100)
67
  REAL tab_cntrl(length)
68
69
  INTEGER isoil, nsrf,isw
70
  CHARACTER (len=2) :: str2
71
  CHARACTER (len=256) :: nam, lnam
72
  INTEGER           :: it, iq, pass
73
74
  !======================================================================
75
76
  ! Get variables which will be written to restart file from module
77
  ! pbl_surface_mod
78
1
  if ( iflag_physiq <= 1 ) then
79
1
     CALL pbl_surface_final(fder, snow, qsurf,  tsoil)
80
  endif
81
82
  ! Get a variable calculated in module fonte_neige_mod
83
1
  CALL fonte_neige_final(run_off_lic_0)
84
85
  !======================================================================
86
87
1
  CALL open_restartphy(fichnom)
88
89
90
101
  DO ierr = 1, length
91
101
     tab_cntrl(ierr) = 0.0
92
  ENDDO
93
1
  tab_cntrl(1) = pdtphys
94
1
  tab_cntrl(2) = radpas
95
  ! co2_ppm : current value of atmospheric CO2
96
1
  tab_cntrl(3) = co2_ppm
97
1
  tab_cntrl(4) = solaire
98
1
  tab_cntrl(5) = iflag_con
99
1
  tab_cntrl(6) = nbapp_rad
100
101
1
  IF( iflag_cycle_diurne.GE.1 ) tab_cntrl( 7 ) = iflag_cycle_diurne
102
1
  IF(   soil_model ) tab_cntrl( 8 ) = 1.
103
1
  IF(     new_oliq ) tab_cntrl( 9 ) = 1.
104
1
  IF(     ok_orodr ) tab_cntrl(10 ) = 1.
105
1
  IF(     ok_orolf ) tab_cntrl(11 ) = 1.
106
107
1
  tab_cntrl(13) = day_end
108
1
  tab_cntrl(14) = annee_ref
109
1
  tab_cntrl(15) = itau_phy
110
111
  ! co2_ppm0 : initial value of atmospheric CO2
112
  ! tab_cntrl(16) = co2_ppm0
113
114
  !  PC -- initial value of RCO2 for the radiation scheme
115
  !  tab_cntrl(17) = co2_ppm * 1.0e-06 * RMCO2 / RMD
116
1
  IF (carbon_cycle_rad) tab_cntrl(17) = RCO2_glo
117
  !PRINT*, "PC : phyredem RCO2_glo =",RCO2_glo
118
119
3
  DO pass=1,2   ! pass=1 netcdf definition ; pass=2 netcdf write
120
121
2
    CALL put_var(pass, "controle", "Parametres de controle", tab_cntrl)
122
123
    CALL put_field(pass,"longitude", &
124
2
         "Longitudes de la grille physique", longitude_deg)
125
126
2
    CALL put_field(pass,"latitude", "Latitudes de la grille physique", latitude_deg)
127
128
    ! PB ajout du masque terre/mer
129
130
2
    CALL put_field(pass,"masque", "masque terre mer", zmasq)
131
132
    ! BP ajout des fraction de chaque sous-surface
133
134
    ! Get last fractions from slab ocean
135

2
    IF (type_ocean == 'slab' .AND. version_ocean == "sicINT") THEN
136
        WHERE (1.-zmasq(:).GT.EPSFRA)
137
            pctsrf(:,is_oce)=(1.-fsic(:))*(1.-zmasq(:))
138
            pctsrf(:,is_sic)=fsic(:)*(1.-zmasq(:))
139
        END WHERE
140
    END IF
141
142
    ! 1. fraction de terre
143
144
2
    CALL put_field(pass,"FTER", "fraction de continent", pctsrf(:, is_ter))
145
146
    ! 2. Fraction de glace de terre
147
148
2
    CALL put_field(pass,"FLIC", "fraction glace de terre", pctsrf(:, is_lic))
149
    ! 3. fraction ocean
150
151
2
    CALL put_field(pass,"FOCE", "fraction ocean", pctsrf(:, is_oce))
152
153
    ! 4. Fraction glace de mer
154
155
2
    CALL put_field(pass,"FSIC", "fraction glace mer", pctsrf(:, is_sic))
156
157
    IF(nbsrf>99) THEN
158
      PRINT*, "Trop de sous-mailles";  CALL abort_physic("phyredem", "", 1)
159
    END IF
160
    IF(nsoilmx>99) THEN
161
      PRINT*, "Trop de sous-surfaces"; CALL abort_physic("phyredem", "", 1)
162
    END IF
163
2
    IF(nsw>99) THEN
164
      PRINT*, "Trop de bandes"; CALL abort_physic("phyredem", "", 1)
165
    END IF
166
167
!    Surface variables
168
2
    CALL put_field_srf1(pass,"TS","Temperature",ftsol(:,:))
169
170

2
    IF (iflag_pbl>1 .AND. iflag_wake>=1  .AND. iflag_pbl_split >=1) then
171
       CALL put_field_srf1(pass, "DELTATS", &
172
2
            "w-x surface temperature difference", delta_tsurf(:,:))
173
2
       CALL put_field_srf1(pass,"BETAS","Aridity factor", beta_aridity(:,:))
174
    end IF
175
!    End surface variables
176
177
! ================== Albedo =======================================
178
2
    print*,'PHYREDEM NOUVEAU'
179
2
    CALL put_field_srf2(pass,"A_dir_SW","Albedo direct",falb_dir(:,:,:))
180
2
    CALL put_field_srf2(pass,"A_dif_SW","Albedo diffus",falb_dif(:,:,:))
181
182
2
    CALL put_field_srf1(pass,"U10M", "u a 10m", u10m)
183
184
2
    CALL put_field_srf1(pass,"V10M", "v a 10m", v10m)
185
186
187
! ================== Tsoil =========================================
188
2
    CALL put_field_srf2(pass,"Tsoil","Temperature",tsoil(:,:,:))
189
!FC
190
!  CALL put_field_srf2("treedrg","freinage arbres",treedrg(:,:,:))
191
2
    CALL put_field(pass,"treedrg_ter","freinage arbres",treedrg(:,:,is_ter))
192
193
194
2
    CALL put_field_srf1(pass,"QS"  , "Humidite",qsurf(:,:))
195
196
2
    CALL put_field     (pass,"QSOL", "Eau dans le sol (mm)", qsol)
197
198
2
    CALL put_field_srf1(pass,"EVAP", "Evaporation", fevap(:,:))
199
200
2
    CALL put_field_srf1(pass,"SNOW", "Neige", snow(:,:))
201
202
2
    CALL put_field(pass,"RADS", "Rayonnement net a la surface", radsol)
203
204
2
    CALL put_field(pass,"solsw", "Rayonnement solaire a la surface", solsw)
205
206
2
    CALL put_field(pass,"solswfdiff", "Fraction du rayonnement solaire a la surface qui est diffus", solswfdiff)
207
208
2
    CALL put_field(pass,"sollw", "Rayonnement IF a la surface", sollw)
209
210
2
    CALL put_field(pass,"sollwdown", "Rayonnement down IF a la surface", sollwdown)
211
212
2
    CALL put_field(pass,"fder", "Derive de flux", fder)
213
214
2
    CALL put_field(pass,"rain_f", "precipitation liquide", rain_fall)
215
216
2
    CALL put_field(pass,"snow_f", "precipitation solide", snow_fall)
217
218
2
    CALL put_field_srf1(pass,"Z0m", "rugosite", z0m(:,:))
219
220
2
    CALL put_field_srf1(pass,"Z0h", "rugosite", z0h(:,:))
221
222
2
    CALL put_field_srf1(pass,"AGESNO", "Age de la neige", agesno(:,:))
223
224
2
    CALL put_field(pass,"ZMEA", "ZMEA", zmea)
225
226
2
    CALL put_field(pass,"ZSTD", "ZSTD", zstd)
227
228
2
    CALL put_field(pass,"ZSIG", "ZSIG", zsig)
229
230
2
    CALL put_field(pass,"ZGAM", "ZGAM", zgam)
231
232
2
    CALL put_field(pass,"ZTHE", "ZTHE", zthe)
233
234
2
    CALL put_field(pass,"ZPIC", "ZPIC", zpic)
235
236
2
    CALL put_field(pass,"ZVAL", "ZVAL", zval)
237
238
2
    CALL put_field(pass,"RUGSREL", "RUGSREL", rugoro)
239
240
2
    CALL put_field(pass,"TANCIEN", "TANCIEN", t_ancien)
241
242
2
    CALL put_field(pass,"QANCIEN", "QANCIEN", q_ancien)
243
244
2
    CALL put_field(pass,"QLANCIEN", "QLANCIEN", ql_ancien)
245
246
2
    CALL put_field(pass,"QSANCIEN", "QSANCIEN", qs_ancien)
247
248
2
    IF (ok_bs) THEN
249
       CALL put_field(pass,"bs_f", "precipitation neige soufflee", bs_fall)
250
       CALL put_field(pass,"QBSANCIEN", "QBSANCIEN", qbs_ancien)
251
       CALL put_field(pass,"PRBSWANCIEN", "PRBSWANCIEN", prbsw_ancien)
252
    ENDIF
253
254
2
    CALL put_field(pass,"RNEBANCIEN", "RNEBANCIEN", rneb_ancien)
255
256
2
    CALL put_field(pass,"PRWANCIEN", "PRWANCIEN", prw_ancien)
257
258
2
    CALL put_field(pass,"PRLWANCIEN", "PRLWANCIEN", prlw_ancien)
259
260
2
    CALL put_field(pass,"PRSWANCIEN", "PRSWANCIEN", prsw_ancien)
261
262
2
    CALL put_field(pass,"UANCIEN", "UANCIEN", u_ancien)
263
264
2
    CALL put_field(pass,"VANCIEN", "VANCIEN", v_ancien)
265
266
2
    CALL put_field(pass,"CLWCON", "Eau liquide convective", clwcon)
267
268
2
    CALL put_field(pass,"RNEBCON", "Nebulosite convective", rnebcon)
269
270
2
    CALL put_field(pass,"RATQS", "Ratqs", ratqs)
271
272
    ! run_off_lic_0
273
274
2
    CALL put_field(pass,"RUNOFFLIC0", "Runofflic0", run_off_lic_0)
275
276
    ! DEB TKE PBL !
277
278
2
    IF (iflag_pbl>1) then
279
      CALL put_field_srf3(pass,"TKE", "Energ. Cineti. Turb.", &
280
2
           pbl_tke(:,:,:))
281
      CALL put_field_srf3(pass,"DELTATKE", "Del TKE wk/env.", &
282
2
           wake_delta_pbl_tke(:,:,:))
283
    END IF
284
285
    ! FIN TKE PBL !
286
    !IM ajout zmax0, f0, sig1, w01
287
    !IM wake_deltat, wake_deltaq, wake_s, wake_cstar, wake_pe, wake_fip
288
289
2
    CALL put_field(pass,"ZMAX0", "ZMAX0", zmax0)
290
291
2
    CALL put_field(pass,"F0", "F0", f0)
292
293
2
    CALL put_field(pass,"sig1", "sig1 Emanuel", sig1)
294
295
2
    CALL put_field(pass,"w01", "w01 Emanuel", w01)
296
297
    ! wake_deltat
298
2
    CALL put_field(pass,"WAKE_DELTAT", "WAKE_DELTAT", wake_deltat)
299
300
2
    CALL put_field(pass,"WAKE_DELTAQ", "WAKE_DELTAQ", wake_deltaq)
301
302
2
    CALL put_field(pass,"WAKE_S", "Wake frac. area", wake_s)
303
304
2
    CALL put_field(pass,"WAKE_DENS", "Wake num. /unit area", wake_dens)
305
306
2
    CALL put_field(pass,"AWAKE_DENS", "Active Wake num. /unit area", awake_dens)
307
308
2
    CALL put_field(pass,"CV_GEN", "CB birth rate", cv_gen)
309
310
2
    CALL put_field(pass,"WAKE_CSTAR", "WAKE_CSTAR", wake_cstar)
311
312
2
    CALL put_field(pass,"WAKE_PE", "WAKE_PE", wake_pe)
313
314
2
    CALL put_field(pass,"WAKE_FIP", "WAKE_FIP", wake_fip)
315
316
    ! thermiques
317
318
2
    CALL put_field(pass,"FM_THERM", "FM_THERM", fm_therm)
319
320
2
    CALL put_field(pass,"ENTR_THERM", "ENTR_THERM", entr_therm)
321
322
2
    CALL put_field(pass,"DETR_THERM", "DETR_THERM", detr_therm)
323
324
2
    CALL put_field(pass,"ALE_BL", "ALE_BL", ale_bl)
325
326
2
    CALL put_field(pass,"ALE_BL_TRIG", "ALE_BL_TRIG", ale_bl_trig)
327
328
2
    CALL put_field(pass,"ALP_BL", "ALP_BL", alp_bl)
329
330
2
    CALL put_field(pass,"ALE_WAKE", "ALE_WAKE", ale_wake)
331
332
2
    CALL put_field(pass,"ALE_BL_STAT", "ALE_BL_STAT", ale_bl_stat)
333
334
335
    ! fisrtilp/clouds
336
2
    CALL put_field(pass,"RATQS_INTER","Relative width of the lsc sugrid scale water",ratqs_inter)
337
338
339

6
    IF (ANY(type_trac == ['co2i','inco'])) THEN
340
       IF (carbon_cycle_cpl) THEN
341
          IF (.NOT. ALLOCATED(co2_send)) THEN
342
             ! This is the case of create_etat0_limit, ce0l
343
             ALLOCATE(co2_send(klon))
344
             co2_send(:) = co2_ppm0
345
          END IF
346
          CALL put_field(pass,"co2_send", "co2_ppm for coupling", co2_send)
347
       END IF
348
349
    ! trs from traclmdz_mod
350
2
    ELSE IF (type_trac == 'lmdz') THEN
351
2
       CALL traclmdz_to_restart(trs)
352
2
       it = 0
353
12
       DO iq = 1, nqtot
354

10
          IF(.NOT.(tracers(iq)%isAdvected .AND. tracers(iq)%isInPhysics)) CYCLE
355
4
          it = it+1
356
12
          CALL put_field(pass,"trs_"//tracers(iq)%name, "", trs(:, it))
357
       END DO
358
    END IF
359
360
    ! Restart variables for Slab ocean
361
2
    IF (type_ocean == 'slab') THEN
362
        IF (nslay.EQ.1) THEN
363
          CALL put_field(pass,"tslab", "Slab ocean temperature", tslab)
364
        ELSE
365
          DO it=1,nslay
366
            WRITE(str2,'(i2.2)') it
367
            CALL put_field(pass,"tslab"//str2, "Slab ocean temperature", tslab(:,it))
368
          END DO
369
        END IF
370
        IF (version_ocean == 'sicINT') THEN
371
            CALL put_field(pass,"seaice", "Slab seaice (kg/m2)", seaice)
372
            CALL put_field(pass,"slab_tice", "Slab sea ice temperature", tice)
373
        END IF
374
    END IF
375
376
2
    if (ok_gwd_rando) call put_field(pass,"du_gwd_rando", &
377
2
         "tendency on zonal wind due to flott gravity waves", du_gwd_rando)
378
379

2
    IF (.not. ok_hines .and. ok_gwd_rando) call put_field(pass,"du_gwd_front", &
380
2
         "tendency on zonal wind due to acama gravity waves", du_gwd_front)
381
382
2
    if (activate_ocean_skin >= 1) then
383
       if (activate_ocean_skin == 2 .and. type_ocean == 'couple') then
384
          CALL put_field(pass, "delta_sal", &
385
               "ocean-air interface salinity minus bulk salinity", delta_sal)
386
          CALL put_field(pass, "delta_SST", &
387
               "ocean-air interface temperature minus bulk SST", delta_sst)
388
          CALL put_field(pass, "dter", &
389
               "ocean-air interface temperature minus subskin temperature", &
390
               dter)
391
          CALL put_field(pass, "dser", &
392
               "ocean-air interface salinity minus subskin salinity", dser)
393
          CALL put_field(pass, "dt_ds", &
394
               "(tks / tkt) * dTer", dt_ds)
395
       end if
396
397
       CALL put_field(pass, "dS_ns", "delta salinity near surface", ds_ns)
398
       CALL put_field(pass, "dT_ns", "delta temperature near surface", dT_ns)
399
    end if
400
401
2
    IF (pass==1) CALL enddef_restartphy
402
3
    IF (pass==2) CALL close_restartphy
403
  ENDDO ! DO pass=1,2   ! pass=1 netcdf definition ; pass=2 netcdf write
404
405
  !$OMP BARRIER
406
407
408
  CONTAINS
409
410
411
22
SUBROUTINE put_field_srf1(pass,nam,lnam,field)
412
413
  IMPLICIT NONE
414
  INTEGER, INTENT(IN)           :: pass
415
  CHARACTER(LEN=*),  INTENT(IN) :: nam, lnam
416
  REAL,              INTENT(IN) :: field(:,:)
417
  CHARACTER(LEN=256) :: nm, lm, str
418
114
  DO nsrf = 1, SIZE(field,2)
419
92
    WRITE(str, '(i2.2)') nsrf
420
92
    nm=TRIM(nam)//TRIM(str)
421
92
    lm=TRIM(lnam)//" de surface No. "//TRIM(str)
422
114
    CALL put_field(pass,nm,lm,field(:,nsrf))
423
  END DO
424
425
22
END SUBROUTINE put_field_srf1
426
427
428
6
SUBROUTINE put_field_srf2(pass,nam,lnam,field)
429
430
  IMPLICIT NONE
431
  INTEGER, INTENT(IN)            :: pass
432
  CHARACTER(LEN=*),  INTENT(IN) :: nam, lnam
433
  REAL,              INTENT(IN) :: field(:,:,:)
434
  CHARACTER(LEN=256) :: nm, lm, str
435
30
  DO nsrf = 1, SIZE(field,3)
436
214
    DO isoil=1, SIZE(field,2)
437
184
      WRITE(str, '(i2.2,"srf",i2.2)')isoil,nsrf
438
!      WRITE(lunout,*)"PHYREDEM ",TRIM(nam)//TRIM(str)
439
184
      nm=TRIM(nam)//TRIM(str)
440
184
      lm=TRIM(lnam)//" du sol No. "//TRIM(str)
441
208
      CALL put_field(pass,nm,lm,field(:,isoil,nsrf))
442
    END DO
443
  END DO
444
445
6
END SUBROUTINE put_field_srf2
446
447
448
4
SUBROUTINE put_field_srf3(pass,nam,lnam,field)
449
450
  IMPLICIT NONE
451
  INTEGER, INTENT(IN)            :: pass
452
  CHARACTER(LEN=*),  INTENT(IN) :: nam, lnam
453
  REAL,              INTENT(IN) :: field(:,:,:)
454
  CHARACTER(LEN=256) :: nm, lm, str
455
24
  DO nsrf = 1, SIZE(field,3)
456
20
    WRITE(str, '(i2.2)') nsrf
457
20
    nm=TRIM(nam)//TRIM(str)
458
20
    lm=TRIM(lnam)//TRIM(str)
459
24
    CALL put_field(pass,nm,lm,field(:,1:klev+1,nsrf))
460
  END DO
461
462
4
END SUBROUTINE put_field_srf3
463
464
465
END SUBROUTINE phyredem