source: LMDZ5/branches/IPSLCM6.0.10/libf/phylmd/limit_slab.F90 @ 5446

Last change on this file since 5446 was 2669, checked in by Laurent Fairhead, 8 years ago

Merged trunk changes r2640:2664 into testing branch

  • 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:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 5.7 KB
Line 
1! $Header$
2
3SUBROUTINE limit_slab(itime, dtime, jour, lmt_bils, diff_sst, diff_siv)
4
5  USE dimphy
6  USE mod_grid_phy_lmdz, ONLY: klon_glo
7  USE mod_phys_lmdz_para
8  USE netcdf
9  USE indice_sol_mod
10
11  IMPLICIT NONE
12
13  INCLUDE "clesphys.h"
14
15! In- and ouput arguments
16!****************************************************************************************
17  INTEGER, INTENT(IN) :: itime   ! numero du pas de temps courant
18  INTEGER, INTENT(IN) :: jour    ! jour a lire dans l'annee
19  REAL   , INTENT(IN) :: dtime   ! pas de temps de la physique (en s)
20  REAL, DIMENSION(klon), INTENT(OUT) :: lmt_bils, diff_sst, diff_siv
21
22! Locals variables with attribute SAVE
23!****************************************************************************************
24  REAL, DIMENSION(:), ALLOCATABLE, SAVE :: bils_save, diff_sst_save
25  REAL, DIMENSION(:), ALLOCATABLE, SAVE :: diff_siv_save
26!$OMP THREADPRIVATE(bils_save, diff_sst_save, diff_siv_save)
27
28! Locals variables
29!****************************************************************************************
30  INTEGER                  :: lmt_pas   
31  INTEGER                  :: nvarid, nid, ierr, i
32  INTEGER, DIMENSION(2)    :: start, epais
33  REAL, DIMENSION(klon_glo):: bils_glo, sst_l_glo, sst_lp1_glo, diff_sst_glo
34  REAL, DIMENSION(klon_glo):: siv_l_glo, siv_lp1_glo, diff_siv_glo
35  CHARACTER (len = 20)     :: modname = 'limit_slab'
36  LOGICAL                  :: read_bils,read_sst,read_siv
37
38! End declaration
39!****************************************************************************************
40
41  ! calculate number of time steps for one day
42  lmt_pas = NINT(86400./dtime)
43 
44! Initialize saved variables
45     IF (.NOT. ALLOCATED(bils_save)) THEN
46        ALLOCATE(bils_save(klon), diff_sst_save(klon), diff_siv_save(klon), stat=ierr)
47        IF (ierr /= 0) CALL abort_physic('limit_slab', 'pb in allocation',1)
48     END IF
49
50  ! F. Codron 5/14: add defaults for bils, diff_sst (0)
51  IF (MOD(itime-1, lmt_pas) == 0) THEN   ! time to read
52!$OMP MASTER  ! Only master thread
53     IF (is_mpi_root) THEN ! Only master processus
54        print*,'in limit_slab time to read, itime=',itime
55        read_bils=.TRUE.
56        read_sst=.TRUE.
57        read_siv=.TRUE.
58       
59        ierr = NF90_OPEN ('limit_slab.nc', NF90_NOWRITE, nid)
60        IF (ierr /= NF90_NOERR) THEN
61            PRINT *,'LIMIT_SLAB file not found'
62            read_bils=.FALSE.
63            read_sst=.FALSE.
64            read_siv=.FALSE.
65        ELSE ! read file
66       
67        ! La tranche de donnees a lire:
68        start(1) = 1
69        start(2) = jour
70        epais(1) = klon_glo
71        epais(2) = 1
72
73!****************************************************************************************
74! 2) Read bils and SST/ ice volume tendency
75!
76!****************************************************************************************
77!
78! Read bils_glo
79        ierr = NF90_INQ_VARID(nid, 'BILS_OCE', nvarid)
80        IF (ierr /= NF90_NOERR) THEN
81            read_bils=.FALSE.
82        ELSE
83            ierr = NF90_GET_VAR(nid,nvarid,bils_glo,start,epais)
84            IF (ierr /= NF90_NOERR) read_bils=.FALSE.
85        END IF
86! Read sst_glo for this day
87        ierr = NF90_INQ_VARID(nid, 'SST', nvarid)
88        IF (ierr /= NF90_NOERR)  THEN
89            read_sst=.FALSE.
90        ELSE
91            ierr = NF90_GET_VAR(nid,nvarid,sst_l_glo,start,epais)
92            IF (ierr /= NF90_NOERR) read_sst=.FALSE.
93! Read sst_glo for one day ahead
94            start(2) = jour + 1
95            IF (start(2) > 360) start(2)=1
96            ierr = NF90_GET_VAR(nid,nvarid,sst_lp1_glo,start,epais)
97            IF (ierr /= NF90_NOERR) read_sst=.FALSE.
98        END IF
99
100! Read siv_glo for this day
101        ierr = NF90_INQ_VARID(nid, 'SICV', nvarid)
102        IF (ierr /= NF90_NOERR)  THEN
103            read_siv=.FALSE.
104        ELSE
105            start(2) = jour
106            ierr = NF90_GET_VAR(nid,nvarid,siv_l_glo,start,epais)
107            IF (ierr /= NF90_NOERR) read_siv=.FALSE.
108! Read siv_glo for one day ahead
109            start(2) = jour + 1
110            IF (start(2) > 360) start(2)=1
111            ierr = NF90_GET_VAR(nid,nvarid,siv_lp1_glo,start,epais)
112            IF (ierr /= NF90_NOERR) read_siv=.FALSE.
113        END IF
114
115!****************************************************************************************
116! 5) Close file and distribute variables to all processus
117!
118!****************************************************************************************
119        ierr = NF90_CLOSE(nid)
120        IF (ierr /= NF90_NOERR) CALL abort_physic(modname,'Pb when closing file', 1)
121        END IF ! Read File
122        IF (read_sst) THEN
123! Calculate difference in temperature between this day and one ahead
124            DO i=1, klon_glo
125               diff_sst_glo(i) = sst_lp1_glo(i) - sst_l_glo(i)
126            END DO
127        END IF !read_sst
128        IF (read_siv) THEN
129! Calculate difference in temperature between this day and one ahead
130            DO i=1, klon_glo
131               diff_siv_glo(i) = siv_lp1_glo(i) - siv_l_glo(i)
132            END DO
133        END IF !read_siv
134     ENDIF ! is_mpi_root
135
136!$OMP END MASTER
137!$OMP BARRIER
138       
139! Send fields to all processes
140! Give default values if needed
141     CALL bcast(read_bils)
142     CALL bcast(read_sst)
143     CALL bcast(read_siv)
144     PRINT *,'limit_slab sst',read_sst,'siv',read_siv,'qflux',read_bils
145     IF (read_bils) THEN
146         CALL Scatter(bils_glo, bils_save)
147     ELSE
148         bils_save(:)=0.
149     END IF
150     IF (read_sst) THEN
151         CALL Scatter(diff_sst_glo, diff_sst_save)
152     ELSE
153         diff_sst_save(:)=0.
154     END IF
155     IF (read_siv) THEN
156         CALL Scatter(diff_siv_glo, diff_siv_save)
157     ELSE
158         diff_siv_save(:)=0.
159     END IF
160     
161  ENDIF ! time to read
162
163  lmt_bils(:) = bils_save(:)
164  diff_sst(:) = diff_sst_save(:)
165  diff_siv(:) = diff_siv_save(:)
166
167END SUBROUTINE limit_slab
Note: See TracBrowser for help on using the repository browser.