histhandlermod.f90

来自「CCSM Research Tools: Community Atmospher」· F90 代码 · 共 531 行 · 第 1/2 页

F90
531
字号
! Calendar calculations! -----------------------------------------------------------------! get current step    nstep = get_nstep()! Set calendar for current time step    call get_curr_date (yr, mon, day, mcsec)     mcdate = yr*10000 + mon*100 + day! Set calendar for current for previous time step    call get_prev_date (yrm1, monm1, daym1, mcsecm1)    mcdatem1 = yrm1*10000 + monm1*100 + daym1! Set elapased time since reference date    call get_curr_time(mdcur, mscur)  ! -----------------------------------------------------------------! Process all active history files! -----------------------------------------------------------------! loop over history tapes    do m = 1, nhist! Skip nstep=0 if monthly average       if (nstep==0 .and. hist_nhtfrq(m)==0) cycle! Determine if end of history interval       ehi(m) = .false.       if (hist_nhtfrq(m)==0) then   !monthly average          if (mon /= monm1) ehi(m) = .true.       else           if (mod(nstep,hist_nhtfrq(m)) == 0) ehi(m) = .true.       end if! Calendar info for current time sample: start of time interval       if (nbeghis(m) == 1) then          mcdate_i(m) = mcdate          mcsec_i(m) = mcsec          mdcur_i(m) = mdcur          mscur_i(m) = mscur       end if    end do    return  end subroutine histend!=======================================================================  subroutine close_and_disp (lhisdisp, lstop, lremovh) !----------------------------------------------------------------------- ! ! Purpose: ! Determine logic for closeing and/or disposing history file! Sets values for logical variables lhisdisp, lstop, lremovh (arguments) ! and lrestwrt (module variable)!! Method: !! Logic to determine if time to dispose history file:! o if history file is full (ntim = mfilt) ! o if have reached end of run !! Logic to determine if time to write a restart file:! o if run through flux coupler!   o when coupler gives signal to write restart!   o when coupler gives signal to stop ! o if not run through flux coupler!   o when primary history file is closed and disposed! ! Logic to determine if time to remove history file:! o remove history files unless this is end of run or!   history file is not full. !! Author: Mariana Vertenstein! !-----------------------------------------------------------------------    use clm_varctl  , only : hist_mfilt     use histFileMod , only : nhist, ntim#if (defined COUP_CSM)    use clm_csmMod         #endif    use time_manager, only : is_last_step! ------------------------ arguments ------------------------------    logical, intent(out) :: lhisdisp(nhist) !true => save and dispose history file     logical, intent(out) :: lstop           !true => last time step of run     logical, intent(out) :: lremovh(nhist)  !true => remove local history file after dispose! -----------------------------------------------------------------! ------------------------ local variables ------------------------    integer m        ! loop index! -----------------------------------------------------------------    lstop = .false.    lrestwrt = .false.    lhisdisp(:) = .false.    lremovh(:) = .false.#if (defined OFFLINE) || (defined COUP_CAM)! If end of run dispose all history files and write restart    if (is_last_step()) then       lstop = .true.       lrestwrt = .true.       lhisdisp(:) = .true.       lremovh(:) = .false.       RETURN    endif! If time to dispose master history file then dispose all ! history files and write restart    if (ntim(1)==hist_mfilt(1))  then       lrestwrt = .true.       lhisdisp(:) = .true.       lremovh(1) = .true.       do m = 2,nhist          if (ntim(m)==hist_mfilt(m)) then             lremovh(m) = .true.          else             lremovh(m) = .false.          endif       end do       RETURN    endif! If not end of run or time to dispose master history file ! then determine if time to dispose individual auxillary files    lrestwrt = .false.    do m = 2,nhist        if (ntim(m)==hist_mfilt(m)) then          lhisdisp(m) = .true.          lremovh(m) = .true.       endif    end do    RETURN#elif (defined COUP_CSM)! If coupler says that next time step is end of run then ! dispose all history files and write restart    if (csmstop_next) then       lstop = .true.       lrestwrt = .true.       lhisdisp(:) = .true.       lremovh(:) = .false.       RETURN    endif! If coupler says to write restart then dispose all history! files and write restart    if (csmrstrt) then       lhisdisp(:) = .true.       lrestwrt = .true.       lremovh(:) = .true.       RETURN    endif! Otherwise check if file is full and dispose if it is    lrestwrt = .false.    lremovh(:) = .false.    do m=1,nhist       if (ntim(m) == hist_mfilt(m)) then          lhisdisp(m) = .true.          lremovh(m) = .true.       endif    end do    lremovh(:) = .true.    RETURN#endif    return100 continue  end subroutine close_and_disp!=======================================================================  logical function do_restwrite()!----------------------------------------------------------------------- ! ! Purpose: ! Determine if restart dataset is to be written at this time step!! Method: !! Author: Mariana Vertenstein! !-----------------------------------------------------------------------        do_restwrite = .false.    if (lrestwrt) do_restwrite = .true.  end function do_restwrite!=======================================================================  character(len=256) function set_hist_filename (hist_freq, hist_file)!----------------------------------------------------------------------- ! ! Purpose: ! Determine history dataset filenames! ! Method: ! ! Author: Mariana Vertenstein! !-----------------------------------------------------------------------    use clm_varctl  , only : caseid    use time_manager, only : get_curr_date, get_prev_date! ------------------------ arguments ------------------------------    integer, intent(in)  :: hist_freq   !history file frequency    integer, intent(in)  :: hist_file   !history file index ! -----------------------------------------------------------------! ------------------------ local variables ------------------------    character(len=256) :: cdate       !date char string    character(len=  1) :: hist_index  !0, 1 or 2 (currently)    integer :: day                    !day (1 -> 31)    integer :: mon                    !month (1 -> 12)    integer :: yr                     !year (0 -> ...)    integer :: sec                    !seconds into current day! -----------------------------------------------------------------    if (hist_freq == 0 ) then   !monthly       call get_prev_date (yr, mon, day, sec)        write(cdate,'(i4.4,"-",i2.2)') yr,mon    else                        !other        call get_curr_date (yr, mon, day, sec)        write(cdate,'(i4.4,"-",i2.2,"-",i2.2,"-",i5.5)') yr,mon,day,sec    endif    write(hist_index,'(i1.1)') hist_file - 1    set_hist_filename = "./"//trim(caseid)//".clm2.h"//hist_index//"."//&         trim(cdate)//".nc"  end function set_hist_filename!=======================================================================end module histHandlerMod

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?