1 | SUBROUTINE read_rsun_rrtm(debut) |
---|
2 | |
---|
3 | !**************************************************************************************** |
---|
4 | ! This routine will read the solar constant fraction per band |
---|
5 | |
---|
6 | ! Olivier Boucher with inputs from Marion Marchand |
---|
7 | !**************************************************************************************** |
---|
8 | |
---|
9 | USE netcdf95, ONLY: nf95_close, nf95_inq_varid, nf95_open, nf95_gw_var |
---|
10 | USE netcdf, ONLY: nf90_get_var, nf90_noerr, nf90_nowrite |
---|
11 | |
---|
12 | USE phys_cal_mod, ONLY : days_elapsed, year_len |
---|
13 | |
---|
14 | USE lmdz_phys_mpi_data, ONLY: is_mpi_root |
---|
15 | USE lmdz_phys_omp_data, ONLY: is_omp_root |
---|
16 | USE lmdz_phys_para |
---|
17 | USE lmdz_abort_physic, ONLY: abort_physic |
---|
18 | |
---|
19 | USE YOESW, ONLY : RSUN |
---|
20 | USE lmdz_clesphys |
---|
21 | |
---|
22 | IMPLICIT NONE |
---|
23 | |
---|
24 | |
---|
25 | ! Input arguments |
---|
26 | LOGICAL, INTENT(IN) :: debut |
---|
27 | |
---|
28 | ! Local variables |
---|
29 | INTEGER :: ncid, dimid, varid, ncerr, nbday |
---|
30 | REAL, ALLOCATABLE :: wlen(:), time(:) |
---|
31 | REAL, ALLOCATABLE, SAVE, DIMENSION(:,:) :: SSI_FRAC |
---|
32 | !$OMP THREADPRIVATE(SSI_FRAC) |
---|
33 | REAL, ALLOCATABLE, SAVE, DIMENSION(:) :: TSI(:) |
---|
34 | !$OMP THREADPRIVATE(TSI) |
---|
35 | |
---|
36 | INTEGER, SAVE :: day_pre=1 |
---|
37 | !$OMP THREADPRIVATE(day_pre) |
---|
38 | |
---|
39 | !--only one processor reads |
---|
40 | IF (debut) THEN |
---|
41 | |
---|
42 | ALLOCATE(SSI_FRAC(NSW,year_len)) |
---|
43 | ALLOCATE(TSI(year_len)) |
---|
44 | |
---|
45 | IF (is_mpi_root.AND.is_omp_root) THEN |
---|
46 | |
---|
47 | CALL nf95_open('solarforcing.nc', NF90_NOWRITE, ncid) |
---|
48 | |
---|
49 | CALL nf95_inq_varid(ncid, 'wlen', varid) |
---|
50 | CALL nf95_gw_var(ncid, varid, wlen) |
---|
51 | |
---|
52 | CALL nf95_inq_varid(ncid, 'time', varid) |
---|
53 | CALL nf95_gw_var(ncid, varid, time) |
---|
54 | |
---|
55 | IF (NSW.NE.size(wlen)) THEN |
---|
56 | PRINT *,'read_rsun_rrtm NSW <> wlen = ',NSW, size(wlen) |
---|
57 | CALL abort_physic('read_rsun_rrtm','size of SSI is different from NSW',1) |
---|
58 | ENDIF |
---|
59 | |
---|
60 | !--test if time is different from year_len but allow a mismatch of 1 day |
---|
61 | IF (size(time).NE.year_len.AND.size(time).NE.year_len+1) THEN |
---|
62 | PRINT *,'read_rsun_rrtm time <> year_len = ', size(time), year_len |
---|
63 | CALL abort_physic('read_rsun_rrtm','time dim should be the number of days in year',1) |
---|
64 | ENDIF |
---|
65 | !--warning only if forcing file has 366 days but year_len has only 365 |
---|
66 | IF (size(time).EQ.year_len+1) THEN |
---|
67 | PRINT *,'Warning read_rsun_rrtm uses a leap year rsun for a noleap year' |
---|
68 | ENDIF |
---|
69 | |
---|
70 | CALL nf95_inq_varid(ncid, 'ssi_frac', varid) |
---|
71 | ncerr = nf90_get_var(ncid, varid, SSI_FRAC) |
---|
72 | |
---|
73 | CALL nf95_inq_varid(ncid, 'tsi', varid) |
---|
74 | ncerr = nf90_get_var(ncid, varid, TSI) |
---|
75 | |
---|
76 | CALL nf95_close(ncid) |
---|
77 | |
---|
78 | DO nbday=1, year_len |
---|
79 | IF (ABS(SUM(SSI_FRAC(:,nbday))-1.).GT.1.e-6) THEN |
---|
80 | PRINT *,'somme SSI_FRAC=', SUM(SSI_FRAC(:,nbday)) |
---|
81 | CALL abort_physic('read_rsun_rrtm','somme SSI_FRAC <> 1',1) |
---|
82 | ENDIF |
---|
83 | ENDDO |
---|
84 | |
---|
85 | ENDIF ! is_mpi_root .AND. is_omp_root |
---|
86 | |
---|
87 | !$OMP BARRIER |
---|
88 | CALL bcast(SSI_FRAC) |
---|
89 | CALL bcast(TSI) |
---|
90 | |
---|
91 | ENDIF |
---|
92 | |
---|
93 | !--only read at beginning of day |
---|
94 | !--day in year is provided as days_elapsed since the beginning of the year +1 |
---|
95 | IF (debut.OR.days_elapsed+1.NE.day_pre) THEN |
---|
96 | |
---|
97 | !--keep memory of previous day |
---|
98 | day_pre=days_elapsed+1 |
---|
99 | |
---|
100 | !--copy |
---|
101 | RSUN(1:NSW)=SSI_FRAC(:,days_elapsed+1) |
---|
102 | solaire=TSI(days_elapsed+1) |
---|
103 | |
---|
104 | PRINT *,'READ_RSUN_RRTM day=', days_elapsed+1,' solaire=', solaire, ' RSUN=', RSUN(1:NSW) |
---|
105 | |
---|
106 | ENDIF !--fin allocation |
---|
107 | |
---|
108 | END SUBROUTINE read_rsun_rrtm |
---|