<commit_before>!>-----------------------------------------
!! Main Program
!!
!! Initialize options and memory in init_model
!! Read initial conditions in bc_init (from a restart file if requested)
!! initialize physics packages in init_physics (e.g. tiedke and thompson if used)
!! If this run is a restart run, then set start to the restart timestep
!!      in otherwords, ntimesteps is the number of BC updates from the beginning of the entire model
!!      run, not just from the begining of this restart run
!! calculate model time in seconds based on the time between BC updates (in_dt)
!! Calculate the next model output time from current model time + output time delta (out_dt)
!!
!! Finally, loop until ntimesteps are reached updating boundary conditions and stepping the model forward
!!
!!  @author
!!  <NAME> (<EMAIL>)
!!
!!-----------------------------------------
program icar

    use options_interface,  only : options_t
    use domain_interface,   only : domain_t
    use boundary_interface, only : boundary_t
    use output_interface,   only : output_t
    use time_step,          only : step                               ! Advance the model forward in time
    use initialization,     only : init_model
    use timer_interface,    only : timer_t

    implicit none

    type(options_t) :: options
    type(domain_t)  :: domain
    type(boundary_t):: boundary
    type(output_t)  :: dataset
    type(timer_t)   :: initialization_timer, total_timer, input_timer, output_timer, physics_timer

    character(len=1024) :: file_name
    integer :: i

    call total_timer%start()
    call initialization_timer%start()
    !-----------------------------------------
    !  Model Initialization
    !
    ! Reads config options and initializes domain and boundary conditions
    call init_model(options, domain, boundary)

    if (this_image()==1) print*, "Setting up output files"
    ! should be combined into a single setup_output call
    call dataset%set_domain(domain)
    call dataset%add_variables(options%vars_for_restart, domain)

    !-----------------------------------------
    !-----------------------------------------
    !  Time Loop
    !
    !   note that a timestep here is a forcing input timestep O(1-3hr), not a physics timestep O(20-100s)
    write(file_name, '(I4.4,"_",A,".nc")') this_image(), trim(domain%model_time%as_string())

    do i=1,len_trim(file_name)
        if (file_name(i:i)==" ") file_name = file_name(:i-1)//"_"//file_name(i+1:)
        if (file_name(i:i)=="/") file_name = file_name(:i-1)//"-"//file_name(i+1:)
        if (file_name(i:i)==":") file_name = file_name(:i-1)//"-"//file_name(i+1:)
    end do
    file_name = trim(options%parameters%output_file)//trim(file_name)
    i=1

    call initialization_timer%stop()

    do while (domain%model_time < options%parameters%end_time)

        if (this_image()==1) write(*,*) ""
        if (this_image()==1) write(*,*) " ----------------------------------------------------------------------"
        if (this_image()==1) print*, "Updating Boundary conditions"
        call input_timer%start()
        call boundary%update_forcing(options)
        call domain%interpolate_forcing(boundary, update=.True.)
        call input_timer%stop()

        if (this_image()==1) print*, "Running Physics"
        if (this_image()==1) write(*,*) "  Model time = ", trim(domain%model_time%as_string())
        if (this_image()==1) write(*,*) "   End  time = ", trim(options%parameters%end_time%as_string())
        if (this_image()==1) write(*,*) "  Input time = ", trim(boundary%current_time%as_string())


        ! this is the meat of the model physics, run all the physics for the current time step looping over internal timesteps
        call physics_timer%start()
        call step(domain, boundary%current_time, options)
        call physics_timer%stop()

        ! This is an ugly hack until the output object is set up better to handle multiple time steps per file
        ! (that may just need "unlimited" specified in variables?)
        if (this_image()==1) print*, "Writing output file"
        if (i>24) then
            write(file_name, '(I4.4,"_",A,".nc")') this_image(), trim(domain%model_time%as_string())
