Ignore:
Timestamp:
May 22, 2013, 9:10:28 AM (12 years ago)
Author:
emillour
Message:

Common dynamics and generic/universal GCM:

  • LMDZ.COMMON: minor bug fix on the computation of physics mesh area in gcm.F
  • LMDZ.UNIVERSAL: missing clean initialization of tab_cntrl(:) array in phyredem.F90
  • LMDZ.GENERIC: minor bug fix in hydrol.F90, only output runoff if it is used. Update output routines so that all outputs files (stats, diagfi.nc, diagsoil.nc, diagspecIR.nc and diagspecVI.nc) can be generated when running LMDZ.UNIVERSAL in MPI mode.

EM

Location:
trunk/LMDZ.GENERIC/libf/phystd
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/LMDZ.GENERIC/libf/phystd/hydrol.F90

    r875 r965  
    110110         
    111111         
    112          ALLOCATE(runoff(ngrid))
     112         if (activerunoff) ALLOCATE(runoff(ngrid))
    113113
    114114         ivap=igcm_h2o_vap
     
    360360      enddo
    361361
    362       call writediagfi(ngrid,'runoff','Runoff amount',' ',2,runoff)
     362      if (activerunoff) then
     363        call writediagfi(ngrid,'runoff','Runoff amount',' ',2,runoff)
     364      endif
    363365
    364366      return
  • trunk/LMDZ.GENERIC/libf/phystd/inistats.F

    r135 r965  
    11      subroutine inistats(ierr)
    22
     3#ifdef CPP_PARA
     4      use mod_phys_lmdz_para, only : is_master
     5#endif
    36      implicit none
    47
     
    1114#include "netcdf.inc"
    1215
     16#ifndef CPP_PARA
     17      logical,parameter :: is_master=.true.
     18#endif
    1319      integer,intent(out) :: ierr
    1420      integer :: nid
     
    4753         pseudoalt(l)=-10.*log(presnivs(l)/preff)   
    4854      enddo
     55
     56      if (is_master) then
     57      ! only the master needs do this
    4958
    5059      ierr = NF_CREATE("stats.nc",NF_CLOBBER,nid)
     
    115124      ierr=NF_CLOSE(nid)
    116125
     126      endif ! of if (is_master)
    117127      end
  • trunk/LMDZ.GENERIC/libf/phystd/iniwrite_specIR.F

    r787 r965  
    1       SUBROUTINE iniwrite_specIR(nid,idayref,phis)
     1      SUBROUTINE iniwrite_specIR(nid,idayref)
    22
    33      use radinc_h, only: L_NSPECTI
    44      use radcommon_h, only: WNOI,DWNI
    5       use comsoil_h
     5!      use comsoil_h
    66
    77      implicit none
     
    4040c   ----------
    4141
    42       integer nid        ! NetCDF file ID
    43       INTEGER*4 idayref  ! date (initial date for this run)
    44       REAL phis(ip1jmp1) ! surface geopotential
     42      integer,intent(in) :: nid        ! NetCDF file ID
     43      INTEGER*4,intent(in) :: idayref  ! date (initial date for this run)
    4544
    4645c   Local:
  • trunk/LMDZ.GENERIC/libf/phystd/iniwrite_specVI.F

    r787 r965  
    1       SUBROUTINE iniwrite_specVI(nid,idayref,phis)
     1      SUBROUTINE iniwrite_specVI(nid,idayref)
    22
    33      use radinc_h, only: L_NSPECTV
     
    4242      integer nid        ! NetCDF file ID
    4343      INTEGER*4 idayref  ! date (initial date for this run)
    44       REAL phis(ip1jmp1) ! surface geopotential
    4544
    4645c   Local:
  • trunk/LMDZ.GENERIC/libf/phystd/iniwritesoil.F90

    r787 r965  
    11subroutine iniwritesoil(nid,ngrid)
    22
    3 use comsoil_h
     3use comsoil_h, only : inertiedat, mlayer
     4#ifdef CPP_PARA
     5use mod_phys_lmdz_para, only : is_mpi_root, is_master, gather
     6use mod_grid_phy_lmdz, only : klon_glo, Grid1Dto2D_glo
     7#endif
    48
    59! initialization routine for 'writediagoil'. Here we create/define
     
    3438integer :: i,j,l,ig0
    3539
     40#ifdef CPP_PARA
     41! Added to work in parallel mode
     42real dx3_glop(klon_glo,nsoilmx)
     43real dx3_glo(iim,jjp1,nsoilmx) ! to store a global 3D data set
     44#else
     45logical,parameter :: is_master=.true.
     46logical,parameter :: is_mpi_root=.true.
     47#endif
     48
    3649! 1. Define the dimensions
     50if (is_master) then
    3751! Switch to NetCDF define mode
    3852ierr=NF_REDEF(nid)
     
    183197! Note no need to write time variable here; it is done in writediagsoil.
    184198
     199endif ! of if (is_master)
     200
    185201! 3. Other variables to be included
    186202
    187203! 3.1 mesh area surrounding each horizontal point
     204if (is_master) then
    188205ierr=NF_REDEF(nid) ! switch to NetCDF define mode
    189206
     
    219236endif
    220237
     238endif ! of if (is_master)
     239
     240
    221241! 3.2 Thermal inertia
     242if (is_master) then
    222243ierr=NF_REDEF(nid) ! switch to NetCDF define mode
    223244
     
    241262ierr=NF_PUT_ATT_TEXT(nid,varid,"units",len_trim(text),text)
    242263
     264endif !of if (is_master)
     265
    243266! Recast data along 'dynamics' grid
     267#ifdef CPP_PARA
     268  ! gather field on a "global" (without redundant longitude) array
     269  call Gather(inertiedat,dx3_glop)
     270!$OMP MASTER
     271  if (is_mpi_root) then
     272    call Grid1Dto2D_glo(dx3_glop,dx3_glo)
     273    ! copy dx3_glo() to dx3(:) and add redundant longitude
     274    data3(1:iim,:,:)=dx3_glo(1:iim,:,:)
     275    data3(iip1,:,:)=data3(1,:,:)
     276  endif
     277!$OMP END MASTER
     278!$OMP BARRIER
     279#else
    244280! Note: inertiedat is known from comsoil.h
    245 
    246281do l=1,nsoilmx
    247282  ! handle the poles
     
    250285    data3(i,jjp1,l)=inertiedat(ngrid,l)
    251286  enddo
    252   !!! THIS WILL NOT WORK IN PARALLEL !!!!
    253287  ! rest of the grid
    254288  do j=2,jjm
     
    260294  enddo
    261295enddo ! of do l=1,nsoilmx
    262 
    263 ! Write data2 to file
    264 ierr=NF_ENDDEF(nid) ! switch out of NetCDF define mode
    265 ! Write
    266 #ifdef NC_DOUBLE
    267 ierr=NF_PUT_VAR_DOUBLE(nid,varid,data3)
    268 #else
    269 ierr=NF_PUT_VAR_REAL(nid,varid,data3)
    270 #endif
    271 if (ierr.ne.NF_NOERR) then
     296#endif
     297
     298! Write data3 to file
     299if (is_master) then
     300 ierr=NF_ENDDEF(nid) ! switch out of NetCDF define mode
     301 ! Write
     302#ifdef NC_DOUBLE
     303 ierr=NF_PUT_VAR_DOUBLE(nid,varid,data3)
     304#else
     305 ierr=NF_PUT_VAR_REAL(nid,varid,data3)
     306#endif
     307 if (ierr.ne.NF_NOERR) then
    272308  write(*,*)"iniwritesoil: Error, could not write th_inertia variable"
    273 endif
     309 endif
     310endif ! of if (is_master)
    274311
    275312end subroutine iniwritesoil
  • trunk/LMDZ.GENERIC/libf/phystd/mkstat.F90

    r135 r965  
    99!  Yann W. july 2003
    1010
     11#ifdef CPP_PARA
     12use mod_phys_lmdz_para, only : is_master
     13#endif
    1114
    1215implicit none
     
    3235integer :: meanid,sdid
    3336!integer, dimension(4) :: dimout
     37#ifndef CPP_PARA
     38logical,parameter :: is_master=.true.
     39#endif
    3440
    3541! Incrementation of count for the last step, which is not done in wstats
    3642count(istime)=count(istime)+1
     43
     44if (is_master) then
     45! only the master needs do this
    3746
    3847ierr = NF_OPEN("stats.nc",NF_WRITE,nid)
     
    161170ierr= NF_CLOSE(nid)
    162171
     172endif ! of if (is_master)
     173
    163174end
  • trunk/LMDZ.GENERIC/libf/phystd/physiq.F90

    r961 r965  
    16861686        call writediagfi(ngrid,"p","Pressure","Pa",3,pplay)
    16871687
     1688!     Subsurface temperatures
     1689        call writediagsoil(ngrid,"tsurf","Surface temperature","K",2,tsurf)
     1690        call writediagsoil(ngrid,"temp","temperature","K",3,tsoil)
     1691
    16881692!     Total energy balance diagnostics
    16891693        if(callrad.and.(.not.newtonian))then
  • trunk/LMDZ.GENERIC/libf/phystd/writediagfi.F

    r862 r965  
    4141
    4242      USE surfdat_h
    43  
     43#ifdef CPP_PARA
     44      USE mod_phys_lmdz_para, only : is_parallel, is_mpi_root,
     45     &                               is_master, gather
     46      USE mod_grid_phy_lmdz, only : klon_glo, Grid1Dto2D_glo
     47#endif
    4448      implicit none
    4549
     
    7074      real*4,save :: date
    7175
    72       REAL phis(ip1jmp1)
     76      REAL phis(ip1jmp1) ! surface geopotential on extended lonxlat grid
    7377
    7478      integer irythme
     
    99103      integer dimvert
    100104
     105#ifdef CPP_PARA
     106! Added to work in parallel mode
     107      real dx3_glop(klon_glo,llm)
     108      real dx3_glo(iim,jjp1,llm) ! to store a global 3D data set
     109      real dx2_glop(klon_glo)
     110      real dx2_glo(iim,jjp1)     ! to store a global 2D (surface) data set
     111      real px2(ngrid)
     112!      real dx1_glo(llm)          ! to store a 1D (column) data set
     113!      real dx0_glo
     114      real phisfi_glo(klon_glo) ! surface geopotential on global physics grid
     115#else
     116      logical,parameter :: is_parallel=.false.
     117      logical,parameter :: is_master=.true.
     118      logical,parameter :: is_mpi_root=.true.
     119      real phisfi_glo(ngrid) ! surface geopotential on global physics grid
     120#endif
    101121!***************************************************************
    102122!Sortie des variables au rythme voulu
     
    170190
    171191#ifdef CPP_PARA
     192          ! Gather phisfi() geopotential on physics grid
     193          call Gather(phisfi,phisfi_glo)
     194#else
     195         phisfi_glo(:)=phisfi(:)
     196#endif
     197
    172198         !! parallel: we cannot use the usual writediagfi method
    173          call iophys_ini
    174 #else
     199!!         call iophys_ini
     200         if (is_master) then
     201         ! only the master is required to do this
     202
    175203         ! Create the NetCDF file
    176204         ierr = NF_CREATE(fichnom, NF_CLOBBER, nid)
     
    193221
    194222         ! write "header" of file (longitudes, latitudes, geopotential, ...)
    195          call gr_fi_dyn(1,ngrid,iip1,jjp1,phisfi,phis)
     223         call gr_fi_dyn(1,size(phisfi_glo),iip1,jjp1,phisfi_glo,phis)
    196224         call iniwrite(nid,day_ini,phis)
    197225
     226         endif ! of if (is_master)
     227
    198228      else
    199          ! Open the NetCDF file
    200          ierr = NF_OPEN(fichnom,NF_WRITE,nid)
    201 #endif
     229
     230         if (is_master) then
     231           ! only the master is required to do this
     232
     233           ! Open the NetCDF file
     234           ierr = NF_OPEN(fichnom,NF_WRITE,nid)
     235         endif ! of if (is_master)
     236
    202237      endif ! if (firstnom.eq.'1234567890')
    203238
     
    223258      if ( MOD(zitau+1,irythme) .eq.0.) then
    224259
    225 #ifdef CPP_PARA
    226          !! parallel: we cannot use the usual writediagfi method
    227          if (dim .eq. 2) then
    228              dimvert = 1
    229          else if (dim == 3) then
    230              dimvert = llm
    231          endif
    232          call iophys_ecrit(nom,dimvert,titre,unite,px)
    233 #else
     260!#ifdef CPP_PARA
     261!         !! parallel: we cannot use the usual writediagfi method
     262!         if (dim .eq. 2) then
     263!             dimvert = 1
     264!         else if (dim == 3) then
     265!             dimvert = llm
     266!         endif
     267!         call iophys_ecrit(nom,dimvert,titre,unite,px)
     268!#else
    234269
    235270! Compute/write/extend 'Time' coordinate (date given in days)
     
    238273!--------------------------------------------------------
    239274
     275        if (is_master) then
     276           ! only the master is required to do this
    240277        if (nom.eq.firstnom) then
    241278        ! We have identified a "first call" (at given date)
     
    261298        end if ! of if (nom.eq.firstnom)
    262299
     300        endif ! of if (is_master)
     301
    263302!Case of a 3D variable
    264303!---------------------
    265304        if (dim.eq.3) then
    266305
     306#ifdef CPP_PARA
     307          ! Gather field on a "global" (without redundant longitude) array
     308          call Gather(px,dx3_glop)
     309!$OMP MASTER
     310          if (is_mpi_root) then
     311            call Grid1Dto2D_glo(dx3_glop,dx3_glo)
     312            ! copy dx3_glo() to dx3(:) and add redundant longitude
     313            dx3(1:iim,:,:)=dx3_glo(1:iim,:,:)
     314            dx3(iip1,:,:)=dx3(1,:,:)
     315          endif
     316!$OMP END MASTER
     317!$OMP BARRIER
     318#else
    267319!         Passage variable physique -->  variable dynamique
    268320!         recast (copy) variable from physics grid to dynamics grid
     
    280332             ENDDO
    281333           ENDDO
    282 
     334#endif
    283335!         Ecriture du champs
    284336
    285 !         write (*,*) 'In  writediagfi, on sauve:  ' , nom
    286 !         write (*,*) 'In  writediagfi. Estimated date = ' ,date
     337          if (is_master) then
     338           ! only the master writes to output
    287339! name of the variable
    288340           ierr= NF_INQ_VARID(nid,nom,varid)
     
    314366!           ierr= NF_PUT_VARA_DOUBLE(nid,varid,corner,edges,dx3)
    315367!#else
     368!           write(*,*)"test:  nid=",nid," varid=",varid
     369!           write(*,*)"       corner()=",corner
     370!           write(*,*)"       edges()=",edges
     371!           write(*,*)"       dx3()=",dx3
    316372           ierr= NF_PUT_VARA_REAL(nid,varid,corner,edges,dx3)
    317373!#endif
     
    320376              write(*,*) "***** PUT_VAR problem in writediagfi"
    321377              write(*,*) "***** with ",nom
    322               write(*,*) 'ierr=', ierr
     378              write(*,*) 'ierr=', ierr,": ",NF_STRERROR(ierr)
    323379c             call abort
    324380           endif
    325381
     382          endif !of if (is_master)
     383
    326384!Case of a 2D variable
    327385!---------------------
    328386
    329387        else if (dim.eq.2) then
     388
     389#ifdef CPP_PARA
     390          ! Gather field on a "global" (without redundant longitude) array
     391          px2(:)=px(:,1)
     392          call Gather(px2,dx2_glop)
     393!$OMP MASTER
     394          if (is_mpi_root) then
     395            call Grid1Dto2D_glo(dx2_glop,dx2_glo)
     396            ! copy dx2_glo() to dx2(:) and add redundant longitude
     397            dx2(1:iim,:)=dx2_glo(1:iim,:)
     398            dx2(iip1,:)=dx2(1,:)
     399          endif
     400!$OMP END MASTER
     401!$OMP BARRIER
     402#else
    330403
    331404!         Passage variable physique -->  physique dynamique
     
    343416                dx2(iip1,j)=dx2(1,j)
    344417             ENDDO
    345 
     418#endif
     419
     420          if (is_master) then
     421           ! only the master writes to output
    346422!         write (*,*) 'In  writediagfi, on sauve:  ' , nom
    347423!         write (*,*) 'In  writediagfi. Estimated date = ' ,date
     
    379455              write(*,*) "***** PUT_VAR matter in writediagfi"
    380456              write(*,*) "***** with ",nom
    381               write(*,*) 'ierr=', ierr
     457              write(*,*) 'ierr=', ierr,": ",NF_STRERROR(ierr)
    382458c             call abort
    383459           endif
    384460
     461          endif !of if (is_master)
     462
    385463!Case of a 1D variable (ie: a column)
    386464!---------------------------------------------------
    387465
    388466       else if (dim.eq.1) then
     467         if (is_parallel) then
     468           write(*,*) "writediagfi error: dim=1 not implemented ",
     469     &                 "in parallel mode"
     470           stop
     471         endif
    389472!         Passage variable physique -->  physique dynamique
    390473!         recast (copy) variable from physics grid to dynamics grid
     
    430513
    431514        else if (dim.eq.0) then
     515         if (is_parallel) then
     516           write(*,*) "writediagfi error: dim=0 not implemented ",
     517     &                 "in parallel mode"
     518           stop
     519         endif
     520
    432521           dx0 = px (1,1)
    433522
     
    462551
    463552        endif ! of if (dim.eq.3) elseif(dim.eq.2)...
    464 #endif
    465553
    466554      endif ! of if ( MOD(zitau+1,irythme) .eq.0.)
    467555
    468 #ifndef CPP_PARA
    469       ierr= NF_CLOSE(nid)
    470 #endif
     556      if (is_master) then
     557        ierr= NF_CLOSE(nid)
     558      endif
    471559
    472560      end
     561
  • trunk/LMDZ.GENERIC/libf/phystd/writediagsoil.F90

    r787 r965  
    1010! (yielding the sought time series of the variable)
    1111
    12 use comsoil_h
     12#ifdef CPP_PARA
     13use mod_phys_lmdz_para, only : is_mpi_root, is_master, gather
     14use mod_grid_phy_lmdz, only : klon_glo, Grid1Dto2D_glo
     15#endif
    1316
    1417implicit none
     
    3134
    3235! Local variables:
    33 real,dimension(iip1,jjp1,nsoilmx) :: data3 ! to store 3D data
     36real,dimension(iip1,jjp1,nsoilmx) :: data3 ! to store 3D data on extended lonxlat grid
    3437! Note iip1,jjp1 known from paramet.h; nsoilmx known from dimphys.h
    35 real,dimension(iip1,jjp1) :: data2 ! to store 2D data
     38real,dimension(iip1,jjp1) :: data2 ! to store 2D data on extended lonxlat grid
    3639real :: data0 ! to store 0D data
    3740integer :: i,j,l ! for loops
     
    5356integer,dimension(4) :: edges,corners
    5457
     58#ifdef CPP_PARA
     59! Added to work in parallel mode
     60real dx3_glop(klon_glo,nsoilmx)
     61real dx3_glo(iim,jjp1,nsoilmx) ! to store a global 3D data set
     62real dx2_glop(klon_glo)
     63real dx2_glo(iim,jjp1)     ! to store a global 2D (surface) data set
     64real px2(ngrid)
     65#else
     66logical,parameter :: is_master=.true.
     67logical,parameter :: is_mpi_root=.true.
     68#endif
     69
    5570! 1. Initialization step
    5671if (firstname.eq."1234567890") then
     
    7287 
    7388  ! Create output NetCDF file
    74   ierr=NF_CREATE(filename,NF_CLOBBER,nid)
    75   if (ierr.ne.NF_NOERR) then
     89  if (is_master) then
     90   ierr=NF_CREATE(filename,NF_CLOBBER,nid)
     91   if (ierr.ne.NF_NOERR) then
    7692    write(*,*)'writediagsoil: Error, failed creating file '//trim(filename)
    7793    stop
    78   endif
    79  
     94   endif
     95  endif ! of if (is_master)
     96
    8097  ! Define dimensions and axis attributes
    8198  call iniwritesoil(nid,ngrid)
     
    86103else
    87104  ! If not an initialization call, simply open the NetCDF file
    88   ierr=NF_OPEN(filename,NF_WRITE,nid)
     105  if (is_master) then
     106   ierr=NF_OPEN(filename,NF_WRITE,nid)
     107  endif
    89108endif ! of if (firstname.eq."1234567890")
    90109
     
    105124    ! Note: day_step is known from control.h
    106125   
    107     ! Get NetCDF ID for "time"
    108     ierr=NF_INQ_VARID(nid,"time",varid)
    109     ! Add the current value of date to the "time" array
     126    if (is_master) then
     127     ! Get NetCDF ID for "time"
     128     ierr=NF_INQ_VARID(nid,"time",varid)
     129     ! Add the current value of date to the "time" array
    110130#ifdef NC_DOUBLE
    111     ierr=NF_PUT_VARA_DOUBLE(nid,varid,ntime,1,date)
    112 #else
    113     ierr=NF_PUT_VARA_REAL(nid,varid,ntime,1,date)
    114 #endif
    115     if (ierr.ne.NF_NOERR) then
     131     ierr=NF_PUT_VARA_DOUBLE(nid,varid,ntime,1,date)
     132#else
     133     ierr=NF_PUT_VARA_REAL(nid,varid,ntime,1,date)
     134#endif
     135     if (ierr.ne.NF_NOERR) then
    116136      write(*,*)"writediagsoil: Failed writing date to time variable"
    117137      stop
    118     endif
     138     endif
     139    endif ! of if (is_master)
    119140  endif ! of if (name.eq.firstname)
    120141
     
    122143if (dimpx.eq.3) then ! Case of a 3D variable
    123144  ! A. Recast data along 'dynamics' grid
     145#ifdef CPP_PARA
     146  ! gather field on a "global" (without redundant longitude) array
     147  call Gather(px,dx3_glop)
     148!$OMP MASTER
     149  if (is_mpi_root) then
     150    call Grid1Dto2D_glo(dx3_glop,dx3_glo)
     151    ! copy dx3_glo() to dx3(:) and add redundant longitude
     152    data3(1:iim,:,:)=dx3_glo(1:iim,:,:)
     153    data3(iip1,:,:)=data3(1,:,:)
     154  endif
     155!$OMP END MASTER
     156!$OMP BARRIER
     157#else
    124158  do l=1,nsoilmx
    125159    ! handle the poles
     
    137171    enddo
    138172  enddo
     173#endif
    139174 
    140175  ! B. Write (append) the variable to the NetCDF file
     176  if (is_master) then
    141177  ! B.1. Get the ID of the variable
    142178  ierr=NF_INQ_VARID(nid,name,varid)
     
    176212               " to file "//trim(filename)//" at time",date
    177213  endif
     214  endif ! of if (is_master)
    178215
    179216elseif (dimpx.eq.2) then ! Case of a 2D variable
     217
    180218  ! A. Recast data along 'dynamics' grid
     219#ifdef CPP_PARA
     220  ! gather field on a "global" (without redundant longitude) array
     221  px2(:)=px(:,1)
     222  call Gather(px2,dx2_glop)
     223!$OMP MASTER
     224  if (is_mpi_root) then
     225    call Grid1Dto2D_glo(dx2_glop,dx2_glo)
     226    ! copy dx3_glo() to dx3(:) and add redundant longitude
     227    data2(1:iim,:)=dx2_glo(1:iim,:)
     228    data2(iip1,:)=data2(1,:)
     229  endif
     230!$OMP END MASTER
     231!$OMP BARRIER
     232#else
    181233  ! handle the poles
    182234  do i=1,iip1
     
    192244    data2(iip1,j)=data2(1,j) ! extra (modulo) longitude
    193245  enddo
     246#endif
    194247
    195248  ! B. Write (append) the variable to the NetCDF file
     249  if (is_master) then
    196250  ! B.1. Get the ID of the variable
    197251  ierr=NF_INQ_VARID(nid,name,varid)
     
    228282               " to file "//trim(filename)//" at time",date
    229283  endif
     284  endif ! of if (is_master)
    230285
    231286elseif (dimpx.eq.0) then ! Case of a 0D variable
     287#ifdef CPP_PARA
     288  write(*,*) "writediagsoil: dimps==0 case not implemented in // mode!!"
     289  stop
     290#endif
    232291  ! A. Copy data value
    233292  data0=px(1,1)
     
    267326
    268327! 4. Close the NetCDF file
    269 ierr=NF_CLOSE(nid)
     328if (is_master) then
     329  ierr=NF_CLOSE(nid)
     330endif
    270331
    271332end subroutine writediagsoil
  • trunk/LMDZ.GENERIC/libf/phystd/writediagspecIR.F

    r787 r965  
    1       subroutine writediagspecIR(ngrid,nom,titre,unite,dim,px)
     1      subroutine writediagspecIR(ngrid,nom,titre,unite,dimpx,px)
    22
    33!  Ecriture de variables diagnostiques au choix dans la physique
     
    3232!      unite : unite de la variable (chaine de caracteres)
    3333!      px : variable a sortir (real 0, 2, ou 3d)
    34 !      dim : dimension de px : 0, 2, ou 3 dimensions
     34!      dimpx : dimension de px : 0, 2, ou 3 dimensions
    3535!
    3636!=================================================================
     
    4343! Addition by RW (2010) to allow OLR to be saved in .nc format
    4444      use radinc_h, only : L_NSPECTI
    45       USE surfdat_h
     45!      USE surfdat_h, only : phisfi
     46#ifdef CPP_PARA
     47      use mod_phys_lmdz_para, only : is_mpi_root, is_master, gather
     48      use mod_grid_phy_lmdz, only : klon_glo, Grid1Dto2D_glo
     49#endif
    4650
    4751      implicit none
     
    6064
    6165! Arguments on input:
    62       integer ngrid
    63       character (len=*) :: nom,titre,unite
    64       integer dim
    65       real px(ngrid,L_NSPECTI)
     66      integer,intent(in) :: ngrid
     67      character (len=*),intent(in) :: nom,titre,unite
     68      integer,intent(in) :: dimpx
     69      real,intent(in) :: px(ngrid,L_NSPECTI)
    6670
    6771! Local variables:
     
    7377      real date
    7478
    75       REAL phis(ip1jmp1)
     79!      REAL phis(ip1jmp1)
    7680
    7781      integer irythme
     
    99103       real dx3(iip1,jjp1,L_NSPECTI) ! to store the data set
    100104
     105#ifdef CPP_PARA
     106! Added to work in parallel mode
     107      real dx3_glop(klon_glo,L_NSPECTI)
     108      real dx3_glo(iim,jjp1,L_NSPECTI) ! to store a global 3D data set
     109#else
     110      logical,parameter :: is_master=.true.
     111      logical,parameter :: is_mpi_root=.true.
     112#endif
    101113
    102114!***************************************************************
     
    109121
    110122!***************************************************************
    111 
    112 ! The following test is here to enforce that writediagfi is not used with the
    113 ! 1D version of the GCM
    114 !not anymore (JL12)
    115       if (ngrid.eq.-1) return
    116      
    117 c     nom=trim((nom))
    118 c     unite=trim((unite))
    119 c     titre=trim((titre))
    120123
    121124! Initialisation of 'firstnom' and create/open the "diagfi.nc" NetCDF file
     
    130133         ! just to be sure, check that firstnom is large enough to hold nom
    131134         if (len_trim(firstnom).lt.len_trim(nom)) then
    132            write(*,*) "writediagfi: Error !!!"
     135           write(*,*) "writediagspecIR: Error !!!"
    133136           write(*,*) "   firstnom string not long enough!!"
    134137           write(*,*) "   increase its size to at least ",len_trim(nom)
     
    137140
    138141         ! Create the NetCDF file
     142         if (is_master) then
    139143         ierr = NF_CREATE(fichnom, NF_CLOBBER, nid)
    140144         ! Define the 'Time' dimension
     
    155159         ierr = NF_ENDDEF(nid)
    156160
    157          ! write "header" of file (longitudes, latitudes, geopotential, ...)
    158          call gr_fi_dyn(1,ngrid,iip1,jjp1,phisfi,phis)
    159 !         call iniwrite(nid,day_ini,phis)
    160          call iniwrite_specIR(nid,day_ini,phis)
     161!         call gr_fi_dyn(1,size(phisfi_glo),iip1,jjp1,phisfi_glo,phis)
     162         ! write "header" of file (longitudes, latitudes, area, ...)
     163         call iniwrite_specIR(nid,day_ini)
     164         endif ! of if (is_master)
    161165
    162166         zitau = -1 ! initialize zitau
    163167      else
    164          ! Open the NetCDF file
    165          ierr = NF_OPEN(fichnom,NF_WRITE,nid)
     168         if (is_master) then
     169           ! Open the NetCDF file
     170           ierr = NF_OPEN(fichnom,NF_WRITE,nid)
     171         endif
    166172      endif ! if (firstnom.eq.'1234567890')
    167173
     
    191197           ! compute corresponding date (in days and fractions thereof)
    192198           date= float (zitau +1)/float (day_step)
    193            ! Get NetCDF ID of 'Time' variable
    194            ierr= NF_INQ_VARID(nid,"Time",varid)
    195 
    196            !print*,'in writediagfi_spec.F, time=',varid
    197 
    198            ! Write (append) the new date to the 'Time' array
     199
     200           if (is_master) then
     201             ! Get NetCDF ID of 'Time' variable
     202             ierr= NF_INQ_VARID(nid,"Time",varid)
     203
     204             ! Write (append) the new date to the 'Time' array
    199205#ifdef NC_DOUBLE
    200            ierr= NF_PUT_VARA_DOUBLE(nid,varid,ntime,1,date)
    201 #else
    202            ierr= NF_PUT_VARA_REAL(nid,varid,ntime,1,date)
    203 #endif
    204            if (ierr.ne.NF_NOERR) then
     206             ierr= NF_PUT_VARA_DOUBLE(nid,varid,ntime,1,date)
     207#else
     208             ierr= NF_PUT_VARA_REAL(nid,varid,ntime,1,date)
     209#endif
     210             if (ierr.ne.NF_NOERR) then
    205211              write(*,*) "***** PUT_VAR matter in writediagspec_nc"
    206212              write(*,*) "***** with time"
    207213              write(*,*) 'ierr=', ierr   
    208214c             call abort
    209            endif
    210 
    211            write(6,*)'WRITEDIAGSPEC: date= ', date
     215             endif
     216
     217             write(6,*)'WRITEDIAGSPEC: date= ', date
     218           endif ! of if (is_master)
    212219        end if ! of if (nom.eq.firstnom)
    213220
     
    216223!Case of a 3D variable
    217224!---------------------
    218         if (dim.eq.3) then
    219 
    220 !         recast (copy) variable from physics grid to dynamics grid
     225        if (dimpx.eq.3) then
     226
     227!         A. Recast (copy) variable from physics grid to dynamics grid
     228#ifdef CPP_PARA
     229  ! gather field on a "global" (without redundant longitude) array
     230          call Gather(px,dx3_glop)
     231!$OMP MASTER
     232          if (is_mpi_root) then
     233            call Grid1Dto2D_glo(dx3_glop,dx3_glo)
     234            ! copy dx3_glo() to dx3(:) and add redundant longitude
     235            dx3(1:iim,:,:)=dx3_glo(1:iim,:,:)
     236            dx3(iip1,:,:)=dx3(1,:,:)
     237          endif
     238!$OMP END MASTER
     239!$OMP BARRIER
     240#else
    221241           DO l=1,L_NSPECTI
    222242             DO i=1,iip1
     
    232252             ENDDO
    233253           ENDDO
     254#endif
     255
     256!         B. Write (append) the variable to the NetCDF file
     257          if (is_master) then
    234258
    235259! name of the variable
     
    245269
    246270              write (*,*) "=========================="
    247               write (*,*) "DIAGSPEC: creating variable ",nom
     271              write (*,*) "DIAGSPECIR: creating variable ",nom
    248272              call def_var(nid,nom,titre,unite,4,id,varid,ierr)
    249273
     
    272296           endif
    273297
    274         endif ! of if (dim.eq.3) elseif(dim.eq.2)...
     298          endif ! of if (is_master)
     299
     300        endif ! of if (dimpx.eq.3)
    275301
    276302      endif ! of if ( MOD(zitau+1,irythme) .eq.0.)
    277303
    278       ierr= NF_CLOSE(nid)
     304      ! Close the NetCDF file
     305      if (is_master) then
     306        ierr= NF_CLOSE(nid)
     307      endif
    279308
    280309      end
  • trunk/LMDZ.GENERIC/libf/phystd/writediagspecVI.F

    r787 r965  
    1       subroutine writediagspecVI(ngrid,nom,titre,unite,dim,px)
     1      subroutine writediagspecVI(ngrid,nom,titre,unite,dimpx,px)
    22
    33!  Ecriture de variables diagnostiques au choix dans la physique
     
    3232!      unite : unite de la variable (chaine de caracteres)
    3333!      px : variable a sortir (real 0, 2, ou 3d)
    34 !      dim : dimension de px : 0, 2, ou 3 dimensions
     34!      dimpx : dimension de px : 0, 2, ou 3 dimensions
    3535!
    3636!=================================================================
     
    4343! Addition by RW (2010) to allow OSR to be saved in .nc format
    4444      use radinc_h, only : L_NSPECTV
    45       USE surfdat_h
     45!      USE surfdat_h
     46#ifdef CPP_PARA
     47      use mod_phys_lmdz_para, only : is_mpi_root, is_master, gather
     48      use mod_grid_phy_lmdz, only : klon_glo, Grid1Dto2D_glo
     49#endif
    4650
    4751      implicit none
     
    6266      integer ngrid
    6367      character (len=*) :: nom,titre,unite
    64       integer dim
     68      integer dimpx
    6569      real px(ngrid,L_NSPECTV)
    6670
     
    7377      real date
    7478
    75       REAL phis(ip1jmp1)
     79!      REAL phis(ip1jmp1)
    7680
    7781      integer irythme
     
    99103       real dx3(iip1,jjp1,L_NSPECTV) ! to store the data set
    100104
     105#ifdef CPP_PARA
     106! Added to work in parallel mode
     107      real dx3_glop(klon_glo,L_NSPECTV)
     108      real dx3_glo(iim,jjp1,L_NSPECTV) ! to store a global 3D data set
     109#else
     110      logical,parameter :: is_master=.true.
     111      logical,parameter :: is_mpi_root=.true.
     112#endif
    101113
    102114!***************************************************************
     
    108120
    109121!***************************************************************
    110 
    111 ! The following test is here to enforce that writediagfi is not used with the
    112 ! 1D version of the GCM
    113 !not anymore (JL12)
    114       if (ngrid.eq.-1) return
    115      
    116 c     nom=trim((nom))
    117 c     unite=trim((unite))
    118 c     titre=trim((titre))
    119122
    120123! Initialisation of 'firstnom' and create/open the "diagfi.nc" NetCDF file
     
    136139
    137140         ! Create the NetCDF file
     141         if (is_master) then
    138142         ierr = NF_CREATE(fichnom, NF_CLOBBER, nid)
    139143         ! Define the 'Time' dimension
     
    155159
    156160         ! write "header" of file (longitudes, latitudes, geopotential, ...)
    157          call gr_fi_dyn(1,ngrid,iip1,jjp1,phisfi,phis)
     161!         call gr_fi_dyn(1,ngrid,iip1,jjp1,phisfi,phis)
    158162!         call iniwrite(nid,day_ini,phis)
    159          call iniwrite_specVI(nid,day_ini,phis)
     163         call iniwrite_specVI(nid,day_ini)
     164         endif ! of if (is_master)
    160165
    161166         zitau = -1 ! initialize zitau
    162167      else
    163          ! Open the NetCDF file
    164          ierr = NF_OPEN(fichnom,NF_WRITE,nid)
     168         if (is_master) then
     169           ! Open the NetCDF file
     170           ierr = NF_OPEN(fichnom,NF_WRITE,nid)
     171         endif
    165172      endif ! if (firstnom.eq.'1234567890')
    166173
     
    190197           ! compute corresponding date (in days and fractions thereof)
    191198           date= float (zitau +1)/float (day_step)
    192            ! Get NetCDF ID of 'Time' variable
    193            ierr= NF_INQ_VARID(nid,"Time",varid)
    194 
    195            !print*,'in writediagfi_spec.F, time=',varid
    196 
    197            ! Write (append) the new date to the 'Time' array
     199
     200           if (is_master) then
     201             ! Get NetCDF ID of 'Time' variable
     202             ierr= NF_INQ_VARID(nid,"Time",varid)
     203
     204             ! Write (append) the new date to the 'Time' array
    198205#ifdef NC_DOUBLE
    199            ierr= NF_PUT_VARA_DOUBLE(nid,varid,ntime,1,date)
    200 #else
    201            ierr= NF_PUT_VARA_REAL(nid,varid,ntime,1,date)
    202 #endif
    203            if (ierr.ne.NF_NOERR) then
     206             ierr= NF_PUT_VARA_DOUBLE(nid,varid,ntime,1,date)
     207#else
     208             ierr= NF_PUT_VARA_REAL(nid,varid,ntime,1,date)
     209#endif
     210             if (ierr.ne.NF_NOERR) then
    204211              write(*,*) "***** PUT_VAR matter in writediagspec_nc"
    205212              write(*,*) "***** with time"
    206213              write(*,*) 'ierr=', ierr   
    207214c             call abort
    208            endif
    209 
    210            write(6,*)'WRITEDIAGSPEC: date= ', date
     215             endif
     216
     217             write(6,*)'WRITEDIAGSPEC: date= ', date
     218           endif ! of if (is_master)
    211219        end if ! of if (nom.eq.firstnom)
    212220
     
    215223!Case of a 3D variable
    216224!---------------------
    217         if (dim.eq.3) then
    218 
    219 !         recast (copy) variable from physics grid to dynamics grid
     225        if (dimpx.eq.3) then
     226
     227!         A. Recast (copy) variable from physics grid to dynamics grid
     228#ifdef CPP_PARA
     229  ! gather field on a "global" (without redundant longitude) array
     230          call Gather(px,dx3_glop)
     231!$OMP MASTER
     232          if (is_mpi_root) then
     233            call Grid1Dto2D_glo(dx3_glop,dx3_glo)
     234            ! copy dx3_glo() to dx3(:) and add redundant longitude
     235            dx3(1:iim,:,:)=dx3_glo(1:iim,:,:)
     236            dx3(iip1,:,:)=dx3(1,:,:)
     237          endif
     238!$OMP END MASTER
     239!$OMP BARRIER
     240#else
    220241           DO l=1,L_NSPECTV
    221242             DO i=1,iip1
     
    231252             ENDDO
    232253           ENDDO
     254#endif
     255
     256!         B. Write (append) the variable to the NetCDF file
     257          if (is_master) then
    233258
    234259! name of the variable
     
    271296           endif
    272297
    273         endif ! of if (dim.eq.3) elseif(dim.eq.2)...
     298          endif ! of if (is_master)
     299
     300        endif ! of if (dimpx.eq.3)
    274301
    275302      endif ! of if ( MOD(zitau+1,irythme) .eq.0.)
    276303
    277       ierr= NF_CLOSE(nid)
     304      ! Close the NetCDF file
     305      if (is_master) then
     306        ierr= NF_CLOSE(nid)
     307      endif
    278308
    279309      end
  • trunk/LMDZ.GENERIC/libf/phystd/wstats.F90

    r135 r965  
    11subroutine wstats(ngrid,nom,titre,unite,dim,px)
     2
     3#ifdef CPP_PARA
     4use mod_phys_lmdz_para, only : is_mpi_root, is_master, gather, klon_mpi_begin
     5use mod_grid_phy_lmdz, only : klon_glo, Grid1Dto2D_glo
     6#endif
    27
    38implicit none
     
    510#include "dimensions.h"
    611#include "dimphys.h"
     12#include "comconst.h"
    713#include "statto.h"
    814#include "netcdf.inc"
    915
    1016integer,intent(in) :: ngrid
    11 character (len=*) :: nom,titre,unite
     17character (len=*),intent(in) :: nom,titre,unite
    1218integer,intent(in) :: dim
    1319integer,parameter :: iip1=iim+1
    1420integer,parameter :: jjp1=jjm+1
    15 real, dimension(ngrid,llm) :: px
     21real,intent(in) :: px(ngrid,llm)
    1622real, dimension(iip1,jjp1,llm) :: mean3d,sd3d,dx3
    1723real, dimension(iip1,jjp1) :: mean2d,sd2d,dx2
     
    2026integer :: ierr,varid,nbdim,nid
    2127integer :: meanid,sdid
    22 integer, dimension(4)  :: id,start,size
     28integer, dimension(4)  :: id,start,sizes
    2329logical, save :: firstcall=.TRUE.
    2430integer :: l,i,j,ig0
    25 integer,save :: index
     31integer,save :: indx
    2632
    2733integer, save :: step=0
    2834
    29 
     35! Added to work in parallel mode
     36#ifdef CPP_PARA
     37real px3_glop(klon_glo,llm) ! to store a 3D data set on global physics grid
     38real px3_glo(iim,jjp1,llm) ! to store a global 3D data set on global lonxlat grid
     39real px2_glop(klon_glo) ! to store a 2D data set on global physics grid
     40real px2_glo(iim,jjp1) ! to store a 2D data set on global lonxlat grid
     41real px2(ngrid)
     42real px3(ngrid,llm)
     43#else
     44! When not running in parallel mode:
     45real px3_glop(ngrid,llm) ! to store a 3D data set on global physics grid
     46real px3_glo(iim,jjp1,llm) ! to store a global 3D data set on global lonxlat grid
     47real px2_glop(ngrid) ! to store a 2D data set on global physics grid
     48real px2_glo(iim,jjp1) ! to store a 2D data set on global lonxlat grid
     49logical,parameter :: is_master=.true.
     50logical,parameter :: is_mpi_root=.true.
     51integer,parameter :: klon_mpi_begin=1
     52#endif
     53
     54! 1. Initialization (creation of stats.nc file)
    3055if (firstcall) then
    3156   firstcall=.false.
     
    3459endif
    3560
    36 if (firstvar==nom) then ! If we're back to the first variable
     61if (firstvar==nom) then ! If we're back to the first variable, increment time counter
    3762      step = step + 1
    3863endif
    3964
    4065if (mod(step,istats).ne.0) then
     66  ! if its not time to write to file, exit
    4167   RETURN
    4268endif
    4369
     70! collect fields on a global physics grid
     71#ifdef CPP_PARA
     72 if (dim.eq.3) then
     73  px3(1:ngrid,1:llm)=px(1:ngrid,1:llm)
     74  ! Gather fieds on a "global" (without redundant longitude) array
     75  call Gather(px3,px3_glop)
     76!$OMP MASTER
     77  if (is_mpi_root) then
     78    call Grid1Dto2D_glo(px3_glop,px3_glo)
     79    ! copy dx3_glo() to dx3(:) and add redundant longitude
     80    dx3(1:iim,:,:)=px3_glo(1:iim,:,:)
     81    dx3(iip1,:,:)=dx3(1,:,:)
     82  endif
     83!$OMP END MASTER
     84!$OMP BARRIER
     85 else ! dim.eq.2
     86  ! Gather fieds on a "global" (without redundant longitude) array
     87  px2(:)=px(:,1)
     88  call Gather(px2,px2_glop)
     89!$OMP MASTER
     90          if (is_mpi_root) then
     91            call Grid1Dto2D_glo(px2_glop,px2_glo)
     92            ! copy px2_glo() to dx2(:) and add redundant longitude
     93            dx2(1:iim,:)=px2_glo(1:iim,:)
     94            dx2(iip1,:)=dx2(1,:)
     95          endif
     96!$OMP END MASTER
     97!$OMP BARRIER
     98 endif
     99#else
     100  if (dim.eq.3) then
     101    px3_glop(:,1:llm)=px(:,1:llm)
     102!  Passage variable physique -->  variable dynamique
     103    DO l=1,llm
     104      DO i=1,iim
     105         px3_glo(i,1,l)=px(1,l)
     106         px3_glo(i,jjp1,l)=px(ngrid,l)
     107      ENDDO
     108      DO j=2,jjm
     109         ig0= 1+(j-2)*iim
     110         DO i=1,iim
     111            px3_glo(i,j,l)=px(ig0+i,l)
     112         ENDDO
     113      ENDDO
     114    ENDDO
     115  else ! dim.eq.2
     116    px2_glop(:)=px(:,1)
     117!    Passage variable physique -->  physique dynamique
     118   DO i=1,iim
     119     px2_glo(i,1)=px(1,1)
     120     px2_glo(i,jjp1)=px(ngrid,1)
     121   ENDDO
     122   DO j=2,jjm
     123     ig0= 1+(j-2)*iim
     124     DO i=1,iim
     125        px2_glo(i,j)=px(ig0+i,1)
     126     ENDDO
     127   ENDDO
     128  endif
     129#endif
     130
     131! 2. Write field to file
     132
     133if (is_master) then
     134! only master needs do this
     135
    44136ierr = NF_OPEN("stats.nc",NF_WRITE,nid)
    45137
    46138namebis=trim(nom)
     139
     140! test: check if that variable already exists in file
    47141ierr= NF_INQ_VARID(nid,namebis,meanid)
    48142
    49143if (ierr.ne.NF_NOERR) then
    50 
     144  ! variable not in file, create/define it
    51145   if (firstvar==nom) then
    52       index=1
    53       count=0
     146      indx=1
     147      count(:)=0
    54148   endif
    55149
     
    73167   namebis=trim(nom)
    74168   call def_var(nid,namebis,titre,unite,nbdim,id,meanid,ierr)
    75    call inivar(nid,meanid,ngrid,dim,index,px,ierr)
     169   if (dim.eq.3) then
     170     call inivar(nid,meanid,size(px3_glop,1),dim,indx,px3_glop,ierr)
     171   else ! dim.eq.2
     172     call inivar(nid,meanid,size(px2_glop,1),dim,indx,px2_glop,ierr)
     173   endif
    76174   namebis=trim(nom)//"_sd"
    77175   call def_var(nid,namebis,trim(titre)//" total standard deviation over the season",unite,nbdim,id,sdid,ierr)
    78    call inivar(nid,sdid,ngrid,dim,index,px,ierr)
     176   if (dim.eq.3) then
     177     call inivar(nid,sdid,size(px3_glop,1),dim,indx,px3_glop,ierr)
     178   else ! dim.eq.2
     179     call inivar(nid,sdid,size(px2_glop,1),dim,indx,px2_glop,ierr)
     180   endif
    79181
    80182   ierr= NF_CLOSE(nid)
     
    82184
    83185else
     186   ! variable found in file
    84187   namebis=trim(nom)//"_sd"
    85188   ierr= NF_INQ_VARID(nid,namebis,sdid)
     
    88191
    89192if (firstvar==nom) then
    90    count(index)=count(int(index))+1
    91    index=index+1
    92    if (index>istime) then
    93       index=1
    94    endif
    95 endif
    96 
    97 if (count(index)==0) then
    98    if (dim.eq.3) then
    99       start=(/1,1,1,index/)
    100       size=(/iip1,jjp1,llm,1/)
    101       mean3d=0
    102       sd3d=0
     193   count(indx)=count(int(indx))+1
     194   indx=indx+1
     195   if (indx>istime) then
     196      indx=1
     197   endif
     198endif
     199
     200if (count(indx)==0) then
     201   ! very first time we write the variable to file
     202   if (dim.eq.3) then
     203      start=(/1,1,1,indx/)
     204      sizes=(/iip1,jjp1,llm,1/)
     205      mean3d(:,:,:)=0
     206      sd3d(:,:,:)=0
    103207   else if (dim.eq.2) then
    104       start=(/1,1,index,0/)
    105       size=(/iip1,jjp1,1,0/)
    106       mean2d=0
    107       sd2d=0
     208      start=(/1,1,indx,0/)
     209      sizes=(/iip1,jjp1,1,0/)
     210      mean2d(:,:)=0
     211      sd2d(:,:)=0
    108212   endif
    109213else
    110    if (dim.eq.3) then
    111       start=(/1,1,1,index/)
    112       size=(/iip1,jjp1,llm,1/)
    113 #ifdef NC_DOUBLE
    114       ierr = NF_GET_VARA_DOUBLE(nid,meanid,start,size,mean3d)
    115       ierr = NF_GET_VARA_DOUBLE(nid,sdid,start,size,sd3d)
    116 #else
    117       ierr = NF_GET_VARA_REAL(nid,meanid,start,size,mean3d)
    118       ierr = NF_GET_VARA_REAL(nid,sdid,start,size,sd3d)
     214   ! load values from file
     215   if (dim.eq.3) then
     216      start=(/1,1,1,indx/)
     217      sizes=(/iip1,jjp1,llm,1/)
     218#ifdef NC_DOUBLE
     219      ierr = NF_GET_VARA_DOUBLE(nid,meanid,start,sizes,mean3d)
     220      ierr = NF_GET_VARA_DOUBLE(nid,sdid,start,sizes,sd3d)
     221#else
     222      ierr = NF_GET_VARA_REAL(nid,meanid,start,sizes,mean3d)
     223      ierr = NF_GET_VARA_REAL(nid,sdid,start,sizes,sd3d)
    119224#endif
    120225      if (ierr.ne.NF_NOERR) then
     
    124229
    125230   else if (dim.eq.2) then
    126       start=(/1,1,index,0/)
    127       size=(/iip1,jjp1,1,0/)
    128 #ifdef NC_DOUBLE
    129       ierr = NF_GET_VARA_DOUBLE(nid,meanid,start,size,mean2d)
    130       ierr = NF_GET_VARA_DOUBLE(nid,sdid,start,size,sd2d)
    131 #else
    132       ierr = NF_GET_VARA_REAL(nid,meanid,start,size,mean2d)
    133       ierr = NF_GET_VARA_REAL(nid,sdid,start,size,sd2d)
     231      start=(/1,1,indx,0/)
     232      sizes=(/iip1,jjp1,1,0/)
     233#ifdef NC_DOUBLE
     234      ierr = NF_GET_VARA_DOUBLE(nid,meanid,start,sizes,mean2d)
     235      ierr = NF_GET_VARA_DOUBLE(nid,sdid,start,sizes,sd2d)
     236#else
     237      ierr = NF_GET_VARA_REAL(nid,meanid,start,sizes,mean2d)
     238      ierr = NF_GET_VARA_REAL(nid,sdid,start,sizes,sd2d)
    134239#endif
    135240      if (ierr.ne.NF_NOERR) then
     
    138243      endif
    139244   endif
    140 endif
     245endif ! of if (count(indx)==0)
     246
     247
     248! 2.1. Build dx* (data on lon-lat grid, with redundant longitude)
    141249
    142250if (dim.eq.3) then
     251  dx3(1:iim,:,:)=px3_glo(:,:,:)
     252  dx3(iip1,:,:)=dx3(1,:,:)
     253else ! dim.eq.2
     254  dx2(1:iim,:)=px2_glo(:,:)
     255  dx2(iip1,:)=dx2(1,:)
     256endif
     257
     258
     259! 2.2. Add current values to previously stored sums
     260
     261if (dim.eq.3) then
     262
     263   mean3d(:,:,:)=mean3d(:,:,:)+dx3(:,:,:)
     264   sd3d(:,:,:)=sd3d(:,:,:)+dx3(:,:,:)**2
     265
     266#ifdef NC_DOUBLE
     267   ierr = NF_PUT_VARA_DOUBLE(nid,meanid,start,sizes,mean3d)
     268   ierr = NF_PUT_VARA_DOUBLE(nid,sdid,start,sizes,sd3d)
     269#else
     270   ierr = NF_PUT_VARA_REAL(nid,meanid,start,sizes,mean3d)
     271   ierr = NF_PUT_VARA_REAL(nid,sdid,start,sizes,sd3d)
     272#endif
     273
     274else if (dim.eq.2) then
     275
     276   mean2d(:,:)= mean2d(:,:)+dx2(:,:)
     277   sd2d(:,:)=sd2d(:,:)+dx2(:,:)**2
     278
     279#ifdef NC_DOUBLE
     280   ierr = NF_PUT_VARA_DOUBLE(nid,meanid,start,sizes,mean2d)
     281   ierr = NF_PUT_VARA_DOUBLE(nid,sdid,start,sizes,sd2d)
     282#else
     283   ierr = NF_PUT_VARA_REAL(nid,meanid,start,sizes,mean2d)
     284   ierr = NF_PUT_VARA_REAL(nid,sdid,start,sizes,sd2d)
     285#endif
     286
     287endif ! of if (dim.eq.3) elseif (dim.eq.2)
     288
     289  ierr= NF_CLOSE(nid)
     290endif ! of if (is_master)
     291
     292end
     293
     294!======================================================
     295subroutine inivar(nid,varid,ngrid,dim,indx,px,ierr)
     296
     297implicit none
     298
     299include "dimensions.h"
     300include "dimphys.h"
     301include "netcdf.inc"
     302
     303integer, intent(in) :: nid,varid,dim,indx,ngrid
     304real, dimension(ngrid,llm), intent(in) :: px
     305integer, intent(out) :: ierr
     306
     307integer,parameter :: iip1=iim+1
     308integer,parameter :: jjp1=jjm+1
     309
     310integer :: l,i,j,ig0
     311integer, dimension(4) :: start,sizes
     312real, dimension(iip1,jjp1,llm) :: dx3
     313real, dimension(iip1,jjp1) :: dx2
     314
     315if (dim.eq.3) then
     316
     317   start=(/1,1,1,indx/)
     318   sizes=(/iip1,jjp1,llm,1/)
    143319
    144320!  Passage variable physique -->  variable dynamique
     
    158334   ENDDO
    159335
    160    mean3d= mean3d+dx3
    161    sd3d= sd3d+dx3**2
    162 
    163 #ifdef NC_DOUBLE
    164    ierr = NF_PUT_VARA_DOUBLE(nid,meanid,start,size,mean3d)
    165    ierr = NF_PUT_VARA_DOUBLE(nid,sdid,start,size,sd3d)
    166 #else
    167    ierr = NF_PUT_VARA_REAL(nid,meanid,start,size,mean3d)
    168    ierr = NF_PUT_VARA_REAL(nid,sdid,start,size,sd3d)
     336#ifdef NC_DOUBLE
     337   ierr = NF_PUT_VARA_DOUBLE(nid,varid,start,sizes,dx3)
     338#else
     339   ierr = NF_PUT_VARA_REAL(nid,varid,start,sizes,dx3)
    169340#endif
    170341
    171342else if (dim.eq.2) then
     343
     344      start=(/1,1,indx,0/)
     345      sizes=(/iip1,jjp1,1,0/)
    172346
    173347!    Passage variable physique -->  physique dynamique
     
    185359  ENDDO
    186360
    187    mean2d= mean2d+dx2
    188    sd2d= sd2d+dx2**2
    189 
    190 #ifdef NC_DOUBLE
    191    ierr = NF_PUT_VARA_DOUBLE(nid,meanid,start,size,mean2d)
    192    ierr = NF_PUT_VARA_DOUBLE(nid,sdid,start,size,sd2d)
    193 #else
    194    ierr = NF_PUT_VARA_REAL(nid,meanid,start,size,mean2d)
    195    ierr = NF_PUT_VARA_REAL(nid,sdid,start,size,sd2d)
    196 #endif
    197 
    198 endif
    199 
    200 ierr= NF_CLOSE(nid)
     361#ifdef NC_DOUBLE
     362   ierr = NF_PUT_VARA_DOUBLE(nid,varid,start,sizes,dx2)
     363#else
     364   ierr = NF_PUT_VARA_REAL(nid,varid,start,sizes,dx2)
     365#endif
     366
     367endif
    201368
    202369end
    203 
    204 !======================================================
    205 subroutine inivar(nid,varid,ngrid,dim,index,px,ierr)
    206 
    207 implicit none
    208 
    209 include "dimensions.h"
    210 include "dimphys.h"
    211 include "netcdf.inc"
    212 
    213 integer, intent(in) :: nid,varid,dim,index,ngrid
    214 real, dimension(ngrid,llm), intent(in) :: px
    215 integer, intent(out) :: ierr
    216 
    217 integer,parameter :: iip1=iim+1
    218 integer,parameter :: jjp1=jjm+1
    219 
    220 integer :: l,i,j,ig0
    221 integer, dimension(4) :: start,size
    222 real, dimension(iip1,jjp1,llm) :: dx3
    223 real, dimension(iip1,jjp1) :: dx2
    224 
    225 if (dim.eq.3) then
    226 
    227    start=(/1,1,1,index/)
    228    size=(/iip1,jjp1,llm,1/)
    229 
    230 !  Passage variable physique -->  variable dynamique
    231 
    232    DO l=1,llm
    233       DO i=1,iip1
    234          dx3(i,1,l)=px(1,l)
    235          dx3(i,jjp1,l)=px(ngrid,l)
    236       ENDDO
    237       DO j=2,jjm
    238          ig0= 1+(j-2)*iim
    239          DO i=1,iim
    240             dx3(i,j,l)=px(ig0+i,l)
    241          ENDDO
    242          dx3(iip1,j,l)=dx3(1,j,l)
    243       ENDDO
    244    ENDDO
    245 
    246 #ifdef NC_DOUBLE
    247    ierr = NF_PUT_VARA_DOUBLE(nid,varid,start,size,dx3)
    248 #else
    249    ierr = NF_PUT_VARA_REAL(nid,varid,start,size,dx3)
    250 #endif
    251 
    252 else if (dim.eq.2) then
    253 
    254       start=(/1,1,index,0/)
    255       size=(/iip1,jjp1,1,0/)
    256 
    257 !    Passage variable physique -->  physique dynamique
    258 
    259   DO i=1,iip1
    260      dx2(i,1)=px(1,1)
    261      dx2(i,jjp1)=px(ngrid,1)
    262   ENDDO
    263   DO j=2,jjm
    264      ig0= 1+(j-2)*iim
    265      DO i=1,iim
    266         dx2(i,j)=px(ig0+i,1)
    267      ENDDO
    268      dx2(iip1,j)=dx2(1,j)
    269   ENDDO
    270 
    271 #ifdef NC_DOUBLE
    272    ierr = NF_PUT_VARA_DOUBLE(nid,varid,start,size,dx2)
    273 #else
    274    ierr = NF_PUT_VARA_REAL(nid,varid,start,size,dx2)
    275 #endif
    276 
    277 endif
    278 
    279 end
Note: See TracChangeset for help on using the changeset viewer.