diff --git a/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/Raster/makebcs/CMakeLists.txt b/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/Raster/makebcs/CMakeLists.txt index bd8458931..b08bc424b 100755 --- a/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/Raster/makebcs/CMakeLists.txt +++ b/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/Raster/makebcs/CMakeLists.txt @@ -11,18 +11,10 @@ zip.c util.c ) -if(NOT FORTRAN_COMPILER_SUPPORTS_FINDLOC) - list(APPEND srcs findloc.F90) -endif () - set_source_files_properties(mkMITAquaRaster.F90 PROPERTIES COMPILE_FLAGS "${BYTERECLEN}") esma_add_library(${this} SRCS ${srcs} DEPENDENCIES MAPL GEOS_SurfaceShared GEOS_LandShared ESMF::ESMF NetCDF::NetCDF_Fortran OpenMP::OpenMP_Fortran) -if(NOT FORTRAN_COMPILER_SUPPORTS_FINDLOC) - target_compile_definitions(${this} PRIVATE USE_EXTERNAL_FINDLOC) -endif () - # MAT NOTE This should use find_package(ZLIB) but Baselibs currently # confuses find_package(). This is a hack until Baselibs is # reorganized. diff --git a/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/Raster/makebcs/findloc.F90 b/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/Raster/makebcs/findloc.F90 deleted file mode 100644 index ef22a99fd..000000000 --- a/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/Raster/makebcs/findloc.F90 +++ /dev/null @@ -1,30 +0,0 @@ -module findloc_mod - - implicit none - - private - public :: findloc - - contains - - function findloc(array, value) - - integer, intent(in) :: array(:) - integer, intent(in) :: value - integer :: findloc(1) - - integer :: num_elements, i - - num_elements = size(array) - - findloc(1) = 0 - do i = 1, num_elements - if (array(i) == value) then - findloc(1) = i - exit - endif - end do - - end function findloc - -end module findloc_mod diff --git a/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/Raster/makebcs/mod_process_hres_data.F90 b/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/Raster/makebcs/mod_process_hres_data.F90 index 6300fdebd..c9c5c3604 100644 --- a/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/Raster/makebcs/mod_process_hres_data.F90 +++ b/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/Raster/makebcs/mod_process_hres_data.F90 @@ -31,10 +31,6 @@ MODULE process_hres_data use lsm_routines, ONLY: sibalb use LogRectRasterizeMod, ONLY: SRTM_maxcat -#if defined USE_EXTERNAL_FINDLOC - use findloc_mod, only: findloc -#endif - implicit none include 'netcdf.inc' diff --git a/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/CMakeLists.txt b/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/CMakeLists.txt index 6c63bfa05..4af3b5863 100644 --- a/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/CMakeLists.txt +++ b/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/CMakeLists.txt @@ -7,17 +7,12 @@ set(srcs ) set (exe_srcs - Scale_Catch.F90 - Scale_CatchCN.F90 cv_SaltRestart.F90 SaltIntSplitter.F90 SaltImpConverter.F90 mk_CICERestart.F90 - mk_CatchCNRestarts.F90 - mk_CatchRestarts.F90 mk_LakeLandiceSaltRestarts.F90 mk_RouteRestarts.F90 - mk_GEOSldasRestarts.F90 mk_catchANDcnRestarts.F90 ) @@ -33,7 +28,6 @@ foreach (src ${exe_srcs}) LIBS MAPL GFTL_SHARED::gftl-shared GEOS_SurfaceShared GEOSroute_GridComp GEOS_LandShared GEOS_CatchCNShared ${this}) endforeach () -install(PROGRAMS mk_Restarts DESTINATION bin) foreach (src ${exe_srcs}) string (REGEX REPLACE ".F90" ".x" exe ${src}) string (REGEX REPLACE ".F90" "" lname ${src}) diff --git a/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/Scale_Catch.F90 b/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/Scale_Catch.F90 deleted file mode 100644 index f79225031..000000000 --- a/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/Scale_Catch.F90 +++ /dev/null @@ -1,728 +0,0 @@ -#define I_AM_MAIN -#include "MAPL_Generic.h" - -program Scale_Catch - - use MAPL - - use LSM_ROUTINES, ONLY: & - catch_calc_soil_moist, & - catch_calc_tp, & - catch_calc_ght - - USE CATCH_CONSTANTS, ONLY: & - N_GT => CATCH_N_GT, & - DZGT => CATCH_DZGT, & - PEATCLSM_POROS_THRESHOLD - - implicit none - - character(256) :: fname1, fname2, fname3 -#ifndef __GFORTRAN__ - integer :: ftell - external :: ftell -#endif - integer :: bpos, epos, ntiles, n, nargs - integer :: old, new, sca - integer :: iargc - real :: SURFLAY ! (Ganymed-3 and earlier) SURFLAY=20.0 for Old Soil Params - ! (Ganymed-4 and later ) SURFLAY=50.0 for New Soil Params - real :: WEMIN_IN, WEMIN_OUT - character*256 :: arg(6) - - type catch_rst - real, pointer :: bf1(:) - real, pointer :: bf2(:) - real, pointer :: bf3(:) - real, pointer :: vgwmax(:) - real, pointer :: cdcr1(:) - real, pointer :: cdcr2(:) - real, pointer :: psis(:) - real, pointer :: bee(:) - real, pointer :: poros(:) - real, pointer :: wpwet(:) - real, pointer :: cond(:) - real, pointer :: gnu(:) - real, pointer :: ars1(:) - real, pointer :: ars2(:) - real, pointer :: ars3(:) - real, pointer :: ara1(:) - real, pointer :: ara2(:) - real, pointer :: ara3(:) - real, pointer :: ara4(:) - real, pointer :: arw1(:) - real, pointer :: arw2(:) - real, pointer :: arw3(:) - real, pointer :: arw4(:) - real, pointer :: tsa1(:) - real, pointer :: tsa2(:) - real, pointer :: tsb1(:) - real, pointer :: tsb2(:) - real, pointer :: atau(:) - real, pointer :: btau(:) - real, pointer :: ity(:) - real, pointer :: tc(:,:) - real, pointer :: qc(:,:) - real, pointer :: capac(:) - real, pointer :: catdef(:) - real, pointer :: rzexc(:) - real, pointer :: srfexc(:) - real, pointer :: ghtcnt1(:) - real, pointer :: ghtcnt2(:) - real, pointer :: ghtcnt3(:) - real, pointer :: ghtcnt4(:) - real, pointer :: ghtcnt5(:) - real, pointer :: ghtcnt6(:) - real, pointer :: tsurf(:) - real, pointer :: wesnn1(:) - real, pointer :: wesnn2(:) - real, pointer :: wesnn3(:) - real, pointer :: htsnnn1(:) - real, pointer :: htsnnn2(:) - real, pointer :: htsnnn3(:) - real, pointer :: sndzn1(:) - real, pointer :: sndzn2(:) - real, pointer :: sndzn3(:) - real, pointer :: ch(:,:) - real, pointer :: cm(:,:) - real, pointer :: cq(:,:) - real, pointer :: fr(:,:) - real, pointer :: ww(:,:) - endtype catch_rst - - type(catch_rst) catch(3) - - real, allocatable, dimension(:) :: dzsf, ar1, ar2, ar4 - real, allocatable, dimension(:,:) :: TP_IN, GHT_IN, FICE, GHT_OUT, TP_OUT - real, allocatable, dimension(:) :: swe_in, depth_in, areasc_in, areasc_out, depth_out - - type(Netcdf4_fileformatter) :: formatter(3) - type(Filemetadata) :: cfg(3) - integer :: i, rc, filetype - integer :: status - character(256) :: Iam = "Scale_Catch" - -! Usage -! ----- - if (iargc() /= 6) then - write(*,*) "Usage: Scale_Catch " - call exit(2) - end if - - do n=1,6 - call getarg(n,arg(n)) - enddo - -! Open INPUT and Regridded Catch Files -! ------------------------------------ - read(arg(1),'(a)') fname1 - - read(arg(2),'(a)') fname2 - -! Open OUTPUT (Scaled) Catch File -! ------------------------------- - read(arg(3),'(a)') fname3 - - call MAPL_NCIOGetFileType(fname1, filetype, __RC__) - - if (filetype == 0) then - call formatter(1)%open(trim(fname1),pFIO_READ, __RC__) - call formatter(2)%open(trim(fname2),pFIO_READ, __RC__) - cfg(1)=formatter(1)%read(__RC__) - cfg(2)=formatter(2)%read(__RC__) - else - open(unit=10, file=trim(fname1), form='unformatted') - open(unit=20, file=trim(fname2), form='unformatted') - open(unit=30, file=trim(fname3), form='unformatted') - end if - -! Get SURFLAY Value -! ----------------- - read(arg(4),*) SURFLAY - read(arg(5),*) WEMIN_IN - read(arg(6),*) WEMIN_OUT - - if (SURFLAY.ne.20 .and. SURFLAY.ne.50) then - print *, "You must supply a valid SURFLAY value:" - print *, "(Ganymed-3 and earlier) SURFLAY=20.0 for Old Soil Params" - print *, "(Ganymed-4 and later ) SURFLAY=50.0 for New Soil Params" - call exit(2) - end if - print *, 'SURFLAY: ',SURFLAY - - if (filetype ==0) then - - ntiles = cfg(1)%get_dimension('tile', __RC__) - - else - -! Determine NTILES -! ---------------- - bpos=0 - read(10) - epos = ftell(10) ! ending position of file pointer - ntiles = (epos-bpos)/4-2 ! record size (in 4 byte words; - rewind 10 - - end if - - write(6,100) ntiles - -! Allocate Catches -! ---------------- - do n=1,3 - call allocatch ( ntiles,catch(n) ) - enddo - -! Read INPUT Catches -! ------------------ - old = 1 - new = 2 - - if (filetype ==0) then - call readcatch_nc4 ( catch(old), formatter(old), __RC__ ) - call readcatch_nc4 ( catch(new), formatter(new), __RC__ ) - else - call readcatch ( 10,catch(old) ) - call readcatch ( 20,catch(new) ) - end if - -! Create Scaled Catch -! ------------------- - sca = 3 - - catch(sca) = catch(new) - -! 1) soil moisture prognostics -! ---------------------------- -! n = count( (catch(old)%catdef .gt. catch(old)%cdcr1) .and. & -! (catch(new)%cdcr2 .gt. catch(old)%cdcr2) ) -! -! write(6,200) n,100*n/ntiles -! -! where( (catch(old)%catdef .gt. catch(old)%cdcr1) .and. & -! (catch(new)%cdcr2 .gt. catch(old)%cdcr2) ) -! -! catch(sca)%rzexc = catch(old)%rzexc * ( catch(new)%vgwmax / & -! catch(old)%vgwmax ) -! -! catch(sca)%catdef = catch(new)%cdcr1 + & -! ( catch(old)%catdef-catch(old)%cdcr1 ) / & -! ( catch(old)%cdcr2 -catch(old)%cdcr1 ) * & -! ( catch(new)%cdcr2 -catch(new)%cdcr1 ) -! end where - - n =count((catch(old)%catdef .gt. catch(old)%cdcr1)) - - write(6,200) n,100*n/ntiles - -! Scale rxexc regardless of CDCR1, CDCR2 differences -! -------------------------------------------------- - catch(sca)%rzexc = catch(old)%rzexc * ( catch(new)%vgwmax / & - catch(old)%vgwmax ) - -! Scale catdef regardless of whether CDCR2 is larger or smaller in the new situation -! ---------------------------------------------------------------------------------- - where (catch(old)%catdef .gt. catch(old)%cdcr1) - - catch(sca)%catdef = catch(new)%cdcr1 + & - ( catch(old)%catdef-catch(old)%cdcr1 ) / & - ( catch(old)%cdcr2 -catch(old)%cdcr1 ) * & - ( catch(new)%cdcr2 -catch(new)%cdcr1 ) - end where - -! Scale catdef also for the case where catdef le cdcr1. -! ----------------------------------------------------- - where( (catch(old)%catdef .le. catch(old)%cdcr1)) - catch(sca)%catdef = catch(old)%catdef * (catch(new)%cdcr1 / catch(old)%cdcr1) - end where - -! Sanity Check (catch_calc_soil_moist() forces consistency betw. srfexc, rzexc, catdef) -! ------------ - print *, 'Performing Sanity Check ...' - allocate ( dzsf(ntiles) ) - allocate ( ar1( ntiles) ) - allocate ( ar2( ntiles) ) - allocate ( ar4( ntiles) ) - - dzsf = SURFLAY - - call catch_calc_soil_moist( ntiles, dzsf, & - catch(sca)%vgwmax, catch(sca)%cdcr1, catch(sca)%cdcr2, & - catch(sca)%psis, catch(sca)%bee, catch(sca)%poros, catch(sca)%wpwet, & - catch(sca)%ars1, catch(sca)%ars2, catch(sca)%ars3, & - catch(sca)%ara1, catch(sca)%ara2, catch(sca)%ara3, catch(sca)%ara4, & - catch(sca)%arw1, catch(sca)%arw2, catch(sca)%arw3, catch(sca)%arw4, & - catch(sca)%bf1, catch(sca)%bf2, & - catch(sca)%srfexc, catch(sca)%rzexc, catch(sca)%catdef, & - ar1, ar2, ar4 ) - - n = count( catch(sca)%catdef .ne. catch(new)%catdef ) - write(6,300) n,100*n/ntiles - n = count( catch(sca)%srfexc .ne. catch(new)%srfexc ) - write(6,400) n,100*n/ntiles - n = count( catch(sca)%rzexc .ne. catch(new)%rzexc ) - write(6,400) n,100*n/ntiles - -! (2) Ground heat -! --------------- - - allocate (TP_IN (N_GT, Ntiles)) - allocate (GHT_IN (N_GT, Ntiles)) - allocate (GHT_OUT(N_GT, Ntiles)) - allocate (FICE (N_GT, NTILES)) - allocate (TP_OUT (N_GT, Ntiles)) - - GHT_IN (1,:) = catch(old)%ghtcnt1 - GHT_IN (2,:) = catch(old)%ghtcnt2 - GHT_IN (3,:) = catch(old)%ghtcnt3 - GHT_IN (4,:) = catch(old)%ghtcnt4 - GHT_IN (5,:) = catch(old)%ghtcnt5 - GHT_IN (6,:) = catch(old)%ghtcnt6 - - call catch_calc_tp ( NTILES, catch(old)%poros, GHT_IN, tp_in, FICE) - GHT_OUT = GHT_IN - -! open (99,file='ght.diff', form = 'formatted') - - do n = 1, ntiles - do i = 1, N_GT - call catch_calc_ght(dzgt(i), catch(new)%poros(n), tp_in(i,n), fice(i,n), GHT_IN(i,n)) -! if (i == N_GT) then -! if (GHT_IN(i,n) /= GHT_OUT(i,n)) write (99,*)n,catch(old)%poros(n),catch(new)%poros(n),ABS(GHT_IN(i,n)-GHT_OUT(i,n)) -! endif - end do - end do - - catch(sca)%ghtcnt1 = GHT_IN (1,:) - catch(sca)%ghtcnt2 = GHT_IN (2,:) - catch(sca)%ghtcnt3 = GHT_IN (3,:) - catch(sca)%ghtcnt4 = GHT_IN (4,:) - catch(sca)%ghtcnt5 = GHT_IN (5,:) - catch(sca)%ghtcnt6 = GHT_IN (6,:) - -! Deep soil temp sanity check -! --------------------------- - - call catch_calc_tp ( NTILES, catch(new)%poros, GHT_IN, tp_out, FICE) - - print *, 'Percent tiles TP Layer 1 differ : ', 100.* count(ABS(tp_out(1,:) - tp_in(1,:)) > 1.e-5) /float (Ntiles) - print *, 'Percent tiles TP Layer 2 differ : ', 100.* count(ABS(tp_out(2,:) - tp_in(2,:)) > 1.e-5) /float (Ntiles) - print *, 'Percent tiles TP Layer 3 differ : ', 100.* count(ABS(tp_out(3,:) - tp_in(3,:)) > 1.e-5) /float (Ntiles) - print *, 'Percent tiles TP Layer 4 differ : ', 100.* count(ABS(tp_out(4,:) - tp_in(4,:)) > 1.e-5) /float (Ntiles) - print *, 'Percent tiles TP Layer 5 differ : ', 100.* count(ABS(tp_out(5,:) - tp_in(5,:)) > 1.e-5) /float (Ntiles) - print *, 'Percent tiles TP Layer 6 differ : ', 100.* count(ABS(tp_out(6,:) - tp_in(6,:)) > 1.e-5) /float (Ntiles) - - -! SNOW scaling -! ------------ - - if(wemin_out /= wemin_in) then - - allocate (swe_in (Ntiles)) - allocate (depth_in (Ntiles)) - allocate (depth_out (Ntiles)) - allocate (areasc_in (Ntiles)) - allocate (areasc_out (Ntiles)) - - swe_in = catch(new)%wesnn1 + catch(new)%wesnn2 + catch(new)%wesnn3 - depth_in = catch(new)%sndzn1 + catch(new)%sndzn2 + catch(new)%sndzn3 - areasc_in = min(swe_in/wemin_in, 1.) - areasc_out= min(swe_in/wemin_out,1.) - - ! catch(sca)%sndzn1=catch(old)%sndzn1 - ! catch(sca)%sndzn2=catch(old)%sndzn2 - ! catch(sca)%sndzn3=catch(old)%sndzn3 - ! do i = 1, ntiles - ! if((swe_in(i) > 0.).and. ((areasc_in(i) < 1.).OR.(areasc_out(i) < 1.))) then - ! print *, i, areasc_in(i), depth_in(i) - ! density_in(i)= swe_in(i)/(areasc_in(i) * depth_in(i)) - ! depth_out(i) = swe_in(i)/(areasc_out(i)*density_in(i)) - ! depth_out(i) = areasc_in(i) * depth_in(i)/(areasc_out(i) + 1.e-20) - ! print *, catch(sca)%sndzn1(i), catch(old)%sndzn1(i),wemin_out/wemin_in - ! catch(sca)%sndzn1(i) = catch(new)%sndzn1(i)*wemin_out/wemin_in ! depth_out(i)/3. - ! catch(sca)%sndzn2(i) = catch(new)%sndzn2(i)*wemin_out/wemin_in ! depth_out(i)/3. - ! catch(sca)%sndzn3(i) = catch(new)%sndzn3(i)*wemin_out/wemin_in ! depth_out(i)/3. - ! endif - ! end do - - where (swe_in .gt. 0.) - where (areasc_in .lt. 1. .or. areasc_out .lt. 1.) - ! density_in= swe_in/(areasc_in * depth_in + 1.e-20) - ! depth_out = swe_in/(areasc_out*density_in) - depth_out = areasc_in * depth_in/(areasc_out + 1.e-20) - catch(sca)%sndzn1 = depth_out/3. - catch(sca)%sndzn2 = depth_out/3. - catch(sca)%sndzn3 = depth_out/3. - endwhere - endwhere - - print *, 'Snow scaling summary' - print *, '....................' - print *, 'Percent tiles SNDZ scaled : ', 100.* count (catch(sca)%sndzn3 .ne. catch(old)%sndzn3) /float (count (catch(sca)%sndzn3 > 0.)) - - endif - - ! PEATCLSM - ensure low CATDEF on peat tiles where "old" restart is not also peat - ! ------------------------------------------------------------------------------- - - where ( (catch(old)%poros < PEATCLSM_POROS_THRESHOLD) .and. (catch(sca)%poros >= PEATCLSM_POROS_THRESHOLD) ) - catch(sca)%catdef = 25. - catch(sca)%rzexc = 0. - catch(sca)%srfexc = 0. - end where - -! Write Scaled Catch -! ------------------ - if (filetype ==0) then - cfg(3)=cfg(2) - call formatter(3)%create(fname3, __RC__) - call formatter(3)%write(cfg(3), __RC__) - call writecatch_nc4 ( catch(sca), formatter(3) ) - else - call writecatch ( 30,catch(sca) ) - end if - -100 format(1x,'Total Tiles: ',i10) -200 format(1x,'Scaled Tiles: ',i10,2x,'(',i2.2,'%)') -300 format(1x,'CatDef Tiles: ',i10,2x,'(',i2.2,'%)') -400 format(1x,'SrfExc Tiles: ',i10,2x,'(',i2.2,'%)') -500 format(1x,' Rzexc Tiles: ',i10,2x,'(',i2.2,'%)') - - stop - - contains - - subroutine allocatch (ntiles,catch) - - integer ntiles - - type(catch_rst) catch - - allocate( catch% bf1(ntiles) ) - allocate( catch% bf2(ntiles) ) - allocate( catch% bf3(ntiles) ) - allocate( catch% vgwmax(ntiles) ) - allocate( catch% cdcr1(ntiles) ) - allocate( catch% cdcr2(ntiles) ) - allocate( catch% psis(ntiles) ) - allocate( catch% bee(ntiles) ) - allocate( catch% poros(ntiles) ) - allocate( catch% wpwet(ntiles) ) - allocate( catch% cond(ntiles) ) - allocate( catch% gnu(ntiles) ) - allocate( catch% ars1(ntiles) ) - allocate( catch% ars2(ntiles) ) - allocate( catch% ars3(ntiles) ) - allocate( catch% ara1(ntiles) ) - allocate( catch% ara2(ntiles) ) - allocate( catch% ara3(ntiles) ) - allocate( catch% ara4(ntiles) ) - allocate( catch% arw1(ntiles) ) - allocate( catch% arw2(ntiles) ) - allocate( catch% arw3(ntiles) ) - allocate( catch% arw4(ntiles) ) - allocate( catch% tsa1(ntiles) ) - allocate( catch% tsa2(ntiles) ) - allocate( catch% tsb1(ntiles) ) - allocate( catch% tsb2(ntiles) ) - allocate( catch% atau(ntiles) ) - allocate( catch% btau(ntiles) ) - allocate( catch% ity(ntiles) ) - allocate( catch% tc(ntiles,4) ) - allocate( catch% qc(ntiles,4) ) - allocate( catch% capac(ntiles) ) - allocate( catch% catdef(ntiles) ) - allocate( catch% rzexc(ntiles) ) - allocate( catch% srfexc(ntiles) ) - allocate( catch% ghtcnt1(ntiles) ) - allocate( catch% ghtcnt2(ntiles) ) - allocate( catch% ghtcnt3(ntiles) ) - allocate( catch% ghtcnt4(ntiles) ) - allocate( catch% ghtcnt5(ntiles) ) - allocate( catch% ghtcnt6(ntiles) ) - allocate( catch% tsurf(ntiles) ) - allocate( catch% wesnn1(ntiles) ) - allocate( catch% wesnn2(ntiles) ) - allocate( catch% wesnn3(ntiles) ) - allocate( catch% htsnnn1(ntiles) ) - allocate( catch% htsnnn2(ntiles) ) - allocate( catch% htsnnn3(ntiles) ) - allocate( catch% sndzn1(ntiles) ) - allocate( catch% sndzn2(ntiles) ) - allocate( catch% sndzn3(ntiles) ) - allocate( catch% ch(ntiles,4) ) - allocate( catch% cm(ntiles,4) ) - allocate( catch% cq(ntiles,4) ) - allocate( catch% fr(ntiles,4) ) - allocate( catch% ww(ntiles,4) ) - - return - end subroutine allocatch - - subroutine readcatch_nc4 (catch,formatter, rc) - type(catch_rst) catch - type(Netcdf4_fileformatter) :: formatter - integer, optional, intent(out) :: rc - integer :: status - character(256) :: Iam = "readcatch_nc4" - - call MAPL_VarRead(formatter,"BF1",catch%bf1, __RC__) - call MAPL_VarRead(formatter,"BF2",catch%bf2, __RC__) - call MAPL_VarRead(formatter,"BF3",catch%bf3, __RC__) - call MAPL_VarRead(formatter,"VGWMAX",catch%vgwmax, __RC__) - call MAPL_VarRead(formatter,"CDCR1",catch%cdcr1, __RC__) - call MAPL_VarRead(formatter,"CDCR2",catch%cdcr2, __RC__) - call MAPL_VarRead(formatter,"PSIS",catch%psis, __RC__) - call MAPL_VarRead(formatter,"BEE",catch%bee, __RC__) - call MAPL_VarRead(formatter,"POROS",catch%poros, __RC__) - call MAPL_VarRead(formatter,"WPWET",catch%wpwet, __RC__) - call MAPL_VarRead(formatter,"COND",catch%cond, __RC__) - call MAPL_VarRead(formatter,"GNU",catch%gnu, __RC__) - call MAPL_VarRead(formatter,"ARS1",catch%ars1, __RC__) - call MAPL_VarRead(formatter,"ARS2",catch%ars2, __RC__) - call MAPL_VarRead(formatter,"ARS3",catch%ars3, __RC__) - call MAPL_VarRead(formatter,"ARA1",catch%ara1, __RC__) - call MAPL_VarRead(formatter,"ARA2",catch%ara2, __RC__) - call MAPL_VarRead(formatter,"ARA3",catch%ara3, __RC__) - call MAPL_VarRead(formatter,"ARA4",catch%ara4, __RC__) - call MAPL_VarRead(formatter,"ARW1",catch%arw1, __RC__) - call MAPL_VarRead(formatter,"ARW2",catch%arw2, __RC__) - call MAPL_VarRead(formatter,"ARW3",catch%arw3, __RC__) - call MAPL_VarRead(formatter,"ARW4",catch%arw4, __RC__) - call MAPL_VarRead(formatter,"TSA1",catch%tsa1, __RC__) - call MAPL_VarRead(formatter,"TSA2",catch%tsa2, __RC__) - call MAPL_VarRead(formatter,"TSB1",catch%tsb1, __RC__) - call MAPL_VarRead(formatter,"TSB2",catch%tsb2, __RC__) - call MAPL_VarRead(formatter,"ATAU",catch%atau, __RC__) - call MAPL_VarRead(formatter,"BTAU",catch%btau, __RC__) - call MAPL_VarRead(formatter,"OLD_ITY",catch%ity, __RC__) - call MAPL_VarRead(formatter,"TC",catch%tc, __RC__) - call MAPL_VarRead(formatter,"QC",catch%qc, __RC__) - call MAPL_VarRead(formatter,"OLD_ITY",catch%ity, __RC__) - call MAPL_VarRead(formatter,"CAPAC",catch%capac, __RC__) - call MAPL_VarRead(formatter,"CATDEF",catch%catdef, __RC__) - call MAPL_VarRead(formatter,"RZEXC",catch%rzexc, __RC__) - call MAPL_VarRead(formatter,"SRFEXC",catch%srfexc, __RC__) - call MAPL_VarRead(formatter,"GHTCNT1",catch%ghtcnt1, __RC__) - call MAPL_VarRead(formatter,"GHTCNT2",catch%ghtcnt2, __RC__) - call MAPL_VarRead(formatter,"GHTCNT3",catch%ghtcnt3, __RC__) - call MAPL_VarRead(formatter,"GHTCNT4",catch%ghtcnt4, __RC__) - call MAPL_VarRead(formatter,"GHTCNT5",catch%ghtcnt5, __RC__) - call MAPL_VarRead(formatter,"GHTCNT6",catch%ghtcnt6, __RC__) - call MAPL_VarRead(formatter,"TSURF",catch%tsurf, __RC__) - call MAPL_VarRead(formatter,"WESNN1",catch%wesnn1, __RC__) - call MAPL_VarRead(formatter,"WESNN2",catch%wesnn2, __RC__) - call MAPL_VarRead(formatter,"WESNN3",catch%wesnn3, __RC__) - call MAPL_VarRead(formatter,"HTSNNN1",catch%htsnnn1, __RC__) - call MAPL_VarRead(formatter,"HTSNNN2",catch%htsnnn2, __RC__) - call MAPL_VarRead(formatter,"HTSNNN3",catch%htsnnn3, __RC__) - call MAPL_VarRead(formatter,"SNDZN1",catch%sndzn1, __RC__) - call MAPL_VarRead(formatter,"SNDZN2",catch%sndzn2, __RC__) - call MAPL_VarRead(formatter,"SNDZN3",catch%sndzn3, __RC__) - call MAPL_VarRead(formatter,"CH",catch%ch, __RC__) - call MAPL_VarRead(formatter,"CM",catch%cm, __RC__) - call MAPL_VarRead(formatter,"CQ",catch%cq, __RC__) - call MAPL_VarRead(formatter,"FR",catch%fr, __RC__) - call MAPL_VarRead(formatter,"WW",catch%ww, __RC__) - if (present(rc)) rc =0 - !_RETURN(_SUCCESS) - end subroutine readcatch_nc4 - - subroutine readcatch (unit,catch) - integer unit - type(catch_rst) catch - - read(unit) catch% bf1 - read(unit) catch% bf2 - read(unit) catch% bf3 - read(unit) catch% vgwmax - read(unit) catch% cdcr1 - read(unit) catch% cdcr2 - read(unit) catch% psis - read(unit) catch% bee - read(unit) catch% poros - read(unit) catch% wpwet - read(unit) catch% cond - read(unit) catch% gnu - read(unit) catch% ars1 - read(unit) catch% ars2 - read(unit) catch% ars3 - read(unit) catch% ara1 - read(unit) catch% ara2 - read(unit) catch% ara3 - read(unit) catch% ara4 - read(unit) catch% arw1 - read(unit) catch% arw2 - read(unit) catch% arw3 - read(unit) catch% arw4 - read(unit) catch% tsa1 - read(unit) catch% tsa2 - read(unit) catch% tsb1 - read(unit) catch% tsb2 - read(unit) catch% atau - read(unit) catch% btau - read(unit) catch% ity - read(unit) catch% tc - read(unit) catch% qc - read(unit) catch% capac - read(unit) catch% catdef - read(unit) catch% rzexc - read(unit) catch% srfexc - read(unit) catch% ghtcnt1 - read(unit) catch% ghtcnt2 - read(unit) catch% ghtcnt3 - read(unit) catch% ghtcnt4 - read(unit) catch% ghtcnt5 - read(unit) catch% ghtcnt6 - read(unit) catch% tsurf - read(unit) catch% wesnn1 - read(unit) catch% wesnn2 - read(unit) catch% wesnn3 - read(unit) catch% htsnnn1 - read(unit) catch% htsnnn2 - read(unit) catch% htsnnn3 - read(unit) catch% sndzn1 - read(unit) catch% sndzn2 - read(unit) catch% sndzn3 - read(unit) catch% ch - read(unit) catch% cm - read(unit) catch% cq - read(unit) catch% fr - read(unit) catch% ww - - return - end subroutine readcatch - - subroutine writecatch_nc4 (catch,formatter) - type(catch_rst) catch - type(Netcdf4_fileformatter) :: formatter - - call MAPL_VarWrite(formatter,"BF1",catch%bf1) - call MAPL_VarWrite(formatter,"BF2",catch%bf2) - call MAPL_VarWrite(formatter,"BF3",catch%bf3) - call MAPL_VarWrite(formatter,"VGWMAX",catch%vgwmax) - call MAPL_VarWrite(formatter,"CDCR1",catch%cdcr1) - call MAPL_VarWrite(formatter,"CDCR2",catch%cdcr2) - call MAPL_VarWrite(formatter,"PSIS",catch%psis) - call MAPL_VarWrite(formatter,"BEE",catch%bee) - call MAPL_VarWrite(formatter,"POROS",catch%poros) - call MAPL_VarWrite(formatter,"WPWET",catch%wpwet) - call MAPL_VarWrite(formatter,"COND",catch%cond) - call MAPL_VarWrite(formatter,"GNU",catch%gnu) - call MAPL_VarWrite(formatter,"ARS1",catch%ars1) - call MAPL_VarWrite(formatter,"ARS2",catch%ars2) - call MAPL_VarWrite(formatter,"ARS3",catch%ars3) - call MAPL_VarWrite(formatter,"ARA1",catch%ara1) - call MAPL_VarWrite(formatter,"ARA2",catch%ara2) - call MAPL_VarWrite(formatter,"ARA3",catch%ara3) - call MAPL_VarWrite(formatter,"ARA4",catch%ara4) - call MAPL_VarWrite(formatter,"ARW1",catch%arw1) - call MAPL_VarWrite(formatter,"ARW2",catch%arw2) - call MAPL_VarWrite(formatter,"ARW3",catch%arw3) - call MAPL_VarWrite(formatter,"ARW4",catch%arw4) - call MAPL_VarWrite(formatter,"TSA1",catch%tsa1) - call MAPL_VarWrite(formatter,"TSA2",catch%tsa2) - call MAPL_VarWrite(formatter,"TSB1",catch%tsb1) - call MAPL_VarWrite(formatter,"TSB2",catch%tsb2) - call MAPL_VarWrite(formatter,"ATAU",catch%atau) - call MAPL_VarWrite(formatter,"BTAU",catch%btau) - call MAPL_VarWrite(formatter,"OLD_ITY",catch%ity) - call MAPL_VarWrite(formatter,"TC",catch%tc) - call MAPL_VarWrite(formatter,"QC",catch%qc) - call MAPL_VarWrite(formatter,"OLD_ITY",catch%ity) - call MAPL_VarWrite(formatter,"CAPAC",catch%capac) - call MAPL_VarWrite(formatter,"CATDEF",catch%catdef) - call MAPL_VarWrite(formatter,"RZEXC",catch%rzexc) - call MAPL_VarWrite(formatter,"SRFEXC",catch%srfexc) - call MAPL_VarWrite(formatter,"GHTCNT1",catch%ghtcnt1) - call MAPL_VarWrite(formatter,"GHTCNT2",catch%ghtcnt2) - call MAPL_VarWrite(formatter,"GHTCNT3",catch%ghtcnt3) - call MAPL_VarWrite(formatter,"GHTCNT4",catch%ghtcnt4) - call MAPL_VarWrite(formatter,"GHTCNT5",catch%ghtcnt5) - call MAPL_VarWrite(formatter,"GHTCNT6",catch%ghtcnt6) - call MAPL_VarWrite(formatter,"TSURF",catch%tsurf) - call MAPL_VarWrite(formatter,"WESNN1",catch%wesnn1) - call MAPL_VarWrite(formatter,"WESNN2",catch%wesnn2) - call MAPL_VarWrite(formatter,"WESNN3",catch%wesnn3) - call MAPL_VarWrite(formatter,"HTSNNN1",catch%htsnnn1) - call MAPL_VarWrite(formatter,"HTSNNN2",catch%htsnnn2) - call MAPL_VarWrite(formatter,"HTSNNN3",catch%htsnnn3) - call MAPL_VarWrite(formatter,"SNDZN1",catch%sndzn1) - call MAPL_VarWrite(formatter,"SNDZN2",catch%sndzn2) - call MAPL_VarWrite(formatter,"SNDZN3",catch%sndzn3) - call MAPL_VarWrite(formatter,"CH",catch%ch) - call MAPL_VarWrite(formatter,"CM",catch%cm) - call MAPL_VarWrite(formatter,"CQ",catch%cq) - call MAPL_VarWrite(formatter,"FR",catch%fr) - call MAPL_VarWrite(formatter,"WW",catch%ww) - - return - end subroutine writecatch_nc4 - - subroutine writecatch (unit,catch) - integer unit - type(catch_rst) catch - - write(unit) catch% bf1 - write(unit) catch% bf2 - write(unit) catch% bf3 - write(unit) catch% vgwmax - write(unit) catch% cdcr1 - write(unit) catch% cdcr2 - write(unit) catch% psis - write(unit) catch% bee - write(unit) catch% poros - write(unit) catch% wpwet - write(unit) catch% cond - write(unit) catch% gnu - write(unit) catch% ars1 - write(unit) catch% ars2 - write(unit) catch% ars3 - write(unit) catch% ara1 - write(unit) catch% ara2 - write(unit) catch% ara3 - write(unit) catch% ara4 - write(unit) catch% arw1 - write(unit) catch% arw2 - write(unit) catch% arw3 - write(unit) catch% arw4 - write(unit) catch% tsa1 - write(unit) catch% tsa2 - write(unit) catch% tsb1 - write(unit) catch% tsb2 - write(unit) catch% atau - write(unit) catch% btau - write(unit) catch% ity - write(unit) catch% tc - write(unit) catch% qc - write(unit) catch% capac - write(unit) catch% catdef - write(unit) catch% rzexc - write(unit) catch% srfexc - write(unit) catch% ghtcnt1 - write(unit) catch% ghtcnt2 - write(unit) catch% ghtcnt3 - write(unit) catch% ghtcnt4 - write(unit) catch% ghtcnt5 - write(unit) catch% ghtcnt6 - write(unit) catch% tsurf - write(unit) catch% wesnn1 - write(unit) catch% wesnn2 - write(unit) catch% wesnn3 - write(unit) catch% htsnnn1 - write(unit) catch% htsnnn2 - write(unit) catch% htsnnn3 - write(unit) catch% sndzn1 - write(unit) catch% sndzn2 - write(unit) catch% sndzn3 - write(unit) catch% ch - write(unit) catch% cm - write(unit) catch% cq - write(unit) catch% fr - write(unit) catch% ww - - return - end subroutine writecatch - - end program diff --git a/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/Scale_CatchCN.F90 b/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/Scale_CatchCN.F90 deleted file mode 100755 index cd2bce354..000000000 --- a/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/Scale_CatchCN.F90 +++ /dev/null @@ -1,962 +0,0 @@ -#define I_AM_MAIN -#include "MAPL_Generic.h" - -program Scale_CatchCN - - use MAPL - - use LSM_ROUTINES, ONLY: & - catch_calc_soil_moist, & - catch_calc_tp, & - catch_calc_ght - - USE CATCH_CONSTANTS, ONLY: & - N_GT => CATCH_N_GT, & - DZGT => CATCH_DZGT, & - PEATCLSM_POROS_THRESHOLD - - implicit none - - character(256) :: fname1, fname2, fname3 -#ifndef __GFORTRAN__ - integer :: ftell - external :: ftell -#endif - integer :: bpos, epos, ntiles, n, nargs - integer :: old, new, sca - integer :: iargc - real :: SURFLAY ! (Ganymed-3 and earlier) SURFLAY=20.0 for Old Soil Params - ! (Ganymed-4 and later ) SURFLAY=50.0 for New Soil Params - real :: WEMIN_IN, WEMIN_OUT - character*256 :: arg(6) - - integer, parameter :: nveg = 4 - integer, parameter :: nzone = 3 - integer :: VAR_COL, VAR_PFT - integer, parameter :: VAR_COL_CLM40 = 40 ! number of CN column restart variables - integer, parameter :: VAR_PFT_CLM40 = 74 ! number of CN PFT variables per column - integer, parameter :: npft = 19 - integer, parameter :: VAR_COL_CLM45 = 35 ! number of CN column restart variables - integer, parameter :: VAR_PFT_CLM45 = 75 ! number of CN PFT variables per column - - logical :: clm45 = .false. - integer :: un_dim3 - - type catch_rst - real, pointer :: bf1(:) - real, pointer :: bf2(:) - real, pointer :: bf3(:) - real, pointer :: vgwmax(:) - real, pointer :: cdcr1(:) - real, pointer :: cdcr2(:) - real, pointer :: psis(:) - real, pointer :: bee(:) - real, pointer :: poros(:) - real, pointer :: wpwet(:) - real, pointer :: cond(:) - real, pointer :: gnu(:) - real, pointer :: ars1(:) - real, pointer :: ars2(:) - real, pointer :: ars3(:) - real, pointer :: ara1(:) - real, pointer :: ara2(:) - real, pointer :: ara3(:) - real, pointer :: ara4(:) - real, pointer :: arw1(:) - real, pointer :: arw2(:) - real, pointer :: arw3(:) - real, pointer :: arw4(:) - real, pointer :: tsa1(:) - real, pointer :: tsa2(:) - real, pointer :: tsb1(:) - real, pointer :: tsb2(:) - real, pointer :: atau(:) - real, pointer :: btau(:) - real, pointer :: ity(:,:) - real, pointer :: fvg(:,:) - real, pointer :: tc(:,:) - real, pointer :: qc(:,:) - real, pointer :: tg(:,:) - real, pointer :: capac(:) - real, pointer :: catdef(:) - real, pointer :: rzexc(:) - real, pointer :: srfexc(:) - real, pointer :: ghtcnt1(:) - real, pointer :: ghtcnt2(:) - real, pointer :: ghtcnt3(:) - real, pointer :: ghtcnt4(:) - real, pointer :: ghtcnt5(:) - real, pointer :: ghtcnt6(:) - real, pointer :: tsurf(:) - real, pointer :: wesnn1(:) - real, pointer :: wesnn2(:) - real, pointer :: wesnn3(:) - real, pointer :: htsnnn1(:) - real, pointer :: htsnnn2(:) - real, pointer :: htsnnn3(:) - real, pointer :: sndzn1(:) - real, pointer :: sndzn2(:) - real, pointer :: sndzn3(:) - real, pointer :: ch(:,:) - real, pointer :: cm(:,:) - real, pointer :: cq(:,:) - real, pointer :: fr(:,:) - real, pointer :: ww(:,:) - real, pointer :: TILE_ID(:) - real, pointer :: ndep(:) - real, pointer :: t2(:) - real, pointer :: BGALBVR(:) - real, pointer :: BGALBVF(:) - real, pointer :: BGALBNR(:) - real, pointer :: BGALBNF(:) - real, pointer :: CNCOL(:,:) - real, pointer :: CNPFT(:,:) - real, pointer :: ABM (:) - real, pointer :: FIELDCAP(:) - real, pointer :: HDM (:) - real, pointer :: GDP (:) - real, pointer :: PEATF (:) - endtype catch_rst - - type(catch_rst) catch(3) - - real, allocatable, dimension(:) :: dzsf, ar1, ar2, ar4 - real, allocatable, dimension(:,:) :: TP_IN, GHT_IN, FICE, GHT_OUT, TP_OUT - real, allocatable, dimension(:) :: swe_in, depth_in, areasc_in, areasc_out, depth_out - - type(Netcdf4_fileformatter) :: formatter(3) - type(Filemetadata) :: cfg(3) - integer :: i, rc, filetype - integer :: status - character(256) :: Iam = "Scale_CatchCN" - -! Usage -! ----- - if (iargc() /= 6) then - write(*,*) "Usage: Scale_CatchCN " - call exit(2) - end if - - do n=1,6 - call getarg(n,arg(n)) - enddo - -! Open INPUT and Regridded Catch Files -! ------------------------------------ - read(arg(1),'(a)') fname1 - - read(arg(2),'(a)') fname2 - -! Open OUTPUT (Scaled) Catch File -! ------------------------------- - read(arg(3),'(a)') fname3 - - call MAPL_NCIOGetFileType(fname1, filetype, __RC__) - - if (filetype == 0) then - call formatter(1)%open(trim(fname1),pFIO_READ, __RC__) - call formatter(2)%open(trim(fname2),pFIO_READ, __RC__) - cfg(1)=formatter(1)%read(__RC__) - cfg(2)=formatter(2)%read(__RC__) - ! else - ! open(unit=10, file=trim(fname1), form='unformatted') - ! open(unit=20, file=trim(fname2), form='unformatted') - ! open(unit=30, file=trim(fname3), form='unformatted') - end if - -! Get SURFLAY Value -! ----------------- - read(arg(4),*) SURFLAY - read(arg(5),*) WEMIN_IN - read(arg(6),*) WEMIN_OUT - - if (SURFLAY.ne.20 .and. SURFLAY.ne.50) then - print *, "You must supply a valid SURFLAY value:" - print *, "(Ganymed-3 and earlier) SURFLAY=20.0 for Old Soil Params" - print *, "(Ganymed-4 and later ) SURFLAY=50.0 for New Soil Params" - call exit(2) - end if - print *, 'SURFLAY: ',SURFLAY - - VAR_COL = VAR_COL_CLM40 - VAR_PFT = VAR_PFT_CLM40 - - if (filetype ==0) then - - ntiles = cfg(1)%get_dimension('tile', __RC__) - un_dim3 = cfg(1)%get_dimension('unknown_dim3', __RC__) - if(un_dim3 == 105) then - clm45 = .true. - VAR_COL = VAR_COL_CLM45 - VAR_PFT = VAR_PFT_CLM45 - print *, 'Processing CLM45 restarts : ', VAR_COL, VAR_PFT, clm45 - else - print *, 'Processing CLM40 restarts : ', VAR_COL, VAR_PFT, clm45 - endif -! else -! -!! Determine NTILES -!! ---------------- -! bpos=0 -! read(10) -! epos = ftell(10) ! ending position of file pointer -! ntiles = (epos-bpos)/4-2 ! record size (in 4 byte words; -! rewind 10 - - end if - - write(6,100) ntiles - -! Allocate Catches -! ---------------- - do n=1,3 - call allocatch ( ntiles,catch(n) ) - enddo - -! Read INPUT Catches -! ------------------ - old = 1 - new = 2 - - if (filetype ==0) then - call readcatchcn_nc4 ( catch(old), formatter(old), cfg(old), __RC__ ) - call readcatchcn_nc4 ( catch(new), formatter(new), cfg(new), __RC__ ) -! else -! call readcatchcn ( 10,catch(old) ) -! call readcatchcn ( 20,catch(new) ) - end if - -! Create Scaled Catch -! ------------------- - sca = 3 - - catch(sca) = catch(new) - -! 1) soil moisture prognostics -! ---------------------------- -! n = count( (catch(old)%catdef .gt. catch(old)%cdcr1) .and. & -! (catch(new)%cdcr2 .gt. catch(old)%cdcr2) ) -! -! write(6,200) n,100*n/ntiles -! -! where( (catch(old)%catdef .gt. catch(old)%cdcr1) .and. & -! (catch(new)%cdcr2 .gt. catch(old)%cdcr2) ) -! -! catch(sca)%rzexc = catch(old)%rzexc * ( catch(new)%vgwmax / & -! catch(old)%vgwmax ) -! -! catch(sca)%catdef = catch(new)%cdcr1 + & -! ( catch(old)%catdef-catch(old)%cdcr1 ) / & -! ( catch(old)%cdcr2 -catch(old)%cdcr1 ) * & -! ( catch(new)%cdcr2 -catch(new)%cdcr1 ) -! end where - - n =count((catch(old)%catdef .gt. catch(old)%cdcr1)) - - write(6,200) n,100*n/ntiles - -! Scale rxexc regardless of CDCR1, CDCR2 differences -! -------------------------------------------------- - catch(sca)%rzexc = catch(old)%rzexc * ( catch(new)%vgwmax / & - catch(old)%vgwmax ) - -! Scale catdef regardless of whether CDCR2 is larger or smaller in the new situation -! ---------------------------------------------------------------------------------- - where (catch(old)%catdef .gt. catch(old)%cdcr1) - - catch(sca)%catdef = catch(new)%cdcr1 + & - ( catch(old)%catdef-catch(old)%cdcr1 ) / & - ( catch(old)%cdcr2 -catch(old)%cdcr1 ) * & - ( catch(new)%cdcr2 -catch(new)%cdcr1 ) - end where - -! Scale catdef also for the case where catdef le cdcr1. -! ----------------------------------------------------- - where( (catch(old)%catdef .le. catch(old)%cdcr1)) - catch(sca)%catdef = catch(old)%catdef * (catch(new)%cdcr1 / catch(old)%cdcr1) - end where - -! Sanity Check (catch_calc_soil_moist() forces consistency betw. srfexc, rzexc, catdef) -! ------------ - print *, 'Performing Sanity Check ...' - allocate ( dzsf(ntiles) ) - allocate ( ar1( ntiles) ) - allocate ( ar2( ntiles) ) - allocate ( ar4( ntiles) ) - - dzsf = SURFLAY - - call catch_calc_soil_moist( ntiles, dzsf, & - catch(sca)%vgwmax, catch(sca)%cdcr1, catch(sca)%cdcr2, & - catch(sca)%psis, catch(sca)%bee, catch(sca)%poros, catch(sca)%wpwet, & - catch(sca)%ars1, catch(sca)%ars2, catch(sca)%ars3, & - catch(sca)%ara1, catch(sca)%ara2, catch(sca)%ara3, catch(sca)%ara4, & - catch(sca)%arw1, catch(sca)%arw2, catch(sca)%arw3, catch(sca)%arw4, & - catch(sca)%bf1, catch(sca)%bf2, & - catch(sca)%srfexc, catch(sca)%rzexc, catch(sca)%catdef, & - ar1, ar2, ar4 ) - - n = count( catch(sca)%catdef .ne. catch(new)%catdef ) - write(6,300) n,100*n/ntiles - n = count( catch(sca)%srfexc .ne. catch(new)%srfexc ) - write(6,400) n,100*n/ntiles - n = count( catch(sca)%rzexc .ne. catch(new)%rzexc ) - write(6,400) n,100*n/ntiles - -! (2) Ground heat -! --------------- - - allocate (TP_IN (N_GT, Ntiles)) - allocate (GHT_IN (N_GT, Ntiles)) - allocate (GHT_OUT(N_GT, Ntiles)) - allocate (FICE (N_GT, NTILES)) - allocate (TP_OUT (N_GT, Ntiles)) - - GHT_IN (1,:) = catch(old)%ghtcnt1 - GHT_IN (2,:) = catch(old)%ghtcnt2 - GHT_IN (3,:) = catch(old)%ghtcnt3 - GHT_IN (4,:) = catch(old)%ghtcnt4 - GHT_IN (5,:) = catch(old)%ghtcnt5 - GHT_IN (6,:) = catch(old)%ghtcnt6 - - call catch_calc_tp ( NTILES, catch(old)%poros, GHT_IN, tp_in, FICE) - GHT_OUT = GHT_IN - -! open (99,file='ght.diff', form = 'formatted') - - do n = 1, ntiles - do i = 1, N_GT - call catch_calc_ght(dzgt(i), catch(new)%poros(n), tp_in(i,n), fice(i,n), GHT_IN(i,n)) -! if (i == N_GT) then -! if (GHT_IN(i,n) /= GHT_OUT(i,n)) write (99,*)n,catch(old)%poros(n),catch(new)%poros(n),ABS(GHT_IN(i,n)-GHT_OUT(i,n)) -! endif - end do - end do - - catch(sca)%ghtcnt1 = GHT_IN (1,:) - catch(sca)%ghtcnt2 = GHT_IN (2,:) - catch(sca)%ghtcnt3 = GHT_IN (3,:) - catch(sca)%ghtcnt4 = GHT_IN (4,:) - catch(sca)%ghtcnt5 = GHT_IN (5,:) - catch(sca)%ghtcnt6 = GHT_IN (6,:) - -! Deep soil temp sanity check -! --------------------------- - - call catch_calc_tp ( NTILES, catch(new)%poros, GHT_IN, tp_out, FICE) - - print *, 'Percent tiles TP Layer 1 differ : ', 100.* count(ABS(tp_out(1,:) - tp_in(1,:)) > 1.e-5) /float (Ntiles) - print *, 'Percent tiles TP Layer 2 differ : ', 100.* count(ABS(tp_out(2,:) - tp_in(2,:)) > 1.e-5) /float (Ntiles) - print *, 'Percent tiles TP Layer 3 differ : ', 100.* count(ABS(tp_out(3,:) - tp_in(3,:)) > 1.e-5) /float (Ntiles) - print *, 'Percent tiles TP Layer 4 differ : ', 100.* count(ABS(tp_out(4,:) - tp_in(4,:)) > 1.e-5) /float (Ntiles) - print *, 'Percent tiles TP Layer 5 differ : ', 100.* count(ABS(tp_out(5,:) - tp_in(5,:)) > 1.e-5) /float (Ntiles) - print *, 'Percent tiles TP Layer 6 differ : ', 100.* count(ABS(tp_out(6,:) - tp_in(6,:)) > 1.e-5) /float (Ntiles) - - -! SNOW scaling -! ------------ - - if(wemin_out /= wemin_in) then - - allocate (swe_in (Ntiles)) - allocate (depth_in (Ntiles)) - allocate (depth_out (Ntiles)) - allocate (areasc_in (Ntiles)) - allocate (areasc_out (Ntiles)) - - swe_in = catch(new)%wesnn1 + catch(new)%wesnn2 + catch(new)%wesnn3 - depth_in = catch(new)%sndzn1 + catch(new)%sndzn2 + catch(new)%sndzn3 - areasc_in = min(swe_in/wemin_in, 1.) - areasc_out= min(swe_in/wemin_out,1.) - - ! catch(sca)%sndzn1=catch(old)%sndzn1 - ! catch(sca)%sndzn2=catch(old)%sndzn2 - ! catch(sca)%sndzn3=catch(old)%sndzn3 - ! do i = 1, ntiles - ! if((swe_in(i) > 0.).and. ((areasc_in(i) < 1.).OR.(areasc_out(i) < 1.))) then - ! print *, i, areasc_in(i), depth_in(i) - ! density_in(i)= swe_in(i)/(areasc_in(i) * depth_in(i)) - ! depth_out(i) = swe_in(i)/(areasc_out(i)*density_in(i)) - ! depth_out(i) = areasc_in(i) * depth_in(i)/(areasc_out(i) + 1.e-20) - ! print *, catch(sca)%sndzn1(i), catch(old)%sndzn1(i),wemin_out/wemin_in - ! catch(sca)%sndzn1(i) = catch(new)%sndzn1(i)*wemin_out/wemin_in ! depth_out(i)/3. - ! catch(sca)%sndzn2(i) = catch(new)%sndzn2(i)*wemin_out/wemin_in ! depth_out(i)/3. - ! catch(sca)%sndzn3(i) = catch(new)%sndzn3(i)*wemin_out/wemin_in ! depth_out(i)/3. - ! endif - ! end do - - where (swe_in .gt. 0.) - where (areasc_in .lt. 1. .or. areasc_out .lt. 1.) - ! density_in= swe_in/(areasc_in * depth_in + 1.e-20) - ! depth_out = swe_in/(areasc_out*density_in) - depth_out = areasc_in * depth_in/(areasc_out + 1.e-20) - catch(sca)%sndzn1 = depth_out/3. - catch(sca)%sndzn2 = depth_out/3. - catch(sca)%sndzn3 = depth_out/3. - endwhere - endwhere - - print *, 'Snow scaling summary' - print *, '....................' - print *, 'Percent tiles SNDZ scaled : ', 100.* count (catch(sca)%sndzn3 .ne. catch(old)%sndzn3) /float (count (catch(sca)%sndzn3 > 0.)) - - endif - - ! PEATCLSM - ensure low CATDEF on peat tiles where "old" restart is not also peat - ! ------------------------------------------------------------------------------- - - where ( (catch(old)%poros < PEATCLSM_POROS_THRESHOLD) .and. (catch(sca)%poros >= PEATCLSM_POROS_THRESHOLD) ) - catch(sca)%catdef = 25. - catch(sca)%rzexc = 0. - catch(sca)%srfexc = 0. - end where - -! Write Scaled Catch -! ------------------ - if (filetype ==0) then - cfg(3)=cfg(2) - call formatter(3)%create(fname3, __RC__) - call formatter(3)%write(cfg(3), __RC__) - call writecatchcn_nc4 ( catch(sca), formatter(3) ,cfg(3) ) -! else -! call writecatchcn ( 30,catch(sca) ) - end if - -100 format(1x,'Total Tiles: ',i10) -200 format(1x,'Scaled Tiles: ',i10,2x,'(',i2.2,'%)') -300 format(1x,'CatDef Tiles: ',i10,2x,'(',i2.2,'%)') -400 format(1x,'SrfExc Tiles: ',i10,2x,'(',i2.2,'%)') -500 format(1x,' Rzexc Tiles: ',i10,2x,'(',i2.2,'%)') - - stop - - contains - - subroutine allocatch (ntiles,catch) - - integer ntiles - - type(catch_rst) catch - - allocate( catch% bf1(ntiles) ) - allocate( catch% bf2(ntiles) ) - allocate( catch% bf3(ntiles) ) - allocate( catch% vgwmax(ntiles) ) - allocate( catch% cdcr1(ntiles) ) - allocate( catch% cdcr2(ntiles) ) - allocate( catch% psis(ntiles) ) - allocate( catch% bee(ntiles) ) - allocate( catch% poros(ntiles) ) - allocate( catch% wpwet(ntiles) ) - allocate( catch% cond(ntiles) ) - allocate( catch% gnu(ntiles) ) - allocate( catch% ars1(ntiles) ) - allocate( catch% ars2(ntiles) ) - allocate( catch% ars3(ntiles) ) - allocate( catch% ara1(ntiles) ) - allocate( catch% ara2(ntiles) ) - allocate( catch% ara3(ntiles) ) - allocate( catch% ara4(ntiles) ) - allocate( catch% arw1(ntiles) ) - allocate( catch% arw2(ntiles) ) - allocate( catch% arw3(ntiles) ) - allocate( catch% arw4(ntiles) ) - allocate( catch% tsa1(ntiles) ) - allocate( catch% tsa2(ntiles) ) - allocate( catch% tsb1(ntiles) ) - allocate( catch% tsb2(ntiles) ) - allocate( catch% atau(ntiles) ) - allocate( catch% btau(ntiles) ) - allocate( catch% ity(ntiles,4) ) - allocate( catch% fvg(ntiles,4) ) - allocate( catch% tc(ntiles,4) ) - allocate( catch% qc(ntiles,4) ) - allocate( catch% tg(ntiles,4) ) - allocate( catch% capac(ntiles) ) - allocate( catch% catdef(ntiles) ) - allocate( catch% rzexc(ntiles) ) - allocate( catch% srfexc(ntiles) ) - allocate( catch% ghtcnt1(ntiles) ) - allocate( catch% ghtcnt2(ntiles) ) - allocate( catch% ghtcnt3(ntiles) ) - allocate( catch% ghtcnt4(ntiles) ) - allocate( catch% ghtcnt5(ntiles) ) - allocate( catch% ghtcnt6(ntiles) ) - allocate( catch% tsurf(ntiles) ) - allocate( catch% wesnn1(ntiles) ) - allocate( catch% wesnn2(ntiles) ) - allocate( catch% wesnn3(ntiles) ) - allocate( catch% htsnnn1(ntiles) ) - allocate( catch% htsnnn2(ntiles) ) - allocate( catch% htsnnn3(ntiles) ) - allocate( catch% sndzn1(ntiles) ) - allocate( catch% sndzn2(ntiles) ) - allocate( catch% sndzn3(ntiles) ) - allocate( catch% ch(ntiles,4) ) - allocate( catch% cm(ntiles,4) ) - allocate( catch% cq(ntiles,4) ) - allocate( catch% fr(ntiles,4) ) - allocate( catch% ww(ntiles,4) ) - allocate( catch% TILE_ID(ntiles) ) - allocate( catch% ndep(ntiles) ) - allocate( catch% t2(ntiles) ) - allocate( catch% BGALBVR(ntiles) ) - allocate( catch% BGALBVF(ntiles) ) - allocate( catch% BGALBNR(ntiles) ) - allocate( catch% BGALBNF(ntiles) ) - allocate( catch% CNCOL(ntiles,nzone*VAR_COL)) - allocate( catch% CNPFT(ntiles,nzone*nveg*VAR_PFT)) - allocate( catch% ABM(ntiles) ) - allocate( catch% FIELDCAP(ntiles) ) - allocate( catch% HDM(ntiles) ) - allocate( catch% GDP(ntiles) ) - allocate( catch% PEATF(ntiles) ) - - return - end subroutine allocatch - - subroutine readcatchcn_nc4 (catch,formatter,cfg, rc) - type(catch_rst) catch - type(Filemetadata) :: cfg - type(Netcdf4_fileformatter) :: formatter - integer, optional, intent(out) :: rc - integer :: j, dim1,dim2 - type(Variable), pointer :: myVariable - character(len=:), pointer :: dname - integer :: status - character(256) :: Iam = "readcatchcn_nc4" - - call MAPL_VarRead(formatter,"BF1",catch%bf1, __RC__) - call MAPL_VarRead(formatter,"BF2",catch%bf2, __RC__) - call MAPL_VarRead(formatter,"BF3",catch%bf3, __RC__) - call MAPL_VarRead(formatter,"VGWMAX",catch%vgwmax, __RC__) - call MAPL_VarRead(formatter,"CDCR1",catch%cdcr1, __RC__) - call MAPL_VarRead(formatter,"CDCR2",catch%cdcr2, __RC__) - call MAPL_VarRead(formatter,"PSIS",catch%psis, __RC__) - call MAPL_VarRead(formatter,"BEE",catch%bee, __RC__) - call MAPL_VarRead(formatter,"POROS",catch%poros, __RC__) - call MAPL_VarRead(formatter,"WPWET",catch%wpwet, __RC__) - call MAPL_VarRead(formatter,"COND",catch%cond, __RC__) - call MAPL_VarRead(formatter,"GNU",catch%gnu, __RC__) - call MAPL_VarRead(formatter,"ARS1",catch%ars1, __RC__) - call MAPL_VarRead(formatter,"ARS2",catch%ars2, __RC__) - call MAPL_VarRead(formatter,"ARS3",catch%ars3, __RC__) - call MAPL_VarRead(formatter,"ARA1",catch%ara1, __RC__) - call MAPL_VarRead(formatter,"ARA2",catch%ara2, __RC__) - call MAPL_VarRead(formatter,"ARA3",catch%ara3, __RC__) - call MAPL_VarRead(formatter,"ARA4",catch%ara4, __RC__) - call MAPL_VarRead(formatter,"ARW1",catch%arw1, __RC__) - call MAPL_VarRead(formatter,"ARW2",catch%arw2, __RC__) - call MAPL_VarRead(formatter,"ARW3",catch%arw3, __RC__) - call MAPL_VarRead(formatter,"ARW4",catch%arw4, __RC__) - call MAPL_VarRead(formatter,"TSA1",catch%tsa1, __RC__) - call MAPL_VarRead(formatter,"TSA2",catch%tsa2, __RC__) - call MAPL_VarRead(formatter,"TSB1",catch%tsb1, __RC__) - call MAPL_VarRead(formatter,"TSB2",catch%tsb2, __RC__) - call MAPL_VarRead(formatter,"ATAU",catch%atau, __RC__) - call MAPL_VarRead(formatter,"BTAU",catch%btau, __RC__) - - myVariable => cfg%get_variable("ITY") - dname => myVariable%get_ith_dimension(2) - dim1 = cfg%get_dimension(dname) - do j=1,dim1 - call MAPL_VarRead(formatter,"ITY",catch%ity(:,j),offset1=j, __RC__) - call MAPL_VarRead(formatter,"FVG",catch%fvg(:,j),offset1=j, __RC__) - enddo - - call MAPL_VarRead(formatter,"TC",catch%tc, __RC__) - call MAPL_VarRead(formatter,"QC",catch%qc, __RC__) - call MAPL_VarRead(formatter,"TG",catch%tg, __RC__) - call MAPL_VarRead(formatter,"CAPAC",catch%capac, __RC__) - call MAPL_VarRead(formatter,"CATDEF",catch%catdef, __RC__) - call MAPL_VarRead(formatter,"RZEXC",catch%rzexc, __RC__) - call MAPL_VarRead(formatter,"SRFEXC",catch%srfexc, __RC__) - call MAPL_VarRead(formatter,"GHTCNT1",catch%ghtcnt1, __RC__) - call MAPL_VarRead(formatter,"GHTCNT2",catch%ghtcnt2, __RC__) - call MAPL_VarRead(formatter,"GHTCNT3",catch%ghtcnt3, __RC__) - call MAPL_VarRead(formatter,"GHTCNT4",catch%ghtcnt4, __RC__) - call MAPL_VarRead(formatter,"GHTCNT5",catch%ghtcnt5, __RC__) - call MAPL_VarRead(formatter,"GHTCNT6",catch%ghtcnt6, __RC__) - call MAPL_VarRead(formatter,"TSURF",catch%tsurf, __RC__) - call MAPL_VarRead(formatter,"WESNN1",catch%wesnn1, __RC__) - call MAPL_VarRead(formatter,"WESNN2",catch%wesnn2, __RC__) - call MAPL_VarRead(formatter,"WESNN3",catch%wesnn3, __RC__) - call MAPL_VarRead(formatter,"HTSNNN1",catch%htsnnn1, __RC__) - call MAPL_VarRead(formatter,"HTSNNN2",catch%htsnnn2, __RC__) - call MAPL_VarRead(formatter,"HTSNNN3",catch%htsnnn3, __RC__) - call MAPL_VarRead(formatter,"SNDZN1",catch%sndzn1, __RC__) - call MAPL_VarRead(formatter,"SNDZN2",catch%sndzn2, __RC__) - call MAPL_VarRead(formatter,"SNDZN3",catch%sndzn3, __RC__) - call MAPL_VarRead(formatter,"CH",catch%ch, __RC__) - call MAPL_VarRead(formatter,"CM",catch%cm, __RC__) - call MAPL_VarRead(formatter,"CQ",catch%cq, __RC__) - call MAPL_VarRead(formatter,"FR",catch%fr, __RC__) - call MAPL_VarRead(formatter,"WW",catch%ww, __RC__) - call MAPL_VarRead(formatter,"TILE_ID",catch%TILE_ID, __RC__) - call MAPL_VarRead(formatter,"NDEP",catch%ndep, __RC__) - call MAPL_VarRead(formatter,"CLI_T2M",catch%t2, __RC__) - call MAPL_VarRead(formatter,"BGALBVR",catch%BGALBVR, __RC__) - call MAPL_VarRead(formatter,"BGALBVF",catch%BGALBVF, __RC__) - call MAPL_VarRead(formatter,"BGALBNR",catch%BGALBNR, __RC__) - call MAPL_VarRead(formatter,"BGALBNF",catch%BGALBNF, __RC__) - myVariable => cfg%get_variable("CNCOL") - dname => myVariable%get_ith_dimension(2) - dim1 = cfg%get_dimension(dname) - if(clm45) then - call MAPL_VarRead(formatter,"ABM", catch%ABM, __RC__) - call MAPL_VarRead(formatter,"FIELDCAP",catch%FIELDCAP, __RC__) - call MAPL_VarRead(formatter,"HDM", catch%HDM , __RC__) - call MAPL_VarRead(formatter,"GDP", catch%GDP , __RC__) - call MAPL_VarRead(formatter,"PEATF", catch%PEATF , __RC__) - endif - do j=1,dim1 - call MAPL_VarRead(formatter,"CNCOL",catch%CNCOL(:,j),offset1=j, __RC__) - enddo - ! The following three lines were added as a bug fix by smahanam on 5 Oct 2020 - ! (to be merged into the "develop" branch in late 2020): - ! The length of the 2nd dim of CNPFT differs from that of CNCOL. Prior to this fix, - ! CNPFT was not read in its entirety and some elements remained uninitialized (or zero), - ! resulting in bad values in the "regridded" (re-tiled) restart file. - ! This impacted re-tiled restarts for both CNCLM40 and CLCLM45. - ! - reichle, 23 Nov 2020 - myVariable => cfg%get_variable("CNPFT") - dname => myVariable%get_ith_dimension(2) - dim1 = cfg%get_dimension(dname) - do j=1,dim1 - call MAPL_VarRead(formatter,"CNPFT",catch%CNPFT(:,j),offset1=j, __RC__) - enddo - if (present(rc)) rc =0 - !_RETURN(_SUCCESS) - end subroutine readcatchcn_nc4 - - subroutine readcatchcn (unit,catch) - integer unit, i,j,n - type(catch_rst) catch - - read(unit) catch% bf1 - read(unit) catch% bf2 - read(unit) catch% bf3 - read(unit) catch% vgwmax - read(unit) catch% cdcr1 - read(unit) catch% cdcr2 - read(unit) catch% psis - read(unit) catch% bee - read(unit) catch% poros - read(unit) catch% wpwet - read(unit) catch% cond - read(unit) catch% gnu - read(unit) catch% ars1 - read(unit) catch% ars2 - read(unit) catch% ars3 - read(unit) catch% ara1 - read(unit) catch% ara2 - read(unit) catch% ara3 - read(unit) catch% ara4 - read(unit) catch% arw1 - read(unit) catch% arw2 - read(unit) catch% arw3 - read(unit) catch% arw4 - read(unit) catch% tsa1 - read(unit) catch% tsa2 - read(unit) catch% tsb1 - read(unit) catch% tsb2 - read(unit) catch% atau - read(unit) catch% btau - read(unit) catch% ity(:,1) - read(unit) catch% ity(:,2) - read(unit) catch% ity(:,3) - read(unit) catch% ity(:,4) - read(unit) catch% fvg(:,1) - read(unit) catch% fvg(:,2) - read(unit) catch% fvg(:,3) - read(unit) catch% fvg(:,4) - read(unit) catch% tc - read(unit) catch% qc - read(unit) catch% tg - read(unit) catch% capac - read(unit) catch% catdef - read(unit) catch% rzexc - read(unit) catch% srfexc - read(unit) catch% ghtcnt1 - read(unit) catch% ghtcnt2 - read(unit) catch% ghtcnt3 - read(unit) catch% ghtcnt4 - read(unit) catch% ghtcnt5 - read(unit) catch% ghtcnt6 - read(unit) catch% tsurf - read(unit) catch% wesnn1 - read(unit) catch% wesnn2 - read(unit) catch% wesnn3 - read(unit) catch% htsnnn1 - read(unit) catch% htsnnn2 - read(unit) catch% htsnnn3 - read(unit) catch% sndzn1 - read(unit) catch% sndzn2 - read(unit) catch% sndzn3 - read(unit) catch% ch - read(unit) catch% cm - read(unit) catch% cq - read(unit) catch% fr - read(unit) catch% ww - read(unit) catch% TILE_ID - read(unit) catch% ndep - read(unit) catch% t2 - read(unit) catch% BGALBVR - read(unit) catch% BGALBVF - read(unit) catch% BGALBNR - read(unit) catch% BGALBNF - - do j = 1,nzone * VAR_COL - read(unit) catch% CNCOL (:,j) - end do - - do i = 1,nzone * nveg * VAR_PFT - read(unit) catch% CNPFT (:,i) - end do - return - end subroutine readcatchcn - - subroutine writecatchcn_nc4 (catch,formatter,cfg) - type(catch_rst) catch - type(Netcdf4_fileformatter) :: formatter - type(filemetadata) :: cfg - integer :: i,j, dim1,dim2 - real, dimension (:), allocatable :: var - type(Variable), pointer :: myVariable - character(len=:), pointer :: dname - - call MAPL_VarWrite(formatter,"BF1",catch%bf1) - call MAPL_VarWrite(formatter,"BF2",catch%bf2) - call MAPL_VarWrite(formatter,"BF3",catch%bf3) - call MAPL_VarWrite(formatter,"VGWMAX",catch%vgwmax) - call MAPL_VarWrite(formatter,"CDCR1",catch%cdcr1) - call MAPL_VarWrite(formatter,"CDCR2",catch%cdcr2) - call MAPL_VarWrite(formatter,"PSIS",catch%psis) - call MAPL_VarWrite(formatter,"BEE",catch%bee) - call MAPL_VarWrite(formatter,"POROS",catch%poros) - call MAPL_VarWrite(formatter,"WPWET",catch%wpwet) - call MAPL_VarWrite(formatter,"COND",catch%cond) - call MAPL_VarWrite(formatter,"GNU",catch%gnu) - call MAPL_VarWrite(formatter,"ARS1",catch%ars1) - call MAPL_VarWrite(formatter,"ARS2",catch%ars2) - call MAPL_VarWrite(formatter,"ARS3",catch%ars3) - call MAPL_VarWrite(formatter,"ARA1",catch%ara1) - call MAPL_VarWrite(formatter,"ARA2",catch%ara2) - call MAPL_VarWrite(formatter,"ARA3",catch%ara3) - call MAPL_VarWrite(formatter,"ARA4",catch%ara4) - call MAPL_VarWrite(formatter,"ARW1",catch%arw1) - call MAPL_VarWrite(formatter,"ARW2",catch%arw2) - call MAPL_VarWrite(formatter,"ARW3",catch%arw3) - call MAPL_VarWrite(formatter,"ARW4",catch%arw4) - call MAPL_VarWrite(formatter,"TSA1",catch%tsa1) - call MAPL_VarWrite(formatter,"TSA2",catch%tsa2) - call MAPL_VarWrite(formatter,"TSB1",catch%tsb1) - call MAPL_VarWrite(formatter,"TSB2",catch%tsb2) - call MAPL_VarWrite(formatter,"ATAU",catch%atau) - call MAPL_VarWrite(formatter,"BTAU",catch%btau) - - myVariable => cfg%get_variable("ITY") - dname => myVariable%get_ith_dimension(2) - dim1 = cfg%get_dimension(dname) - do j=1,dim1 - call MAPL_VarWrite(formatter,"ITY",catch%ity(:,j),offset1=j) - call MAPL_VarWrite(formatter,"FVG",catch%fvg(:,j),offset1=j) - enddo - - call MAPL_VarWrite(formatter,"TC",catch%tc) - call MAPL_VarWrite(formatter,"QC",catch%qc) - call MAPL_VarWrite(formatter,"TG",catch%TG) - call MAPL_VarWrite(formatter,"CAPAC",catch%capac) - call MAPL_VarWrite(formatter,"CATDEF",catch%catdef) - call MAPL_VarWrite(formatter,"RZEXC",catch%rzexc) - call MAPL_VarWrite(formatter,"SRFEXC",catch%srfexc) - call MAPL_VarWrite(formatter,"GHTCNT1",catch%ghtcnt1) - call MAPL_VarWrite(formatter,"GHTCNT2",catch%ghtcnt2) - call MAPL_VarWrite(formatter,"GHTCNT3",catch%ghtcnt3) - call MAPL_VarWrite(formatter,"GHTCNT4",catch%ghtcnt4) - call MAPL_VarWrite(formatter,"GHTCNT5",catch%ghtcnt5) - call MAPL_VarWrite(formatter,"GHTCNT6",catch%ghtcnt6) - call MAPL_VarWrite(formatter,"TSURF",catch%tsurf) - call MAPL_VarWrite(formatter,"WESNN1",catch%wesnn1) - call MAPL_VarWrite(formatter,"WESNN2",catch%wesnn2) - call MAPL_VarWrite(formatter,"WESNN3",catch%wesnn3) - call MAPL_VarWrite(formatter,"HTSNNN1",catch%htsnnn1) - call MAPL_VarWrite(formatter,"HTSNNN2",catch%htsnnn2) - call MAPL_VarWrite(formatter,"HTSNNN3",catch%htsnnn3) - call MAPL_VarWrite(formatter,"SNDZN1",catch%sndzn1) - call MAPL_VarWrite(formatter,"SNDZN2",catch%sndzn2) - call MAPL_VarWrite(formatter,"SNDZN3",catch%sndzn3) - call MAPL_VarWrite(formatter,"CH",catch%ch) - call MAPL_VarWrite(formatter,"CM",catch%cm) - call MAPL_VarWrite(formatter,"CQ",catch%cq) - call MAPL_VarWrite(formatter,"FR",catch%fr) - call MAPL_VarWrite(formatter,"WW",catch%ww) - call MAPL_VarWrite(formatter,"TILE_ID",catch%TILE_ID) - call MAPL_VarWrite(formatter,"NDEP",catch%NDEP) - call MAPL_VarWrite(formatter,"CLI_T2M",catch%t2) - call MAPL_VarWrite(formatter,"BGALBVR",catch%BGALBVR) - call MAPL_VarWrite(formatter,"BGALBVF",catch%BGALBVF) - call MAPL_VarWrite(formatter,"BGALBNR",catch%BGALBNR) - call MAPL_VarWrite(formatter,"BGALBNF",catch%BGALBNF) - myVariable => cfg%get_variable("CNCOL") - dname => myVariable%get_ith_dimension(2) - dim1 = cfg%get_dimension(dname) - - do j=1,dim1 - call MAPL_VarWrite(formatter,"CNCOL",catch%CNCOL(:,j),offset1=j) - enddo - myVariable => cfg%get_variable("CNPFT") - dname => myVariable%get_ith_dimension(2) - dim1 = cfg%get_dimension(dname) - do j=1,dim1 - call MAPL_VarWrite(formatter,"CNPFT",catch%CNPFT(:,j),offset1=j) - enddo - - dim1 = cfg%get_dimension('tile') - allocate (var (dim1)) - var = 0. - - call MAPL_VarWrite(formatter,"BFLOWM", var) - call MAPL_VarWrite(formatter,"TOTWATM",var) - call MAPL_VarWrite(formatter,"TAIRM", var) - call MAPL_VarWrite(formatter,"TPM", var) - call MAPL_VarWrite(formatter,"CNSUM", var) - call MAPL_VarWrite(formatter,"SNDZM", var) - call MAPL_VarWrite(formatter,"ASNOWM", var) - - myVariable => cfg%get_variable("TGWM") - dname => myVariable%get_ith_dimension(2) - dim1 = cfg%get_dimension(dname) - do j=1,dim1 - call MAPL_VarWrite(formatter,"TGWM",var,offset1=j) - call MAPL_VarWrite(formatter,"RZMM",var,offset1=j) - end do - - if (clm45) then - do j=1,dim1 - call MAPL_VarWrite(formatter,"SFMM", var,offset1=j) - enddo - - call MAPL_VarWrite(formatter,"ABM", catch%ABM, rc =rc ) - call MAPL_VarWrite(formatter,"FIELDCAP",catch%FIELDCAP) - call MAPL_VarWrite(formatter,"HDM", catch%HDM ) - call MAPL_VarWrite(formatter,"GDP", catch%GDP ) - call MAPL_VarWrite(formatter,"PEATF", catch%PEATF ) - call MAPL_VarWrite(formatter,"RHM", var) - call MAPL_VarWrite(formatter,"WINDM", var) - call MAPL_VarWrite(formatter,"RAINFM", var) - call MAPL_VarWrite(formatter,"SNOWFM", var) - call MAPL_VarWrite(formatter,"RUNSRFM", var) - call MAPL_VarWrite(formatter,"AR1M", var) - call MAPL_VarWrite(formatter,"T2M10D", var) - call MAPL_VarWrite(formatter,"TPREC10D",var) - call MAPL_VarWrite(formatter,"TPREC60D",var) - else - call MAPL_VarWrite(formatter,"SFMCM", var) - endif - - myVariable => cfg%get_variable("PSNSUNM") - dname => myVariable%get_ith_dimension(2) - dim1 = cfg%get_dimension(dname) - dname => myVariable%get_ith_dimension(3) - dim2 = cfg%get_dimension(dname) - do i=1,dim2 - do j=1,dim1 - call MAPL_VarWrite(formatter,"PSNSUNM",var,offset1=j,offset2=i) - call MAPL_VarWrite(formatter,"PSNSHAM",var,offset1=j,offset2=i) - end do - end do - call formatter%close() - return - end subroutine writecatchcn_nc4 - - subroutine writecatchcn (unit,catch) - integer unit, i,j,n - type(catch_rst) catch - - write(unit) catch% bf1 - write(unit) catch% bf2 - write(unit) catch% bf3 - write(unit) catch% vgwmax - write(unit) catch% cdcr1 - write(unit) catch% cdcr2 - write(unit) catch% psis - write(unit) catch% bee - write(unit) catch% poros - write(unit) catch% wpwet - write(unit) catch% cond - write(unit) catch% gnu - write(unit) catch% ars1 - write(unit) catch% ars2 - write(unit) catch% ars3 - write(unit) catch% ara1 - write(unit) catch% ara2 - write(unit) catch% ara3 - write(unit) catch% ara4 - write(unit) catch% arw1 - write(unit) catch% arw2 - write(unit) catch% arw3 - write(unit) catch% arw4 - write(unit) catch% tsa1 - write(unit) catch% tsa2 - write(unit) catch% tsb1 - write(unit) catch% tsb2 - write(unit) catch% atau - write(unit) catch% btau - write(unit) catch% ity(:,1) - write(unit) catch% ity(:,2) - write(unit) catch% ity(:,3) - write(unit) catch% ity(:,4) - write(unit) catch% fvg(:,1) - write(unit) catch% fvg(:,2) - write(unit) catch% fvg(:,3) - write(unit) catch% fvg(:,4) - write(unit) catch% tc - write(unit) catch% qc - write(unit) catch% tg - write(unit) catch% capac - write(unit) catch% catdef - write(unit) catch% rzexc - write(unit) catch% srfexc - write(unit) catch% ghtcnt1 - write(unit) catch% ghtcnt2 - write(unit) catch% ghtcnt3 - write(unit) catch% ghtcnt4 - write(unit) catch% ghtcnt5 - write(unit) catch% ghtcnt6 - write(unit) catch% tsurf - write(unit) catch% wesnn1 - write(unit) catch% wesnn2 - write(unit) catch% wesnn3 - write(unit) catch% htsnnn1 - write(unit) catch% htsnnn2 - write(unit) catch% htsnnn3 - write(unit) catch% sndzn1 - write(unit) catch% sndzn2 - write(unit) catch% sndzn3 - write(unit) catch% ch - write(unit) catch% cm - write(unit) catch% cq - write(unit) catch% fr - write(unit) catch% ww - write(unit) catch% TILE_ID - write(unit) catch% ndep - write(unit) catch% t2 - write(unit) catch% BGALBVR - write(unit) catch% BGALBVF - write(unit) catch% BGALBNR - write(unit) catch% BGALBNF - - do j = 1,nzone * VAR_COL - write(unit) catch% CNCOL (:,j) - end do - - do i = 1,nzone * nveg * VAR_PFT - write(unit) catch% CNPFT (:,i) - end do - - return - end subroutine writecatchcn - - end program - diff --git a/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/mk_CatchCNRestarts.F90 b/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/mk_CatchCNRestarts.F90 deleted file mode 100755 index e4ab880c8..000000000 --- a/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/mk_CatchCNRestarts.F90 +++ /dev/null @@ -1,2453 +0,0 @@ -#define I_AM_MAIN -#include "MAPL_Generic.h" - -program mk_CatchCNRestarts - -! Usage : mk_CatchCNRestarts OutTileFile InTileFile InRestart SURFLAY RestartTime -! Version 1 : Sarith Mahanama -! sarith.p.mahanama@nasa.gov (Feb 19, 2016) -! The program follows the same nearest neighbor based procedure, as in mk_CatchRestarts.F90, -! to regrid hydrological variables and BCs-based parameters. The algorithm developed -! by Greg Walker (~gkwalker/geos5/convert_offline_cn_restart.f90) to regrid carbon -! variables that looks for a neighbor with a similar vegetation type was modified -! to improve efficiency (in subroutine regrid_carbon_vars). The two main -! modifications in this implementation include: (1) instead looping over the globe, -! it starts from a 10 x 10 window and zoom out until a similar type appears, -! (2) uses MPI enabling parrellel computation. -! Version 2 : Sarith Mahanama (Oct 12, 2016) -! (1) updated to read both carbon and hydrological variables more recent SMAP M09 simulation from Fanwei. -! (2) added subroutine reorder_LDASsa_rst -! The program produces catchcn_internal_rst in nc4 format for any user specified AGCM grid resolution. - -! regrid.pl visits this program twice during the regridding process. During the first visit, the program does not use BCs data. -! It just regrids hydrological variables and BCs-based land parameters in InRestart from InTile space to OutTile -! space (InRestart could be either a catchcn_internal_rst or a catch_internal_rst). If InRestart is a -! catchcn_internal_rst, carbon variables will be regridded using the same simple nearest neighbor algorithm (getids.H) that -! was employed for regridding all other variables. If InRestart is a catch_internal_rst, carbon variables will be -! filled with zeros. - -! During the second visit, the program uses the catchcn_internal_rst produced from the first visit as InRestart (herein -! referred to as InRestart2 which is in OutTile space already). The program reads BCs data from BCSDIR, carbon variables -! from an offline simulation on the SMAP_EASEv2_M09 grid which has been initialized by another 3000-year offline simulation, and -! hydrological from -! InRestart2 in Version 1, -! the same offline simulation on the SMAP_EASEv2_M09 in Version 2. -! Then, they will be regridded to OutTile space. The regridding carbon variables utilizes a more complicated algorithm which looks -! for a M09 grid cell in the neighborhood with a similar vegetation type seperately for each fractional vegetation type within the -! catchment-tile. Note, the model can have upto 4 different types per catchment-tile: primary and secondary types -! and 2 split types for each primary and secondary type. - -! regrid.pl will then execute Scale_CatchCN.F90 which reads catchcn_internal_rst files created in the above 2 steps, -! and scale soil moisture variables to be consistent with the new BCs-based land parameters to produce the final -! catchcn_internal_rst file. - -! Output file format: Output catchcn_internal_rst is always a nc4 file. - -! Here are available options: -! (1) OPT1 (for above first step) -! Input : (1) catchcn_internal_rst from an existing AGCM run (will always be nc4) -! (2) InTile and OutTile are DIFFERENT -! (3) NO land BCs -! OutPut: Every variable (BCs-based land parameters, hydrological variables, and carbon parameters) will be regridded -! from InTile to OutTile space using the simple nearest neighbor algorithm (getids.H) - -! (2) OPT2 (for above first step) -! Input : (1) catch_internal_rst from an existing AGCM run (either nc4 or binary) -! (2) InTile and OutTile are DIFFERENT -! (3) NO land BCs -! OutPut: BCs-based land parameters, and hydrological variables will regridded from InTile to OutTile space -! using the simple nearest neighbor algorithm (getids.H). All carbon variables are filled with zeros. - -! (3) OPT3 (above second step) : -! Input : (1) catchcn_internal_rst (file format is always nc4) -! (2) InTile and OutTile are the same user defined OutTile -! (3) land BCs, -! Output: BCs-based land parameters will be replaced and carbon variables will be filled with regridded (from the -! nearest offline cell with the same vegetation type) data to produce catchcn_internal_rst - -! ---------------------------------------------------------------------------------------------------------------------------------------------- - - ! ====================== ! - ! Process ! - ! ====================== ! - -! HAVEDATA -! | -! _______________________________________________________________________ -! | | -! -! NO (OPT1/OPT2) YES (OPT3) -! -------------- ---------- -!OutTile : /= InTile == InTile -!regridding: ID (InTile to OutTile using getids.H) ID (one-to-one i.e. 1:NTILES, no regridding) -! | | -! clsmcn_file | -! _____________________________________ | -! | | | -! YES (OPT1) NO (OPT2) | -!InRestart : catchcn_internal_rst catch_internal_rst catchcn_internal_rst -! | | | -! | filetype | -! | | | -! | _________________________________ | -! | | | | -! V 0 /= 0 V -!call : read_catchcn_nc4 read_catch_nc4 read_catch_bin read_bcs_data -! | | -! ----------------------------------- -! | -! V -!1) reads InRestart nVars records (1) reads InCNRestart/regrids/writes (1:65) (1) reads BCs -!2) regrids (takes hydrological initial conditions (2) writes 1:37; 66:72 -!3) writes from offline SMAP M09) (3) reads InRestart2/writes 38, 39,40=38,41:65 -!4) close files (2) close files (4) call regrid_carbon_vars (from offline SMAP M09) -! (a) reads from InCNRestart -! (b) regrids each veg type from the nearest InRestart cell -! (c) writes (73-192,193-1080) -! (d) close files -! -! -! -! OUTPUT catchcn_internal_rst will always be nc4 -! ---------------------------------------------------------------------------------------------------------------------------------------------- - - -! The order of the INTERNAL STATE variables in GEOS_CatchCNGridComp -! ----------------------------------------------------------------- -! 1: BF1 -! 2: BF2 -! 3: BF3 -! 4: VGWMAX -! 5: CDCR1 -! 6: CDCR2 -! 7: PSIS -! 8: BEE -! 9: POROS -! 10: WPWET -! 11: COND -! 12: GNU -! 13: ARS1 -! 14: ARS2 -! 15: ARS3 -! 16: ARA1 -! 17: ARA2 -! 18: ARA3 -! 19: ARA4 -! 20: ARW1 -! 21: ARW2 -! 22: ARW3 -! 23: ARW4 -! 24: TSA1 -! 25: TSA2 -! 26: TSB1 -! 27: TSB2 -! 28: ATAU -! 29: BTAU -! 30-33: ITY * NUM_VEG -! 34-37: FVEG * NUM_VEG -! 38: ((TC (n,i),n=1,n_catd),i=1,4) -! 39: ((QC (n,i),n=1,n_catd),i=1,4) -! 40: ((TG (n,i),n=1,n_catd),i=1,4) -! 41: CAPAC -! 42: CATDEF -! 43: RZEXC -! 44: SRFEXC -! 45: GHTCNT1 -! 46: GHTCNT2 -! 47: GHTCNT3 -! 48: GHTCNT4 -! 49: GHTCNT5 -! 50: GHTCNT6 -! 51: TSURF -! 52: WESNN1 -! 53: WESNN2 -! 54: WESNN3 -! 55: HTSNNN1 -! 56: HTSNNN2 -! 57: HTSNNN3 -! 58: SNDZN1 -! 59: SNDZN2 -! 60: SNDZN3 -! 61: ((CH (n,i),n=1,n_catd),i=1,4) -! 62: ((CM (n,i),n=1,n_catd),i=1,4) -! 63: ((CQ (n,i),n=1,n_catd),i=1,4) -! 64: ((FR (n,i),n=1,n_catd),i=1,4) -! 65: ((WW (n,i),n=1,n_catd),i=1,4) -! 66: cat_id -! 67: ndep -! 68: cli_t2m -! 69: BGALBVR -! 70: BGALBVF -! 71: BGALBNR -! 72: BGALBNF -! 73-192: CNCOL (n,nz*VAR_COL) -! 193-1080: CNPFT (n,nz*nv*VAR_PFT) -! 1081-1083: TGWM (n,nz) -! 1084: SFMCM -! 1085: BFLOWM -! 1086: TOTWATM -! 1087: TAIRM -! 1088: TPM -! 1089: CNSUM -! 1090: SNDZM -! 1091: ASNOWM -! 1092-1103: PSNSUNM (n,nz*nv) -! 1104-1115: PSNSHAM (n,nz*nv) - - use MAPL - use ESMF - use gFTL_StringVector - use ieee_arithmetic, only: isnan => ieee_is_nan - use mk_restarts_getidsMod, only: GetIDs, ReadTileFile_RealLatLon - use clm_varpar_shared , only : nzone => NUM_ZON_CN, nveg => NUM_VEG_CN, & - VAR_COL => VAR_COL_40, VAR_PFT => VAR_PFT_40, & - npft => numpft_CN - - implicit none - include 'mpif.h' - INCLUDE 'netcdf.inc' - - ! initialize to non-MPI values - - integer :: myid=0, numprocs=1, mpierr, mpistatus(MPI_STATUS_SIZE) - logical :: root_proc=.true. - - real, parameter :: nan = O'17760000000' - real, parameter :: fmin= 1.e-4 ! ignore vegetation fractions at or below this value - integer, parameter :: OutUnit = 40, InUnit = 50 - - ! =============================================================================================== - ! Below hard-wired ldas restart file is from a global offline simulation on the SMAP M09 grid - ! after 1000s of years of simulations - - integer, parameter :: ntiles_cn = 1684725 - character(len=300), parameter :: & - InCNRestart = '/discover/nobackup/projects/gmao/ssd/land/l_data/LandRestarts_for_Regridding/CatchCN/M09/20151231/catchcn_internal_rst', & - InCNTilFile = '/discover/nobackup/projects/gmao/bcs_shared/legacy_bcs/Icarus-NLv3/Icarus-NLv3_EASE/SMAP_EASEv2_M09/SMAP_EASEv2_M09_3856x1624.til' - - character(len=256), parameter :: CatNames (57) = & - (/'BF1 ','BF2 ','BF3 ','VGWMAX ','CDCR1 ', & - 'CDCR2 ','PSIS ','BEE ','POROS ','WPWET ', & - 'COND ','GNU ','ARS1 ','ARS2 ','ARS3 ', & - 'ARA1 ','ARA2 ','ARA3 ','ARA4 ','ARW1 ', & - 'ARW2 ','ARW3 ','ARW4 ','TSA1 ','TSA2 ', & - 'TSB1 ','TSB2 ','ATAU ','BTAU ','OLD_ITY', & - 'TC ','QC ','CAPAC ','CATDEF ','RZEXC ', & - 'SRFEXC ','GHTCNT1','GHTCNT2','GHTCNT3','GHTCNT4', & - 'GHTCNT5','GHTCNT6','TSURF ','WESNN1 ','WESNN2 ', & - 'WESNN3 ','HTSNNN1','HTSNNN2','HTSNNN3','SNDZN1 ', & - 'SNDZN2 ','SNDZN3 ','CH ','CM ','CQ ', & - 'FR ','WW '/) - - character(len=256), parameter :: CarbNames (68) = & - (/'BF1 ','BF2 ','BF3 ','VGWMAX ','CDCR1 ', & - 'CDCR2 ','PSIS ','BEE ','POROS ','WPWET ', & - 'COND ','GNU ','ARS1 ','ARS2 ','ARS3 ', & - 'ARA1 ','ARA2 ','ARA3 ','ARA4 ','ARW1 ', & - 'ARW2 ','ARW3 ','ARW4 ','TSA1 ','TSA2 ', & - 'TSB1 ','TSB2 ','ATAU ','BTAU ','ITY ', & - 'FVG ','TC ','QC ','TG ','CAPAC ', & - 'CATDEF ','RZEXC ','SRFEXC ','GHTCNT1','GHTCNT2', & - 'GHTCNT3','GHTCNT4','GHTCNT5','GHTCNT6','TSURF ', & - 'WESNN1 ','WESNN2 ','WESNN3 ','HTSNNN1','HTSNNN2', & - 'HTSNNN3','SNDZN1 ','SNDZN2 ','SNDZN3 ','CH ', & - 'CM ','CQ ','FR ','WW ','TILE_ID', & - 'NDEP ','CLI_T2M','BGALBVR','BGALBVF','BGALBNR', & - 'BGALBNF','CNCOL ','CNPFT ' /) - - integer :: AGCM_YY, AGCM_MM, AGCM_DD, AGCM_HR - - character*256 :: DataDir="OutData/clsm/" - character*256 :: Usage="mk_CatchCNRestarts OutTileFile InTileFile InRestart SURFLAY RestartTime" - character*256 :: OutTileFile, InTileFile, InRestart, arg(6), OutFileName - character*10 :: RestartTime - - logical :: clsmcn_file = .true., RegridSMAP = .false. - logical :: havedata - integer :: i, i1, iargc, n, k, ncatch,ntiles,ntiles_in, filetype, rc, nVars, req, infos, STATUS - integer, pointer :: Id(:), id_loc(:), tid_in(:) - real, pointer :: loni(:),lono(:), lati(:), lato(:) , lonn(:), latt(:) - real :: SURFLAY - type(Netcdf4_Fileformatter) :: InFmt,OutFmt - type(FileMetadata) :: InCfg,OutCfg - integer, allocatable :: low_ind(:), upp_ind(:), nt_local (:) - character(256) :: Iam = "mk_CatchCNRestarts" - - call init_MPI() - call MPI_Info_create(infos, STATUS) ; VERIFY_(STATUS) - call MPI_Info_set(infos, "romio_cb_read", "automatic", STATUS) ; VERIFY_(STATUS) - call MPI_Barrier(MPI_COMM_WORLD, STATUS) - - !----------------------------------------------------- - ! Read command-line arguments, file names (inRestart, - ! inTile, outTile), determine file format, and BCs - ! availability. - !----------------------------------------------------- - - call ESMF_Initialize(LogKindFlag=ESMF_LOGKIND_NONE) - - I = iargc() - - if( I /=5 ) then - print *, "Wrong Number of arguments: ", i - print *, trim(Usage) - stop - end if - - do n=1,I - call getarg(n,arg(n)) - enddo - - read(arg(1),'(a)') OutTileFile - read(arg(2),'(a)') InTileFile - read(arg(3),'(a)') InRestart - read(arg(4),*) SURFLAY - read(arg(5),'(a)') RestartTime - - if (SURFLAY.ne.20 .and. SURFLAY.ne.50) then - print *, "You must supply a valid SURFLAY value:" - print *, "(Ganymed-3 and earlier) SURFLAY=20.0 for Old Soil Params" - print *, "(Ganymed-4 and later ) SURFLAY=50.0 for New Soil Params" - call exit(2) - end if - - ! Are BCs data available? - ! ----------------------- - - inquire(file=trim(DataDir)//"CLM_veg_typs_fracs",exist=havedata) - - ! Reading restart time stamp and constructing daylength array - ! ----------------------------------------------------------- - read (RestartTime (1: 4), '(i4)', IOSTAT = K) AGCM_YY ; VERIFY_(K) - read (RestartTime (5: 6), '(i2)', IOSTAT = K) AGCM_MM ; VERIFY_(K) - read (RestartTime (7: 8), '(i2)', IOSTAT = K) AGCM_DD ; VERIFY_(K) - read (RestartTime (9:10), '(i2)', IOSTAT = K) AGCM_HR ; VERIFY_(K) - - MPI_PROC0 : if (root_proc) then - - ! Read Output/Input .til files - call ReadTileFile_RealLatLon(OutTileFile, ntiles, xlon=lono, xlat=lato) - call ReadTileFile_RealLatLon(InTileFile,ntiles_in,xlon=loni, xlat=lati) - allocate(Id (ntiles)) - - ! ------------------------------------------------ - ! create output catchcn_internal_rst in nc4 format - ! ------------------------------------------------ - - call InFmt%open('/discover/nobackup/projects/gmao/ssd/land/l_data/LandRestarts_for_Regridding/CatchCN/catchcn_internal_dummy',pFIO_READ, __RC__) - InCfg=InFmt%read( __RC__) - call MAPL_IOCountNonDimVars(InCfg,nvars, __RC__) - call MAPL_IOChangeRes(InCfg,OutCfg,(/'tile'/),(/ntiles/),__RC__) - i = index(InRestart,'/',back=.true.) - OutFileName = "OutData/"//trim(InRestart(i+1:)) - call OutFmt%create(OutFileName, __RC__) - call OutFmt%write(OutCfg, __RC__) - i1= index(InRestart,'/',back=.true.) - i = index(InRestart,'catchcn',back=.true.) - - endif MPI_PROC0 - - call MPI_Barrier(MPI_COMM_WORLD, mpierr) - call MPI_BCAST(NTILES , 1, MPI_INTEGER , 0,MPI_COMM_WORLD,mpierr) ; VERIFY_(mpierr) - call MPI_BCAST(NTILES_IN, 1, MPI_INTEGER , 0,MPI_COMM_WORLD,mpierr) ; VERIFY_(mpierr) - - HAVE_DATA :if(havedata) then - - ! OPT3 - ! ---- - ! Get number of catchments - ! ------------------------ - - open(unit=22, & - file=trim(DataDir)//"catchment.def",status='old',form='formatted') - - read(22,*) ncatch - - close(22) - - if(ncatch /= ntiles) then - print *, "Number of tiles in BCs data, ",Ncatch," does not match number in OutTile file ", NTILES - print *, trim(OutTileFile) - stop - endif - - if(ntiles_in /= ntiles) then - print *, "HAVEDATA : Number of tiles in InTileFile, ",NTILES_IN," does not match number in OutTileFile ", NTILES - print *, trim ( InTileFile) - print *, trim (OutTileFile) - stop - endif - - allocate (Id(ntiles)) - - do i = 1,ntiles - id (i) = i ! Just one-to-one mapping - end do - RegridSMAP = .true. - - !OPT3 (Reading/writing BCs/hydrological variables) - - if (root_proc) call read_bcs_data (ntiles, SURFLAY, OutFmt, InRestart, __RC__) - - else - - ! What is the format of the InRestart file? - ! ----------------------------------------- - - call MAPL_NCIOGetFileType(InRestart, filetype, __RC__) - - if (filetype /= 0) then - - ! OPT2 (filetype =/ 0: a binary file must be a catch_internal_rst) - ! ---- - clsmcn_file = .false. - - open(unit=InUnit,FILE=InRestart,form='unformatted', & - status='old',convert='little_endian') - - else - - ! filetype = 0 : nc4, could be catch_internal_rst or catchcn_internal_rst - ! check nVars: if nVars > 57 OPT1 (catchcn_internal_rst) ; else OPT2 (catch_internal_rst) - ! --------------------------------------------------------------------------------------- - - call InFmt%open(InRestart,pFIO_READ, __RC__) - InCfg = InFmt%read(__RC__) - call InFmt%close() - - call MAPL_IOCountNonDimVars(InCfg,nvars) - - if(nVars == 57) clsmcn_file = .false. - - endif - - CATCHCN: if (clsmcn_file) then - - ! OPT1 - ! ---- - - ! ---------------------------------------------------- - ! INPUT/OUTPUT Mapping since InTileFile =/ OutTileFile - ! ---------------------------------------------------- - - if(myid > 0) allocate (loni (1:ntiles_in)) - if(myid > 0) allocate (lati (1:ntiles_in)) - - allocate (tid_in (1:ntiles_in)) - do n = 1, NTILES_IN - tid_in (n) = n - end do - - call MPI_BCAST(loni,ntiles_in,MPI_REAL,0,MPI_COMM_WORLD,mpierr) - call MPI_BCAST(lati,ntiles_in,MPI_REAL,0,MPI_COMM_WORLD,mpierr) - call MPI_Barrier(MPI_COMM_WORLD, mpierr) - - ! Now mapping (Id) - ! ---------------- - - allocate (Id(ntiles)) ! Id contains corresponding InTileID after mapping InTiles on to OutTile - ! call GetIds(loni,lati,lono,lato,zoom,Id) - allocate(low_ind ( numprocs)) - allocate(upp_ind ( numprocs)) - allocate(nt_local( numprocs)) - low_ind (:) = 1 - upp_ind (:) = NTILES - nt_local(:) = NTILES - - ! Domain decomposition - ! -------------------- - - if (numprocs > 1) then - do i = 1, numprocs - 1 - upp_ind(i) = low_ind(i) + (ntiles/numprocs) - 1 - low_ind(i+1) = upp_ind(i) + 1 - nt_local(i) = upp_ind(i) - low_ind(i) + 1 - end do - nt_local(numprocs) = upp_ind(numprocs) - low_ind(numprocs) + 1 - endif - - ! Get out tile lat/lots from root - - allocate (id_loc (nt_local (myid + 1))) - allocate (lonn (nt_local (myid + 1))) - allocate (latt (nt_local (myid + 1))) - - do i = 1, numprocs - if((I == 1).and.(myid == 0)) then - lonn(:) = lono(low_ind(i) : upp_ind(i)) - latt(:) = lato(low_ind(i) : upp_ind(i)) - else if (I > 1) then - if(I-1 == myid) then - ! receiving from root - - call MPI_RECV(lonn,nt_local(i) , MPI_REAL, 0,995,MPI_COMM_WORLD,MPI_STATUS_IGNORE,mpierr) - call MPI_RECV(latt,nt_local(i) , MPI_REAL, 0,994,MPI_COMM_WORLD,MPI_STATUS_IGNORE,mpierr) - else if (myid == 0) then - ! root sends - - call MPI_ISend(lono(low_ind(i) : upp_ind(i)),nt_local(i),MPI_REAL,i-1,995,MPI_COMM_WORLD,req,mpierr) - call MPI_WAIT (req,MPI_STATUS_IGNORE,mpierr) - call MPI_ISend(lato(low_ind(i) : upp_ind(i)),nt_local(i),MPI_REAL,i-1,994,MPI_COMM_WORLD,req,mpierr) - call MPI_WAIT (req,MPI_STATUS_IGNORE,mpierr) - endif - endif - end do - - call GetIds(loni,lati,lonn,latt,id_loc, tid_in) - call MPI_Barrier(MPI_COMM_WORLD, mpierr) - - do i = 1, numprocs - if((I == 1).and.(myid == 0)) then - id(low_ind(i) : upp_ind(i)) = Id_loc(:) - else if (I > 1) then - if(I-1 == myid) then - ! send to root - call MPI_ISend(id_loc,nt_local(i),MPI_INTEGER,0,993,MPI_COMM_WORLD,req,mpierr) - call MPI_WAIT (req,MPI_STATUS_IGNORE,mpierr) - else if (myid == 0) then - ! root receives - call MPI_RECV(id(low_ind(i) : upp_ind(i)),nt_local(i) , MPI_INTEGER, i-1,993,MPI_COMM_WORLD,MPI_STATUS_IGNORE,mpierr) - endif - endif - end do - - if(root_proc) deallocate (lono, lato,lonn,latt, tid_in) - - deallocate (loni,lati) - - - if (root_proc) call read_catchcn_nc4 (NTILES_IN, NTILES, OutFmt, ID, InRestart, __RC__) - - else - - call regrid_hyd_vars (NTILES, OutFmt) - - ! OPT2 - ! ---- - ! NC4ORBIN: if(filetype ==0) then - ! - ! call read_catch_nc4 (NTILES_IN, NTILES, OutFmt, ID, InRestart) - ! - ! else - ! - ! call read_catch_bin (NTILES_IN, NTILES, OutFmt, ID) - ! - ! endif NC4ORBIN - - endif CATCHCN - - endif HAVE_DATA - - if (root_proc) then - - ! ----------------- - ! BEGIN THE PROCESS - ! ----------------- - - print *, " " - print *, "**********************************************************************" - print *, " " - print *, "mk_CatchCNRestarts Configuration" - print *, "--------------------------------" - print *, " " - print '(A22, i4.4,i2.2,i2.2,i2.2)', " Restart Time :",AGCM_YY,AGCM_MM,AGCM_DD,AGCM_HR - print *, 'SURFLAY : ',SURFLAY - print *, 'Have BCs data : ',havedata - print *, "# of tiles in InTile : ",ntiles_in - print *, "# of tiles in OutTile: ",ntiles - - if(clsmcn_file) then - print *,"InRestart is from : Catchment-carbon AGCM simulation" - else - InRestart = trim(InCNRestart) - print *,"InRestart is from : offline SMAP_EASEv2_M09" - endif - - print *, "InRestart filename : ",trim(InRestart) - print *, "OutRestart filename : ",trim(OutFileName) - print *, "OutRestart file fmt : nc4" - print *, " " - print *, "**********************************************************************" - print *, " " - - endif - - call MPI_BCAST(OutFileName , 256, MPI_CHARACTER, 0,MPI_COMM_WORLD,mpierr) - call MPI_Barrier(MPI_COMM_WORLD, mpierr) - - if (RegridSMAP) then - ntiles_in = ntiles_cn - !OPT3 (carbon variables from offline SMAP M09) - call regrid_carbon_vars (NTILES,AGCM_YY,AGCM_MM,AGCM_DD,AGCM_HR, OutFileName, OutTileFile) - ! call regrid_carbon_vars_omp (NTILES,AGCM_YY,AGCM_MM,AGCM_DD,AGCM_HR, OutFileName, OutTileFile) - - endif -call MPI_BARRIER( MPI_COMM_WORLD, mpierr) -call ESMF_Finalize(endflag=ESMF_END_KEEPMPI) -call MPI_FINALIZE(mpierr) - -contains - - ! ***************************************************************************** - - SUBROUTINE read_bcs_data (ntiles, SURFLAY, OutFmt, InRestart, rc) - - ! This subroutine : - ! 1) reads BCs from BCSDIR and hydrological varables from InRestart. - ! InRestart is a catchcn_internal_rst nc4 file. - ! - ! 2) writes out BCs and hydrological variables in catchcn_internal_rst (1:72). - ! output catchcn_internal_rst is nc4. - - implicit none - real, intent (in) :: SURFLAY - integer, intent (in) :: ntiles - character (*), intent (in) :: InRestart - type(Netcdf4_Fileformatter), intent (inout) :: OutFmt - integer, optional, intent(out) :: rc - - real, allocatable :: CLMC_pf1(:), CLMC_pf2(:), CLMC_sf1(:), CLMC_sf2(:) - real, allocatable :: CLMC_pt1(:), CLMC_pt2(:), CLMC_st1(:), CLMC_st2(:) - real, allocatable :: BF1(:), BF2(:), BF3(:), VGWMAX(:) - real, allocatable :: CDCR1(:), CDCR2(:), PSIS(:), BEE(:) - real, allocatable :: POROS(:), WPWET(:), COND(:), GNU(:) - real, allocatable :: ARS1(:), ARS2(:), ARS3(:) - real, allocatable :: ARA1(:), ARA2(:), ARA3(:), ARA4(:) - real, allocatable :: ARW1(:), ARW2(:), ARW3(:), ARW4(:) - real, allocatable :: TSA1(:), TSA2(:), TSB1(:), TSB2(:) - real, allocatable :: ATAU2(:), BTAU2(:), DP2BR(:), rity(:), CanopH(:) - real, allocatable :: NDEP(:), BVISDR(:), BVISDF(:), BNIRDR(:), BNIRDF(:) - real, allocatable :: T2(:), var1(:) - integer, allocatable :: ity(:) - character*256 :: vname - character*256 :: DataDir="OutData/clsm/" - integer :: idum, i,j,n, ib, nv - real :: rdum, zdep1, zdep2, zdep3, zmet, term1, term2, bare,fvg(4) - logical :: file_exists - type(Netcdf4_Fileformatter) :: InFmt,CatchCNFmt, CatchFmt - integer :: status - - allocate ( BF1(ntiles), BF2 (ntiles), BF3(ntiles) ) - allocate (VGWMAX(ntiles), CDCR1(ntiles), CDCR2(ntiles) ) - allocate ( PSIS(ntiles), BEE(ntiles), POROS(ntiles) ) - allocate ( WPWET(ntiles), COND(ntiles), GNU(ntiles) ) - allocate ( ARS1(ntiles), ARS2(ntiles), ARS3(ntiles) ) - allocate ( ARA1(ntiles), ARA2(ntiles), ARA3(ntiles) ) - allocate ( ARA4(ntiles), ARW1(ntiles), ARW2(ntiles) ) - allocate ( ARW3(ntiles), ARW4(ntiles), TSA1(ntiles) ) - allocate ( TSA2(ntiles), TSB1(ntiles), TSB2(ntiles) ) - allocate ( ATAU2(ntiles), BTAU2(ntiles), DP2BR(ntiles) ) - allocate (BVISDR(ntiles), BVISDF(ntiles), BNIRDR(ntiles) ) - allocate (BNIRDF(ntiles), T2(ntiles), NDEP(ntiles) ) - allocate ( ity(ntiles), rity(ntiles), CanopH(ntiles)) - allocate (CLMC_pf1(ntiles), CLMC_pf2(ntiles), CLMC_sf1(ntiles)) - allocate (CLMC_sf2(ntiles), CLMC_pt1(ntiles), CLMC_pt2(ntiles)) - allocate (CLMC_st1(ntiles), CLMC_st2(ntiles)) - - inquire(file = trim(DataDir)//'/catchcn_params.nc4', exist=file_exists) - - if(file_exists) then - - print *,'FILE FORMAT FOR LAND BCS IS NC4' - call CatchFmt%open(trim(DataDir)//'/catch_params.nc4',pFIO_READ, __RC__) - call CatchCNFmt%open(trim(DataDir)//'/catchcn_params.nc4',pFIO_READ, __RC__) - call MAPL_VarRead ( CatchFmt ,'OLD_ITY', rity, __RC__) - call MAPL_VarRead ( CatchFmt ,'ARA1', ARA1, __RC__) - call MAPL_VarRead ( CatchFmt ,'ARA2', ARA2, __RC__) - call MAPL_VarRead ( CatchFmt ,'ARA3', ARA3, __RC__) - call MAPL_VarRead ( CatchFmt ,'ARA4', ARA4, __RC__) - call MAPL_VarRead ( CatchFmt ,'ARS1', ARS1, __RC__) - call MAPL_VarRead ( CatchFmt ,'ARS2', ARS2, __RC__) - call MAPL_VarRead ( CatchFmt ,'ARS3', ARS3, __RC__) - call MAPL_VarRead ( CatchFmt ,'ARW1', ARW1, __RC__) - call MAPL_VarRead ( CatchFmt ,'ARW2', ARW2, __RC__) - call MAPL_VarRead ( CatchFmt ,'ARW3', ARW3, __RC__) - call MAPL_VarRead ( CatchFmt ,'ARW4', ARW4, __RC__) - - if( SURFLAY.eq.20.0 ) then - call MAPL_VarRead ( CatchFmt ,'ATAU2', ATAU2, __RC__) - call MAPL_VarRead ( CatchFmt ,'BTAU2', BTAU2, __RC__) - endif - - if( SURFLAY.eq.50.0 ) then - call MAPL_VarRead ( CatchFmt ,'ATAU5', ATAU2, __RC__) - call MAPL_VarRead ( CatchFmt ,'BTAU5', BTAU2, __RC__) - endif - - call MAPL_VarRead ( CatchFmt ,'PSIS', PSIS, __RC__) - call MAPL_VarRead ( CatchFmt ,'BEE', BEE, __RC__) - call MAPL_VarRead ( CatchFmt ,'BF1', BF1, __RC__) - call MAPL_VarRead ( CatchFmt ,'BF2', BF2, __RC__) - call MAPL_VarRead ( CatchFmt ,'BF3', BF3, __RC__) - call MAPL_VarRead ( CatchFmt ,'TSA1', TSA1, __RC__) - call MAPL_VarRead ( CatchFmt ,'TSA2', TSA2, __RC__) - call MAPL_VarRead ( CatchFmt ,'TSB1', TSB1, __RC__) - call MAPL_VarRead ( CatchFmt ,'TSB2', TSB2, __RC__) - call MAPL_VarRead ( CatchFmt ,'COND', COND, __RC__) - call MAPL_VarRead ( CatchFmt ,'GNU', GNU, __RC__) - call MAPL_VarRead ( CatchFmt ,'WPWET', WPWET, __RC__) - call MAPL_VarRead ( CatchFmt ,'DP2BR', DP2BR, __RC__) - call MAPL_VarRead ( CatchFmt ,'POROS', POROS, __RC__) - call MAPL_VarRead ( CatchCNFmt ,'BGALBNF', BNIRDF, __RC__) - call MAPL_VarRead ( CatchCNFmt ,'BGALBNR', BNIRDR, __RC__) - call MAPL_VarRead ( CatchCNFmt ,'BGALBVF', BVISDF, __RC__) - call MAPL_VarRead ( CatchCNFmt ,'BGALBVR', BVISDR, __RC__) - call MAPL_VarRead ( CatchCNFmt ,'NDEP', NDEP, __RC__) - call MAPL_VarRead ( CatchCNFmt ,'T2_M', T2, __RC__) - call MAPL_VarRead(CatchCNFmt,'ITY',CLMC_pt1,offset1=1, __RC__) ! 30 - call MAPL_VarRead(CatchCNFmt,'ITY',CLMC_pt2,offset1=2, __RC__) ! 31 - call MAPL_VarRead(CatchCNFmt,'ITY',CLMC_st1,offset1=3, __RC__) ! 32 - call MAPL_VarRead(CatchCNFmt,'ITY',CLMC_st2,offset1=4, __RC__) ! 33 - call MAPL_VarRead(CatchCNFmt,'FVG',CLMC_pf1,offset1=1, __RC__) ! 34 - call MAPL_VarRead(CatchCNFmt,'FVG',CLMC_pf2,offset1=2, __RC__) ! 35 - call MAPL_VarRead(CatchCNFmt,'FVG',CLMC_sf1,offset1=3, __RC__) ! 36 - call MAPL_VarRead(CatchCNFmt,'FVG',CLMC_sf2,offset1=4, __RC__) ! 37 - call CatchFmt%close() - call CatchCNFmt%close() - - else - - open(unit=22, & - file=trim(DataDir)//"mosaic_veg_typs_fracs",status='old',form='formatted') - - do N=1,ntiles - read(22,*) I, j, ITY(N),idum, rdum, rdum, CanopH(N) - enddo - - rity(:) = float(ity) - - close(22) - - open(unit=22, file=trim(DataDir)//'bf.dat' ,form='formatted') - open(unit=23, file=trim(DataDir)//'soil_param.dat' ,form='formatted') - open(unit=24, file=trim(DataDir)//'ar.new' ,form='formatted') - open(unit=25, file=trim(DataDir)//'ts.dat' ,form='formatted') - open(unit=26, file=trim(DataDir)//'tau_param.dat' ,form='formatted') - open(unit=27, file=trim(DataDir)//'CLM_veg_typs_fracs' ,form='formatted') - open(unit=28, file=trim(DataDir)//'CLM_NDep_SoilAlb_T2m' ,form='formatted') - - do n=1,ntiles - read (22, *) i,j, GNU(n), BF1(n), BF2(n), BF3(n) - - read (23, *) i,j, idum, idum, BEE(n), PSIS(n),& - POROS(n), COND(n), WPWET(n), DP2BR(n) - - read (24, *) i,j, rdum, ARS1(n), ARS2(n), ARS3(n), & - ARA1(n), ARA2(n), ARA3(n), ARA4(n), & - ARW1(n), ARW2(n), ARW3(n), ARW4(n) - - read (25, *) i,j, rdum, TSA1(n), TSA2(n), TSB1(n), TSB2(n) - - if( SURFLAY.eq.20.0 ) read (26, *) i,j, ATAU2(n), BTAU2(n), rdum, rdum ! for old soil params - if( SURFLAY.eq.50.0 ) read (26, *) i,j, rdum , rdum, ATAU2(n), BTAU2(n) ! for new soil params - - read (27, *) i,j, CLMC_pt1(n), CLMC_pt2(n), CLMC_st1(n), CLMC_st2(n), & - CLMC_pf1(n), CLMC_pf2(n), CLMC_sf1(n), CLMC_sf2(n) - - read (28, *) NDEP(n), BVISDR(n), BVISDF(n), BNIRDR(n), BNIRDF(n), T2(n) ! MERRA-2 Annual Mean Temp is default. - - end do - - CLOSE (22, STATUS = 'KEEP') - CLOSE (23, STATUS = 'KEEP') - CLOSE (24, STATUS = 'KEEP') - CLOSE (25, STATUS = 'KEEP') - CLOSE (26, STATUS = 'KEEP') - CLOSE (27, STATUS = 'KEEP') - CLOSE (28, STATUS = 'KEEP') - - endif - - do n=1,ntiles - - BVISDR(n) = amax1(1.e-6, BVISDR(n)) - BVISDF(n) = amax1(1.e-6, BVISDF(n)) - BNIRDR(n) = amax1(1.e-6, BNIRDR(n)) - BNIRDF(n) = amax1(1.e-6, BNIRDF(n)) - - zdep2=1000. - zdep3=amax1(1000.,DP2BR(n)) - - if (zdep2 .gt.0.75*zdep3) then - zdep2 = 0.75*zdep3 - end if - - zdep1=20. - zmet=zdep3/1000. - - term1=-1.+((PSIS(n)-zmet)/PSIS(n))**((BEE(n)-1.)/BEE(n)) - term2=PSIS(n)*BEE(n)/(BEE(n)-1) - - VGWMAX(n) = POROS(n)*zdep2 - CDCR1(n) = 1000.*POROS(n)*(zmet-(-term2*term1)) - CDCR2(n) = (1.-WPWET(n))*POROS(n)*zdep3 - - ! convert % to fractions - - CLMC_pf1(n) = CLMC_pf1(n) / 100. - CLMC_pf2(n) = CLMC_pf2(n) / 100. - CLMC_sf1(n) = CLMC_sf1(n) / 100. - CLMC_sf2(n) = CLMC_sf2(n) / 100. - - fvg(1) = CLMC_pf1(n) - fvg(2) = CLMC_pf2(n) - fvg(3) = CLMC_sf1(n) - fvg(4) = CLMC_sf2(n) - - BARE = 1. - - DO NV = 1, NVEG - BARE = BARE - FVG(NV)! subtract vegetated fractions - END DO - - if (BARE /= 0.) THEN - IB = MAXLOC(FVG(:),1) - FVG (IB) = FVG(IB) + BARE ! This also corrects all cases sum ne 0. - ENDIF - - CLMC_pf1(n) = fvg(1) - CLMC_pf2(n) = fvg(2) - CLMC_sf1(n) = fvg(3) - CLMC_sf2(n) = fvg(4) - - enddo - - NDEP = NDEP * 1.e-9 - -! prevent trivial fractions -! ------------------------- - do n = 1,ntiles - if(CLMC_pf1(n) <= 1.e-4) then - CLMC_pf2(n) = CLMC_pf2(n) + CLMC_pf1(n) - CLMC_pf1(n) = 0. - endif - - if(CLMC_pf2(n) <= 1.e-4) then - CLMC_pf1(n) = CLMC_pf1(n) + CLMC_pf2(n) - CLMC_pf2(n) = 0. - endif - - if(CLMC_sf1(n) <= 1.e-4) then - if(CLMC_sf2(n) > 1.e-4) then - CLMC_sf2(n) = CLMC_sf2(n) + CLMC_sf1(n) - else if(CLMC_pf2(n) > 1.e-4) then - CLMC_pf2(n) = CLMC_pf2(n) + CLMC_sf1(n) - else if(CLMC_pf1(n) > 1.e-4) then - CLMC_pf1(n) = CLMC_pf1(n) + CLMC_sf1(n) - else - stop 'fveg3' - endif - CLMC_sf1(n) = 0. - endif - - if(CLMC_sf2(n) <= 1.e-4) then - if(CLMC_sf1(n) > 1.e-4) then - CLMC_sf1(n) = CLMC_sf1(n) + CLMC_sf2(n) - else if(CLMC_pf2(n) > 1.e-4) then - CLMC_pf2(n) = CLMC_pf2(n) + CLMC_sf2(n) - else if(CLMC_pf1(n) > 1.e-4) then - CLMC_pf1(n) = CLMC_pf1(n) + CLMC_sf2(n) - else - stop 'fveg4' - endif - CLMC_sf2(n) = 0. - endif - end do - - - - ! Now writing BCs (from BCSDIR) and regridded hydrological variables 1-72 - ! ----------------------------------------------------------------------- - - call InFmt%open(InRestart,pFIO_READ, __RC__) - - call MAPL_VarWrite(OutFmt,trim(CarbNames(1)),BF1) ! 1 - call MAPL_VarWrite(OutFmt,trim(CarbNames(2)),BF2) ! 2 - call MAPL_VarWrite(OutFmt,trim(CarbNames(3)),BF3) ! 3 - call MAPL_VarWrite(OutFmt,trim(CarbNames(4)),VGWMAX) ! 4 - call MAPL_VarWrite(OutFmt,trim(CarbNames(5)),CDCR1) ! 5 - call MAPL_VarWrite(OutFmt,trim(CarbNames(6)),CDCR2) ! 6 - call MAPL_VarWrite(OutFmt,trim(CarbNames(7)),PSIS) ! 7 - call MAPL_VarWrite(OutFmt,trim(CarbNames(8)),BEE) ! 8 - call MAPL_VarWrite(OutFmt,trim(CarbNames(9)),POROS) ! 9 - call MAPL_VarWrite(OutFmt,trim(CarbNames(10)),WPWET) ! 10 - call MAPL_VarWrite(OutFmt,trim(CarbNames(11)),COND) ! 11 - call MAPL_VarWrite(OutFmt,trim(CarbNames(12)),GNU) ! 12 - call MAPL_VarWrite(OutFmt,trim(CarbNames(13)),ARS1) ! 13 - call MAPL_VarWrite(OutFmt,trim(CarbNames(14)),ARS2) ! 14 - call MAPL_VarWrite(OutFmt,trim(CarbNames(15)),ARS3) ! 15 - call MAPL_VarWrite(OutFmt,trim(CarbNames(16)),ARA1) ! 16 - call MAPL_VarWrite(OutFmt,trim(CarbNames(17)),ARA2) ! 17 - call MAPL_VarWrite(OutFmt,trim(CarbNames(18)),ARA3) ! 18 - call MAPL_VarWrite(OutFmt,trim(CarbNames(19)),ARA4) ! 19 - call MAPL_VarWrite(OutFmt,trim(CarbNames(20)),ARW1) ! 20 - call MAPL_VarWrite(OutFmt,trim(CarbNames(21)),ARW2) ! 21 - call MAPL_VarWrite(OutFmt,trim(CarbNames(22)),ARW3) ! 22 - call MAPL_VarWrite(OutFmt,trim(CarbNames(23)),ARW4) ! 23 - call MAPL_VarWrite(OutFmt,trim(CarbNames(24)),TSA1) ! 24 - call MAPL_VarWrite(OutFmt,trim(CarbNames(25)),TSA2) ! 25 - call MAPL_VarWrite(OutFmt,trim(CarbNames(26)),TSB1) ! 26 - call MAPL_VarWrite(OutFmt,trim(CarbNames(27)),TSB2) ! 27 - call MAPL_VarWrite(OutFmt,trim(CarbNames(28)),ATAU2) ! 28 - call MAPL_VarWrite(OutFmt,trim(CarbNames(29)),BTAU2) ! 29 - call MAPL_VarWrite(OutFmt,'ITY',CLMC_pt1,offset1=1) ! 30 - call MAPL_VarWrite(OutFmt,'ITY',CLMC_pt2,offset1=2) ! 31 - call MAPL_VarWrite(OutFmt,'ITY',CLMC_st1,offset1=3) ! 32 - call MAPL_VarWrite(OutFmt,'ITY',CLMC_st2,offset1=4) ! 33 - call MAPL_VarWrite(OutFmt,'FVG',CLMC_pf1,offset1=1) ! 34 - call MAPL_VarWrite(OutFmt,'FVG',CLMC_pf2,offset1=2) ! 35 - call MAPL_VarWrite(OutFmt,'FVG',CLMC_sf1,offset1=3) ! 36 - call MAPL_VarWrite(OutFmt,'FVG',CLMC_sf2,offset1=4) ! 37 - - allocate(var1(ntiles)) - - ! TC QC TG - - do n = 38,40 - if(n == 38) vname = 'TC' - if(n == 39) vname = 'QC' - if(n == 40) vname = 'TG' - do j = 1,4 - call MAPL_VarRead ( InFmt,vname,var1 ,offset1=j, __RC__) - call MAPL_VarWrite(OutFmt,vname,var1 ,offset1=j) ! 38-40 - end do - end do - - ! CAPAC CATDEF RZEXC SRFEXC ... SNDZN3 - - do n=41,60 - call MAPL_VarRead ( InFmt,trim(CarbNames(n-6)),var1, __RC__) - call MAPL_VarWrite(OutFmt,trim(CarbNames(n-6)),var1) ! 41-60 - enddo - - ! CH CM CQ FR WW - var1 = 0. - - do n=61,65 - if((n >= 61).AND.(n <= 63)) var1 = 1.e-3 - if(n == 64) var1 = 0.25 - if(n == 65) var1 = 0.1 - do j = 1,4 - - call MAPL_VarRead ( InFmt,trim(CarbNames(n-6)),var1 ,offset1=j, __RC__) - call MAPL_VarWrite(OutFmt,trim(CarbNames(n-6)),var1 ,offset1=j) ! 61-65 - end do - end do - - do i=1,ntiles - var1(i) = real(i) - end do - - call MAPL_VarWrite(OutFmt,'TILE_ID',var1 ) ! 66 : cat_id - call MAPL_VarWrite(OutFmt,'NDEP' ,NDEP ) ! 67 : ndep - call MAPL_VarWrite(OutFmt,'CLI_T2M',T2 ) ! 68 : cli_t2m - call MAPL_VarWrite(OutFmt,'BGALBVR',BVISDR) ! 69 : BGALBVR - call MAPL_VarWrite(OutFmt,'BGALBVF',BVISDF) ! 70 : BGALBVF - call MAPL_VarWrite(OutFmt,'BGALBNR',BNIRDR) ! 71 : BGALBNR - call MAPL_VarWrite(OutFmt,'BGALBNF',BNIRDF) ! 72 : BGALBNF - - deallocate (var1) - call InFmt%close() - call OutFmt%close() - -! Vegdyn Boundary Condition -! ------------------------- -! -! open(20,file=trim("OutData/vegdyn_internal_rst"), & -! status="unknown", & -! form="unformatted",convert="little_endian") -! write(20) rity -! write(20) CanopH -! close(20) -! print *, "Wrote vegdyn_internal_restart" - - deallocate ( BF1, BF2, BF3 ) - deallocate (VGWMAX, CDCR1, CDCR2 ) - deallocate ( PSIS, BEE, POROS ) - deallocate ( WPWET, COND, GNU ) - deallocate ( ARS1, ARS2, ARS3 ) - deallocate ( ARA1, ARA2, ARA3 ) - deallocate ( ARA4, ARW1, ARW2 ) - deallocate ( ARW3, ARW4, TSA1 ) - deallocate ( TSA2, TSB1, TSB2 ) - deallocate ( ATAU2, BTAU2, DP2BR ) - deallocate (BVISDR, BVISDF, BNIRDR ) - deallocate (BNIRDF, T2, NDEP ) - deallocate ( ity, rity, CanopH) - deallocate (CLMC_pf1, CLMC_pf2, CLMC_sf1) - deallocate (CLMC_sf2, CLMC_pt1, CLMC_pt2) - deallocate (CLMC_st1,CLMC_st2) - if (present(rc)) rc = 0 - !_RETURN(_SUCCESS) - END SUBROUTINE read_bcs_data - - ! ***************************************************************************** - - SUBROUTINE read_catchcn_nc4 (NTILES_IN, NTILES, OutFmt, IDX, InRestart, rc) - - implicit none - - ! Reads catchcn_internal_rst nc4 file, regrids every single variable and writes - ! out catchcn_internal_rst in nc4 format. - ! This subroutine is called when BCs data are not available. - - integer, intent (in) :: NTILES_IN, NTILES - character(*), intent (in) :: InRestart - type(Netcdf4_Fileformatter), intent (inout) :: OutFmt - integer, dimension (NTILES), intent (in) :: IDX - integer, optional, intent(out) :: rc - type(Netcdf4_Fileformatter) :: InFmt - type(FileMetadata) :: InCfg - integer :: n,i,j, ndims, nVars,dim1,dim2 - character(len=:), pointer :: vname - real, allocatable :: var1 (:), var2 (:) - integer, allocatable :: TILE_ID (:) - type(StringVariableMap), pointer :: variables - type(Variable), pointer :: var - type(StringVariableMapIterator) :: var_iter - type(StringVector), pointer :: var_dimensions - character(len=:), pointer :: dname - integer :: status - - call InFmt%open(InRestart,pFIO_READ, __RC__) - InCfg = InFmt%read(__RC__) - - allocate (var1 (1:NTILES_IN)) - allocate (var2 (1:NTILES_IN)) - allocate (TILE_ID (1:NTILES_IN)) - - call MAPL_VarRead ( InFmt,'TILE_ID',var1, __RC__) - do n = 1, NTILES_IN - tile_id (NINT (var1(n))) = n - end do - - variables => InCfg%get_variables() - var_iter = variables%begin() - do while (var_iter /= variables%end()) - - vname => var_iter%key() - var => var_iter%value() - var_dimensions => var%get_dimensions() - - ndims = var_dimensions%size() - - if (ndims == 1) then - call MAPL_VarRead ( InFmt,vname,var1, __RC__) - var2 = var1 (tile_id) - call MAPL_VarWrite(OutFmt,vname,var2(idx)) - - else if (ndims == 2) then - - dname => var%get_ith_dimension(2) - dim1=InCfg%get_dimension(dname) - do j=1,dim1 - call MAPL_VarRead ( InFmt,vname,var1 ,offset1=j, __RC__) - var2 = var1 (tile_id) - call MAPL_VarWrite(OutFmt,vname,var2(idx),offset1=j) - enddo - - else if (ndims == 3) then - - dname => var%get_ith_dimension(2) - dim1=InCfg%get_dimension(dname) - dname => var%get_ith_dimension(3) - dim2=InCfg%get_dimension(dname) - do i=1,dim2 - do j=1,dim1 - call MAPL_VarRead ( InFmt,vname,var1 ,offset1=j,offset2=i, __RC__) - var2 = var1 (tile_id) - call MAPL_VarWrite(OutFmt,vname,var2(idx),offset1=j,offset2=i) - enddo - enddo - - end if - - call var_iter%next() - enddo - - deallocate (var1, var2, tile_id) - call InFmt%close() - call OutFmt%close() - if (present(rc)) rc = 0 - !_RETURN(_SUCCESS) - END SUBROUTINE read_catchcn_nc4 - - ! ***************************************************************************** - - SUBROUTINE regrid_carbon_vars ( & - NTILES,AGCM_YY,AGCM_MM,AGCM_DD,AGCM_HR, OutFileName, OutTileFile) - - implicit none - character (*), intent (in) :: OutTileFile, OutFileName - integer, intent (in) :: NTILES,AGCM_YY,AGCM_MM,AGCM_DD,AGCM_HR - real, allocatable, dimension (:) :: CLMC_pf1, CLMC_pf2, CLMC_sf1, CLMC_sf2, & - CLMC_pt1, CLMC_pt2,CLMC_st1,CLMC_st2 - - ! =============================================================================================== - - integer :: iclass(npft) = (/1,1,2,3,3,4,5,5,6,7,8,9,10,11,12,11,12,11,12/) - integer, allocatable, dimension(:,:) :: Id_glb, Id_loc - integer, allocatable, dimension(:) :: tid_offl, id_vec - real, allocatable, dimension(:,:) :: fveg_offl, ityp_offl - real :: fveg_new, sub_dist - integer :: n,i,j, k, nv, nx, nz, iv, offl_cell, ityp_new, STATUS,NCFID, req - integer :: outid, local_id - integer, allocatable, dimension (:) :: sub_tid, sub_ityp1, sub_ityp2,icl_ityp1 - real , pointer, dimension (:) :: sub_lon, sub_lat, rev_dist, sub_fevg1, sub_fevg2,& - lonc, latc, LATT, LONN, DAYX, long, latg, var_dum, TILE_ID, var_dum2 - real, allocatable :: var_off_col (:,:,:), var_off_pft (:,:,:,:) - real, allocatable :: var_col_out (:,:,:), var_pft_out (:,:,:,:) - integer, allocatable :: low_ind(:), upp_ind(:), nt_local (:) - integer :: AGCM_YYY, AGCM_MMM, AGCM_DDD, AGCM_HRR, AGCM_MI, AGCM_S, dofyr - type(MAPL_SunOrbit) :: ORBIT - type(ESMF_Time) :: CURRENT_TIME - type(ESMF_TimeInterval) :: timeStep - type(ESMF_Clock) :: CLOCK - type(ESMF_Config) :: CF - - - allocate (tid_offl (ntiles_cn)) - allocate (ityp_offl (ntiles_cn,nveg)) - allocate (fveg_offl (ntiles_cn,nveg)) - - allocate(low_ind ( numprocs)) - allocate(upp_ind ( numprocs)) - allocate(nt_local( numprocs)) - - low_ind (:) = 1 - upp_ind (:) = NTILES - nt_local(:) = NTILES - - ! Domain decomposition - ! -------------------- - - if (numprocs > 1) then - do i = 1, numprocs - 1 - upp_ind(i) = low_ind(i) + (ntiles/numprocs) - 1 - low_ind(i+1) = upp_ind(i) + 1 - nt_local(i) = upp_ind(i) - low_ind(i) + 1 - end do - nt_local(numprocs) = upp_ind(numprocs) - low_ind(numprocs) + 1 - endif - - allocate (id_loc (nt_local (myid + 1),4)) - allocate (lonn (nt_local (myid + 1))) - allocate (latt (nt_local (myid + 1))) - allocate (CLMC_pf1(nt_local (myid + 1))) - allocate (CLMC_pf2(nt_local (myid + 1))) - allocate (CLMC_sf1(nt_local (myid + 1))) - allocate (CLMC_sf2(nt_local (myid + 1))) - allocate (CLMC_pt1(nt_local (myid + 1))) - allocate (CLMC_pt2(nt_local (myid + 1))) - allocate (CLMC_st1(nt_local (myid + 1))) - allocate (CLMC_st2(nt_local (myid + 1))) - allocate (lonc (1:ntiles_cn)) - allocate (latc (1:ntiles_cn)) - - if (root_proc) then - - ! -------------------------------------------- - ! Read exact lonn, latt from output .til file - ! -------------------------------------------- - - allocate (long (ntiles)) - allocate (latg (ntiles)) - allocate (DAYX (NTILES)) - - call ReadTileFile_RealLatLon (OutTileFile, i, xlon=long, xlat=latg) - - !----------------------- - ! COMPUTE DAYX - !----------------------- - - AGCM_YYY = AGCM_YY - AGCM_MMM = AGCM_MM - AGCM_DDD = AGCM_DD - AGCM_HRR = AGCM_HR - AGCM_MI = 0 - AGCM_S = 0 - - - call ESMF_CalendarSetDefault ( ESMF_CALKIND_GREGORIAN, rc=status ) - - ! get current date & time - ! ----------------------- - call ESMF_TimeSet ( CURRENT_TIME, YY = AGCM_YYY, & - MM = AGCM_MMM, & - DD = AGCM_DDD, & - H = AGCM_HRR, & - M = AGCM_MI, & - S = AGCM_S , & - rc=status ) - VERIFY_(STATUS) - - call ESMF_TimeIntervalSet(TimeStep, S=450, RC=status) - clock = ESMF_ClockCreate(TimeStep, startTime = CURRENT_TIME, RC=status) - VERIFY_(STATUS) - call ESMF_ClockSet ( clock, CurrTime=CURRENT_TIME, rc=status ) - - CF = ESMF_ConfigCreate(RC=STATUS) - VERIFY_(status) - - ORBIT = MAPL_SunOrbitCreateFromConfig(CF, CLOCK, .false., RC=status) - VERIFY_(status) - - ! compute current daylight duration - !---------------------------------- - call MAPL_SunGetDaylightDuration(ORBIT,latg,dayx,currTime=CURRENT_TIME,RC=STATUS) - VERIFY_(STATUS) - - ! --------------------------------------------- - ! Read exact lonc, latc from offline .til File - ! --------------------------------------------- - - call ReadTileFile_RealLatLon(InCNTilFile,i,xlon=lonc,xlat=latc) - - endif - -! call MPI_SCATTERV ( & -! long,nt_local,low_ind-1,MPI_real, & -! lonn,size(lonn),MPI_real , & -! 0,MPI_COMM_WORLD, mpierr ) -! -! call MPI_SCATTERV ( & -! latg,nt_local,low_ind-1,MPI_real, & -! latt,nt_local(myid+1),MPI_real , & -! 0,MPI_COMM_WORLD, mpierr ) - - do i = 1, numprocs - if((I == 1).and.(myid == 0)) then - lonn(:) = long(low_ind(i) : upp_ind(i)) - latt(:) = latg(low_ind(i) : upp_ind(i)) - else if (I > 1) then - if(I-1 == myid) then - ! receiving from root - call MPI_RECV(lonn,nt_local(i) , MPI_REAL, 0,995,MPI_COMM_WORLD,MPI_STATUS_IGNORE,mpierr) - call MPI_RECV(latt,nt_local(i) , MPI_REAL, 0,994,MPI_COMM_WORLD,MPI_STATUS_IGNORE,mpierr) - else if (myid == 0) then - ! root sends - call MPI_ISend(long(low_ind(i) : upp_ind(i)),nt_local(i),MPI_REAL,i-1,995,MPI_COMM_WORLD,req,mpierr) - call MPI_WAIT (req,MPI_STATUS_IGNORE,mpierr) - call MPI_ISend(latg(low_ind(i) : upp_ind(i)),nt_local(i),MPI_REAL,i-1,994,MPI_COMM_WORLD,req,mpierr) - call MPI_WAIT (req,MPI_STATUS_IGNORE,mpierr) - endif - endif - end do - - if(root_proc) deallocate (long, latg) - - call MPI_BCAST(lonc,ntiles_cn,MPI_REAL,0,MPI_COMM_WORLD,mpierr) - call MPI_BCAST(latc,ntiles_cn,MPI_REAL,0,MPI_COMM_WORLD,mpierr) - - ! Open GKW/Fzeng SMAP M09 catchcn_internal_rst and output catchcn_internal_rst - ! ---------------------------------------------------------------------------- - ! call MPI_Info_create(info, STATUS) - ! call MPI_Info_set(info, "romio_cb_read", "automatic", STATUS) - ! STATUS = NF_OPEN_PAR (trim(InCNRestart),IOR(NF_NOWRITE,NF_MPIIO),MPI_COMM_WORLD, info,NCFID) - ! STATUS = NF_OPEN_PAR (trim(OutFileName),IOR(NF_WRITE ,NF_MPIIO),MPI_COMM_WORLD, info,OUTID) - - STATUS = NF_OPEN_PAR (trim(OutFileName),IOR(NF_NOWRITE,NF_MPIIO),MPI_COMM_WORLD, infos,OUTID) ; VERIFY_(STATUS) - ! if(root_proc) then - ! STATUS = NF_OPEN (trim(OutFileName),NF_WRITE,OUTID) - ! - ! else - ! STATUS = NF_OPEN (trim(OutFileName),NF_NOWRITE,OUTID) - ! endif - ! - IF (STATUS .NE. NF_NOERR) CALL HANDLE_ERR(STATUS, 'OUTPUT RESTART FAILED') - - STATUS = NF_GET_VARA_REAL(OUTID,VarID(OUTID,'ITY'), (/low_ind(myid+1),1/), (/nt_local(myid+1),1/),CLMC_pt1) - STATUS = NF_GET_VARA_REAL(OUTID,VarID(OUTID,'ITY'), (/low_ind(myid+1),2/), (/nt_local(myid+1),1/),CLMC_pt2) - STATUS = NF_GET_VARA_REAL(OUTID,VarID(OUTID,'ITY'), (/low_ind(myid+1),3/), (/nt_local(myid+1),1/),CLMC_st1) - STATUS = NF_GET_VARA_REAL(OUTID,VarID(OUTID,'ITY'), (/low_ind(myid+1),4/), (/nt_local(myid+1),1/),CLMC_st2) - STATUS = NF_GET_VARA_REAL(OUTID,VarID(OUTID,'FVG'), (/low_ind(myid+1),1/), (/nt_local(myid+1),1/),CLMC_pf1) - STATUS = NF_GET_VARA_REAL(OUTID,VarID(OUTID,'FVG'), (/low_ind(myid+1),2/), (/nt_local(myid+1),1/),CLMC_pf2) - STATUS = NF_GET_VARA_REAL(OUTID,VarID(OUTID,'FVG'), (/low_ind(myid+1),3/), (/nt_local(myid+1),1/),CLMC_sf1) - STATUS = NF_GET_VARA_REAL(OUTID,VarID(OUTID,'FVG'), (/low_ind(myid+1),4/), (/nt_local(myid+1),1/),CLMC_sf2) - - if (root_proc) then - - STATUS = NF_OPEN (trim(InCNRestart),NF_NOWRITE,NCFID) - IF (STATUS .NE. NF_NOERR) CALL HANDLE_ERR(STATUS, 'OFFLINE RESTART FAILED') - allocate (TILE_ID (1:ntiles_cn)) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'TILE_ID' ), (/1/), (/NTILES_cn/),TILE_ID) - - do n = 1,ntiles_cn - - K = NINT (TILE_ID (n)) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'ITY'), (/n,1/), (/1,4/),ityp_offl(k,:)) - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'FVG'), (/n,1/), (/1,4/),fveg_offl(k,:)) - - tid_offl (n) = n - - do nv = 1,nveg - if(ityp_offl(k,nv)<0 .or. ityp_offl(k,nv)>npft) stop 'ityp' - if(fveg_offl(k,nv)<0..or. fveg_offl(k,nv)>1.00001) stop 'fveg' - end do - - if((ityp_offl(k,3) == 0).and.(ityp_offl(k,4) == 0)) then - if(ityp_offl(k,1) /= 0) then - ityp_offl(k,3) = ityp_offl(k,1) - else - ityp_offl(k,3) = ityp_offl(k,2) - endif - endif - - if((ityp_offl(k,1) == 0).and.(ityp_offl(k,2) /= 0)) ityp_offl(k,1) = ityp_offl(k,2) - if((ityp_offl(k,2) == 0).and.(ityp_offl(k,1) /= 0)) ityp_offl(k,2) = ityp_offl(k,1) - if((ityp_offl(k,3) == 0).and.(ityp_offl(k,4) /= 0)) ityp_offl(k,3) = ityp_offl(k,4) - if((ityp_offl(k,4) == 0).and.(ityp_offl(k,3) /= 0)) ityp_offl(k,4) = ityp_offl(k,3) - - end do - - endif - - call MPI_BCAST(tid_offl ,size(tid_offl ),MPI_INTEGER,0,MPI_COMM_WORLD,mpierr) - call MPI_BCAST(ityp_offl,size(ityp_offl),MPI_REAL ,0,MPI_COMM_WORLD,mpierr) - call MPI_BCAST(fveg_offl,size(fveg_offl),MPI_REAL ,0,MPI_COMM_WORLD,mpierr) - - ! -------------------------------------------------------------------------------- - ! Here we create transfer index array to map offline restarts to output tile space - ! -------------------------------------------------------------------------------- - - call GetIds(lonc,latc,lonn,latt,id_loc, tid_offl, & - CLMC_pf1, CLMC_pf2, CLMC_sf1, CLMC_sf2, CLMC_pt1, CLMC_pt2,CLMC_st1,CLMC_st2, & - fveg_offl, ityp_offl) - deallocate (CLMC_pf1, CLMC_pf2, CLMC_sf1, CLMC_sf2, CLMC_pt1, CLMC_pt2,CLMC_st1,CLMC_st2,lonc,latc,lonn,latt) - - ! update id_glb in root - - if(root_proc) then - allocate (id_glb (ntiles,4)) - allocate (id_vec (ntiles)) - endif - - do nv = 1, nveg - call MPI_Barrier(MPI_COMM_WORLD, STATUS) -! call MPI_GATHERV( & -! id_loc (:,nv), nt_local(myid+1) , MPI_real, & -! id_vec, nt_local,low_ind-1, MPI_real, & -! 0, MPI_COMM_WORLD, mpierr ) - - do i = 1, numprocs - if((I == 1).and.(myid == 0)) then - id_vec(low_ind(i) : upp_ind(i)) = Id_loc(:,nv) - else if (I > 1) then - if(I-1 == myid) then - ! send to root - call MPI_ISend(id_loc(:,nv),nt_local(i),MPI_INTEGER,0,993,MPI_COMM_WORLD,req,mpierr) - call MPI_WAIT (req,MPI_STATUS_IGNORE,mpierr) - else if (myid == 0) then - ! root receives - call MPI_RECV(id_vec(low_ind(i) : upp_ind(i)),nt_local(i) , MPI_INTEGER, i-1,993,MPI_COMM_WORLD,MPI_STATUS_IGNORE,mpierr) - endif - endif - end do - - if(root_proc) id_glb (:,nv) = id_vec - - end do - - call MPI_Barrier(MPI_COMM_WORLD, STATUS) - STATUS = NF_CLOSE (OutID) -! write out regridded carbon variables - - if(root_proc) then - - STATUS = NF_OPEN (trim(OutFileName),NF_WRITE,OUTID) ; VERIFY_(STATUS) - allocate (CLMC_pf1(NTILES)) - allocate (CLMC_pf2(NTILES)) - allocate (CLMC_sf1(NTILES)) - allocate (CLMC_sf2(NTILES)) - allocate (CLMC_pt1(NTILES)) - allocate (CLMC_pt2(NTILES)) - allocate (CLMC_st1(NTILES)) - allocate (CLMC_st2(NTILES)) - allocate (VAR_DUM (NTILES)) - allocate (var_dum2 (1:ntiles_cn)) - - STATUS = NF_GET_VARA_REAL(OUTID,VarID(OUTID,'ITY'), (/1,1/), (/NTILES,1/),CLMC_pt1) - STATUS = NF_GET_VARA_REAL(OUTID,VarID(OUTID,'ITY'), (/1,2/), (/NTILES,1/),CLMC_pt2) - STATUS = NF_GET_VARA_REAL(OUTID,VarID(OUTID,'ITY'), (/1,3/), (/NTILES,1/),CLMC_st1) - STATUS = NF_GET_VARA_REAL(OUTID,VarID(OUTID,'ITY'), (/1,4/), (/NTILES,1/),CLMC_st2) - STATUS = NF_GET_VARA_REAL(OUTID,VarID(OUTID,'FVG'), (/1,1/), (/NTILES,1/),CLMC_pf1) - STATUS = NF_GET_VARA_REAL(OUTID,VarID(OUTID,'FVG'), (/1,2/), (/NTILES,1/),CLMC_pf2) - STATUS = NF_GET_VARA_REAL(OUTID,VarID(OUTID,'FVG'), (/1,3/), (/NTILES,1/),CLMC_sf1) - STATUS = NF_GET_VARA_REAL(OUTID,VarID(OUTID,'FVG'), (/1,4/), (/NTILES,1/),CLMC_sf2) - - allocate (var_off_col (1: NTILES_CN, 1 : nzone,1 : var_col)) - allocate (var_off_pft (1: NTILES_CN, 1 : nzone,1 : nveg, 1 : var_pft)) - - allocate (var_col_out (1: NTILES, 1 : nzone,1 : var_col)) - allocate (var_pft_out (1: NTILES, 1 : nzone,1 : nveg, 1 : var_pft)) - - i = 1 - do nv = 1,VAR_COL - do nz = 1,nzone - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'CNCOL'), (/1,i/), (/NTILES_CN,1 /),VAR_DUM2) - do k = 1, NTILES_CN - var_off_col(TILE_ID(K), nz,nv) = VAR_DUM2(K) - end do - i = i + 1 - end do - end do - - i = 1 - do iv = 1,VAR_PFT - do nv = 1,nveg - do nz = 1,nzone - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'CNPFT'), (/1,i/), (/NTILES_CN,1 /),VAR_DUM2) - do k = 1, NTILES_CN - var_off_pft(TILE_ID(K), nz,nv,iv) = VAR_DUM2(K) - end do - i = i + 1 - end do - end do - end do - - var_col_out = 0. - var_pft_out = NaN - - where(isnan(var_off_pft)) var_off_pft = 0. - where(var_off_pft /= var_off_pft) var_off_pft = 0. - - OUT_TILE : DO N = 1, NTILES - - !if(mod (n,1000) == 0) print *, myid +1, n, Id_glb(n,:) - - NVLOOP2 : do nv = 1, nveg - - if(nv <= 2) then ! index for secondary PFT index if primary or primary if secondary - nx = nv + 2 - else - nx = nv - 2 - endif - - if (nv == 1) ityp_new = CLMC_pt1(n) - if (nv == 1) fveg_new = CLMC_pf1(n) - if (nv == 2) ityp_new = CLMC_pt2(n) - if (nv == 2) fveg_new = CLMC_pf2(n) - if (nv == 3) ityp_new = CLMC_st1(n) - if (nv == 3) fveg_new = CLMC_sf1(n) - if (nv == 4) ityp_new = CLMC_st2(n) - if (nv == 4) fveg_new = CLMC_sf2(n) - - if (fveg_new > fmin) then - - offl_cell = Id_glb(n,nv) - - if(ityp_new == ityp_offl (offl_cell,nv) .and. fveg_offl (offl_cell,nv)> fmin) then - iv = nv ! same type fraction (primary of secondary) - else if(ityp_new == ityp_offl (offl_cell,nx) .and. fveg_offl (offl_cell,nx)> fmin) then - iv = nx ! not same fraction - else if(iclass(ityp_new)==iclass(ityp_offl(offl_cell,nv)) .and. fveg_offl (offl_cell,nv)> fmin) then - iv = nv ! primary, other type (same class) - else if(fveg_offl (offl_cell,nx)> fmin) then - iv = nx ! secondary, other type (same class) - endif - - ! Get col and pft variables for the Id_glb(nv) grid cell from offline catchcn_internal_rst - ! ---------------------------------------------------------------------------------------- - - ! call NCDF_reshape_getOput (NCFID,Id_glb(n,nv),var_off_col,var_off_pft,.true.) - - var_pft_out (n,:,nv,:) = var_off_pft(Id_glb(n,nv), :,iv,:) - var_col_out (n,:,:) = var_col_out(n,:,:) + fveg_new * var_off_col(Id_glb(n,nv), :,:) ! gkw: column state simple weighted mean; ! could use "woody" fraction? - - ! Check whether var_pft_out is realistic - do nz = 1, nzone - do j = 1, VAR_PFT - if (isnan(var_pft_out (n, nz,nv,j))) print *,j,nv,nz,n,var_pft_out (n, nz,nv,j),fveg_new - !if(isnan(var_pft_out (n, nz,nv,69))) var_pft_out (n, nz,nv,69) = 1.e-6 - !if(isnan(var_pft_out (n, nz,nv,70))) var_pft_out (n, nz,nv,70) = 1.e-6 - !if(isnan(var_pft_out (n, nz,nv,73))) var_pft_out (n, nz,nv,73) = 1.e-6 - !if(isnan(var_pft_out (n, nz,nv,74))) var_pft_out (n, nz,nv,74) = 1.e-6 - end do - end do - endif - - end do NVLOOP2 - - ! reset carbon if negative < 10g - ! ------------------------ - - NZLOOP : do nz = 1, nzone - - if(var_col_out (n, nz,14) < 10.) then - - var_col_out(n, nz, 1) = max(var_col_out(n, nz, 1), 0.) - var_col_out(n, nz, 2) = max(var_col_out(n, nz, 2), 0.) - var_col_out(n, nz, 3) = max(var_col_out(n, nz, 3), 0.) - var_col_out(n, nz, 4) = max(var_col_out(n, nz, 4), 0.) - var_col_out(n, nz, 5) = max(var_col_out(n, nz, 5), 0.) - var_col_out(n, nz,10) = max(var_col_out(n, nz,10), 0.) - var_col_out(n, nz,11) = max(var_col_out(n, nz,11), 0.) - var_col_out(n, nz,12) = max(var_col_out(n, nz,12), 0.) - var_col_out(n, nz,13) = max(var_col_out(n, nz,13),10.) ! soil4c - var_col_out(n, nz,14) = max(var_col_out(n, nz,14), 0.) - var_col_out(n, nz,15) = max(var_col_out(n, nz,15), 0.) - var_col_out(n, nz,16) = max(var_col_out(n, nz,16), 0.) - var_col_out(n, nz,17) = max(var_col_out(n, nz,17), 0.) - var_col_out(n, nz,18) = max(var_col_out(n, nz,18), 0.) - var_col_out(n, nz,19) = max(var_col_out(n, nz,19), 0.) - var_col_out(n, nz,20) = max(var_col_out(n, nz,20), 0.) - var_col_out(n, nz,24) = max(var_col_out(n, nz,24), 0.) - var_col_out(n, nz,25) = max(var_col_out(n, nz,25), 0.) - var_col_out(n, nz,26) = max(var_col_out(n, nz,26), 0.) - var_col_out(n, nz,27) = max(var_col_out(n, nz,27), 0.) - var_col_out(n, nz,28) = max(var_col_out(n, nz,28), 1.) - var_col_out(n, nz,29) = max(var_col_out(n, nz,29), 0.) - - NVLOOP3 : do nv = 1,nveg - - if (nv == 1) ityp_new = CLMC_pt1(n) - if (nv == 1) fveg_new = CLMC_pf1(n) - if (nv == 2) ityp_new = CLMC_pt2(n) - if (nv == 2) fveg_new = CLMC_pf2(n) - if (nv == 3) ityp_new = CLMC_st1(n) - if (nv == 3) fveg_new = CLMC_sf1(n) - if (nv == 4) ityp_new = CLMC_st2(n) - if (nv == 4) fveg_new = CLMC_sf2(n) - - if(fveg_new > fmin) then - var_pft_out(n, nz,nv, 1) = max(var_pft_out(n, nz,nv, 1),0.) - var_pft_out(n, nz,nv, 2) = max(var_pft_out(n, nz,nv, 2),0.) - var_pft_out(n, nz,nv, 3) = max(var_pft_out(n, nz,nv, 3),0.) - var_pft_out(n, nz,nv, 4) = max(var_pft_out(n, nz,nv, 4),0.) - - if(ityp_new <= 12) then ! tree or shrub deadstemc - var_pft_out(n, nz,nv, 5) = max(var_pft_out(n, nz,nv, 5),0.1) - else - var_pft_out(n, nz,nv, 5) = max(var_pft_out(n, nz,nv, 5),0.0) - endif - - var_pft_out(n, nz,nv, 6) = max(var_pft_out(n, nz,nv, 6),0.) - var_pft_out(n, nz,nv, 7) = max(var_pft_out(n, nz,nv, 7),0.) - var_pft_out(n, nz,nv, 8) = max(var_pft_out(n, nz,nv, 8),0.) - var_pft_out(n, nz,nv, 9) = max(var_pft_out(n, nz,nv, 9),0.) - var_pft_out(n, nz,nv,10) = max(var_pft_out(n, nz,nv,10),0.) - var_pft_out(n, nz,nv,11) = max(var_pft_out(n, nz,nv,11),0.) - var_pft_out(n, nz,nv,12) = max(var_pft_out(n, nz,nv,12),0.) - - if(ityp_new <=2 .or. ityp_new ==4 .or. ityp_new ==5 .or. ityp_new == 9) then - var_pft_out(n, nz,nv,13) = max(var_pft_out(n, nz,nv,13),1.) ! leaf carbon display for evergreen - var_pft_out(n, nz,nv,14) = max(var_pft_out(n, nz,nv,14),0.) - else - var_pft_out(n, nz,nv,13) = max(var_pft_out(n, nz,nv,13),0.) - var_pft_out(n, nz,nv,14) = max(var_pft_out(n, nz,nv,14),1.) ! leaf carbon storage for deciduous - endif - - var_pft_out(n, nz,nv,15) = max(var_pft_out(n, nz,nv,15),0.) - var_pft_out(n, nz,nv,16) = max(var_pft_out(n, nz,nv,16),0.) - var_pft_out(n, nz,nv,17) = max(var_pft_out(n, nz,nv,17),0.) - var_pft_out(n, nz,nv,18) = max(var_pft_out(n, nz,nv,18),0.) - var_pft_out(n, nz,nv,19) = max(var_pft_out(n, nz,nv,19),0.) - var_pft_out(n, nz,nv,20) = max(var_pft_out(n, nz,nv,20),0.) - var_pft_out(n, nz,nv,21) = max(var_pft_out(n, nz,nv,21),0.) - var_pft_out(n, nz,nv,22) = max(var_pft_out(n, nz,nv,22),0.) - var_pft_out(n, nz,nv,23) = max(var_pft_out(n, nz,nv,23),0.) - var_pft_out(n, nz,nv,25) = max(var_pft_out(n, nz,nv,25),0.) - var_pft_out(n, nz,nv,26) = max(var_pft_out(n, nz,nv,26),0.) - var_pft_out(n, nz,nv,27) = max(var_pft_out(n, nz,nv,27),0.) - var_pft_out(n, nz,nv,41) = max(var_pft_out(n, nz,nv,41),0.) - var_pft_out(n, nz,nv,42) = max(var_pft_out(n, nz,nv,42),0.) - var_pft_out(n, nz,nv,44) = max(var_pft_out(n, nz,nv,44),0.) - var_pft_out(n, nz,nv,45) = max(var_pft_out(n, nz,nv,45),0.) - var_pft_out(n, nz,nv,46) = max(var_pft_out(n, nz,nv,46),0.) - var_pft_out(n, nz,nv,47) = max(var_pft_out(n, nz,nv,47),0.) - var_pft_out(n, nz,nv,48) = max(var_pft_out(n, nz,nv,48),0.) - var_pft_out(n, nz,nv,49) = max(var_pft_out(n, nz,nv,49),0.) - var_pft_out(n, nz,nv,50) = max(var_pft_out(n, nz,nv,50),0.) - var_pft_out(n, nz,nv,51) = max(var_pft_out(n, nz,nv, 5)/500.,0.) - var_pft_out(n, nz,nv,52) = max(var_pft_out(n, nz,nv,52),0.) - var_pft_out(n, nz,nv,53) = max(var_pft_out(n, nz,nv,53),0.) - var_pft_out(n, nz,nv,54) = max(var_pft_out(n, nz,nv,54),0.) - var_pft_out(n, nz,nv,55) = max(var_pft_out(n, nz,nv,55),0.) - var_pft_out(n, nz,nv,56) = max(var_pft_out(n, nz,nv,56),0.) - var_pft_out(n, nz,nv,57) = max(var_pft_out(n, nz,nv,13)/25.,0.) - var_pft_out(n, nz,nv,58) = max(var_pft_out(n, nz,nv,14)/25.,0.) - var_pft_out(n, nz,nv,59) = max(var_pft_out(n, nz,nv,59),0.) - var_pft_out(n, nz,nv,60) = max(var_pft_out(n, nz,nv,60),0.) - var_pft_out(n, nz,nv,61) = max(var_pft_out(n, nz,nv,61),0.) - var_pft_out(n, nz,nv,62) = max(var_pft_out(n, nz,nv,62),0.) - var_pft_out(n, nz,nv,63) = max(var_pft_out(n, nz,nv,63),0.) - var_pft_out(n, nz,nv,64) = max(var_pft_out(n, nz,nv,64),0.) - var_pft_out(n, nz,nv,65) = max(var_pft_out(n, nz,nv,65),0.) - var_pft_out(n, nz,nv,66) = max(var_pft_out(n, nz,nv,66),0.) - var_pft_out(n, nz,nv,67) = max(var_pft_out(n, nz,nv,67),0.) - var_pft_out(n, nz,nv,68) = max(var_pft_out(n, nz,nv,68),0.) - var_pft_out(n, nz,nv,69) = max(var_pft_out(n, nz,nv,69),0.) - var_pft_out(n, nz,nv,70) = max(var_pft_out(n, nz,nv,70),0.) - var_pft_out(n, nz,nv,73) = max(var_pft_out(n, nz,nv,73),0.) - var_pft_out(n, nz,nv,74) = max(var_pft_out(n, nz,nv,74),0.) - endif - end do NVLOOP3 ! end veg loop - endif ! end carbon check - end do NZLOOP ! end zone loop - - ! Update dayx variable var_pft_out (:,:,28) - - do j = 28, 28 ! 1,VAR_PFT var_pft_out (:,:,:,28) - do nv = 1,nveg - do nz = 1,nzone - var_pft_out (n, nz,nv,j) = dayx(n) - end do - end do - end do - - ! call NCDF_reshape_getOput (OutID,N,var_col_out,var_pft_out,.false.) - - ! column vars - ! ----------- - ! 1 clm3%g%l%c%ccs%col_ctrunc - ! 2 clm3%g%l%c%ccs%cwdc - ! 3 clm3%g%l%c%ccs%litr1c - ! 4 clm3%g%l%c%ccs%litr2c - ! 5 clm3%g%l%c%ccs%litr3c - ! 6 clm3%g%l%c%ccs%pcs_a%totvegc - ! 7 clm3%g%l%c%ccs%prod100c - ! 8 clm3%g%l%c%ccs%prod10c - ! 9 clm3%g%l%c%ccs%seedc - ! 10 clm3%g%l%c%ccs%soil1c - ! 11 clm3%g%l%c%ccs%soil2c - ! 12 clm3%g%l%c%ccs%soil3c - ! 13 clm3%g%l%c%ccs%soil4c - ! 14 clm3%g%l%c%ccs%totcolc - ! 15 clm3%g%l%c%ccs%totlitc - ! 16 clm3%g%l%c%cns%col_ntrunc - ! 17 clm3%g%l%c%cns%cwdn - ! 18 clm3%g%l%c%cns%litr1n - ! 19 clm3%g%l%c%cns%litr2n - ! 20 clm3%g%l%c%cns%litr3n - ! 21 clm3%g%l%c%cns%prod100n - ! 22 clm3%g%l%c%cns%prod10n - ! 23 clm3%g%l%c%cns%seedn - ! 24 clm3%g%l%c%cns%sminn - ! 25 clm3%g%l%c%cns%soil1n - ! 26 clm3%g%l%c%cns%soil2n - ! 27 clm3%g%l%c%cns%soil3n - ! 28 clm3%g%l%c%cns%soil4n - ! 29 clm3%g%l%c%cns%totcoln - ! 30 clm3%g%l%c%cps%ann_farea_burned - ! 31 clm3%g%l%c%cps%annsum_counter - ! 32 clm3%g%l%c%cps%cannavg_t2m - ! 33 clm3%g%l%c%cps%cannsum_npp - ! 34 clm3%g%l%c%cps%farea_burned - ! 35 clm3%g%l%c%cps%fire_prob - ! 36 clm3%g%l%c%cps%fireseasonl - ! 37 clm3%g%l%c%cps%fpg - ! 38 clm3%g%l%c%cps%fpi - ! 39 clm3%g%l%c%cps%me - ! 40 clm3%g%l%c%cps%mean_fire_prob - - ! PFT vars - ! -------- - ! 1 clm3%g%l%c%p%pcs%cpool - ! 2 clm3%g%l%c%p%pcs%deadcrootc - ! 3 clm3%g%l%c%p%pcs%deadcrootc_storage - ! 4 clm3%g%l%c%p%pcs%deadcrootc_xfer - ! 5 clm3%g%l%c%p%pcs%deadstemc - ! 6 clm3%g%l%c%p%pcs%deadstemc_storage - ! 7 clm3%g%l%c%p%pcs%deadstemc_xfer - ! 8 clm3%g%l%c%p%pcs%frootc - ! 9 clm3%g%l%c%p%pcs%frootc_storage - ! 10 clm3%g%l%c%p%pcs%frootc_xfer - ! 11 clm3%g%l%c%p%pcs%gresp_storage - ! 12 clm3%g%l%c%p%pcs%gresp_xfer - ! 13 clm3%g%l%c%p%pcs%leafc - ! 14 clm3%g%l%c%p%pcs%leafc_storage - ! 15 clm3%g%l%c%p%pcs%leafc_xfer - ! 16 clm3%g%l%c%p%pcs%livecrootc - ! 17 clm3%g%l%c%p%pcs%livecrootc_storage - ! 18 clm3%g%l%c%p%pcs%livecrootc_xfer - ! 19 clm3%g%l%c%p%pcs%livestemc - ! 20 clm3%g%l%c%p%pcs%livestemc_storage - ! 21 clm3%g%l%c%p%pcs%livestemc_xfer - ! 22 clm3%g%l%c%p%pcs%pft_ctrunc - ! 23 clm3%g%l%c%p%pcs%xsmrpool - ! 24 clm3%g%l%c%p%pepv%annavg_t2m - ! 25 clm3%g%l%c%p%pepv%annmax_retransn - ! 26 clm3%g%l%c%p%pepv%annsum_npp - ! 27 clm3%g%l%c%p%pepv%annsum_potential_gpp - ! 28 clm3%g%l%c%p%pepv%dayl - ! 29 clm3%g%l%c%p%pepv%days_active - ! 30 clm3%g%l%c%p%pepv%dormant_flag - ! 31 clm3%g%l%c%p%pepv%offset_counter - ! 32 clm3%g%l%c%p%pepv%offset_fdd - ! 33 clm3%g%l%c%p%pepv%offset_flag - ! 34 clm3%g%l%c%p%pepv%offset_swi - ! 35 clm3%g%l%c%p%pepv%onset_counter - ! 36 clm3%g%l%c%p%pepv%onset_fdd - ! 37 clm3%g%l%c%p%pepv%onset_flag - ! 38 clm3%g%l%c%p%pepv%onset_gdd - ! 39 clm3%g%l%c%p%pepv%onset_gddflag - ! 40 clm3%g%l%c%p%pepv%onset_swi - ! 41 clm3%g%l%c%p%pepv%prev_frootc_to_litter - ! 42 clm3%g%l%c%p%pepv%prev_leafc_to_litter - ! 43 clm3%g%l%c%p%pepv%tempavg_t2m - ! 44 clm3%g%l%c%p%pepv%tempmax_retransn - ! 45 clm3%g%l%c%p%pepv%tempsum_npp - ! 46 clm3%g%l%c%p%pepv%tempsum_potential_gpp - ! 47 clm3%g%l%c%p%pepv%xsmrpool_recover - ! 48 clm3%g%l%c%p%pns%deadcrootn - ! 49 clm3%g%l%c%p%pns%deadcrootn_storage - ! 50 clm3%g%l%c%p%pns%deadcrootn_xfer - ! 51 clm3%g%l%c%p%pns%deadstemn - ! 52 clm3%g%l%c%p%pns%deadstemn_storage - ! 53 clm3%g%l%c%p%pns%deadstemn_xfer - ! 54 clm3%g%l%c%p%pns%frootn - ! 55 clm3%g%l%c%p%pns%frootn_storage - ! 56 clm3%g%l%c%p%pns%frootn_xfer - ! 57 clm3%g%l%c%p%pns%leafn - ! 58 clm3%g%l%c%p%pns%leafn_storage - ! 59 clm3%g%l%c%p%pns%leafn_xfer - ! 60 clm3%g%l%c%p%pns%livecrootn - ! 61 clm3%g%l%c%p%pns%livecrootn_storage - ! 62 clm3%g%l%c%p%pns%livecrootn_xfer - ! 63 clm3%g%l%c%p%pns%livestemn - ! 64 clm3%g%l%c%p%pns%livestemn_storage - ! 65 clm3%g%l%c%p%pns%livestemn_xfer - ! 66 clm3%g%l%c%p%pns%npool - ! 67 clm3%g%l%c%p%pns%pft_ntrunc - ! 68 clm3%g%l%c%p%pns%retransn - ! 69 clm3%g%l%c%p%pps%elai - ! 70 clm3%g%l%c%p%pps%esai - ! 71 clm3%g%l%c%p%pps%hbot - ! 72 clm3%g%l%c%p%pps%htop - ! 73 clm3%g%l%c%p%pps%tlai - ! 74 clm3%g%l%c%p%pps%tsai - - end do OUT_TILE - - i = 1 - do nv = 1,VAR_COL - do nz = 1,nzone - STATUS = NF_PUT_VARA_REAL(OutID,VarID(OUTID,'CNCOL'), (/1,i/), (/NTILES,1 /),var_col_out(:, nz,nv)) - i = i + 1 - end do - end do - - i = 1 - do iv = 1,VAR_PFT - do nv = 1,nveg - do nz = 1,nzone - STATUS = NF_PUT_VARA_REAL(OutID,VarID(OUTID,'CNPFT'), (/1,i/), (/NTILES,1 /),var_pft_out(:, nz,nv,iv)) - i = i + 1 - end do - end do - end do - - VAR_DUM = 0. - - do nz = 1,nzone - STATUS = NF_PUT_VARA_REAL(OutID,VarID(OUTID,'TGWM'), (/1,nz/), (/NTILES,1 /),VAR_DUM(:)) - STATUS = NF_PUT_VARA_REAL(OutID,VarID(OUTID,'RZMM'), (/1,nz/), (/NTILES,1 /),VAR_DUM(:)) - end do - - STATUS = NF_PUT_VARA_REAL(OutID,VarID(OUTID,'SFMCM'), (/1/), (/NTILES/),VAR_DUM(:)) - STATUS = NF_PUT_VARA_REAL(OutID,VarID(OUTID,'BFLOWM'), (/1/), (/NTILES/),VAR_DUM(:)) - STATUS = NF_PUT_VARA_REAL(OutID,VarID(OUTID,'TOTWATM'), (/1/), (/NTILES/),VAR_DUM(:)) - STATUS = NF_PUT_VARA_REAL(OutID,VarID(OUTID,'TAIRM'), (/1/), (/NTILES/),VAR_DUM(:)) - STATUS = NF_PUT_VARA_REAL(OutID,VarID(OUTID,'TPM'), (/1/), (/NTILES/),VAR_DUM(:)) - STATUS = NF_PUT_VARA_REAL(OutID,VarID(OUTID,'CNSUM'), (/1/), (/NTILES/),VAR_DUM(:)) - STATUS = NF_PUT_VARA_REAL(OutID,VarID(OUTID,'SNDZM'), (/1/), (/NTILES/),VAR_DUM(:)) - STATUS = NF_PUT_VARA_REAL(OutID,VarID(OUTID,'ASNOWM'), (/1/), (/NTILES/),VAR_DUM(:)) - - do nv = 1,nzone - do nz = 1,nveg - STATUS = NF_PUT_VARA_REAL(OutID,VarID(OUTID,'PSNSUNM'), (/1,nz,nv/), (/NTILES,1,1/),VAR_DUM(:)) - STATUS = NF_PUT_VARA_REAL(OutID,VarID(OUTID,'PSNSHAM'), (/1,nz,nv/), (/NTILES,1,1/),VAR_DUM(:)) - end do - end do - - STATUS = NF_CLOSE (NCFID) - STATUS = NF_CLOSE (OutID) - - deallocate (var_off_col,var_off_pft,var_col_out,var_pft_out) - deallocate (CLMC_pf1, CLMC_pf2, CLMC_sf1, CLMC_sf2) - deallocate (CLMC_pt1, CLMC_pt2, CLMC_st1, CLMC_st2) - - endif - - call MPI_Barrier(MPI_COMM_WORLD, STATUS) - - - END SUBROUTINE regrid_carbon_vars - - ! ***************************************************************************** - - SUBROUTINE NCDF_reshape_getOput (NCFID,CID,col,pft, get_var) - - implicit none - - integer, intent (in) :: NCFID,CID - logical, intent (in) :: get_var - real, intent (inout) :: col (nzone * VAR_COL) - real, intent (inout) :: pft (nzone * nveg * var_PFT) - integer :: STATUS - - if (get_var) then - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'CNCOL'), (/CID,1/), (/1,nzone * VAR_COL /),col) - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'CNPFT'), (/CID,1/), (/1,nzone * nveg * var_PFT/),pft) - else - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'CNCOL'), (/CID,1/), (/1,nzone * VAR_COL /),col) - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'CNPFT'), (/CID,1/), (/1,nzone * nveg * var_PFT/),pft) - endif - - IF ((STATUS .NE. NF_NOERR).and.(get_var)) then - print *,CID - CALL HANDLE_ERR(STATUS, 'Out : NCDF_reshape_getOput') - ENDIF - - IF ((STATUS .NE. NF_NOERR).and.(.not.get_var)) then - print *,CID - CALL HANDLE_ERR(STATUS, 'In : NCDF_reshape_getOput') - ENDIF - END SUBROUTINE NCDF_reshape_getOput - - ! ***************************************************************************** - - SUBROUTINE NCDF_whole_getOput (NCFID,NTILES,col,pft, get_var) - - implicit none - - integer, intent (in) :: NCFID,NTILES - logical, intent (in) :: get_var - real, intent (inout) :: col (NTILES, nzone * VAR_COL) - real, intent (inout) :: pft (NTILES, nzone * nveg * var_PFT) - integer :: STATUS, J - - if (get_var) then - DO J = 1,nzone * VAR_COL - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'CNCOL'), (/1,J/), (/NTILES,1 /),col(:,j)) - END DO - DO J = 1, nzone * nveg * var_PFT - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'CNPFT'), (/1,J/), (/NTILES,1/),pft(:,J)) - END DO - else - DO J = 1,nzone * VAR_COL - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'CNCOL'), (/1,J/), (/NTILES,1 /),col(:,J)) - END DO - DO J = 1, nzone * nveg * var_PFT - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'CNPFT'), (/1,J/), (/NTILES,1/) ,pft(:,J)) - END DO - endif - - IF ((STATUS .NE. NF_NOERR).and.(get_var)) CALL HANDLE_ERR(STATUS, 'Out : NCDF_whole_getOput') - IF ((STATUS .NE. NF_NOERR).and.(.not.get_var)) CALL HANDLE_ERR(STATUS, 'In : NCDF_whole_getOput') - - END SUBROUTINE NCDF_whole_getOput - - ! ----------------------------------------------------------------------- - - SUBROUTINE HANDLE_ERR(STATUS, Line) - - INTEGER, INTENT (IN) :: STATUS - CHARACTER(*), INTENT (IN) :: Line - - IF (STATUS .NE. NF_NOERR) THEN - PRINT *, trim(Line),': ',NF_STRERROR(STATUS) - STOP 'Stopped' - ENDIF - - END SUBROUTINE HANDLE_ERR - - ! ***************************************************************************** - - integer function VarID (NCFID, VNAME) - - integer, intent (in) :: NCFID - character(*), intent (in) :: VNAME - integer :: status - - STATUS = NF_INQ_VARID (NCFID, trim(VNAME) ,VarID) - IF (STATUS .NE. NF_NOERR) & - CALL HANDLE_ERR(STATUS, trim(VNAME)) - - end function VarID - - ! ***************************************************************************** - - SUBROUTINE regrid_hyd_vars (NTILES, OutFMT) - - implicit none - integer, intent (in) :: NTILES - - ! =============================================================================================== - - integer, allocatable, dimension(:) :: Id_glb, Id_loc - integer, allocatable, dimension(:) :: ld_reorder, tid_offl - real , allocatable, dimension(:) :: tmp_var - integer :: n,i,j, nv, nx, offl_cell, STATUS,NCFID, req - integer :: outid, local_id - real , pointer, dimension (:) :: lonc, latc, LATT, LONN, long, latg - integer, allocatable :: low_ind(:), upp_ind(:), nt_local (:) - type(Netcdf4_Fileformatter) :: InFmt, OutFmt - - allocate (tid_offl (ntiles_cn)) - allocate (tmp_var (ntiles_cn)) - - allocate(low_ind ( numprocs)) - allocate(upp_ind ( numprocs)) - allocate(nt_local( numprocs)) - - low_ind (:) = 1 - upp_ind (:) = NTILES - nt_local(:) = NTILES - - ! Domain decomposition - ! -------------------- - - if (numprocs > 1) then - do i = 1, numprocs - 1 - upp_ind(i) = low_ind(i) + (ntiles/numprocs) - 1 - low_ind(i+1) = upp_ind(i) + 1 - nt_local(i) = upp_ind(i) - low_ind(i) + 1 - end do - nt_local(numprocs) = upp_ind(numprocs) - low_ind(numprocs) + 1 - endif - - allocate (id_loc (nt_local (myid + 1))) - allocate (lonn (nt_local (myid + 1))) - allocate (latt (nt_local (myid + 1))) - allocate (lonc (1:ntiles_cn)) - allocate (latc (1:ntiles_cn)) - - if (root_proc) then - - allocate (long (ntiles)) - allocate (latg (ntiles)) - allocate (ld_reorder(ntiles_cn)) - - call ReadTileFile_RealLatLon (OutTileFile, i, xlon=long, xlat=latg) - - ! --------------------------------------------- - ! Read exact lonc, latc from offline .til File - ! --------------------------------------------- - - call ReadTileFile_RealLatLon(trim(InCNTilFile), i,xlon=lonc,xlat=latc) - - STATUS = NF_OPEN (trim(InCNRestart),NF_NOWRITE,NCFID) - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'TILE_ID' ), (/1/), (/NTILES_CN/),tmp_var) - STATUS = NF_CLOSE (NCFID) - - do n = 1, ntiles_cn - ld_reorder ( NINT(tmp_var(n))) = n - tid_offl(n) = n - end do - - deallocate (tmp_var) - - endif - - call MPI_Barrier(MPI_COMM_WORLD, STATUS) - - do i = 1, numprocs - if((I == 1).and.(myid == 0)) then - lonn(:) = long(low_ind(i) : upp_ind(i)) - latt(:) = latg(low_ind(i) : upp_ind(i)) - else if (I > 1) then - if(I-1 == myid) then - ! receiving from root - call MPI_RECV(lonn,nt_local(i) , MPI_REAL, 0,995,MPI_COMM_WORLD,MPI_STATUS_IGNORE,mpierr) - call MPI_RECV(latt,nt_local(i) , MPI_REAL, 0,994,MPI_COMM_WORLD,MPI_STATUS_IGNORE,mpierr) - else if (myid == 0) then - ! root sends - call MPI_ISend(long(low_ind(i) : upp_ind(i)),nt_local(i),MPI_REAL,i-1,995,MPI_COMM_WORLD,req,mpierr) - call MPI_WAIT (req,MPI_STATUS_IGNORE,mpierr) - call MPI_ISend(latg(low_ind(i) : upp_ind(i)),nt_local(i),MPI_REAL,i-1,994,MPI_COMM_WORLD,req,mpierr) - call MPI_WAIT (req,MPI_STATUS_IGNORE,mpierr) - endif - endif - end do - -! call MPI_SCATTERV ( & -! long,nt_local,low_ind-1,MPI_real, & -! lonn,size(lonn),MPI_real , & -! 0,MPI_COMM_WORLD, mpierr ) -! -! call MPI_SCATTERV ( & -! latg,nt_local,low_ind-1,MPI_real, & -! latt,nt_local(myid+1),MPI_real , & -! 0,MPI_COMM_WORLD, mpierr ) - - if(root_proc) deallocate (long, latg) - - call MPI_BCAST(lonc,ntiles_cn,MPI_REAL,0,MPI_COMM_WORLD,mpierr) - call MPI_BCAST(latc,ntiles_cn,MPI_REAL,0,MPI_COMM_WORLD,mpierr) - call MPI_BCAST(tid_offl,size(tid_offl ),MPI_INTEGER,0,MPI_COMM_WORLD,mpierr) - - ! -------------------------------------------------------------------------------- - ! Here we create transfer index array to map offline restarts to output tile space - ! -------------------------------------------------------------------------------- - - call GetIds(lonc,latc,lonn,latt,id_loc, tid_offl) - - ! Loop through NTILES (# of tiles in output array) find the nearest neighbor from Qing. - - if(root_proc) allocate (id_glb (ntiles)) - - call MPI_Barrier(MPI_COMM_WORLD, STATUS) - - do i = 1, numprocs - if((I == 1).and.(myid == 0)) then - id_glb(low_ind(i) : upp_ind(i)) = Id_loc(:) - else if (I > 1) then - if(I-1 == myid) then - ! send to root - call MPI_ISend(id_loc,nt_local(i),MPI_INTEGER,0,993,MPI_COMM_WORLD,req,mpierr) - call MPI_WAIT (req,MPI_STATUS_IGNORE,mpierr) - else if (myid == 0) then - ! root receives - call MPI_RECV(id_glb(low_ind(i) : upp_ind(i)),nt_local(i) , MPI_INTEGER, i-1,993,MPI_COMM_WORLD,MPI_STATUS_IGNORE,mpierr) - endif - endif - end do - -! call MPI_GATHERV( & -! id_loc, nt_local(myid+1) , MPI_real, & -! id_glb, nt_local,low_ind-1, MPI_real, & -! 0, MPI_COMM_WORLD, mpierr ) - - if (root_proc) call put_land_vars (NTILES, id_glb, ld_reorder, OutFmt) - - call MPI_Barrier(MPI_COMM_WORLD, STATUS) - - END SUBROUTINE regrid_hyd_vars - - ! ***************************************************************************** - SUBROUTINE put_land_vars (NTILES, id_glb, ld_reorder, OutFmt) - - implicit none - - integer, intent (in) :: NTILES - integer, intent (in) :: id_glb(NTILES), ld_reorder (NTILES_CN) - integer :: i,k,n - real , dimension (:), allocatable :: var_get, var_put - type(Netcdf4_Fileformatter) :: OutFmt - integer :: nVars, STATUS, NCFID - - allocate (var_get (NTILES_CN)) - allocate (var_put (NTILES)) - - ! Read catparam - ! ------------- - - STATUS = NF_OPEN (trim(InCNRestart),NF_NOWRITE,NCFID) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'POROS' ), (/1/), (/NTILES_CN/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'POROS',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'COND' ), (/1/), (/NTILES_CN/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'COND',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'PSIS' ), (/1/), (/NTILES_CN/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'PSIS',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'BEE' ), (/1/), (/NTILES_CN/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'BEE',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'WPWET' ), (/1/), (/NTILES_CN/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'WPWET',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'GNU' ), (/1/), (/NTILES_CN/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'GNU',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'VGWMAX' ), (/1/), (/NTILES_CN/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'VGWMAX',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'BF1' ), (/1/), (/NTILES_CN/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'BF1',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'BF2' ), (/1/), (/NTILES_CN/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'BF2',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'BF3' ), (/1/), (/NTILES_CN/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'BF3',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'CDCR1' ), (/1/), (/NTILES_CN/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'CDCR1',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'CDCR2' ), (/1/), (/NTILES_CN/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'CDCR2',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'ARS1' ), (/1/), (/NTILES_CN/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'ARS1',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'ARS2' ), (/1/), (/NTILES_CN/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'ARS2',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'ARS3' ), (/1/), (/NTILES_CN/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'ARS3',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'ARA1' ), (/1/), (/NTILES_CN/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'ARA1',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'ARA2' ), (/1/), (/NTILES_CN/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'ARA2',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'ARA3' ), (/1/), (/NTILES_CN/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'ARA3',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'ARA4' ), (/1/), (/NTILES_CN/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'ARA4',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'ARW1' ), (/1/), (/NTILES_CN/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'ARW1',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'ARW2' ), (/1/), (/NTILES_CN/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'ARW2',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'ARW3' ), (/1/), (/NTILES_CN/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'ARW3',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'ARW4' ), (/1/), (/NTILES_CN/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'ARW4',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'TSA1' ), (/1/), (/NTILES_CN/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'TSA1',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'TSA2' ), (/1/), (/NTILES_CN/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'TSA2',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'TSB1' ), (/1/), (/NTILES_CN/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'TSB1',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'TSB2' ), (/1/), (/NTILES_CN/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'TSB2',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'ATAU' ), (/1/), (/NTILES_CN/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'ATAU',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'BTAU' ), (/1/), (/NTILES_CN/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'BTAU',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'ITY' ), (/1,1/), (/NTILES_CN,1/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'ITY',var_put, offset1=1) - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'ITY' ), (/1,2/), (/NTILES_CN,1/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'ITY',var_put, offset1=2) - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'ITY' ), (/1,3/), (/NTILES_CN,1/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'ITY',var_put, offset1=3) - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'ITY' ), (/1,4/), (/NTILES_CN,1/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'ITY',var_put, offset1=4) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'FVG' ), (/1,1/), (/NTILES_CN,1/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'FVG',var_put, offset1=1) - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'FVG' ), (/1,2/), (/NTILES_CN,1/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'FVG',var_put, offset1=2) - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'FVG' ), (/1,3/), (/NTILES_CN,1/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'FVG',var_put, offset1=3) - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'FVG' ), (/1,4/), (/NTILES_CN,1/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'FVG',var_put, offset1=4) - - ! read restart and regrid - ! ----------------------- - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'TG' ), (/1,1/), (/NTILES_CN,1/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'TG',var_put, offset1=1) ! if you see offset1=1 it is a 2-D var - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'TG' ), (/1,2/), (/NTILES_CN,1/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'TG',var_put, offset1=2) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'TG' ), (/1,3/), (/NTILES_CN,1/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'TG',var_put, offset1=3) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'TC' ), (/1,1/), (/NTILES_CN,1/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'TC',var_put, offset1=1) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'TC' ), (/1,2/), (/NTILES_CN,1/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'TC',var_put, offset1=2) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'TC' ), (/1,3/), (/NTILES_CN,1/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'TC',var_put, offset1=3) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'QC' ), (/1,1/), (/NTILES_CN,1/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'QC',var_put, offset1=1) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'QC' ), (/1,2/), (/NTILES_CN,1/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'QC',var_put, offset1=2) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'QC' ), (/1,3/), (/NTILES_CN,1/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'QC',var_put, offset1=3) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'CAPAC' ), (/1/), (/NTILES_CN/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'CAPAC',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'CATDEF' ), (/1/), (/NTILES_CN/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'CATDEF',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'RZEXC' ), (/1/), (/NTILES_CN/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'RZEXC',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'SRFEXC' ), (/1/), (/NTILES_CN/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'SRFEXC',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'GHTCNT1' ), (/1/), (/NTILES_CN/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'GHTCNT1',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'GHTCNT2' ), (/1/), (/NTILES_CN/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'GHTCNT2',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'GHTCNT3' ), (/1/), (/NTILES_CN/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'GHTCNT3',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'GHTCNT4' ), (/1/), (/NTILES_CN/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'GHTCNT4',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'GHTCNT5' ), (/1/), (/NTILES_CN/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'GHTCNT5',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'GHTCNT6' ), (/1/), (/NTILES_CN/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'GHTCNT6',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'WESNN1' ), (/1/), (/NTILES_CN/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'WESNN1',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'WESNN2' ), (/1/), (/NTILES_CN/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'WESNN2',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'WESNN3' ), (/1/), (/NTILES_CN/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'WESNN3',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'HTSNNN1' ), (/1/), (/NTILES_CN/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'HTSNNN1',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'HTSNNN2' ), (/1/), (/NTILES_CN/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'HTSNNN2',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'HTSNNN3' ), (/1/), (/NTILES_CN/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'HTSNNN3',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'SNDZN1' ), (/1/), (/NTILES_CN/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'SNDZN1',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'SNDZN2' ), (/1/), (/NTILES_CN/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'SNDZN2',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'SNDZN3' ), (/1/), (/NTILES_CN/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'SNDZN3',var_put) - - STATUS = NF_CLOSE ( NCFID) - - deallocate (var_get, var_put) - - END SUBROUTINE put_land_vars - - ! ***************************************************************************** - subroutine init_MPI() - - ! initialize MPI - - call MPI_INIT(mpierr) - - call MPI_COMM_RANK( MPI_COMM_WORLD, myid, mpierr ) - call MPI_COMM_SIZE( MPI_COMM_WORLD, numprocs, mpierr ) - - if (myid .ne. 0) root_proc = .false. - -! write (*,*) "MPI process ", myid, " of ", numprocs, " is alive" -! write (*,*) "MPI process ", myid, ": root_proc=", root_proc - - end subroutine init_MPI - - ! ***************************************************************************** - -end program mk_CatchCNRestarts - diff --git a/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/mk_CatchRestarts.F90 b/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/mk_CatchRestarts.F90 deleted file mode 100644 index 26884ad03..000000000 --- a/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/mk_CatchRestarts.F90 +++ /dev/null @@ -1,778 +0,0 @@ -#define I_AM_MAIN -#include "MAPL_Generic.h" -program mk_CatchRestarts - -! $Id: - - use MAPL - use mk_restarts_getidsMod, only: GetIDs,ReadTileFile_RealLatLon - use gFTL_StringVector - - implicit none - include 'mpif.h' - ! initialize to non-MPI values - - integer :: myid=0, numprocs=1, mpierr, mpistatus(MPI_STATUS_SIZE) - logical :: root_proc=.true. - - character*256 :: Usage="mk_CatchRestarts OutTileFile InTileFile InRestart SURFLAY " - character*256 :: OutTileFile - character*256 :: InTileFile - character*256 :: InRestart - character*256 :: OutType - character*256 :: arg(6) - - integer :: i, k, iargc, n, ntiles,ntiles_in, nplus, req - integer, pointer :: Id(:), tid_in (:) - real, pointer :: loni(:),lono(:), lati(:), lato(:) - real :: SURFLAY - integer, allocatable :: low_ind(:), upp_ind(:), nt_local (:), Id_loc (:) - real , pointer, dimension (:) :: LATT, LONN - logical :: OutIsOld, havedata - character*256, parameter :: DataDir="OutData/clsm/" - real :: min_lon, max_lon, min_lat, max_lat - logical, allocatable, dimension(:) :: mask - integer, allocatable, dimension (:) :: sub_tid - real , allocatable, dimension (:) :: sub_lon, sub_lat - integer :: status - - call init_MPI() - -!--------------------------------------------------------------------------- - - I = iargc() - - if( I<4 .or. I>5 ) then - print *, "Wrong Number of arguments: ", i - print *, trim(Usage) - call exit(1) - end if - - do n=1,I - call getarg(n,arg(n)) - enddo - read(arg(1),'(a)') OutTileFile - read(arg(2),'(a)') InTileFile - read(arg(3),'(a)') InRestart - read(arg(4),*) SURFLAY - - if(I==5) then - call getarg(6,OutType) - OutIsOld = trim(OutType)=="OutIsOld" - else - OutIsOld = .false. - endif - - if (SURFLAY.ne.20 .and. SURFLAY.ne.50) then - print *, "You must supply a valid SURFLAY value:" - print *, "(Ganymed-3 and earlier) SURFLAY=20.0 for Old Soil Params" - print *, "(Ganymed-4 and later ) SURFLAY=50.0 for New Soil Params" - call exit(2) - end if - - inquire(file=trim(DataDir)//"mosaic_veg_typs_fracs",exist=havedata) - - if (root_proc) then - - ! Read Output/Input .til files - call ReadTileFile_RealLatLon(OutTileFile, ntiles, xlon=lono, xlat=lato) - call ReadTileFile_RealLatLon(InTileFile,ntiles_in,xlon=loni, xlat=lati) - allocate(Id (ntiles)) - ! allocate(mask (ntiles_in)) - ! allocate(tid_in (ntiles_in)) - ! do n = 1, NTILES_IN - ! tid_in (n) = n - ! end do - - endif - - if (havedata) then - if (root_proc) call read_and_write_rst (NTILES, SURFLAY, OutIsOld, NTILES, __RC__) - else - - call MPI_BCAST (ntiles , 1, MPI_INTEGER, 0,MPI_COMM_WORLD, mpierr) - call MPI_BCAST (ntiles_in, 1, MPI_INTEGER, 0,MPI_COMM_WORLD, mpierr) - - allocate(low_ind ( numprocs)) - allocate(upp_ind ( numprocs)) - allocate(nt_local( numprocs)) - - low_ind (:) = 1 - upp_ind (:) = NTILES - nt_local(:) = NTILES - - if (numprocs > 1) then - do i = 1, numprocs - 1 - upp_ind(i) = low_ind(i) + (ntiles/numprocs) - 1 - low_ind(i+1) = upp_ind(i) + 1 - nt_local(i) = upp_ind(i) - low_ind(i) + 1 - end do - nt_local(numprocs) = upp_ind(numprocs) - low_ind(numprocs) + 1 - endif - - ! Get intile lat/lon - -! do i = 2, numprocs -! if (i -1 == myid) then -! ! receive ntiles_in in the block -! call MPI_RECV(ntiles_in, 1, MPI_INTEGER,0,999,MPI_COMM_WORLD,MPI_STATUS_IGNORE,mpierr) -! ! ALLOCATE -! allocate (loni (1:NTILES_IN)) -! allocate (lati (1:NTILES_IN)) -! allocate (tid_in (1:NTILES_IN)) -! -! ! RECEIVE LAT/LON IN -! call MPI_RECV(tid_in, ntiles_in, MPI_INTEGER,0,998,MPI_COMM_WORLD,MPI_STATUS_IGNORE,mpierr) -! call MPI_RECV(loni , ntiles_in, MPI_REAL ,0,997,MPI_COMM_WORLD,MPI_STATUS_IGNORE,mpierr) -! call MPI_RECV(lati , ntiles_in, MPI_REAL ,0,996,MPI_COMM_WORLD,MPI_STATUS_IGNORE,mpierr) -! -! else if (myid == 0) then -! -! ! Send local ntiles_in -! -! min_lon = MAX(MINVAL(lono (low_ind(i) : upp_ind(i))) - 5, -180.) -! max_lon = MIN(MAXVAL(lono (low_ind(i) : upp_ind(i))) + 5, 180.) -! min_lat = MAX(MINVAL(lato (low_ind(i) : upp_ind(i))) - 5, -90.) -! max_lat = MIN(MAXVAL(lato (low_ind(i) : upp_ind(i))) + 5, 90.) -! mask = .false. -! mask = ((lati >= min_lat .and. lati <= max_lat).and.(loni >= min_lon .and. loni <= max_lon)) -! nplus = count(mask = mask) -! -! call MPI_ISend(NPLUS ,1,MPI_INTEGER,i-1,999,MPI_COMM_WORLD,req,mpierr) -! call MPI_WAIT (req,MPI_STATUS_IGNORE,mpierr) -! -! -! ! SEND LAT/LON IN -! allocate (sub_tid (1:nplus)) -! allocate (sub_lon (1:nplus)) -! allocate (sub_lat (1:nplus)) -! -! sub_tid = PACK (tid_in , mask= mask) -! sub_lon = PACK (loni , mask= mask) -! sub_lat = PACK (lati , mask= mask) -! -! call MPI_ISend(sub_tid, nplus,MPI_INTEGER,i-1,998,MPI_COMM_WORLD,req,mpierr) -! call MPI_WAIT (req,MPI_STATUS_IGNORE,mpierr) -! call MPI_ISend(sub_lon, nplus,MPI_REAL ,i-1,997,MPI_COMM_WORLD,req,mpierr) -! call MPI_WAIT (req,MPI_STATUS_IGNORE,mpierr) -! call MPI_ISend(sub_lat, nplus,MPI_REAL ,i-1,996,MPI_COMM_WORLD,req,mpierr) -! call MPI_WAIT (req,MPI_STATUS_IGNORE,mpierr) -! deallocate (sub_tid,sub_lon,sub_lat) -! endif -! end do - - ! Get out tile lat/lots from root - - allocate (id_loc (nt_local (myid + 1))) - allocate (lonn (nt_local (myid + 1))) - allocate (latt (nt_local (myid + 1))) - - do i = 1, numprocs - if((I == 1).and.(myid == 0)) then - lonn(:) = lono(low_ind(i) : upp_ind(i)) - latt(:) = lato(low_ind(i) : upp_ind(i)) - else if (I > 1) then - if(I-1 == myid) then - ! receiving from root - call MPI_RECV(lonn,nt_local(i) , MPI_REAL, 0,995,MPI_COMM_WORLD,MPI_STATUS_IGNORE,mpierr) - call MPI_RECV(latt,nt_local(i) , MPI_REAL, 0,994,MPI_COMM_WORLD,MPI_STATUS_IGNORE,mpierr) - else if (myid == 0) then - ! root sends - call MPI_ISend(lono(low_ind(i) : upp_ind(i)),nt_local(i),MPI_REAL,i-1,995,MPI_COMM_WORLD,req,mpierr) - call MPI_WAIT (req,MPI_STATUS_IGNORE,mpierr) - call MPI_ISend(lato(low_ind(i) : upp_ind(i)),nt_local(i),MPI_REAL,i-1,994,MPI_COMM_WORLD,req,mpierr) - call MPI_WAIT (req,MPI_STATUS_IGNORE,mpierr) - endif - endif - end do - -! call MPI_SCATTERV ( & -! lono,nt_local,low_ind-1,MPI_real, & -! lonn,size(lonn),MPI_real , & -! 0,MPI_COMM_WORLD, mpierr ) -! -! call MPI_SCATTERV ( & -! lato,nt_local,low_ind-1,MPI_real, & -! latt,size(latt),MPI_real , & -! 0,MPI_COMM_WORLD, mpierr ) - - if(myid > 0) allocate (loni (1:NTILES_IN)) - if(myid > 0) allocate (lati (1:NTILES_IN)) - - call MPI_BCAST(loni,ntiles_in,MPI_REAL,0,MPI_COMM_WORLD,mpierr) - call MPI_BCAST(lati,ntiles_in,MPI_REAL,0,MPI_COMM_WORLD,mpierr) - - allocate(tid_in (ntiles_in)) - do n = 1, NTILES_IN - tid_in (n) = n - end do - - call GetIds(loni,lati,lonn,latt,Id_loc, tid_in) - call MPI_Barrier(MPI_COMM_WORLD, mpierr) -! call MPI_GATHERV( & -! id_loc (:), nt_local(myid+1), MPI_real, & -! id, nt_local,low_ind-1, MPI_real, & -! 0, MPI_COMM_WORLD, mpierr ) - - do i = 1, numprocs - if((I == 1).and.(myid == 0)) then - id(low_ind(i) : upp_ind(i)) = Id_loc(:) - else if (I > 1) then - if(I-1 == myid) then - ! send to root - call MPI_ISend(id_loc,nt_local(i),MPI_INTEGER,0,993,MPI_COMM_WORLD,req,mpierr) - call MPI_WAIT (req,MPI_STATUS_IGNORE,mpierr) - else if (myid == 0) then - ! root receives - call MPI_RECV(id(low_ind(i) : upp_ind(i)),nt_local(i) , MPI_INTEGER, i-1,993,MPI_COMM_WORLD,MPI_STATUS_IGNORE,mpierr) - endif - endif - end do - - deallocate (loni,lati,lonn,latt, tid_in) - call MPI_Barrier(MPI_COMM_WORLD, mpierr) - - if (root_proc) call read_and_write_rst (NTILES, SURFLAY, OutIsOld, NTILES_IN, id, __RC__) - - endif - - call MPI_BARRIER( MPI_COMM_WORLD, mpierr) - call MPI_FINALIZE(mpierr) - -contains - - SUBROUTINE read_and_write_rst (NTILES, SURFLAY, OutIsOld, NTILES_IN, idi, rc) - - implicit none - real, intent (in) :: SURFLAY - logical, intent (in) :: OutIsOld - integer, intent (in) :: NTILES, NTILES_IN - integer, pointer, dimension(:), optional, intent (in) :: idi - integer, optional, intent(out) :: rc - logical :: havedata, NewLand - character(len=256), parameter :: Names(29) = & - (/'BF1 ','BF2 ','BF3 ','VGWMAX','CDCR1 ', & - 'CDCR2 ','PSIS ','BEE ','POROS ','WPWET ', & - 'COND ','GNU ','ARS1 ','ARS2 ','ARS3 ', & - 'ARA1 ','ARA2 ','ARA3 ','ARA4 ','ARW1 ', & - 'ARW2 ','ARW3 ','ARW4 ','TSA1 ','TSA2 ', & - 'TSB1 ','TSB2 ','ATAU ','BTAU '/) - - integer, pointer :: ity(:) - real, allocatable :: BF1(:), BF2(:), BF3(:), VGWMAX(:) - real, allocatable :: CDCR1(:), CDCR2(:), PSIS(:), BEE(:) - real, allocatable :: POROS(:), WPWET(:), COND(:), GNU(:) - real, allocatable :: ARS1(:), ARS2(:), ARS3(:) - real, allocatable :: ARA1(:), ARA2(:), ARA3(:), ARA4(:) - real, allocatable :: ARW1(:), ARW2(:), ARW3(:), ARW4(:) - real, allocatable :: TSA1(:), TSA2(:), TSB1(:), TSB2(:) - real, allocatable :: ATAU2(:), BTAU2(:), DP2BR(:), rity(:) - - real :: zdep1, zdep2, zdep3, zmet, term1, term2, rdum - real, allocatable :: var1(:),var2(:,:) - character*256 :: vname - character*256 :: OutFileName - integer :: i, n, j,k,ncatch,idum - logical,allocatable :: written(:) - integer :: ndims,filetype - integer :: dimSizes(3),nVars - logical :: file_exists - integer, pointer :: Ido(:), idx(:), id(:) - logical :: InIsOld - type(NetCDF4_Fileformatter) :: InFmt,OutFmt,CatchFmt - type(FileMetadata) :: InCfg,OutCfg - type(StringVariableMap), pointer :: variables - type(Variable), pointer :: myVariable - type(StringVariableMapIterator) :: var_iter - character(len=:), pointer :: var_name,dname - type(StringVector), pointer :: var_dimensions - integer :: dim1, dim2 - character(256) :: Iam = "read_and_write_rst" - integer :: status - - print *, 'SURFLAY: ',SURFLAY - - inquire(file=trim(DataDir)//"mosaic_veg_typs_fracs",exist=havedata) - inquire(file=trim(DataDir)//"CLM_veg_typs_fracs" ,exist=NewLand ) - - print *, 'havedata = ',havedata - - call MAPL_NCIOGetFileType(InRestart, filetype,__RC__) - - if (filetype == 0) then - - call InFmt%open(InRestart,pFIO_READ,__RC__) - InCfg=InFmt%read(__RC__) - call MAPL_IOChangeRes(InCfg,OutCfg,(/'tile'/),(/ntiles/),__RC__) - i = index(InRestart,'/',back=.true.) - OutFileName = "OutData/"//trim(InRestart(i+1:)) - call OutFmt%create(OutFileName,__RC__) - call OutFmt%write(OutCfg,__RC__) - call MAPL_IOCountNonDimVars(OutCfg,nvars,__RC__) - - allocate(written(nvars)) - written=.false. - - else - - open(unit=50,FILE=InRestart,form='unformatted',& - status='old',convert='little_endian') - - do i=1,58 - read(50,end=2001) - end do -2001 continue - InIsOld = I==59 - - rewind(50) - - i = index(InRestart,'/',back=.true.) - - open(unit=40,FILE="OutData/"//trim(InRestart(i+1:)),form='unformatted',& - status='unknown',convert='little_endian') - - end if - - HAVE: if(havedata) then - - print *,'Working from Sariths data pretiled for this resolution' - - ! Get number of catchments - - open(unit=22, & - file=trim(DataDir)//"catchment.def",status='old',form='formatted') - - read (22, *) ncatch - - close(22) - - if(ncatch==ntiles) then - print *, "Read ",Ncatch," land tiles." - allocate (ido (ntiles)) - do i=1,ncatch - ido(i) = i - enddo - else - print *, "Number of tiles in data, ",Ncatch," does not match number in til file ", size(Ido) - call exit(1) - endif - - allocate(ity(ncatch),rity(ncatch)) - allocate ( BF1(ncatch), BF2 (ncatch), BF3(ncatch) ) - allocate (VGWMAX(ncatch), CDCR1(ncatch), CDCR2(ncatch) ) - allocate ( PSIS(ncatch), BEE(ncatch), POROS(ncatch) ) - allocate ( WPWET(ncatch), COND(ncatch), GNU(ncatch) ) - allocate ( ARS1(ncatch), ARS2(ncatch), ARS3(ncatch) ) - allocate ( ARA1(ncatch), ARA2(ncatch), ARA3(ncatch) ) - allocate ( ARA4(ncatch), ARW1(ncatch), ARW2(ncatch) ) - allocate ( ARW3(ncatch), ARW4(ncatch), TSA1(ncatch) ) - allocate ( TSA2(ncatch), TSB1(ncatch), TSB2(ncatch) ) - allocate ( ATAU2(ncatch), BTAU2(ncatch), DP2BR(ncatch) ) - - inquire(file = trim(DataDir)//'/catch_params.nc4', exist=file_exists) - - if(file_exists) then - print *,'FILE FORMAT FOR LAND BCS IS NC4' - call CatchFmt%open(trim(DataDir)//'/catch_params.nc4',pFIO_Read, __RC__) - call MAPL_VarRead ( catchFmt ,'OLD_ITY', rity, __RC__) - call MAPL_VarRead ( catchFmt ,'ARA1', ARA1, __RC__) - call MAPL_VarRead ( catchFmt ,'ARA2', ARA2, __RC__) - call MAPL_VarRead ( catchFmt ,'ARA3', ARA3, __RC__) - call MAPL_VarRead ( catchFmt ,'ARA4', ARA4, __RC__) - call MAPL_VarRead ( catchFmt ,'ARS1', ARS1, __RC__) - call MAPL_VarRead ( catchFmt ,'ARS2', ARS2, __RC__) - call MAPL_VarRead ( catchFmt ,'ARS3', ARS3, __RC__) - call MAPL_VarRead ( catchFmt ,'ARW1', ARW1, __RC__) - call MAPL_VarRead ( catchFmt ,'ARW2', ARW2, __RC__) - call MAPL_VarRead ( catchFmt ,'ARW3', ARW3, __RC__) - call MAPL_VarRead ( catchFmt ,'ARW4', ARW4, __RC__) - - if( SURFLAY.eq.20.0 ) then - call MAPL_VarRead ( catchFmt ,'ATAU2', ATAU2, __RC__) - call MAPL_VarRead ( catchFmt ,'BTAU2', BTAU2, __RC__) - endif - - if( SURFLAY.eq.50.0 ) then - call MAPL_VarRead ( catchFmt ,'ATAU5', ATAU2, __RC__) - call MAPL_VarRead ( catchFmt ,'BTAU5', BTAU2, __RC__) - endif - - call MAPL_VarRead ( catchFmt ,'PSIS', PSIS, __RC__) - call MAPL_VarRead ( catchFmt ,'BEE', BEE, __RC__) - call MAPL_VarRead ( catchFmt ,'BF1', BF1, __RC__) - call MAPL_VarRead ( catchFmt ,'BF2', BF2, __RC__) - call MAPL_VarRead ( catchFmt ,'BF3', BF3, __RC__) - call MAPL_VarRead ( catchFmt ,'TSA1', TSA1, __RC__) - call MAPL_VarRead ( catchFmt ,'TSA2', TSA2, __RC__) - call MAPL_VarRead ( catchFmt ,'TSB1', TSB1, __RC__) - call MAPL_VarRead ( catchFmt ,'TSB2', TSB2, __RC__) - call MAPL_VarRead ( catchFmt ,'COND', COND, __RC__) - call MAPL_VarRead ( catchFmt ,'GNU', GNU, __RC__) - call MAPL_VarRead ( catchFmt ,'WPWET', WPWET, __RC__) - call MAPL_VarRead ( catchFmt ,'DP2BR', DP2BR, __RC__) - call MAPL_VarRead ( catchFmt ,'POROS', POROS, __RC__) - call catchFmt%close(__RC__) - - else - open(unit=21, file=trim(DataDir)//"mosaic_veg_typs_fracs",status='old',form='formatted') - open(unit=22, file=trim(DataDir)//'bf.dat' ,form='formatted') - open(unit=23, file=trim(DataDir)//'soil_param.dat' ,form='formatted') - open(unit=24, file=trim(DataDir)//'ar.new' ,form='formatted') - open(unit=25, file=trim(DataDir)//'ts.dat' ,form='formatted') - open(unit=26, file=trim(DataDir)//'tau_param.dat' ,form='formatted') - - do n=1,ncatch - read (21,*) I, j, ITY(N) - read (22, *) i,j, GNU(n), BF1(n), BF2(n), BF3(n) - - read (23, *) i,j, idum, idum, BEE(n), PSIS(n),& - POROS(n), COND(n), WPWET(n), DP2BR(n) - - read (24, *) i,j, rdum, ARS1(n), ARS2(n), ARS3(n), & - ARA1(n), ARA2(n), ARA3(n), ARA4(n), & - ARW1(n), ARW2(n), ARW3(n), ARW4(n) - - read (25, *) i,j, rdum, TSA1(n), TSA2(n), TSB1(n), TSB2(n) - - if( SURFLAY.eq.20.0 ) read (26, *) i,j, ATAU2(n), BTAU2(n), rdum, rdum ! for old soil params - if( SURFLAY.eq.50.0 ) read (26, *) i,j, rdum , rdum, ATAU2(n), BTAU2(n) ! for new soil params - end do - - rity = float(ity) - CLOSE (21, STATUS = 'KEEP') - CLOSE (22, STATUS = 'KEEP') - CLOSE (23, STATUS = 'KEEP') - CLOSE (24, STATUS = 'KEEP') - CLOSE (25, STATUS = 'KEEP') - - endif - - do n=1,ncatch - - zdep2=1000. - zdep3=amax1(1000.,DP2BR(n)) - - if (zdep2 > 0.75*zdep3) then - zdep2 = 0.75*zdep3 - end if - - zdep1=20. - zmet=zdep3/1000. - - term1=-1.+((PSIS(n)-zmet)/PSIS(n))**((BEE(n)-1.)/BEE(n)) - term2=PSIS(n)*BEE(n)/(BEE(n)-1) - - VGWMAX(n) = POROS(n)*zdep2 - CDCR1(n) = 1000.*POROS(n)*(zmet-(-term2*term1)) - CDCR2(n) = (1.-WPWET(n))*POROS(n)*zdep3 - enddo - - - if (filetype /=0) then - do i=1,30 - read(50) - enddo - end if - - idx => ido - - else - - print *,'Working from restarts alone' - - ncatch = NTILES_IN - - allocate ( rity(ncatch)) - allocate ( BF1(ncatch), BF2 (ncatch), BF3(ncatch) ) - allocate (VGWMAX(ncatch), CDCR1(ncatch), CDCR2(ncatch) ) - allocate ( PSIS(ncatch), BEE(ncatch), POROS(ncatch) ) - allocate ( WPWET(ncatch), COND(ncatch), GNU(ncatch) ) - allocate ( ARS1(ncatch), ARS2(ncatch), ARS3(ncatch) ) - allocate ( ARA1(ncatch), ARA2(ncatch), ARA3(ncatch) ) - allocate ( ARA4(ncatch), ARW1(ncatch), ARW2(ncatch) ) - allocate ( ARW3(ncatch), ARW4(ncatch), TSA1(ncatch) ) - allocate ( TSA2(ncatch), TSB1(ncatch), TSB2(ncatch) ) - allocate ( ATAU2(ncatch), BTAU2(ncatch), DP2BR(ncatch) ) - - if (filetype == 0) then - - call MAPL_VarRead(InFmt,names(1),BF1, __RC__) - call MAPL_VarRead(InFmt,names(2),BF2, __RC__) - call MAPL_VarRead(InFmt,names(3),BF3, __RC__) - call MAPL_VarRead(InFmt,names(4),VGWMAX, __RC__) - call MAPL_VarRead(InFmt,names(5),CDCR1, __RC__) - call MAPL_VarRead(InFmt,names(6),CDCR2, __RC__) - call MAPL_VarRead(InFmt,names(7),PSIS, __RC__) - call MAPL_VarRead(InFmt,names(8),BEE, __RC__) - call MAPL_VarRead(InFmt,names(9),POROS, __RC__) - call MAPL_VarRead(InFmt,names(10),WPWET, __RC__) - - call MAPL_VarRead(InFmt,names(11),COND, __RC__) - call MAPL_VarRead(InFmt,names(12),GNU, __RC__) - call MAPL_VarRead(InFmt,names(13),ARS1, __RC__) - call MAPL_VarRead(InFmt,names(14),ARS2, __RC__) - call MAPL_VarRead(InFmt,names(15),ARS3, __RC__) - call MAPL_VarRead(InFmt,names(16),ARA1, __RC__) - call MAPL_VarRead(InFmt,names(17),ARA2, __RC__) - call MAPL_VarRead(InFmt,names(18),ARA3, __RC__) - call MAPL_VarRead(InFmt,names(19),ARA4, __RC__) - call MAPL_VarRead(InFmt,names(20),ARW1, __RC__) - - call MAPL_VarRead(InFmt,names(21),ARW2, __RC__) - call MAPL_VarRead(InFmt,names(22),ARW3, __RC__) - call MAPL_VarRead(InFmt,names(23),ARW4, __RC__) - call MAPL_VarRead(InFmt,names(24),TSA1, __RC__) - call MAPL_VarRead(InFmt,names(25),TSA2, __RC__) - call MAPL_VarRead(InFmt,names(26),TSB1, __RC__) - call MAPL_VarRead(InFmt,names(27),TSB2, __RC__) - call MAPL_VarRead(InFmt,names(28),ATAU2, __RC__) - call MAPL_VarRead(InFmt,names(29),BTAU2, __RC__) - call MAPL_VarRead(InFmt,'OLD_ITY',rITY, __RC__) - - else - - read(50) BF1 - read(50) BF2 - read(50) BF3 - read(50) VGWMAX - read(50) CDCR1 - read(50) CDCR2 - read(50) PSIS - read(50) BEE - read(50) POROS - read(50) WPWET - - read(50) COND - read(50) GNU - read(50) ARS1 - read(50) ARS2 - read(50) ARS3 - read(50) ARA1 - read(50) ARA2 - read(50) ARA3 - read(50) ARA4 - read(50) ARW1 - - read(50) ARW2 - read(50) ARW3 - read(50) ARW4 - read(50) TSA1 - read(50) TSA2 - read(50) TSB1 - read(50) TSB2 - read(50) ATAU2 - read(50) BTAU2 - read(50) rITY - - end if - - idx => idi - - endif HAVE - - if (filetype == 0) then - call MAPL_VarWrite(OutFmt,names(1),BF1(Idx)) - call MAPL_VarWrite(OutFmt,names(2),BF2(Idx)) - call MAPL_VarWrite(OutFmt,names(3),BF3(Idx)) - call MAPL_VarWrite(OutFmt,names(4),VGWMAX(Idx)) - call MAPL_VarWrite(OutFmt,names(5),CDCR1(Idx)) - call MAPL_VarWrite(OutFmt,names(6),CDCR2(Idx)) - call MAPL_VarWrite(OutFmt,names(7),PSIS(Idx)) - call MAPL_VarWrite(OutFmt,names(8),BEE(Idx)) - call MAPL_VarWrite(OutFmt,names(9),POROS(Idx)) - call MAPL_VarWrite(OutFmt,names(10),WPWET(Idx)) - call MAPL_VarWrite(OutFmt,names(11),COND(Idx)) - call MAPL_VarWrite(OutFmt,names(12),GNU(Idx)) - call MAPL_VarWrite(OutFmt,names(13),ARS1(Idx)) - call MAPL_VarWrite(OutFmt,names(14),ARS2(Idx)) - call MAPL_VarWrite(OutFmt,names(15),ARS3(Idx)) - call MAPL_VarWrite(OutFmt,names(16),ARA1(Idx)) - call MAPL_VarWrite(OutFmt,names(17),ARA2(Idx)) - call MAPL_VarWrite(OutFmt,names(18),ARA3(Idx)) - call MAPL_VarWrite(OutFmt,names(19),ARA4(Idx)) - call MAPL_VarWrite(OutFmt,names(20),ARW1(Idx)) - call MAPL_VarWrite(OutFmt,names(21),ARW2(Idx)) - call MAPL_VarWrite(OutFmt,names(22),ARW3(Idx)) - call MAPL_VarWrite(OutFmt,names(23),ARW4(Idx)) - call MAPL_VarWrite(OutFmt,names(24),TSA1(Idx)) - call MAPL_VarWrite(OutFmt,names(25),TSA2(Idx)) - call MAPL_VarWrite(OutFmt,names(26),TSB1(Idx)) - call MAPL_VarWrite(OutFmt,names(27),TSB2(Idx)) - call MAPL_VarWrite(OutFmt,names(28),ATAU2(Idx)) - call MAPL_VarWrite(OutFmt,names(29),BTAU2(Idx)) - call MAPL_VarWrite(OutFmt,'OLD_ITY',rity(Idx)) - - - call MAPL_IOCountNonDimVars(InCfg,nvars) - - variables => InCfg%get_variables() - var_iter = variables%begin() - i = 0 - do while (var_iter /= variables%end()) - - var_name => var_iter%key() - i=i+1 - do j=1,29 - if ( trim(var_name) == trim(names(j)) ) written(i) = .true. - enddo - if (trim(var_name) == "OLD_ITY" ) written(i) = .true. - - call var_iter%next() - - enddo - - variables => InCfg%get_variables() - var_iter = variables%begin() - n=0 - allocate(var1(NTILES_IN)) - do while (var_iter /= variables%end()) - - var_name => var_iter%key() - myVariable => var_iter%value() - - if (.not.InCfg%is_coordinate_variable(var_name)) then - - n=n+1 - if (.not.written(n) ) then - - var_dimensions => myVariable%get_dimensions() - - ndims = var_dimensions%size() - - if (ndims == 1) then - call MAPL_VarRead(InFmt,var_name,var1, __RC__) - call MAPL_VarWrite(OutFmt,var_name,var1(idx)) - else if (ndims == 2) then - - dname => myVariable%get_ith_dimension(2) - dim1=InCfg%get_dimension(dname) - do j=1,dim1 - call MAPL_VarRead(InFmt,var_name,var1,offset1=j, __RC__) - call MAPL_VarWrite(OutFmt,var_name,var1(idx),offset1=j) - enddo - else if (ndims == 3) then - - dname => myVariable%get_ith_dimension(2) - dim1=InCfg%get_dimension(dname) - dname => myVariable%get_ith_dimension(3) - dim2=InCfg%get_dimension(dname) - do k=1,dim2 - do j=1,dim1 - call MAPL_VarRead(InFmt,var_name,var1,offset1=j,offset2=k, __RC__) - call MAPL_VarWrite(OutFmt,var_name,var1(idx),offset1=j,offset2=k) - enddo - enddo - - end if - - end if - end if - call var_iter%next() - - enddo - - else - - write(40) BF1(Idx) - write(40) BF2(Idx) - write(40) BF3(Idx) - write(40) VGWMAX(Idx) - write(40) CDCR1(Idx) - write(40) CDCR2(Idx) - write(40) PSIS(Idx) - write(40) BEE(Idx) - write(40) POROS (Idx) - write(40) WPWET(Idx) - write(40) COND(Idx) - write(40) GNU(Idx) - write(40) ARS1(Idx) - write(40) ARS2(Idx) - write(40) ARS3(Idx) - write(40) ARA1(Idx) - write(40) ARA2(Idx) - write(40) ARA3(Idx) - write(40) ARA4(Idx) - write(40) ARW1(Idx) - write(40) ARW2(Idx) - write(40) ARW3(Idx) - write(40) ARW4(Idx) - write(40) TSA1(Idx) - write(40) TSA2(Idx) - write(40) TSB1(Idx) - write(40) TSB2(Idx) - write(40) ATAU2(Idx) - write(40) BTAU2(Idx) - write(40) rITY(Idx) - - - allocate(var1(NTILES_IN)) - allocate(var2(NTILES_IN,4)) - - ! TC QC - - do n=1,2 - read (50) var2 - write(40) ((var2(idx(i),j),i=1,ntiles),j=1,4) - end do - - !CAPAC CATDEF RZEXC SRFEXC ... SNDZN3 - - do n=1,20 - read (50) var1 - write(40) var1(Idx) - enddo - - ! CH CM CQ FR - - do n=1,4 - read (50) var2 - write(40) ((var2(idx(i),j),i=1,ntiles),j=1,4) - end do - - ! These are the 2 prev/next pairs that dont are not - ! in the internal in fortuna-2_0 and later. Earlier the - ! record are there, but their values are not needed, since - ! they are initialized on start-up. - - if(InIsOld) then - do n=1,4 - read (50) - enddo - endif - - if(OutIsOld) then - var1 = 0.0 - do n=1,4 - write(40) (var1(idx(i)),i = 1, ntiles) - end do - endif - - ! WW - - read (50) var2 - write(40) ((var2(idx(i),j),i=1,ntiles),j=1,4) - end if - if (present(rc)) rc =0 - !_RETURN(_SUCCESS) - END SUBROUTINE read_and_write_rst - - ! ***************************************************************************** - - subroutine init_MPI() - - ! initialize MPI - - call MPI_INIT(mpierr) - - call MPI_COMM_RANK( MPI_COMM_WORLD, myid, mpierr ) - call MPI_COMM_SIZE( MPI_COMM_WORLD, numprocs, mpierr ) - - if (myid .ne. 0) root_proc = .false. - -! write (*,*) "MPI process ", myid, " of ", numprocs, " is alive" -! write (*,*) "MPI process ", myid, ": root_proc=", root_proc - - end subroutine init_MPI - -end program mk_CatchRestarts - diff --git a/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/mk_GEOSldasRestarts.F90 b/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/mk_GEOSldasRestarts.F90 deleted file mode 100644 index 5e3da8d3a..000000000 --- a/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/mk_GEOSldasRestarts.F90 +++ /dev/null @@ -1,3917 +0,0 @@ -#define I_AM_MAIN -#include "MAPL_Generic.h" - -PROGRAM mk_GEOSldasRestarts - -! USAGE/HELP (NOTICE mpirun -np 1) -! mpirun -np 1 bin/mk_GEOSldasRestarts.x -h -! -! (1) to create an initial catch(cn)_internal_rst file ready for an offline experiment : -! -------------------------------------------------------------------------------------- -! (1.1) mpirun -np 1 bin/mk_GEOSldasRestarts.x -a SPONSORCODE -b BCSDIR -m MODEL -s SURFLAY(20/50) -t TILFILE -! where MODEL : catch or catchcn -! (1.2) sbatch mkLDAS.j -! -! (2) to reorder an LDASsa restart file to the order of the BCs for use in an GCM experiment : -! -------------------------------------------------------------------------------------------- -! mpirun -np 1 bin/mk_GEOSldasRestarts.x -b BCSDIR -d YYYYMMDD -e EXPNAME -l EXPDIR -m MODEL -s SURFLAY(20/50) -r Y -t TILFILE -p PARAMFILE - use netcdf - use MAPL - use mk_restarts_getidsMod, only: GetIDs, ReadTileFile_RealLatLon - use gFTL_StringVector - use ieee_arithmetic, only: isnan => ieee_is_nan - USE STIEGLITZSNOW, ONLY : & - StieglitzSnow_calc_tpsnow - implicit none - include 'mpif.h' - INCLUDE 'netcdf.inc' - - ! initialize to non-MPI values - - integer :: myid=0, numprocs=1, mpierr - logical :: root_proc=.true. - - ! Carbon model specifics - ! ---------------------- - - character*256 :: Usage="mk_GEOSldasRestarts.x -a SPONSORCODE -b BCSDIR -d YYYYMMDDHH -e EXPNAME -j JOBFILE -k ENS -l EXPDIR -m MODEL -r REORDER -s SURFLAY -t TILFILE -p PARAMFILE -f RSTFILE" - character*256 :: BCSDIR, SPONSORCODE, EXPNAME, EXPDIR, TILFILE, SFL, PFILE - character*400 :: CMD - character*10 :: YYYYMMDDHH - character(len=:), allocatable :: model, catch_scaler, rstfile - - real, parameter :: ECCENTRICITY = 0.0167 - real, parameter :: PERIHELION = 102.0 - real, parameter :: OBLIQUITY = 23.45 - integer, parameter :: EQUINOX = 80 - - integer, parameter :: nveg = 4 - integer, parameter :: nzone = 3 - integer, parameter :: VAR_COL_CLM40 = 40 ! number of CN column restart variables - integer, parameter :: VAR_PFT_CLM40 = 74 ! number of CN PFT variables per column - integer, parameter :: npft = 19 - integer, parameter :: npft_clm45 = 19 - integer, parameter :: VAR_COL_CLM45 = 35 ! number of CN column restart variables - integer, parameter :: VAR_PFT_CLM45 = 75 ! number of CN PFT variables per column - - real, parameter :: nan = O'17760000000' - real, parameter :: fmin= 1.e-4 ! ignore vegetation fractions at or below this value - integer, parameter :: OutUnit = 40, InUnit = 50 - character*256 :: arg, tmpstring, ESMADIR - character*1 :: opt, REORDER='N', JOBFILE ='N' - character*4 :: ENS='0000' - integer :: ntiles, rc, nxt - character(len=300) :: OutFileName - integer :: VAR_COL, VAR_PFT - integer :: iclass(npft) = (/1,1,2,3,3,4,5,5,6,7,8,9,10,11,12,11,12,11,12/) - - ! =============================================================================================== - ! Below hard-wired ldas restart file is from a global offline simulation on the SMAP M09 grid - ! after 1000s of years of simulations - - integer, parameter :: ntiles_cn = 1684725, ntiles_cat = 1653157 - character(len=300), parameter :: & - InCNRestart = '/discover/nobackup/projects/gmao/ssd/land/l_data/LandRestarts_for_Regridding/CatchCN/M09/20151231/catchcn_internal_rst', & - InCNTilFile = '/discover/nobackup/projects/gmao/bcs_shared/legacy_bcs/Heracles-NL/SMAP_EASEv2_M09/SMAP_EASEv2_M09_3856x1624.til', & - InCatRestart= '/discover/nobackup/projects/gmao/ssd/land/l_data/LandRestarts_for_Regridding/Catch/M09/20170101/catch_internal_rst', & - InCatTilFile= '/discover/nobackup/projects/gmao/ssd/land/l_data/geos5/bcs/CLSM_params/mkCatchParam_SMAP_L4SM_v002/' & - //'SMAP_EASEv2_M09/SMAP_EASEv2_M09_3856x1624.til', & - InCatRest45 = '/discover/nobackup/projects/gmao/ssd/land/l_data/LandRestarts_for_Regridding/Catch/M09/20170101/catch_internal_rst', & - InCatTil45 = '/discover/nobackup/projects/gmao/ssd/land/l_data/geos5/bcs/CLSM_params/mkCatchParam_SMAP_L4SM_v002/' & - //'SMAP_EASEv2_M09/SMAP_EASEv2_M09_3856x1624.til' - REAL :: SURFLAY = 50. - integer :: STATUS - - character(len=256), parameter :: CatNames (57) = & - (/'BF1 ', 'BF2 ', 'BF3 ', 'VGWMAX ', 'CDCR1 ', & - 'CDCR2 ', 'PSIS ', 'BEE ', 'POROS ', 'WPWET ', & - 'COND ', 'GNU ', 'ARS1 ', 'ARS2 ', 'ARS3 ', & - 'ARA1 ', 'ARA2 ', 'ARA3 ', 'ARA4 ', 'ARW1 ', & - 'ARW2 ', 'ARW3 ', 'ARW4 ', 'TSA1 ', 'TSA2 ', & - 'TSB1 ', 'TSB2 ', 'ATAU ', 'BTAU ', 'OLD_ITY', & - 'TC ', 'QC ', 'CAPAC ', 'CATDEF ', 'RZEXC ', & - 'SRFEXC ', 'GHTCNT1', 'GHTCNT2', 'GHTCNT3', 'GHTCNT4', & - 'GHTCNT5', 'GHTCNT6', 'TSURF ', 'WESNN1 ', 'WESNN2 ', & - 'WESNN3 ', 'HTSNNN1', 'HTSNNN2', 'HTSNNN3', 'SNDZN1 ', & - 'SNDZN2 ', 'SNDZN3 ', 'CH ', 'CM ', 'CQ ', & - 'FR ', 'WW '/) - - character(len=256), parameter :: CarbNames (68) = & - (/'BF1 ', 'BF2 ', 'BF3 ', 'VGWMAX ', 'CDCR1 ', & - 'CDCR2 ', 'PSIS ', 'BEE ', 'POROS ', 'WPWET ', & - 'COND ', 'GNU ', 'ARS1 ', 'ARS2 ', 'ARS3 ', & - 'ARA1 ', 'ARA2 ', 'ARA3 ', 'ARA4 ', 'ARW1 ', & - 'ARW2 ', 'ARW3 ', 'ARW4 ', 'TSA1 ', 'TSA2 ', & - 'TSB1 ', 'TSB2 ', 'ATAU ', 'BTAU ', 'ITY ', & - 'FVG ', 'TC ', 'QC ', 'TG ', 'CAPAC ', & - 'CATDEF ', 'RZEXC ', 'SRFEXC ', 'GHTCNT1', 'GHTCNT2', & - 'GHTCNT3', 'GHTCNT4', 'GHTCNT5', 'GHTCNT6', 'TSURF ', & - 'WESNN1 ', 'WESNN2 ', 'WESNN3 ', 'HTSNNN1', 'HTSNNN2', & - 'HTSNNN3', 'SNDZN1 ', 'SNDZN2 ', 'SNDZN3 ', 'CH ', & - 'CM ', 'CQ ', 'FR ', 'WW ', 'TILE_ID', & - 'NDEP ', 'CLI_T2M', 'BGALBVR', 'BGALBVF', 'BGALBNR', & - 'BGALBNF', 'CNCOL ', 'CNPFT ' /) - - CHARACTER( * ), PARAMETER :: LOWER_CASE = 'abcdefghijklmnopqrstuvwxyz' - CHARACTER( * ), PARAMETER :: UPPER_CASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' - logical :: clm45 = .false. - logical :: second_visit - integer :: zoom, k, n, infos - character*100 :: InRestart - character(100) :: Iam = "mk_GEOSldasRestarts" - - VAR_COL = VAR_COL_CLM40 - VAR_PFT = VAR_PFT_CLM40 - - call init_MPI() - call MPI_Info_create(infos, STATUS) ; VERIFY_(STATUS) - call MPI_Info_set(infos, "romio_cb_read", "automatic", STATUS) ; VERIFY_(STATUS) - call MPI_Barrier(MPI_COMM_WORLD, STATUS) - ! process commands - ! ---------------- - - CALL get_command (cmd) - call getenv ("ESMADIR" ,ESMADIR ) - nxt = 1 - - call getarg(nxt,arg) - rstfile = 'NONE' - do while(arg(1:1)=='-') - - opt=arg(2:2) - if(len(trim(arg))==2) then - nxt = nxt + 1 - call getarg(nxt,arg) - else - arg = arg(3:) - end if - - select case (opt) - case ('a') - SPONSORCODE = trim(arg) - case ('b') - BCSDIR = trim(arg) - case ('d') - YYYYMMDDHH = trim(arg) - case ('e') - EXPNAME = trim(arg) - case ('h') - print *,' ' - print *,'(1) to create an initial catch(cn)_internal_rst file ready for an offline experiment :' - print *,'--------------------------------------------------------------------------------------' - print *,'(1.1) mpirun -np 1 bin/mk_GEOSldasRestarts.x -a SPONSORCODE -b BCSDIR -m MODEL -s SURFLAY(20/50)' - print *,'where MODEL : catch, catchcnclm40, catchcnclm45' - print *,'(1.2) sbatch mkLDAS.j' - print *,' ' - print *,'(2) to reorder an LDASsa restart file to the order of the BCs for use in an GCM experiment :' - print *,'--------------------------------------------------------------------------------------------' - print *,'mpirun -np 1 bin/mk_GEOSldasRestarts.x -b BCSDIR -d YYYYMMDDHH -e EXPNAME -l EXPDIR -m MODEL -s SURFLAY(20/50) -r Y -t TILFILE -p PARAMFILE' - stop - case ('j') - JOBFILE = trim(arg) - case ('k') - ENS = trim(arg) - case ('l') - EXPDIR = trim(arg) - case ('m') - MODEL = StrLowCase(trim(arg)) - case ('r') - REORDER = trim(arg) - case ('s') - SFL = trim(arg) - read(arg,*) SURFLAY - case ('t') - TILFILE = trim(arg) - case ('p') - PFILE = trim(arg) - case ('f') - RSTFILE = trim(arg) - case default - print *, trim(Usage) - call exit(1) - end select - nxt = nxt + 1 - call getarg(nxt,arg) - end do - - if (index(model, 'catchcn') /=0 ) then - if((INDEX(BCSDIR, 'NL') == 0).AND.(INDEX(BCSDIR, 'OutData') == 0)) then - print *,'Land BCs in : ',trim(BCSDIR) - print *,'do not support ',trim (model) - stop - endif - - if (index(model,'45') /=0) then - clm45 = .true. - VAR_COL = VAR_COL_CLM45 - VAR_PFT = VAR_PFT_CLM45 - endif - catch_scaler = 'Scale_CatchCN' - else - catch_scaler = 'Scale_Catch' - endif - - - if(trim(REORDER) == 'Y') then - - ! This call is to reorder a LDASsa restart file (RESTART: 1) - - call reorder_LDASsa_restarts (SURFLAY, BCSDIR, YYYYMMDDHH, EXPNAME, EXPDIR, MODEL, ENS, rstfile, __RC__) - - call MPI_Barrier(MPI_COMM_WORLD, STATUS) - call MPI_FINALIZE(mpierr) - call exit(0) - - elseif (trim(REORDER) == 'R') then - - ! This call is to regrid LDASsa/GEOSldas restarts from a different grid (RESTART: 2) - - call regrid_from_xgrid (SURFLAY, BCSDIR, YYYYMMDDHH, EXPNAME, EXPDIR, MODEL, PFILE, rstfile) - - call MPI_Barrier(MPI_COMM_WORLD, STATUS) - call MPI_FINALIZE(mpierr) - call exit(0) - - else - - ! The user does not have restarts, thus cold start (RESTART: 0) - - if(JOBFILE == 'N') then - - call system('mkdir -p InData/ OutData/') - tmpstring = 'cp '//trim(BCSDIR)//'/'//trim(TILFILE)//' InData/OutTileFile' - call system(tmpstring) - tmpstring = 'cp '//trim(BCSDIR)//'/'//trim(TILFILE)//' OutData/OutTileFile' - call system(tmpstring) - tmpstring = 'ln -s '//trim(BCSDIR)//'/clsm OutData/clsm' - call system(tmpstring) - - open (10, file ='mkLDASsa.j', form = 'formatted', status ='unknown', action = 'write') - write(10,'(a)')'#!/bin/csh -fx' - write(10,'(a)')' ' - write(10,'(a)')'#SBATCH --account='//trim(SPONSORCODE) - write(10,'(a)')'#SBATCH --time=1:00:00' - write(10,'(a)')'#SBATCH --ntasks=56' - write(10,'(a)')'#SBATCH --job-name=mkLDAS' - write(10,'(a)')'###SBATCH --constraint=hasw' - write(10,'(a)')'#SBATCH --output=mkLDAS.o' - write(10,'(a)')'#SBATCH --error=mkLDAS.e' - write(10,'(a)')' ' - write(10,'(a)')'limit stacksize unlimited' - write(10,'(a)')'source bin/g5_modules' - !tmpstring = "set BINDIR=`ls -l bin | cut -d'>' -f2`" - !write(10,'(a)')trim(tmpstring) - !tmpstring = "setenv ESMADIR `echo $BINDIR | sed 's/Linux\/bin//g'`" - write(10,'(a)')'setenv ESMADIR '//trim(ESMADIR) - write(10,'(a)')'setenv MKL_CBWR SSE4_2 # ensure zero-diff across archs' - write(10,'(a)')'setenv MV2_ON_DEMAND_THRESHOLD 8192 # MVAPICH2' - write(10,'(a)')' ' - write(10,'(a)')'mpirun -np 56 '//trim(cmd)//' -j Y' - - write(10,'(a)')'bin/'//trim(catch_scaler)//' InData/'//model//'_internal_rst OutData/'//model//'_internal_rst '//model//'_internal_rst '//trim(SFL) - - close (10, status ='keep') - call system('chmod 755 mkLDASsa.j') - stop - endif - endif - - if (root_proc) then - - ! read in ntiles - ! ---------------------------- - - open (10,file = trim(BCSDIR)//'/clsm/catchment.def', form = 'formatted', status ='old', action = 'read') - read (10,*) ntiles - close (10, status ='keep') - - endif - - call MPI_BCAST(NTILES , 1, MPI_INTEGER , 0,MPI_COMM_WORLD,mpierr) - - ! Regridding - inquire(file='InData/'//trim(MODEL)//'_internal_rst',exist=second_visit ) - - if(.not. second_visit) then - call regrid_hyd_vars (NTILES, trim(MODEL)) - call MPI_Barrier(MPI_COMM_WORLD, STATUS) - stop - endif - if (root_proc) then - call read_bcs_data (NTILES, SURFLAY, trim(MODEL),'OutData/clsm/','OutData/'//trim(MODEL)//'_internal_rst', __RC__) - endif - - call MPI_Barrier(MPI_COMM_WORLD, STATUS) - - if(index(MODEL,'catchcn') /=0) then - - call regrid_carbon_vars (NTILES, model) - - endif - - call MPI_FINALIZE(mpierr) - -contains - - ! ***************************************************************************** - - SUBROUTINE regrid_from_xgrid (SURFLAY, BCSDIR, YYYYMMDDHH, EXPNAME, EXPDIR, MODEL, PFILE, rstfile) - - implicit none - - real, intent (in) :: SURFLAY - character(*), intent (in) :: BCSDIR, YYYYMMDDHH, EXPNAME, EXPDIR, MODEL, PFILE, rstfile - character(256) :: tile_coord, vname - character(300) :: rst_file - integer :: NTILES, nv, iv, i,j,k,n, nx, nz, ndims,dimSizes(3), NTILES_RST,nplus, STATUS,NCFID, req, filetype, OUTID - integer, allocatable :: LDAS2BCS (:), tile_id(:) - real, allocatable :: var1(:), var2(:),wesn1(:), htsn1(:), lon_rst(:), lat_rst(:) - logical :: fexist, bin_out = .false., lendian = .true. - real , allocatable, dimension (:) :: LATT, LONN, DAYX - real , pointer , dimension (:) :: long, latg, lonc, latc - integer, allocatable, dimension (:) :: low_ind, upp_ind, nt_local - integer, allocatable, dimension (:) :: Id_glb, id_loc - integer, allocatable, dimension (:,:) :: Id_glb_cn, id_loc_cn - integer, allocatable, dimension (:) :: ld_reorder, tid_offl - real, allocatable, dimension (:) :: CLMC_pf1, CLMC_pf2, CLMC_sf1, CLMC_sf2, & - CLMC_pt1, CLMC_pt2,CLMC_st1,CLMC_st2, var_dum2 - integer :: AGCM_YY,AGCM_MM,AGCM_DD,AGCM_HR=0,AGCM_DATE - real, allocatable, dimension(:,:) :: fveg_offl, ityp_offl, fveg_tmp, ityp_tmp - real, allocatable :: var_off_col (:,:,:), var_off_pft (:,:,:,:) - type(Netcdf4_FileFormatter) :: ldFmt - type(FileMetadata) :: meta_data - character(256) :: Iam = "regrid_from_xgrid" - ! read NTILES from output BCs and tile_coord from GEOSldas/LDASsa input restarts - - open (10,file =trim(BCSDIR)//"clsm/catchment.def",status='old',form='formatted') - read (10,*) ntiles - close (10, status = 'keep') - - ! Determine whether LDASsa or GEOSldas - if (trim(rstfile) == "NONE") then - if (trim(MODEL) == 'catch') then - rst_file = trim(EXPDIR)//'rs/ens'//ENS//'/Y'//YYYYMMDDHH(1:4)//'/M'//YYYYMMDDHH(5:6)//'/'//trim(ExpName)//& - '.catch_internal_rst.'//YYYYMMDDHH(1:8)//'_'//YYYYMMDDHH(9:10)//'00' - inquire(file = trim(rst_file), exist=fexist) - if (.not.fexist) then - rst_file = trim(EXPDIR)//'rs/ens'//ENS//'/Y'//YYYYMMDDHH(1:4)//'/M'//YYYYMMDDHH(5:6)//'/' & - //trim(ExpName)//'.ens'//ENS//'.catch_ldas_rst.'// & - YYYYMMDDHH(1:8)//'_'//YYYYMMDDHH(9:10)//'00z.bin' - lendian = .false. - endif - else !catchcn - rst_file = trim(EXPDIR)//'rs/ens'//ENS//'/Y'//YYYYMMDDHH(1:4)//'/M'//YYYYMMDDHH(5:6)//'/'//trim(ExpName)//& - '.'//trim(MODEL)//'_internal_rst.'//YYYYMMDDHH(1:8)//'_'//YYYYMMDDHH(9:10)//'00' - inquire(file = trim(rst_file), exist=fexist) - if (.not. fexist) then - rst_file = trim(EXPDIR)//'rs/ens'//ENS//'/Y'//YYYYMMDDHH(1:4)//'/M'//YYYYMMDDHH(5:6)//'/'//trim(ExpName)//& - '.ens'//ENS//'.'//trim(MODEL)//'_ldas_rst.'//YYYYMMDDHH(1:8)//'_'//YYYYMMDDHH(9:10)//'00z' - lendian = .false. - endif - endif ! catch - else ! rstfile is provided - rst_file = rstfile - if (index(rst_file, "_ldas_rst") /=0) lendian = .false. - endif - - if (index(MODEL, 'catchcn') /=0) then - call ldFmt%open(trim(rst_file) , pFIO_READ,__RC__) - meta_data = ldFmt%read(__RC__) - call ldFmt%close(__RC__) - if(meta_data%get_dimension('unknown_dim3',rc=status) == 105) then - clm45 = .true. - VAR_COL = VAR_COL_CLM45 - VAR_PFT = VAR_PFT_CLM45 - if (root_proc) print *, 'Processing CLM45 restarts : ', VAR_COL, VAR_PFT, clm45 - else - if (root_proc) print *, 'Processing CLM40 restarts : ', VAR_COL, VAR_PFT, clm45 - endif - endif - - ! Open input tile_coord - tile_coord = trim(EXPDIR)//'rc_out/'//trim(expname)//'.ldas_tilecoord.bin' - inquire(file = trim(tile_coord), exist=fexist) - if ( .not. fexist ) then - print*, tile_coord // " file not exists" - stop " no tile_coord file" - endif - - if(lendian) then - open (10,file =trim(tile_coord),status='old',form='unformatted', action = 'read') - else - open (10,file =trim(tile_coord),status='old',form='unformatted', action = 'read', convert ='big_endian') - endif - - read (10) NTILES_RST - - if(root_proc) then - print *,'NTILES in BCs : ',NTILES - print *,'NTILES in restarts : ',NTILES_RST - endif - - ! Domain decomposition - ! -------------------- - - allocate(low_ind ( numprocs)) - allocate(upp_ind ( numprocs)) - allocate(nt_local( numprocs)) - - low_ind (:) = 1 - upp_ind (:) = NTILES - nt_local(:) = NTILES - - if (numprocs > 1) then - do i = 1, numprocs - 1 - upp_ind(i) = low_ind(i) + (ntiles/numprocs) - 1 - low_ind(i+1) = upp_ind(i) + 1 - nt_local(i) = upp_ind(i) - low_ind(i) + 1 - end do - nt_local(numprocs) = upp_ind(numprocs) - low_ind(numprocs) + 1 - endif - - allocate (id_loc (nt_local (myid + 1))) - allocate (lonn (nt_local (myid + 1))) - allocate (latt (nt_local (myid + 1))) - allocate (lonc (1:ntiles_rst)) - allocate (latc (1:ntiles_rst)) - allocate (tid_offl (ntiles_rst)) - - if (root_proc) then - allocate (long (ntiles)) - allocate (latg (ntiles)) - allocate (ld_reorder(ntiles_rst)) - allocate (tile_id (1:ntiles_rst)) - allocate (LDAS2BCS (1:ntiles_rst)) - allocate (lon_rst (1:ntiles_rst)) - allocate (lat_rst (1:ntiles_rst)) - - call ReadTileFile_RealLatLon ('InData/OutTileFile', i, xlon=long, xlat=latg); VERIFY_(i-ntiles) - - read (10) LDAS2BCS - read (10) tile_id - read (10) tile_id - read (10) lon_rst - read (10) lat_rst - - tile_id = LDAS2BCS - - do n = 1, NTILES_RST - ld_reorder (tile_id(n)) = n - tid_offl(n) = n - end do - do n = 1, NTILES_RST - lonc(n) = lon_rst(ld_reorder(n)) - latc(n) = lat_rst(ld_reorder(n)) - END DO - deallocate (lon_rst, lat_rst) - endif - - close (10, status = 'keep') - call MPI_Barrier(MPI_COMM_WORLD, STATUS) - - do i = 1, numprocs - if((I == 1).and.(myid == 0)) then - lonn(:) = long(low_ind(i) : upp_ind(i)) - latt(:) = latg(low_ind(i) : upp_ind(i)) - else if (I > 1) then - if(I-1 == myid) then - ! receiving from root - call MPI_RECV(lonn,nt_local(i) , MPI_REAL, 0,995,MPI_COMM_WORLD,MPI_STATUS_IGNORE,mpierr) - call MPI_RECV(latt,nt_local(i) , MPI_REAL, 0,994,MPI_COMM_WORLD,MPI_STATUS_IGNORE,mpierr) - else if (myid == 0) then - ! root sends - call MPI_ISend(long(low_ind(i) : upp_ind(i)),nt_local(i),MPI_REAL,i-1,995,MPI_COMM_WORLD,req,mpierr) - call MPI_WAIT (req,MPI_STATUS_IGNORE,mpierr) - call MPI_ISend(latg(low_ind(i) : upp_ind(i)),nt_local(i),MPI_REAL,i-1,994,MPI_COMM_WORLD,req,mpierr) - call MPI_WAIT (req,MPI_STATUS_IGNORE,mpierr) - endif - endif - end do - - if(root_proc) deallocate (long) - - call MPI_BCAST(lonc,ntiles_rst,MPI_REAL,0,MPI_COMM_WORLD,mpierr) - call MPI_BCAST(latc,ntiles_rst,MPI_REAL,0,MPI_COMM_WORLD,mpierr) - call MPI_BCAST(tid_offl,size(tid_offl ),MPI_INTEGER,0,MPI_COMM_WORLD,mpierr) - - ! -------------------------------------------------------------------------------- - ! Here we create transfer index array to map offline restarts to output tile space - ! -------------------------------------------------------------------------------- - - ! id_glb for hydrologic variable - - call GetIds(lonc,latc,lonn,latt,id_loc, tid_offl) - if(root_proc) allocate (id_glb (ntiles)) - - call MPI_Barrier(MPI_COMM_WORLD, STATUS) -! call MPI_GATHERV( & -! id_loc, nt_local(myid+1) , MPI_real, & -! id_glb, nt_local,low_ind-1, MPI_real, & -! 0, MPI_COMM_WORLD, mpierr ) - do i = 1, numprocs - if((I == 1).and.(myid == 0)) then - id_glb(low_ind(i) : upp_ind(i)) = Id_loc(:) - else if (I > 1) then - if(I-1 == myid) then - ! send to root - call MPI_ISend(id_loc,nt_local(i),MPI_INTEGER,0,993,MPI_COMM_WORLD,req,mpierr) - call MPI_WAIT (req,MPI_STATUS_IGNORE,mpierr) - else if (myid == 0) then - ! root receives - call MPI_RECV(id_glb(low_ind(i) : upp_ind(i)),nt_local(i) , MPI_INTEGER, i-1,993,MPI_COMM_WORLD,MPI_STATUS_IGNORE,mpierr) - endif - endif - end do - - deallocate (id_loc) - - if(root_proc) then - - inquire(file = trim(rst_file), exist=fexist) - if (.not. fexist) then - print*, "WARNING!!" - print*, trim(rst_file) // " does not exist .. !" - stop - endif - - ! =========================================================== - ! Map restart nearest restart to output grid (hydrologic var) - ! =========================================================== - - filetype = 0 - call MAPL_NCIOGetFileType(rst_file, filetype,__RC__) - if(filetype == 0) then - ! GEOSldas CATCH/CATCHCN or CATCHCN LDASsa - call put_land_vars (NTILES, ntiles_rst, id_glb, ld_reorder, model, rst_file) - else - call read_ldas_restarts (NTILES, ntiles_rst, id_glb, ld_reorder, rst_file, pfile) - endif - - ! ==================== - ! READ AND PUT OUT BCS - ! ==================== - - do i = 1,10000 - ! just delaying few seconds to allow the system to copy the file - end do - - call read_bcs_data (NTILES, SURFLAY, trim(MODEL),'OutData/clsm/','OutData/'//trim(model)//'_internal_rst', __RC__) - - endif - - call MPI_Barrier(MPI_COMM_WORLD, STATUS) - - ! ============= - ! REGRID Carbon - ! ============= - - if (index(MODEL, 'catchcn') /=0) then - - allocate (CLMC_pf1(nt_local (myid + 1))) - allocate (CLMC_pf2(nt_local (myid + 1))) - allocate (CLMC_sf1(nt_local (myid + 1))) - allocate (CLMC_sf2(nt_local (myid + 1))) - allocate (CLMC_pt1(nt_local (myid + 1))) - allocate (CLMC_pt2(nt_local (myid + 1))) - allocate (CLMC_st1(nt_local (myid + 1))) - allocate (CLMC_st2(nt_local (myid + 1))) - allocate (ityp_offl (ntiles_rst,nveg)) - allocate (fveg_offl (ntiles_rst,nveg)) - allocate (id_loc_cn (nt_local (myid + 1),nveg)) - -! STATUS = NF90_OPEN ('OutData/catchcn_internal_rst',NF_WRITE,OUTID) ; VERIFY_(STATUS) - STATUS = NF_OPEN_PAR ('OutData/'//trim(model)//'_internal_rst',IOR(NF_WRITE,NF_MPIIO),MPI_COMM_WORLD, infos,OUTID) ; VERIFY_(STATUS) - STATUS = NF_GET_VARA_REAL(OUTID,VarID(OUTID,'ITY'), (/low_ind(myid+1),1/), (/nt_local(myid+1),1/),CLMC_pt1) - STATUS = NF_GET_VARA_REAL(OUTID,VarID(OUTID,'ITY'), (/low_ind(myid+1),2/), (/nt_local(myid+1),1/),CLMC_pt2) - STATUS = NF_GET_VARA_REAL(OUTID,VarID(OUTID,'ITY'), (/low_ind(myid+1),3/), (/nt_local(myid+1),1/),CLMC_st1) - STATUS = NF_GET_VARA_REAL(OUTID,VarID(OUTID,'ITY'), (/low_ind(myid+1),4/), (/nt_local(myid+1),1/),CLMC_st2) - STATUS = NF_GET_VARA_REAL(OUTID,VarID(OUTID,'FVG'), (/low_ind(myid+1),1/), (/nt_local(myid+1),1/),CLMC_pf1) - STATUS = NF_GET_VARA_REAL(OUTID,VarID(OUTID,'FVG'), (/low_ind(myid+1),2/), (/nt_local(myid+1),1/),CLMC_pf2) - STATUS = NF_GET_VARA_REAL(OUTID,VarID(OUTID,'FVG'), (/low_ind(myid+1),3/), (/nt_local(myid+1),1/),CLMC_sf1) - STATUS = NF_GET_VARA_REAL(OUTID,VarID(OUTID,'FVG'), (/low_ind(myid+1),4/), (/nt_local(myid+1),1/),CLMC_sf2) - - if (root_proc) then - - allocate (ityp_tmp (ntiles_rst,nveg)) - allocate (fveg_tmp (ntiles_rst,nveg)) - allocate (DAYX (NTILES)) - - READ(YYYYMMDDHH(1:8),'(I8)') AGCM_DATE - AGCM_YY = AGCM_DATE / 10000 - AGCM_MM = (AGCM_DATE - AGCM_YY*10000) / 100 - AGCM_DD = (AGCM_DATE - AGCM_YY*10000 - AGCM_MM*100) - - call compute_dayx ( & - NTILES, AGCM_YY, AGCM_MM, AGCM_DD, AGCM_HR, & - LATG, DAYX) - - STATUS = NF_OPEN (trim(rst_file),NF_NOWRITE,NCFID) ; VERIFY_(STATUS) - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'ITY'), (/1,1/), (/ntiles_rst,4/),ityp_tmp) - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'FVG'), (/1,1/), (/ntiles_rst,4/),fveg_tmp) - - do n = 1, NTILES_RST - ityp_offl (n,:) = ityp_tmp (ld_reorder(n),:) - fveg_offl (n,:) = fveg_tmp (ld_reorder(n),:) - - if((ityp_offl(N,3) == 0).and.(ityp_offl(N,4) == 0)) then - if(ityp_offl(N,1) /= 0) then - ityp_offl(N,3) = ityp_offl(N,1) - else - ityp_offl(N,3) = ityp_offl(N,2) - endif - endif - - if((ityp_offl(N,1) == 0).and.(ityp_offl(N,2) /= 0)) ityp_offl(N,1) = ityp_offl(N,2) - if((ityp_offl(N,2) == 0).and.(ityp_offl(N,1) /= 0)) ityp_offl(N,2) = ityp_offl(N,1) - if((ityp_offl(N,3) == 0).and.(ityp_offl(N,4) /= 0)) ityp_offl(N,3) = ityp_offl(N,4) - if((ityp_offl(N,4) == 0).and.(ityp_offl(N,3) /= 0)) ityp_offl(N,4) = ityp_offl(N,3) - end do - deallocate (ityp_tmp, fveg_tmp) - endif - - call MPI_BCAST(ityp_offl,size(ityp_offl),MPI_REAL ,0,MPI_COMM_WORLD,mpierr) - call MPI_BCAST(fveg_offl,size(fveg_offl),MPI_REAL ,0,MPI_COMM_WORLD,mpierr) - - call GetIds(lonc,latc,lonn,latt,id_loc_cn, tid_offl, & - CLMC_pf1, CLMC_pf2, CLMC_sf1, CLMC_sf2, CLMC_pt1, CLMC_pt2,CLMC_st1,CLMC_st2, & - fveg_offl, ityp_offl) - - if(root_proc) allocate (id_glb_cn (ntiles,nveg)) - - allocate (id_loc (ntiles)) - call MPI_Barrier(MPI_COMM_WORLD, STATUS) - deallocate (CLMC_pf1, CLMC_pf2, CLMC_sf1, CLMC_sf2) - deallocate (CLMC_pt1, CLMC_pt2, CLMC_st1, CLMC_st2) - - do nv = 1, nveg - call MPI_Barrier(MPI_COMM_WORLD, STATUS) - ! call MPI_GATHERV( & - ! id_loc (:,nv), nt_local(myid+1) , MPI_real, & - ! id_vec, nt_local,low_ind-1, MPI_real, & - ! 0, MPI_COMM_WORLD, mpierr ) - - do i = 1, numprocs - if((I == 1).and.(myid == 0)) then - id_loc(low_ind(i) : upp_ind(i)) = Id_loc_cn(:,nv) - else if (I > 1) then - if(I-1 == myid) then - ! send to root - call MPI_ISend(id_loc_cn(:,nv),nt_local(i),MPI_INTEGER,0,994,MPI_COMM_WORLD,req,mpierr) - call MPI_WAIT (req,MPI_STATUS_IGNORE,mpierr) - else if (myid == 0) then - ! root receives - call MPI_RECV(id_loc(low_ind(i) : upp_ind(i)),nt_local(i) , MPI_INTEGER, i-1,994,MPI_COMM_WORLD,MPI_STATUS_IGNORE,mpierr) - endif - endif - end do - - if(root_proc) id_glb_cn (:,nv) = id_loc - - end do - - if(root_proc) then - - allocate (var_off_col (1: NTILES_RST, 1 : nzone,1 : var_col)) - allocate (var_off_pft (1: NTILES_RST, 1 : nzone,1 : nveg, 1 : var_pft)) - allocate (var_dum2 (1:ntiles_rst)) - - i = 1 - do nv = 1,VAR_COL - do nz = 1,nzone - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'CNCOL'), (/1,i/), (/NTILES_RST,1 /),VAR_DUM2) - do k = 1, NTILES_RST - var_off_col(k, nz,nv) = VAR_DUM2(ld_reorder(k)) - end do - i = i + 1 - end do - end do - - i = 1 - do iv = 1,VAR_PFT - do nv = 1,nveg - do nz = 1,nzone - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'CNPFT'), (/1,i/), (/NTILES_RST,1 /),VAR_DUM2) - do k = 1, NTILES_RST - var_off_pft(K, nz,nv,iv) = VAR_DUM2(ld_reorder(k)) - end do - i = i + 1 - end do - end do - end do - - where(isnan(var_off_pft)) var_off_pft = 0. - where(var_off_pft /= var_off_pft) var_off_pft = 0. - print *, 'Writing regridded carbn' - call write_regridded_carbon (NTILES, ntiles_rst, NCFID, OUTID, id_glb_cn, & - DAYX, var_off_col,var_off_pft, ityp_offl, fveg_offl) - deallocate (var_off_col,var_off_pft) - endif - call MPI_Barrier(MPI_COMM_WORLD, STATUS) - STATUS = NF_CLOSE (OutID) - endif - - END SUBROUTINE regrid_from_xgrid - - ! ***************************************************************************** - - SUBROUTINE reorder_LDASsa_restarts (SURFLAY, BCSDIR, YYYYMMDDHH, EXPNAME, EXPDIR, MODEL, ENS, rstfile, rc) - - implicit none - - real, intent (in) :: SURFLAY - character(*), intent (in) :: BCSDIR, YYYYMMDDHH, EXPNAME, EXPDIR, MODEL, ENS, rstfile - integer, optional, intent(out) :: rc - character(256) :: tile_coord - character(300) :: rst_file, out_rst_file - type(Netcdf4_FileFormatter) :: InFmt,OutFmt, ldFmt - type(FileMetadata) :: meta_data - integer :: NTILES, i,j,k,n, ndims,dimSizes(3) - integer, allocatable :: LDAS2BCS (:), g2d(:), tile_id(:) - real, allocatable :: var1(:), var2(:),wesn1(:), htsn1(:) - integer :: dim1,dim2 - type(StringVariableMap), pointer :: variables - type(Variable), pointer :: var - type(StringVariableMapIterator) :: var_iter - type(StringVector), pointer :: var_dimensions - character(len=:), pointer :: vname,dname - logical :: fexist, bin_out = .false. - character(len=:), allocatable :: ftype - character*256 :: Iam = "reorder_LDASsa_restarts" - integer :: status - - if (trim(rstfile) == "NONE") then - ftype = '' - if(trim(MODEL) == 'catch') ftype='.bin' - rst_file = trim(EXPDIR)//'rs/ens'//ENS//'/Y'//YYYYMMDDHH(1:4)//'/M'//YYYYMMDDHH(5:6)//'/'//trim(ExpName)//& - '.ens'//ENS//'.'//trim(model)//'_ldas_rst.'//YYYYMMDDHH(1:8)//'_'//YYYYMMDDHH(9:10)//'00z'//trim(ftype) - else - rst_file = rstfile - endif - - inquire(file = trim(rst_file), exist=fexist) - if (.not. fexist) then - print*, "WARNING!!" - print*, rst_file // "does not exsit" - print*, "MAY USE ENS0000 only!!" - return - endif - - out_rst_file = trim(model)//ENS//'_internal_rst.'//YYYYMMDDHH(1:8) - - if (index(model,'catchcn') /=0) then - call ldFmt%open(trim(rst_file) , pFIO_READ,__RC__) - meta_data = ldFmt%read(__RC__) - call ldFmt%close(__RC__) - if(meta_data%get_dimension('unknown_dim3',rc=status) == 105) then - VAR_COL = VAR_COL_CLM45 - VAR_PFT = VAR_PFT_CLM45 - if ( .not. clm45) stop ' ERROR: Given clm45 restart, but the model is not clm45' - if (root_proc) print *, 'Processing CLM45 restarts : ', VAR_COL, VAR_PFT, clm45 - else - if (root_proc) print *, 'Processing CLM40 restarts : ', VAR_COL, VAR_PFT, clm45 - endif - endif - - open (10,file =trim(BCSDIR)//"clsm/catchment.def",status='old',form='formatted') - read (10,*) ntiles - close (10, status = 'keep') - - ! read NTILES from BCs and tile_coord from LDASsa experiment - - tile_coord = trim(EXPDIR)//'rc_out/'//trim(expname)//'.ldas_tilecoord.bin' - inquire(file = tile_coord, exist=fexist) - if (.not. fexist) then - print*, trim(tile_coord) // " file should be provided" - stop "no tile_coord file" - endif - - open (10,file =trim(tile_coord),status='old',form='unformatted',convert='big_endian') - read (10) i - if (i /= ntiles) then - print *,'NTILES BCs/LDASsa mismatch:', i,ntiles - stop - endif - - if(trim(MODEL) == 'catch') then - call InFmt%open('/discover/nobackup/projects/gmao/ssd/land/l_data/LandRestarts_for_Regridding/Catch/catch_internal_rst' , pFIO_READ,__RC__) - end if - if(index(MODEL, 'catchcn') /=0) then - if (clm45) then - call InFmt%open('/discover/nobackup/projects/gmao/ssd/land/l_data/LandRestarts_for_Regridding/CatchCN/catchcn_internal_clm45',PFIO_READ, __RC__) - else - call InFmt%open('/discover/nobackup/projects/gmao/ssd/land/l_data/LandRestarts_for_Regridding/CatchCN/catchcn_internal_dummy' , pFIO_READ, __RC__) - endif - end if - meta_data = InFmt%read(__RC__) - call inFmt%close(__RC__) - - call meta_data%modify_dimension('tile',ntiles,__RC__) - - call OutFmt%create(trim(out_rst_file),__RC__) - call OutFmt%write(meta_data, __RC__) - - - allocate (tile_id (1:ntiles)) - allocate (LDAS2BCS (1:ntiles)) - allocate (g2d (1:ntiles)) - - read (10) LDAS2BCS - close (10, status = 'keep') - - ! ========================== - ! READ/WRITE LDASsa RESTARTS - ! ========================== - - allocate(var1(ntiles)) - allocate(var2(ntiles)) - allocate(wesn1 (ntiles)) - allocate(htsn1 (ntiles)) - ! CH CM CQ FR WW - ! WW - var1 = 0.1 - do j = 1,4 - call MAPL_VarWrite(OutFmt,'WW',var1 ,offset1=j) - end do - ! FR - var1 = 0.25 - do j = 1,4 - call MAPL_VarWrite(OutFmt,'FR',var1 ,offset1=j) - end do - ! CH CM CQ - var1 = 0.001 - do j = 1,4 - call MAPL_VarWrite(OutFmt,'CH',var1 ,offset1=j) - call MAPL_VarWrite(OutFmt,'CM',var1 ,offset1=j) - call MAPL_VarWrite(OutFmt,'CQ',var1 ,offset1=j) - end do - - tile_id = LDAS2BCS - do n = 1, NTILES - G2D(tile_id(n)) = n - end do - - if(trim(MODEL) == 'catch') then - - open(10, file=trim(rst_file), form='unformatted', status='old', & - convert='big_endian', action='read') - - var1 = real(tile_id) - var2 = var1 (tile_id) - do n = 1, NTILES - var2(n) = var1(g2d(n)) - end do - call MAPL_VarWrite(OutFmt,'TILE_ID' ,var2) - - read(10) var1 - var2 = var1 (tile_id) - do n = 1, NTILES - var2(n) = var1(g2d(n)) - end do - call MAPL_VarWrite(OutFmt,'TC' ,var2, offset1=1) - read(10) var1 - var2 = var1 (tile_id) - do n = 1, NTILES - var2(n) = var1(g2d(n)) - end do - call MAPL_VarWrite(OutFmt,'TC' ,var2, offset1=2) - read(10) var1 - var2 = var1 (tile_id) - do n = 1, NTILES - var2(n) = var1(g2d(n)) - end do - call MAPL_VarWrite(OutFmt,'TC' ,var2, offset1=3) - - read(10) var1 - var2 = var1 (tile_id) - do n = 1, NTILES - var2(n) = var1(g2d(n)) - end do - call MAPL_VarWrite(OutFmt,'QC' ,var2, offset1=1) - read(10) var1 - var2 = var1 (tile_id) - do n = 1, NTILES - var2(n) = var1(g2d(n)) - end do - call MAPL_VarWrite(OutFmt,'QC' ,var2, offset1=2) - read(10) var1 - var2 = var1 (tile_id) - do n = 1, NTILES - var2(n) = var1(g2d(n)) - end do - call MAPL_VarWrite(OutFmt,'QC' ,var2, offset1=3) - call MAPL_VarWrite(OutFmt,'QC' ,var2, offset1=4) - - read(10) var1 - var2 = var1 (tile_id) - do n = 1, NTILES - var2(n) = var1(g2d(n)) - end do - call MAPL_VarWrite(OutFmt,'CAPAC' ,var2) - read(10) var1 - var2 = var1 (tile_id) - do n = 1, NTILES - var2(n) = var1(g2d(n)) - end do - call MAPL_VarWrite(OutFmt,'CATDEF' ,var2) - read(10) var1 - var2 = var1 (tile_id) - do n = 1, NTILES - var2(n) = var1(g2d(n)) - end do - call MAPL_VarWrite(OutFmt,'RZEXC' ,var2) - read(10) var1 - var2 = var1 (tile_id) - do n = 1, NTILES - var2(n) = var1(g2d(n)) - end do - call MAPL_VarWrite(OutFmt,'SRFEXC' ,var2) - read(10) var1 - var2 = var1 (tile_id) - do n = 1, NTILES - var2(n) = var1(g2d(n)) - end do - call MAPL_VarWrite(OutFmt,'GHTCNT1' ,var2) - read(10) var1 - var2 = var1 (tile_id) - do n = 1, NTILES - var2(n) = var1(g2d(n)) - end do - call MAPL_VarWrite(OutFmt,'GHTCNT2' ,var2) - read(10) var1 - var2 = var1 (tile_id) - do n = 1, NTILES - var2(n) = var1(g2d(n)) - end do - call MAPL_VarWrite(OutFmt,'GHTCNT3' ,var2) - read(10) var1 - var2 = var1 (tile_id) - do n = 1, NTILES - var2(n) = var1(g2d(n)) - end do - call MAPL_VarWrite(OutFmt,'GHTCNT4' ,var2) - read(10) var1 - var2 = var1 (tile_id) - do n = 1, NTILES - var2(n) = var1(g2d(n)) - end do - call MAPL_VarWrite(OutFmt,'GHTCNT5' ,var2) - read(10) var1 - var2 = var1 (tile_id) - do n = 1, NTILES - var2(n) = var1(g2d(n)) - end do - call MAPL_VarWrite(OutFmt,'GHTCNT6' ,var2) - read(10) var1 - var2 = var1 (tile_id) - - do n = 1, NTILES - var2(n) = var1(g2d(n)) - end do - wesn1 = var2 - call MAPL_VarWrite(OutFmt,'WESNN1' ,var2) - read(10) var1 - var2 = var1 (tile_id) - do n = 1, NTILES - var2(n) = var1(g2d(n)) - end do - call MAPL_VarWrite(OutFmt,'WESNN2' ,var2) - read(10) var1 - var2 = var1 (tile_id) - do n = 1, NTILES - var2(n) = var1(g2d(n)) - end do - call MAPL_VarWrite(OutFmt,'WESNN3' ,var2) - read(10) var1 - var2 = var1 (tile_id) - do n = 1, NTILES - var2(n) = var1(g2d(n)) - end do - htsn1 = var2 - call MAPL_VarWrite(OutFmt,'HTSNNN1' ,var2) - read(10) var1 - var2 = var1 (tile_id) - do n = 1, NTILES - var2(n) = var1(g2d(n)) - end do - call MAPL_VarWrite(OutFmt,'HTSNNN2' ,var2) - read(10) var1 - var2 = var1 (tile_id) - do n = 1, NTILES - var2(n) = var1(g2d(n)) - end do - call MAPL_VarWrite(OutFmt,'HTSNNN3' ,var2) - read(10) var1 - var2 = var1 (tile_id) - do n = 1, NTILES - var2(n) = var1(g2d(n)) - end do - call MAPL_VarWrite(OutFmt,'SNDZN1' ,var2) - read(10) var1 - var2 = var1 (tile_id) - do n = 1, NTILES - var2(n) = var1(g2d(n)) - end do - call MAPL_VarWrite(OutFmt,'SNDZN2' ,var2) - read(10) var1 - var2 = var1 (tile_id) - do n = 1, NTILES - var2(n) = var1(g2d(n)) - end do - call MAPL_VarWrite(OutFmt,'SNDZN3' ,var2) - call STIEGLITZSNOW_CALC_TPSNOW(NTILES, HTSN1(:), WESN1(:), var2, var1) - var2 = var2 + 273.16 - call MAPL_VarWrite(OutFmt,'TC' ,var2, offset1=4) - deallocate (var1, var2) - call OutFmt%close() - close(10) - - else ! CATCHCN - - call InFmt%open(trim(rst_file),pFIO_READ,__RC__) - meta_data = InFmt%read(__RC__) - - call MAPL_VarRead ( InFmt,'TILE_ID',var1, __RC__) - if(sum (nint(var1) - LDAS2BCS) /= 0) then - print *, 'Tile order mismatch ', sum(var1)/ntiles, sum(LDAS2BCS)/ntiles - stop - endif - - variables => meta_data%get_variables() - var_iter = variables%begin() - do while (var_iter /= variables%end()) - - vname => var_iter%key() - var => var_iter%value() - var_dimensions => var%get_dimensions() - - ndims = var_dimensions%size() - - if (ndims == 1) then - call MAPL_VarRead ( InFmt,vname,var1, __RC__) - var2 = var1 (tile_id) - do n = 1, NTILES - var2(n) = var1(g2d(n)) - end do - if(trim(vname) == 'SFMCM' ) var2 = 0. - if(trim(vname) == 'BFLOWM' ) var2 = 0. - if(trim(vname) == 'TOTWATM') var2 = 0. - if(trim(vname) == 'TAIRM' ) var2 = 0. - if(trim(vname) == 'TPM' ) var2 = 0. - if(trim(vname) == 'CNSUM' ) var2 = 0. - if(trim(vname) == 'SNDZM' ) var2 = 0. - if(trim(vname) == 'ASNOWM' ) var2 = 0. - if(trim(vname) == 'TSURF' ) var2 = 0. - - call MAPL_VarWrite(OutFmt,vname,var2) - - else if (ndims == 2) then - - dname => var%get_ith_dimension(2) - dim1=meta_data%get_dimension(dname) - do j=1,dim1 - call MAPL_VarRead ( InFmt,vname,var1 ,offset1=j, __RC__) - var2 = var1 (tile_id) - do n = 1, NTILES - var2(n) = var1(g2d(n)) - end do - if(trim(vname) == 'TGWM' ) var2 = 0. - if(trim(vname) == 'RZMM' ) var2 = 0. - if(trim(vname) == 'WW' ) var2 = 0.1 - if(trim(vname) == 'FR' ) var2 = 0.25 - if(trim(vname) == 'CQ' ) var2 = 0.001 - if(trim(vname) == 'CN' ) var2 = 0.001 - if(trim(vname) == 'CM' ) var2 = 0.001 - if(trim(vname) == 'CH' ) var2 = 0.001 - call MAPL_VarWrite(OutFmt,vname,var2 ,offset1=j) - enddo - - else if (ndims == 3) then - - dname => var%get_ith_dimension(2) - dim1=meta_data%get_dimension(dname) - dname => var%get_ith_dimension(3) - dim2=meta_data%get_dimension(dname) - do i=1,dim2 - do j=1,dim1 - call MAPL_VarRead ( InFmt,vname,var1 ,offset1=j,offset2=i, __RC__) - var2 = var1 (tile_id) - do n = 1, NTILES - var2(n) = var1(g2d(n)) - end do - if(trim(vname) == 'PSNSUNM' ) var2 = 0. - if(trim(vname) == 'PSNSHAM' ) var2 = 0. - call MAPL_VarWrite(OutFmt,vname,var2 ,offset1=j,offset2=i) - enddo - enddo - - end if - call var_iter%next() - enddo - - call InFmt%close() - call OutFmt%close() - deallocate (var1, var2, tile_id) - endif - - call read_bcs_data (ntiles, SURFLAY, trim(MODEL), trim(BCSDIR)//'/clsm/',trim(out_rst_file), __RC__) - - if(bin_out) then - call InFmt%open(trim(out_rst_file),pFIO_READ,__RC__) - open(unit=30, file=trim(out_rst_file)//'.bin', form='unformatted') - call write_bin (30, InFmt, NTILES) - close(30) - call InFmt%close() - endif - if (present(rc)) rc =0 - !_RETURN(_SUCCESS) - - END SUBROUTINE reorder_LDASsa_restarts - - ! ***************************************************************************** - - SUBROUTINE regrid_hyd_vars (NTILES, model) - - implicit none - integer, intent (in) :: NTILES - character(*), intent (in) :: model - - ! =============================================================================================== - - integer, allocatable, dimension(:) :: Id_glb, Id_loc - integer, allocatable, dimension(:) :: ld_reorder, tid_offl - real , allocatable, dimension(:) :: tmp_var - integer :: n,i,nplus, STATUS,NCFID, req - integer :: local_id, ntiles_smap - real , allocatable, dimension (:) :: LATT, LONN - real , pointer , dimension (:) :: long, latg, lonc, latc - integer, allocatable :: low_ind(:), upp_ind(:), nt_local (:) - - logical :: all_found - character(256) :: Iam="regrid_hyd_vars" - - if(index(MODEL, 'catchcn') /=0) ntiles_smap = ntiles_cn - if(trim(MODEL) == 'catch' ) ntiles_smap = ntiles_cat - - allocate (tid_offl (ntiles_smap)) - allocate (tmp_var (ntiles_smap)) - - allocate(low_ind ( numprocs)) - allocate(upp_ind ( numprocs)) - allocate(nt_local( numprocs)) - - low_ind (:) = 1 - upp_ind (:) = NTILES - nt_local(:) = NTILES - - ! Domain decomposition - ! -------------------- - - if (numprocs > 1) then - do i = 1, numprocs - 1 - upp_ind(i) = low_ind(i) + (ntiles/numprocs) - 1 - low_ind(i+1) = upp_ind(i) + 1 - nt_local(i) = upp_ind(i) - low_ind(i) + 1 - end do - nt_local(numprocs) = upp_ind(numprocs) - low_ind(numprocs) + 1 - endif - - allocate (id_loc (nt_local (myid + 1))) - allocate (lonn (nt_local (myid + 1))) - allocate (latt (nt_local (myid + 1))) - allocate (lonc (1:ntiles_smap)) - allocate (latc (1:ntiles_smap)) - - if (root_proc) then - - allocate (long (ntiles)) - allocate (latg (ntiles)) - allocate (ld_reorder(ntiles_smap)) - - call ReadTileFile_RealLatLon ('InData/OutTileFile', i, xlon=long, xlat=latg); VERIFY_(i-ntiles) - ! --------------------------------------------- - ! Read exact lonc, latc from offline .til File - ! --------------------------------------------- - - if(index(MODEL,'catchcn') /=0) then - call ReadTileFile_RealLatLon(trim(InCNTilFile ),i,xlon=lonc,xlat=latc) - VERIFY_(i-ntiles_smap) - endif - if(trim(MODEL) == 'catch' ) then - call ReadTileFile_RealLatLon(trim(InCatTilFile),i,xlon=lonc,xlat=latc) - VERIFY_(i-ntiles_smap) - endif - if(index(MODEL,'catchcn') /=0) then - STATUS = NF_OPEN (trim(InCNRestart ),NF_NOWRITE,NCFID) ; VERIFY_(STATUS) - endif - if(trim(MODEL) == 'catch' ) then - STATUS = NF_OPEN (trim(InCatRestart),NF_NOWRITE,NCFID) ; VERIFY_(STATUS) - endif - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'TILE_ID' ), (/1/), (/NTILES_SMAP/),tmp_var) - STATUS = NF_CLOSE (NCFID) - - do n = 1, ntiles_smap - ld_reorder ( NINT(tmp_var(n))) = n - tid_offl(n) = n - end do - - deallocate (tmp_var) - - endif - - call MPI_Barrier(MPI_COMM_WORLD, STATUS) - - do i = 1, numprocs - if((I == 1).and.(myid == 0)) then - lonn(:) = long(low_ind(i) : upp_ind(i)) - latt(:) = latg(low_ind(i) : upp_ind(i)) - else if (I > 1) then - if(I-1 == myid) then - ! receiving from root - call MPI_RECV(lonn,nt_local(i) , MPI_REAL, 0,995,MPI_COMM_WORLD,MPI_STATUS_IGNORE,mpierr) - call MPI_RECV(latt,nt_local(i) , MPI_REAL, 0,994,MPI_COMM_WORLD,MPI_STATUS_IGNORE,mpierr) - else if (myid == 0) then - ! root sends - call MPI_ISend(long(low_ind(i) : upp_ind(i)),nt_local(i),MPI_REAL,i-1,995,MPI_COMM_WORLD,req,mpierr) - call MPI_WAIT (req,MPI_STATUS_IGNORE,mpierr) - call MPI_ISend(latg(low_ind(i) : upp_ind(i)),nt_local(i),MPI_REAL,i-1,994,MPI_COMM_WORLD,req,mpierr) - call MPI_WAIT (req,MPI_STATUS_IGNORE,mpierr) - endif - endif - end do - -! call MPI_SCATTERV ( & -! long,nt_local,low_ind-1,MPI_real, & -! lonn,size(lonn),MPI_real , & -! 0,MPI_COMM_WORLD, mpierr ) -! -! call MPI_SCATTERV ( & -! latg,nt_local,low_ind-1,MPI_real, & -! latt,nt_local(myid+1),MPI_real , & -! 0,MPI_COMM_WORLD, mpierr ) - - if(root_proc) deallocate (long, latg) - - call MPI_BCAST(lonc,ntiles_smap,MPI_REAL,0,MPI_COMM_WORLD,mpierr) - call MPI_BCAST(latc,ntiles_smap,MPI_REAL,0,MPI_COMM_WORLD,mpierr) - call MPI_BCAST(tid_offl,size(tid_offl ),MPI_INTEGER,0,MPI_COMM_WORLD,mpierr) - - ! -------------------------------------------------------------------------------- - ! Here we create transfer index array to map offline restarts to output tile space - ! -------------------------------------------------------------------------------- - - call GetIds(lonc,latc,lonn,latt,id_loc, tid_offl) - - ! Loop through NTILES (# of tiles in output array) find the nearest neighbor from Qing. - - if(root_proc) allocate (id_glb (ntiles)) - - call MPI_Barrier(MPI_COMM_WORLD, STATUS) -! call MPI_GATHERV( & -! id_loc, nt_local(myid+1) , MPI_real, & -! id_glb, nt_local,low_ind-1, MPI_real, & -! 0, MPI_COMM_WORLD, mpierr ) - do i = 1, numprocs - if((I == 1).and.(myid == 0)) then - id_glb(low_ind(i) : upp_ind(i)) = Id_loc(:) - else if (I > 1) then - if(I-1 == myid) then - ! send to root - call MPI_ISend(id_loc,nt_local(i),MPI_INTEGER,0,993,MPI_COMM_WORLD,req,mpierr) - call MPI_WAIT (req,MPI_STATUS_IGNORE,mpierr) - else if (myid == 0) then - ! root receives - call MPI_RECV(id_glb(low_ind(i) : upp_ind(i)),nt_local(i) , MPI_INTEGER, i-1,993,MPI_COMM_WORLD,MPI_STATUS_IGNORE,mpierr) - endif - endif - end do - - if (root_proc) call put_land_vars (NTILES, ntiles_smap, id_glb, ld_reorder, model) - - call MPI_Barrier(MPI_COMM_WORLD, STATUS) - - END SUBROUTINE regrid_hyd_vars - - - ! ***************************************************************************** - - SUBROUTINE read_bcs_data (ntiles, SURFLAY,MODEL, DataDir, InRestart, rc) - - ! This subroutine : - ! 1) reads BCs from BCSDIR and hydrological varables from InRestart. - ! InRestart is a catchcn_internal_rst nc4 file. - ! - ! 2) writes out BCs and hydrological variables in catchcn_internal_rst (1:72). - ! output catchcn_internal_rst is nc4. - - implicit none - real, intent (in) :: SURFLAY - integer, intent (in) :: ntiles - character(*), intent (in) :: MODEL, DataDir, InRestart - integer, optional, intent(out) :: rc - real, allocatable :: CLMC_pf1(:), CLMC_pf2(:), CLMC_sf1(:), CLMC_sf2(:) - real, allocatable :: CLMC_pt1(:), CLMC_pt2(:), CLMC_st1(:), CLMC_st2(:) - real, allocatable :: CLMC45_pf1(:), CLMC45_pf2(:), CLMC45_sf1(:), CLMC45_sf2(:) - real, allocatable :: CLMC45_pt1(:), CLMC45_pt2(:), CLMC45_st1(:), CLMC45_st2(:) - real, allocatable :: BF1(:), BF2(:), BF3(:), VGWMAX(:) - real, allocatable :: CDCR1(:), CDCR2(:), PSIS(:), BEE(:) - real, allocatable :: POROS(:), WPWET(:), COND(:), GNU(:) - real, allocatable :: ARS1(:), ARS2(:), ARS3(:) - real, allocatable :: ARA1(:), ARA2(:), ARA3(:), ARA4(:) - real, allocatable :: ARW1(:), ARW2(:), ARW3(:), ARW4(:) - real, allocatable :: TSA1(:), TSA2(:), TSB1(:), TSB2(:) - real, allocatable :: ATAU2(:), BTAU2(:), DP2BR(:), CanopH(:) - real, allocatable :: NDEP(:), BVISDR(:), BVISDF(:), BNIRDR(:), BNIRDF(:) - real, allocatable :: T2(:), var1(:), hdm(:), fc(:), gdp(:), peatf(:), RITY(:) - integer, allocatable :: ity(:), abm (:) - integer :: NCFID, STATUS - integer :: idum, i,j,n, ib, nv - real :: rdum, zdep1, zdep2, zdep3, zmet, term1, term2, bare,fvg(4) - logical :: NEWLAND, isCatchCN - logical :: file_exists - type(NetCDF4_Fileformatter) :: CatchFmt,CatchCNFmt - character*256 :: Iam = "read_bcs_data" - - allocate ( BF1(ntiles), BF2 (ntiles), BF3(ntiles) ) - allocate (VGWMAX(ntiles), CDCR1(ntiles), CDCR2(ntiles) ) - allocate ( PSIS(ntiles), BEE(ntiles), POROS(ntiles) ) - allocate ( WPWET(ntiles), COND(ntiles), GNU(ntiles) ) - allocate ( ARS1(ntiles), ARS2(ntiles), ARS3(ntiles) ) - allocate ( ARA1(ntiles), ARA2(ntiles), ARA3(ntiles) ) - allocate ( ARA4(ntiles), ARW1(ntiles), ARW2(ntiles) ) - allocate ( ARW3(ntiles), ARW4(ntiles), TSA1(ntiles) ) - allocate ( TSA2(ntiles), TSB1(ntiles), TSB2(ntiles) ) - allocate ( ATAU2(ntiles), BTAU2(ntiles), DP2BR(ntiles) ) - allocate (BVISDR(ntiles), BVISDF(ntiles), BNIRDR(ntiles) ) - allocate (BNIRDF(ntiles), T2(ntiles), NDEP(ntiles) ) - allocate ( ity(ntiles), CanopH(ntiles) ) - allocate (CLMC_pf1(ntiles), CLMC_pf2(ntiles), CLMC_sf1(ntiles)) - allocate (CLMC_sf2(ntiles), CLMC_pt1(ntiles), CLMC_pt2(ntiles)) - allocate (CLMC45_pf1(ntiles), CLMC45_pf2(ntiles), CLMC45_sf1(ntiles)) - allocate (CLMC45_sf2(ntiles), CLMC45_pt1(ntiles), CLMC45_pt2(ntiles)) - allocate (CLMC_st1(ntiles), CLMC_st2(ntiles)) - allocate (CLMC45_st1(ntiles), CLMC45_st2(ntiles)) - allocate (hdm(ntiles), fc(ntiles), gdp(ntiles)) - allocate (peatf(ntiles), abm(ntiles), var1(ntiles), RITY(ntiles)) - - inquire(file = trim(DataDir)//'/catchcn_params.nc4', exist=file_exists) - inquire(file = trim(DataDir)//"CLM_veg_typs_fracs" ,exist=NewLand ) - - isCatchCN = (index(model,'catchcn') /=0) - - if(file_exists) then - - print *,'FILE FORMAT FOR LAND BCS IS NC4' - call CatchFmt%Open(trim(DataDir)//'/catch_params.nc4', pFIO_READ, __RC__) - call MAPL_VarRead ( CatchFmt ,'OLD_ITY', RITY, __RC__) - ITY = NINT (RITY) - call MAPL_VarRead ( CatchFmt ,'ARA1', ARA1, __RC__) - call MAPL_VarRead ( CatchFmt ,'ARA2', ARA2, __RC__) - call MAPL_VarRead ( CatchFmt ,'ARA3', ARA3, __RC__) - call MAPL_VarRead ( CatchFmt ,'ARA4', ARA4, __RC__) - call MAPL_VarRead ( CatchFmt ,'ARS1', ARS1, __RC__) - call MAPL_VarRead ( CatchFmt ,'ARS2', ARS2, __RC__) - call MAPL_VarRead ( CatchFmt ,'ARS3', ARS3, __RC__) - call MAPL_VarRead ( CatchFmt ,'ARW1', ARW1, __RC__) - call MAPL_VarRead ( CatchFmt ,'ARW2', ARW2, __RC__) - call MAPL_VarRead ( CatchFmt ,'ARW3', ARW3, __RC__) - call MAPL_VarRead ( CatchFmt ,'ARW4', ARW4, __RC__) - - if( SURFLAY.eq.20.0 ) then - call MAPL_VarRead ( CatchFmt ,'ATAU2', ATAU2, __RC__) - call MAPL_VarRead ( CatchFmt ,'BTAU2', BTAU2, __RC__) - endif - - if( SURFLAY.eq.50.0 ) then - call MAPL_VarRead ( CatchFmt ,'ATAU5', ATAU2, __RC__) - call MAPL_VarRead ( CatchFmt ,'BTAU5', BTAU2, __RC__) - endif - - call MAPL_VarRead ( CatchFmt ,'PSIS', PSIS, __RC__) - call MAPL_VarRead ( CatchFmt ,'BEE', BEE, __RC__) - call MAPL_VarRead ( CatchFmt ,'BF1', BF1, __RC__) - call MAPL_VarRead ( CatchFmt ,'BF2', BF2, __RC__) - call MAPL_VarRead ( CatchFmt ,'BF3', BF3, __RC__) - call MAPL_VarRead ( CatchFmt ,'TSA1', TSA1, __RC__) - call MAPL_VarRead ( CatchFmt ,'TSA2', TSA2, __RC__) - call MAPL_VarRead ( CatchFmt ,'TSB1', TSB1, __RC__) - call MAPL_VarRead ( CatchFmt ,'TSB2', TSB2, __RC__) - call MAPL_VarRead ( CatchFmt ,'COND', COND, __RC__) - call MAPL_VarRead ( CatchFmt ,'GNU', GNU, __RC__) - call MAPL_VarRead ( CatchFmt ,'WPWET', WPWET, __RC__) - call MAPL_VarRead ( CatchFmt ,'DP2BR', DP2BR, __RC__) - call MAPL_VarRead ( CatchFmt ,'POROS', POROS, __RC__) - call CatchFmt%close() - if(isCatchCN) then - call CatchCNFmt%Open(trim(DataDir)//'/catchcn_params.nc4', pFIO_READ, __RC__) - call MAPL_VarRead ( CatchCNFmt ,'BGALBNF', BNIRDF, __RC__) - call MAPL_VarRead ( CatchCNFmt ,'BGALBNR', BNIRDR, __RC__) - call MAPL_VarRead ( CatchCNFmt ,'BGALBVF', BVISDF, __RC__) - call MAPL_VarRead ( CatchCNFmt ,'BGALBVR', BVISDR, __RC__) - call MAPL_VarRead ( CatchCNFmt ,'NDEP', NDEP, __RC__) - call MAPL_VarRead ( CatchCNFmt ,'T2_M', T2, __RC__) - call MAPL_VarRead(CatchCNFmt,'ITY',CLMC_pt1,offset1=1, __RC__) ! 30 - call MAPL_VarRead(CatchCNFmt,'ITY',CLMC_pt2,offset1=2, __RC__) ! 31 - call MAPL_VarRead(CatchCNFmt,'ITY',CLMC_st1,offset1=3, __RC__) ! 32 - call MAPL_VarRead(CatchCNFmt,'ITY',CLMC_st2,offset1=4, __RC__) ! 33 - call MAPL_VarRead(CatchCNFmt,'FVG',CLMC_pf1,offset1=1, __RC__) ! 34 - call MAPL_VarRead(CatchCNFmt,'FVG',CLMC_pf2,offset1=2, __RC__) ! 35 - call MAPL_VarRead(CatchCNFmt,'FVG',CLMC_sf1,offset1=3, __RC__) ! 36 - call MAPL_VarRead(CatchCNFmt,'FVG',CLMC_sf2,offset1=4, __RC__) ! 37 - call CatchCNFmt%close() - if(clm45) then - open(unit=30, file=trim(DataDir)//'CLM4.5_abm_peatf_gdp_hdm_fc' ,form='formatted') - do n=1,ntiles - read (30, *) i, j, abm(n), peatf(n), & - gdp(n), hdm(n), fc(n) - end do - CLOSE (30, STATUS = 'KEEP') - endif - endif - - - else - open(unit=21, file=trim(DataDir)//'mosaic_veg_typs_fracs',form='formatted') - open(unit=22, file=trim(DataDir)//'bf.dat' ,form='formatted') - open(unit=23, file=trim(DataDir)//'soil_param.dat' ,form='formatted') - open(unit=24, file=trim(DataDir)//'ar.new' ,form='formatted') - open(unit=25, file=trim(DataDir)//'ts.dat' ,form='formatted') - open(unit=26, file=trim(DataDir)//'tau_param.dat' ,form='formatted') - - if(NewLand .and. isCatchCN) then - open(unit=27, file=trim(DataDir)//'CLM_veg_typs_fracs' ,form='formatted') - open(unit=28, file=trim(DataDir)//'CLM_NDep_SoilAlb_T2m' ,form='formatted') - if(clm45) then - open(unit=29, file=trim(DataDir)//'CLM4.5_veg_typs_fracs',form='formatted') - open(unit=30, file=trim(DataDir)//'CLM4.5_abm_peatf_gdp_hdm_fc' ,form='formatted') - endif - endif - - do n=1,ntiles - var1 (n) = real (n) - ! W.J notes: CanopH is not used. If CLM_veg_typs_fracs exists, the read some dummy ???? Ask Sarith - if (NewLand) then - read(21,*) I, j, ITY(N),idum, rdum, rdum, CanopH(N) - else - read(21,*) I, j, ITY(N),idum, rdum, rdum - endif - - read (22, *) i,j, GNU(n), BF1(n), BF2(n), BF3(n) - - read (23, *) i,j, idum, idum, BEE(n), PSIS(n),& - POROS(n), COND(n), WPWET(n), DP2BR(n) - - read (24, *) i,j, rdum, ARS1(n), ARS2(n), ARS3(n), & - ARA1(n), ARA2(n), ARA3(n), ARA4(n), & - ARW1(n), ARW2(n), ARW3(n), ARW4(n) - - read (25, *) i,j, rdum, TSA1(n), TSA2(n), TSB1(n), TSB2(n) - - if( SURFLAY.eq.20.0 ) read (26, *) i,j, ATAU2(n), BTAU2(n), rdum, rdum ! for old soil params - if( SURFLAY.eq.50.0 ) read (26, *) i,j, rdum , rdum, ATAU2(n), BTAU2(n) ! for new soil params - - if (NewLand .and. isCatchCN) then - read (27, *) i,j, CLMC_pt1(n), CLMC_pt2(n), CLMC_st1(n), CLMC_st2(n), & - CLMC_pf1(n), CLMC_pf2(n), CLMC_sf1(n), CLMC_sf2(n) - - read (28, *) NDEP(n), BVISDR(n), BVISDF(n), BNIRDR(n), BNIRDF(n), T2(n) ! MERRA-2 Annual Mean Temp is default. - if(clm45) then - read (29, *) i,j, CLMC45_pt1(n), CLMC45_pt2(n), CLMC45_st1(n), CLMC45_st2(n), & - CLMC45_pf1(n), CLMC45_pf2(n), CLMC45_sf1(n), CLMC45_sf2(n) - - read (30, *) i, j, abm(n), peatf(n), & - gdp(n), hdm(n), fc(n) - endif - endif - end do - - CLOSE (21, STATUS = 'KEEP') - CLOSE (22, STATUS = 'KEEP') - CLOSE (23, STATUS = 'KEEP') - CLOSE (24, STATUS = 'KEEP') - CLOSE (25, STATUS = 'KEEP') - CLOSE (26, STATUS = 'KEEP') - - if(NewLand .and. isCatchCN) then - CLOSE (27, STATUS = 'KEEP') - CLOSE (28, STATUS = 'KEEP') - if(clm45) then - CLOSE (29, STATUS = 'KEEP') - CLOSE (30, STATUS = 'KEEP') - endif - endif - endif - - - do n=1,ntiles - var1 (n) = real (n) - - zdep2=1000. - zdep3=amax1(1000.,DP2BR(n)) - - if (zdep2 .gt.0.75*zdep3) then - zdep2 = 0.75*zdep3 - end if - - zdep1=20. - zmet=zdep3/1000. - - term1=-1.+((PSIS(n)-zmet)/PSIS(n))**((BEE(n)-1.)/BEE(n)) - term2=PSIS(n)*BEE(n)/(BEE(n)-1) - - VGWMAX(n) = POROS(n)*zdep2 - CDCR1(n) = 1000.*POROS(n)*(zmet-(-term2*term1)) - CDCR2(n) = (1.-WPWET(n))*POROS(n)*zdep3 - - if( isCatchCN) then - - BVISDR(n) = amax1(1.e-6, BVISDR(n)) - BVISDF(n) = amax1(1.e-6, BVISDF(n)) - BNIRDR(n) = amax1(1.e-6, BNIRDR(n)) - BNIRDF(n) = amax1(1.e-6, BNIRDF(n)) - - ! convert % to fractions - - CLMC_pf1(n) = CLMC_pf1(n) / 100. - CLMC_pf2(n) = CLMC_pf2(n) / 100. - CLMC_sf1(n) = CLMC_sf1(n) / 100. - CLMC_sf2(n) = CLMC_sf2(n) / 100. - - fvg(1) = CLMC_pf1(n) - fvg(2) = CLMC_pf2(n) - fvg(3) = CLMC_sf1(n) - fvg(4) = CLMC_sf2(n) - - BARE = 1. - - DO NV = 1, NVEG - BARE = BARE - FVG(NV)! subtract vegetated fractions - END DO - - if (BARE /= 0.) THEN - IB = MAXLOC(FVG(:),1) - FVG (IB) = FVG(IB) + BARE ! This also corrects all cases sum ne 0. - ENDIF - - CLMC_pf1(n) = fvg(1) - CLMC_pf2(n) = fvg(2) - CLMC_sf1(n) = fvg(3) - CLMC_sf2(n) = fvg(4) - - if(CLM45) then - ! CLM 45 - - CLMC45_pf1(n) = CLMC45_pf1(n) / 100. - CLMC45_pf2(n) = CLMC45_pf2(n) / 100. - CLMC45_sf1(n) = CLMC45_sf1(n) / 100. - CLMC45_sf2(n) = CLMC45_sf2(n) / 100. - - fvg(1) = CLMC45_pf1(n) - fvg(2) = CLMC45_pf2(n) - fvg(3) = CLMC45_sf1(n) - fvg(4) = CLMC45_sf2(n) - - BARE = 1. - - DO NV = 1, NVEG - BARE = BARE - FVG(NV)! subtract vegetated fractions - END DO - - if (BARE /= 0.) THEN - IB = MAXLOC(FVG(:),1) - FVG (IB) = FVG(IB) + BARE ! This also corrects all cases sum ne 0. - ENDIF - - CLMC45_pf1(n) = fvg(1) - CLMC45_pf2(n) = fvg(2) - CLMC45_sf1(n) = fvg(3) - CLMC45_sf2(n) = fvg(4) - endif - endif - enddo - - if( isCatchCN) then - - NDEP = NDEP * 1.e-9 - - ! prevent trivial fractions - ! ------------------------- - do n = 1,ntiles - if(CLMC_pf1(n) <= 1.e-4) then - CLMC_pf2(n) = CLMC_pf2(n) + CLMC_pf1(n) - CLMC_pf1(n) = 0. - endif - - if(CLMC_pf2(n) <= 1.e-4) then - CLMC_pf1(n) = CLMC_pf1(n) + CLMC_pf2(n) - CLMC_pf2(n) = 0. - endif - - if(CLMC_sf1(n) <= 1.e-4) then - if(CLMC_sf2(n) > 1.e-4) then - CLMC_sf2(n) = CLMC_sf2(n) + CLMC_sf1(n) - else if(CLMC_pf2(n) > 1.e-4) then - CLMC_pf2(n) = CLMC_pf2(n) + CLMC_sf1(n) - else if(CLMC_pf1(n) > 1.e-4) then - CLMC_pf1(n) = CLMC_pf1(n) + CLMC_sf1(n) - else - stop 'fveg3' - endif - CLMC_sf1(n) = 0. - endif - - if(CLMC_sf2(n) <= 1.e-4) then - if(CLMC_sf1(n) > 1.e-4) then - CLMC_sf1(n) = CLMC_sf1(n) + CLMC_sf2(n) - else if(CLMC_pf2(n) > 1.e-4) then - CLMC_pf2(n) = CLMC_pf2(n) + CLMC_sf2(n) - else if(CLMC_pf1(n) > 1.e-4) then - CLMC_pf1(n) = CLMC_pf1(n) + CLMC_sf2(n) - else - stop 'fveg4' - endif - CLMC_sf2(n) = 0. - endif - - if (clm45) then - ! CLM45 - if(CLMC45_pf1(n) <= 1.e-4) then - CLMC45_pf2(n) = CLMC45_pf2(n) + CLMC45_pf1(n) - CLMC45_pf1(n) = 0. - endif - - if(CLMC45_pf2(n) <= 1.e-4) then - CLMC45_pf1(n) = CLMC45_pf1(n) + CLMC45_pf2(n) - CLMC45_pf2(n) = 0. - endif - - if(CLMC45_sf1(n) <= 1.e-4) then - if(CLMC45_sf2(n) > 1.e-4) then - CLMC45_sf2(n) = CLMC45_sf2(n) + CLMC45_sf1(n) - else if(CLMC45_pf2(n) > 1.e-4) then - CLMC45_pf2(n) = CLMC45_pf2(n) + CLMC45_sf1(n) - else if(CLMC45_pf1(n) > 1.e-4) then - CLMC45_pf1(n) = CLMC45_pf1(n) + CLMC45_sf1(n) - else - stop 'fveg3' - endif - CLMC45_sf1(n) = 0. - endif - - if(CLMC45_sf2(n) <= 1.e-4) then - if(CLMC45_sf1(n) > 1.e-4) then - CLMC45_sf1(n) = CLMC45_sf1(n) + CLMC45_sf2(n) - else if(CLMC45_pf2(n) > 1.e-4) then - CLMC45_pf2(n) = CLMC45_pf2(n) + CLMC45_sf2(n) - else if(CLMC45_pf1(n) > 1.e-4) then - CLMC45_pf1(n) = CLMC45_pf1(n) + CLMC45_sf2(n) - else - stop 'fveg4' - endif - CLMC45_sf2(n) = 0. - endif - endif - end do - endif - - - ! Vegdyn Boundary Condition - ! ------------------------- - - ! open(20,file=trim("vegdyn_internal_rst"), & - ! status="unknown", & - ! form="unformatted",convert="little_endian") - ! write(20) real(ity) - ! if(NewLand) write(20) CanopH - ! close(20) - ! print *, "Wrote vegdyn_internal_restart" - - ! Now writing BCs (from BCSDIR) and regridded hydrological variables 1-72 - ! ----------------------------------------------------------------------- - - STATUS = NF_OPEN (trim(InRestart),NF_WRITE,NCFID) ; VERIFY_(STATUS) - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'BF1'), (/1/), (/NTILES/),BF1) - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'BF2'), (/1/), (/NTILES/),BF2) - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'BF3'), (/1/), (/NTILES/),BF3) - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'VGWMAX'), (/1/), (/NTILES/),VGWMAX) - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'CDCR1'), (/1/), (/NTILES/),CDCR1) - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'CDCR2'), (/1/), (/NTILES/),CDCR2) - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'PSIS'), (/1/), (/NTILES/),PSIS) - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'BEE'), (/1/), (/NTILES/),BEE) - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'POROS'), (/1/), (/NTILES/),POROS) - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'WPWET'), (/1/), (/NTILES/),WPWET) - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'COND'), (/1/), (/NTILES/),COND) - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'GNU'), (/1/), (/NTILES/),GNU) - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'ARS1'), (/1/), (/NTILES/),ARS1) - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'ARS2'), (/1/), (/NTILES/),ARS2) - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'ARS3'), (/1/), (/NTILES/),ARS3) - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'ARA1'), (/1/), (/NTILES/),ARA1) - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'ARA2'), (/1/), (/NTILES/),ARA2) - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'ARA3'), (/1/), (/NTILES/),ARA3) - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'ARA4'), (/1/), (/NTILES/),ARA4) - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'ARW1'), (/1/), (/NTILES/),ARW1) - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'ARW2'), (/1/), (/NTILES/),ARW2) - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'ARW3'), (/1/), (/NTILES/),ARW3) - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'ARW4'), (/1/), (/NTILES/),ARW4) - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'TSA1'), (/1/), (/NTILES/),TSA1) - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'TSA2'), (/1/), (/NTILES/),TSA2) - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'TSB1'), (/1/), (/NTILES/),TSB1) - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'TSB2'), (/1/), (/NTILES/),TSB2) - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'ATAU'), (/1/), (/NTILES/),ATAU2) - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'BTAU'), (/1/), (/NTILES/),BTAU2) - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'TILE_ID'), (/1/), (/NTILES/),VAR1) - - if( isCatchCN ) then - - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'ITY'), (/1,1/), (/NTILES,1/),CLMC_pt1) - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'ITY'), (/1,2/), (/NTILES,1/),CLMC_pt2) - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'ITY'), (/1,3/), (/NTILES,1/),CLMC_st1) - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'ITY'), (/1,4/), (/NTILES,1/),CLMC_st2) - - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'FVG'), (/1,1/), (/NTILES,1/),CLMC_pf1) - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'FVG'), (/1,2/), (/NTILES,1/),CLMC_pf2) - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'FVG'), (/1,3/), (/NTILES,1/),CLMC_sf1) - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'FVG'), (/1,4/), (/NTILES,1/),CLMC_sf2) - - - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'NDEP' ), (/1/), (/NTILES/),NDEP) - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'CLI_T2M'), (/1/), (/NTILES/),T2) - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'BGALBVR'), (/1/), (/NTILES/),BVISDR) - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'BGALBVF'), (/1/), (/NTILES/),BVISDF) - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'BGALBNR'), (/1/), (/NTILES/),BNIRDR) - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'BGALBNF'), (/1/), (/NTILES/),BNIRDF) - - if(CLM45) then - - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'ABM' ), (/1/), (/NTILES/),real(ABM)) - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'FIELDCAP'), (/1/), (/NTILES/),FC) - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'HDM' ), (/1/), (/NTILES/),HDM) - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'GDP' ), (/1/), (/NTILES/),GDP) - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'PEATF' ), (/1/), (/NTILES/),PEATF) - endif - - else - STATUS = NF_PUT_VARA_REAL(NCFID,VarID(NCFID,'OLD_ITY'), (/1/), (/NTILES/),real(ITY)) - endif - - STATUS = NF_CLOSE ( NCFID) - - deallocate ( BF1, BF2, BF3 ) - deallocate (VGWMAX, CDCR1, CDCR2 ) - deallocate ( PSIS, BEE, POROS ) - deallocate ( WPWET, COND, GNU ) - deallocate ( ARS1, ARS2, ARS3 ) - deallocate ( ARA1, ARA2, ARA3 ) - deallocate ( ARA4, ARW1, ARW2 ) - deallocate ( ARW3, ARW4, TSA1 ) - deallocate ( TSA2, TSB1, TSB2 ) - deallocate ( ATAU2, BTAU2, DP2BR ) - deallocate (BVISDR, BVISDF, BNIRDR ) - deallocate (BNIRDF, T2, NDEP ) - deallocate ( ity, CanopH) - deallocate (CLMC_pf1, CLMC_pf2, CLMC_sf1) - deallocate (CLMC_sf2, CLMC_pt1, CLMC_pt2) - deallocate (CLMC_st1,CLMC_st2) - if (present(rc)) rc =0 - !_RETURN(_SUCCESS) - END SUBROUTINE read_bcs_data - - ! ***************************************************************************** - - SUBROUTINE regrid_carbon_vars (NTILES, model) - - implicit none - - integer, intent (in) :: NTILES - character(*), intent (in) :: model - character*300 :: OutTileFile = 'InData/OutTileFile' - character*300 :: OutFileName - integer :: AGCM_YY=2015,AGCM_MM=1,AGCM_DD=1,AGCM_HR=0 - real, allocatable, dimension (:) :: CLMC_pf1, CLMC_pf2, CLMC_sf1, CLMC_sf2, & - CLMC_pt1, CLMC_pt2,CLMC_st1,CLMC_st2 - - ! =============================================================================================== - - integer, allocatable, dimension(:,:) :: Id_glb, Id_loc - integer, allocatable, dimension(:) :: tid_offl, id_vec - real, allocatable, dimension(:,:) :: fveg_offl, ityp_offl - integer :: n,i,j, k, offl_cell, STATUS,NCFID, req - integer :: outid, local_id, nv, nz, iv - real , allocatable, dimension (:) :: LATT, LONN, DAYX, TILE_ID, var_dum2 - real, allocatable :: var_off_col (:,:,:), var_off_pft (:,:,:,:) - integer, allocatable :: low_ind(:), upp_ind(:), nt_local (:) - real , pointer , dimension (:) :: long, latg, lonc, latc - character*256 :: Iam = "regrid_carbon_vars" - - OutFileName='OutData/'//trim(model)//'_internal_rst' - - allocate (tid_offl (ntiles_cn)) - allocate (ityp_offl (ntiles_cn,nveg)) - allocate (fveg_offl (ntiles_cn,nveg)) - - allocate(low_ind ( numprocs)) - allocate(upp_ind ( numprocs)) - allocate(nt_local( numprocs)) - - low_ind (:) = 1 - upp_ind (:) = NTILES - nt_local(:) = NTILES - - ! Domain decomposition - ! -------------------- - - if (numprocs > 1) then - do i = 1, numprocs - 1 - upp_ind(i) = low_ind(i) + (ntiles/numprocs) - 1 - low_ind(i+1) = upp_ind(i) + 1 - nt_local(i) = upp_ind(i) - low_ind(i) + 1 - end do - nt_local(numprocs) = upp_ind(numprocs) - low_ind(numprocs) + 1 - endif - - allocate (id_loc (nt_local (myid + 1),4)) - allocate (lonn (nt_local (myid + 1))) - allocate (latt (nt_local (myid + 1))) - allocate (CLMC_pf1(nt_local (myid + 1))) - allocate (CLMC_pf2(nt_local (myid + 1))) - allocate (CLMC_sf1(nt_local (myid + 1))) - allocate (CLMC_sf2(nt_local (myid + 1))) - allocate (CLMC_pt1(nt_local (myid + 1))) - allocate (CLMC_pt2(nt_local (myid + 1))) - allocate (CLMC_st1(nt_local (myid + 1))) - allocate (CLMC_st2(nt_local (myid + 1))) - allocate (lonc (1:ntiles_cn)) - allocate (latc (1:ntiles_cn)) - - if (root_proc) then - - ! -------------------------------------------- - ! Read exact lonn, latt from output .til file - ! -------------------------------------------- - - allocate (long (ntiles)) - allocate (latg (ntiles)) - allocate (DAYX (NTILES)) - - call ReadTileFile_RealLatLon (OutTileFile, i, xlon=long, xlat=latg); VERIFY_(i-ntiles) - - ! Compute DAYX - ! ------------ - - call compute_dayx ( & - NTILES, AGCM_YY, AGCM_MM, AGCM_DD, AGCM_HR, & - LATG, DAYX) - - ! --------------------------------------------- - ! Read exact lonc, latc from offline .til File - ! --------------------------------------------- - - call ReadTileFile_RealLatLon(trim(InCNTilFile),i,xlon=lonc,xlat=latc); VERIFY_(i-ntiles_cn) - - endif - -! call MPI_SCATTERV ( & -! long,nt_local,low_ind-1,MPI_real, & -! lonn,size(lonn),MPI_real , & -! 0,MPI_COMM_WORLD, mpierr ) - -! call MPI_SCATTERV ( & -! latg,nt_local,low_ind-1,MPI_real, & -! latt,nt_local(myid+1),MPI_real , & -! 0,MPI_COMM_WORLD, mpierr ) - - do i = 1, numprocs - if((I == 1).and.(myid == 0)) then - lonn(:) = long(low_ind(i) : upp_ind(i)) - latt(:) = latg(low_ind(i) : upp_ind(i)) - else if (I > 1) then - if(I-1 == myid) then - ! receiving from root - call MPI_RECV(lonn,nt_local(i) , MPI_REAL, 0,995,MPI_COMM_WORLD,MPI_STATUS_IGNORE,mpierr) - call MPI_RECV(latt,nt_local(i) , MPI_REAL, 0,994,MPI_COMM_WORLD,MPI_STATUS_IGNORE,mpierr) - else if (myid == 0) then - ! root sends - call MPI_ISend(long(low_ind(i) : upp_ind(i)),nt_local(i),MPI_REAL,i-1,995,MPI_COMM_WORLD,req,mpierr) - call MPI_WAIT (req,MPI_STATUS_IGNORE,mpierr) - call MPI_ISend(latg(low_ind(i) : upp_ind(i)),nt_local(i),MPI_REAL,i-1,994,MPI_COMM_WORLD,req,mpierr) - call MPI_WAIT (req,MPI_STATUS_IGNORE,mpierr) - endif - endif - end do - - - if(root_proc) deallocate (long, latg) - - call MPI_BCAST(lonc,ntiles_cn,MPI_REAL,0,MPI_COMM_WORLD,mpierr) - call MPI_BCAST(latc,ntiles_cn,MPI_REAL,0,MPI_COMM_WORLD,mpierr) - - ! Open GKW/Fzeng SMAP M09 catchcn_internal_rst and output catchcn_internal_rst - ! ---------------------------------------------------------------------------- - - STATUS = NF_OPEN_PAR (trim(OutFileName),IOR(NF_WRITE ,NF_MPIIO),MPI_COMM_WORLD, infos,OUTID) - IF (STATUS .NE. NF_NOERR) CALL HANDLE_ERR(STATUS, 'OUTPUT RESTART FAILED') - - STATUS = NF_GET_VARA_REAL(OUTID,VarID(OUTID,'ITY'), (/low_ind(myid+1),1/), (/nt_local(myid+1),1/),CLMC_pt1) - STATUS = NF_GET_VARA_REAL(OUTID,VarID(OUTID,'ITY'), (/low_ind(myid+1),2/), (/nt_local(myid+1),1/),CLMC_pt2) - STATUS = NF_GET_VARA_REAL(OUTID,VarID(OUTID,'ITY'), (/low_ind(myid+1),3/), (/nt_local(myid+1),1/),CLMC_st1) - STATUS = NF_GET_VARA_REAL(OUTID,VarID(OUTID,'ITY'), (/low_ind(myid+1),4/), (/nt_local(myid+1),1/),CLMC_st2) - STATUS = NF_GET_VARA_REAL(OUTID,VarID(OUTID,'FVG'), (/low_ind(myid+1),1/), (/nt_local(myid+1),1/),CLMC_pf1) - STATUS = NF_GET_VARA_REAL(OUTID,VarID(OUTID,'FVG'), (/low_ind(myid+1),2/), (/nt_local(myid+1),1/),CLMC_pf2) - STATUS = NF_GET_VARA_REAL(OUTID,VarID(OUTID,'FVG'), (/low_ind(myid+1),3/), (/nt_local(myid+1),1/),CLMC_sf1) - STATUS = NF_GET_VARA_REAL(OUTID,VarID(OUTID,'FVG'), (/low_ind(myid+1),4/), (/nt_local(myid+1),1/),CLMC_sf2) - - if (root_proc) then - STATUS = NF_OPEN (trim(InCNRestart),NF_NOWRITE,NCFID) - allocate (TILE_ID (1:ntiles_cn)) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'TILE_ID' ), (/1/), (/NTILES_CN/),TILE_ID) - - do n = 1,ntiles_cn - - K = NINT (TILE_ID (n)) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'ITY'), (/n,1/), (/1,4/),ityp_offl(K,:)) - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'FVG'), (/n,1/), (/1,4/),fveg_offl(K,:)) - - tid_offl (n) = n - - do nv = 1,nveg - if(ityp_offl(K,nv)<0 .or. ityp_offl(K,nv)>npft) stop 'ityp' - if(fveg_offl(K,nv)<0..or. fveg_offl(K,nv)>1.00001) stop 'fveg' - end do - - if((ityp_offl(K,3) == 0).and.(ityp_offl(K,4) == 0)) then - if(ityp_offl(K,1) /= 0) then - ityp_offl(K,3) = ityp_offl(K,1) - else - ityp_offl(K,3) = ityp_offl(K,2) - endif - endif - - if((ityp_offl(K,1) == 0).and.(ityp_offl(K,2) /= 0)) ityp_offl(K,1) = ityp_offl(K,2) - if((ityp_offl(K,2) == 0).and.(ityp_offl(K,1) /= 0)) ityp_offl(K,2) = ityp_offl(K,1) - if((ityp_offl(K,3) == 0).and.(ityp_offl(K,4) /= 0)) ityp_offl(K,3) = ityp_offl(K,4) - if((ityp_offl(K,4) == 0).and.(ityp_offl(K,3) /= 0)) ityp_offl(K,4) = ityp_offl(K,3) - - end do - - endif - - call MPI_BCAST(tid_offl ,size(tid_offl ),MPI_INTEGER,0,MPI_COMM_WORLD,mpierr) - call MPI_BCAST(ityp_offl,size(ityp_offl),MPI_REAL ,0,MPI_COMM_WORLD,mpierr) - call MPI_BCAST(fveg_offl,size(fveg_offl),MPI_REAL ,0,MPI_COMM_WORLD,mpierr) - - ! -------------------------------------------------------------------------------- - ! Here we create transfer index array to map offline restarts to output tile space - ! -------------------------------------------------------------------------------- - - call GetIds(lonc,latc,lonn,latt,id_loc, tid_offl, & - CLMC_pf1, CLMC_pf2, CLMC_sf1, CLMC_sf2, CLMC_pt1, CLMC_pt2,CLMC_st1,CLMC_st2, & - fveg_offl, ityp_offl) - - ! update id_glb in root - - if(root_proc) then - allocate (id_glb (ntiles, nveg)) - allocate (id_vec (ntiles)) - endif - - do nv = 1, nveg - call MPI_Barrier(MPI_COMM_WORLD, STATUS) - ! call MPI_GATHERV( & - ! id_loc (:,nv), nt_local(myid+1) , MPI_real, & - ! id_vec, nt_local,low_ind-1, MPI_real, & - ! 0, MPI_COMM_WORLD, mpierr ) - - do i = 1, numprocs - if((I == 1).and.(myid == 0)) then - id_vec(low_ind(i) : upp_ind(i)) = Id_loc(:,nv) - else if (I > 1) then - if(I-1 == myid) then - ! send to root - call MPI_ISend(id_loc(:,nv),nt_local(i),MPI_INTEGER,0,993,MPI_COMM_WORLD,req,mpierr) - call MPI_WAIT (req,MPI_STATUS_IGNORE,mpierr) - else if (myid == 0) then - ! root receives - call MPI_RECV(id_vec(low_ind(i) : upp_ind(i)),nt_local(i) , MPI_INTEGER, i-1,993,MPI_COMM_WORLD,MPI_STATUS_IGNORE,mpierr) - endif - endif - end do - - if(root_proc) id_glb (:,nv) = id_vec - - end do - - if(root_proc) then - - allocate (var_off_col (1: NTILES_CN, 1 : nzone,1 : var_col)) - allocate (var_off_pft (1: NTILES_CN, 1 : nzone,1 : nveg, 1 : var_pft)) - allocate (var_dum2 (1:ntiles_cn)) - i = 1 - do nv = 1,VAR_COL - do nz = 1,nzone - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'CNCOL'), (/1,i/), (/NTILES_CN,1 /),VAR_DUM2) - do k = 1, NTILES_CN - var_off_col(TILE_ID(K), nz,nv) = VAR_DUM2(K) - end do - i = i + 1 - end do - end do - - i = 1 - do iv = 1,VAR_PFT - do nv = 1,nveg - do nz = 1,nzone - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'CNPFT'), (/1,i/), (/NTILES_CN,1 /),VAR_DUM2) - do k = 1, NTILES_CN - var_off_pft(TILE_ID(K), nz,nv,iv) = VAR_DUM2(K) - end do - i = i + 1 - end do - end do - end do - - where(isnan(var_off_pft)) var_off_pft = 0. - where(var_off_pft /= var_off_pft) var_off_pft = 0. - - call write_regridded_carbon (NTILES, ntiles_cn, NCFID, OUTID, id_glb, & - DAYX, var_off_col, var_off_pft, ityp_offl, fveg_offl) - deallocate (var_off_col,var_off_pft) - endif - - call MPI_Barrier(MPI_COMM_WORLD, STATUS) - - END SUBROUTINE regrid_carbon_vars - -! --------------------------------------------------------------------------------------------------------- - - SUBROUTINE write_regridded_carbon (NTILES, ntiles_rst, NCFID, OUTID, id_glb, & - DAYX, var_off_col, var_off_pft, ityp_offl, fveg_offl) - - ! write out regridded carbon variables - implicit none - integer, intent (in) :: NTILES, ntiles_rst,NCFID, OUTID, id_glb (ntiles,nveg) - real, intent (in) :: DAYX (NTILES), var_off_col(NTILES_RST,NZONE,var_col), var_off_pft(NTILES_RST,NZONE, NVEG, var_pft) - real, intent (in), dimension(ntiles_rst,nveg) :: fveg_offl, ityp_offl - real, allocatable, dimension (:) :: CLMC_pf1, CLMC_pf2, CLMC_sf1, CLMC_sf2, & - CLMC_pt1, CLMC_pt2,CLMC_st1,CLMC_st2, var_dum - real, allocatable :: var_col_out (:,:,:), var_pft_out (:,:,:,:) - integer :: N, STATUS, nv, nx, offl_cell, ityp_new, i, j, nz, iv - real :: fveg_new - character(256) :: Iam = "write_regridded_carbon" - - - allocate (CLMC_pf1(NTILES)) - allocate (CLMC_pf2(NTILES)) - allocate (CLMC_sf1(NTILES)) - allocate (CLMC_sf2(NTILES)) - allocate (CLMC_pt1(NTILES)) - allocate (CLMC_pt2(NTILES)) - allocate (CLMC_st1(NTILES)) - allocate (CLMC_st2(NTILES)) - allocate (VAR_DUM (NTILES)) - - STATUS = NF_GET_VARA_REAL(OUTID,VarID(OUTID,'ITY'), (/1,1/), (/NTILES,1/),CLMC_pt1) ; VERIFY_(STATUS) - STATUS = NF_GET_VARA_REAL(OUTID,VarID(OUTID,'ITY'), (/1,2/), (/NTILES,1/),CLMC_pt2) ; VERIFY_(STATUS) - STATUS = NF_GET_VARA_REAL(OUTID,VarID(OUTID,'ITY'), (/1,3/), (/NTILES,1/),CLMC_st1) ; VERIFY_(STATUS) - STATUS = NF_GET_VARA_REAL(OUTID,VarID(OUTID,'ITY'), (/1,4/), (/NTILES,1/),CLMC_st2) ; VERIFY_(STATUS) - STATUS = NF_GET_VARA_REAL(OUTID,VarID(OUTID,'FVG'), (/1,1/), (/NTILES,1/),CLMC_pf1) ; VERIFY_(STATUS) - STATUS = NF_GET_VARA_REAL(OUTID,VarID(OUTID,'FVG'), (/1,2/), (/NTILES,1/),CLMC_pf2) ; VERIFY_(STATUS) - STATUS = NF_GET_VARA_REAL(OUTID,VarID(OUTID,'FVG'), (/1,3/), (/NTILES,1/),CLMC_sf1) ; VERIFY_(STATUS) - STATUS = NF_GET_VARA_REAL(OUTID,VarID(OUTID,'FVG'), (/1,4/), (/NTILES,1/),CLMC_sf2) ; VERIFY_(STATUS) - - allocate (var_col_out (1: NTILES, 1 : nzone,1 : var_col)) - allocate (var_pft_out (1: NTILES, 1 : nzone,1 : nveg, 1 : var_pft)) - - var_col_out = 0. - var_pft_out = NaN - - OUT_TILE : DO N = 1, NTILES - - ! if(mod (n,1000) == 0) print *, myid +1, n, Id_glb(n,:) - - NVLOOP2 : do nv = 1, nveg - - if(nv <= 2) then ! index for secondary PFT index if primary or primary if secondary - nx = nv + 2 - else - nx = nv - 2 - endif - - if (nv == 1) ityp_new = CLMC_pt1(n) - if (nv == 1) fveg_new = CLMC_pf1(n) - if (nv == 2) ityp_new = CLMC_pt2(n) - if (nv == 2) fveg_new = CLMC_pf2(n) - if (nv == 3) ityp_new = CLMC_st1(n) - if (nv == 3) fveg_new = CLMC_sf1(n) - if (nv == 4) ityp_new = CLMC_st2(n) - if (nv == 4) fveg_new = CLMC_sf2(n) - - if (fveg_new > fmin) then - - offl_cell = Id_glb(n,nv) - - if(ityp_new == ityp_offl (offl_cell,nv) .and. fveg_offl (offl_cell,nv)> fmin) then - iv = nv ! same type fraction (primary of secondary) - else if(ityp_new == ityp_offl (offl_cell,nx) .and. fveg_offl (offl_cell,nx)> fmin) then - iv = nx ! not same fraction - else if(iclass(ityp_new)==iclass(ityp_offl(offl_cell,nv)) .and. fveg_offl (offl_cell,nv)> fmin) then - iv = nv ! primary, other type (same class) - else if(fveg_offl (offl_cell,nx)> fmin) then - iv = nx ! secondary, other type (same class) - endif - - ! Get col and pft variables for the Id_glb(nv) grid cell from offline catchcn_internal_rst - ! ---------------------------------------------------------------------------------------- - - ! call NCDF_reshape_getOput (NCFID,Id_glb(n,nv),var_off_col,var_off_pft,.true.) - - var_pft_out (n,:,nv,:) = var_off_pft(Id_glb(n,nv), :,iv,:) - var_col_out (n,:,:) = var_col_out(n,:,:) + fveg_new * var_off_col(Id_glb(n,nv), :,:) ! gkw: column state simple weighted mean; ! could use "woody" fraction? - - ! Check whether var_pft_out is realistic - do nz = 1, nzone - do j = 1, VAR_PFT - if (isnan(var_pft_out (n, nz,nv,j))) print *,j,nv,nz,n,var_pft_out (n, nz,nv,j),fveg_new - !if(isnan(var_pft_out (n, nz,nv,69))) var_pft_out (n, nz,nv,69) = 1.e-6 - !if(isnan(var_pft_out (n, nz,nv,70))) var_pft_out (n, nz,nv,70) = 1.e-6 - !if(isnan(var_pft_out (n, nz,nv,73))) var_pft_out (n, nz,nv,73) = 1.e-6 - !if(isnan(var_pft_out (n, nz,nv,74))) var_pft_out (n, nz,nv,74) = 1.e-6 - end do - end do - endif - - end do NVLOOP2 - - ! reset carbon if negative < 10g - ! ------------------------ - - NZLOOP : do nz = 1, nzone - - if(var_col_out (n, nz,14) < 10.) then - - var_col_out(n, nz, 1) = max(var_col_out(n, nz, 1), 0.) - var_col_out(n, nz, 2) = max(var_col_out(n, nz, 2), 0.) - var_col_out(n, nz, 3) = max(var_col_out(n, nz, 3), 0.) - var_col_out(n, nz, 4) = max(var_col_out(n, nz, 4), 0.) - var_col_out(n, nz, 5) = max(var_col_out(n, nz, 5), 0.) - var_col_out(n, nz,10) = max(var_col_out(n, nz,10), 0.) - var_col_out(n, nz,11) = max(var_col_out(n, nz,11), 0.) - var_col_out(n, nz,12) = max(var_col_out(n, nz,12), 0.) - var_col_out(n, nz,13) = max(var_col_out(n, nz,13),10.) ! soil4c - var_col_out(n, nz,14) = max(var_col_out(n, nz,14), 0.) - var_col_out(n, nz,15) = max(var_col_out(n, nz,15), 0.) - var_col_out(n, nz,16) = max(var_col_out(n, nz,16), 0.) - var_col_out(n, nz,17) = max(var_col_out(n, nz,17), 0.) - var_col_out(n, nz,18) = max(var_col_out(n, nz,18), 0.) - var_col_out(n, nz,19) = max(var_col_out(n, nz,19), 0.) - var_col_out(n, nz,20) = max(var_col_out(n, nz,20), 0.) - var_col_out(n, nz,24) = max(var_col_out(n, nz,24), 0.) - var_col_out(n, nz,25) = max(var_col_out(n, nz,25), 0.) - var_col_out(n, nz,26) = max(var_col_out(n, nz,26), 0.) - var_col_out(n, nz,27) = max(var_col_out(n, nz,27), 0.) - var_col_out(n, nz,28) = max(var_col_out(n, nz,28), 1.) - var_col_out(n, nz,29) = max(var_col_out(n, nz,29), 0.) - - NVLOOP3 : do nv = 1,nveg - - if (nv == 1) ityp_new = CLMC_pt1(n) - if (nv == 1) fveg_new = CLMC_pf1(n) - if (nv == 2) ityp_new = CLMC_pt2(n) - if (nv == 2) fveg_new = CLMC_pf2(n) - if (nv == 3) ityp_new = CLMC_st1(n) - if (nv == 3) fveg_new = CLMC_sf1(n) - if (nv == 4) ityp_new = CLMC_st2(n) - if (nv == 4) fveg_new = CLMC_sf2(n) - - if(fveg_new > fmin) then - var_pft_out(n, nz,nv, 1) = max(var_pft_out(n, nz,nv, 1),0.) - var_pft_out(n, nz,nv, 2) = max(var_pft_out(n, nz,nv, 2),0.) - var_pft_out(n, nz,nv, 3) = max(var_pft_out(n, nz,nv, 3),0.) - var_pft_out(n, nz,nv, 4) = max(var_pft_out(n, nz,nv, 4),0.) - - if(ityp_new <= 12) then ! tree or shrub deadstemc - var_pft_out(n, nz,nv, 5) = max(var_pft_out(n, nz,nv, 5),0.1) - else - var_pft_out(n, nz,nv, 5) = max(var_pft_out(n, nz,nv, 5),0.0) - endif - - var_pft_out(n, nz,nv, 6) = max(var_pft_out(n, nz,nv, 6),0.) - var_pft_out(n, nz,nv, 7) = max(var_pft_out(n, nz,nv, 7),0.) - var_pft_out(n, nz,nv, 8) = max(var_pft_out(n, nz,nv, 8),0.) - var_pft_out(n, nz,nv, 9) = max(var_pft_out(n, nz,nv, 9),0.) - var_pft_out(n, nz,nv,10) = max(var_pft_out(n, nz,nv,10),0.) - var_pft_out(n, nz,nv,11) = max(var_pft_out(n, nz,nv,11),0.) - var_pft_out(n, nz,nv,12) = max(var_pft_out(n, nz,nv,12),0.) - - if(ityp_new <=2 .or. ityp_new ==4 .or. ityp_new ==5 .or. ityp_new == 9) then - var_pft_out(n, nz,nv,13) = max(var_pft_out(n, nz,nv,13),1.) ! leaf carbon display for evergreen - var_pft_out(n, nz,nv,14) = max(var_pft_out(n, nz,nv,14),0.) - else - var_pft_out(n, nz,nv,13) = max(var_pft_out(n, nz,nv,13),0.) - var_pft_out(n, nz,nv,14) = max(var_pft_out(n, nz,nv,14),1.) ! leaf carbon storage for deciduous - endif - - var_pft_out(n, nz,nv,15) = max(var_pft_out(n, nz,nv,15),0.) - var_pft_out(n, nz,nv,16) = max(var_pft_out(n, nz,nv,16),0.) - var_pft_out(n, nz,nv,17) = max(var_pft_out(n, nz,nv,17),0.) - var_pft_out(n, nz,nv,18) = max(var_pft_out(n, nz,nv,18),0.) - var_pft_out(n, nz,nv,19) = max(var_pft_out(n, nz,nv,19),0.) - var_pft_out(n, nz,nv,20) = max(var_pft_out(n, nz,nv,20),0.) - var_pft_out(n, nz,nv,21) = max(var_pft_out(n, nz,nv,21),0.) - var_pft_out(n, nz,nv,22) = max(var_pft_out(n, nz,nv,22),0.) - var_pft_out(n, nz,nv,23) = max(var_pft_out(n, nz,nv,23),0.) - var_pft_out(n, nz,nv,25) = max(var_pft_out(n, nz,nv,25),0.) - var_pft_out(n, nz,nv,26) = max(var_pft_out(n, nz,nv,26),0.) - var_pft_out(n, nz,nv,27) = max(var_pft_out(n, nz,nv,27),0.) - var_pft_out(n, nz,nv,41) = max(var_pft_out(n, nz,nv,41),0.) - var_pft_out(n, nz,nv,42) = max(var_pft_out(n, nz,nv,42),0.) - var_pft_out(n, nz,nv,44) = max(var_pft_out(n, nz,nv,44),0.) - var_pft_out(n, nz,nv,45) = max(var_pft_out(n, nz,nv,45),0.) - var_pft_out(n, nz,nv,46) = max(var_pft_out(n, nz,nv,46),0.) - var_pft_out(n, nz,nv,47) = max(var_pft_out(n, nz,nv,47),0.) - var_pft_out(n, nz,nv,48) = max(var_pft_out(n, nz,nv,48),0.) - var_pft_out(n, nz,nv,49) = max(var_pft_out(n, nz,nv,49),0.) - var_pft_out(n, nz,nv,50) = max(var_pft_out(n, nz,nv,50),0.) - var_pft_out(n, nz,nv,51) = max(var_pft_out(n, nz,nv, 5)/500.,0.) - var_pft_out(n, nz,nv,52) = max(var_pft_out(n, nz,nv,52),0.) - var_pft_out(n, nz,nv,53) = max(var_pft_out(n, nz,nv,53),0.) - var_pft_out(n, nz,nv,54) = max(var_pft_out(n, nz,nv,54),0.) - var_pft_out(n, nz,nv,55) = max(var_pft_out(n, nz,nv,55),0.) - var_pft_out(n, nz,nv,56) = max(var_pft_out(n, nz,nv,56),0.) - var_pft_out(n, nz,nv,57) = max(var_pft_out(n, nz,nv,13)/25.,0.) - var_pft_out(n, nz,nv,58) = max(var_pft_out(n, nz,nv,14)/25.,0.) - var_pft_out(n, nz,nv,59) = max(var_pft_out(n, nz,nv,59),0.) - var_pft_out(n, nz,nv,60) = max(var_pft_out(n, nz,nv,60),0.) - var_pft_out(n, nz,nv,61) = max(var_pft_out(n, nz,nv,61),0.) - var_pft_out(n, nz,nv,62) = max(var_pft_out(n, nz,nv,62),0.) - var_pft_out(n, nz,nv,63) = max(var_pft_out(n, nz,nv,63),0.) - var_pft_out(n, nz,nv,64) = max(var_pft_out(n, nz,nv,64),0.) - var_pft_out(n, nz,nv,65) = max(var_pft_out(n, nz,nv,65),0.) - var_pft_out(n, nz,nv,66) = max(var_pft_out(n, nz,nv,66),0.) - var_pft_out(n, nz,nv,67) = max(var_pft_out(n, nz,nv,67),0.) - var_pft_out(n, nz,nv,68) = max(var_pft_out(n, nz,nv,68),0.) - var_pft_out(n, nz,nv,69) = max(var_pft_out(n, nz,nv,69),0.) - var_pft_out(n, nz,nv,70) = max(var_pft_out(n, nz,nv,70),0.) - var_pft_out(n, nz,nv,73) = max(var_pft_out(n, nz,nv,73),0.) - var_pft_out(n, nz,nv,74) = max(var_pft_out(n, nz,nv,74),0.) - if(clm45) var_pft_out(n, nz,nv,75) = max(var_pft_out(n, nz,nv,75),0.) - endif - end do NVLOOP3 ! end veg loop - endif ! end carbon check - end do NZLOOP ! end zone loop - - ! Update dayx variable var_pft_out (:,:,28) - - do j = 28, 28 ! 1,VAR_PFT var_pft_out (:,:,:,28) - do nv = 1,nveg - do nz = 1,nzone - var_pft_out (n, nz,nv,j) = dayx(n) - end do - end do - end do - - ! call NCDF_reshape_getOput (OutID,N,var_col_out,var_pft_out,.false.) - - ! column vars clm40 clm45 - ! ----------------- --------------------- - ! 1 clm3%g%l%c%ccs%col_ctrunc ! 1 ccs%col_ctrunc_vr (:,1) - ! 2 clm3%g%l%c%ccs%cwdc ! 2 ccs%decomp_cpools_vr(:,1,4) ! cwdc - ! 3 clm3%g%l%c%ccs%litr1c ! 3 ccs%decomp_cpools_vr(:,1,1) ! litr1c - ! 4 clm3%g%l%c%ccs%litr2c ! 4 ccs%decomp_cpools_vr(:,1,2) ! litr2c - ! 5 clm3%g%l%c%ccs%litr3c ! 5 ccs%decomp_cpools_vr(:,1,3) ! litr3c - ! 6 clm3%g%l%c%ccs%pcs_a%totvegc ! 6 ccs%totvegc_col - ! 7 clm3%g%l%c%ccs%prod100c ! 7 ccs%prod100c - ! 8 clm3%g%l%c%ccs%prod10c ! 8 ccs%prod10c - ! 9 clm3%g%l%c%ccs%seedc ! 9 ccs%seedc - ! 10 clm3%g%l%c%ccs%soil1c ! 10 ccs%decomp_cpools_vr(:,1,5) ! soil1c - ! 11 clm3%g%l%c%ccs%soil2c ! 11 ccs%decomp_cpools_vr(:,1,6) ! soil2c - ! 12 clm3%g%l%c%ccs%soil3c ! 12 ccs%decomp_cpools_vr(:,1,7) ! soil3c - ! 13 clm3%g%l%c%ccs%soil4c ! 13 ccs%decomp_cpools_vr(:,1,8) ! soil4c - ! 14 clm3%g%l%c%ccs%totcolc ! 14 ccs%totcolc - ! 15 clm3%g%l%c%ccs%totlitc ! 15 ccs%totlitc - ! 16 clm3%g%l%c%cns%col_ntrunc ! 16 cns%col_ntrunc_vr (:,1) - ! 17 clm3%g%l%c%cns%cwdn ! 17 cns%decomp_npools_vr(:,1,4) ! cwdn - ! 18 clm3%g%l%c%cns%litr1n ! 18 cns%decomp_npools_vr(:,1,1) ! litr1n - ! 19 clm3%g%l%c%cns%litr2n ! 19 cns%decomp_npools_vr(:,1,2) ! litr2n - ! 20 clm3%g%l%c%cns%litr3n ! 20 cns%decomp_npools_vr(:,1,3) ! litr3n - ! 21 clm3%g%l%c%cns%prod100n ! 21 cns%prod100n - ! 22 clm3%g%l%c%cns%prod10n ! 22 cns%prod10n - ! 23 clm3%g%l%c%cns%seedn ! 23 cns%seedn - ! 24 clm3%g%l%c%cns%sminn ! 24 cns%sminn_vr (:,1) - ! 25 clm3%g%l%c%cns%soil1n ! 25 cns%decomp_npools_vr(:,1,5) ! soil1n - ! 26 clm3%g%l%c%cns%soil2n ! 26 cns%decomp_npools_vr(:,1,6) ! soil2n - ! 27 clm3%g%l%c%cns%soil3n ! 27 cns%decomp_npools_vr(:,1,7) ! soil3n - ! 28 clm3%g%l%c%cns%soil4n ! 28 cns%decomp_npools_vr(:,1,8) ! soil4n - ! 29 clm3%g%l%c%cns%totcoln ! 29 cns%totcoln - ! 30 clm3%g%l%c%cps%ann_farea_burned ! 30 cps%fpg - ! 31 clm3%g%l%c%cps%annsum_counter ! 31 cps%annsum_counter - ! 32 clm3%g%l%c%cps%cannavg_t2m ! 32 cps%cannavg_t2m - ! 33 clm3%g%l%c%cps%cannsum_npp ! 33 cps%cannsum_npp - ! 34 clm3%g%l%c%cps%farea_burned ! 34 cps%farea_burned - ! 35 clm3%g%l%c%cps%fire_prob ! 35 cps%fpi_vr (:,1) - ! 36 clm3%g%l%c%cps%fireseasonl ! OLD ! 30 cps%altmax - ! 37 clm3%g%l%c%cps%fpg ! OLD ! 31 cps%annsum_counter - ! 38 clm3%g%l%c%cps%fpi ! OLD ! 32 cps%cannavg_t2m - ! 39 clm3%g%l%c%cps%me ! OLD ! 33 cps%cannsum_npp - ! 40 clm3%g%l%c%cps%mean_fire_prob ! OLD ! 34 cps%farea_burned - ! OLD ! 35 cps%altmax_lastyear - ! OLD ! 36 cps%altmax_indx - ! OLD ! 37 cps%fpg - ! OLD ! 38 cps%fpi_vr (:,1) - ! OLD ! 39 cps%altmax_lastyear_indx - - ! PFT vars CLM40 CLM45 - ! -------------- ----- - ! 1 clm3%g%l%c%p%pcs%cpool ! 1 pcs%cpool - ! 2 clm3%g%l%c%p%pcs%deadcrootc ! 2 pcs%deadcrootc - ! 3 clm3%g%l%c%p%pcs%deadcrootc_storage ! 3 pcs%deadcrootc_storage - ! 4 clm3%g%l%c%p%pcs%deadcrootc_xfer ! 4 pcs%deadcrootc_xfer - ! 5 clm3%g%l%c%p%pcs%deadstemc ! 5 pcs%deadstemc - ! 6 clm3%g%l%c%p%pcs%deadstemc_storage ! 6 pcs%deadstemc_storage - ! 7 clm3%g%l%c%p%pcs%deadstemc_xfer ! 7 pcs%deadstemc_xfer - ! 8 clm3%g%l%c%p%pcs%frootc ! 8 pcs%frootc - ! 9 clm3%g%l%c%p%pcs%frootc_storage ! 9 pcs%frootc_storage - ! 10 clm3%g%l%c%p%pcs%frootc_xfer ! 10 pcs%frootc_xfer - ! 11 clm3%g%l%c%p%pcs%gresp_storage ! 11 pcs%gresp_storage - ! 12 clm3%g%l%c%p%pcs%gresp_xfer ! 12 pcs%gresp_xfer - ! 13 clm3%g%l%c%p%pcs%leafc ! 13 pcs%leafc - ! 14 clm3%g%l%c%p%pcs%leafc_storage ! 14 pcs%leafc_storage - ! 15 clm3%g%l%c%p%pcs%leafc_xfer ! 15 pcs%leafc_xfer - ! 16 clm3%g%l%c%p%pcs%livecrootc ! 16 pcs%livecrootc - ! 17 clm3%g%l%c%p%pcs%livecrootc_storage ! 17 pcs%livecrootc_storage - ! 18 clm3%g%l%c%p%pcs%livecrootc_xfer ! 18 pcs%livecrootc_xfer - ! 19 clm3%g%l%c%p%pcs%livestemc ! 19 pcs%livestemc - ! 20 clm3%g%l%c%p%pcs%livestemc_storage ! 20 pcs%livestemc_storage - ! 21 clm3%g%l%c%p%pcs%livestemc_xfer ! 21 pcs%livestemc_xfer - ! 22 clm3%g%l%c%p%pcs%pft_ctrunc ! 22 pcs%pft_ctrunc - ! 23 clm3%g%l%c%p%pcs%xsmrpool ! 23 pcs%xsmrpool - ! 24 clm3%g%l%c%p%pepv%annavg_t2m ! 24 pepv%annavg_t2m - ! 25 clm3%g%l%c%p%pepv%annmax_retransn ! 25 pepv%annmax_retransn - ! 26 clm3%g%l%c%p%pepv%annsum_npp ! 26 pepv%annsum_npp - ! 27 clm3%g%l%c%p%pepv%annsum_potential_gpp ! 27 pepv%annsum_potential_gpp - ! 28 clm3%g%l%c%p%pepv%dayl ! 28 pepv%dayl - ! 29 clm3%g%l%c%p%pepv%days_active ! 29 pepv%days_active - ! 30 clm3%g%l%c%p%pepv%dormant_flag ! 30 pepv%dormant_flag - ! 31 clm3%g%l%c%p%pepv%offset_counter ! 31 pepv%offset_counter - ! 32 clm3%g%l%c%p%pepv%offset_fdd ! 32 pepv%offset_fdd - ! 33 clm3%g%l%c%p%pepv%offset_flag ! 33 pepv%offset_flag - ! 34 clm3%g%l%c%p%pepv%offset_swi ! 34 pepv%offset_swi - ! 35 clm3%g%l%c%p%pepv%onset_counter ! 35 pepv%onset_counter - ! 36 clm3%g%l%c%p%pepv%onset_fdd ! 36 pepv%onset_fdd - ! 37 clm3%g%l%c%p%pepv%onset_flag ! 37 pepv%onset_flag - ! 38 clm3%g%l%c%p%pepv%onset_gdd ! 38 pepv%onset_gdd - ! 39 clm3%g%l%c%p%pepv%onset_gddflag ! 39 pepv%onset_gddflag - ! 40 clm3%g%l%c%p%pepv%onset_swi ! 40 pepv%onset_swi - ! 41 clm3%g%l%c%p%pepv%prev_frootc_to_litter ! 41 pepv%prev_frootc_to_litter - ! 42 clm3%g%l%c%p%pepv%prev_leafc_to_litter ! 42 pepv%prev_leafc_to_litter - ! 43 clm3%g%l%c%p%pepv%tempavg_t2m ! 43 pepv%tempavg_t2m - ! 44 clm3%g%l%c%p%pepv%tempmax_retransn ! 44 pepv%tempmax_retransn - ! 45 clm3%g%l%c%p%pepv%tempsum_npp ! 45 pepv%tempsum_npp - ! 46 clm3%g%l%c%p%pepv%tempsum_potential_gpp ! 46 pepv%tempsum_potential_gpp - ! 47 clm3%g%l%c%p%pepv%xsmrpool_recover ! 47 pepv%xsmrpool_recover - ! 48 clm3%g%l%c%p%pns%deadcrootn ! 48 pns%deadcrootn - ! 49 clm3%g%l%c%p%pns%deadcrootn_storage ! 49 pns%deadcrootn_storage - ! 50 clm3%g%l%c%p%pns%deadcrootn_xfer ! 50 pns%deadcrootn_xfer - ! 51 clm3%g%l%c%p%pns%deadstemn ! 51 pns%deadstemn - ! 52 clm3%g%l%c%p%pns%deadstemn_storage ! 52 pns%deadstemn_storage - ! 53 clm3%g%l%c%p%pns%deadstemn_xfer ! 53 pns%deadstemn_xfer - ! 54 clm3%g%l%c%p%pns%frootn ! 54 pns%frootn - ! 55 clm3%g%l%c%p%pns%frootn_storage ! 55 pns%frootn_storage - ! 56 clm3%g%l%c%p%pns%frootn_xfer ! 56 pns%frootn_xfer - ! 57 clm3%g%l%c%p%pns%leafn ! 57 pns%leafn - ! 58 clm3%g%l%c%p%pns%leafn_storage ! 58 pns%leafn_storage - ! 59 clm3%g%l%c%p%pns%leafn_xfer ! 59 pns%leafn_xfer - ! 60 clm3%g%l%c%p%pns%livecrootn ! 60 pns%livecrootn - ! 61 clm3%g%l%c%p%pns%livecrootn_storage ! 61 pns%livecrootn_storage - ! 62 clm3%g%l%c%p%pns%livecrootn_xfer ! 62 pns%livecrootn_xfer - ! 63 clm3%g%l%c%p%pns%livestemn ! 63 pns%livestemn - ! 64 clm3%g%l%c%p%pns%livestemn_storage ! 64 pns%livestemn_storage - ! 65 clm3%g%l%c%p%pns%livestemn_xfer ! 65 pns%livestemn_xfer - ! 66 clm3%g%l%c%p%pns%npool ! 66 pns%npool - ! 67 clm3%g%l%c%p%pns%pft_ntrunc ! 67 pns%pft_ntrunc - ! 68 clm3%g%l%c%p%pns%retransn ! 68 pns%retransn - ! 69 clm3%g%l%c%p%pps%elai ! 69 pps%elai - ! 70 clm3%g%l%c%p%pps%esai ! 70 pps%esai - ! 71 clm3%g%l%c%p%pps%hbot ! 71 pps%hbot - ! 72 clm3%g%l%c%p%pps%htop ! 72 pps%htop - ! 73 clm3%g%l%c%p%pps%tlai ! 73 pps%tlai - ! 74 clm3%g%l%c%p%pps%tsai ! 74 pps%tsai - ! 75 pepv%plant_ndemand - ! OLD ! 75 pps%gddplant - ! OLD ! 76 pps%gddtsoi - ! OLD ! 77 pps%peaklai - ! OLD ! 78 pps%idop - ! OLD ! 79 pps%aleaf - ! OLD ! 80 pps%aleafi - ! OLD ! 81 pps%astem - ! OLD ! 82 pps%astemi - ! OLD ! 83 pps%htmx - ! OLD ! 84 pps%hdidx - ! OLD ! 85 pps%vf - ! OLD ! 86 pps%cumvd - ! OLD ! 87 pps%croplive - ! OLD ! 88 pps%cropplant - ! OLD ! 89 pps%harvdate - ! OLD ! 90 pps%gdd1020 - ! OLD ! 91 pps%gdd820 - ! OLD ! 92 pps%gdd020 - ! OLD ! 93 pps%gddmaturity - ! OLD ! 94 pps%huileaf - ! OLD ! 95 pps%huigrain - ! OLD ! 96 pcs%grainc - ! OLD ! 97 pcs%grainc_storage - ! OLD ! 98 pcs%grainc_xfer - ! OLD ! 99 pns%grainn - ! OLD !100 pns%grainn_storage - ! OLD !101 pns%grainn_xfer - ! OLD !102 pepv%fert_counter - ! OLD !103 pnf%fert - ! OLD !104 pepv%grain_flag - - end do OUT_TILE - - i = 1 - do nv = 1,VAR_COL - do nz = 1,nzone - STATUS = NF_PUT_VARA_REAL(OutID,VarID(OutID,'CNCOL'), (/1,i/), (/NTILES,1 /),var_col_out(:, nz,nv)) ; VERIFY_(STATUS) - i = i + 1 - end do - end do - - i = 1 - if(clm45) then - do iv = 1,VAR_PFT - do nv = 1,nveg - do nz = 1,nzone - if(iv <= 74) then - STATUS = NF_PUT_VARA_REAL(OutID,VarID(OutID,'CNPFT'), (/1,i/), (/NTILES,1 /),var_pft_out(:, nz,nv,iv)) ; VERIFY_(STATUS) - else - if((iv == 78) .OR. (iv == 89)) then ! idop and harvdate - var_dum = 999 - STATUS = NF_PUT_VARA_REAL(OutID,VarID(OutID,'CNPFT'), (/1,i/), (/NTILES,1 /),var_dum) ; VERIFY_(STATUS) - else - var_dum = 0. - STATUS = NF_PUT_VARA_REAL(OutID,VarID(OutID,'CNPFT'), (/1,i/), (/NTILES,1 /),var_dum) ; VERIFY_(STATUS) - endif - endif - i = i + 1 - end do - end do - end do - else - do iv = 1,VAR_PFT - do nv = 1,nveg - do nz = 1,nzone - STATUS = NF_PUT_VARA_REAL(OutID,VarID(OutID,'CNPFT'), (/1,i/), (/NTILES,1 /),var_pft_out(:, nz,nv,iv)) ; VERIFY_(STATUS) - i = i + 1 - end do - end do - end do - endif - - VAR_DUM = 0. - - do nz = 1,nzone - STATUS = NF_PUT_VARA_REAL(OutID,VarID(OUTID,'TGWM'), (/1,nz/), (/NTILES,1 /),VAR_DUM(:)) ; VERIFY_(STATUS) - STATUS = NF_PUT_VARA_REAL(OutID,VarID(OUTID,'RZMM'), (/1,nz/), (/NTILES,1 /),VAR_DUM(:)) ; VERIFY_(STATUS) - if(clm45) STATUS = NF_PUT_VARA_REAL(OutID,VarID(OUTID,'SFMM'), (/1,nz/), (/NTILES,1 /),VAR_DUM(:)) ; VERIFY_(STATUS) - end do - - STATUS = NF_PUT_VARA_REAL(OutID,VarID(OUTID,'BFLOWM' ), (/1/), (/NTILES/),VAR_DUM(:)) ; VERIFY_(STATUS) - STATUS = NF_PUT_VARA_REAL(OutID,VarID(OUTID,'TOTWATM'), (/1/), (/NTILES/),VAR_DUM(:)) ; VERIFY_(STATUS) - STATUS = NF_PUT_VARA_REAL(OutID,VarID(OUTID,'TAIRM' ), (/1/), (/NTILES/),VAR_DUM(:)) ; VERIFY_(STATUS) - STATUS = NF_PUT_VARA_REAL(OutID,VarID(OUTID,'TPM' ), (/1/), (/NTILES/),VAR_DUM(:)) ; VERIFY_(STATUS) - STATUS = NF_PUT_VARA_REAL(OutID,VarID(OUTID,'CNSUM' ), (/1/), (/NTILES/),VAR_DUM(:)) ; VERIFY_(STATUS) - STATUS = NF_PUT_VARA_REAL(OutID,VarID(OUTID,'SNDZM' ), (/1/), (/NTILES/),VAR_DUM(:)) ; VERIFY_(STATUS) - STATUS = NF_PUT_VARA_REAL(OutID,VarID(OUTID,'ASNOWM' ), (/1/), (/NTILES/),VAR_DUM(:)) ; VERIFY_(STATUS) - - if(clm45) then - STATUS = NF_PUT_VARA_REAL(OutID,VarID(OUTID,'AR1M' ), (/1/), (/NTILES/),VAR_DUM(:)) ; VERIFY_(STATUS) - STATUS = NF_PUT_VARA_REAL(OutID,VarID(OUTID,'RAINFM' ), (/1/), (/NTILES/),VAR_DUM(:)) ; VERIFY_(STATUS) - STATUS = NF_PUT_VARA_REAL(OutID,VarID(OUTID,'RHM' ), (/1/), (/NTILES/),VAR_DUM(:)) ; VERIFY_(STATUS) - STATUS = NF_PUT_VARA_REAL(OutID,VarID(OUTID,'RUNSRFM' ), (/1/), (/NTILES/),VAR_DUM(:)) ; VERIFY_(STATUS) - STATUS = NF_PUT_VARA_REAL(OutID,VarID(OUTID,'SNOWFM' ), (/1/), (/NTILES/),VAR_DUM(:)) ; VERIFY_(STATUS) - STATUS = NF_PUT_VARA_REAL(OutID,VarID(OUTID,'WINDM' ), (/1/), (/NTILES/),VAR_DUM(:)) ; VERIFY_(STATUS) - STATUS = NF_PUT_VARA_REAL(OutID,VarID(OUTID,'TPREC10D'), (/1/), (/NTILES/),VAR_DUM(:)) ; VERIFY_(STATUS) - STATUS = NF_PUT_VARA_REAL(OutID,VarID(OUTID,'TPREC60D'), (/1/), (/NTILES/),VAR_DUM(:)) ; VERIFY_(STATUS) - STATUS = NF_PUT_VARA_REAL(OutID,VarID(OUTID,'T2M10D' ), (/1/), (/NTILES/),VAR_DUM(:)) ; VERIFY_(STATUS) - else - STATUS = NF_PUT_VARA_REAL(OutID,VarID(OUTID,'SFMCM'), (/1/), (/NTILES/),VAR_DUM(:)) ; VERIFY_(STATUS) - endif - - do nv = 1,nzone - do nz = 1,nveg - STATUS = NF_PUT_VARA_REAL(OutID,VarID(OUTID,'PSNSUNM'), (/1,nz,nv/), (/NTILES,1,1/),VAR_DUM(:)) ; VERIFY_(STATUS) - STATUS = NF_PUT_VARA_REAL(OutID,VarID(OUTID,'PSNSHAM'), (/1,nz,nv/), (/NTILES,1,1/),VAR_DUM(:)) ; VERIFY_(STATUS) - end do - end do - - VAR_DUM = 0.1 - do i = 1,4 - STATUS = NF_PUT_VARA_REAL(OutID,VarID(OUTID,'WW'), (/1,i/), (/NTILES,1 /),VAR_DUM(:)) - end do - - VAR_DUM = 0.25 - do i = 1,4 - STATUS = NF_PUT_VARA_REAL(OutID,VarID(OUTID,'FR'), (/1,i/), (/NTILES,1 /),VAR_DUM(:)) - end do - - VAR_DUM = 0.001 - do i = 1,4 - STATUS = NF_PUT_VARA_REAL(OutID,VarID(OUTID,'CH'), (/1,i/), (/NTILES,1 /),VAR_DUM(:)) - STATUS = NF_PUT_VARA_REAL(OutID,VarID(OUTID,'CM'), (/1,i/), (/NTILES,1 /),VAR_DUM(:)) - STATUS = NF_PUT_VARA_REAL(OutID,VarID(OUTID,'CQ'), (/1,i/), (/NTILES,1 /),VAR_DUM(:)) - end do - - STATUS = NF_CLOSE (NCFID) - - deallocate (var_col_out,var_pft_out) - deallocate (CLMC_pf1, CLMC_pf2, CLMC_sf1, CLMC_sf2) - deallocate (CLMC_pt1, CLMC_pt2, CLMC_st1, CLMC_st2) - - END SUBROUTINE write_regridded_carbon - - ! ***************************************************************************** - - SUBROUTINE put_land_vars (NTILES, ntiles_rst, id_glb, ld_reorder, model, rst_file) - - implicit none - character(*), intent (in) :: model - integer, intent (in) :: NTILES, ntiles_rst - integer, intent (in) :: id_glb(NTILES), ld_reorder (ntiles_rst) - integer :: k, rc - real , dimension (:), allocatable :: var_get, var_put - type(Netcdf4_FileFormatter):: OutFmt, InFmt - type(FileMetadata) :: meta_data - integer :: STATUS, NCFID, OUTID - character(*), intent (in), optional :: rst_file - character(256) :: Iam = "put_land_vars" - - allocate (var_get (NTILES_RST)) - allocate (var_put (NTILES)) - - ! create output catchcn_internal_rst - if(index(model,'catchcn') /=0) then - if (clm45) then - call InFmt%open('/discover/nobackup/projects/gmao/ssd/land/l_data/LandRestarts_for_Regridding/CatchCN/catchcn_internal_clm45',PFIO_READ, __RC__) - else - call InFmt%open(trim(InCNRestart ), pFIO_READ, __RC__) - endif - endif - if(trim(model) == 'catch' ) then - call InFmt%open(trim(InCatRestart), pFIO_READ, __RC__) - endif - meta_data = InFmt%read(__RC__) - call InFmt%close(__RC__) - - call meta_data%modify_dimension('tile', ntiles, __RC__) - - OutFileName = "InData/"//trim(model)//"_internal_rst" - - call OutFmt%create(trim(OutFileName),__RC__) - call OutFmt%write(meta_data,__RC__) - - if (present(rst_file)) then - STATUS = NF_OPEN (trim(rst_file ),NF_NOWRITE,NCFID) ; VERIFY_(STATUS) - else - if(index(model, 'catchcn') /=0 ) then - STATUS = NF_OPEN (trim(InCNRestart ),NF_NOWRITE,NCFID) ; VERIFY_(STATUS) - endif - if(trim(model) == 'catch') then - STATUS = NF_OPEN (trim(InCatRestart),NF_NOWRITE,NCFID) ; VERIFY_(STATUS) - endif - endif - - ! Read catparam - ! ------------- - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'POROS' ), (/1/), (/NTILES_RST/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'POROS',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'COND' ), (/1/), (/NTILES_RST/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'COND',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'PSIS' ), (/1/), (/NTILES_RST/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'PSIS',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'BEE' ), (/1/), (/NTILES_RST/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'BEE',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'WPWET' ), (/1/), (/NTILES_RST/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'WPWET',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'GNU' ), (/1/), (/NTILES_RST/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'GNU',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'VGWMAX' ), (/1/), (/NTILES_RST/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'VGWMAX',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'BF1' ), (/1/), (/NTILES_RST/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'BF1',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'BF2' ), (/1/), (/NTILES_RST/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'BF2',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'BF3' ), (/1/), (/NTILES_RST/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'BF3',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'CDCR1' ), (/1/), (/NTILES_RST/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'CDCR1',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'CDCR2' ), (/1/), (/NTILES_RST/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'CDCR2',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'ARS1' ), (/1/), (/NTILES_RST/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'ARS1',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'ARS2' ), (/1/), (/NTILES_RST/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'ARS2',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'ARS3' ), (/1/), (/NTILES_RST/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'ARS3',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'ARA1' ), (/1/), (/NTILES_RST/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'ARA1',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'ARA2' ), (/1/), (/NTILES_RST/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'ARA2',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'ARA3' ), (/1/), (/NTILES_RST/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'ARA3',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'ARA4' ), (/1/), (/NTILES_RST/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'ARA4',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'ARW1' ), (/1/), (/NTILES_RST/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'ARW1',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'ARW2' ), (/1/), (/NTILES_RST/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'ARW2',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'ARW3' ), (/1/), (/NTILES_RST/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'ARW3',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'ARW4' ), (/1/), (/NTILES_RST/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'ARW4',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'TSA1' ), (/1/), (/NTILES_RST/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'TSA1',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'TSA2' ), (/1/), (/NTILES_RST/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'TSA2',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'TSB1' ), (/1/), (/NTILES_RST/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'TSB1',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'TSB2' ), (/1/), (/NTILES_RST/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'TSB2',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'ATAU' ), (/1/), (/NTILES_RST/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'ATAU',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'BTAU' ), (/1/), (/NTILES_RST/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'BTAU',var_put) - - if(index(model,'catchcn') /=0) then - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'ITY' ), (/1,1/), (/NTILES_RST,1/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'ITY',var_put, offset1=1) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'ITY' ), (/1,2/), (/NTILES_RST,1/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'ITY',var_put, offset1=2) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'ITY' ), (/1,3/), (/NTILES_RST,1/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'ITY',var_put, offset1=3) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'ITY' ), (/1,4/), (/NTILES_RST,1/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'ITY',var_put, offset1=4) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'FVG' ), (/1,1/), (/NTILES_RST,1/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'FVG',var_put, offset1=1) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'FVG' ), (/1,2/), (/NTILES_RST,1/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'FVG',var_put, offset1=2) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'FVG' ), (/1,3/), (/NTILES_RST,1/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'FVG',var_put, offset1=3) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'FVG' ), (/1,4/), (/NTILES_RST,1/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'FVG',var_put, offset1=4) - - ! read restart and regrid - ! ----------------------- - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'TG' ), (/1,1/), (/NTILES_RST,1/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'TG',var_put, offset1=1) ! if you see offset1=1 it is a 2-D var - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'TG' ), (/1,2/), (/NTILES_RST,1/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'TG',var_put, offset1=2) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'TG' ), (/1,3/), (/NTILES_RST,1/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'TG',var_put, offset1=3) - - endif - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'TC' ), (/1,1/), (/NTILES_RST,1/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'TC',var_put, offset1=1) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'TC' ), (/1,2/), (/NTILES_RST,1/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'TC',var_put, offset1=2) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'TC' ), (/1,3/), (/NTILES_RST,1/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'TC',var_put, offset1=3) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'QC' ), (/1,1/), (/NTILES_RST,1/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'QC',var_put, offset1=1) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'QC' ), (/1,2/), (/NTILES_RST,1/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'QC',var_put, offset1=2) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'QC' ), (/1,3/), (/NTILES_RST,1/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'QC',var_put, offset1=3) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'CAPAC' ), (/1/), (/NTILES_RST/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'CAPAC',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'CATDEF' ), (/1/), (/NTILES_RST/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'CATDEF',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'RZEXC' ), (/1/), (/NTILES_RST/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'RZEXC',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'SRFEXC' ), (/1/), (/NTILES_RST/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'SRFEXC',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'GHTCNT1' ), (/1/), (/NTILES_RST/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'GHTCNT1',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'GHTCNT2' ), (/1/), (/NTILES_RST/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'GHTCNT2',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'GHTCNT3' ), (/1/), (/NTILES_RST/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'GHTCNT3',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'GHTCNT4' ), (/1/), (/NTILES_RST/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'GHTCNT4',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'GHTCNT5' ), (/1/), (/NTILES_RST/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'GHTCNT5',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'GHTCNT6' ), (/1/), (/NTILES_RST/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'GHTCNT6',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'WESNN1' ), (/1/), (/NTILES_RST/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'WESNN1',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'WESNN2' ), (/1/), (/NTILES_RST/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'WESNN2',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'WESNN3' ), (/1/), (/NTILES_RST/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'WESNN3',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'HTSNNN1' ), (/1/), (/NTILES_RST/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'HTSNNN1',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'HTSNNN2' ), (/1/), (/NTILES_RST/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'HTSNNN2',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'HTSNNN3' ), (/1/), (/NTILES_RST/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'HTSNNN3',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'SNDZN1' ), (/1/), (/NTILES_RST/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'SNDZN1',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'SNDZN2' ), (/1/), (/NTILES_RST/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'SNDZN2',var_put) - - STATUS = NF_GET_VARA_REAL(NCFID,VarID(NCFID,'SNDZN3' ), (/1/), (/NTILES_RST/),var_get) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'SNDZN3',var_put) - - ! CH CM CQ FR WW - ! WW - VAR_PUT = 0.1 - do k = 1,4 - call MAPL_VarWrite(OutFmt,'WW',VAR_PUT ,offset1=k) - end do - ! FR - VAR_PUT = 0.25 - do k = 1,4 - call MAPL_VarWrite(OutFmt,'FR',VAR_PUT ,offset1=k) - end do - ! CH CM CQ - VAR_PUT = 0.001 - do k = 1,4 - call MAPL_VarWrite(OutFmt,'CH',VAR_PUT ,offset1=k) - call MAPL_VarWrite(OutFmt,'CM',VAR_PUT ,offset1=k) - call MAPL_VarWrite(OutFmt,'CQ',VAR_PUT ,offset1=k) - end do - - call OutFmt%close(__RC__) - STATUS = NF_CLOSE ( NCFID) - - deallocate (var_get, var_put) - CALL EXECUTE_COMMAND_LINE('/bin/cp InData/'//trim(model)//'_internal_rst OutData/'//trim(model)//'_internal_rst', .TRUE.) - - END SUBROUTINE put_land_vars - - ! ***************************************************************************** - - subroutine init_MPI() - - ! initialize MPI - - call MPI_INIT(mpierr) - - call MPI_COMM_RANK( MPI_COMM_WORLD, myid, mpierr ) - call MPI_COMM_SIZE( MPI_COMM_WORLD, numprocs, mpierr ) - - if (myid .ne. 0) root_proc = .false. - -! call init_MPI_types() - - write (*,*) "MPI process ", myid, " of ", numprocs, " is alive" - write (*,*) "MPI process ", myid, ": root_proc=", root_proc - - end subroutine init_MPI - - ! ----------------------------------------------------------------------- - - SUBROUTINE HANDLE_ERR(STATUS, Line) - - INTEGER, INTENT (IN) :: STATUS - CHARACTER(*), INTENT (IN) :: Line - - IF (STATUS .NE. NF_NOERR) THEN - PRINT *, trim(Line),': ',NF_STRERROR(STATUS) - STOP 'Stopped' - ENDIF - - END SUBROUTINE HANDLE_ERR - - ! ***************************************************************************** - - subroutine compute_dayx ( & - NTILES, AGCM_YY, AGCM_MM, AGCM_DD, AGCM_HR, & - LATT, DAYX) - - implicit none - - integer, intent (in) :: NTILES,AGCM_YY,AGCM_MM,AGCM_DD,AGCM_HR - real, dimension (NTILES), intent (in) :: LATT - real, dimension (NTILES), intent (out) :: DAYX - integer, parameter :: DT = 900 - integer, parameter :: ncycle = 1461 ! number of days in a 4-year leap cycle (365*4 + 1) - real, dimension(ncycle) :: zc, zs - integer :: dofyr, sec,YEARS_PER_CYCLE, DAYS_PER_CYCLE, year, iday, idayp1, nn, n - real :: fac, YEARLEN, zsin, zcos, declin - - dofyr = AGCM_DD - if(AGCM_MM > 1) dofyr = dofyr + 31 - if(AGCM_MM > 2) then - dofyr = dofyr + 28 - if(mod(AGCM_YY,4) == 0) dofyr = dofyr + 1 - endif - if(AGCM_MM > 3) dofyr = dofyr + 31 - if(AGCM_MM > 4) dofyr = dofyr + 30 - if(AGCM_MM > 5) dofyr = dofyr + 31 - if(AGCM_MM > 6) dofyr = dofyr + 30 - if(AGCM_MM > 7) dofyr = dofyr + 31 - if(AGCM_MM > 8) dofyr = dofyr + 31 - if(AGCM_MM > 9) dofyr = dofyr + 30 - if(AGCM_MM > 10) dofyr = dofyr + 31 - if(AGCM_MM > 11) dofyr = dofyr + 30 - - sec = AGCM_HR * 3600 - DT ! subtract DT to get time of previous physics step - fac = real(sec) / 86400. - - call orbit_create(zs,zc,ncycle) ! GEOS5 leap cycle routine - - YEARLEN = 365.25 - - ! Compute length of leap cycle - !------------------------------ - - if(YEARLEN-int(YEARLEN) > 0.) then - YEARS_PER_CYCLE = nint(1./(YEARLEN-int(YEARLEN))) - else - YEARS_PER_CYCLE = 1 - endif - - DAYS_PER_CYCLE=nint(YEARLEN*YEARS_PER_CYCLE) - - ! declination & daylength - ! ----------------------- - - YEAR = mod(AGCM_YY-1,YEARS_PER_CYCLE) - - IDAY = YEAR*int(YEARLEN)+dofyr - IDAYP1 = mod(IDAY,DAYS_PER_CYCLE) + 1 - - ZSin = ZS(IDAYP1)*FAC + ZS(IDAY)*(1.-FAC) ! sine of solar declination - ZCos = ZC(IDAYP1)*FAC + ZC(IDAY)*(1.-FAC) ! cosine of solar declination - - nn = 0 - do n = 1,days_per_cycle - nn = nn + 1 - if(nn > 365) nn = nn - 365 - ! print *, 'cycle:',n,nn,asin(ZS(n)) - end do - - declin = asin(ZSin) - - ! compute daylength on input tile space (accounts for any change in physics time step) - ! do n = 1,ntiles_cn - ! fac = -(sin((latc(n)/zoom)*(MAPL_PI/180.))*zsin)/(cos((latc(n)/zoom)*(MAPL_PI/180.))*zcos) - ! fac = min(1.,max(-1.,fac)) - ! dayl(n) = (86400./MAPL_PI) * acos(fac) ! daylength (seconds) - ! end do - - ! compute daylength on output tile space (accounts for lat shift due to split & change in time step) - - do n = 1,ntiles - fac = -(sin(latt(n)*(MAPL_PI/180.))*zsin)/(cos(latt(n)*(MAPL_PI/180.))*zcos) - fac = min(1.,max(-1.,fac)) - dayx(n) = (86400./MAPL_PI) * acos(fac) ! daylength (seconds) - end do - - ! print *,'DAYX : ', minval(dayx),maxval(dayx), minval(latt), maxval(latt), zsin, zcos, dofyr, iday, idayp1, declin - - end subroutine compute_dayx - - ! ***************************************************************************** - - subroutine orbit_create(zs,zc,ncycle) - - implicit none - - integer, intent(in) :: ncycle - real, intent(out), dimension(ncycle) :: zs, zc - - integer :: YEARS_PER_CYCLE, DAYS_PER_CYCLE - integer :: K, KP !, KM - real*8 :: T1, T2, T3, T4, FUN, Y, SOB, OMG, PRH, TT - real*8 :: YEARLEN - - ! STATEMENT FUNCTION - - FUN(Y) = OMG*(1.0-ECCENTRICITY*cos(Y-PRH))**2 - - YEARLEN = 365.25 - - ! Factors involving the orbital parameters - !------------------------------------------ - - OMG = (2.0*MAPL_PI/YEARLEN) / (sqrt(1.-ECCENTRICITY**2)**3) - PRH = PERIHELION*(MAPL_PI/180.) - SOB = sin(OBLIQUITY*(MAPL_PI/180.)) - - ! Compute length of leap cycle - !------------------------------ - - if(YEARLEN-int(YEARLEN) > 0.) then - YEARS_PER_CYCLE = nint(1./(YEARLEN-int(YEARLEN))) - else - YEARS_PER_CYCLE = 1 - endif - - DAYS_PER_CYCLE=nint(YEARLEN*YEARS_PER_CYCLE) - - if(days_per_cycle /= ncycle) stop 'bad cycle' - - ! ZS: Sine of declination - ! ZC: Cosine of declination - - ! Begin integration at vernal equinox - - KP = EQUINOX - TT = 0.0 - ZS(KP) = sin(TT)*SOB - ZC(KP) = sqrt(1.0-ZS(KP)**2) - - ! Integrate orbit for entire leap cycle using Runge-Kutta - - do K=2,DAYS_PER_CYCLE - T1 = FUN(TT ) - T2 = FUN(TT+T1*0.5) - T3 = FUN(TT+T2*0.5) - T4 = FUN(TT+T3 ) - KP = mod(KP,DAYS_PER_CYCLE) + 1 - TT = TT + (T1 + 2.0*(T2 + T3) + T4) / 6.0 - ZS(KP) = sin(TT)*SOB - ZC(KP) = sqrt(1.0-ZS(KP)**2) - end do - - end subroutine orbit_create - -! ***************************************************************************** - -! function to_radian(degree) result(rad) -! -! ! degrees to radians -! real,intent(in) :: degree -! real :: rad -! -! rad = degree*MAPL_PI/180. -! -! end function to_radian -! -! ! ***************************************************************************** -! -! real function haversine(deglat1,deglon1,deglat2,deglon2) -! ! great circle distance -- adapted from Matlab -! real,intent(in) :: deglat1,deglon1,deglat2,deglon2 -! real :: a,c, dlat,dlon,lat1,lat2 -! real,parameter :: radius = MAPL_radius -! -!! dlat = to_radian(deglat2-deglat1) -!! dlon = to_radian(deglon2-deglon1) -! ! lat1 = to_radian(deglat1) -!! lat2 = to_radian(deglat2) -! dlat = deglat2-deglat1 -! dlon = deglon2-deglon1 -! lat1 = deglat1 -! lat2 = deglat2 -! a = (sin(dlat/2))**2 + cos(lat1)*cos(lat2)*(sin(dlon/2))**2 -! if(a>=0. .and. a<=1.) then -! c = 2*atan2(sqrt(a),sqrt(1-a)) -! haversine = radius*c / 1000. -! else -! haversine = 1.e20 -! endif -! end function -! -! ! ---------------------------------------------------------------------- - - integer function VarID (NCFID, VNAME) - - integer, intent (in) :: NCFID - character(*), intent (in) :: VNAME - integer :: status - - STATUS = NF_INQ_VARID (NCFID, trim(VNAME) ,VarID) - IF (STATUS .NE. NF_NOERR) & - CALL HANDLE_ERR(STATUS, trim(VNAME)) - - end function VarID -! ! ----------------------------------------------------------------------------- -! - - FUNCTION StrUpCase ( Input_String ) RESULT ( Output_String ) - ! -- Argument and result - CHARACTER( * ), INTENT( IN ) :: Input_String - CHARACTER( LEN( Input_String ) ) :: Output_String - ! -- Local variables - INTEGER :: i, n - - - ! -- Copy input string - Output_String = Input_String - ! -- Loop over string elements - DO i = 1, LEN( Output_String ) - ! -- Find location of letter in lower case constant string - n = INDEX( LOWER_CASE, Output_String( i:i ) ) - ! -- If current substring is a lower case letter, make it upper case - IF ( n /= 0 ) Output_String( i:i ) = UPPER_CASE( n:n ) - END DO - END FUNCTION StrUpCase - - ! ----------------------------------------------------------------------------- - - FUNCTION StrLowCase ( Input_String ) RESULT ( Output_String ) - ! -- Argument and result - CHARACTER( * ), INTENT( IN ) :: Input_String - CHARACTER( LEN( Input_String ) ) :: Output_String - ! -- Local variables - INTEGER :: i, n - - ! -- Copy input string - Output_String = Input_String - ! -- Loop over string elements - DO i = 1, LEN( Output_String ) - ! -- Find location of letter in upper case constant string - n = INDEX( UPPER_CASE, Output_String( i:i ) ) - ! -- If current substring is an upper case letter, make it lower case - IF ( n /= 0 ) Output_String( i:i ) = LOWER_CASE( n:n ) - END DO - END FUNCTION StrLowCase - - ! ----------------------------------------------------------------------------- - - FUNCTION StrExtName ( Input_String ) RESULT ( Output_String ) - ! -- Argument and result - CHARACTER( * ), INTENT( IN ) :: Input_String - CHARACTER( LEN( Input_String ) ) :: Output_String - ! -- Local variables - INTEGER :: i, n1, n2, n3, n4, n5, n, k - - ! -- Copy input string - ! Output_String = Input_String - ! -- Loop over string elements - - k = 1 - - DO i = 1, LEN( Input_String ) - - ! -- Find location of letter in upper case constant string - n1 = INDEX( UPPER_CASE, Input_String( i:i ) ) - n2 = INDEX( LOWER_CASE, Input_String( i:i ) ) - n3 = INDEX( '.', Input_String( i:i ) ) - n4 = INDEX( '-', Input_String( i:i ) ) - n5 = INDEX( '_', Input_String( i:i ) ) - - n = 0 - Output_String(i:i) = '' - - if (n1 /= 0) n = n1 - if (n2 /= 0) n = n2 - if (n3 /= 0) n = n3 - if (n4 /= 0) n = n4 - if (n5 /= 0) n = n5 - - ! -- If current substring is acceptable - IF ( n /= 0 ) then - Output_String( k:k ) = Input_String( i:i ) - k = k + 1 - endif - - END DO - - END FUNCTION StrExtName - - ! ---------------------------------------------------------------------------- - - SUBROUTINE write_bin (unit, InFmt, NTILES) - - implicit none - integer :: ntiles - integer :: unit - type(Netcdf4_FileFormatter) :: InFmt - - - real :: bf1(ntiles) - real :: bf2(ntiles) - real :: bf3(ntiles) - real :: vgwmax(ntiles) - real :: cdcr1(ntiles) - real :: cdcr2(ntiles) - real :: psis(ntiles) - real :: bee(ntiles) - real :: poros(ntiles) - real :: wpwet(ntiles) - real :: cond(ntiles) - real :: gnu(ntiles) - real :: ars1(ntiles) - real :: ars2(ntiles) - real :: ars3(ntiles) - real :: ara1(ntiles) - real :: ara2(ntiles) - real :: ara3(ntiles) - real :: ara4(ntiles) - real :: arw1(ntiles) - real :: arw2(ntiles) - real :: arw3(ntiles) - real :: arw4(ntiles) - real :: tsa1(ntiles) - real :: tsa2(ntiles) - real :: tsb1(ntiles) - real :: tsb2(ntiles) - real :: atau(ntiles) - real :: btau(ntiles) - real :: ity(ntiles) - real :: tc(ntiles,4) - real :: qc(ntiles,4) - real :: capac(ntiles) - real :: catdef(ntiles) - real :: rzexc(ntiles) - real :: srfexc(ntiles) - real :: ghtcnt1(ntiles) - real :: ghtcnt2(ntiles) - real :: ghtcnt3(ntiles) - real :: ghtcnt4(ntiles) - real :: ghtcnt5(ntiles) - real :: ghtcnt6(ntiles) - real :: tsurf(ntiles) - real :: wesnn1(ntiles) - real :: wesnn2(ntiles) - real :: wesnn3(ntiles) - real :: htsnnn1(ntiles) - real :: htsnnn2(ntiles) - real :: htsnnn3(ntiles) - real :: sndzn1(ntiles) - real :: sndzn2(ntiles) - real :: sndzn3(ntiles) - real :: ch(ntiles,4) - real :: cm(ntiles,4) - real :: cq(ntiles,4) - real :: fr(ntiles,4) - real :: ww(ntiles,4) - character*256 :: Iam = "Write bin" - integer :: status - - call MAPL_VarRead(InFmt,"BF1",bf1, __RC__) - call MAPL_VarRead(InFmt,"BF2",bf2, __RC__) - call MAPL_VarRead(InFmt,"BF3",bf3, __RC__) - call MAPL_VarRead(InFmt,"VGWMAX",vgwmax, __RC__) - call MAPL_VarRead(InFmt,"CDCR1",cdcr1, __RC__) - call MAPL_VarRead(InFmt,"CDCR2",cdcr2, __RC__) - call MAPL_VarRead(InFmt,"PSIS",psis, __RC__) - call MAPL_VarRead(InFmt,"BEE",bee, __RC__) - call MAPL_VarRead(InFmt,"POROS",poros, __RC__) - call MAPL_VarRead(InFmt,"WPWET",wpwet, __RC__) - call MAPL_VarRead(InFmt,"COND",cond, __RC__) - call MAPL_VarRead(InFmt,"GNU",gnu, __RC__) - call MAPL_VarRead(InFmt,"ARS1",ars1, __RC__) - call MAPL_VarRead(InFmt,"ARS2",ars2, __RC__) - call MAPL_VarRead(InFmt,"ARS3",ars3, __RC__) - call MAPL_VarRead(InFmt,"ARA1",ara1, __RC__) - call MAPL_VarRead(InFmt,"ARA2",ara2, __RC__) - call MAPL_VarRead(InFmt,"ARA3",ara3, __RC__) - call MAPL_VarRead(InFmt,"ARA4",ara4, __RC__) - call MAPL_VarRead(InFmt,"ARW1",arw1, __RC__) - call MAPL_VarRead(InFmt,"ARW2",arw2, __RC__) - call MAPL_VarRead(InFmt,"ARW3",arw3, __RC__) - call MAPL_VarRead(InFmt,"ARW4",arw4, __RC__) - call MAPL_VarRead(InFmt,"TSA1",tsa1, __RC__) - call MAPL_VarRead(InFmt,"TSA2",tsa2, __RC__) - call MAPL_VarRead(InFmt,"TSB1",tsb1, __RC__) - call MAPL_VarRead(InFmt,"TSB2",tsb2, __RC__) - call MAPL_VarRead(InFmt,"ATAU",atau, __RC__) - call MAPL_VarRead(InFmt,"BTAU",btau, __RC__) - call MAPL_VarRead(InFmt,"OLD_ITY",ity, __RC__) - call MAPL_VarRead(InFmt,"TC",tc, __RC__) - call MAPL_VarRead(InFmt,"QC",qc, __RC__) - call MAPL_VarRead(InFmt,"OLD_ITY",ity, __RC__) - call MAPL_VarRead(InFmt,"CAPAC",capac, __RC__) - call MAPL_VarRead(InFmt,"CATDEF",catdef, __RC__) - call MAPL_VarRead(InFmt,"RZEXC",rzexc, __RC__) - call MAPL_VarRead(InFmt,"SRFEXC",srfexc, __RC__) - call MAPL_VarRead(InFmt,"GHTCNT1",ghtcnt1, __RC__) - call MAPL_VarRead(InFmt,"GHTCNT2",ghtcnt2, __RC__) - call MAPL_VarRead(InFmt,"GHTCNT3",ghtcnt3, __RC__) - call MAPL_VarRead(InFmt,"GHTCNT4",ghtcnt4, __RC__) - call MAPL_VarRead(InFmt,"GHTCNT5",ghtcnt5, __RC__) - call MAPL_VarRead(InFmt,"GHTCNT6",ghtcnt6, __RC__) - call MAPL_VarRead(InFmt,"TSURF",tsurf, __RC__) - call MAPL_VarRead(InFmt,"WESNN1",wesnn1, __RC__) - call MAPL_VarRead(InFmt,"WESNN2",wesnn2, __RC__) - call MAPL_VarRead(InFmt,"WESNN3",wesnn3, __RC__) - call MAPL_VarRead(InFmt,"HTSNNN1",htsnnn1, __RC__) - call MAPL_VarRead(InFmt,"HTSNNN2",htsnnn2, __RC__) - call MAPL_VarRead(InFmt,"HTSNNN3",htsnnn3, __RC__) - call MAPL_VarRead(InFmt,"SNDZN1",sndzn1, __RC__) - call MAPL_VarRead(InFmt,"SNDZN2",sndzn2, __RC__) - call MAPL_VarRead(InFmt,"SNDZN3",sndzn3, __RC__) - call MAPL_VarRead(InFmt,"CH",ch, __RC__) - call MAPL_VarRead(InFmt,"CM",cm, __RC__) - call MAPL_VarRead(InFmt,"CQ",cq, __RC__) - call MAPL_VarRead(InFmt,"FR",fr, __RC__) - call MAPL_VarRead(InFmt,"WW",ww, __RC__) - - write(unit) bf1 - write(unit) bf2 - write(unit) bf3 - write(unit) vgwmax - write(unit) cdcr1 - write(unit) cdcr2 - write(unit) psis - write(unit) bee - write(unit) poros - write(unit) wpwet - write(unit) cond - write(unit) gnu - write(unit) ars1 - write(unit) ars2 - write(unit) ars3 - write(unit) ara1 - write(unit) ara2 - write(unit) ara3 - write(unit) ara4 - write(unit) arw1 - write(unit) arw2 - write(unit) arw3 - write(unit) arw4 - write(unit) tsa1 - write(unit) tsa2 - write(unit) tsb1 - write(unit) tsb2 - write(unit) atau - write(unit) btau - write(unit) ity - write(unit) tc - write(unit) qc - write(unit) capac - write(unit) catdef - write(unit) rzexc - write(unit) srfexc - write(unit) ghtcnt1 - write(unit) ghtcnt2 - write(unit) ghtcnt3 - write(unit) ghtcnt4 - write(unit) ghtcnt5 - write(unit) ghtcnt6 - write(unit) tsurf - write(unit) wesnn1 - write(unit) wesnn2 - write(unit) wesnn3 - write(unit) htsnnn1 - write(unit) htsnnn2 - write(unit) htsnnn3 - write(unit) sndzn1 - write(unit) sndzn2 - write(unit) sndzn3 - write(unit) ch - write(unit) cm - write(unit) cq - write(unit) fr - write(unit) ww - - END SUBROUTINE write_bin - - ! ---------------------------------------------------------------------------- - - SUBROUTINE read_ldas_restarts (NTILES, ntiles_rst, id_glb, ld_reorder, rst_file, pfile) - - implicit none - integer, intent (in) :: NTILES, ntiles_rst - integer, intent (in) :: id_glb(NTILES), ld_reorder (ntiles_rst) - integer :: k - character(*), intent (in) :: rst_file, pfile - real , dimension (:), allocatable :: var_get, var_put - type(Netcdf4_FileFormatter) :: OutFmt, InFmt - type(FileMetadata) :: meta_data - - allocate (var_get (NTILES_RST)) - allocate (var_put (NTILES)) - - call InFmt%Open(trim(InCatRestart), pFIO_READ, __RC__) - meta_data = InFmt%read(__RC__) - call InFmt%close() - call meta_data%modify_dimension('tile', ntiles, __RC__) - - OutFileName = "InData/catch_internal_rst" - call OutFmt%create(OutFileName, __RC__) - call OutFmt%write(meta_data, __RC__) - - open(10, file=trim(rst_file), form='unformatted', status='old', & - convert='big_endian', action='read') - - read (10) var_get ! (cat_progn(n)%tc1, n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'TC',var_put, offset1=1) - - read (10) var_get ! (cat_progn(n)%tc2, n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'TC',var_put, offset1=2) - - read (10) var_get ! (cat_progn(n)%tc4, n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'TC',var_put, offset1=3) - - read (10) var_get ! (cat_progn(n)%qa1, n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'QC',var_put, offset1=1) - - read (10) var_get ! (cat_progn(n)%qa2, n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'QC',var_put, offset1=2) - - read (10) var_get ! (cat_progn(n)%qa4, n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'QC',var_put, offset1=3) - call MAPL_VarWrite(OutFmt,'QC',var_put, offset1=4) - - read (10) var_get ! (cat_progn(n)%capac, n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'CAPAC',var_put) - - read (10) var_get ! (cat_progn(n)%catdef, n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'CATDEF',var_put) - - read (10) var_get ! (cat_progn(n)%rzexc, n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'RZEXC',var_put) - - read (10) var_get ! (cat_progn(n)%srfexc, n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'SRFEXC',var_put) - - read (10) var_get ! (cat_progn(n)%ght(k), n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'GHTCNT1',var_put) - read (10) var_get ! (cat_progn(n)%ght(k), n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'GHTCNT2',var_put) - read (10) var_get ! (cat_progn(n)%ght(k), n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'GHTCNT3',var_put) - read (10) var_get ! (cat_progn(n)%ght(k), n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'GHTCNT4',var_put) - read (10) var_get ! (cat_progn(n)%ght(k), n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'GHTCNT5',var_put) - read (10) var_get ! (cat_progn(n)%ght(k), n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'GHTCNT6',var_put) - - read (10) var_get !(cat_progn(n)%wesn(k), n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'WESNN1',var_put) - read (10) var_get !(cat_progn(n)%wesn(k), n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'WESNN2',var_put) - read (10) var_get !(cat_progn(n)%wesn(k), n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'WESNN3',var_put) - - read (10) var_get !(cat_progn(n)%htsn(k), n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'HTSNNN1',var_put) - read (10) var_get !(cat_progn(n)%htsn(k), n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'HTSNNN2',var_put) - read (10) var_get !(cat_progn(n)%htsn(k), n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'HTSNNN3',var_put) - - read (10) var_get !(cat_progn(n)%sndz(k), n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'SNDZN1',var_put) - read (10) var_get !(cat_progn(n)%sndz(k), n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'SNDZN2',var_put) - read (10) var_get !(cat_progn(n)%sndz(k), n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'SNDZN3',var_put) - - close (10) - -! PARAM - - open(10, file=trim(pfile), form='unformatted', status='old', & - convert='big_endian', action='read') - - - read (10) var_get !(cat_param(n)%dpth, n=1,N_catd) - - read (10) var_get !(cat_param(n)%dzsf, n=1,N_catd) - read (10) var_get !(cat_param(n)%dzrz, n=1,N_catd) - read (10) var_get !(cat_param(n)%dzpr, n=1,N_catd) - - do k=1,6 - read (10) var_get !(cat_param(n)%dzgt(k), n=1,N_catd) - end do - do k = 1, NTILES - VAR_PUT(k) = id_glb(k) - end do - call MAPL_VarWrite(OutFmt,'TILE_ID',var_put) - - read (10) var_get !(cat_param(n)%poros, n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'POROS',var_put) - - read (10) var_get !(cat_param(n)%cond, n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'COND',var_put) - - read (10) var_get !(cat_param(n)%psis, n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'PSIS',var_put) - - read (10) var_get !(cat_param(n)%bee, n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'BEE',var_put) - - read (10) var_get !(cat_param(n)%wpwet, n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'WPWET',var_put) - - read (10) var_get !(cat_param(n)%gnu, n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'GNU',var_put) - - read (10) var_get !(cat_param(n)%vgwmax, n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'VGWMAX',var_put) - - read (10) var_get !(cat_param(n)%vegcls, n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'OLD_ITY',var_put) - - read (10) var_get !(cat_param(n)%soilcls30, n=1,N_catd) - read (10) var_get !(cat_param(n)%soilcls100, n=1,N_catd) - - read (10) var_get !(cat_param(n)%bf1, n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'BF1',var_put) - - read (10) var_get !(cat_param(n)%bf2, n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'BF2',var_put) - - read (10) var_get !(cat_param(n)%bf3, n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'BF3',var_put) - - read (10) var_get !(cat_param(n)%cdcr1, n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'CDCR1',var_put) - - read (10) var_get !(cat_param(n)%cdcr2, n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'CDCR2',var_put) - - read (10) var_get !(cat_param(n)%ars1, n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'ARS1',var_put) - - read (10) var_get !(cat_param(n)%ars2, n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'ARS2',var_put) - - read (10) var_get !(cat_param(n)%ars3, n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'ARS3',var_put) - - read (10) var_get !(cat_param(n)%ara1, n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'ARA1',var_put) - - read (10) var_get !(cat_param(n)%ara2, n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'ARA2',var_put) - - read (10) var_get !(cat_param(n)%ara3, n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'ARA3',var_put) - - read (10) var_get !(cat_param(n)%ara4, n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'ARA4',var_put) - - read (10) var_get !(cat_param(n)%arw1, n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'ARW1',var_put) - - read (10) var_get !(cat_param(n)%arw2, n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'ARW2',var_put) - - read (10) var_get !(cat_param(n)%arw3, n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'ARW3',var_put) - - read (10) var_get !(cat_param(n)%arw4, n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'ARW4',var_put) - - read (10) var_get !(cat_param(n)%tsa1, n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'TSA1',var_put) - - read (10) var_get !(cat_param(n)%tsa2, n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'TSA2',var_put) - - read (10) var_get !(cat_param(n)%tsb1, n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'TSB1',var_put) - - read (10) var_get !(cat_param(n)%tsb2, n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'TSB2',var_put) - - read (10) var_get !(cat_param(n)%atau, n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'ATAU',var_put) - - read (10) var_get !(cat_param(n)%btau, n=1,N_catd) - do k = 1, NTILES - VAR_PUT(k) = var_get(ld_reorder(id_glb(k))) - end do - call MAPL_VarWrite(OutFmt,'BTAU',var_put) - - read (10) var_get !(cat_param(n)%gravel30, n=1,N_catd) - read (10) var_get !(cat_param(n)%orgC30 , n=1,N_catd) - read (10) var_get !(cat_param(n)%orgC , n=1,N_catd) - read (10) var_get !(cat_param(n)%sand30 , n=1,N_catd) - read (10) var_get !(cat_param(n)%clay30 , n=1,N_catd) - read (10) var_get !(cat_param(n)%sand , n=1,N_catd) - read (10) var_get !(cat_param(n)%clay , n=1,N_catd) - read (10) var_get !(cat_param(n)%wpwet30 , n=1,N_catd) - read (10) var_get !(cat_param(n)%poros30 , n=1,N_catd) - - close (10, status = 'keep') - deallocate (var_get, var_put) - - call OutFmt%close() - - call system('/bin/cp InData/catch_internal_rst OutData/catch_internal_rst') - - END SUBROUTINE read_ldas_restarts - - END PROGRAM mk_GEOSldasRestarts diff --git a/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/mk_Restarts b/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/mk_Restarts deleted file mode 100755 index 7040cf2a6..000000000 --- a/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/mk_Restarts +++ /dev/null @@ -1,404 +0,0 @@ -#!/usr/bin/env perl -#======================================================================= -# name - mk_Restarts -# purpose - wrapper script to run programs which regrid surface restarts -#======================================================================= -use strict; -use warnings; -use FindBin qw($Bin); -use lib ("$Bin"); -use Cwd qw(getcwd); - -# global variables -#----------------- -my ($saltwater, $openwater, $seaice, $lake, $landice, $route); -my ($catchFLG, $catchcn, $catchcnFLG, @cnlist, @cnlen); -my ($surflay, $rsttime, $grpID, $numtasks, $walltime, $rescale, $qos, $partition, $constraint, $yyyymm); -my ($mk_catch_j, $mk_catch_log, $weminIN, $weminOUT, $weminDFLT); -my ($zoom); - -# mk_catch job and log file names (also applies to catchcn) -#---------------------------------------------------------- -$mk_catch_j = "mk_catch.j"; -$mk_catch_log = "mk_catch.log"; - -# main program -#------------- -{ - my ($cmd, $line, $pid); - - init(); - - #--------------------------- - # catch and catchcn restarts - #--------------------------- - if ($catchFLG or $catchcnFLG) { - write_mk_catch_j() unless -e $mk_catch_j; - - # run interactively if already on interactive job nodes - #------------------------------------------------------ - if (-x $mk_catch_j) { - $cmd = "./$mk_catch_j"; - system_($cmd); - } - else { - $cmd = "sbatch -W $mk_catch_j"; - print "$cmd\n"; - chomp($line = `$cmd`); - $pid = (split /\s+/, $line)[-1]; - } - } - - #------------------ - # saltwater restart - #------------------ - if ($saltwater) { - $cmd = "$Bin/mk_LakeLandiceSaltRestarts " - . "OutData/\*.til " - . "InData/\*.til " - . "InData/\*saltwater_internal_rst\* 0 $zoom"; - system_($cmd); - } - - if ($openwater) { - $cmd = "$Bin/mk_LakeLandiceSaltRestarts " - . "OutData/\*.til " - . "InData/\*.til " - . "InData/\*openwater_internal_rst\* 0 $zoom"; - system_($cmd); - } - - if ($seaice) { - $cmd = "$Bin/mk_LakeLandiceSaltRestarts " - . "OutData/\*.til " - . "InData/\*.til " - . "InData/\*seaicethermo_internal_rst\* 0 $zoom"; - system_($cmd); - } - - #------------- - # lake restart - #------------- - if ($lake) { - $cmd = "$Bin/mk_LakeLandiceSaltRestarts " - . "OutData/\*.til " - . "InData/\*.til " - . "InData/\*lake_internal_rst\* 19 $zoom"; - system_($cmd); - } - - #---------------- - # landice restart - #---------------- - if ($landice) { - $cmd = "$Bin/mk_LakeLandiceSaltRestarts " - . "OutData/\*.til " - . "InData/\*.til " - . "InData/\*landice_internal_rst\* 20 $zoom"; - system_($cmd); - } - - #-------------- - # route restart - #-------------- - if ($route) { - $cmd = "$Bin/mk_RouteRestarts OutData/\*.til $yyyymm"; - system_($cmd); - } - wait_for_pid($pid) if $pid; -} - -#======================================================================= -# name - init -# purpose - get runtime flags to determine which restarts to regrid -#======================================================================= -sub init { - use Getopt::Long; - my $help; - $| = 1; # flush buffer after each output operation - - GetOptions( "saltwater" => \$saltwater, - "openwater" => \$openwater, - "seaice" => \$seaice, - "lake" => \$lake, - "landice" => \$landice, - "catch" => \$catchFLG, - "catchcn=s" => \$catchcn, - "wemin=i" => \$weminIN, - "wemout=i" => \$weminOUT, - "route" => \$route, - - "surflay=i" => \$surflay, - "rsttime=i" => \$rsttime, - "grpID=s" => \$grpID, - - "constraint=s" => \$constraint, - - "ntasks=i" => \$numtasks, - "walltime=s"=> \$walltime, - "rescale" => \$rescale, - "qos=s" => \$qos, - "partition=s" => \$partition, - "zoom=i" => \$zoom, - "h|help" => \$help ); - # defaults - #--------- - $rsttime = 0 unless $rsttime; - $catchcnFLG = 0 unless $catchcn; - $rescale = 0 unless $rescale; - $weminDFLT = 26; - $weminIN = $weminDFLT unless defined($weminIN); - $weminOUT = $weminDFLT unless defined($weminOUT); - $zoom = 8 unless $zoom; - - usage() if $help; - - # unpack catchcn values - #---------------------- - if ($catchcn) { - $catchcnFLG = 1; - @cnlist = split(/,/, $catchcn); - @cnlen = scalar(@cnlist); - } - - # error if no restart specified - #------------------------------ - die "Error. No restart specified;" - unless $saltwater or $lake or $landice or $catchFLG or $catchcnFLG; - - # rsttime and grpID values are needed for catchcn - #---------------------------------------------- - if ($catchcnFLG) { - die "Error. Must specify rsttime for catchcn;" unless $rsttime; - die "Error. rsttime not in yyyymmddhh format: $rsttime;" - unless $rsttime =~ m/^\d{10}$/; - } - if ($catchFLG or $catchcnFLG) { - unless ($grpID) { - $grpID = `$Bin/getsponsor.pl -d`; - print "Using default grpID = $grpID\n"; - } - unless ($walltime) { $walltime = "1:00:00" } - unless ($numtasks) { $numtasks = 84 } - $qos = "" unless $qos; - $partition = "" unless $partition; - $constraint = "" unless $constraint; - } - - # rsttime value is needed for route - #---------------------------------- - if ($route) { - die "Error. Must specify rsttime for route;" unless $rsttime; - die "Error. Cannot extract yyyymm from rsttime: $rsttime" - unless $rsttime =~ m/^\d{6,}$/; - $yyyymm = $1 if $rsttime =~ /^(\d{6})/; - } -} - -#======================================================================= -# name - write_mk_catch_j -# purpose - write job file to make catch and/or catchcn restart -#======================================================================= -sub write_mk_catch_j { - my ($grouplist, $cwd, $QOSline, $PARTline, $CONSline, $FH); - - $grouplist = ""; - $grouplist = "SBATCH --account=$grpID" if $grpID; - - $cwd = getcwd; - - $QOSline = ""; - if ($qos) { - $QOSline = "SBATCH --qos=$qos"; - if ($qos eq "debug") { - $QOSline = "" unless $numtasks <= 532 and $walltime le "1:00:00"; - } - } - $PARTline = ""; - if ($partition) { - $PARTline = "SBATCH --partition=$partition"; - } - $CONSline = ""; - if ($constraint) { - $CONSline = "SBATCH --constraint=$constraint"; - } - print("\nWriting jobscript: $mk_catch_j\n"); - open CNj, ">> $mk_catch_j" or die "Error opening $mk_catch_j: $!"; - - $FH = select; - select CNj; - - print <<"EOF"; -#!/bin/csh -f -#$grouplist -#SBATCH --ntasks=$numtasks -#SBATCH --time=$walltime -#SBATCH --job-name=catchcnj -#SBATCH --output=$cwd/$mk_catch_log -#$QOSline -#$PARTline -#$CONSline - -source $Bin/g5_modules -set echo - -#limit stacksize unlimited -unlimit - -set catchFLG = $catchFLG -set catchcnFLG = $catchcnFLG -set weminIN = $weminIN -set weminOUT = $weminOUT -set rescaleFLG = $rescale - -set numtasks = $numtasks -set rsttime = $rsttime -set surflay = $surflay -set zoom = $zoom - -set esma_mpirun_X = ( $Bin/esma_mpirun -np \$numtasks ) -set mk_CatchRestarts_X = ( \$esma_mpirun_X $Bin/mk_CatchRestarts ) -set mk_CatchCNRestarts_X = ( \$esma_mpirun_X $Bin/mk_CatchCNRestarts ) -set mk_GEOSldasRestarts_X = ( \$esma_mpirun_X $Bin/mk_GEOSldasRestarts ) -set Scale_Catch_X = $Bin/Scale_Catch -set Scale_CatchCN_X = $Bin/Scale_CatchCN - -set OUT_til = OutData/\*.til -set IN_til = InData/\*.til - -if (\$catchFLG) then - set catchIN = InData/\*catch_internal_rst\* - set params = ( \$OUT_til \$IN_til \$catchIN \$surflay ) - \$mk_CatchRestarts_X \$params - - if (\$rescaleFLG) then - set catch_regrid = OutData/\$catchIN:t - set catch_scaled = \${catch_regrid}.scaled - set params = ( \$catchIN \$catch_regrid \$catch_scaled \$surflay ) - set params = ( \$params \$weminIN \$weminOUT ) - \$Scale_Catch_X \$params - - mv \$catch_regrid \${catch_regrid}.1 - mv \$catch_scaled \$catch_regrid - endif -endif - -if (\$catchcnFLG) then - if ($cnlen[0] == 1) then - set catchcnIN = InData/\*catchcn_internal_rst\* - set params = ( \$OUT_til \$IN_til \$catchcnIN \$surflay \$rsttime ) - \$mk_CatchCNRestarts_X \$params - endif - if ($cnlen[0] == 4) then - set OUT_til = `ls OutData/\*.til | cut -d '/' -f2` - /bin/cp OutData/\*.til OutData/OutTileFile - /bin/cp OutData/\*.til InData/OutTileFile - set CN_VERSION = $cnlist[0] - set RESTART_ID = $cnlist[1] - set RESTART_PATH = $cnlist[2] - set RESTART_DOMAIN = $cnlist[3] - set RESTART_short = \${RESTART_PATH}/\${RESTART_ID}/output/\${RESTART_DOMAIN}/ - set YYYY = `echo \${rsttime} | cut -c1-4` - set MM = `echo \${rsttime} | cut -c5-6` - set PARAM_FILE = `ls \$RESTART_short/rc_out/Y\${YYYY}/M\${MM}/*ldas_catparam* | head -1` - set params = ( -b OutData/ -d \$rsttime -e \$RESTART_ID -m catchcn\$CN_VERSION -s \$surflay -j Y -r R -p \$PARAM_FILE -l \$RESTART_short) - \$mk_GEOSldasRestarts_X \$params - endif - if (\$rescaleFLG) then - set catchcnIN = InData/catchcn\${CN_VERSION}_internal_rst\* - set catchcn_regrid = OutData/\$catchcnIN:t - set catchcn_scaled = \${catchcn_regrid}.scaled - set params = ( \$catchcnIN \$catchcn_regrid \$catchcn_scaled \$surflay ) - set params = ( \$params \$weminIN \$weminOUT ) - \$Scale_CatchCN_X \$params - - mv \$catchcn_regrid \${catchcn_regrid}.1 - mv \$catchcn_scaled \$catchcn_regrid - endif -endif -exit -EOF -; - close CNj; - select $FH; - chmod 0755, $mk_catch_j if $ENV{"SLURM_JOBID"}; -} - -#======================================================================= -# name - system_ -# purpose - wrapper for perl system command -#======================================================================= -sub system_ { - my $cmd = shift @_; - print "\n$cmd\n"; - die "Error: $!;" if system($cmd); -} - -#======================================================================= -# name - wait_for_pid -# purpose - wait for batch job to finish -# -# input parameter -# => $pid: process ID of batch job to wait for -#======================================================================= -sub wait_for_pid { - my ($pid, $first, %found, $line, $id); - $pid = shift @_; - return unless $pid; - - $first = 1; - while (1) { - %found = (); - #--foreach $line (`qstat | grep $ENV{"USER"}`) { - foreach $line (`squeue | grep $ENV{"USER"}`) { - $line =~ s/^\s+//; - $id = (split /\s+/, $line)[0]; - $found{$id} = 1; - } - last unless $found{$pid}; - print "\nWaiting for job $pid to finish\n" if $first; - $first = 0; - sleep 10; - } - print "Job $pid is DONE\n\n" unless $first; -} - -#======================================================================= -# name - usage -# purpose - print usage information -#======================================================================= -sub usage { - use File::Basename ("basename"); - my $name = basename $0; - print <<"EOF"; - -usage $name [-saltwater] [-lake] [-landice] [-catch] [-h] - -option flags - -saltwater regrid saltwater internal restart - -lake regrid lake internal restart - -landice regrid landice internal restart - -catch regrid catchment internal restart - -catchcn regrid catchment CN internal restart - -wemin weminIN minimum snow water equivalent threshold for input catch/cn [$weminDFLT] - -wemout weminOUT minimum snow water equivalent threshold for output catch/cn [$weminDFLT] - -route create the route internal restart - -surflay n thickness [mm] of surface soil moisture layer (catch & catchcn) - Ganymed-3 and earlier: SURFLAY=20 - Ganymed-4 and later : SURFLAY=50 - -rsttime n10 restart time in format, yyyymmddhh (catchcn) or yyyymm (route) - -grpID grpID group ID for batch submittal (catchcn) - -ntasks nt number of tasks to assign to catchcn batch job [112] - -walltime wt walltime in format \"hh:mm:ss\" for catchcn batch job [1:00:00] - -rescale - -qos val use \"SBATCH --qos=val directive\" for batch jobs; - \"-qos debug\" will not work unless these conditions are met - -> numtasks <= 532 - -> walltime le \"1:00:00\" - -partition val use \"SBATCH --partition=val directive\" for batch jobs - -zoom n zoom value to send to land regridding codes [8] - -h print usage information - -EOF -exit; -} diff --git a/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/obsolete/catchplt b/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/obsolete/catchplt deleted file mode 100755 index dd2d3fc40..000000000 --- a/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/obsolete/catchplt +++ /dev/null @@ -1,25 +0,0 @@ -n = 1 -while ( n < 64 ) - -m = n -if( m < 10 ) ; m = 0n ; endif - -'set dfile 1' -'setx' -'set y 1' -'set z 1' -'set cmark 0' -'d var'm'.1' - -'set dfile 2' -'setx' -'set y 1' -'set z 1' -'set cmark 0' -'d var'm'.2' - -'draw title Var: 'm -pull flag -'c' -n = n + 1 -endwhile diff --git a/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/obsolete/check_land_restarts.pro b/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/obsolete/check_land_restarts.pro deleted file mode 100755 index 54afd3705..000000000 --- a/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/obsolete/check_land_restarts.pro +++ /dev/null @@ -1,1167 +0,0 @@ -; ========================================================================= -; USAGE : -; Edit lines to 44-47 specify paths to BCs dir and yjecatch{cn}_internal_rst file -; ========================================================================= -;_____________________________________________________________________ -;_____________________________________________________________________ - -FUNCTION NCDF_ISNCDF, FILENAME - -;- Set return values - -false = 0B -true = 1B - -;- Establish error handler - -catch, error_status -if error_status ne 0 then begin - catch, /cancel - return, false -endif - -;- Try opening the file - -cdfid = ncdf_open( filename ) - -;- If we get this far, open must have worked - -ncdf_close, cdfid -catch, /cancel -return, true - -END - -;_____________________________________________________________________ -;_____________________________________________________________________ - -pro plot_rst - -; ********************************************************************************************************** -; STEP (1) Specify below: -; ----------------------- - -BCSDIR = '/discover/nobackup/smahanam/bcs/Heracles-4_3/Heracles-4_3_MERRA-3/CF0180x6C_DE1440xPE0720/' -GFILE = 'CF0180x6C_DE1440xPE0720-Pfafstetter' -OutDir = 'OutData2/' -int_rst = 'catchcn_internal_rst' - -; STEP (2) save : -; --------------- -; On dali : (a) module load tool/idl-8.5, (b) idl (c) .compile chk_restarts -; and (d) plot_rst - -; ********************************************************************************************************** - -; Setting up and select variables for plotting -; -------------------------------------------- - -TILFILE = BCSDIR + 'til/' + GFILE + '.til' -RSTFILE = BCSDIR + 'rst/' + GFILE + '.rst' - -NTILES = 0l -NG = 0l -NC = 0l -NR = 0l - -openr,1,BCSDIR + 'clsm/catchment.def' -readf,1,NTILES -close,1 - -openr,1,TILFILE -readf,1,NG,NC,NR -close,1 - -Var_Names = [ $ - 'CDCR2' , $ ; 0 - 'BEE' , $ ; 1 - 'POROS' , $ ; 2 - 'ITY1' , $ ; 3 - 'ITY2' , $ ; 4 - 'ITY3' , $ ; 5 - 'ITY4' , $ ; 6 - 'TC1' , $ ; 7 - 'TC2' , $ ; 8 - 'TC3' , $ ; 9 - 'TC4' , $ ;10 - 'CATDEF' , $ ;11 - 'RZEXC' , $ ;12 - 'SFEXC' ] - -N_VARS = N_ELEMENTS (Var_Names) -PLOT_VARS = fltarr (NTILES,N_VARS) -TMP_VAR1 = fltarr (NTILES) -TMP_VAR2 = fltarr (NTILES,4) - - -; Get file information : (1) model, (2) file format -; ------------------------------------------------- - -catch_model = boolean (strcmp(int_rst,'catchcn',7,/fold_case) eq 0) -ncdf_file = boolean (ncdf_isncdf(OutDir + int_rst)) - -; Set up vector to grid for plotting -; ---------------------------------- - -NC_plot = 4320 -NR_plot = 2160 - -tileid_plot = lonarr (NC_plot,NR_plot) - -dx = NC/NC_plot -dy = NR/NR_plot - -catrow = lonarr(nc) -cat = lonarr(nc,dy) - -openr,1,RSTFILE,/F77_UNFORMATTED - -for j = 0l, NR_plot -1 do begin - - for i=0,dy -1 do begin - readu,1,catrow - cat (*,i) = catrow - endfor - - for i = 0, NC_plot -1 do begin - subset = cat (i*dx: (i+1)*dx -1,*) - if (min (subset) le NTILES) then begin - min1 = min(subset) - subset(where (subset gt NTILES)) = 0 - hh = histogram(subset,bin=1,min = min1, locations=loc_val) - dom_tile = max(hh,loc) - tileid_plot[i,j] = loc_val(loc) - endif - endfor - -endfor - -close,1 - -; Reading catch*_internal_rst -; --------------------------- - -if (ncdf_file) then begin - - ncid = NCDF_OPEN(OutDir + int_rst,/NOWRITE) - result = ncdf_inquire( ncid) - if(result.nvars gt 60) then catch_model = boolean (result.nvars lt 60) - NCDF_VARGET, ncid,'CDCR2' ,TMP_VAR1 - PLOT_VARS (*,0) = TMP_VAR1 - NCDF_VARGET, ncid,'BEE' ,TMP_VAR1 - PLOT_VARS (*,1) = TMP_VAR1 - NCDF_VARGET, ncid,'POROS' ,TMP_VAR1 - PLOT_VARS (*,2) = TMP_VAR1 - NCDF_VARGET, ncid,'TC' ,TMP_VAR2 - PLOT_VARS (*,7) = TMP_VAR2(*,0) - PLOT_VARS (*,8) = TMP_VAR2(*,1) - PLOT_VARS (*,9) = TMP_VAR2(*,2) - PLOT_VARS (*,10)= TMP_VAR2(*,3) - NCDF_VARGET, ncid,'CATDEF' ,TMP_VAR1 - PLOT_VARS (*,11) = TMP_VAR1 - NCDF_VARGET, ncid,'RZEXC' ,TMP_VAR1 - PLOT_VARS (*,12) = TMP_VAR1 - NCDF_VARGET, ncid,'SRFEXC' ,TMP_VAR1 - PLOT_VARS (*,13) = TMP_VAR1 - - if(catch_model) then begin - - NCDF_VARGET, ncid,'OLD_ITY' ,TMP_VAR1 - PLOT_VARS (*,3) = TMP_VAR1 - - endif else begin - - NCDF_VARGET, ncid,'ITY' ,TMP_VAR2 - PLOT_VARS (*,3) = TMP_VAR2(*,0) - PLOT_VARS (*,4) = TMP_VAR2(*,1) - PLOT_VARS (*,5) = TMP_VAR2(*,2) - PLOT_VARS (*,6) = TMP_VAR2(*,3) - - endelse - - NCDF_CLOSE, ncid - -endif else begin - - openr,1,OutDir + int_rst, /F77_UNFORMATTED - - if(catch_model) then begin - - for i = 1,30 do begin - readu,1,TMP_VAR1 - if (i eq 6) then PLOT_VARS (*,0) = TMP_VAR1 - if (i eq 8) then PLOT_VARS (*,1) = TMP_VAR1 - if (i eq 9) then PLOT_VARS (*,2) = TMP_VAR1 - if (i eq 30) then PLOT_VARS (*,3) = TMP_VAR1 - endfor - - readu,1,TMP_VAR2 - PLOT_VARS (*,7) = TMP_VAR2(*,0) - PLOT_VARS (*,8) = TMP_VAR2(*,1) - PLOT_VARS (*,9) = TMP_VAR2(*,2) - PLOT_VARS (*,10)= TMP_VAR2(*,3) - - readu,1,TMP_VAR2 - readu,1,TMP_VAR1 - readu,1,TMP_VAR1 - PLOT_VARS (*,11) = TMP_VAR1 - readu,1,TMP_VAR1 - PLOT_VARS (*,12) = TMP_VAR1 - readu,1,TMP_VAR1 - PLOT_VARS (*,13) = TMP_VAR1 - - endif else begin - - for i = 1,37 do begin - readu,1,TMP_VAR1 - if (i eq 6) then PLOT_VARS (*,0) = TMP_VAR1 - if (i eq 8) then PLOT_VARS (*,1) = TMP_VAR1 - if (i eq 9) then PLOT_VARS (*,2) = TMP_VAR1 - if (i eq 30) then PLOT_VARS (*,3) = TMP_VAR1 - if (i eq 31) then PLOT_VARS (*,4) = TMP_VAR1 - if (i eq 32) then PLOT_VARS (*,5) = TMP_VAR1 - if (i eq 33) then PLOT_VARS (*,6) = TMP_VAR1 - endfor - readu,1,TMP_VAR2 - PLOT_VARS (*,7) = TMP_VAR2(*,0) - PLOT_VARS (*,8) = TMP_VAR2(*,1) - PLOT_VARS (*,9) = TMP_VAR2(*,2) - PLOT_VARS (*,10)= TMP_VAR2(*,3) - - readu,1,TMP_VAR2 - readu,1,TMP_VAR2 - readu,1,TMP_VAR1 - readu,1,TMP_VAR1 - PLOT_VARS (*,11) = TMP_VAR1 - readu,1,TMP_VAR1 - PLOT_VARS (*,12) = TMP_VAR1 - readu,1,TMP_VAR1 - PLOT_VARS (*,13) = TMP_VAR1 - - endelse - - close,1 - -endelse - -; Plotting -; -------- - -spawn, 'mkdir -p ' + OutDir + 'plots' -load_colors - -thisDevice = !D.Name -set_plot,'Z' -Device, Set_Resolution=[720,800], Z_Buffer=0 -Erase,255 -!p.background = 255 - -!P.position=0 -!P.Multi = [0, 2, 3, 0, 0] - -plot_6maps, ntiles, tileid_plot, PLOT_VARS(*,0), [min(PLOT_VARS(*,0)), max(PLOT_VARS(*,0))] , Var_Names (0) -plot_6maps, ntiles, tileid_plot, PLOT_VARS(*,1), [min(PLOT_VARS(*,1)), max(PLOT_VARS(*,1))] , Var_Names (1),advance =1 -plot_6maps, ntiles, tileid_plot, PLOT_VARS(*,2), [0.37,0.8] , Var_Names (2),advance =1 -plot_6maps, ntiles, tileid_plot, PLOT_VARS(*,11),[min(PLOT_VARS(*,11)), max(PLOT_VARS(*,11))], Var_Names (11),advance =1 -plot_6maps, ntiles, tileid_plot, PLOT_VARS(*,12),[min(PLOT_VARS(*,12)), max(PLOT_VARS(*,12))], Var_Names (12),advance =1 -plot_6maps, ntiles, tileid_plot, PLOT_VARS(*,13),[min(PLOT_VARS(*,13)), max(PLOT_VARS(*,13))], Var_Names (13),advance =1 - -snapshot = TVRD() -TVLCT, r, g, b, /Get -Device, Z_Buffer=1 -Set_Plot, thisDevice -image24 = BytArr(3, 720, 800) -image24[0,*,*] = r[snapshot] -image24[1,*,*] = g[snapshot] -image24[2,*,*] = b[snapshot] -Write_JPEG, OutDir + 'plots/soil_var.jpg', image24, True=1, Quality=100 - -plot_tc, NTILES, tileid_plot,OutDir + 'plots/', plot_vars (*,7), plot_vars (*,8), plot_vars (*,9), plot_vars (*,10) - -if(catch_model) then begin - plot_mosaic, ntiles, OutDir + 'plots/', tileid_plot, fix(plot_vars (*,3)) -endif else begin - plot_carbon, ntiles, OutDir + 'plots/', tileid_plot, fix(plot_vars (*,3:6)) -endelse - -end - -;_____________________________________________________________________ -;_____________________________________________________________________ - -pro check_regrid_carbon - -; ********************************************************************************************************** -; STEP (1) Specify below: -; ----------------------- - -BCSDIR1 = '/discover/nobackup/smahanam/bcs/Heracles-4_3/Heracles-4_3_MERRA-3/SMAP_EASEv2_M09/' -GFILE1 = 'SMAP_EASEv2_M09_3856x1624' -OutDir1 = '/discover/nobackup/projects/gmao/ssd/land/l_data/LandRestarts_for_Regridding/CatchCN/M09/20151231/' -int_rst1 = 'catchcn_internal_rst' - -BCSDIR2 = '/discover/nobackup/smahanam/bcs/Heracles-4_3/Heracles-4_3_MERRA-3/CF0180x6C_DE1440xPE0720/' -GFILE2 = 'CF0180x6C_DE1440xPE0720-Pfafstetter' -OutDir2 = '' -int_rst2 = 'catchcn_internal_rst' - -; STEP (2) save : -; --------------- -; On dali : (a) module load tool/idl-8.5, (b) idl (c) .compile chk_restarts -; and (d) plot_rst - -; ********************************************************************************************************** - -; Setting up and select variables for plotting -; -------------------------------------------- -Var_Names = [ $ - 'CDCR2' , $ ; 0 - 'BEE' , $ ; 1 - 'POROS' , $ ; 2 - 'ITY1' , $ ; 3 - 'ITY2' , $ ; 4 - 'ITY3' , $ ; 5 - 'ITY4' , $ ; 6 - 'TC1' , $ ; 7 - 'TC2' , $ ; 8 - 'TC3' , $ ; 9 - 'TC4' , $ ;10 - 'CATDEF' , $ ;11 - 'RZEXC' , $ ;12 - 'SFEXC' ] -NC_plot = 4320 -NR_plot = 2160 - -;goto, jump - -for resol = 1,2 do begin - -if(resol eq 1) then begin - BCSDIR = BCSDIR1 - TILFILE = BCSDIR1 + 'til/' + GFILE1 + '.til' - RSTFILE = BCSDIR1 + 'rst/' + GFILE1 + '.rst' -endif else begin - BCSDIR = BCSDIR2 - TILFILE = BCSDIR2 + 'til/' + GFILE2 + '.til' - RSTFILE = BCSDIR2 + 'rst/' + GFILE2 + '.rst' -endelse - - -NTILES = 0l -NG = 0l -NC = 0l -NR = 0l - -openr,1,BCSDIR + 'clsm/catchment.def' -readf,1,NTILES -close,1 - -openr,1,TILFILE -readf,1,NG,NC,NR -close,1 -; Set up vector to grid for plotting -; ---------------------------------- - - - -tileid_plot = lonarr (NC_plot,NR_plot) - -dx = NC/NC_plot -dy = NR/NR_plot - -catrow = lonarr(nc) -cat = lonarr(nc,dy) - -openr,1,RSTFILE,/F77_UNFORMATTED - -for j = 0l, NR_plot -1 do begin - - for i=0,dy -1 do begin - readu,1,catrow - cat (*,i) = catrow - endfor - - for i = 0, NC_plot -1 do begin - subset = cat (i*dx: (i+1)*dx -1,*) - if (min (subset) le NTILES) then begin - min1 = min(subset) - subset(where (subset gt NTILES)) = 0 - hh = histogram(subset,bin=1,min = min1, locations=loc_val) - dom_tile = max(hh,loc) - tileid_plot[i,j] = loc_val(loc) - endif - endfor - -endfor - -close,1 -if (resol eq 1) then begin - tileid_plot1 = tileid_plot - NTILES1 = NTILES -endif else begin - tileid_plot2 = tileid_plot - NTILES2 = NTILES -endelse -endfor - -cnpft1 = fltarr (ntiles1, 888) -cnpft2 = fltarr (ntiles2, 888) -fvg1 = fltarr (ntiles1, 4) -fvg2 = fltarr (ntiles2, 4) -ncid = NCDF_OPEN(OutDir1 + int_rst1,/NOWRITE) -NCDF_VARGET, ncid,'TILE_ID' ,TILE_ID -NCDF_VARGET, ncid,'CNPFT' ,CNPFT1 -NCDF_VARGET, ncid,'FVG' ,fvg1 -TILE_ID = long (TILE_ID) - 1l - -CNPFT=CNPFT1 -FVG =FVG1 - -for k =0l,n_elements (CNPFT1(*,0)) -1l do CNPFT1(TILE_ID(k),*) = CNPFT(k,*) -for k =0l,n_elements (FVG1 (*,0)) -1l do FVG1 (TILE_ID(k),*) = FVG (k,*) - -CNPFT=0. -FVG =0. -NCDF_CLOSE, ncid - -ncid = NCDF_OPEN(OutDir2 + int_rst2,/NOWRITE) -NCDF_VARGET, ncid,'CNPFT' ,CNPFT2 -NCDF_VARGET, ncid,'FVG' ,fvg2 -NCDF_CLOSE, ncid -save,NTILES1,NTILES2,tileid_plot1,tileid_plot2,CNPFT1,CNPFT2, fvg1, fvg2,file = 'temp_file.idl' -;stop - -jump: - -restore,'temp_file.idl' - -; Plotting -; -------- - -spawn, 'mkdir -p plots' -load_colors -limits = [-60,-180,90,180] - -plot_varid = 14 -cnpft1 = reform ( cnpft1,[ntiles1,3,4,74],/overwrite) -cnpft2 = reform ( cnpft2,[ntiles2,3,4,74],/overwrite) - -for iv = 1,4 do begin - -plot_vars1 = cnpft1(*,0,iv - 1,plot_varid-1) -plot_vars2 = cnpft2(*,0,iv - 1,plot_varid-1) - - -thisDevice = !D.Name -set_plot,'Z' -Device, Set_Resolution=[720,1000], Z_Buffer=0 -Erase,255 -!p.background = 255 - -!P.position=0 -!P.Multi = [0, 1, 2, 0, 1] - -plot_2maps, ntiles1, tileid_plot1, plot_vars1(*), [min([PLOT_VARS1,plot_vars2],/nan),max([PLOT_VARS1,plot_vars2],/nan)], string(plot_varid,'(i2.2)')+'_v' + string(iv,'(i1.1)') -plot_2maps, ntiles2, tileid_plot2, plot_vars2(*), [min([PLOT_VARS1,plot_vars2],/nan),max([PLOT_VARS1,plot_vars2],/nan)], string(plot_varid,'(i2.2)')+'_v' + string(iv,'(i1.1)'),advance =1 - -snapshot = TVRD() -TVLCT, r, g, b, /Get -Device, Z_Buffer=1 -Set_Plot, thisDevice -image24 = BytArr(3, 720, 1000) -image24[0,*,*] = r[snapshot] -image24[1,*,*] = g[snapshot] -image24[2,*,*] = b[snapshot] -Write_JPEG, 'plots/pft_'+ string(plot_varid,'(i2.2)')+'_v' + string(iv,'(i1.1)') +'.jpg', image24, True=1, Quality=100 -endfor -fvg1(where (fvg1 le 1.e-4)) = !VALUES.F_NAN -fvg2(where (fvg2 le 1.e-4)) = !VALUES.F_NAN - -plot_fr, NTILES1, tileid_plot1,'plots/offl_', fvg1 (*,0), fvg1 (*,1), fvg1 (*,2), fvg1 (*,3) - -plot_fr, NTILES2, tileid_plot2,'plots/agcm_', fvg2 (*,0), fvg2 (*,1), fvg2 (*,2), fvg2 (*,3) - -end -;_____________________________________________________________________ -;_____________________________________________________________________ - -PRO plot_2maps, ncat, tile_id, data, vlim, vname,advance = advance - -lwval = vlim(0) -upval = vlim(1) - -im = n_elements(tile_id[*,0]) -jm = n_elements(tile_id[0,*]) - -dx = 360. / im -dy = 180. / jm - -x = indgen(im)*dx -180. + dx/2. -y = indgen(jm)*dy -90. + dy/2. - -data_grid = fltarr (im,jm) -data_grid (*,*) = !VALUES.F_NAN - -for j = 0l, jm -1l do begin - for i = 0l, im -1 do begin - if(tile_id[i,j] gt 0) then data_grid(i,j) = data(tile_id[i,j] -1) - endfor -endfor - -limits = [-60,-180,90,180] - -colors = [27,26,25,24,23,22,21,20,40,41,42,43,44,45,46,47,48] -n_levels = n_elements (colors) - -levels = [lwval,lwval+(upval-lwval)/(n_levels -1) +indgen(n_levels -1)*(upval-lwval)/(n_levels -1)] - -if keyword_set (advance) then begin - -MAP_SET,/CYLINDRICAL,/hires,color= 0,/NoErase,limit=limits,/ADVANCE,/ISOTROPIC,/NOBORDER, title =vname -endif else begin -MAP_SET,/CYLINDRICAL,/hires,color= 0,/NoErase,limit=limits,/ISOTROPIC,/NOBORDER, title =vname -endelse - -contour, data_grid,x,y,levels = levels,c_colors=colors,/cell_fill,/overplot - -levels_x = levels - -alpha=fltarr(n_levels,2) -alpha(*,0)=levels -alpha(*,1)=levels -h=[0,1] - -dx = (240.)/(n_levels-1) - -clev = levels -clev (*) = 1 -n=0 -k = 0 -fmt_string = '(f7.2)' -!P.position=[0.30, 0.0+0.005, 0.70, 0.015+0.005] - -contour,alpha,levels_x,h,levels=levels,c_colors=colors,/fill,/xstyle,/ystyle, $ - /noerase,yticks=1,ytickname=[' ',' '] ,xrange=[min(levels),max(levels)], $ - xtitle=' ', color=0,xtickv=levels, $ - C_charsize=1.0, charsize=0.5 ,xtickformat = "(A1)" -contour,alpha,levels_x,h,levels=levels,color=0,/overplot,c_label=clev - for k = 0,n_elements(colors) -1 do xyouts,levels_x[k],1.1,string(levels[k],format=fmt_string) ,orientation=90,color=0,charsize =0.8 - -!P.position=0 - -END - -;_____________________________________________________________________ -;_____________________________________________________________________ - -pro plot_fr, ncat, tile_id,out_path, VISDR, VISDF, NIRDR, NIRDF - -load_colors -thisDevice = !D.Name -set_plot,'Z' -Device, Set_Resolution=[720,500], Z_Buffer=0 -Erase,255 -!p.background = 255 - -!P.position=0 -!P.Multi = [0, 2, 2, 0, 0] -limits = [-60,-180,90,180] - -lwval = 0. -upval = 1. - -im = n_elements(tile_id[*,0]) -jm = n_elements(tile_id[0,*]) - -dx = 360. / im -dy = 180. / jm - -x = indgen(im)*dx -180. + dx/2. -y = indgen(jm)*dy -90. + dy/2. - -colors = [27,26,25,24,23,22,21,20,40,41,42,43,44,45,46,47,48] -n_levels = n_elements (colors) - -for map = 1,4 do begin - - if (map eq 1) then data = VISDR - if (map eq 2) then data = VISDF - if (map eq 3) then data = NIRDR - if (map eq 4) then data = NIRDF - - if (map eq 1) then ctitle = 'PF1' - if (map eq 2) then ctitle = 'PF2' - if (map eq 3) then ctitle = 'SF1' - if (map eq 4) then ctitle = 'SF2' - - levels = [lwval,lwval+(upval-lwval)/(n_levels -1) +indgen(n_levels -1)*(upval-lwval)/(n_levels -1)] - - data_grid = fltarr (im,jm) - data_grid (*,*) = !VALUES.F_NAN - - for j = 0l, jm -1l do begin - for i = 0l, im -1 do begin - if(tile_id[i,j] gt 0) then data_grid(i,j) = data(tile_id[i,j] -1) - endfor - endfor - - if(map eq 1) then begin - MAP_SET,/CYLINDRICAL,/hires,color= 0,/NoErase,limit=limits,/ISOTROPIC,/NOBORDER, title = ctitle - endif else begin - MAP_SET,/CYLINDRICAL,/hires,color= 0,/NoErase,limit=limits,/ADVANCE,/ISOTROPIC,/NOBORDER, title = ctitle - endelse - - contour, data_grid,x,y,levels = levels,c_colors=colors,/cell_fill,/overplot - if(map eq 3) then begin - !P.position=[0.25, 0.05, 0.75, 0.075] - - alpha=fltarr(n_levels,2) - alpha(*,0)=levels - alpha(*,1)=levels - h=[0,1] - clev = levels - clev (*) = 1 - n=0 - k = 0 - fmt_string = '(f6.2)' - contour,alpha,levels,h,levels=levels,c_colors=colors,/fill,/xstyle,/ystyle, $ - /noerase,yticks=1,ytickname=[' ',' '] ,xrange=[min(levels),max(levels)], $ - xtitle=' ', color=0,xtickv=levels, $ - C_charsize=1.0, charsize=0.5 ,xtickformat = "(A1)" - contour,alpha,levels,h,levels=levels,color=0,/overplot,c_label=clev - for k = 0,n_elements(colors) -1 do xyouts,levels[k],1.1,string(levels[k],format=fmt_string) ,orientation=90,color=0,charsize =0.8 - !P.position=0 - endif -endfor - -snapshot = TVRD() -TVLCT, r, g, b, /Get -Device, Z_Buffer=1 -Set_Plot, thisDevice -image24 = BytArr(3, 720, 500) -image24[0,*,*] = r[snapshot] -image24[1,*,*] = g[snapshot] -image24[2,*,*] = b[snapshot] -Write_JPEG, out_path +'FR.jpg', image24, True=1, Quality=100 - -end - -;_____________________________________________________________________ -;_____________________________________________________________________ - -pro load_colors - -R = intarr (256) -G = intarr (256) -B = intarr (256) - -R (*) = 255 -G (*) = 255 -B (*) = 255 - -r_drought = [0, 0, 0, 0, 47, 200, 255, 255, 255, 255, 249, 197] -g_drought = [0, 115, 159, 210, 255, 255, 255, 255, 219, 157, 0, 0] -b_drought = [0, 0, 0, 0, 67, 130, 255, 0, 0, 0, 0, 0] - -colors = indgen (11) + 1 -R (0:11) = r_drought -G (0:11) = g_drought -B (0:11) = b_drought - -r_green = [200, 150, 47, 60, 0, 0, 0, 0] -g_green = [255, 255, 255, 230, 219, 187, 159, 131] -b_green = [200, 150, 67, 15, 0, 0, 0, 0] - -r_blue = [ 55, 0, 0, 0, 0, 0, 0, 0, 0, 0] -g_blue = [255, 255, 227, 195, 167, 115, 83, 0, 0, 0] -b_blue = [199, 255, 255, 255, 255, 255, 255, 255, 200, 130] - -r_red = [255, 240, 255, 255, 255, 255, 255, 233, 197] -g_red = [255, 255, 219, 187, 159, 131, 51, 23, 0] -b_red = [153, 15, 0, 0, 0, 0, 0, 0, 0] - -r_grey = [245, 225, 205, 185, 165, 145, 125, 105, 85] -g_grey = [245, 225, 205, 185, 165, 145, 125, 105, 85] -b_grey = [245, 225, 205, 185, 165, 145, 125, 105, 85] - -r_type = [255,106,202,251, 0, 29, 77,109,142,233,255,255,255,127,164,164,217,217,204,104, 0] -g_type = [245, 91,178,154, 85,115,145,165,185, 23,131,131,191, 39, 53, 53, 72, 72,204,104, 70] -b_type = [215,154,214,153, 0, 0, 0, 0, 13, 0, 0,200, 0, 4, 3,200, 1,200,204,200,200] - -R (20:27) = r_green -G (20:27) = g_green -B (20:27) = b_green - -R (30:39) = r_blue -G (30:39) = g_blue -B (30:39) = b_blue - -R (40:48) = r_red -G (40:48) = g_red -B (40:48) = b_red - -R (50:58) = r_grey -G (50:58) = g_grey -B (50:58) = b_grey - -R (60:80) = r_type -G (60:80) = g_type -B (60:80) = b_type - -TVLCT,R ,G ,B - -end - -;_____________________________________________________________________ -;_____________________________________________________________________ - -PRO plot_6maps, ncat, tile_id, data, vlim, vname,advance = advance - -lwval = vlim(0) -upval = vlim(1) -if (vname eq 'SOILDEPTH') then upval = 5000. - -im = n_elements(tile_id[*,0]) -jm = n_elements(tile_id[0,*]) - -dx = 360. / im -dy = 180. / jm - -x = indgen(im)*dx -180. + dx/2. -y = indgen(jm)*dy -90. + dy/2. - -data_grid = fltarr (im,jm) -data_grid (*,*) = !VALUES.F_NAN - -for j = 0l, jm -1l do begin - for i = 0l, im -1 do begin - if(tile_id[i,j] gt 0) then data_grid(i,j) = data(tile_id[i,j] -1) - endfor -endfor - -limits = [-60,-180,90,180] -if file_test ('limits.idl') then restore,'limits.idl' - -colors = [27,26,25,24,23,22,21,20,40,41,42,43,44,45,46,47,48] -n_levels = n_elements (colors) - -levels = [lwval,lwval+(upval-lwval)/(n_levels -1) +indgen(n_levels -1)*(upval-lwval)/(n_levels -1)] - -if(vname eq 'POROS') then $ -levels = [lwval,lwval+(0.57-lwval)/(n_levels -2) +indgen(n_levels -2)*(0.57-lwval)/(n_levels -2),upval] - -if keyword_set (advance) then begin - -MAP_SET,/CYLINDRICAL,/hires,color= 0,/NoErase,limit=limits,/ADVANCE,/ISOTROPIC,/NOBORDER, title =vname -endif else begin -MAP_SET,/CYLINDRICAL,/hires,color= 0,/NoErase,limit=limits,/ISOTROPIC,/NOBORDER, title =vname -endelse - -contour, data_grid,x,y,levels = levels,c_colors=colors,/cell_fill,/overplot - -levels_x = levels - -if(vname eq 'POROS') then begin -dxp = (0.8-0.37)/16. -levels_x = indgen(17)*dxp+ 0.37 -endif - -alpha=fltarr(n_levels,2) -alpha(*,0)=levels -alpha(*,1)=levels -h=[0,1] - -dx = (240.)/(n_levels-1) - -clev = levels -clev (*) = 1 -n=0 -k = 0 -fmt_string = '(f7.2)' - -if(vname eq 'CDCR2' ) then !P.position=[0.064, 0.675, 0.41, 0.69] -if(vname eq 'BEE' ) then !P.position=[0.58, 0.675, 0.92, 0.69] -if(vname eq 'POROS' ) then !P.position=[0.064, 0.345, 0.41, 0.36] -if(vname eq 'CATDEF') then !P.position=[0.58, 0.345, 0.92, 0.36] -if(vname eq 'RZEXC' ) then !P.position=[0.064, 0.015, 0.41, 0.03] -if(vname eq 'SFEXC' ) then !P.position=[0.58, 0.015, 0.92, 0.03] - -;!P.position=[0.064, 0.675, 0.41, 0.69] -;!P.position=[0.58, 0.0+0.005, 0.92, 0.015+0.005] - -contour,alpha,levels_x,h,levels=levels,c_colors=colors,/fill,/xstyle,/ystyle, $ - /noerase,yticks=1,ytickname=[' ',' '] ,xrange=[min(levels),max(levels)], $ - xtitle=' ', color=0,xtickv=levels, $ - C_charsize=1.0, charsize=0.5 ,xtickformat = "(A1)" -contour,alpha,levels_x,h,levels=levels,color=0,/overplot,c_label=clev - for k = 0,n_elements(colors) -1 do xyouts,levels_x[k],1.1,string(levels[k],format=fmt_string) ,orientation=90,color=0,charsize =0.8 - -;for l = 0,n_levels -2 do begin -; k = l -; xbox = [-120. + k*dx,-120. + k*dx, -120. + (k+1)*dx, -120. + (k+1)*dx,-120. + k*dx] -; ybox = [-65., -55.,-55.,-65.,-65.] -; polyfill, xbox,ybox,color=colors [k] -; -; xyouts,xbox[1],ybox[2]+0.05,string(levels[l],format=fmt_string),color =0, orientation =90,charsize =0.8 -; k = k + 1 -;endfor -; -;l = n_levels -1 -;xyouts,-120. + l*dx,ybox[2]+0.05,string(levels[l],format=fmt_string),color =0, orientation =90,charsize =0.8 -!P.position=0 - -END -;_____________________________________________________________________ -;_____________________________________________________________________ - -pro plot_tc, ncat, tile_id,out_path, VISDR, VISDF, NIRDR, NIRDF - -load_colors -thisDevice = !D.Name -set_plot,'Z' -Device, Set_Resolution=[720,500], Z_Buffer=0 -Erase,255 -!p.background = 255 - -!P.position=0 -!P.Multi = [0, 2, 2, 0, 0] -limits = [-60,-180,90,180] - -lwval = min ([min(VISDR), min(VISDF), min(NIRDR), min(NIRDF)]) -upval = max ([max(VISDR), max(VISDF), max(NIRDR), max(NIRDF)]) - -im = n_elements(tile_id[*,0]) -jm = n_elements(tile_id[0,*]) - -dx = 360. / im -dy = 180. / jm - -x = indgen(im)*dx -180. + dx/2. -y = indgen(jm)*dy -90. + dy/2. - -colors = [27,26,25,24,23,22,21,20,40,41,42,43,44,45,46,47,48] -n_levels = n_elements (colors) - -for map = 1,4 do begin - - if (map eq 1) then data = VISDR - if (map eq 2) then data = VISDF - if (map eq 3) then data = NIRDR - if (map eq 4) then data = NIRDF - - if (map eq 1) then ctitle = 'TC1' - if (map eq 2) then ctitle = 'TC2' - if (map eq 3) then ctitle = 'TC3' - if (map eq 4) then ctitle = 'TC4' - - levels = [lwval,lwval+(upval-lwval)/(n_levels -1) +indgen(n_levels -1)*(upval-lwval)/(n_levels -1)] - - data_grid = fltarr (im,jm) - data_grid (*,*) = !VALUES.F_NAN - - for j = 0l, jm -1l do begin - for i = 0l, im -1 do begin - if(tile_id[i,j] gt 0) then data_grid(i,j) = data(tile_id[i,j] -1) - endfor - endfor - - if(map eq 1) then begin - MAP_SET,/CYLINDRICAL,/hires,color= 0,/NoErase,limit=limits,/ISOTROPIC,/NOBORDER, title = ctitle - endif else begin - MAP_SET,/CYLINDRICAL,/hires,color= 0,/NoErase,limit=limits,/ADVANCE,/ISOTROPIC,/NOBORDER, title = ctitle - endelse - - contour, data_grid,x,y,levels = levels,c_colors=colors,/cell_fill,/overplot - if(map eq 3) then begin - !P.position=[0.25, 0.05, 0.75, 0.075] - - alpha=fltarr(n_levels,2) - alpha(*,0)=levels - alpha(*,1)=levels - h=[0,1] - clev = levels - clev (*) = 1 - n=0 - k = 0 - fmt_string = '(f6.2)' - contour,alpha,levels,h,levels=levels,c_colors=colors,/fill,/xstyle,/ystyle, $ - /noerase,yticks=1,ytickname=[' ',' '] ,xrange=[min(levels),max(levels)], $ - xtitle=' ', color=0,xtickv=levels, $ - C_charsize=1.0, charsize=0.5 ,xtickformat = "(A1)" - contour,alpha,levels,h,levels=levels,color=0,/overplot,c_label=clev - for k = 0,n_elements(colors) -1 do xyouts,levels[k],1.1,string(levels[k],format=fmt_string) ,orientation=90,color=0,charsize =0.8 - !P.position=0 - endif -endfor - -snapshot = TVRD() -TVLCT, r, g, b, /Get -Device, Z_Buffer=1 -Set_Plot, thisDevice -image24 = BytArr(3, 720, 500) -image24[0,*,*] = r[snapshot] -image24[1,*,*] = g[snapshot] -image24[2,*,*] = b[snapshot] -Write_JPEG, out_path +'TC.jpg', image24, True=1, Quality=100 - -end -; ============================================================================== -; Mosaic classes -; ============================================================================== - -PRO plot_mosaic, ncat, outdir, tile_id, mos_type - -im = n_elements(tile_id[*,0]) -jm = n_elements(tile_id[0,*]) - -dx = 360. / im -dy = 180. / jm - -x = indgen(im)*dx -180. + dx/2. -y = indgen(jm)*dy -90. + dy/2. - -mos_grid = intarr (im,jm) -mos_grid (*,*) = !VALUES.F_NAN - -for j = 0l, jm -1l do begin - for i = 0l, im -1 do begin - if(tile_id[i,j] gt 0) then mos_grid(i,j) = mos_type(tile_id[i,j] -1) - endfor -endfor - -limits = [-60,-180,90,180] -if file_test ('limits.idl') then restore,'limits.idl' - -thisDevice = !D.Name -set_plot,'Z' -Device, Set_Resolution=[700,500], Z_Buffer=0 - -r_in = [233,255,255,255,210, 0, 0, 0,204,170,255,220,205, 0, 0,170, 0, 40,120,140,190,150,255,255, 0, 0, 0,195,255, 0,255, 0] -g_in = [ 23,131,191,255,255,255,155, 0,204,240,255,240,205,100,160,200, 60,100,130,160,150,100,180,235,120,150,220, 20,245, 70,255, 0] -b_in = [ 0, 0, 0,178,255,255,255,200,204,240,100,100,102, 0, 0, 0, 0, 0, 0, 0, 0, 0, 50,175, 90,120,130, 0,215,200,255, 0] -vtypes =[ 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 14, 20, 30, 40, 50, 60, 70, 90,100,110,120,130,140,150,160,170,180,190,200,210,220,230] - -red = intarr (256) -green= intarr (256) -blue = intarr (256) -red (255) = 255 -green(255) = 255 -blue (255) = 255 - -for k = 0, n_elements(vtypes) -1 do begin - red (vtypes(k)) = r_in (k) - green(vtypes(k)) = g_in (k) - blue (vtypes(k)) = b_in (k) -endfor - -TVLCT,red,green,blue - -colors = vtypes -levels = vtypes - -Erase,255 -!p.background = 255 -!P.position=0 -!P.Multi = [0, 1, 1, 0, 1] -MAP_SET,/CYLINDRICAL,/hires,color= 0,/NoErase,limit=limits -contour, mos_grid,x,y,levels = levels,c_colors=colors,/cell_fill,/overplot - -mos_name = strarr(6) -mos_name( 0) = 'BL Evergreen' -mos_name( 1) = 'BL Deciduous' -mos_name( 2) = 'Needleleaf' -mos_name( 3) = 'Grassland' -mos_name( 4) = 'BL Shrubs' -mos_name( 5) = 'Dwarf' - -n_levels = 6;n_elements(vtypes) -alpha=fltarr(n_levels,2) -alpha(*,0)=levels [0:n_levels-1] -alpha(*,1)=levels [0:n_levels-1] -h=[0,1] -!P.position=[0.30, 0.0+0.005, 0.70, 0.015+0.005] -clev = levels -clev (*) = 1 -contour,alpha,levels[0:5],h,levels=levels,c_colors=colors,/fill,/xstyle,/ystyle, $ - /noerase,yticks=1,ytickname=[' ',' '] ,xrange=[1,7], $ - xtitle=' ', color=0,xtickv=levels, $ - C_charsize=1.0, charsize=0.5 ,xtickformat = "(A1)" -contour,alpha,levels[0:5],h,levels=levels,color=0,/overplot,c_label=clev -for k = 0,5 do xyouts,levels[k]+0.5,1.2,mos_name[k] ,orientation=90,color=0 - -snapshot = TVRD() -TVLCT, r, g, b, /Get -Device, Z_Buffer=1 -Set_Plot, thisDevice -image24 = BytArr(3, 700, 500) -image24[0,*,*] = r[snapshot] -image24[1,*,*] = g[snapshot] -image24[2,*,*] = b[snapshot] -Write_JPEG, outdir + '/mosaic_prim.jpg', image24, True=1, Quality=100 - - -END -; ============================================================================== -; CLM-Carbon classes -; ============================================================================== - -PRO plot_carbon,ncat, OutDir, tile_id, clm_type - -im = n_elements(tile_id[*,0]) -jm = n_elements(tile_id[0,*]) - -dx = 360. / im -dy = 180. / jm - -x = indgen(im)*dx -180. + dx/2. -y = indgen(jm)*dy -90. + dy/2. - -clm_grid = intarr (im,jm,4) - -clm_grid (*,*,*) = !VALUES.F_NAN - -for j = 0l, jm -1l do begin - for i = 0l, im -1 do begin - if(tile_id[i,j] gt 0) then begin - clm_grid(i,j,0) = clm_type(tile_id[i,j] -1,0) - clm_grid(i,j,1) = clm_type(tile_id[i,j] -1,1) - clm_grid(i,j,2) = clm_type(tile_id[i,j] -1,2) - clm_grid(i,j,3) = clm_type(tile_id[i,j] -1,3) - endif - endfor -endfor - -clm_type = 0 - -limits = [-60,-180,90,180] -if file_test ('limits.idl') then restore,'limits.idl' - -thisDevice = !D.Name -set_plot,'Z' -Device, Set_Resolution=[700,1000], Z_Buffer=0 -;types= [ 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,11a, 12, 13, 14,14a, 15,15a, 16,16a, 17] -r_in = [106,202,251, 0, 29, 77,109,142,233,255,255,255,127,164,164,217,217,204,104, 0] -g_in = [ 91,178,154, 85,115,145,165,185, 23,131,131,191, 39, 53, 53, 72, 72,204,104, 70] -b_in = [154,214,153, 0, 0, 0, 0, 13, 0, 0,200, 0, 4, 3,200, 1,200,204,200,200] -vtypes= [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] - -red = intarr (256) -green= intarr (256) -blue = intarr (256) - -red (255) = 255 -green(255) = 255 -blue (255) = 255 - -for k = 0, n_elements(vtypes) -1 do begin - red (vtypes(k)) = r_in (k) - green(vtypes(k)) = g_in (k) - blue (vtypes(k)) = b_in (k) -endfor - -TVLCT,red,green,blue - -colors = vtypes -levels = vtypes - -clm_name = strarr(19) -clm_name( 0) = 'NLEt' ; 1 needleleaf evergreen temperate tree -clm_name( 1) = 'NLEB' ; 2 needleleaf evergreen boreal tree -clm_name( 2) = 'NLDB' ; 3 needleleaf deciduous boreal tree -clm_name( 3) = 'BLET' ; 4 broadleaf evergreen tropical tree -clm_name( 4) = 'BLEt' ; 5 broadleaf evergreen temperate tree -clm_name( 5) = 'BLDT' ; 6 broadleaf deciduous tropical tree -clm_name( 6) = 'BLDt' ; 7 broadleaf deciduous temperate tree -clm_name( 7) = 'BLDB' ; 8 broadleaf deciduous boreal tree -clm_name( 8) = 'BLEtS' ; 9 broadleaf evergreen temperate shrub -clm_name( 9) = 'BLDtS' ; 10 broadleaf deciduous temperate shrub [moisture + deciduous] -clm_name(10) = 'BLDtSm'; 11 broadleaf deciduous temperate shrub [moisture stress only] -clm_name(11) = 'BLDBS' ; 12 broadleaf deciduous boreal shrub -clm_name(12) = 'AC3G' ; 13 arctic c3 grass -clm_name(13) = 'CC3G' ; 14 cool c3 grass [moisture + deciduous] -clm_name(14) = 'CC3Gm' ; 15 cool c3 grass [moisture stress only] -clm_name(15) = 'WC4G' ; 16 warm c4 grass [moisture + deciduous] -clm_name(16) = 'WC4Gm' ; 17 warm c4 grass [moisture stress only] -clm_name(17) = 'CROP' ; 18 crop [moisture + deciduous] -clm_name(18) = 'CROPm' ; 19 crop [moisture stress only] - -Erase,255 -!p.background = 255 -!P.position=0 -!P.Multi = [0, 1, 2, 0, 1] - -MAP_SET,/CYLINDRICAL,/hires,color= 0,/NoErase,limit=limits -contour, clm_grid[*,*,0],x,y,levels = levels,c_colors=colors,/cell_fill,/overplot - -MAP_SET,/CYLINDRICAL,/hires,color= 0,/NoErase,limit=limits,/advance -contour, clm_grid[*,*,1],x,y,levels = levels,c_colors=colors,/cell_fill,/overplot - -n_levels = n_elements(vtypes) -alpha=fltarr(n_levels,2) -alpha(*,0)=levels (0:n_levels-1) -alpha(*,1)=levels (0:n_levels-1) -h=[0,1] - -!P.position=[0.30, 0.0+0.005, 0.70, 0.015+0.005] -clev = levels -clev (*) = 1 -contour,alpha,levels,h,levels=levels,c_colors=colors,/fill,/xstyle,/ystyle, $ - /noerase,yticks=1,ytickname=[' ',' '] ,xrange=[min(levels),max(levels)], $ - xtitle=' ', color=0,xtickv=levels, $ - C_charsize=1.0, charsize=0.5 ,xtickformat = "(A1)" -contour,alpha,levels,h,levels=levels,color=0,/overplot,c_label=clev - for k = 0,n_elements(vtypes) -2 do xyouts,levels[k]+0.5,1.1,clm_name(k) ,orientation=90,color=0 -snapshot = TVRD() - -TVLCT, r, g, b, /Get -Device, Z_Buffer=1 -Set_Plot, thisDevice -image24 = BytArr(3, 700, 1000) -image24[0,*,*] = r[snapshot] -image24[1,*,*] = g[snapshot] -image24[2,*,*] = b[snapshot] -Write_JPEG, OutDir + '/CLM-Carbon_PRIM_veg_typs.jpg', image24, True=1, Quality=100 - -; now plotting secondary -thisDevice = !D.Name -set_plot,'Z' -Device, Set_Resolution=[700,1000], Z_Buffer=0 - -Erase,255 -!p.background = 255 -!P.position=0 -!P.Multi = [0, 1, 2, 0, 1] - -MAP_SET,/CYLINDRICAL,/hires,color= 0,/NoErase,limit=limits -contour, clm_grid[*,*,2],x,y,levels = levels,c_colors=colors,/cell_fill,/overplot - -MAP_SET,/CYLINDRICAL,/hires,color= 0,/NoErase,limit=limits,/advance -contour, clm_grid[*,*,3],x,y,levels = levels,c_colors=colors,/cell_fill,/overplot - -n_levels = n_elements(vtypes) -alpha=fltarr(n_levels,2) -alpha(*,0)=levels (0:n_levels-1) -alpha(*,1)=levels (0:n_levels-1) -h=[0,1] - -!P.position=[0.30, 0.0+0.005, 0.70, 0.015+0.005] -clev = levels -clev (*) = 1 -contour,alpha,levels,h,levels=levels,c_colors=colors,/fill,/xstyle,/ystyle, $ - /noerase,yticks=1,ytickname=[' ',' '] ,xrange=[min(levels),max(levels)], $ - xtitle=' ', color=0,xtickv=levels, $ - C_charsize=1.0, charsize=0.5 ,xtickformat = "(A1)" -contour,alpha,levels,h,levels=levels,color=0,/overplot,c_label=clev - for k = 0,n_elements(vtypes) -2 do xyouts,levels[k]+0.5,1.1,clm_name(k) ,orientation=90,color=0 -snapshot = TVRD() - -TVLCT, r, g, b, /Get -Device, Z_Buffer=1 -Set_Plot, thisDevice -image24 = BytArr(3, 700, 1000) -image24[0,*,*] = r[snapshot] -image24[1,*,*] = g[snapshot] -image24[2,*,*] = b[snapshot] -Write_JPEG, OutDir + '/CLM-Carbon_SEC_veg_typs.jpg', image24, True=1, Quality=100 - -END diff --git a/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/obsolete/mk_catch_restart b/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/obsolete/mk_catch_restart deleted file mode 100755 index 0aa20db94..000000000 --- a/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/obsolete/mk_catch_restart +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/csh - -setenv ARCH `uname` -setenv LANDIR /land/l_data/geos5/bcs/SiB2_V2 -setenv HOMDIR /home1/ltakacs/catchment/ -setenv WRKDIR $HOMDIR/wrk -cd $WRKDIR -/bin/rm mk_catch_restart.x - - -setenv old_rslv 540x361 -setenv old_dateline DC -setenv old_tilefile FV_540x361_DC_360x180_DE.til -setenv old_restart d500_eros_01.catch_internal_rst.20060529_21z.bin - -setenv new_rslv 1080x721 -setenv new_tilefile FV_1080x721_DC_360x180_DE.til -setenv new_dateline DC - - -if( $ARCH == 'IRIX64' ) then - f90 -o mk_catch_restart.x -g $HOMDIR/mk_catch_restart.F90 -endif - -if( $ARCH == 'OSF1' ) then - f90 -o mk_catch_restart.x -g -convert big_endian -assume byterecl $HOMDIR/mk_catch_restart.F90 -endif - -./mk_catch_restart.x diff --git a/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/obsolete/mk_catch_restart.F90 b/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/obsolete/mk_catch_restart.F90 deleted file mode 100755 index 4b54e203a..000000000 --- a/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/obsolete/mk_catch_restart.F90 +++ /dev/null @@ -1,859 +0,0 @@ -PROGRAM mk_catch_internal -implicit none - -integer :: im_gcm_old, jm_gcm_old -integer :: im_ocn_old, jm_ocn_old -integer :: im_gcm_new, jm_gcm_new -integer :: im_ocn_new, jm_ocn_new -integer :: ntiles_old, ntiles_new -integer :: nland_old, nland_new - -integer qtile -parameter ( qtile = 45848 ) - -real, allocatable :: lats_old(:), lats_new(:), lats_tmp(:) -real, allocatable :: lons_old(:), lons_new(:), lons_tmp(:) -integer, allocatable :: ii_old(:), ii_new(:), ii_tmp(:) -integer, allocatable :: jj_old(:), jj_new(:), jj_tmp(:) -real, allocatable :: fr_old(:), fr_new(:), fr_tmp(:) -integer, allocatable :: typ_tmp(:) - -character*20 :: version1, version2 -character*400 :: landir,wrkdir, old_tilefile, new_tilefile, arch, flag -character*400 :: old_rslv, old_dateline, oldtilnam -character*400 :: new_rslv, new_dateline, newtildir, newtilnam -character*400 :: old_restart, new_restart, sarithpath, home -character*400 :: maxtilnam, maxtildir, logfile -character*400 :: old_diag_grids, new_diag_grids - -logical :: maxoldtoggle, twotiles -integer :: ierr, indr1, indr2, indr3, ig, jg, indx_dum, ip1, ip2 -real :: fr_ocn, rdum -integer :: dum,n,nn,nta,v,loc,idum -character*4 :: bak=char(8)//char(8)//char(8)//char(8) -real, allocatable :: oldprogvars(:,:), oldparmvars(:,:), oldallvars(:,:) -real, allocatable :: newallvars(:,:) -real, allocatable :: oldvargrids(:,:,:) -real, allocatable :: newvargrids(:,:,:), dumtile(:,:), dumgrid(:,:) -real, allocatable :: tiletilevar(:,:), tilevar(:) -integer :: numrecs, allrecs, numparmrecs, numsubtiles -logical, allocatable :: ttlookup(:) -integer, allocatable :: corners_lookup(:,:) -real, allocatable :: weights_lookup(:,:) -real, allocatable :: BF1(:), BF2(:), BF3(:), VGWMAX(:) -real, allocatable :: CDCR1(:), CDCR2(:), PSIS(:), BEE(:) -real, allocatable :: POROS(:), WPWET(:), COND(:), GNU(:) -real, allocatable :: ARS1(:), ARS2(:), ARS3(:) -real, allocatable :: ARA1(:), ARA2(:), ARA3(:), ARA4(:) -real, allocatable :: ARW1(:), ARW2(:), ARW3(:), ARW4(:) -real, allocatable :: TSA1(:), TSA2(:), TSB1(:), TSB2(:) -real, allocatable :: ATAU2(:), BTAU2(:), ITY0(:) -integer, allocatable :: ity_int(:) -integer :: ity2, nmin -real :: frc1, frc2, dmin, dist -real, allocatable :: DP2BR(:), tmp_wgt(:,:), tmp_sum(:,:) -real :: zdep1, zdep2, zdep3, zmet, term1, term2 -integer :: catindex21, catindex22, catindex23 -integer :: catindex24, catindex25, catindex26 -integer :: catid, checksum -integer :: ii0, jj0, i,j -real :: fr0, val0, ESMF_MISSING -real :: lata, latb,lona, lonb, vaa, vbb, vab, vba -real :: lat00_old, lon00_old, dx_old, dy_old -real :: lonIM_old, lon0, lat0, d1,d2,d3,d4 -integer :: ia, ib, ja, jb -real :: waa, wab, wba, wbb, wsum, tol, tempval -!real :: mindist, olddist, thislat, thislon - -! ------------------------------------------------------------------------------- -! Strategy: -! 1. Read in the "old" .til definition file -! 2. Read in the "new" .til definition file -! 3. Read in the "old" restart from a previous run -! 4. Read in Sarith's tilespace catchment parameters -! 5. Convert the prognostic variables from the old restart -! to the new catchment definitions -! a. Create aggregate imxjm grid of progs from old restart -! b. Create reasonable interolated values based on centroids -! in the new .til definitions file. -! 6. Write the restart using stored values -! ------------------------------------------------------------------------------- - -! user parameters -! --------------- - - call getenv ('ARCH' ,arch ) - call getenv ('LANDIR' ,landir ) - call getenv ('WRKDIR' ,wrkdir ) - - call getenv ('old_rslv' ,old_rslv ) - call getenv ('old_dateline',old_dateline) - call getenv ('old_tilefile',old_tilefile) - call getenv ('old_restart' ,old_restart ) - - call getenv ('new_rslv' ,new_rslv ) - call getenv ('new_dateline',new_dateline) - call getenv ('new_tilefile',new_tilefile) - - if( ARCH == 'OSF1' ) flag = 'no' - if( ARCH == 'IRIX64' ) flag = 'yes' - -old_restart = trim(wrkdir) // '/' // trim(old_restart) -new_restart = trim(old_restart) // '.' // trim(new_rslv) // '_' // trim(new_dateline) - sarithpath = trim(landir) // '/' - -numsubtiles = 4 -numrecs = 61 ! number of records in the restart (includes tiletile vars) -numparmrecs = 30 ! number of parameters at the beginning of restart - -allrecs = numrecs + 7*3 ! all records, with tile-tile prognostic variables expanded - -allocate(ttlookup(numrecs)) -ttlookup(:) = .false. ! ttlookup specifies which records in restart are tile-tile -ttlookup(31:32) = .true. ! or tileonly (.false.=tileonly) -ttlookup(53:56) = .true. -ttlookup(61) = .true. - -twotiles=.false. ! set this to true to force a two tile test -ESMF_MISSING=-999.0 ! missing value in old restart prognostic variables -tol=1.0E-6 -logfile='mk_catch_restart.log' - -old_diag_grids = 'old_grids.dat' -new_diag_grids = 'new_grids.dat' - -! ------------------------------------------------------------------------------- -! 1. Read in the old .til file and store the I, J, FR's -! ------------------------------------------------------------------------------- - -newtildir = trim(sarithpath) // trim(new_dateline) // '/FV_' // trim(new_rslv) - -oldtilnam = trim(wrkdir) // '/' // trim(old_tilefile) -newtilnam = trim(wrkdir) // '/' // trim(new_tilefile) -print *, 'newtilenam1 = ',newtilnam -!newtilnam = trim(newtildir) // '/FV_' // trim(new_rslv) //'_'//trim(new_dateline)//'_360x180_DE_NO_TINY.til' -!newtilnam = trim(newtildir) // '/FV_' // trim(new_rslv) //'_'//trim(new_dateline)//'_576x540_DE_NO_TINY.til' -print *, 'newtilenam2 = ',newtilnam - -open(9, file=trim(logfile),action='write',form='formatted') - -write (*,*) -write (*,*) '---------------------------------------------------------------------' -write (*,*) 'Reading source (old) tile definitions from:' -write (9,*) '---------------------------------------------------------------------' -write (9,*) 'Reading source (old) tile definitions from:' -write (9,*) trim(oldtilnam) -write (*,*) trim(oldtilnam) - -open (10,file=trim(oldtilnam),status='old', action='read',form='formatted') -read (10,*) ntiles_old -read (10,*) dum -read (10,'(a)')version1 -read (10,*)im_gcm_old -read (10,*)jm_gcm_old -read (10,'(a)')version2 -read (10,*) im_ocn_old -read (10,*) jm_ocn_old -write(9,*) 'Header: ', ntiles_old, dum, trim(version1), im_gcm_old, jm_gcm_old, & - trim(version2), im_ocn_old, jm_ocn_old - -allocate(lats_tmp(ntiles_old)) -allocate(lons_tmp(ntiles_old)) -allocate( fr_tmp(ntiles_old)) -allocate( ii_tmp(ntiles_old)) -allocate( jj_tmp(ntiles_old)) -allocate( typ_tmp(ntiles_old)) - -write(*, 40, advance=trim(flag)) -nland_old=0 -do n = 1,ntiles_old - read(10,'(i10,i9,2f10.4,2i5,f10.6,3i8,f10.6,i8)',IOSTAT=ierr)typ_tmp(n),& - indr1,lons_tmp(n),lats_tmp(n),ii_tmp(n),jj_tmp(n),fr_tmp(n),indx_dum,indr2,dum,fr_ocn,indr3 - if (typ_tmp(n) == 100) then - ip2=n - nland_old=nland_old+1 - endif - if (typ_tmp(n) == 0) then - ip1=n - endif - if(ierr /= 0) write (*,*) 'Problem reading' - write(*, 50, advance=trim(flag)) bak, floor(float(n)/float(ntiles_old)*100) -end do -close (10,status='keep') - -write(9,*) 'Last ocean index:', ip1 -write(9,*) 'Last land index:', ip2 -write(9,*) 'NTILES LAND:', nland_old -write(*,*) - -!write(*,*) 'Packing land coordinate arrays...' - -allocate ( lats_old(nland_old) ) -allocate ( lons_old(nland_old) ) -allocate ( fr_old(nland_old) ) -allocate ( ii_old(nland_old) ) -allocate ( jj_old(nland_old) ) - -lats_old = pack(lats_tmp, mask=typ_tmp .eq. 100) -lons_old = pack(lons_tmp, mask=typ_tmp .eq. 100) - fr_old = pack( fr_tmp, mask=typ_tmp .eq. 100) - ii_old = pack( ii_tmp, mask=typ_tmp .eq. 100) - jj_old = pack( jj_tmp, mask=typ_tmp .eq. 100) - -write(9,*) 'lats', size(lats_old), minval(lats_old), maxval(lats_old) -write(9,*) 'lons', size(lons_old), minval(lons_old), maxval(lons_old) -write(9,*) 'fr ', size (fr_old), minval (fr_old), maxval (fr_old) -write(9,*) 'ii ', size (ii_old), minval (ii_old), maxval (ii_old) -write(9,*) 'jj ', size (jj_old), minval (jj_old), maxval (jj_old) - -deallocate(lats_tmp) -deallocate(lons_tmp) -deallocate( fr_tmp) -deallocate( ii_tmp) -deallocate( jj_tmp) -deallocate( typ_tmp) - -! ------------------------------------------------------------------------------- -! 2. Read in the new .til file and store the I, J, FR's -! ------------------------------------------------------------------------------- - -write (*,*) -write (*,*) '---------------------------------------------------------------------' -write (*,*) 'Reading source (new) tile definitions from:' -write (*,*) trim(newtilnam) -write (9,*) '---------------------------------------------------------------------' -write (9,*) 'Reading source (new) tile definitions from:' -write (9,*) trim(newtilnam) - -open (10,file=trim(newtilnam),status='old',action='read',form='formatted') -read (10,*) ntiles_new -read (10,*) dum -read (10,'(a)')version1 -read (10,*)im_gcm_new -read (10,*)jm_gcm_new -read (10,'(a)')version2 -read (10,*) im_ocn_new -read (10,*) jm_ocn_new -write(9,*) 'Header: ', ntiles_new, dum, trim(version1), im_gcm_new, jm_gcm_new, & - trim(version2), im_ocn_new, jm_ocn_new - -allocate ( lats_tmp(ntiles_new) ) -allocate ( lons_tmp(ntiles_new) ) -allocate ( fr_tmp(ntiles_new) ) -allocate ( ii_tmp(ntiles_new) ) -allocate ( jj_tmp(ntiles_new) ) -allocate ( typ_tmp(ntiles_new) ) - - write(*, 40, advance=trim(flag)) -nland_new=0 -do n = 1,ntiles_new - read(10,'(i10,i9,2f10.4,2i5,f10.6,3i8,f10.6,i8)',IOSTAT=ierr)typ_tmp(n),& - indr1,lons_tmp(n),lats_tmp(n),ii_tmp(n),jj_tmp(n),fr_tmp(n),indx_dum,indr2,dum,fr_ocn,indr3 - if (typ_tmp(n) == 100) then - ip2=n - nland_new=nland_new+1 - endif - if (typ_tmp(n) == 0) then - ip1=n - endif - if(ierr /= 0) write (*,*) 'Problem reading' - write(*, 50, advance=trim(flag)) bak, floor(float(n)/float(ntiles_new)*100) -end do -close (10,status='keep') - -write(9,*) 'Last ocean index:', ip1 -write(9,*) 'Last land index:', ip2 -write(9,*) 'NTILES LAND:', nland_new -write(*,*) - -allocate ( lats_new(nland_new) ) -allocate ( lons_new(nland_new) ) -allocate ( fr_new(nland_new) ) -allocate ( ii_new(nland_new) ) -allocate ( jj_new(nland_new) ) - -lats_new = pack(lats_tmp, mask=typ_tmp .eq. 100) -lons_new = pack(lons_tmp, mask=typ_tmp .eq. 100) - fr_new = pack( fr_tmp, mask=typ_tmp .eq. 100) - ii_new = pack( ii_tmp, mask=typ_tmp .eq. 100) - jj_new = pack( jj_tmp, mask=typ_tmp .eq. 100) - -write(9,*) 'lats', size(lats_new), minval(lats_new), maxval(lats_new) -write(9,*) 'lons', size(lons_new), minval(lons_new), maxval(lons_new) -write(9,*) 'fr ', size(fr_new), minval(fr_new), maxval(fr_new) -write(9,*) 'ii ', size(ii_new), minval(ii_new), maxval(ii_new) -write(9,*) 'jj ', size(jj_new), minval(jj_new), maxval(jj_new) - -deallocate(lats_tmp) -deallocate(lons_tmp) -deallocate( fr_tmp) -deallocate( ii_tmp) -deallocate( jj_tmp) -deallocate( typ_tmp) - -! ------------------------------------------------------------------------------- -! 3. Read in the old restart from a previous run -! Here, I separate the parameters and prognostic variables. Some of the -! prognostic variables are printed out by catch-finalize as var(ntiles, 4) -! This routine takes that into account, and I put the parameters and -! prognostics in separate arrays. Then, the parameters will be replaced by -! something Sarith makes, while the prognostics will be regridded. If you -! wish, you can also retain the soil parameters in the trivial case (eg. -! you want to keep same land specification but just adjust the initialization -! to a different date) -! ------------------------------------------------------------------------------- - -allocate(oldparmvars(nland_old, numparmrecs)) -allocate(oldprogvars(nland_old,allrecs-numparmrecs)) - -allocate( oldallvars(nland_old,allrecs)) -allocate(tiletilevar(nland_old, numsubtiles)) -allocate( tilevar(nland_old)) - -open(unit=30, file=trim(old_restart),form='unformatted') - -write (*,*) -write (*,*) '---------------------------------------------------------------------' -write (*,*) 'Reading old restart from:' -write (*,*) trim(old_restart) - -write (9,*) -write (9,*) '---------------------------------------------------------------------' -write (9,*) 'Reading '//trim(old_restart) -write (9,*) 'Sizes', size(tiletilevar), size(tilevar) - - write(*, 70, advance=trim(flag)) -open(unit=65, file='old_catch.dat' ,form='unformatted') - -nta=1 -do n=1, numrecs - if (ttlookup(n)) then - read(30) tiletilevar - do nn=1, numsubtiles - oldallvars(:,nta)=tiletilevar(:,nn) - write (65) tiletilevar(:,nn) ! Write Grads-Formatted Catchment File - nta=nta+1 - enddo - else - read(30) tilevar - oldallvars(:,nta)=tilevar(:) - write (65) tilevar(:) ! Write Grads-Formatted Catchment File - nta=nta+1 - endif - write(*, 50, advance=trim(flag)) bak, floor(float(n)/float(numrecs)*100) -enddo - -close(30) -deallocate(tiletilevar) -deallocate(tilevar) - -write(*,*) 'Separating parameter and prognostic variables' -write(9,*) 'Separating parameter and prognostic variables' - -do n=1, numparmrecs - oldparmvars(:,n)=oldallvars(:,n) -enddo -do n=1, allrecs-numparmrecs - oldprogvars(:,n)=oldallvars(:,n+numparmrecs) -end do - -loc = 0 -do n=1,numrecs - nta = 1 - if( ttlookup(n) ) nta = numsubtiles - do nn = 1,nta - loc = loc+1 - if( loc.le.numparmrecs ) then - write(9,*) ' Transferred old parameter (',n,',',nn,') ', & - minval(oldallvars(:,loc)), maxval(oldallvars(:,loc)) - else - write(9,*) ' Transferred old prognostic (',n,',',nn,') ', & - minval(oldallvars(:,loc)), maxval(oldallvars(:,loc)) - endif - enddo -enddo - - -! ------------------------------------------------------------------------------- -! 4. Read in the soil parameter variables (there are 29 of them) from Sarith -! vegetation type is also read in here, from an old Aries format (this needs -! to be changed, so vegtype is in .til file!) -! ------------------------------------------------------------------------------- - -allocate ( BF1(nland_new), BF2 (nland_new), BF3(nland_new) ) -allocate (VGWMAX(nland_new), CDCR1(nland_new), CDCR2(nland_new) ) -allocate ( PSIS(nland_new), BEE(nland_new), POROS(nland_new) ) -allocate ( WPWET(nland_new), COND(nland_new), GNU(nland_new) ) -allocate ( ARS1(nland_new), ARS2(nland_new), ARS3(nland_new) ) -allocate ( ARA1(nland_new), ARA2(nland_new), ARA3(nland_new) ) -allocate ( ARA4(nland_new), ARW1(nland_new), ARW2(nland_new) ) -allocate ( ARW3(nland_new), ARW4(nland_new), TSA1(nland_new) ) -allocate ( TSA2(nland_new), TSB1(nland_new), TSB2(nland_new) ) -allocate ( ATAU2(nland_new), BTAU2(nland_new), DP2BR(nland_new) ) -allocate ( ITY0(nland_new), ity_int(nland_new)) - -write(*,*) -write(*,*) '---------------------------------------------------------------------' -write(9,*) -write(9,*) '---------------------------------------------------------------------' -write(9,*) 'Reading Sarith parameters from:' -write(9,*) trim(newtildir) -write(9,*) 'Sample output ... ' -write(*,*) 'Reading Sarith parameters from:' -write(*,*) trim(newtildir) -write(*,*) 'Sample output ... ' - -open(unit=21, file=trim(newtildir) // '/' //'mosaic_veg_typs_fracs',form='formatted') -open(unit=22, file=trim(newtildir) // '/' //'bf.dat' ,form='formatted') -open(unit=23, file=trim(newtildir) // '/' //'soil_param.dat' ,form='formatted') -open(unit=24, file=trim(newtildir) // '/' //'ar.new' ,form='formatted') -open(unit=25, file=trim(newtildir) // '/' //'ts.dat' ,form='formatted') -open(unit=26, file=trim(newtildir) // '/' //'tau_param.dat' ,form='formatted') - - write(*, 80, advance=trim(flag)) - -do n=1,nland_new -! read (21, *) catindex21, catid, ity_int(n), ity2, frc1, frc2, rdum - read (21, *) catindex21, catid, ity_int(n), ity2, frc1, frc2 ! version 2 doesnt have rdum variable - ITY0(n)=1.0*ity_int(n) - read (22, *) catindex22, catid, GNU(n), BF1(n), BF2(n), BF3(n) - read (23, *) catindex23, catid, idum, idum, BEE(n), PSIS(n), POROS(n), COND(n), WPWET(n), DP2BR(n) - - read (24, *) catindex24, catid, rdum, ARS1(n), ARS2(n), ARS3(n), & - ARA1(n), ARA2(n), ARA3(n), ARA4(n), & - ARW1(n), ARW2(n), ARW3(n), ARW4(n) - - read (25, *) catindex25, catid, rdum, TSA1(n), TSA2(n), TSB1(n), TSB2(n) - - read (26, *) catindex26, catid, ATAU2(n), BTAU2(n), rdum, rdum - - checksum=catindex21+catindex22+catindex23+catindex24+catindex25+catindex26-6*(n+ip1) - zdep2=1000. - zdep3=amax1(1000.,DP2BR(n)) - if (zdep2 .gt.0.75*zdep3) then - zdep2 = 0.75*zdep3 - end if - zdep1=20. - zmet=zdep3/1000. - term1=-1.+((PSIS(n)-zmet)/PSIS(n))**((BEE(n)-1.)/BEE(n)) - term2=PSIS(n)*BEE(n)/(BEE(n)-1) - VGWMAX(n)=POROS(n)*zdep2 - CDCR1(n)=1000.*POROS(n)*(zmet-(-term2*term1)) - CDCR2(n)=(1.-WPWET(n))*POROS(n)*zdep3 - if (checksum .ne. 0) then - write(9,*) 'Catchment id mismatch with following id list at n=', n - write(9,*) catindex22, catindex23, catindex24, catindex25, catindex26, ip1+n - write(*,*) 'Halted on catchment mismatch' - STOP - else - if (modulo(n, 1000).eq.1 .or. n.eq.qtile ) then - write(9,*) - write(9,*) n, 'mosaic_vegtype: ', ity_int(n) - write(9,*) n, 'bf.dat: ', catindex22, catid, GNU(n), BF1(n), BF2(n) - write(9,*) n, 'bf.dat: ', BF3(n) - write(9,*) n, 'soil_param.dat: ', catindex23, catid, rdum, BEE(n), PSIS(n) - write(9,*) n, 'soil_param.dat: ', POROS(n), COND(n), WPWET(n), DP2BR(n) - write(9,*) n, 'ar.dat: ', catindex24, catid, rdum, ARS1(n), ARS2(n) - write(9,*) n, 'ar.dat: ', ARS3(n), ARA1(n), ARA2(n), ARA3(n), ARA4(n) - write(9,*) n, 'ar.dat: ', ARW1(n), ARW2(n), ARW3(n), ARW4(n) - write(9,*) n, 'ts.dat: ', catindex25, catid, rdum, TSA1(n), TSA2(n) - write(9,*) n, 'ts.dat: ', TSB1(n), TSB2(n) - write(9,*) n, 'tau_param.dat: ', catindex26, catid, ATAU2(n), BTAU2(n) - write(9,*) n, 'Computed: ', VGWMAX(n), CDCR1(n), CDCR2(n) - end if - endif - write(*, 50, advance=trim(flag)) bak, floor(float(n)/float(nland_new)*100) -end do - -close (21) -close (22) -close (23) -close (24) -close (25) -close (26) - -! ------------------------------------------------------------------------------- -! 5. Regrid all variables to im_gcm_oldXjm_gcm_old grid -! Then, find interpolated values based upon the centroids of tiles in -! new .til definitions. Missing values: if a single tile is missing, -! it's influence on the gridded value is ignored, except if there are no -! non-missing values in an i,j cell, then the new tile is defined as missing -! -! Alternatives for future development: -! -! a. Nearest neighbor -! b. Nearest neighbor of same/similar vegetation type, latitude, etc. -! c. Gridding, ungridding (this is done currently) -! d. Krieging of some kind, pick a radius of influence and weigh by inverse -! square of distance, or limit to veg type, or whatever. -! -! ------------------------------------------------------------------------------- - -open(unit=8, file=trim(old_diag_grids),form='unformatted') - -allocate( tmp_sum(im_gcm_old,jm_gcm_old)) -allocate( tmp_wgt(im_gcm_old,jm_gcm_old)) -allocate(oldvargrids(im_gcm_old,jm_gcm_old,allrecs)) -allocate( dumgrid(im_gcm_old,jm_gcm_old)) - -loc = 0 -do v=1, numrecs - nta = 1 - if( ttlookup(v) ) nta = numsubtiles - do nn = 1,nta - loc = loc+1 - tmp_sum(:,:)=0.0 - tmp_wgt(:,:)=0.0 - do n=1, nland_old - val0=oldallvars(n,loc) - ii0=ii_old(n) - jj0=jj_old(n) - fr0=fr_old(n) - if (abs(val0-ESMF_MISSING) .gt. tol) then - tmp_sum(ii0,jj0) = tmp_sum(ii0,jj0) + fr0*val0 - tmp_wgt(ii0,jj0) = tmp_wgt(ii0,jj0) + fr0 - else - print *, 'Old_Catch_Val = ',val0,' n = ',n,' loc = ',loc - endif - enddo - do j=1,jm_gcm_old - do i=1,im_gcm_old - if (tmp_wgt(i,j) .gt. tol) then - oldvargrids(i,j,loc)=tmp_sum(i,j)/tmp_wgt(i,j) - else - oldvargrids(i,j,loc)=ESMF_MISSING - endif - dumgrid(i,j) =oldvargrids(i,j,loc) - enddo - enddo - write (8) dumgrid - enddo -enddo - -deallocate(dumgrid) -deallocate(tmp_sum) -deallocate(tmp_wgt) -close(8) - -allocate( corners_lookup(nland_new, 4) ) -allocate( weights_lookup(nland_new, 4) ) - -lat00_old = -90 - dx_old = (360.0)/ im_gcm_old - dy_old = (180.0)/(jm_gcm_old-1) - -if (old_dateline .eq. 'DC') then - lon00_old = -180 - lonIM_old = 180-dx_old -else - lon00_old = -180+0.5*dx_old - lonIM_old = 180-0.5*dx_old -end if - -write(*,*) -write(*,*) '---------------------------------------------------------------------' -write(*,*) 'Computing interpolation lookup table for new tiles' -write(9,*) -write(9,*) '---------------------------------------------------------------------' -write(9,*) 'Computing interpolation lookup table for new tiles' - write(*, 90, advance=trim(flag)) - -do n=1,nland_new - lat0=lats_new(n) ! latitude of tile centroid to find - lon0=lons_new(n) ! longitude of tile centroid - if ((lon0 .gt. lonIM_old) .or. (lon0 .lt. lon00_old)) then - ia=im_gcm_old - ib=1 - lona=lonIM_old - lonb=lon00_old - else - ia=floor((lon0-lon00_old)/dx_old)+1 - ib=ia+1 - lona=(ia-1)*dx_old+lon00_old - lonb=lona+dx_old - end if - ja=floor((lat0-lat00_old)/dy_old)+1 ! left bottom corner y coordinate - jb=ja+1 ! right top corner y coordinate - lata=(ja-1)*dy_old+lat00_old ! latitude of left bottom corner - latb=lata+dy_old - - if( ia.lt.1 .or. ia.gt.im_gcm_old .or. & - ib.lt.1 .or. ib.gt.im_gcm_old .or. & - ja.lt.1 .or. ja.gt.jm_gcm_old .or. & - jb.lt.1 .or. jb.gt.jm_gcm_old ) then - print *, 'Warning, bad indicies!' - print *, 'New Land variable: ',n,ia,ib,ja,jb - stop - endif - - if (modulo(n, 1000).eq.1 .or. n.eq.qtile) then - write (9,*) - write (9,*) n, lona, lon0, lonb, ia, ib - write (9,*) n, lata, lat0, latb, ja, jb - end if - corners_lookup(n,1)=ia - corners_lookup(n,2)=ib - corners_lookup(n,3)=ja - corners_lookup(n,4)=jb - waa=sqrt((lat0-lata)**2+(lon0-lona)**2) - wab=sqrt((lat0-lata)**2+(lon0-lonb)**2) - wba=sqrt((lat0-latb)**2+(lon0-lona)**2) - wbb=sqrt((lat0-latb)**2+(lon0-lonb)**2) - wsum=waa+wab+wba+wbb - weights_lookup(n,1)=waa - weights_lookup(n,2)=wab - weights_lookup(n,3)=wba - weights_lookup(n,4)=wbb - write(*, 50, advance=trim(flag)) bak, floor(float(n)/float(nland_new)*100) -end do - -allocate(newallvars(nland_new, allrecs)) -! new allvars allocated by number of new land tiles X number of total restart records -write(*,*) -write(*,*) '---------------------------------------------------------------------' -write(*,*) 'Interpolating prognostic records to new tile definitions' -write(9,*) -write(9,*) '---------------------------------------------------------------------' -write(9,*) 'Interpolating prognostic records to new tile definitions' - write(*, 90, advance=trim(flag)) - write(*, 50, advance=trim(flag)) bak, 0 - -do v=31, allrecs - do n=1, nland_new - ia=corners_lookup(n,1) - ib=corners_lookup(n,2) - ja=corners_lookup(n,3) - jb=corners_lookup(n,4) - waa=weights_lookup(n,1) - wbb=weights_lookup(n,4) - wab=weights_lookup(n,2) - wba=weights_lookup(n,3) - wsum=0 - tempval=0 - vaa=oldvargrids(ia,ja, v) - vbb=oldvargrids(ib,jb, v) - vab=oldvargrids(ia,jb, v) - vba=oldvargrids(ib,ja, v) - if (abs(vaa-ESMF_MISSING) .gt. tol) then - tempval=tempval+vaa*waa - wsum=waa+wsum - end if - if (abs(vab-ESMF_MISSING) .gt. tol) then - tempval=tempval+vab*wab - wsum=wab+wsum - end if - if (abs(vba-ESMF_MISSING) .gt. tol) then - tempval=tempval+vba*wba - wsum=wsum+wba - end if - if (abs(vbb-ESMF_MISSING) .gt. tol) then - tempval=tempval+vbb*wbb - wsum=wsum+wbb - end if - if (abs(wsum) .lt. tol) then - dmin = 1e15 - nmin = 0 - do nn = 1,nland_old - dist = sqrt( (lats_old(nn)-lats_new(n))**2 & - + (lons_old(nn)-lons_new(n))**2 ) - if( dist.lt.dmin ) then - nmin = nn - dmin = dist - endif - enddo - tempval=oldallvars(nmin,v) ! Find nearest old tile to new tile - print *, 'NewVal = ',tempval,' nmin = ',nmin,' loc = ',v - print *, 'newlat = ',lats_new(n),' oldlat = ',lats_old(nmin) - print *, 'newlon = ',lons_new(n),' oldlon = ',lons_old(nmin) - print * - else - tempval=tempval/(1.0*wsum) - end if - newallvars(n, v)=tempval - if (modulo(n, 1000) .eq. 1) then - write(9,*) - write(9,*) n, 'Interpolation summary' - write(9,*) n, 'Weights:', waa, wab, wba, wbb - write(9,*) n, 'Values:', vaa, vab, vba, vbb - write(9,*) n, 'Results:', tempval, wsum - end if - end do - - write(*,*) v - write(*, 50, advance=trim(flag)) bak, floor((float(v-31)/float(allrecs-31)*100)) -end do - -! I am now finished with the old tiles, get rid of them -deallocate(oldprogvars, oldparmvars, oldallvars) -deallocate(corners_lookup, weights_lookup) - -! ------------------------------------------------------------------------------- -! 6. Create the restart from stored values -! a. 29 Sarith tilespace records from his parameter files -! b. The vegetation type from Sarith's mosaic_veg_typ_file -! (I have used the PRIMARY veg type for this work, as opposed -! to the second one that also has a fraction. I am assuming that -! the catchment fraction is totally composed of the PRIMARY veg type) -! c. The modified/regridded prognostic variables that have been regridded -! At this point, the variable newallvars contains ALL records for the -! restart, including estimates of Sarith's parameters based upon -! the old values interpolated from the old restart. These are skipped, but -! might be useful for comparison in a debugging situation -! ------------------------------------------------------------------------------- - -open(unit=41, file=trim(new_restart),form='unformatted') -open(unit=66, file='new_catch.dat' ,form='unformatted') - -! replace the old interpolated parameters in newallvars with the new Sarith ones - - write(9,*) ' Min/Max for ARS1: ', minval(ARS1), maxval(ARS1) - write(9,*) ' Min/Max for ARS2: ', minval(ARS2), maxval(ARS2) - write(9,*) ' Min/Max for ARS3: ', minval(ARS3), maxval(ARS3) - -newallvars(:,1)=BF1 -newallvars(:,2)=BF2 -newallvars(:,3)=BF3 -newallvars(:,4)=VGWMAX -newallvars(:,5)=CDCR1 -newallvars(:,6)=CDCR2 -newallvars(:,7)=PSIS -newallvars(:,8)=BEE -newallvars(:,9)=POROS -newallvars(:,10)=WPWET -newallvars(:,11)=COND -newallvars(:,12)=GNU -newallvars(:,13)=ARS1 -newallvars(:,14)=ARS2 -newallvars(:,15)=ARS3 -newallvars(:,16)=ARA1 -newallvars(:,17)=ARA2 -newallvars(:,18)=ARA3 -newallvars(:,19)=ARA4 -newallvars(:,20)=ARW1 -newallvars(:,21)=ARW2 -newallvars(:,22)=ARW3 -newallvars(:,23)=ARW4 -newallvars(:,24)=TSA1 -newallvars(:,25)=TSA2 -newallvars(:,26)=TSB1 -newallvars(:,27)=TSB2 -newallvars(:,28)=ATAU2 -newallvars(:,29)=BTAU2 -newallvars(:,30)=ITY0 - -write(*,*) -write(*,*) '---------------------------------------------------------------------' -write(*,*) 'Writing new restart' -write(9,*) -write(9,*) '---------------------------------------------------------------------' -write(9,*) 'Writing new restart' - -loc = 0 -do v=1,numrecs - nta = 1 - if( ttlookup(v) ) nta = numsubtiles - allocate( dumtile(nland_new,nta) ) - do nn = 1,nta - loc = loc+1 - dumtile(:,nn) = newallvars(:,loc) - write (66) dumtile(:,nn) ! Write Grads-Formatted Catchment File - enddo - write (41) dumtile - write(9,*) 'NEW RESTART RECORD #', v , ' Size = ',size(dumtile) - deallocate ( dumtile ) -enddo -close(41) - -loc = 0 -do n=1,numrecs - nta = 1 - if( ttlookup(n) ) nta = numsubtiles - do nn = 1,nta - loc = loc+1 - if( loc.le.numparmrecs ) then - write(9,*) ' Transferred new parameter (',n,',',nn,') ', & - minval(newallvars(:,loc)), maxval(newallvars(:,loc)) - else - write(9,*) ' Transferred new prognostic (',n,',',nn,') ', & - minval(newallvars(:,loc)), maxval(newallvars(:,loc)) - endif - enddo -enddo - - -! ------------------------------------------------------------------------------- -! 7. Save a gridded copy of the new restart on rectangular grid found in the -! new .til file definitions. This can be used to check the results. -! ------------------------------------------------------------------------------- - -open(unit=42, file=trim(new_diag_grids),form='unformatted') - -allocate( tmp_sum(im_gcm_new, jm_gcm_new)) -allocate( tmp_wgt(im_gcm_new, jm_gcm_new)) -allocate( dumgrid(im_gcm_new, jm_gcm_new)) - -loc = 0 -do v=1, numrecs - nta = 1 - if( ttlookup(v) ) nta = numsubtiles - do nn = 1,nta - loc = loc+1 - tmp_sum(:,:)=0.0 - tmp_wgt(:,:)=0.0 - do n=1, nland_new - val0=newallvars(n,loc) - ii0=ii_new(n) - jj0=jj_new(n) - fr0=fr_new(n) - if (abs(val0-ESMF_MISSING) .gt. tol) then - tmp_sum(ii0,jj0)=tmp_sum(ii0,jj0)+fr0*val0 - tmp_wgt(ii0,jj0)=tmp_wgt(ii0,jj0)+fr0 - endif - enddo - do i=1,im_gcm_new - do j=1,jm_gcm_new - if (tmp_wgt(i,j) .gt. tol) then - dumgrid(i,j)=tmp_sum(i,j)/tmp_wgt(i,j) - else - dumgrid(i,j)=ESMF_MISSING - endif - enddo - enddo - write (42) dumgrid - enddo -enddo -close(42) - -deallocate(tmp_sum) -deallocate(tmp_wgt) -deallocate( dumgrid ) - -deallocate(BF1, BF2, BF3, VGWMAX) -deallocate(CDCR1, CDCR2, PSIS, BEE) -deallocate(POROS, WPWET, COND, GNU) -deallocate(ARS1, ARS2, ARS3) -deallocate(ARA1, ARA2, ARA3) -deallocate(ARA4, ARW1, ARW2, ARW3, ARW4) -deallocate(TSA1, TSA2, TSB1, TSB2) -deallocate(DP2BR, ATAU2, BTAU2) -deallocate(ITY0, ity_int) - -deallocate(lats_old) -deallocate(lons_old) -deallocate(fr_old) -deallocate(ii_old) -deallocate(jj_old) -deallocate(lats_new) -deallocate(lons_new) -deallocate(fr_new) -deallocate(ii_new) -deallocate(jj_new) -deallocate(ttlookup) - -40 FORMAT(' Percent tile definitions read: ') -50 FORMAT(A4, I3.3, '%') -60 FORMAT(' Percent MODIS data read: ') -70 FORMAT(' Percent restart read: ') -80 FORMAT(' Percent Sarith catchment parameters read: ') -90 FORMAT(' Percent completed: ') -END diff --git a/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/obsolete/mk_vegdyn_restart b/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/obsolete/mk_vegdyn_restart deleted file mode 100755 index 86e90e73a..000000000 --- a/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/obsolete/mk_vegdyn_restart +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/csh - -setenv ARCH `uname` -setenv LANDIR /land/l_data/geos5/bcs/SiB2_V2 -setenv HOMDIR /home1/ltakacs/catchment -setenv WRKDIR $HOMDIR/wrk -cd $WRKDIR - -setenv rslv 1080x721 -setenv dateline DC -setenv nland 374925 # Note, check mk_catch LOG file for number of land tiles - - -if( $ARCH == 'IRIX64' ) then - f90 -o mk_vegdyn_restart.x $HOMDIR/mk_vegdyn_restart.F90 -endif - -if( $ARCH == 'OSF1' ) then - f90 -o mk_vegdyn_restart.x -convert big_endian -assume byterecl $HOMDIR/mk_vegdyn_restart.F90 -endif - -mk_vegdyn_restart.x - diff --git a/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/obsolete/mk_vegdyn_restart.F90 b/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/obsolete/mk_vegdyn_restart.F90 deleted file mode 100755 index 849e9f8e4..000000000 --- a/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/obsolete/mk_vegdyn_restart.F90 +++ /dev/null @@ -1,54 +0,0 @@ -PROGRAM mk_vegdyn_internal -implicit none -real, allocatable :: dummy(:),ity0(:) -integer,allocatable :: ity0_int(:) -real :: filler, dum0 -integer :: vvv -integer :: bi,li -integer :: nland, nt, index, id, dum -character*256 outpath, sarithdir, dateline, restag, vegname, numland -character*256 landir - -!--------------------------------------------------------------------------- - call GETENV ( 'LANDIR' , landir ) - call GETENV ( 'rslv' , restag ) - call GETENV ( 'dateline', dateline ) - call GETENV ( 'nland' , numland ) - read(numland,*)nland - -outpath = 'vegdyn_internal_restart.' // trim(restag) // '_' // trim(dateline) -!--------------------------------------------------------------------------- - -allocate(dummy (nland)) -allocate(ity0 (nland)) -allocate(ity0_int(nland)) - -dummy(:)=-999.0 -sarithdir = trim(landir) // '/' // trim(dateline) // '/FV_' // trim(restag) // '/' -vegname = trim(sarithdir)//'mosaic_veg_typs_fracs' -write (*,*) 'Reading '//vegname - -open(unit=21, file=trim(vegname),form='formatted') -DO nt=1,nland -! read (21, *) index, id, ity0_int(nt), dum, dum0, dum0, dum0 - read (21, *) index, id, ity0_int(nt), dum, dum0, dum0 ! version 2 doesn't have frc3 - print *, ity0_int(nt) -ENDDO -ity0=ity0_int*1.0 -close(21) - - -open(unit=30, file=trim(outpath),form='unformatted') -! write out dummy lai_prev, lai_next, grn_prev, grn_next -print *, ' VEGTYPES', minval(ity0), maxval(ity0) -write (30) dummy -write (30) dummy -write (30) dummy -write (30) dummy -write (30) ity0 -close (30) -deallocate(ity0) -deallocate(ity0_int) -deallocate(dummy) -END - diff --git a/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/obsolete/new_catch.ctl b/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/obsolete/new_catch.ctl deleted file mode 100755 index b48983d75..000000000 --- a/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/obsolete/new_catch.ctl +++ /dev/null @@ -1,73 +0,0 @@ -dset wrk/new_catch.dat -options sequential template big_endian -undef -9999.0 -xdef 45147 linear 1 1 -ydef 1 linear 1 1 -zdef 4 linear 1 1 -tdef 1 linear jan1900 1mo -* -VARS 63 -var01 0 99 topo_baseflow_param_1 -var02 0 99 topo_baseflow_param_2 -var03 0 99 topo_baseflow_param_3 -var04 0 99 max_rootzone_water_content -var05 0 99 moisture_threshold -var06 0 99 max_water_content_unsat_zone -var07 0 99 saturated_matrix_potential -var08 0 99 clapp_hornberger_b -var09 0 99 soil_porosity -var10 0 99 wetness_at_wilting_point -var11 0 99 sfc_sat_hydraulic_conduct -var12 0 99 vertical_transmissivity -var13 0 99 wetness_param_1 -var14 0 99 wetness_param_2 -var15 0 99 wetness_param_3 -var16 0 99 shape_param_1 -var17 0 99 shape_param_2 -var18 0 99 shape_param_3 -var19 0 99 shape_param_4 -var20 0 99 min_theta_1 -var21 0 99 min_theta_2 -var22 0 99 min_theta_3 -var23 0 99 min_theta_4 -var24 0 99 water_transfer_1 -var25 0 99 water_transfer_2 -var26 0 99 water_transfer_3 -var27 0 99 water_transfer_4 -var28 0 99 soil_param_1 -var29 0 99 soil_param_2 -var30 0 99 vegetation_type -var31 4 99 canopy_temperature_1,2,3,4 -var32 4 99 canopy_specific_humidity_1,2,3,4 -var33 0 99 interception_reservoir_capac -var34 0 99 catchment_deficit -var35 0 99 root_zone_excess -var36 0 99 surface_excess -var37 0 99 soil_heat_content_layer1 -var38 0 99 soil_heat_content_layer2 -var39 0 99 soil_heat_content_layer3 -var40 0 99 soil_heat_content_layer4 -var41 0 99 soil_heat_content_layer5 -var42 0 99 soil_heat_content_layer6 -var43 0 99 mean_catchment_temp_incl_snow -var44 0 99 water_eq_snow_layer1 -var45 0 99 water_eq_snow_layer2 -var46 0 99 water_eq_snow_layer3 -var47 0 99 heat_content_snow_layer1 -var48 0 99 heat_content_snow_layer2 -var49 0 99 heat_content_snow_layer3 -var50 0 99 snow_depth_layer1 -var51 0 99 snow_depth_layer2 -var52 0 99 snow_depth_layer3 -var53 4 99 surface_heat_exchange_coefficient_1,2,3,4 -var54 4 99 surface_momentum_exchange_coefficient_1,2,3,4 -var55 4 99 surface_moisture_exchange_coefficient_1,2,3,4 -var56 4 99 subtile_fractions_1,2,3,4 -var57 0 99 observed_albedo_minimum_previous -var58 0 99 observed_albedo_minimum_next -var59 0 99 observed_albedo_mean_previous -var60 0 99 observed_albedo_mean_next -var61 0 99 observed_albedo_maxmindif_previous -var62 0 99 observed_albedo_maxmindir_next -var63 4 99 vertical_velocity_scale_squared_1,2,3,4 -ENDVARS diff --git a/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/obsolete/newcatch.F90 b/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/obsolete/newcatch.F90 deleted file mode 100644 index 0ad4f26e3..000000000 --- a/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/obsolete/newcatch.F90 +++ /dev/null @@ -1,91 +0,0 @@ -#define VERIFY_(A) if(A /=0)then;print *,'ERROR code',A,'at',__LINE__;call exit(3);endif - -program newcatch - implicit none - -#ifndef __GFORTRAN__ - integer*4 :: iargc - external :: iargc - integer*8 :: ftell - external :: ftell -#endif - character(256) :: str, f_in, f_out - - integer :: m - integer :: status - integer*8 :: bpos, epos, rsize - real, allocatable :: a(:) - -! Begin - - if (iargc() /= 2) then - call getarg(0,str) - write(*,*) "Usage:",trim(str)," " - call exit(2) - end if - - call getarg(1,f_in) - - open(unit=10, file=trim(f_in), form='unformatted') - -! Count the records in the files -! ------------------------------ -! Valid numbers are: -! 61 - old catch_internal_restart -! 57 - old catch_internal_restart - m=0 - do while(.true.) - read(10, end=50, err=200) ! skip to next record - m = m+1 - end do -50 continue - rewind(10) - - if (m == 57) then - print *,'WARNING: this file contains ', m, ' records and appears to have been already convered' - print *,'Refuse to convert!' - print *,'Exiting ...' - call exit(1) - else if (m /= 61) then - print *,'ERROR: this file contains ',m, & - ' records and does not appear to be a valid catchment internal restart' - print *,'Exiting ...' - call exit(2) - end if - -! Open the output file -! -------------------- - call getarg(2,f_out) - open(unit=20, file=trim(f_out), form='unformatted') - - m=0 - bpos=0 - do while(.true.) - m = m+1 - read(10, end=100, err=200) ! skip to next record - epos = ftell(10) ! ending position of file pointer - backspace(10) - - rsize = (epos-bpos)/4-2 ! record size (in 4 byte words; - bpos = epos - allocate(a(rsize), stat=status) - VERIFY_(status) - read (10) a - if (m < 57 .or. m > 60) then - print *,'Writing record ',m - write(20) a - else - print *,'Skipping record ',m - end if - deallocate(a) - end do -100 continue - close(10) - close(20) - stop - -! If we are here something must have gone wrong -200 VERIFY_(200) - -end program newcatch - diff --git a/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/obsolete/newvegdyn.f90 b/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/obsolete/newvegdyn.f90 deleted file mode 100644 index beafa8424..000000000 --- a/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/obsolete/newvegdyn.f90 +++ /dev/null @@ -1,57 +0,0 @@ -program newvegdyn - implicit none - - real, pointer :: var(:) - - integer :: i, bpos, epos, status - integer :: rsize - character(256) :: str, f_in, f_out - integer*4 :: ftell - external :: ftell - - integer*4 :: iargc - external :: iargc - -! Begin - - if (iargc() /= 2) then - call getarg(0,str) - write(*,*) "Usage:",trim(str)," " - call exit(2) - end if - - call getarg(1,f_in) - call getarg(2,f_out) - - open(unit=10, file=trim(f_in), form='unformatted') - open(unit=20, file=trim(f_out), form='unformatted') - - print *,'New Restart Format for File: ',trim(f_in) - - bpos=0 - read(10, err=200) ! skip to next record - epos = ftell(10) ! ending position of file pointer - - rsize = (epos-bpos)/4-2 ! record size (in 4 byte words; - ! 2 is the number of fortran control words) - allocate(var(rsize), stat=status) - if (status /= 0) then - print *, 'Error: allocation ', rsize, ' failed!' - call exit(11) - end if - - read(10, err=200) ! skip to next record - read(10, err=200) ! skip to next record - read(10, err=200) ! skip to next record -! alltogather we skip 4 record - read (10) var - write(20) var - deallocate(var) - close(10) - close(20) - stop - -200 print *,'Error reading file ',trim(f_in) - call exit(11) - -end diff --git a/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/obsolete/old_catch.ctl b/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/obsolete/old_catch.ctl deleted file mode 100755 index b98d32163..000000000 --- a/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/obsolete/old_catch.ctl +++ /dev/null @@ -1,73 +0,0 @@ -dset wrk/old_catch.dat -options sequential template big_endian -undef -9999.0 -xdef 76847 linear 1 1 -ydef 1 linear 1 1 -zdef 4 linear 1 1 -tdef 1 linear jan1900 1mo -* -VARS 63 -var01 0 99 topo_baseflow_param_1 -var02 0 99 topo_baseflow_param_2 -var03 0 99 topo_baseflow_param_3 -var04 0 99 max_rootzone_water_content -var05 0 99 moisture_threshold -var06 0 99 max_water_content_unsat_zone -var07 0 99 saturated_matrix_potential -var08 0 99 clapp_hornberger_b -var09 0 99 soil_porosity -var10 0 99 wetness_at_wilting_point -var11 0 99 sfc_sat_hydraulic_conduct -var12 0 99 vertical_transmissivity -var13 0 99 wetness_param_1 -var14 0 99 wetness_param_2 -var15 0 99 wetness_param_3 -var16 0 99 shape_param_1 -var17 0 99 shape_param_2 -var18 0 99 shape_param_3 -var19 0 99 shape_param_4 -var20 0 99 min_theta_1 -var21 0 99 min_theta_2 -var22 0 99 min_theta_3 -var23 0 99 min_theta_4 -var24 0 99 water_transfer_1 -var25 0 99 water_transfer_2 -var26 0 99 water_transfer_3 -var27 0 99 water_transfer_4 -var28 0 99 soil_param_1 -var29 0 99 soil_param_2 -var30 0 99 vegetation_type -var31 4 99 canopy_temperature_1,2,3,4 -var32 4 99 canopy_specific_humidity_1,2,3,4 -var33 0 99 interception_reservoir_capac -var34 0 99 catchment_deficit -var35 0 99 root_zone_excess -var36 0 99 surface_excess -var37 0 99 soil_heat_content_layer1 -var38 0 99 soil_heat_content_layer2 -var39 0 99 soil_heat_content_layer3 -var40 0 99 soil_heat_content_layer4 -var41 0 99 soil_heat_content_layer5 -var42 0 99 soil_heat_content_layer6 -var43 0 99 mean_catchment_temp_incl_snow -var44 0 99 water_eq_snow_layer1 -var45 0 99 water_eq_snow_layer2 -var46 0 99 water_eq_snow_layer3 -var47 0 99 heat_content_snow_layer1 -var48 0 99 heat_content_snow_layer2 -var49 0 99 heat_content_snow_layer3 -var50 0 99 snow_depth_layer1 -var51 0 99 snow_depth_layer2 -var52 0 99 snow_depth_layer3 -var53 4 99 surface_heat_exchange_coefficient_1,2,3,4 -var54 4 99 surface_momentum_exchange_coefficient_1,2,3,4 -var55 4 99 surface_moisture_exchange_coefficient_1,2,3,4 -var56 4 99 subtile_fractions_1,2,3,4 -var57 0 99 observed_albedo_minimum_previous -var58 0 99 observed_albedo_minimum_next -var59 0 99 observed_albedo_mean_previous -var60 0 99 observed_albedo_mean_next -var61 0 99 observed_albedo_maxmindif_previous -var62 0 99 observed_albedo_maxmindir_next -var63 4 99 vertical_velocity_scale_squared_1,2,3,4 -ENDVARS diff --git a/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/obsolete/replace_params.F90 b/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/obsolete/replace_params.F90 deleted file mode 100644 index 09fa5c26b..000000000 --- a/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/obsolete/replace_params.F90 +++ /dev/null @@ -1,296 +0,0 @@ -PROGRAM replace_params - implicit none - - integer :: nland_old, nland_new - character*400 :: tilefile - character*400 :: old_restart, new_restart, sarithpath - - real, allocatable :: var1(:),var2(:,:) - integer :: numrecs, allrecs, numparmrecs - - real, allocatable :: BF1(:), BF2(:), BF3(:), VGWMAX(:) - real, allocatable :: CDCR1(:), CDCR2(:), PSIS(:), BEE(:) - real, allocatable :: POROS(:), WPWET(:), COND(:), GNU(:) - real, allocatable :: ARS1(:), ARS2(:), ARS3(:) - real, allocatable :: ARA1(:), ARA2(:), ARA3(:), ARA4(:) - real, allocatable :: ARW1(:), ARW2(:), ARW3(:), ARW4(:) - real, allocatable :: TSA1(:), TSA2(:), TSB1(:), TSB2(:) - real, allocatable :: ATAU2(:), BTAU2(:), ITY0(:) - integer, allocatable :: ity_int(:) - integer :: ity2, nmin, type - real, allocatable :: DP2BR(:), tmp_wgt(:,:), tmp_sum(:,:) - real :: zdep1, zdep2, zdep3, zmet, term1, term2 - integer :: catindex21, catindex22, catindex23 - integer :: catindex24, catindex25, catindex26 - real :: frc1, frc2, rdum - integer :: catid, checksum, ntilesold - integer :: ii0, jj0, i,j,n, idum,II - integer :: IARGC - - - II = iargc() - - if(II /= 4) then - print *, "Wrong Number of arguments: ", ii - call exit(66) - end if - - call getarg(1,old_restart) - call getarg(2,new_restart) - call getarg(3,tilefile) - call getarg(4,sarithpath) - - sarithpath = "/land/l_data/geos5/bcs/SiB2_V2/DC/"//trim(sarithpath) - - numrecs = 61 - numparmrecs = 30 - - ! read .til file - - open (10,file=trim(tilefile),status='old',form='formatted') - read (10,*) ntilesold - read (10,*) - read (10,*) - read (10,*) - read (10,*) - read (10,*) - read (10,*) - read (10,*) - nland_old=0 - do n = 1,ntilesold - read(10,*) type - if (type == 100) then - nland_old=nland_old+1 - endif - end do - close (10,status='keep') - - print *, ' Number of land tiles = ', nland_old - - nland_new = nland_old - - allocate ( BF1(nland_new), BF2 (nland_new), BF3(nland_new) ) - allocate (VGWMAX(nland_new), CDCR1(nland_new), CDCR2(nland_new) ) - allocate ( PSIS(nland_new), BEE(nland_new), POROS(nland_new) ) - allocate ( WPWET(nland_new), COND(nland_new), GNU(nland_new) ) - allocate ( ARS1(nland_new), ARS2(nland_new), ARS3(nland_new) ) - allocate ( ARA1(nland_new), ARA2(nland_new), ARA3(nland_new) ) - allocate ( ARA4(nland_new), ARW1(nland_new), ARW2(nland_new) ) - allocate ( ARW3(nland_new), ARW4(nland_new), TSA1(nland_new) ) - allocate ( TSA2(nland_new), TSB1(nland_new), TSB2(nland_new) ) - allocate ( ATAU2(nland_new), BTAU2(nland_new), DP2BR(nland_new) ) - allocate ( ITY0(nland_new), ity_int(nland_new)) - - - - open(unit=21, file=trim(sarithpath) // '/' //'mosaic_veg_typs_fracs',form='formatted') - open(unit=22, file=trim(sarithpath) // '/' //'bf.dat' ,form='formatted') - open(unit=23, file=trim(sarithpath) // '/' //'soil_param.dat' ,form='formatted') - open(unit=24, file=trim(sarithpath) // '/' //'ar.new' ,form='formatted') - open(unit=25, file=trim(sarithpath) // '/' //'ts.dat' ,form='formatted') - open(unit=26, file=trim(sarithpath) // '/' //'tau_param.dat' ,form='formatted') - - - print *, 'opened units' - - do n=1,nland_new - read (21, *) catindex21, catid, ity_int(n), ity2, frc1, frc2 - ITY0(n)=1.0*ity_int(n) - - read (22, *) catindex22, catid, GNU(n), BF1(n), BF2(n), BF3(n) - - read (23, *) catindex23, catid, idum, idum, BEE(n), PSIS(n), POROS(n), COND(n), WPWET(n), DP2BR(n) - - read (24, *) catindex24, catid, rdum, ARS1(n), ARS2(n), ARS3(n), & - ARA1(n), ARA2(n), ARA3(n), ARA4(n), & - ARW1(n), ARW2(n), ARW3(n), ARW4(n) - - read (25, *) catindex25, catid, rdum, TSA1(n), TSA2(n), TSB1(n), TSB2(n) - - read (26, *) catindex26, catid, ATAU2(n), BTAU2(n), rdum, rdum - - zdep2=1000. - zdep3=amax1(1000.,DP2BR(n)) - if (zdep2 .gt.0.75*zdep3) then - zdep2 = 0.75*zdep3 - end if - zdep1=20. - zmet=zdep3/1000. - - term1=-1.+((PSIS(n)-zmet)/PSIS(n))**((BEE(n)-1.)/BEE(n)) - term2=PSIS(n)*BEE(n)/(BEE(n)-1) - - VGWMAX(n) = POROS(n)*zdep2 - CDCR1(n) = 1000.*POROS(n)*(zmet-(-term2*term1)) - CDCR2(n) = (1.-WPWET(n))*POROS(n)*zdep3 - enddo - - close (21) - close (22) - close (23) - close (24) - close (25) - close (26) - - - print *, ' Doing restarts' - - open(unit=30, file=trim(old_restart),form='unformatted',status='old',convert='little_endian') - open(unit=40, file=trim(new_restart),form='unformatted',status='unknown',convert='little_endian') - - allocate(var1(nland_old)) - allocate(var2(nland_old,4)) - - print *, 'Opened restart files' - print *, 30, trim(old_restart) - print *, 40, trim(new_restart) - - - - write(40) BF1 - read(30) var1 - print *, "BF1",maxval(BF1), maxval(var1), minval(BF1),minval(var1) - - write(40) BF2 - read(30) var1 - print *, "BF2",maxval(BF2), maxval(var1), minval(BF2),minval(var1) - - write(40) BF3 - read(30) var1 - print *, "BF3",maxval(BF3), maxval(var1), minval(BF3),minval(var1) - - write(40) VGWMAX - read(30) var1 - print *, "VGWMAX",maxval(VGWMAX), maxval(var1), minval(VGWMAX),minval(var1) - - write(40) CDCR1 - read(30) var1 - print *, "CDCR1",maxval(CDCR1), maxval(var1), minval(CDCR1),minval(var1) - - write(40) CDCR2 - read(30) var1 - print *, "CDCR2",maxval(CDCR2), maxval(var1), minval(CDCR2),minval(var1) - - write(40) PSIS - read(30) var1 - print *, "PSIS",maxval(PSIS), maxval(var1), minval(PSIS),minval(var1) - - write(40) BEE - read(30) var1 - print *, "BEE",maxval(BEE), maxval(var1), minval(BEE),minval(var1) - - write(40) POROS - read(30) var1 - print *, "POROS ",maxval(POROS ), maxval(var1), minval(POROS ),minval(var1) - - write(40) WPWET - read(30) var1 - print *, "WPWET",maxval(WPWET), maxval(var1), minval(WPWET),minval(var1) - - write(40) COND - read(30) var1 - print *, "COND",maxval(COND), maxval(var1), minval(COND),minval(var1) - - write(40) GNU - read(30) var1 - print *, "GNU",maxval(GNU), maxval(var1), minval(GNU),minval(var1) - - write(40) ARS1 - read(30) var1 - print *, "ARS1",maxval(ARS1), maxval(var1), minval(ARS1),minval(var1) - - write(40) ARS2 - read(30) var1 - print *, "ARS2",maxval(ARS2), maxval(var1), minval(ARS2),minval(var1) - - write(40) ARS3 - read(30) var1 - print *, "ARS3",maxval(ARS3), maxval(var1), minval(ARS3),minval(var1) - - write(40) ARA1 - read(30) var1 - print *, "ARA1",maxval(ARA1), maxval(var1), minval(ARA1),minval(var1) - - write(40) ARA2 - read(30) var1 - print *, "ARA2",maxval(ARA2), maxval(var1), minval(ARA2),minval(var1) - - write(40) ARA3 - read(30) var1 - print *, "ARA3",maxval(ARA3), maxval(var1), minval(ARA3),minval(var1) - - write(40) ARA4 - read(30) var1 - print *, "ARA4",maxval(ARA4), maxval(var1), minval(ARA4),minval(var1) - - write(40) ARW1 - read(30) var1 - print *, "ARW1",maxval(ARW1), maxval(var1), minval(ARW1),minval(var1) - - write(40) ARW2 - read(30) var1 - print *, "ARW2",maxval(ARW2), maxval(var1), minval(ARW2),minval(var1) - - write(40) ARW3 - read(30) var1 - print *, "ARW3",maxval(ARW3), maxval(var1), minval(ARW3),minval(var1) - - write(40) ARW4 - read(30) var1 - print *, "ARW4",maxval(ARW4), maxval(var1), minval(ARW4),minval(var1) - - write(40) TSA1 - read(30) var1 - print *, "TSA1",maxval(TSA1), maxval(var1), minval(TSA1),minval(var1) - - write(40) TSA2 - read(30) var1 - print *, "TSA2",maxval(TSA2), maxval(var1), minval(TSA2),minval(var1) - - write(40) TSB1 - read(30) var1 - print *, "TSB1",maxval(TSB1), maxval(var1), minval(TSB1),minval(var1) - - write(40) TSB2 - read(30) var1 - print *, "TSB2",maxval(TSB2), maxval(var1), minval(TSB2),minval(var1) - - write(40) ATAU2 - read(30) var1 - print *, "ATAU2",maxval(ATAU2), maxval(var1), minval(ATAU2),minval(var1) - - write(40) BTAU2 - read(30) var1 - print *, "BTAU2",maxval(BTAU2), maxval(var1), minval(BTAU2),minval(var1) - - write(40) ITY0 - read(30) var1 - print *, "ITY0",maxval(ITY0), maxval(var1), minval(ITY0),minval(var1) - - - print *, 'Wrote parameters' - - do n=1,2 - read (30) var2 - write(40) var2 - end do - - do n=1,20 - read (30) var1 - write(40) var1 - enddo - - do n=1,4 - read (30) var2 - write(40) var2 - end do - - do n=1,4 - read (30) var1 - write(40) var1 - enddo - - read (30) var2 - write(40) var2 - -END PROGRAM replace_params diff --git a/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/obsolete/strip_vegdyn.F90 b/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/obsolete/strip_vegdyn.F90 deleted file mode 100644 index 2fd95d2b8..000000000 --- a/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/mk_restarts/obsolete/strip_vegdyn.F90 +++ /dev/null @@ -1,78 +0,0 @@ -#define VERIFY_(A) if(A /=0)then;print *,'ERROR code',A,'at',__LINE__;call exit(3);endif - -program checkVegDyn - implicit none - -#ifndef __GFORTRAN__ - integer*4 :: iargc - external :: iargc - integer :: ftell - external :: ftell -#endif - character(256) :: str, f_in, f_out - - integer :: m, n - integer :: status - integer :: bpos, epos, nt - integer, parameter :: unit=10 - real, allocatable :: a(:) - integer, allocatable :: veg(:) - integer :: minVegType - integer :: maxVegType - -! Begin - - if (iargc() /= 2) then - call getarg(0,str) - write(*,*) "Usage:",trim(str)," "," " - call exit(2) - end if - - call getarg(1,f_in) - call getarg(2,f_out) - - open(unit=unit, file=trim(f_in), form='unformatted') - -! count the records - m=0 - do while(.true.) - read(unit, end=50, err=200) ! skip to next record - m = m+1 - end do -50 continue - if (m == 1) then - print *, 'File ', trim(f_in), 'contains only only record. Exiting ...' - goto 100 - end if - - rewind(unit) - - open(unit=20, file=trim(f_out), form='unformatted') - -! determine number of tiles by the size of the first record - - bpos=0 - read(unit, err=200) ! skip to next record - epos = ftell(unit) ! ending position of file pointer - nt = (epos-bpos)/4-2 ! record size (in 4 byte words; - rewind(unit) - - allocate(a(nt), stat=status) - VERIFY_(status) - -! Read and copy first record - read (unit) a - write(20) a - - close(20) - -! clean up -100 continue - close(unit) - stop - -! If we are here, something must have gone wrong -200 VERIFY_(200) - -end program checkVegDyn -