source: LMDZ6/branches/Amaury_dev/libf/phylmd/limit_slab.F90 @ 5111

Last change on this file since 5111 was 5111, checked in by abarral, 4 months ago

Put abort_physic into a module
Remove -g option from makelmdz_fcm, since that option is linked to a header file that isn't included anywhere.
(lint) light lint on traversed files

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