diff --git a/test_fms/interpolator/test_interpolator2.F90 b/test_fms/interpolator/test_interpolator2.F90 index 076d9b53be..d0e0e6ff06 100644 --- a/test_fms/interpolator/test_interpolator2.F90 +++ b/test_fms/interpolator/test_interpolator2.F90 @@ -35,7 +35,8 @@ program test_interpolator2 use time_manager_mod, only: time_type, set_calendar_type, time_manager_init, & get_date_no_leap, get_date_julian, set_date, set_time, & set_date_no_leap, set_date_julian, & - operator(+), operator(-), time_type_to_real + operator(+), operator(-), time_type_to_real, increment_time, & + leap_year, days_in_month, print_date use fms_mod, only: fms_init use constants_mod, only: PI use platform_mod, only: r4_kind, r8_kind @@ -51,8 +52,8 @@ program test_interpolator2 integer :: calendar_type !> climatology related variables and arrays (made up data) - integer :: nlonlat !< number of latitude and longitudinal center coordinates - integer :: nlonlatb !< number of latitude and longitudinal boundary coordinates + integer :: nlonlat !< number of latitude and longitudinal center coordinates in file + integer :: nlonlatb !< number of latitude and longitudinal boundary coordinates in file integer :: ntime !< number of time slices integer :: npfull !< number of p levels integer :: nphalf !< number of half p levels @@ -72,10 +73,14 @@ program test_interpolator2 real(TEST_INTP_KIND_), allocatable :: latb_mod(:,:) !< model coordinates real(TEST_INTP_KIND_), allocatable :: lonb_mod(:,:) !< model coordinates + type(time_type), allocatable :: model_time_julian(:), model_time_noleap(:) + type(interpolate_type) :: o3 !< recyclable interpolate_type + logical :: yearly, daily, noleap + logical :: test_daily_julian=.true., test_daily_noleap=.false., test_yearly_noleap=.false., test_yearly_julian=.false. - integer :: nml_unit_var + integer :: nml_unit_var=99 character(*), parameter :: nml_file='test_interpolator.nml' NAMELIST / test_interpolator_nml / test_daily_noleap, test_daily_julian, test_yearly_noleap, test_yearly_julian @@ -83,34 +88,49 @@ program test_interpolator2 read(unit=nml_unit_var, nml=test_interpolator_nml) close(nml_unit_var) + if(test_daily_noleap) write(*,*) ' ** DAILY FILE CALENDAR NOLEAP ** FILE CALENDAR NOLEAP ** FILE CALENDAR NOLEAP' + if(test_daily_julian) write(*,*) ' ** DAILY FILE CALENDAR JULIAN ** FILE CALENDAR JULIAN ** FILE CALENDAR JULIAN' + if(test_yearly_noleap) write(*,*) ' ** YEARLY FILE CALENDAR NOLEAP ** FILE CALENDAR NOLEAP ** FILE CALENDAR NOLEAP' + if(test_yearly_julian) write(*,*) ' ** YEARLY FILE CALENDAR JULIAN ** FILE CALENDAR JULIAN ** FILE CALENDAR JULIAN' + call fms_init call time_manager_init !> set data - if(test_daily_noleap) call set_write_data(nlonlat_in=10, nlonlat_mod_in=10, ntime_in=5, npfull_in=3, daily=.true., noleap=.true.) - if(test_daily_julian) call set_write_data(nlonlat_in=10, nlonlat_mod_in=10, ntime_in=5, npfull_in=3, daily=.true., noleap=.false.) - if(test_yearly_noleap) call set_write_data(nlonlat_in=10, nlonlat_mod_in=10, ntime_in=5, npfull_in=3, yearly=.true., noleap=.true.) - if(test_yearly_julian) call set_write_data(nlonlat_in=10, nlonlat_mod_in=10, ntime_in=5, npfull_in=3, yearly=.true., noleap=.false.) + if(test_daily_noleap) then + call set_parameters(nlonlat_in=10, nlonlat_mod_in=10, ntime_in=20, npfull_in=3, & + daily_in=.true., yearly_in=.false., noleap_in=.true.) + else if(test_daily_julian) then + call set_parameters(nlonlat_in=10, nlonlat_mod_in=10, ntime_in=20, npfull_in=3, & + daily_in=.true., yearly_in=.false., noleap_in=.false.) + else if(test_yearly_noleap) then + call set_parameters(nlonlat_in=10, nlonlat_mod_in=10, ntime_in=20, npfull_in=3, & + daily_in=.false., yearly_in=.true., noleap_in=.true.) + else if(test_yearly_julian) then + call set_parameters(nlonlat_in=10, nlonlat_mod_in=10, ntime_in=20, npfull_in=3, & + daily_in=.false., yearly_in=.true., noleap_in=.false.) + end if + call set_and_write_data !> test interpolator_init with model JULIAN calendar - calendar_type=2 !< JULIAN calendar + calendar_type=2 !< JULIAN calendar for model call set_calendar_type(calendar_type) - call run_test_set('JULIAN') + call run_test_set !--------------------------------------------------------- !> test interpolator_init with model NOLEAP calendar - calendar_type=4 !< NOLEAP calendar + calendar_type=4 !< NOLEAP calendar for model call set_calendar_type(calendar_type) - call run_test_set('NOLEAP') + call run_test_set !---------------------------------------------------------------------------------- !> Need to deallocate arrays because a new NetCDF File will be written out - call deallocate_arrays() + !call deallocate_arrays() !> test interpolator_no_time_axis !! Write out new set of data that will have a time axis, but will have "0" time points !! because that's how interpolator_init is set up. - call set_write_data(nlonlat_in=10, nlonlat_mod_in=10, ntime_in=0, npfull_in=3) - call test_interpolator_init(o3) - write(*,*) ' ===== test_intepolator_no_time_axis =======' - call test_interpolator_no_time_axis(o3) + !call set_write_data(nlonlat_in=10, nlonlat_mod_in=10, ntime_in=0, npfull_in=3) + !call test_interpolator_init(o3) + !write(*,*) ' ===== test_intepolator_no_time_axis =======' + !call test_interpolator_no_time_axis(o3) contains !===============================================! @@ -129,7 +149,7 @@ subroutine test_interpolator_init(clim_type) end subroutine test_interpolator_init !===============================================! - subroutine test_interpolator(clim_type) + subroutine test_interpolator(clim_type, model_time) !> call the variants of interpolator (4D-2d) that interpolates data at a given time-point !! The tests here do not test the "no_axis" interpolator routines @@ -138,10 +158,9 @@ subroutine test_interpolator(clim_type) implicit none type(interpolate_type), intent(inout) :: clim_type - real(TEST_INTP_KIND_), dimension(nlonlat,nlonlat,npfull,1) :: interp_data !< last column, there is only one field - real(TEST_INTP_KIND_), dimension(nlonlat,nlonlat,nphalf) :: phalf - type(time_type) :: model_time, start_time - type(time_type) :: yearly_model_time(5) + type(time_type), dimension(ntime), intent(in) :: model_time + real(TEST_INTP_KIND_), dimension(nlonlat_mod,nlonlat_mod,npfull,1) :: interp_data !< last column, there is only one field + real(TEST_INTP_KIND_), dimension(nlonlat_mod,nlonlat_mod,nphalf) :: phalf integer :: itime, i, j, k, l phalf(:,:,1)=0.0000_lkind @@ -149,43 +168,30 @@ subroutine test_interpolator(clim_type) phalf(:,:,3)=0.0004_lkind phalf(:,:,4)=0.0005_lkind - if(test_yearly_noleap .or. test_yearly_julian) then - yearly_model_time(1)=set_date(1850,2, 1,0,0,0) - yearly_model_time(2)=set_date(1852,2,28,0,0,0) - yearly_model_time(3)=set_date(1900,1, 2,0,0,0) - yearly_model_time(4)=set_date(1905,1, 1,0,0,0) - yearly_model_time(5)=set_date(1951,12,5,0,0,0) - end if - - do itime=1, ntime - - !> only when clim_time is not an integer - if(test_daily_noleap .or. test_daily_julian) model_time=get_complicated_time(clim_time(itime)) - - !call print_date(model_time) + do itime=2, ntime-1 !> test interpolator_4D_r4/8 - call interpolator(clim_type, model_time, phalf, interp_data, 'ozone') + call interpolator(clim_type, model_time(itime), phalf, interp_data, 'ozone') do i=1, npfull - do j=1, nlonlat - do k=1, nlonlat + do j=1, nlonlat_mod + do k=1, nlonlat_mod call check_answers(interp_data(k,j,i,1), ozone(k,j,i,itime), tol, 'test interpolator_4D') end do end do end do !> test interpolator_3_r4/8 - call interpolator(clim_type, model_time, phalf, interp_data(:,:,:,1), 'ozone') + call interpolator(clim_type, model_time(itime), phalf, interp_data(:,:,:,1), 'ozone') do i=1, npfull - do j=1, nlonlat - do k=1, nlonlat + do j=1, nlonlat_mod + do k=1, nlonlat_mod call check_answers(interp_data(k,j,i,1), ozone(k,j,i,itime), tol, 'test interpolator_3D') end do end do end do !> test interpolator_2D_r4/8 - call interpolator(clim_type, model_time, interp_data(:,:,1,1), 'ozone') + call interpolator(clim_type, model_time(itime), interp_data(:,:,1,1), 'ozone') do j=1, nlonlat_mod do k=1, nlonlat_mod call check_answers(interp_data(k,j,1,1), ozone(k,j,1,itime), tol, 'test interpolator_2D') @@ -193,8 +199,8 @@ subroutine test_interpolator(clim_type) end do !> Test obtain_interpolator_time_slices - call obtain_interpolator_time_slices(clim_type,model_time) - call interpolator(clim_type, model_time, interp_data(:,:,1,1), 'ozone') + call obtain_interpolator_time_slices(clim_type,model_time(itime)) + call interpolator(clim_type, model_time(itime), interp_data(:,:,1,1), 'ozone') call unset_interpolator_time_flag(clim_type) do j=1, nlonlat_mod do k=1, nlonlat_mod @@ -275,7 +281,8 @@ subroutine test_interpolate_type_eq type(interpolate_type) :: o3_copy o3_copy = o3 - call test_interpolator(o3_copy) + if(calendar_type==2) call test_interpolator(o3_copy, model_time_julian) + if(calendar_type==4) call test_interpolator(o3_copy, model_time_noleap) end subroutine test_interpolate_type_eq !===============================================! @@ -302,70 +309,37 @@ subroutine test_query_interpolator end subroutine test_query_interpolator !===============================================! - subroutine run_test_set(test_model_calendar) + subroutine run_test_set - character(*), intent(in) :: test_model_calendar + implicit none + integer :: i + + if(calendar_type==2) write(*,*) "** MODEL CALENDAR JULIAN ** MODEL CALENDAR JULIAN ** MODEL CALENDAR JULIAN **" + if(calendar_type==4) write(*,*) "** MODEL CALENDAR NOLEAP ** MODEL CALENDAR NOLEAP ** MODEL CALENDAR NOLEAP **" - write(*,*) ' ===== test_interpolator_init'//trim(test_model_calendar)//' =====' + write(*,*) ' ===== test_interpolator_init =====' call test_interpolator_init(o3) !> test interpolator 2D-4D - write(*,*) ' ===== test_intepolator'//trim(test_model_calendar)//' =====' - call test_interpolator(o3) + if(calendar_type==2) call test_interpolator(o3, model_time_julian) + if(calendar_type==4) call test_interpolator(o3, model_time_noleap) !> test interpolate_type_eq - !! This test has been commented out and will be included - !! in the testing suite once fileobj cp is added into - !! test_interpolate_type_eq + !! This test has been commented out and will be included in the testing suite once fileobj cp is added into !write(*,*) '===== test_interpolate_type_eq =====' !call test_interpolate_type_eq() !> test query_interpolator - write(*,*) ' ===== test_query_interpolator'//trim(test_model_calendar)//' =====' + write(*,*) ' ===== test_query_interpolator =====' call test_query_interpolator() !> test interpolator end - write(*,*) ' ===== test_interpolator_end'//trim(test_model_calendar)//' =====' + write(*,*) ' ===== test_interpolator_end =====' call test_interpolator_end(o3) end subroutine run_test_set !===============================================! - function get_complicated_time(days_in) - - implicit none - type(time_type) :: get_complicated_time - real(TEST_INTP_KIND_), intent(in) :: days_in - - integer, parameter :: seconds_per_day=86400 - type(time_type) :: tmp_time, base_time - integer :: yr, mo, dy, hr, mn, sc - real(TEST_INTP_KIND_) :: frac_day - - !1849,1,1 - if(test_daily_noleap.or.test_yearly_noleap) base_time=set_date_no_leap(1849,1,1,0,0,0) - if(test_daily_julian.or.test_yearly_julian) base_time=set_date_julian(1849,1,1,0,0,0) - tmp_time = set_time(0,int(days_in)) + base_time - frac_day = days_in - real(int(days_in),TEST_INTP_KIND_) - if(test_daily_noleap .and. calendar_type==2) then - !> daily file calendar = noleap, model calendar = julian - call get_date_no_leap(tmp_time, yr, mo, dy, hr, mn, sc) - get_complicated_time=set_date(yr, mo, dy, mn, sc) - else if(test_daily_noleap .and. calendar_type==4) then - !> daily file calendar = noleap, model calendar = noleap - get_complicated_time=set_time(int(seconds_per_day*frac_day),int(days_in))+base_time - else if(test_daily_julian .and. calendar_type==2) then - !> daily file calendar = julian, model_calendar = julian - get_complicated_time=set_time(int(seconds_per_day*frac_day),int(days_in))+base_time - else if(test_daily_julian .and. calendar_type==4) then - !> daily file calendar = julian, model calendar = noleap - call get_date_julian(tmp_time, yr, mo, dy, hr, mn, sc) - get_complicated_time=set_date(yr, mo, dy, hr, mn, sc) - end if - - - end function get_complicated_time - !===============================================! subroutine check_answers(results, answers, tol, whoami) implicit none diff --git a/test_fms/interpolator/test_interpolator2.sh b/test_fms/interpolator/test_interpolator2.sh index dfe9656613..bd41548635 100755 --- a/test_fms/interpolator/test_interpolator2.sh +++ b/test_fms/interpolator/test_interpolator2.sh @@ -83,6 +83,8 @@ test_expect_success "test_interpolator2 daily r4 noleap unit tests" 'mpirun -n 1 test_expect_success "test_interpolator2 daily r8 noleap unit tests" 'mpirun -n 1 ./test_interpolator2_r8' #rm -rf INPUT *.nc test_interpolator.nml +exit + #Run the yearly interpolator tests when the file calendar is in units of years and calendar type is NOLEAP cat < test_interpolator.nml &test_interpolator_nml diff --git a/test_fms/interpolator/test_interpolator_write_climatology.inc b/test_fms/interpolator/test_interpolator_write_climatology.inc index 5247e1dcd2..52e02f7f4c 100644 --- a/test_fms/interpolator/test_interpolator_write_climatology.inc +++ b/test_fms/interpolator/test_interpolator_write_climatology.inc @@ -19,25 +19,11 @@ !> This file contains subroutines that initialize data and write out the climatology file. -subroutine write_climatology_file(daily, yearly, noleap) +subroutine write_climatology_file implicit none - logical, intent(in) :: daily, yearly - logical, intent(in), optional :: noleap - type(FmsNetcdfFile_t) :: fileobj - integer :: i,j,k,l, itime - integer :: stringlen - character(100) :: mystring - logical :: noleap2, daily2, yearly2 - - if( daily.eq.yearly) then - call mpp_error(WARNING, "write_climatology_file only daily, monthly, or yearly must be true. Going with daily") - daily2=.true. - yearly2=.false. - end if - noleap2=.false. ; if(present(noleap)) noleap2=noleap ! write netcdf file if(open_file(fileobj, 'INPUT/'//trim(ncfile), 'overwrite')) then @@ -55,11 +41,10 @@ subroutine write_climatology_file(daily, yearly, noleap) !if(ntime /=0 ) then call register_field(fileobj, 'time', 'double', dimensions=(/'time'/)) call register_string_attribute(fileobj, 'time', 'axis', 'T') - if(noleap2) call register_string_attribute(fileobj, 'time', 'calendar', 'noleap') - if(.not.noleap2) call register_string_attribute(fileobj, 'time', 'calendar', 'julian') - call register_string_attribute(fileobj, 'time', 'climatology', '1979-01-01 00:00:00, 1998-01-01 00:00:00') - if(daily) call register_string_attribute(fileobj, 'time', 'units', 'days since 1849-01-01 00:00:00') - if(yearly) call register_string_attribute(fileobj, 'time', 'units', 'years since 1849-01-01 00:00:00') + if(noleap) call register_string_attribute(fileobj, 'time', 'calendar', 'noleap') + if(.not.noleap) call register_string_attribute(fileobj, 'time', 'calendar', 'julian') + if(daily) call register_string_attribute(fileobj, 'time', 'units', 'days since 1849-01-01 00:00:00') + if(yearly) call register_string_attribute(fileobj, 'time', 'units', 'years since 1849-01-01 00:00:00') !end if !lon axes @@ -132,30 +117,6 @@ subroutine register_string_attribute(fileobj, variable, attribute, att_value) end subroutine register_string_attribute !===============================================! -subroutine allocate_arrays() - - implicit none - integer :: ntime2 - - ntime2=ntime - if(ntime==0) ntime2=1 - - allocate( lat(nlonlat), & - lon(nlonlat), & - latb(nlonlatb), & - lonb(nlonlatb), & - clim_time(ntime2),& - pfull(npfull), & - phalf(nphalf), & - ozone(nlonlat, nlonlat, npfull, ntime2) ) - - allocate( lat_mod(nlonlat_mod, nlonlat_mod), & - lon_mod(nlonlat_mod, nlonlat_mod), & - latb_mod(nlonlatb_mod, nlonlatb_mod), & - lonb_mod(nlonlatb_mod, nlonlatb_mod) ) - -end subroutine allocate_arrays -!===============================================! subroutine deallocate_arrays() implicit none @@ -164,6 +125,8 @@ subroutine deallocate_arrays() latb, & lonb, & clim_time, & + model_time_noleap, & + model_time_julian, & pfull, & phalf, & lat_mod, & @@ -174,18 +137,11 @@ subroutine deallocate_arrays() end subroutine deallocate_arrays !===============================================! -subroutine set_write_data(nlonlat_in, nlonlat_mod_in, ntime_in, npfull_in, daily, yearly, noleap) +subroutine set_parameters(nlonlat_in, nlonlat_mod_in, ntime_in, npfull_in, daily_in, yearly_in, noleap_in) implicit none integer, intent(in) :: nlonlat_in, nlonlat_mod_in, ntime_in, npfull_in - logical, intent(in), optional :: daily, yearly, noleap - - logical :: daily_in, monthly_in, yearly_in, noleap_in - - daily_in=.true. ; yearly_in=.false. ; noleap_in=.false. - if(present(daily)) daily_in=daily - if(present(yearly)) yearly_in=yearly - if(present(noleap)) noleap_in=noleap + logical, intent(in) :: daily_in, yearly_in, noleap_in nlonlat = nlonlat_in !< number of latitude and longitudinal center coordinates nlonlatb = nlonlat_in+1 !< number of latitude and longitudinal boundary coordinates @@ -194,16 +150,25 @@ subroutine set_write_data(nlonlat_in, nlonlat_mod_in, ntime_in, npfull_in, daily ntime = ntime_in !< number of time slices npfull = npfull_in !< number of p levels nphalf = npfull_in+1 !< number of half p levels - call allocate_arrays() + + daily = daily_in + yearly = yearly_in + noleap = noleap_in + +end subroutine set_parameters +!===============================================! +subroutine set_and_write_data + + implicit none + if( ntime /= 0) call set_clim_time() call set_latlon_b() + call set_latlon_b_mod() call set_pfullhalf() call set_ozone() - call write_climatology_file(daily_in, yearly_in, noleap) + call write_climatology_file - call set_latlon_b_mod() - -end subroutine set_write_data +end subroutine set_and_write_data !===============================================! subroutine set_clim_time() @@ -211,45 +176,79 @@ subroutine set_clim_time() integer :: i type(time_type) :: base_time, tmp_time, tmp_time2 + integer :: l, ii, yr, mo, dy, hr, mn, sc + integer :: ntime2 + + if(allocated(clim_time)) deallocate(clim_time) + if(allocated(model_time_julian)) deallocate(model_time_julian) + if(allocated(model_time_noleap)) deallocate(model_time_noleap) + allocate(clim_time(ntime)) + allocate(model_time_julian(ntime), model_time_noleap(ntime)) + + !write(*,*) ' -- SETTING TIME -- ' - if(test_daily_noleap .or. test_daily_julian) then + if(test_daily_noleap) then + base_time=set_date_no_leap(1849,1,1,0,0,0) do i=1, ntime - clim_time(i)=2*real(i,lkind) + real(i,lkind)/4.0_lkind + tmp_time=increment_time(base_time,0,(365+5)*i) + call get_date_no_leap(tmp_time, yr, mo, dy, hr, mn, sc) + model_time_julian(i)=set_date_julian(yr, mo, dy, hr, mn, sc) + model_time_noleap(i)=set_date_no_leap(yr, mo, dy, hr, mn, sc) + clim_time(i)=time_type_to_real(tmp_time-base_time)/86400._lkind + call set_calendar_type(4) + call print_date(tmp_time) + call set_calendar_type(0) end do - else if(test_yearly_julian) then + else if(test_daily_julian) then base_time=set_date_julian(1849,1,1,0,0,0) - ! 1 - tmp_time=set_date_julian(1850,2,1,0,0,0) - clim_time(1)=time_type_to_real(tmp_time-base_time)/365.0_lkind - ! 2 - tmp_time=set_date_julian(1852,2,28,0,0,0) ; tmp_time2=set_date_julian(1852,1,1,0,0,0) - clim_time(2)=real(1852-1849,lkind) + time_type_to_real(tmp_time-tmp_time2)/366.0_lkind - !3 - tmp_time=set_date_julian(1900,1,2,0,0,0) ; tmp_time2=set_date_julian(1900,1,1,0,0,0) - clim_time(3)=real(1900-1849,lkind) + time_type_to_real(tmp_time-tmp_time2)/366.0_lkind - !4 - tmp_time=set_date_julian(1905,1,1,0,0,0) - clim_time(4)=real(1905-1849,lkind) - !5 - tmp_time=set_date_julian(1951,12,5,0,0,0) ; tmp_time2=set_date_julian(1951,1,1,0,0,0) - clim_time(5)=real(1951-1849,lkind) + time_type_to_real(tmp_time-tmp_time2)/365.0_lkind - else if (test_yearly_noleap) then + do i=1, ntime + tmp_time=increment_time(base_time,0, (365+5)*i) + call get_date_julian(tmp_time, yr, mo, dy, hr, mn, sc) + model_time_julian(i)=set_date_julian(yr, mo, dy, hr, mn, sc) + model_time_noleap(i)=set_date_no_leap(yr, mo, dy, hr, mn, sc) + clim_time(i)=time_type_to_real(tmp_time-base_time)/86400._lkind + call set_calendar_type(2) + call print_date(tmp_time) + call set_calendar_type(0) + end do + else if(test_yearly_noleap) then base_time=set_date_no_leap(1849,1,1,0,0,0) - ! 1 - tmp_time=set_date_no_leap(1850,2,1,0,0,0) - clim_time(1)=time_type_to_real(tmp_time-base_time)/365.0_lkind/86400.0_lkind - ! 2 - tmp_time=set_date_no_leap(1852,2,28,0,0,0) ; tmp_time2=set_date_no_leap(1852,1,1,0,0,0) - clim_time(2)=real(1852-1849,lkind) + time_type_to_real(tmp_time-tmp_time2)/365.0_lkind/86400._lkind - !3 - tmp_time=set_date_no_leap(1900,1,2,0,0,0) ; tmp_time2=set_date_no_leap(1900,1,1,0,0,0) - clim_time(3)=real(1900-1849,lkind) + time_type_to_real(tmp_time-tmp_time2)/365.0_lkind/86400._lkind - !4 - tmp_time=set_date_no_leap(1905,1,1,0,0,0) - clim_time(4)=real(1905-1849,lkind) - !5 - tmp_time=set_date_no_leap(1951,12,5,0,0,0) ; tmp_time2=set_date_no_leap(1951,1,1,0,0,0) - clim_time(5)=real(1951-1849,lkind) + time_type_to_real(tmp_time-tmp_time2)/365.0_lkind/86400._lkind + do i=1, ntime + tmp_time=increment_time(base_time,0,(365+3)*i) + call get_date_no_leap(tmp_time, yr, mo, dy, hr, mn, sc) + model_time_julian(i)=set_date_julian(yr, mo, dy, hr, mn, sc) + model_time_noleap(i)=set_date_no_leap(yr, mo, dy, hr, mn, sc) + clim_time(i)=real(yr-1849,lkind) + do ii=1, mo-1 + select case(ii) + case(1,3,5,7,8,10,12) ; clim_time(i) = clim_time(i) + 31.0_lkind/365._lkind + case(2) ; clim_time(i) = clim_time(i) + real(28,lkind)/365._lkind + case(4,6,9,11) ; clim_time(i) = clim_time(i) + 30.0_lkind/365._lkind + end select + end do + clim_time(i) = clim_time(i) + (dy-1)/real(365,lkind) + end do + else if(test_yearly_julian) then + base_time=set_date_julian(1849,1,1,0,0,0) + call set_calendar_type(2) + do i=1, ntime + tmp_time=increment_time(base_time,0,(365+4)*i) + call get_date_julian(tmp_time, yr, mo, dy, hr, mn, sc) + model_time_julian(i)=set_date_julian(yr,mo,dy,hr,mn,sc) + model_time_noleap(i)=set_date_no_leap(yr,mo,dy,hr,mn,sc) + clim_time(i)=real(yr-1849,lkind) + l=0 ; if(leap_year(tmp_time)) l=l+1 + do ii=1, mo-1 + select case(ii) + case(1,3,5,7,8,10,12) ; clim_time(i) = clim_time(i) + 31.0_lkind/real(365+l,lkind) + case(2) ; clim_time(i) = clim_time(i) + real(28+l,lkind)/real(365+l,lkind) + case(4,6,9,11) ; clim_time(i) = clim_time(i) + 30.0_lkind/real(365+l,lkind) + end select + end do + clim_time(i) = clim_time(i) + (dy-1)/real(365+l,lkind) + !call print_date(tmp_time) + end do + call set_calendar_type(0) end if end subroutine set_clim_time @@ -259,6 +258,14 @@ subroutine set_latlon_b() implicit none integer :: i + if(allocated(lat)) deallocate(lat) + if(allocated(lon)) deallocate(lon) + if(allocated(latb)) deallocate(latb) + if(allocated(lonb)) deallocate(lonb) + + allocate(lat(nlonlat), lon(nlonlat)) + allocate(latb(nlonlat+1), lonb(nlonlat+1)) + do i=1, nlonlat lat(i)= real(2*i-1,TEST_INTP_KIND_) lon(i)= real(2*i-1,TEST_INTP_KIND_) @@ -281,20 +288,26 @@ subroutine set_latlon_b_mod implicit none integer :: i, j - !> the model grid and the climatology grid are the same - do i=1, nlonlat - lon_mod(:,i) = real(2*i-1,TEST_INTP_KIND_) - lat_mod(i,:) = real(2*i-1,TEST_INTP_KIND_) - end do + if(allocated(lat_mod)) deallocate(lat_mod) + if(allocated(lon_mod)) deallocate(lon_mod) + if(allocated(latb_mod)) deallocate(latb_mod) + if(allocated(lonb_mod)) deallocate(lonb_mod) - lonb_mod(1:nlonlatb,1)=1.0_lkind - latb_mod(1,1:nlonlatb)=1.0_lkind - do i=1, nlonlat-1 - lonb_mod(1:nlonlatb,i+1)=2*i - latb_mod(i+1,1:nlonlatb)=2*i + allocate(lat_mod(nlonlat_mod,nlonlat_mod), lon_mod(nlonlat_mod,nlonlat_mod)) + allocate(latb_mod(nlonlatb_mod,nlonlatb_mod), lonb_mod(nlonlatb_mod,nlonlatb_mod)) + + !> nlonlat = nlonlat_mod + ! the model coordinates are the same as the file coordinates + do i=1, nlonlat_mod + lat_mod(i,:) = lat(i) + lon_mod(:,i) = lon(i) + end do + !> nlonlatb_mod = nlonlatb + !! the model coordinates are the same as the file coordinates + do i=1, nlonlatb_mod + latb_mod(i,:) = latb(i) + lonb_mod(:,i) = lonb(i) end do - lonb_mod(1:nlonlatb,nlonlatb)=real(2*nlonlat-1,TEST_INTP_KIND_) - latb_mod(nlonlatb,1:nlonlatb)=real(2*nlonlat-1,TEST_INTP_KIND_) !> convert from degrees to radians lon_mod = lon_mod*real(PI,TEST_INTP_KIND_)/180.0_lkind @@ -310,6 +323,10 @@ subroutine set_pfullhalf() implicit none integer :: i + if(allocated(pfull)) deallocate(pfull) + if(allocated(phalf)) deallocate(phalf) + allocate(pfull(npfull), phalf(nphalf)) + do i=1, npfull pfull(i) = 0.0001_lkind * real(i-1,TEST_INTP_KIND_) end do @@ -329,8 +346,10 @@ subroutine set_ozone() integer :: ntime2 ntime2=ntime - if(ntime == 0 ) ntime2=1 + if(allocated(ozone)) deallocate(ozone) + allocate(ozone(nlonlat, nlonlat, npfull, ntime2)) + if(ntime == 0 ) ntime2=1 do i=1, ntime2 do j=1, npfull do k=1, nlonlat