source: LMDZ6/trunk/libf/phylmd/phyredem.F90 @ 3703

Last change on this file since 3703 was 3506, checked in by yann meurdesoif, 6 years ago

Solve 2 problems when writing restartphy files at high resolution :

  • large memory consumption that can lead to crash with an oom kill
  • very very long tile due to usage of NF_ENDDEF/NF_REDEF for each saved field. Now the first pass will create the nectdf header and the second pass will write the fields.

YM

  • Property copyright set to
    Name of program: LMDZ
    Creation date: 1984
    Version: LMDZ5
    License: CeCILL version 2
    Holder: Laboratoire de m\'et\'eorologie dynamique, CNRS, UMR 8539
    See the license file in the root directory
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.9 KB
RevLine 
[3080]1!
2! $Id: phyredem.F90 3506 2019-05-16 14:38:11Z adurocher $
3!
[1827]4SUBROUTINE phyredem (fichnom)
[2293]5!
6!-------------------------------------------------------------------------------
7! Author: Z.X. Li (LMD/CNRS), 1993/08/18
8!-------------------------------------------------------------------------------
9! Purpose: Write restart state for physics.
10!-------------------------------------------------------------------------------
[2395]11  USE dimphy, ONLY: klon, klev
[1827]12  USE fonte_neige_mod,  ONLY : fonte_neige_final
13  USE pbl_surface_mod,  ONLY : pbl_surface_final
[2499]14  USE phys_state_var_mod, ONLY: radpas, zmasq, pctsrf, ftsol, falb_dir,      &
[2395]15                                falb_dif, qsol, fevap, radsol, solsw, sollw, &
[2499]16                                sollwdown, rain_fall, snow_fall, z0m, z0h,   &
17                                agesno, zmea, zstd, zsig, zgam, zthe, zpic,  &
18                                zval, rugoro, t_ancien, q_ancien,            &
19                                prw_ancien, prlw_ancien, prsw_ancien,        &
20                                ql_ancien, qs_ancien,  u_ancien,             &
21                                v_ancien, clwcon, rnebcon, ratqs, pbl_tke,   &
22                                wake_delta_pbl_tke, zmax0, f0, sig1, w01,    &
[2635]23                                wake_deltat, wake_deltaq, wake_s, wake_dens, &
24                                wake_cstar,                                  &
[2499]25                                wake_pe, wake_fip, fm_therm, entr_therm,     &
[3080]26                                detr_therm, ale_bl, ale_bl_trig, alp_bl,     &
27                                ale_wake, ale_bl_stat,                       &
[2952]28                                du_gwd_rando, du_gwd_front, u10m, v10m,      &
29                                treedrg
[2395]30  USE geometry_mod, ONLY : longitude_deg, latitude_deg
[3506]31  USE iostart, ONLY: open_restartphy, close_restartphy, enddef_restartphy, put_field, put_var
[1827]32  USE traclmdz_mod, ONLY : traclmdz_to_restart
[2320]33  USE infotrac_phy, ONLY: type_trac, niadv, tname, nbtr, nqo
[1827]34  USE carbon_cycle_mod, ONLY : carbon_cycle_cpl, co2_send
[2395]35  USE indice_sol_mod, ONLY: nbsrf, is_oce, is_sic, is_ter, is_lic, epsfra
36  USE surface_data, ONLY: type_ocean, version_ocean
[2656]37  USE ocean_slab_mod, ONLY : nslay, tslab, seaice, tice, fsic
[2344]38  USE time_phylmdz_mod, ONLY: annee_ref, day_end, itau_phy, pdtphys
[967]39
[1827]40  IMPLICIT none
[2293]41
[1827]42  include "dimsoil.h"
43  include "clesphys.h"
44  include "thermcell.h"
45  include "compbl.h"
46  !======================================================================
47  CHARACTER*(*) fichnom
[967]48
[1827]49  ! les variables globales ecrites dans le fichier restart
[782]50
[1827]51  REAL tsoil(klon, nsoilmx, nbsrf)
52  REAL qsurf(klon, nbsrf)
53  REAL snow(klon, nbsrf)
54  real fder(klon)
55  REAL run_off_lic_0(klon)
56  REAL trs(klon, nbtr)
[782]57
[1827]58  INTEGER nid, nvarid, idim1, idim2, idim3
59  INTEGER ierr
60  INTEGER length
61  PARAMETER (length=100)
62  REAL tab_cntrl(length)
[782]63
[2237]64  INTEGER isoil, nsrf,isw
[2656]65  CHARACTER (len=2) :: str2
[2293]66  CHARACTER (len=256) :: nam, lnam
[3506]67  INTEGER           :: it, iiq, pass
[524]68
[1827]69  !======================================================================
[524]70
[1827]71  ! Get variables which will be written to restart file from module
72  ! pbl_surface_mod
[2243]73  CALL pbl_surface_final(fder, snow, qsurf,  tsoil)
[1279]74
[1827]75  ! Get a variable calculated in module fonte_neige_mod
76  CALL fonte_neige_final(run_off_lic_0)
[1001]77
[1827]78  !======================================================================
[1001]79
[1827]80  CALL open_restartphy(fichnom)
[1001]81
[3506]82 
[1827]83  DO ierr = 1, length
84     tab_cntrl(ierr) = 0.0
85  ENDDO
[2344]86  tab_cntrl(1) = pdtphys
[1827]87  tab_cntrl(2) = radpas
88  ! co2_ppm : current value of atmospheric CO2
89  tab_cntrl(3) = co2_ppm
90  tab_cntrl(4) = solaire
91  tab_cntrl(5) = iflag_con
92  tab_cntrl(6) = nbapp_rad
[524]93
[3317]94  IF( iflag_cycle_diurne.GE.1 ) tab_cntrl( 7 ) = iflag_cycle_diurne
[1827]95  IF(   soil_model ) tab_cntrl( 8 ) = 1.
96  IF(     new_oliq ) tab_cntrl( 9 ) = 1.
97  IF(     ok_orodr ) tab_cntrl(10 ) = 1.
98  IF(     ok_orolf ) tab_cntrl(11 ) = 1.
[524]99
[1827]100  tab_cntrl(13) = day_end
101  tab_cntrl(14) = annee_ref
102  tab_cntrl(15) = itau_phy
103
104  ! co2_ppm0 : initial value of atmospheric CO2
105  tab_cntrl(16) = co2_ppm0
106
[3506]107  DO pass=1,2   ! pass=1 netcdf definition ; pass=2 netcdf write
108 
109    CALL put_var(pass, "controle", "Parametres de controle", tab_cntrl)
[1827]110
[3506]111    CALL put_field(pass,"longitude", &
112         "Longitudes de la grille physique", longitude_deg)
[1827]113
[3506]114    CALL put_field(pass,"latitude", "Latitudes de la grille physique", latitude_deg)
[1827]115
[3506]116    ! PB ajout du masque terre/mer
[1827]117
[3506]118    CALL put_field(pass,"masque", "masque terre mer", zmasq)
[1827]119
[3506]120    ! BP ajout des fraction de chaque sous-surface
[1827]121
[3506]122    ! Get last fractions from slab ocean
123    IF (type_ocean == 'slab' .AND. version_ocean == "sicINT") THEN
124        WHERE (1.-zmasq(:).GT.EPSFRA)
125            pctsrf(:,is_oce)=(1.-fsic(:))*(1.-zmasq(:))
126            pctsrf(:,is_sic)=fsic(:)*(1.-zmasq(:))
127        END WHERE
128    END IF
[2209]129
[3506]130    ! 1. fraction de terre
[1827]131
[3506]132    CALL put_field(pass,"FTER", "fraction de continent", pctsrf(:, is_ter))
[1827]133
[3506]134    ! 2. Fraction de glace de terre
[1827]135
[3506]136    CALL put_field(pass,"FLIC", "fraction glace de terre", pctsrf(:, is_lic))
[1827]137
[3506]138    ! 3. fraction ocean
[1827]139
[3506]140    CALL put_field(pass,"FOCE", "fraction ocean", pctsrf(:, is_oce))
[1827]141
[3506]142    ! 4. Fraction glace de mer
[1827]143
[3506]144    CALL put_field(pass,"FSIC", "fraction glace mer", pctsrf(:, is_sic))
[1827]145
[3506]146    IF(nbsrf>99) THEN
147      PRINT*, "Trop de sous-mailles";  CALL abort_physic("phyredem", "", 1)
148    END IF
149    IF(nsoilmx>99) THEN
150      PRINT*, "Trop de sous-surfaces"; CALL abort_physic("phyredem", "", 1)
151    END IF
152    IF(nsw>99) THEN
153      PRINT*, "Trop de bandes"; CALL abort_physic("phyredem", "", 1)
154    END IF
[1827]155
[3506]156    CALL put_field_srf1(pass,"TS","Temperature",ftsol(:,:))
[2293]157
[2237]158! ================== Albedo =======================================
[3506]159    print*,'PHYREDEM NOUVEAU'
160    CALL put_field_srf2(pass,"A_dir_SW","Albedo direct",falb_dir(:,:,:))
161    CALL put_field_srf2(pass,"A_dif_SW","Albedo diffus",falb_dif(:,:,:))
[2237]162
[3506]163    CALL put_field_srf1(pass,"U10M", "u a 10m", u10m)
[2569]164
[3506]165    CALL put_field_srf1(pass,"V10M", "v a 10m", v10m)
[2569]166
167
[2293]168! ================== Tsoil =========================================
[3506]169    CALL put_field_srf2(pass,"Tsoil","Temperature",tsoil(:,:,:))
[2952]170!FC
171!  CALL put_field_srf2("treedrg","freinage arbres",treedrg(:,:,:))
[3506]172    CALL put_field(pass,"treedrg_ter","freinage arbres",treedrg(:,:,is_ter))
[524]173
[2952]174
[3506]175    CALL put_field_srf1(pass,"QS"  , "Humidite",qsurf(:,:))
[1827]176
[3506]177    CALL put_field     (pass,"QSOL", "Eau dans le sol (mm)", qsol)
[1827]178
[3506]179    CALL put_field_srf1(pass,"EVAP", "Evaporation", fevap(:,:))
[1827]180
[3506]181    CALL put_field_srf1(pass,"SNOW", "Neige", snow(:,:))
[1827]182
[3506]183    CALL put_field(pass,"RADS", "Rayonnement net a la surface", radsol)
[1827]184
[3506]185    CALL put_field(pass,"solsw", "Rayonnement solaire a la surface", solsw)
[1827]186
[3506]187    CALL put_field(pass,"sollw", "Rayonnement IF a la surface", sollw)
[1827]188
[3506]189    CALL put_field(pass,"sollwdown", "Rayonnement down IF a la surface", sollwdown)
[2188]190
[3506]191    CALL put_field(pass,"fder", "Derive de flux", fder)
[1827]192
[3506]193    CALL put_field(pass,"rain_f", "precipitation liquide", rain_fall)
[1827]194
[3506]195    CALL put_field(pass,"snow_f", "precipitation solide", snow_fall)
[1827]196
[3506]197    CALL put_field_srf1(pass,"Z0m", "rugosite", z0m(:,:))
[1827]198
[3506]199    CALL put_field_srf1(pass,"Z0h", "rugosite", z0h(:,:))
[1827]200
[3506]201    CALL put_field_srf1(pass,"AGESNO", "Age de la neige", agesno(:,:))
[2293]202
[3506]203    CALL put_field(pass,"ZMEA", "ZMEA", zmea)
[1827]204
[3506]205    CALL put_field(pass,"ZSTD", "ZSTD", zstd)
[1827]206
[3506]207    CALL put_field(pass,"ZSIG", "ZSIG", zsig)
[1827]208
[3506]209    CALL put_field(pass,"ZGAM", "ZGAM", zgam)
[1827]210
[3506]211    CALL put_field(pass,"ZTHE", "ZTHE", zthe)
[1827]212
[3506]213    CALL put_field(pass,"ZPIC", "ZPIC", zpic)
[1827]214
[3506]215    CALL put_field(pass,"ZVAL", "ZVAL", zval)
[1827]216
[3506]217    CALL put_field(pass,"RUGSREL", "RUGSREL", rugoro)
[1827]218
[3506]219    CALL put_field(pass,"TANCIEN", "TANCIEN", t_ancien)
[1827]220
[3506]221    CALL put_field(pass,"QANCIEN", "QANCIEN", q_ancien)
[1827]222
[3506]223    CALL put_field(pass,"QLANCIEN", "QLANCIEN", ql_ancien)
[2497]224
[3506]225    CALL put_field(pass,"QSANCIEN", "QSANCIEN", qs_ancien)
[2497]226
[3506]227    CALL put_field(pass,"PRWANCIEN", "PRWANCIEN", prw_ancien)
[1827]228
[3506]229    CALL put_field(pass,"PRLWANCIEN", "PRLWANCIEN", prlw_ancien)
[1827]230
[3506]231    CALL put_field(pass,"PRSWANCIEN", "PRSWANCIEN", prsw_ancien)
[2499]232
[3506]233    CALL put_field(pass,"UANCIEN", "UANCIEN", u_ancien)
[2499]234
[3506]235    CALL put_field(pass,"VANCIEN", "VANCIEN", v_ancien)
[2499]236
[3506]237    CALL put_field(pass,"CLWCON", "Eau liquide convective", clwcon)
[1827]238
[3506]239    CALL put_field(pass,"RNEBCON", "Nebulosite convective", rnebcon)
[1827]240
[3506]241    CALL put_field(pass,"RATQS", "Ratqs", ratqs)
[1827]242
[3506]243    ! run_off_lic_0
[1827]244
[3506]245    CALL put_field(pass,"RUNOFFLIC0", "Runofflic0", run_off_lic_0)
[1827]246
[3506]247    ! DEB TKE PBL !
[1827]248
[3506]249    IF (iflag_pbl>1) then
250      CALL put_field_srf3(pass,"TKE", "Energ. Cineti. Turb.", &
251           pbl_tke(:,:,:))
252      CALL put_field_srf3(pass,"DELTATKE", "Del TKE wk/env.", &
253           wake_delta_pbl_tke(:,:,:))
254    END IF
[1619]255
[3506]256    ! FIN TKE PBL !
257    !IM ajout zmax0, f0, sig1, w01
258    !IM wake_deltat, wake_deltaq, wake_s, wake_cstar, wake_pe, wake_fip
[1619]259
[3506]260    CALL put_field(pass,"ZMAX0", "ZMAX0", zmax0)
[1619]261
[3506]262    CALL put_field(pass,"F0", "F0", f0)
[878]263
[3506]264    CALL put_field(pass,"sig1", "sig1 Emanuel", sig1)
[1001]265
[3506]266    CALL put_field(pass,"w01", "w01 Emanuel", w01)
[1001]267
[3506]268    ! wake_deltat
269    CALL put_field(pass,"WAKE_DELTAT", "WAKE_DELTAT", wake_deltat)
[1279]270
[3506]271    CALL put_field(pass,"WAKE_DELTAQ", "WAKE_DELTAQ", wake_deltaq)
[1403]272
[3506]273    CALL put_field(pass,"WAKE_S", "Wake frac. area", wake_s)
[1403]274
[3506]275    CALL put_field(pass,"WAKE_DENS", "Wake num. /unit area", wake_dens)
[2635]276
[3506]277    CALL put_field(pass,"WAKE_CSTAR", "WAKE_CSTAR", wake_cstar)
[1403]278
[3506]279    CALL put_field(pass,"WAKE_PE", "WAKE_PE", wake_pe)
[1403]280
[3506]281    CALL put_field(pass,"WAKE_FIP", "WAKE_FIP", wake_fip)
[1279]282
[3506]283    ! thermiques
[1827]284
[3506]285    CALL put_field(pass,"FM_THERM", "FM_THERM", fm_therm)
[1827]286
[3506]287    CALL put_field(pass,"ENTR_THERM", "ENTR_THERM", entr_therm)
[1827]288
[3506]289    CALL put_field(pass,"DETR_THERM", "DETR_THERM", detr_therm)
[1827]290
[3506]291    CALL put_field(pass,"ALE_BL", "ALE_BL", ale_bl)
[2069]292
[3506]293    CALL put_field(pass,"ALE_BL_TRIG", "ALE_BL_TRIG", ale_bl_trig)
[2069]294
[3506]295    CALL put_field(pass,"ALP_BL", "ALP_BL", alp_bl)
[2069]296
[3506]297    CALL put_field(pass,"ALE_WAKE", "ALE_WAKE", ale_wake)
[3080]298
[3506]299    CALL put_field(pass,"ALE_BL_STAT", "ALE_BL_STAT", ale_bl_stat)
[3080]300
301
[3506]302    ! trs from traclmdz_mod
303    IF (type_trac == 'lmdz') THEN
304       CALL traclmdz_to_restart(trs)
305       DO it=1, nbtr
[2265]306!!        iiq=niadv(it+2)                                                           ! jyg
[3506]307          iiq=niadv(it+nqo)                                                           ! jyg
308          CALL put_field(pass,"trs_"//tname(iiq), "", trs(:, it))
309       END DO
310       IF (carbon_cycle_cpl) THEN
311          IF (.NOT. ALLOCATED(co2_send)) THEN
312             ! This is the case of create_etat0_limit, ce0l
313             ALLOCATE(co2_send(klon))
314             co2_send(:) = co2_ppm0
315          END IF
316          CALL put_field(pass,"co2_send", "co2_ppm for coupling", co2_send)
317       END IF
318    END IF
319
320    ! Restart variables for Slab ocean
321    IF (type_ocean == 'slab') THEN
322        IF (nslay.EQ.1) THEN
323          CALL put_field(pass,"tslab", "Slab ocean temperature", tslab)
324        ELSE
325          DO it=1,nslay
326            WRITE(str2,'(i2.2)') it
327            CALL put_field(pass,"tslab"//str2, "Slab ocean temperature", tslab(:,it))
328          END DO
[1827]329        END IF
[3506]330        IF (version_ocean == 'sicINT') THEN
331            CALL put_field(pass,"seaice", "Slab seaice (kg/m2)", seaice)
332            CALL put_field(pass,"slab_tice", "Slab sea ice temperature", tice)
333        END IF
334    END IF
[1827]335
[3506]336    if (ok_gwd_rando) call put_field(pass,"du_gwd_rando", &
337         "tendency on zonal wind due to flott gravity waves", du_gwd_rando)
[2057]338
[3506]339    IF (.not. ok_hines .and. ok_gwd_rando) call put_field(pass,"du_gwd_front", &
340         "tendency on zonal wind due to acama gravity waves", du_gwd_front)
[1938]341
[3506]342    IF (pass==1) CALL enddef_restartphy
343    IF (pass==2) CALL close_restartphy
344  ENDDO
345 
[1827]346  !$OMP BARRIER
347
[2293]348
349  CONTAINS
350
351
[3506]352SUBROUTINE put_field_srf1(pass,nam,lnam,field)
[2293]353
354  IMPLICIT NONE
[3506]355  INTEGER, INTENT(IN)            :: pass
[2293]356  CHARACTER(LEN=*),  INTENT(IN) :: nam, lnam
357  REAL,              INTENT(IN) :: field(:,:)
358  CHARACTER(LEN=256) :: nm, lm, str
[2299]359  DO nsrf = 1, SIZE(field,2)
[2293]360    WRITE(str, '(i2.2)') nsrf
361    nm=TRIM(nam)//TRIM(str)
362    lm=TRIM(lnam)//" de surface No. "//TRIM(str)
[3506]363    CALL put_field(pass,nm,lm,field(:,nsrf))
[2293]364  END DO
365
366END SUBROUTINE put_field_srf1
367
368
[3506]369SUBROUTINE put_field_srf2(pass,nam,lnam,field)
[2293]370
371  IMPLICIT NONE
[3506]372  INTEGER, INTENT(IN)            :: pass
[2293]373  CHARACTER(LEN=*),  INTENT(IN) :: nam, lnam
374  REAL,              INTENT(IN) :: field(:,:,:)
375  CHARACTER(LEN=256) :: nm, lm, str
[2299]376  DO nsrf = 1, SIZE(field,3)
377    DO isoil=1, SIZE(field,2)
[2293]378      WRITE(str, '(i2.2,"srf",i2.2)')isoil,nsrf
379!      WRITE(lunout,*)"PHYREDEM ",TRIM(nam)//TRIM(str)
380      nm=TRIM(nam)//TRIM(str)
381      lm=TRIM(lnam)//" du sol No. "//TRIM(str)
[3506]382      CALL put_field(pass,nm,lm,field(:,isoil,nsrf))
[2293]383    END DO
384  END DO
385
386END SUBROUTINE put_field_srf2
387
388
[3506]389SUBROUTINE put_field_srf3(pass,nam,lnam,field)
[2293]390
391  IMPLICIT NONE
[3506]392  INTEGER, INTENT(IN)            :: pass
[2293]393  CHARACTER(LEN=*),  INTENT(IN) :: nam, lnam
394  REAL,              INTENT(IN) :: field(:,:,:)
395  CHARACTER(LEN=256) :: nm, lm, str
[2299]396  DO nsrf = 1, SIZE(field,3)
[2293]397    WRITE(str, '(i2.2)') nsrf
398    nm=TRIM(nam)//TRIM(str)
399    lm=TRIM(lnam)//TRIM(str)
[3506]400    CALL put_field(pass,nm,lm,field(:,1:klev+1,nsrf))
[2293]401  END DO
402
403END SUBROUTINE put_field_srf3
404
405
[1827]406END SUBROUTINE phyredem
Note: See TracBrowser for help on using the repository browser.