source: dynamico_lmdz/aquaplanet/LMDZ5/libf/phylmd/limit_slab.F90 @ 3814

Last change on this file since 3814 was 3814, checked in by ymipsl, 10 years ago

remove all dynamic dependency in LMDZ physics except for the include "dimensions.h"

YM

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