Ignore:
Timestamp:
2022-11-08T16:24:46+01:00 (20 months ago)
Author:
xiaoni.wang
Message:

Updated the new driver in Tag2.2, with the corresponding changes in the commits 7714, 7770, 7771 and 7774 for trunk. Tested in debug and prod mode, with safran and cru forcings.

Location:
branches/ORCHIDEE_2_2/ORCHIDEE/src_driver
Files:
3 edited

Legend:

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

    r7475 r7796  
    5151  USE mod_orchidee_para 
    5252  USE forcingdaily_tools 
     53  USE grid 
    5354  ! 
    5455  IMPLICIT NONE 
     
    9091  REAL(r_std), SAVE, ALLOCATABLE, DIMENSION(:,:,:)   :: time_bounds 
    9192  CHARACTER(LEN=20), SAVE, ALLOCATABLE, DIMENSION(:) :: time_axename, time_cellmethod 
    92   REAL(r_std), SAVE, ALLOCATABLE, DIMENSION(:)       :: preciptime 
    9393  INTEGER(i_std), SAVE, ALLOCATABLE, DIMENSION(:)    :: time_sourcefile 
    9494  INTEGER(i_std), SAVE, ALLOCATABLE, DIMENSION(:,:)  :: time_id 
     
    404404! 
    405405  SUBROUTINE forcing_open(filenames_in, iim, jjm, lon, lat, nbpoint_in, drvzoom_lon, drvzoom_lat, & 
    406        &                  kindex, nbindex_perproc, wunit, landonly_arg) 
     406       &                  kindex, nbindex_perproc, wunit, model_guess, landonly_arg) 
    407407    ! 
    408408    ! Opens the forcing file and reads some key information and stores them in the shared variables of the 
     
    424424    INTEGER(i_std), OPTIONAL, INTENT(in)  :: wunit 
    425425    LOGICAL, OPTIONAL, INTENT(in)         :: landonly_arg 
     426    CHARACTER(LEN=*), INTENT(in)          :: model_guess 
    426427    ! 
    427428    ! LOCAL 
     
    501502       ! 
    502503       IF ( PRESENT(wunit) ) THEN 
    503           WRITE(wunit,*) "Getting the zoomed grid", nbpoint_tmp 
     504          WRITE(wunit,*) "Getting the full grid", nbpoint_tmp 
    504505          CALL FLUSH(wunit) 
    505506       ENDIF 
    506        CALL forcing_zoomgrid(drvzoom_lon, drvzoom_lat, forfilename(1), .FALSE.) 
     507       CALL forcing_zoomgrid(drvzoom_lon, drvzoom_lat, forfilename(1), model_guess, .FALSE.) 
    507508       IF ( PRESENT(wunit) ) THEN 
    508509          WRITE(wunit,*) "Out of the zoomed grid operation" 
     
    14281429    ! Local 
    14291430    ! 
    1430     INTEGER(i_std)  :: is 
     1431    INTEGER(i_std)  :: is, tlen 
    14311432    REAL(r_std), ALLOCATABLE, DIMENSION(:,:)    :: tair_full, qair_full 
    14321433    REAL(r_std), ALLOCATABLE, DIMENSION(:,:)    :: tairmin_full, tairmax_full 
     
    14351436    REAL(r_std), ALLOCATABLE, DIMENSION(:,:)    :: u_full, v_full 
    14361437    REAL(r_std), ALLOCATABLE, DIMENSION(:,:)    :: ps_full, ztq_full, zuv_full 
    1437     REAL(r_std), ALLOCATABLE, DIMENSION(:)      :: preciptime_tmp 
     1438    REAL(r_std), ALLOCATABLE, DIMENSION(:)      :: time_precip_old  
     1439    REAL(r_std), ALLOCATABLE, DIMENSION(:,:)    :: savepreciptime  
     1440    INTEGER(i_std) :: s2in1(1)  
     1441    LOGICAL, SAVE :: first_call_readslab=.TRUE.  
    14381442    ! 
    14391443    ! 1.0 Verify that for the slabs the memory is allocated for the variable 
     
    14571461    IF ( .NOT. ALLOCATED(timebnd_precip) ) ALLOCATE(timebnd_precip(slab_size,2)) 
    14581462    IF ( .NOT. ALLOCATED(preciptime_slab) ) ALLOCATE(preciptime_slab(nbpoint_proc,slab_size))  
    1459     IF ( .NOT. ALLOCATED(preciptime_tmp) ) ALLOCATE(preciptime_tmp(slab_size)) 
     1463    IF ( .NOT. ALLOCATED(time_precip_old) ) ALLOCATE(time_precip_old(slab_size))  
     1464    IF ( .NOT. ALLOCATED(savepreciptime) ) ALLOCATE(savepreciptime(nbpoint_proc,slab_size))  
     1465     
    14601466    ! 
    14611467    IF ( .NOT. ALLOCATED(swdown_slab) ) ALLOCATE(swdown_slab(nbpoint_proc,slab_size)) 
     
    14821488    IF ( .NOT. ALLOCATED(zuv_slab) ) ALLOCATE(zuv_slab(nbpoint_proc,slab_size)) 
    14831489    !     
     1490    !  
     1491    ! Save the old time axis for precipitation.  
     1492    !  
     1493    IF ( first_call_readslab ) THEN  
     1494       time_precip_old(:) = zero  
     1495       preciptime_slab(:,:) = zero  
     1496    ELSE  
     1497       time_precip_old(:) = time_precip(:)  
     1498    ENDIF 
    14841499    ! 
    14851500    IF ( is_root_prc) THEN 
     
    15061521       ALLOCATE(zuv_full(nbpoint_loc,slab_size)) 
    15071522       ! 
    1508        CALL forcing_readslab_root(time_int, & 
     1523       CALL forcing_readslab_root(time_int, first_call_readslab, & 
    15091524            &                     tair_full, tairmax_full, tairmin_full, time_tair, timebnd_tair, & 
    15101525            &                     qair_full, time_qair, timebnd_qair, & 
    1511             &                     rainf_full, snowf_full, time_precip, timebnd_precip, preciptime_tmp, & 
     1526            &                     rainf_full, snowf_full, time_precip, timebnd_precip, & 
    15121527            &                     swdown_full, time_swdown, timebnd_swdown, & 
    15131528            &                     lwdown_full, time_lwdown, timebnd_lwdown, & 
     
    15461561    CALL bcast(time_precip) 
    15471562    CALL bcast(timebnd_precip) 
    1548     CALL bcast(preciptime_tmp) 
    15491563    CALL bcast(time_swdown) 
    15501564    CALL bcast(timebnd_swdown) 
     
    15961610    ! 
    15971611    ! 
    1598     DO is=1,nbpoint_proc 
    1599        preciptime_slab(is,:) = preciptime_tmp(:) 
    1600     ENDDO 
     1612    ! Transfer preciptime_slab from the old slab to the new one.  
     1613    ! s2in1: the index of the starting time from new slab in the previous slab  
     1614    s2in1 = MINLOC(ABS(time_precip_old-time_precip(1)))  
     1615    IF ( size(s2in1) .EQ. 0 ) THEN  
     1616       s2in1(1) = 1  
     1617    ENDIF 
     1618    tlen=slab_size-s2in1(1)+1    
     1619    savepreciptime(:,:) = zero      
     1620    savepreciptime(:,1:tlen) = preciptime_slab(:,s2in1(1):slab_size)      
     1621    preciptime_slab(:,:) = zero  
     1622    preciptime_slab(:,1:tlen) = savepreciptime(:,1:tlen)  
     1623     
     1624     
     1625    IF (first_call_readslab) THEN  
     1626       first_call_readslab = .FALSE.  
     1627    ENDIF 
     1628 
    16011629    ! 
    16021630    ! Clean-up to free the memory on the root processor. 
     
    16301658!_ ============================================================================================================================== 
    16311659 
    1632   SUBROUTINE forcing_readslab_root(time_int, & 
     1660  SUBROUTINE forcing_readslab_root(time_int, first_call_readslab, & 
    16331661            &                     tair, tairmax, tairmin, t_tair, tbnd_tair, & 
    16341662            &                     qair, t_qair, tbnd_qair, & 
    1635             &                     rainf, snowf, t_prec, tbnd_prec, prectime, & 
     1663            &                     rainf, snowf, t_prec, tbnd_prec, & 
    16361664            &                     swdown, t_swdown, tbnd_swdown, & 
    16371665            &                     lwdown, t_lwdown, tbnd_lwdown, & 
     
    16451673    REAL(r_std), INTENT(in)  :: time_int(2)                            !! The time interval over which the forcing is needed. 
    16461674    ! 
     1675    LOGICAL,     INTENT(in)  :: first_call_readslab  
    16471676    REAL(r_std), INTENT(out) :: tair(:,:), tairmax(:,:), tairmin(:,:) 
    16481677    REAL(r_std), INTENT(out) :: t_tair(:) 
     
    16571686    REAL(r_std), INTENT(out) :: t_prec(:) 
    16581687    REAL(r_std), INTENT(out) :: tbnd_prec(:,:) 
    1659     REAL(r_std), INTENT(out) :: prectime(:) 
    16601688    ! 
    16611689    REAL(r_std), INTENT(out) :: swdown(:,:) 
     
    16961724    CHARACTER(LEN=80) :: cellmethod 
    16971725    ! 
    1698     LOGICAL, SAVE :: first_call_readslab=.TRUE. 
    1699     ! 
    17001726    ALLOCATE(time_tmp(slab_size,nbtax)) 
    17011727    ALLOCATE(rau(nbpoint_loc,slab_size)) 
     
    17131739    IF ( first_call_readslab ) THEN 
    17141740       ! 
    1715        preciptime(:) = 0 
    17161741       ! 
    17171742       ! If the first file is only there to provide the last time step of the previous year, we 
     
    17221747       current_offset = MAX(imin(1)-2,1) 
    17231748       ! 
    1724        first_call_readslab = .FALSE. 
    1725        write(numout, *) "first_call_readslab in forcing_readslab_root" 
    17261749       ! 
    17271750    ELSE        
    17281751       ! 
    1729        ! Put back the cummulated time of rainfall into the global array 
    1730        ! 
    1731        preciptime(position_slab(1):position_slab(2)) = preciptime(position_slab(1):position_slab(2)) + & 
    1732             &    prectime(1:slab_size) 
    1733        ! 
    17341752       ! Compute new offset 
    17351753       ! 
    17361754       current_offset = position_slab(2)-2 
    1737        write(numout, *) "first_call_readslab in forcing_readslab_root 22" 
    17381755       ! 
    17391756    ENDIF 
     
    19301947       t_prec(1:slab_size) = time(position_slab(1):position_slab(2), timeid_precip) 
    19311948       tbnd_prec(1:slab_size,:) = time_bounds(position_slab(1):position_slab(2),timeid_precip,:) 
    1932        prectime(1:slab_size) = preciptime(position_slab(1):position_slab(2)) 
    19331949       ! 
    19341950       WRITE(*,*) "For SWdown we are using time axis '",TRIM(time_axename(timeid_swdown)),& 
     
    32533269!_ ============================================================================================================================== 
    32543270 
    3255   SUBROUTINE forcing_zoomgrid (zoom_lon, zoom_lat, filename, dumpncdf) 
     3271  SUBROUTINE forcing_zoomgrid (zoom_lon, zoom_lat, filename,model_guess, dumpncdf) 
    32563272    ! 
    32573273    ! Get the area to be zoomed and the sizes of arrays we will need. 
     
    32623278    ! 
    32633279    REAL(r_std), DIMENSION(2), INTENT(in) :: zoom_lon, zoom_lat 
    3264     CHARACTER(LEN=*), INTENT(in) :: filename 
     3280    CHARACTER(LEN=*), INTENT(in) :: filename,  model_guess  
    32653281    LOGICAL, INTENT(in) :: dumpncdf 
    32663282    ! 
     
    32733289    REAL(r_std), ALLOCATABLE, DIMENSION(:) :: lon_val, lat_val 
    32743290    INTEGER(i_std), ALLOCATABLE, DIMENSION(:,:,:) :: zoom_index 
     3291    INTEGER(i_std),DIMENSION(2) ::  tmp_lon_ind1, tmp_lat_ind1, tmp_lon_ind2, tmp_lat_ind2  
     3292    INTEGER(i_std) :: iindex_init, jindex_init, iindex_end, jindex_end, i_orig, j_orig  
    32753293    ! 
    32763294    INTEGER(i_std) :: iret, force_id, iv 
     
    33213339    ! Determine the size in x and y of the zoom 
    33223340    ! 
    3323     IF ( zoom_forcing ) THEN 
     3341    lon_tmp(:) = 0.0  
     3342    lat_tmp(:) = 0.0  
     3343    IF ( zoom_forcing .AND. model_guess .EQ. 'WRF') THEN  
     3344       tmp_lon_ind1 = MINLOC(ABS(longlo_tmp(:,:)-zoom_lon(1)))  
     3345       tmp_lat_ind1 = MINLOC(ABS(lat_glo(:,:)-zoom_lat(1)))  
     3346        
     3347       tmp_lon_ind2 = MINLOC(ABS(longlo_tmp(:,:)-zoom_lon(2)))  
     3348       tmp_lat_ind2 = MINLOC(ABS(lat_glo(:,:)-zoom_lat(2)))  
     3349        
     3350       iindex_init = tmp_lon_ind1(1)  
     3351       jindex_init = tmp_lat_ind1(2)  
     3352                  
     3353       iindex_end= tmp_lon_ind2(1)  
     3354       jindex_end= tmp_lat_ind2(2)  
     3355        
     3356       lat_tmp(jindex_init:jindex_end) = 1.0  
     3357       lon_tmp(iindex_init:iindex_end) = 1.0  
     3358        
     3359       iim_loc = iindex_end - iindex_init +1  
     3360       jjm_loc = jindex_end - jindex_init +1  
     3361 
     3362    ELSE IF ( zoom_forcing  .AND. model_guess .EQ. 'regular') THEN  
    33243363       ! 
    33253364       ! Working with the hypothesis it is a regular global grid and bring it back to the -180 to 180 interval 
     
    33463385       jjm_loc = NINT(SUM(lat_tmp)) 
    33473386    ELSE 
     3387       iindex_init = 1  
     3388       jindex_init = 1  
     3389        
     3390       iindex_end= size(longlo_tmp(:,1))  
     3391       jindex_end= size(lat_glo(1,:))  
     3392 
    33483393       iim_loc = iim_glo 
    33493394       jjm_loc = jjm_glo 
     
    33833428    ! Now find the correspondance between the zoomed & re-ordered grid and the global one. 
    33843429    ! 
    3385     DO i=1,iim_loc 
    3386        DO j=1,jjm_loc 
    3387           ! 
    3388           imin=MINLOC(ABS(longlo_tmp(:,1)-lon_val(i))) 
    3389           jmin=MINLOC(ABS(lat_glo(1,:)-lat_val(j))) 
    3390           ! 
    3391           lon_loc(i,j) = longlo_tmp(imin(1),jmin(1)) 
    3392           lat_loc(i,j) = lat_glo(imin(1),jmin(1)) 
    3393           mask_loc(i,j) = mask_glo(imin(1),jmin(1)) 
    3394           ! 
    3395           zoom_index(i,j,1) = imin(1) 
    3396           zoom_index(i,j,2) = jmin(1) 
    3397           ! 
     3430    IF (model_guess .EQ. 'WRF' .AND.  zoom_forcing) THEN  
     3431       ! if WRF grid and zoomed grid, added a few lines here  
     3432       mask_loc(:,:) = mask_glo(iindex_init:iindex_end, jindex_init:jindex_end)  
     3433       lat_loc(:,:) = lat_glo(iindex_init:iindex_end, jindex_init:jindex_end)  
     3434       lon_loc(:,:) = longlo_tmp(iindex_init:iindex_end, jindex_init:jindex_end)  
     3435        
     3436        
     3437       nbpoint_loc = 0  
     3438       DO i=1,iim_loc  
     3439          DO j=1,jjm_loc  
     3440             zoom_index(i,j,1) = iindex_init + i - 1  
     3441             zoom_index(i,j,2) = jindex_init + j - 1  
     3442             ! this is consistent to glogrd_getwrf code  
     3443             if ( mask_loc(i,j) .GT. 0.5 ) THEN  
     3444                nbpoint_loc = nbpoint_loc +1  
     3445             ENDIF 
     3446          ENDDO 
    33983447       ENDDO 
    3399     ENDDO 
    3400     ! 
    3401     nbpoint_loc = SUM(mask_loc) 
     3448    
     3449   ELSE  
     3450      ! if regular grid, or wrf full grids:  
     3451      ! the orginal code, not modified  
     3452      DO i=1,iim_loc  
     3453         DO j=1,jjm_loc  
     3454            !  
     3455            imin=MINLOC(ABS(longlo_tmp(:,1)-lon_val(i)))  
     3456            jmin=MINLOC(ABS(lat_glo(1,:)-lat_val(j)))  
     3457            !  
     3458            lon_loc(i,j) = longlo_tmp(imin(1),jmin(1))  
     3459            lat_loc(i,j) = lat_glo(imin(1),jmin(1))  
     3460            mask_loc(i,j) = mask_glo(imin(1),jmin(1))  
     3461            !  
     3462            zoom_index(i,j,1) = imin(1)  
     3463            zoom_index(i,j,2) = jmin(1)  
     3464            !  
     3465         ENDDO 
     3466      ENDDO 
     3467      !  
     3468      nbpoint_loc = SUM(mask_loc)  
     3469       
     3470   ENDIF 
    34023471     
    34033472 
     
    34823551    ! Treat first the longitudes 
    34833552    ! 
    3484     DO j=1,jjm_loc 
    3485        dx = zero 
    3486        DO i=1,iim_loc-1 
    3487           dx = dx+ABS(lon_loc(i,j)-lon_loc(i+1,j)) 
     3553    IF ( model_guess .EQ. "WRF" ) THEN  
     3554       ! if grid is wrf  
     3555       !  
     3556       DO i=1,iim_loc  
     3557          DO j=1,jjm_loc  
     3558             i_orig = iindex_init + i - 1  
     3559             j_orig = jindex_init + j - 1  
     3560              
     3561             ! Corners  
     3562             CALL grid_tolola(i_orig+0.5, j_orig+0.5, corners_loc(i,j,1,1), corners_loc(i,j,1,2))  
     3563             CALL grid_tolola(i_orig+0.5, j_orig-0.5, corners_loc(i,j,2,1), corners_loc(i,j,2,2))  
     3564             CALL grid_tolola(i_orig-0.5, j_orig-0.5, corners_loc(i,j,3,1), corners_loc(i,j,3,2))  
     3565             CALL grid_tolola(i_orig-0.5, j_orig-0.5, corners_loc(i,j,4,1), corners_loc(i,j,4,2))  
     3566              
     3567             coslat = MAX( COS(lat_glo(i_orig,j_orig) * pi/180. ), mincos )  
     3568             dx = ABS(corners_loc(i,j,2,1) - corners_loc(i,j,1,1)) * pi/180. * R_Earth * coslat  
     3569             dy = ABS(corners_loc(i,j,1,2) - corners_loc(i,j,3,2)) * pi/180. * R_Earth  
     3570             area_loc(i,j) = dx*dy  
     3571          ENDDO 
    34883572       ENDDO 
    3489        dx = dx/(iim_loc-1) 
     3573 
     3574    ELSE  
     3575       ! if regular grid: original code, not modified  
     3576       ! Treat first the longitudes  
     3577       !  
     3578       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)  
     3584          DO i=1,iim_loc  
     3585             corners_loc(i,j,1,1) = lon_loc(i,j)-dx/2.0  
     3586             corners_loc(i,j,2,1) = lon_loc(i,j)+dx/2.0  
     3587             corners_loc(i,j,3,1) = lon_loc(i,j)+dx/2.0  
     3588             corners_loc(i,j,4,1) = lon_loc(i,j)-dx/2.0  
     3589          ENDDO 
     3590       ENDDO 
     3591       !  
     3592       ! Now treat the latitudes  
     3593       !  
    34903594       DO i=1,iim_loc 
    3491           corners_loc(i,j,1,1) = lon_loc(i,j)-dx/2.0 
    3492           corners_loc(i,j,2,1) = lon_loc(i,j)+dx/2.0 
    3493           corners_loc(i,j,3,1) = lon_loc(i,j)+dx/2.0 
    3494           corners_loc(i,j,4,1) = lon_loc(i,j)-dx/2.0 
     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)  
     3600          DO j=1,jjm_loc  
     3601             corners_loc(i,j,1,2) = lat_loc(i,j)+dy/2.0  
     3602             corners_loc(i,j,2,2) = lat_loc(i,j)+dy/2.0  
     3603             corners_loc(i,j,3,2) = lat_loc(i,j)-dy/2.0  
     3604             corners_loc(i,j,4,2) = lat_loc(i,j)-dy/2.0  
     3605          ENDDO 
    34953606       ENDDO 
    3496     ENDDO 
    3497     ! 
    3498     ! Now treat the latitudes 
    3499     ! 
    3500     DO i=1,iim_loc 
    3501        dy = zero 
    3502        DO j=1,jjm_loc-1 
    3503           dy = dy + ABS(lat_loc(i,j)-lat_loc(i,j+1)) 
     3607     
     3608       !  
     3609       ! Compute the areas of the grid (using the simplification that the grid is regular in lon/lat).  
     3610       !  
     3611       DO i=1,iim_loc  
     3612          DO j=1,jjm_loc  
     3613             coslat = MAX( COS(lat_loc(i,j) * pi/180. ), mincos )  
     3614             dx = ABS(corners_loc(i,j,2,1) - corners_loc(i,j,1,1)) * pi/180. * R_Earth * coslat  
     3615             dy = ABS(corners_loc(i,j,1,2) - corners_loc(i,j,3,2)) * pi/180. * R_Earth  
     3616             area_loc(i,j) = dx*dy  
     3617          ENDDO 
    35043618       ENDDO 
    3505        dy = dy/(jjm_loc-1) 
    3506        DO j=1,jjm_loc 
    3507           corners_loc(i,j,1,2) = lat_loc(i,j)+dy/2.0 
    3508           corners_loc(i,j,2,2) = lat_loc(i,j)+dy/2.0 
    3509           corners_loc(i,j,3,2) = lat_loc(i,j)-dy/2.0 
    3510           corners_loc(i,j,4,2) = lat_loc(i,j)-dy/2.0 
    3511        ENDDO 
    3512     ENDDO 
    3513     ! 
    3514     ! Compute the areas of the grid (using the simplification that the grid is regular in lon/lat). 
    3515     ! 
    3516     DO i=1,iim_loc 
    3517        DO j=1,jjm_loc 
    3518           coslat = MAX( COS(lat_loc(i,j) * pi/180. ), mincos ) 
    3519           dx = ABS(corners_loc(i,j,2,1) - corners_loc(i,j,1,1)) * pi/180. * R_Earth * coslat 
    3520           dy = ABS(corners_loc(i,j,1,2) - corners_loc(i,j,3,2)) * pi/180. * R_Earth 
    3521           area_loc(i,j) = dx*dy 
    3522        ENDDO 
    3523     ENDDO 
     3619        
     3620    ENDIF 
     3621 
    35243622    ! 
    35253623    ! If requested we read a variable, zoomin and dump the result into a test file. 
     
    40114109  ALLOCATE(time(nb_forcing_steps, nbtax*nbtmethods), time_bounds(nb_forcing_steps,nbtax*nbtmethods,2)) 
    40124110  ALLOCATE(time_axename(nbtax*nbtmethods), time_cellmethod(nbtax*nbtmethods)) 
    4013   ALLOCATE(preciptime(nb_forcing_steps)) 
    40144111  ALLOCATE(time_sourcefile(nb_forcing_steps)) 
    40154112  ALLOCATE(time_id(nb_forcing_steps, nbtax)) 
     
    42624359  ENDDO 
    42634360  ! 
    4264   ! Set to zero the variable for the cummulated time for rainfall 
    4265   ! 
    4266   preciptime(:) = zero 
    42674361  ! 
    42684362  ! Keep the very first date of the time axis for future use 
  • branches/ORCHIDEE_2_2/ORCHIDEE/src_driver/globgrd.f90

    r7261 r7796  
    8080    ! 
    8181    INTEGER(i_std) :: iret, ndims, nvars, nb_atts, id_unlim, iv, lll 
     82    INTEGER(i_std) :: iindex_init, jindex_init, iindex_end, jindex_end 
    8283    INTEGER(i_std) :: iim_full, jjm_full, nbland_full 
    8384    CHARACTER(LEN=20) :: axname, varname 
    8485    CHARACTER(LEN=120) :: tmpfile 
    8586    REAL(r_std), DIMENSION(2) :: loczoom_lon, loczoom_lat 
    86     REAL(r_std), ALLOCATABLE, DIMENSION(:,:) :: mask 
     87    INTEGER(i_std), DIMENSION(2) :: tmp_lon_ind1, tmp_lat_ind1, tmp_lon_ind2, tmp_lat_ind2  
     88    REAL(r_std), ALLOCATABLE, DIMENSION(:,:) :: mask,zoom_mask, lat, lon  
    8789    ! 
    8890    ! Set default values against which we can test 
     
    9294    ! 
    9395    ! Verify the grid file name 
     96    ! if forcing_file exists and if grid file exists: tmpfile = grid file  
     97    ! if forcing_file exits and grid file not exists: tmpfile = forcing_file  
     98    ! if forcing_file not exists: tmp_file= grid file  
    9499    !  
    95     IF ( INDEX(filename,"NONE") >= 1 ) THEN 
     100    IF ( PRESENT(forcingfile) ) THEN 
    96101       is_forcing_file=.TRUE. 
    97        IF ( PRESENT(forcingfile) ) THEN 
     102       IF ( INDEX(filename,"NONE") >= 1 ) THEN 
    98103          tmpfile=forcingfile(1) 
    99104       ELSE 
    100           CALL ipslerr (3,'globgrd_getdomsz',"Error No grid file provided :",tmpfile, " ") 
     105          tmpfile=filename 
    101106       ENDIF 
    102107    ELSE 
     
    105110    ENDIF 
    106111    ! 
    107     ! Verify that the zomm is provided. Else choose the entire globe 
     112    ! Verify that the zoomed region is provided. Else choose the entire globe 
    108113    ! 
    109114    IF ( PRESENT(zoom_lon) .AND. PRESENT(zoom_lat) ) THEN 
     
    144149          !! Coordinate variables used by WRF. 
    145150       CASE("west_east") 
    146           iim = lll 
     151          iim_full = lll 
    147152          model_guess = "WRF" 
    148153       CASE("south_north") 
    149           jjm = lll 
     154          jjm_full = lll 
    150155          model_guess = "WRF" 
    151156          ! 
    152157          !! Variables used in WFDEI 
    153158       CASE("lon") 
    154           iim = lll 
     159          iim_full = lll 
    155160          model_guess = "regular" 
    156161       CASE("lat") 
    157           jjm = lll 
     162          jjm_full = lll 
    158163          model_guess = "regular" 
    159164       CASE("nbland") 
    160           nbland = lll 
     165          nbland_full = lll 
    161166          ! 
    162167          !! Variables used by CRU-NCEP 
    163168       CASE("nav_lon") 
    164           iim = lll 
     169          iim_full = lll 
    165170          model_guess = "regular" 
    166171       CASE("nav_lat") 
    167           jjm = lll 
     172          jjm_full = lll 
    168173          model_guess = "regular" 
    169174       CASE("land") 
    170           nbland = lll 
     175          nbland_full = lll 
     176 
     177        
     178          !! Variables used by CRU-JRA (v2.2.2)  
     179       CASE("longitude")  
     180          iim_full = lll  
     181          model_guess = "regular"  
     182       CASE("latitude")  
     183          jjm_full = lll  
     184          model_guess = "regular"  
    171185       END SELECT 
    172186    ENDDO 
    173187    ! 
    174     ! If we have a WRF file we need to count the number of land points. 
     188    ! If we have a WRF file we need to count the number of land points,  define iim jjm and mask  
    175189    ! 
    176190    IF (  model_guess == "WRF" ) THEN 
    177191 
    178        ALLOCATE(mask(iim,jjm)) 
     192       IF ( .NOT. ALLOCATED(mask) ) ALLOCATE(mask(iim_full,jjm_full))  
    179193 
    180194       varname = "LANDMASK" 
     
    186200       ENDIF 
    187201 
    188        nbland = COUNT(mask > 0.5) 
    189  
    190     ENDIF 
    191     ! 
    192     ! 
    193     ! If we are in the case of a forcing file a few functions from forcing_tools need to be called 
     202       nbland_full = COUNT(mask > 0.5)  
     203        
     204        
     205       IF ( .NOT. ALLOCATED(lat)) ALLOCATE(lat(iim_full,jjm_full))  
     206       IF ( .NOT. ALLOCATED(lon)) ALLOCATE(lon(iim_full,jjm_full))  
     207        
     208       varname = "XLONG_M"  
     209       iret = NF90_INQ_VARID (fid, varname, iv)  
     210       IF (iret /= NF90_NOERR) THEN  
     211          CALL ipslerr (3,'globgrd_getdomsz',"Could not find variable ", varname," ")  
     212       ELSE  
     213          iret = NF90_GET_VAR (fid,iv,lon)  
     214       ENDIF 
     215        
     216       varname = "XLAT_M"  
     217       iret = NF90_INQ_VARID (fid, varname, iv)  
     218       IF (iret /= NF90_NOERR) THEN  
     219          CALL ipslerr (3,'globgrd_getdomsz',"Could not find variable ", varname," ")  
     220       ELSE  
     221          iret = NF90_GET_VAR (fid,iv,lat)  
     222       ENDIF 
     223        
     224       !define nbland for full-region simulation in case of need  
     225       nbland = nbland_full  
     226        
     227    ENDIF 
     228    !  
     229    !  
     230    ! If we are in the case of a forcing file and model_guess is regular grid,  
     231    ! then a few functions from forcing_tools need to be called  
    194232    ! so that the file is analysed with the tools of the forcing module. 
    195233    ! 
    196     IF ( is_forcing_file ) THEN 
     234    ! predefine nbland, iim, jjm in the case is_forcing_file=false, or full grid simulation for wrf  
     235    iim = iim_full  
     236    jjm = jjm_full  
     237    IF ( is_forcing_file .AND. model_guess .EQ. "regular") THEN  
    197238       ! 
    198239       ! Because we are re-using routines from the forcing module, we have to 
     
    204245       ENDIF 
    205246       ! 
    206        ! This has to be a regular grid. A more clever clasification of files will be needed. 
    207        model_guess = "regular" 
    208  
    209247       ! Set last argument closefile=.FALSE. as the forcing file has been closed here above.  
    210248       ! This will also induce that dump_mask=.FALSE. in forcing_getglogrid and the 
     
    213251       WRITE(*,*) forcingfile, "Forcing file with dimensions : ", iim_full, jjm_full, nbland_full 
    214252       ! 
    215        CALL forcing_zoomgrid (loczoom_lon, loczoom_lat, forcingfile(1), .TRUE.) 
     253       CALL forcing_zoomgrid (loczoom_lon, loczoom_lat, forcingfile(1), model_guess, .TRUE.)   
    216254       ! 
    217255       CALL forcing_givegridsize (iim, jjm, nbland) 
    218256       ! 
     257 
     258    ELSE IF ( is_forcing_file .AND. model_guess .EQ. "WRF") THEN  
     259       !  
     260       ! if forcing_file exists and model_guess is wrf, and zoomed domain is asked,  
     261       ! then we define the domain size according to the zoom  
     262       ! if the full domain is asked, then we do not define the domain size again here.  
     263       !  
     264       ! get the beginning and endding index in the case of zoomed region, for WRF grids (XW)  
     265       ! Not to close the grid file here, to be used by globgrd_getgrid  
     266       !  
     267       !IF ( PRESENT(zoom_lon) .AND. PRESENT(zoom_lat) ) THEN  
     268       IF ( PRESENT(zoom_lon) .OR. PRESENT(zoom_lat) ) THEN  
     269           
     270          ! to get new iim, jjm and nbland for the zoomed region  
     271          tmp_lon_ind1 = MINLOC(ABS(lon(:,:)-loczoom_lon(1)))  
     272          tmp_lat_ind1 = MINLOC(ABS(lat(:,:)-loczoom_lat(1)))  
     273          tmp_lon_ind2 = MINLOC(ABS(lon(:,:)-loczoom_lon(2)))  
     274          tmp_lat_ind2 = MINLOC(ABS(lat(:,:)-loczoom_lat(2)))  
     275          !  
     276          ! the zoomed region  
     277          ! lon1, lat2------- lon2,lat2  
     278          !   |                   |  
     279          ! lon1, lat1------- lon2,lat1  
     280          !  
     281          iindex_init = tmp_lon_ind1(1)  
     282          jindex_init= tmp_lat_ind1(2)  
     283           
     284          iindex_end= tmp_lon_ind2(1)  
     285          jindex_end= tmp_lat_ind2(2)  
     286           
     287          iim = iindex_end - iindex_init + 1  
     288          jjm = jindex_end - jindex_init + 1  
     289           
     290           
     291          IF ( .NOT. ALLOCATED(zoom_mask) ) ALLOCATE(zoom_mask(iim,jjm))  
     292          zoom_mask = mask(iindex_init:iindex_end, jindex_init:jindex_end)  
     293          nbland = COUNT(zoom_mask > 0.5)  
     294          IF ( ALLOCATED(zoom_mask) ) DEALLOCATE(zoom_mask)  
     295           
     296       ENDIF 
     297        
     298       IF ( ALLOCATED(lat) ) DEALLOCATE(lat)  
     299       IF ( ALLOCATED(lon) ) DEALLOCATE(lon)  
     300       IF ( ALLOCATED(mask) ) DEALLOCATE(mask)  
     301 
    219302    ENDIF 
    220303    ! 
     
    250333  !--------------------------------------------------------------------- 
    251334  SUBROUTINE globgrd_getgrid(fid, iim, jjm, nbland, model_guess, lon, lat, mask, area, corners, & 
    252        &                     lindex, contfrac, calendar) 
     335       &                     lindex, contfrac, calendar, zoom_lon, zoom_lat) 
    253336    ! 
    254337    ! 
     
    262345    INTEGER(i_std), INTENT(in)   :: iim, jjm, nbland 
    263346    CHARACTER(LEN=*), INTENT(in) :: model_guess 
     347    REAL(r_std), DIMENSION(2), INTENT(in), OPTIONAL :: zoom_lon, zoom_lat 
    264348    ! 
    265349    ! OUTPUT 
     
    275359    CASE("WRF") 
    276360       CALL globgrd_getwrf(fid, iim, jjm, nbland, lon, lat, mask, area, corners, & 
    277             &               lindex, contfrac, calendar) 
     361            &               lindex, contfrac, calendar, zoom_lon, zoom_lat) 
    278362    CASE("regular") 
    279363       IF ( .NOT. is_forcing_file ) THEN 
     
    482566!! 
    483567  SUBROUTINE globgrd_getwrf(fid, iim, jjm, nbland, lon, lat, mask, area, corners, & 
    484        &                     lindex, contfrac, calendar) 
     568       &                     lindex, contfrac, calendar, zoom_lon, zoom_lat) 
    485569    ! 
    486570    USE defprec 
     
    491575    INTEGER(i_std), INTENT(in)   :: fid 
    492576    INTEGER(i_std), INTENT(in)   :: iim, jjm, nbland 
     577    REAL(r_std), DIMENSION(2), INTENT(in), OPTIONAL :: zoom_lon, zoom_lat 
    493578    ! 
    494579    ! OUTPUT 
     
    503588    ! 
    504589    INTEGER(i_std) :: i, ip, jp, k, iret, iv, nvars, varndim 
    505     INTEGER(i_std) :: imm1, imp1 
     590    INTEGER(i_std),DIMENSION(2) ::  tmp_lon_ind1, tmp_lat_ind1, tmp_lon_ind2, tmp_lat_ind2  
     591    REAL(r_std), DIMENSION(2) :: loczoom_lon, loczoom_lat  
     592    INTEGER(i_std) ::  ndims, nb_atts, id_unlim, lll, iim_full, jjm_full, iim_tmp, jjm_tmp  
     593    INTEGER(i_std) :: iindex_init, jindex_init, iindex_end, jindex_end, i_orig, j_orig  
    506594    CHARACTER(LEN=20) :: varname 
    507     REAL(r_std),DIMENSION(iim,jjm) :: mapfac_x, mapfac_y 
     595     
    508596    INTEGER(i_std), DIMENSION(4) :: vardims 
    509597    INTEGER(i_std), DIMENSION(8) :: rose 
    510598    ! 
     599    REAL(r_std), ALLOCATABLE, DIMENSION(:,:) :: mask_full, lon_full, lat_full, area_full  
     600    REAL(r_std),ALLOCATABLE, DIMENSION(:,:) :: mapfac_x_full, mapfac_y_full  
     601    CHARACTER(LEN=20) :: axname  
     602    REAL(r_std) :: dx, dy, coslat  
     603    !  
     604    REAL(r_std), PARAMETER :: mincos  = 0.0001  
     605    REAL(r_std), PARAMETER :: pi = 3.141592653589793238  
     606    REAL(r_std), PARAMETER :: R_Earth = 6378000.  
     607    !  
     608    ! A lot of modifications are added to this subroutine (XW)  
    511609    ! 
    512610    ! Set some default values agains which we can check  
     
    523621    calendar = 'gregorian' 
    524622    ! 
     623    ! get dimension of full-grid data   
     624    !  
     625    iret = NF90_INQUIRE (fid, nDimensions=ndims, nVariables=nvars, &  
     626         nAttributes=nb_atts, unlimitedDimId=id_unlim)  
     627    !  
     628    DO iv=1,ndims  
     629       !  
     630       iret = NF90_INQUIRE_DIMENSION (fid, iv, name=axname, len=lll)  
     631       IF (iret /= NF90_NOERR) THEN  
     632          CALL ipslerr (3,'globgrd_getdomsz',"Could not get size of dimension :"," "," ")  
     633       ENDIF 
     634       !  
     635       ! This can be refined by testing the actual grid found in the file.  
     636       !  
     637       SELECT CASE(axname)  
     638          !  
     639          !! Coordinate variables used by WRF.  
     640       CASE("west_east")  
     641          iim_full = lll  
     642           
     643       CASE("south_north")  
     644          jjm_full = lll  
     645           
     646       END SELECT 
     647    ENDDO 
     648 
    525649    ! 
    526650    !  Init projection in grid.f90 so that it can be used later for projections. 
    527651    ! 
    528     CALL grid_initproj(fid, iim, jjm) 
     652    CALL grid_initproj(fid, iim_full, jjm_full) 
    529653    ! 
    530654    iret = NF90_INQUIRE (fid, nVariables=nvars) 
     
    533657       CALL ipslerr (3,'globgrd_getwrf',"Error inquiering variables from WRF grid file."," ", " ") 
    534658    ENDIF 
     659    IF ( .NOT. ALLOCATED(lon_full) ) ALLOCATE(lon_full(iim_full,jjm_full))  
     660    IF ( .NOT. ALLOCATED(lat_full) ) ALLOCATE(lat_full(iim_full,jjm_full))  
     661    IF ( .NOT. ALLOCATED(mask_full) ) ALLOCATE(mask_full(iim_full,jjm_full))  
     662    IF ( .NOT. ALLOCATED(mapfac_x_full) ) ALLOCATE(mapfac_x_full(iim_full,jjm_full))  
     663    IF ( .NOT. ALLOCATED(mapfac_y_full) ) ALLOCATE(mapfac_y_full(iim_full,jjm_full))  
    535664    ! 
    536665    DO iv = 1,nvars 
     
    541670       ! 
    542671       CASE("XLONG_M") 
    543           iret = NF90_GET_VAR(fid, iv, lon) 
     672          iret = NF90_GET_VAR(fid, iv, lon_full) 
    544673          IF (iret /= NF90_NOERR) THEN 
    545674             CALL ipslerr (3,'globgrd_getwrf',"Could not read the longitude from the WRF grid file.", " ", " ") 
    546675          ENDIF 
    547676       CASE("XLAT_M") 
    548           iret = NF90_GET_VAR(fid, iv, lat) 
     677          iret = NF90_GET_VAR(fid, iv, lat_full) 
    549678          IF (iret /= NF90_NOERR) THEN 
    550679             CALL ipslerr (3,'globgrd_getwrf',"Could not read the latitude from the WRF grid file.", " ", " ") 
    551680          ENDIF 
    552681       CASE("LANDMASK") 
    553           iret = NF90_GET_VAR(fid, iv, mask) 
     682          iret = NF90_GET_VAR(fid, iv, mask_full) 
    554683          IF (iret /= NF90_NOERR) THEN 
    555684             CALL ipslerr (3,'globgrd_getwrf',"Could not read the land mask from the WRF grid file.", " ", " ") 
    556685          ENDIF 
    557686       CASE("MAPFAC_MX") 
    558           iret = NF90_GET_VAR(fid, iv, mapfac_x) 
     687          iret = NF90_GET_VAR(fid, iv, mapfac_x_full) 
    559688          IF (iret /= NF90_NOERR) THEN 
    560689             CALL ipslerr (3,'globgrd_getwrf',"Could not read the land mask from the WRF grid file.", " ", " ") 
    561690          ENDIF 
    562691       CASE("MAPFAC_MY") 
    563           iret = NF90_GET_VAR(fid, iv, mapfac_y) 
     692          iret = NF90_GET_VAR(fid, iv, mapfac_y_full) 
    564693          IF (iret /= NF90_NOERR) THEN 
    565694             CALL ipslerr (3,'globgrd_getwrf',"Could not read the land mask from the WRF grid file.", " ", " ") 
     
    569698    ENDDO 
    570699    ! 
    571     ! Compute corners and area on the iimxjjm grid 
    572     ! 
     700    IF ( PRESENT(zoom_lon) .AND. PRESENT(zoom_lat) ) THEN   
     701       !   
     702       ! if zoomed region  
     703       !  
     704       loczoom_lon = zoom_lon  
     705       loczoom_lat = zoom_lat  
     706        
     707        
     708       ! to get new iim, jjm and nbland for the zoomed region  
     709       ! tmp_lon_ind1, tmp_lat_ind1 etc: dimension(2),   
     710       ! with the first one for longitude, second one for latitude  
     711       tmp_lon_ind1 = MINLOC(ABS(lon_full(:,:)-loczoom_lon(1)))  
     712       tmp_lat_ind1 = MINLOC(ABS(lat_full(:,:)-loczoom_lat(1)))  
     713        
     714       tmp_lon_ind2 = MINLOC(ABS(lon_full(:,:)-loczoom_lon(2)))  
     715       tmp_lat_ind2 = MINLOC(ABS(lat_full(:,:)-loczoom_lat(2)))  
     716       !  
     717       ! get indices for the zoomed region  
     718       ! lon1, lat2------- lon2,lat2  
     719       !   |                   |  
     720       ! lon1, lat1------- lon2,lat1  
     721       !  
     722       iindex_init = tmp_lon_ind1(1)  
     723       jindex_init = tmp_lat_ind1(2)  
     724        
     725       iindex_end= tmp_lon_ind2(1)  
     726       jindex_end= tmp_lat_ind2(2)  
     727        
     728       ! allocate variable values for the zoomed region  
     729       mask(:,:) = mask_full(iindex_init:iindex_end, jindex_init:jindex_end)  
     730       lat(:,:) = lat_full(iindex_init:iindex_end, jindex_init:jindex_end)  
     731       lon(:,:) = lon_full(iindex_init:iindex_end, jindex_init:jindex_end)  
     732        
     733       iim_tmp = iindex_end - iindex_init +1  
     734       jjm_tmp = jindex_end - jindex_init +1  
     735        
     736        
     737    ELSE  
     738       !  
     739       ! if full grids  
     740       !  
     741       iindex_init = 1  
     742       jindex_init = 1   
     743        
     744       ! define variable values for full grids  
     745       lat(:,:) = lat_full(:,:)  
     746       lon(:,:) = lon_full(:,:)  
     747       mask(:,:) = mask_full(:,:)  
     748        
     749    ENDIF                       
     750    !  
     751    ! Compute corners on the iimxjjm full or zoomed grid  
    573752    DO ip=1,iim 
    574753       DO jp=1,jjm 
     754          i_orig = iindex_init + ip - 1  
     755          j_orig = jindex_init + jp - 1  
    575756          ! Corners 
    576           CALL grid_tolola(ip+0.5, jp+0.5, corners(ip,jp,1,1), corners(ip,jp,1,2)) 
    577           CALL grid_tolola(ip+0.5, jp-0.5, corners(ip,jp,2,1), corners(ip,jp,2,2)) 
    578           CALL grid_tolola(ip-0.5, jp-0.5, corners(ip,jp,3,1), corners(ip,jp,3,2)) 
    579           CALL grid_tolola(ip-0.5, jp-0.5, corners(ip,jp,4,1), corners(ip,jp,4,2)) 
     757          CALL grid_tolola(i_orig+0.5, j_orig+0.5, corners(ip,jp,1,1), corners(ip,jp,1,2))  
     758          CALL grid_tolola(i_orig+0.5, j_orig-0.5, corners(ip,jp,2,1), corners(ip,jp,2,2))  
     759          CALL grid_tolola(i_orig-0.5, j_orig-0.5, corners(ip,jp,3,1), corners(ip,jp,3,2))  
     760          CALL grid_tolola(i_orig-0.5, j_orig-0.5, corners(ip,jp,4,1), corners(ip,jp,4,2))  
    580761          ! 
    581762       ENDDO 
    582763    ENDDO 
    583764    ! 
    584     ! Compute resolution and area on the gathered grid 
     765    ! Compute resolution and area on the gathered, full or zoomed grid  
    585766    ! 
    586767    k=0 
     
    588769    DO jp=1,jjm 
    589770       DO ip=1,iim 
     771          !  
     772          !get the right index of zoomed/full region in the original grids  
     773          !  
     774          i_orig = iindex_init + ip - 1  
     775          j_orig = jindex_init + jp - 1  
     776          !  
     777          !  
     778          ! compute area  
     779          coslat = MAX( COS(lat_full(i_orig,j_orig) * pi/180. ), mincos )  
     780          dx = ABS(corners(ip,jp,2,1) - corners(ip,jp,1,1)) * pi/180. * R_Earth * coslat  
     781          dy = ABS(corners(ip,jp,1,2) - corners(ip,jp,3,2)) * pi/180. * R_Earth  
     782          area(ip,jp) = dx*dy  
     783          !  
     784          ! compute index and contfrac  
    590785          IF ( mask(ip,jp) > 0.5 ) THEN 
    591786             ! 
     787             ! index of the points in the local zoomed grid  
    592788             k=k+1 
    593789             lindex(k) = (jp-1)*iim+ip  
     
    602798       CALL ipslerr (3,'globgrd_getwrf',"Error closing the WRF grid file :", " ", " ") 
    603799    ENDIF 
     800    IF ( ALLOCATED(lon_full) ) DEALLOCATE(lon_full)  
     801    IF ( ALLOCATED(lat_full) ) DEALLOCATE(lat_full)  
     802    IF ( ALLOCATED(mask_full) ) DEALLOCATE(mask_full)  
     803    IF ( ALLOCATED(mapfac_x_full) ) DEALLOCATE(mapfac_x_full)  
     804    IF ( ALLOCATED(mapfac_y_full) ) DEALLOCATE(mapfac_y_full)  
     805     
    604806    ! 
    605807  END SUBROUTINE globgrd_getwrf 
  • branches/ORCHIDEE_2_2/ORCHIDEE/src_driver/orchideedriver.f90

    r7265 r7796  
    2626!================================================================================================================================ 
    2727!  
    28 PROGRAM orchidedriver 
     28PROGRAM orchideedriver 
    2929  !--------------------------------------------------------------------- 
    3030  !- 
     
    159159  ! Case when no ouput is desired. 
    160160  REAL(r_std), DIMENSION(2) :: testpt=(/9999.99,9999.99/) 
    161   INTEGER(i_std) :: ktest 
     161  INTEGER(i_std) :: ktest,alloc_stat  
    162162  INTEGER :: printlev_loc  !! local write level 
    163163 
     
    329329  !- Allocation of memory 
    330330  !- variables over the entire grid (thus in x,y) 
    331   ALLOCATE(lon_glo(iim_glo, jjm_glo)) 
    332   ALLOCATE(lat_glo(iim_glo, jjm_glo)) 
    333   ALLOCATE(mask_glo(iim_glo, jjm_glo)) 
    334   ALLOCATE(area_glo(iim_glo, jjm_glo)) 
    335   ALLOCATE(corners_glo(iim_glo, jjm_glo, nbseg, 2)) 
     331  ALLOCATE(lon_glo(iim_glo, jjm_glo),stat=alloc_stat)  
     332  ALLOCATE(lat_glo(iim_glo, jjm_glo),stat=alloc_stat)  
     333  ALLOCATE(mask_glo(iim_glo, jjm_glo),stat=alloc_stat)  
     334  ALLOCATE(area_glo(iim_glo, jjm_glo),stat=alloc_stat)  
     335  ALLOCATE(corners_glo(iim_glo, jjm_glo, nbseg, 2),stat=alloc_stat)  
    336336  ! 
    337337  ! Gathered variables 
    338   ALLOCATE(kindex_g(nbindex_g)) 
    339   ALLOCATE(contfrac_glo(nbindex_g)) 
    340   !- 
     338  ALLOCATE(kindex_g(nbindex_g), stat=alloc_stat) 
     339  ALLOCATE(contfrac_glo(nbindex_g), stat=alloc_stat) 
     340  !--kindex_g: index of points in zoomed grids (if simulate zoomed region), or in full grids, both in case of regular grids  
    341341  IF ( is_root_prc) THEN 
    342342     CALL globgrd_getgrid(file_id, iim_glo, jjm_glo, nbindex_g, model_guess, & 
    343343          &               lon_glo, lat_glo, mask_glo, area_glo, corners_glo,& 
    344           &               kindex_g, contfrac_glo, calendar) 
     344          &               kindex_g, contfrac_glo, calendar,  zoom_lon, zoom_lat) 
    345345  ENDIF 
    346346   
     
    356356  CALL bcast(model_guess) 
    357357  ! 
    358   ALLOCATE(lalo_glo(nbindex_g,2)) 
     358  ALLOCATE(lalo_glo(nbindex_g,2), stat=alloc_stat) 
    359359  DO ik=1,nbindex_g 
    360360     ! 
     
    386386  !- 
    387387  CALL grid_set_glo(iim_glo, jjm_glo, nbindex_g) 
    388    
     388  CALL grid_allocate_glo(nbseg)  
    389389 
    390   CALL grid_allocate_glo(nbseg) 
    391390  ! Copy the list of indexes of land points into index_g used by ORCHIDEE and then broacast to all 
    392391  ! processors 
     
    397396  WRITE(numout,*) "Rank", mpi_rank, "Into Init_orchidee_data_para_driver with ", nbindex_g 
    398397  WRITE(numout,*) "Rank", mpi_rank, "Into ", index_g(1), index_g(nbindex_g) 
     398  CALL flush(numout)  
    399399  ! 
    400400  CALL Init_orchidee_data_para_driver(nbindex_g,index_g) 
     
    406406  ! Allocate grid on the local processor 
    407407  ! 
     408  CALL flush(numout)  
     409  !  
     410  ! Allocate grid varibles on the local processor by using nbp_loc:   
     411  ! variables are: lalo, corners, area, neighbours, contfrac etc, with save attributes  
     412  ! but these variables are not really used in the later parts of code.  
     413  !   
    408414  IF ( model_guess == "regular") THEN 
    409415     CALL grid_init (nbp_loc, nbseg, regular_lonlat, "ForcingGrid") 
     
    433439  ! 
    434440  WRITE(numout,*) mpi_rank, "DIMENSIONS of grid on processor : iim, jjm, kjpindex = ", iim, jjm, kjpindex 
     441  CALL flush(numout)  
    435442  ! 
    436443  !  Allocate the local arrays we need : 
     
    498505  ! 
    499506  CALL forcing_open(forfilename, iim_glo,  jjm_glo, lon_glo, lat_glo, nbindex_g, zoom_lon, zoom_lat, & 
    500        &            index_g, kjpindex, numout) 
     507       &            index_g, kjpindex, numout,  model_guess) 
    501508  ! 
    502509  !- 
     
    972979  END SUBROUTINE orchideedriver_clear 
    973980  ! 
    974 END PROGRAM orchidedriver 
     981END PROGRAM orchideedriver 
Note: See TracChangeset for help on using the changeset viewer.