<commit_msg>Added output of initial conditions in main/driver<commit_after>!>-----------------------------------------
!! Main Program
!!
!! Initialize options and memory in init_model
!! Read initial conditions in bc_init (from a restart file if requested)
!! initialize physics packages in init_physics (e.g. tiedke and thompson if used)
!! If this run is a restart run, then set start to the restart timestep
!!      in otherwords, ntimesteps is the number of BC updates from the beginning of the entire model
!!      run, not just from the begining of this restart run
!! calculate model time in seconds based on the time between BC updates (in_dt)
!! Calculate the next model output time from current model time + output time delta (out_dt)
!!
!! Finally, loop until ntimesteps are reached updating boundary conditions and stepping the model forward
!!
!!  @author
!!  <NAME> (<EMAIL>)
!!
!!-----------------------------------------
program icar

    use options_interface,  only : options_t
    use domain_interface,   only : domain_t
    use boundary_interface, only : boundary_t
    use output_interface,   only : output_t
    use time_step,          only : step                               ! Advance the model forward in time
    use initialization,     only : init_model
    use timer_interface,    only : timer_t

    implicit none

    type(options_t) :: options
    type(domain_t)  :: domain
    type(boundary_t):: boundary
    type(output_t)  :: dataset
    type(timer_t)   :: initialization_timer, total_timer, input_timer, output_timer, physics_timer

    character(len=1024) :: file_name
    integer :: i

    call total_timer%start()
    call initialization_timer%start()
    !-----------------------------------------
    !  Model Initialization
    !
    ! Reads config options and initializes domain and boundary conditions
    call init_model(options, domain, boundary)

    if (this_image()==1) print*, "Setting up output files"
    ! should be combined into a single setup_output call
    call dataset%set_domain(domain)
    call dataset%add_variables(options%vars_for_restart, domain)

    !-----------------------------------------
    !-----------------------------------------
    !  Time Loop
    !
    !   note that a timestep here is a forcing input timestep O(1-3hr), not a physics timestep O(20-100s)
    write(file_name, '(I4.4,"_",A,".nc")') this_image(), trim(domain%model_time%as_string())

    do i=1,len_trim(file_name)
        if (file_name(i:i)==" ") file_name = file_name(:i-1)//"_"//file_name(i+1:)
        if (file_name(i:i)=="/") file_name = file_name(:i-1)//"-"//file_name(i+1:)
        if (file_name(i:i)==":") file_name = file_name(:i-1)//"-"//file_name(i+1:)
    end do
    file_name = trim(options%parameters%output_file)//trim(file_name)
    i=1

    call initialization_timer%stop()

    call output_timer%start()
    call dataset%save_file(trim(file_name), i, domain%model_time)
    call output_timer%stop()
    i = i + 1

    do while (domain%model_time < options%parameters%end_time)

        if (this_image()==1) write(*,*) ""
        if (this_image()==1) write(*,*) " ----------------------------------------------------------------------"
        if (this_image()==1) print*, "Updating Boundary conditions"
        call input_timer%start()
        call boundary%update_forcing(options)
        call domain%interpolate_forcing(boundary, update=.True.)
        call input_timer%stop()

        if (this_image()==1) print*, "Running Physics"
        if (this_image()==1) write(*,*) "  Model time = ", trim(domain%model_time%as_string())
        if (this_image()==1) write(*,*) "   End  time = ", trim(options%parameters%end_time%as_string())
        if (this_image()==1) write(*,*) "  Input time = ", trim(boundary%current_time%as_string())


        ! this is the meat of the model physics, run all the physics for the current time step looping over internal timesteps
        call physics_timer%start()
        call step(domain, boundary%current_time, options)
        call physics_timer%stop()

        ! This is an ugly hack until the output object is set up better to handle multiple time steps per file
        ! (that may just need "unlimited" specified in variables?)
        if (this_image()==1) print*, "Writing output file"
        if (i>24) then
            write(file_name, '(I4.4,"_",A,".nc")') this_image(), trim(domain%model_time%as_string())

{'fraction_non_alphanumeric': 0.17226598702502316, 'fraction_numerical': 0.0079935125115848, 'mean_word_length': 2.6303616484440706, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3175966', 'n_tokens_mistral': 2533, 'n_tokens_neox': 2446, 'n_words': 759}