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