Ignore:
Timestamp:
2023-03-02T15:18:40+01:00 (16 months ago)
Author:
xiaoni.wang
Message:

Modified and updated the new driver in Tag2.2 in response to ticket #895. Tested with CRUJRA and daily forcings, and it works.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ORCHIDEE_2_2/ORCHIDEE/src_driver/forcing_tools.f90

    r7796 r7901  
    9999  INTEGER(i_std), SAVE                                :: nb_forcefile=0 
    100100  CHARACTER(LEN=100), SAVE, ALLOCATABLE, DIMENSION(:) :: forfilename 
    101   INTEGER(i_std), SAVE, ALLOCATABLE, DIMENSION(:)     :: force_id, id_unlim 
     101  INTEGER(i_std), SAVE, ALLOCATABLE, DIMENSION(:), public     :: force_id 
     102  INTEGER(i_std), SAVE, ALLOCATABLE, DIMENSION(:)     :: id_unlim 
    102103  INTEGER(i_std), SAVE, ALLOCATABLE, DIMENSION(:)     :: nb_atts, ndims, nvars 
    103104  REAL(r_std), SAVE, ALLOCATABLE, DIMENSION(:)        :: convtosec 
     
    148149  REAL(r_std), SAVE, ALLOCATABLE, DIMENSION(:,:)    :: tair_slab, qair_slab 
    149150  REAL(r_std), SAVE, ALLOCATABLE, DIMENSION(:,:)    :: tairmax_slab, tairmin_slab 
     151  REAL(r_std), SAVE, ALLOCATABLE, DIMENSION(:,:)    :: hurs_slab 
    150152  REAL(r_std), SAVE, ALLOCATABLE, DIMENSION(:)      :: time_tair, time_qair 
    151153  REAL(r_std), SAVE, ALLOCATABLE, DIMENSION(:,:)    :: timebnd_tair, timebnd_qair 
     
    732734       CALL forcingdaily_gensubd(time_int, dt, iim_loc, jjm_loc, lon_loc, lat_loc, glolindex_proc, & 
    733735            &                    nbpoint_proc, slab_size, time_tair, ztq_slab, zuv_slab, tair_slab, & 
    734             &                    tairmin_slab, tairmax_slab, qair_slab, rainf_slab, snowf_slab, & 
     736            &                    tairmin_slab, tairmax_slab, qair_slab, hurs_slab, rainf_slab, snowf_slab, & 
    735737            &                    swdown_slab, lwdown_slab, u_slab, v_slab, ps_slab) 
    736738       CALL forcingdaily_getvalues(time_int, dt, zlev_tq, zlev_uv, tair, qair, rainf, snowf, & 
     
    14321434    REAL(r_std), ALLOCATABLE, DIMENSION(:,:)    :: tair_full, qair_full 
    14331435    REAL(r_std), ALLOCATABLE, DIMENSION(:,:)    :: tairmin_full, tairmax_full 
     1436    REAL(r_std), ALLOCATABLE, DIMENSION(:,:)    :: hurs_full 
    14341437    REAL(r_std), ALLOCATABLE, DIMENSION(:,:)    :: rainf_full, snowf_full 
    14351438    REAL(r_std), ALLOCATABLE, DIMENSION(:,:)    :: swdown_full, lwdown_full 
     
    14501453       IF ( .NOT. ALLOCATED(tairmax_slab) ) ALLOCATE(tairmax_slab(nbpoint_proc,slab_size)) 
    14511454       IF ( .NOT. ALLOCATED(tairmin_slab) ) ALLOCATE(tairmin_slab(nbpoint_proc,slab_size)) 
     1455       IF ( .NOT. ALLOCATED(hurs_slab) ) ALLOCATE(hurs_slab(nbpoint_proc,slab_size)) 
    14521456    ENDIF 
    14531457    ! 
     
    15061510          ALLOCATE(tairmax_full(nbpoint_loc,slab_size)) 
    15071511          ALLOCATE(tairmin_full(nbpoint_loc,slab_size)) 
     1512          ALLOCATE(hurs_full(nbpoint_loc,slab_size)) 
    15081513       ELSE 
    15091514          ALLOCATE(tairmax_full(1,1)) 
    15101515          ALLOCATE(tairmin_full(1,1)) 
     1516          ALLOCATE(hurs_full(1,1)) 
    15111517       ENDIF 
    15121518       ALLOCATE(qair_full(nbpoint_loc,slab_size)) 
     
    15231529       CALL forcing_readslab_root(time_int, first_call_readslab, & 
    15241530            &                     tair_full, tairmax_full, tairmin_full, time_tair, timebnd_tair, & 
    1525             &                     qair_full, time_qair, timebnd_qair, & 
     1531            &                     qair_full, hurs_full, time_qair, timebnd_qair, & 
    15261532            &                     rainf_full, snowf_full, time_precip, timebnd_precip, & 
    15271533            &                     swdown_full, time_swdown, timebnd_swdown, & 
     
    15791585          CALL scatter(tairmax_full, tairmax_slab) 
    15801586          CALL scatter(tairmin_full, tairmin_slab) 
     1587          CALL scatter(hurs_full, hurs_slab) 
    15811588       ENDIF 
    15821589       CALL scatter(qair_full, qair_slab) 
     
    15951602          tairmax_slab(:,:) = tairmax_full(:,:) 
    15961603          tairmin_slab(:,:) = tairmin_full(:,:) 
     1604          hurs_slab(:,:) = hurs_full(:,:) 
    15971605       ENDIF 
    15981606       qair_slab(:,:) = qair_full(:,:) 
     
    16331641    IF ( ALLOCATED(tairmax_full) ) DEALLOCATE(tairmax_full) 
    16341642    IF ( ALLOCATED(tairmin_full) ) DEALLOCATE(tairmin_full) 
     1643    IF ( ALLOCATED(hurs_full) ) DEALLOCATE(hurs_full) 
    16351644    IF ( ALLOCATED(qair_full) ) DEALLOCATE(qair_full) 
    16361645    IF ( ALLOCATED(rainf_full) ) DEALLOCATE(rainf_full) 
     
    16601669  SUBROUTINE forcing_readslab_root(time_int, first_call_readslab, & 
    16611670            &                     tair, tairmax, tairmin, t_tair, tbnd_tair, & 
    1662             &                     qair, t_qair, tbnd_qair, & 
     1671            &                     qair, hurs, t_qair, tbnd_qair, & 
    16631672            &                     rainf, snowf, t_prec, tbnd_prec, & 
    16641673            &                     swdown, t_swdown, tbnd_swdown, & 
     
    16781687    REAL(r_std), INTENT(out) :: tbnd_tair(:,:) 
    16791688    ! 
    1680     REAL(r_std), INTENT(out) :: qair(:,:) 
     1689    REAL(r_std), INTENT(out) :: qair(:,:), hurs(:,:) 
    16811690    REAL(r_std), INTENT(out) :: t_qair(:) 
    16821691    REAL(r_std), INTENT(out) :: tbnd_qair(:,:) 
     
    18051814          ! 
    18061815          ! 2.1 Deal with air temperature and humidity as the fist and basic case 
    1807           ! 
     1816          ! hurs: relative humidity  
     1817          ! qair: specific humidity  
     1818          ! 
     1819          IF ( ExistVariable(if, "Tair") ) THEN  
     1820             CALL forcing_varforslab(if, "Tair", nctstart, nctcount, inslabpos, tair, cellmethod)  
     1821             CALL forcing_attributetimeaxe(cellmethod, timeid_tair)  
     1822          ELSE IF ( ( forcing_tstep_ave >= one_day/3.0) .AND.  ( ExistVariable(if, "Tmax"))) THEN  
     1823             CALL forcing_varforslab(if, "Tmax", nctstart, nctcount, inslabpos, tairmax, cellmethod)  
     1824             CALL forcing_varforslab(if, "Tmin", nctstart, nctcount, inslabpos, tairmin, cellmethod)  
     1825             CALL forcing_attributetimeaxe(cellmethod, timeid_tair)  
     1826             tair(:,:) = tairmax(:,:)  
     1827          ELSE  
     1828             CALL ipslerr(3, 'forcing_readslab_root','We do not have Tair or Tmax in the file but we need it',&  
     1829                                     &          'because the timestep of the forcing is sub-diurnal','')  
     1830          ENDIF 
     1831                     
    18081832          !  
    1809           ! 
    1810           IF ( forcing_tstep_ave >= one_day/3.0) THEN 
    1811              CALL forcing_varforslab(if, "Tairmax", nctstart, nctcount, inslabpos, tairmax, cellmethod) 
    1812              CALL forcing_varforslab(if, "Tairmin", nctstart, nctcount, inslabpos, tairmin, cellmethod) 
     1833          ! 2.2 Deal with rainfall and snowfall.  
     1834          !  
     1835          IF ( ExistVariable(if, "Rainf") ) THEN  
     1836             CALL forcing_varforslab(if, "Rainf", nctstart, nctcount, inslabpos, rainf, cellmethod)  
     1837             CALL forcing_attributetimeaxe(cellmethod, timeid_precip)  
     1838                 
     1839          ELSE IF ( (forcing_tstep_ave >= one_day/3.0)) THEN  
     1840             CALL forcing_varforslab(if, "precip", nctstart, nctcount, inslabpos, rainf, cellmethod)  
     1841             CALL forcing_attributetimeaxe(cellmethod, timeid_precip)  
    18131842          ENDIF 
    1814            
    1815            
    1816           CALL forcing_varforslab(if, "Tair", nctstart, nctcount, inslabpos, tair, cellmethod) 
    1817           CALL forcing_attributetimeaxe(cellmethod, timeid_tair) 
    1818           ! 
    1819           CALL forcing_varforslab(if, "Qair", nctstart, nctcount, inslabpos, qair, cellmethod) 
    1820           CALL forcing_attributetimeaxe(cellmethod, timeid_qair) 
    1821           ! 
    1822           ! 2.2 Deal with rainfall and snowfall. 
    1823           ! 
    1824           CALL forcing_varforslab(if, "Rainf", nctstart, nctcount, inslabpos, rainf, cellmethod) 
    1825           CALL forcing_attributetimeaxe(cellmethod, timeid_precip) 
    1826           ! 
    1827           CALL forcing_varforslab(if, "Snowf", nctstart, nctcount, inslabpos, snowf, cellmethod) 
    1828           CALL forcing_attributetimeaxe(cellmethod, timeid_tmp) 
    1829           IF ( timeid_precip .NE. timeid_tmp) THEN 
    1830              CALL ipslerr(3, 'forcing_readslab_root','Rainf and Snwof have different time axes.', & 
    1831                   &         'Please check the forcing file to ensure both variable have the same cell_method.','') 
     1843          !  
     1844          IF ( ExistVariable(if, "Snowf")) THEN  
     1845             CALL forcing_varforslab(if, "Snowf", nctstart, nctcount, inslabpos, snowf, cellmethod)  
     1846             CALL forcing_attributetimeaxe(cellmethod, timeid_tmp)  
     1847             IF ( timeid_precip .NE. timeid_tmp) THEN  
     1848                CALL ipslerr(3, 'forcing_readslab_root','Rainf and Snwof have different time axes.', &  
     1849                     &         'Please check the forcing file to ensure both variable have the same cell_method.','')  
     1850             ENDIF 
     1851                 
     1852          ELSE IF ( (forcing_tstep_ave >= one_day/3.0) )THEN  
     1853             snowf(:,:) = rainf(:,:)   
     1854             WHERE (tair(:,:)>=273.15)  
     1855                snowf(:,:) = 0.0  
     1856             ELSEWHERE (tair(:,:)<273.15)  
     1857                rainf(:,:) = 0.0  
     1858             END WHERE 
    18321859          ENDIF 
     1860          ! 
     1861          ! 
     1862          IF ( ExistVariable(if, "Qair") ) THEN 
     1863             CALL forcing_varforslab(if, "Qair", nctstart, nctcount, inslabpos, qair, cellmethod) 
     1864             CALL forcing_attributetimeaxe(cellmethod, timeid_qair) 
     1865          ELSE IF ( ExistVariable(if, "hurs") ) THEN 
     1866             CALL forcing_varforslab(if, "hurs", nctstart, nctcount, inslabpos, hurs, cellmethod) 
     1867             CALL forcing_attributetimeaxe(cellmethod, timeid_qair) 
     1868             CALL ipslerr(3, 'forcing_readslab_root','hurs is read from forcing file', & 
     1869                  &         'Please make sure that the conversion from hurs to specific humidity is correct before continue simulation.','') 
     1870          ELSE 
     1871             CALL ipslerr(3, 'forcing_readslab_root','We do not have Qair or hurs in the file but we need one of them',& 
     1872                  &          'because the timestep of the forcing is sub-diurnal','') 
     1873          ENDIF 
     1874          ! 
    18331875          ! 
    18341876          ! 
     
    24472489    INTEGER(i_std) :: ik, i, j, iff, ndimsvar 
    24482490    ! Read a test variabe 
    2449     CHARACTER(len=8) :: testvarname='Tair' 
     2491    CHARACTER(len=8) :: testvarname 
    24502492    INTEGER(i_std)   :: testvar_id, contfrac_id 
    24512493    REAL(r_std) :: testvar_missing, contfrac_missing 
     
    25312573       ENDIF 
    25322574    ENDDO 
    2533      
     2575    ! 
     2576    iret = NF90_INQ_VARID(force_id(1), 'Tair', iv) 
     2577    IF (iret == NF90_NOERR) THEN 
     2578       testvarname = 'Tair' 
     2579    ELSE 
     2580       iret = NF90_INQ_VARID(force_id(1), 'Tmax', iv) 
     2581       IF (iret == NF90_NOERR) THEN 
     2582          testvarname = 'Tmax' 
     2583       ELSE 
     2584          CALL ipslerr (3,'forcing_getglogrid',"Could not find variable Tair or Tmax in file."," "," ") 
     2585       ENDIF 
     2586    ENDIF 
    25342587    ! 
    25352588    ! 3.0 Read the spatial coordinate variables found in the first file. 
     
    32923345    INTEGER(i_std) :: iindex_init, jindex_init, iindex_end, jindex_end, i_orig, j_orig  
    32933346    ! 
    3294     INTEGER(i_std) :: iret, force_id, iv 
     3347    INTEGER(i_std) :: iret, force_id, iv, ierr 
    32953348    INTEGER(i_std), DIMENSION(1) :: imin, jmin 
    32963349    INTEGER(i_std), DIMENSION(2) :: start, count 
     
    33003353    INTEGER(i_std), ALLOCATABLE, DIMENSION(:) :: index_glotoloc 
    33013354    REAL(r_std), ALLOCATABLE, DIMENSION(:,:) :: lalo 
    3302     CHARACTER(LEN=8) :: testvarname="Tair" 
     3355    CHARACTER(LEN=8) :: testvarname 
    33033356    ! 
    33043357    ! 0.0 Verify we are on the root processor 
     
    33283381          ENDDO 
    33293382       ENDDO 
     3383    ENDIF 
     3384    !! define dx and dy for regular grids 
     3385    IF ( model_guess .EQ. 'regular' ) THEN 
     3386       dx=ABS(lon_glo(2,1)-lon_glo(1,1)) 
     3387       dy=ABS(lat_glo(1,1)-lat_glo(1,2))  
    33303388    ENDIF 
    33313389    ! 
     
    35773635       !  
    35783636       DO j=1,jjm_loc  
    3579           dx = zero  
    3580           DO i=1,iim_loc-1  
    3581              dx = dx+ABS(lon_loc(i,j)-lon_loc(i+1,j))  
    3582           ENDDO 
    3583           dx = dx/(iim_loc-1)  
    35843637          DO i=1,iim_loc  
    35853638             corners_loc(i,j,1,1) = lon_loc(i,j)-dx/2.0  
     
    35933646       !  
    35943647       DO i=1,iim_loc 
    3595           dy = zero  
    3596           DO j=1,jjm_loc-1  
    3597              dy = dy + ABS(lat_loc(i,j)-lat_loc(i,j+1))  
    3598           ENDDO 
    3599           dy = dy/(jjm_loc-1)  
    36003648          DO j=1,jjm_loc  
    36013649             corners_loc(i,j,1,2) = lat_loc(i,j)+dy/2.0  
     
    36313679       ALLOCATE(readvar(ncdfcount), readvar2d(iim_glo,jjm_glo), zoomedvar(nbpoint_loc)) 
    36323680       ! 
    3633        iret = NF90_INQ_VARID(force_id, TRIM(testvarname), iv) 
    3634        IF (iret /= NF90_NOERR) THEN 
    3635           CALL ipslerr (3,'forcing_zoomgrid',"Could not find variable Tair in file."," "," ") 
    3636        ENDIF 
    3637  
     3681       ! 
     3682       iret = NF90_INQ_VARID(force_id, 'Tair', iv) 
     3683       IF (iret == NF90_NOERR) THEN 
     3684          testvarname = 'Tair' 
     3685       ELSE 
     3686          iret = NF90_INQ_VARID(force_id, 'Tmax', iv) 
     3687          IF (iret == NF90_NOERR) THEN 
     3688             testvarname = 'Tmax' 
     3689          ELSE 
     3690             CALL ipslerr (3,'forcing_zoomgrid',"Could not find variable Tair or Tmax in file."," "," ") 
     3691          ENDIF 
     3692       ENDIF 
     3693       ! 
    36383694       IF ( compressed ) THEN 
    36393695          ! 
     
    36693725            &                    lon_loc(:,1), lat_loc(1,:), lindex_loc, mask_loc, & 
    36703726            &                    TRIM(testvarname), zoomedvar) 
     3727       ierr = NF90_CLOSE(force_id) 
    36713728       ! 
    36723729    ENDIF 
     
    40894146  ! 
    40904147  ! Go through all files in the list in order to get the total number of time steps we have 
    4091   ! in the nbfiles files to be read 
     4148  ! in the nbfiles files to be read. nb_forcing_steps: three full years of forcing time steps  
    40924149  ! 
    40934150  nb_forcing_steps = 0 
     
    43704427END SUBROUTINE forcing_time 
    43714428 
     4429 
     4430!! -------------------------------------------------------------------- 
     4431!! FUNCTION  ExistVariable(): 
     4432!!    This function tests if the variable exists in the file. 
     4433!! -------------------------------------------------------------------- 
     4434FUNCTION  ExistVariable(fileindex, varname) RESULT(exists)  
     4435  IMPLICIT  NONE 
     4436  INTEGER(i_std), INTENT(in) :: fileindex 
     4437  CHARACTER(LEN=*), INTENT(in) :: varname 
     4438  LOGICAL :: exists 
     4439  ! 
     4440  CHARACTER(LEN=80) :: name 
     4441  INTEGER(i_std) :: iret, iv 
     4442  ! 
     4443  exists=.FALSE. 
     4444  ! 
     4445  DO iv=1,nvars(fileindex) 
     4446     ! 
     4447     iret = NF90_INQUIRE_VARIABLE(force_id(fileindex), iv, name=name) 
     4448     ! 
     4449     IF ( INDEX(name, varname) > 0 ) THEN 
     4450        exists = .TRUE. 
     4451     ENDIF 
     4452  ENDDO 
     4453   
     4454END FUNCTION ExistVariable 
     4455 
    43724456!!  ============================================================================================================================= 
    43734457!! SUBROUTINE: forcing_varforslab 
Note: See TracChangeset for help on using the changeset viewer.