Skip to content

Commit

Permalink
Outputted files have a new init function that calls the three functio…
Browse files Browse the repository at this point in the history
…ns that need to be called, cleaning up the driver code a bit. Old output init is renamed to init_variables
  • Loading branch information
scrasmussen committed Apr 19, 2024
1 parent c979e4a commit 862bb28
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 20 deletions.
24 changes: 19 additions & 5 deletions src/io/output_h.f90
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module output_interface
use variable_interface, only : variable_t
use domain_interface, only : domain_t
use meta_data_interface,only : meta_data_t
use options_interface, only : options_t
use time_object, only : Time_type, THREESIXTY, GREGORIAN, NOCALENDAR, NOLEAP

implicit none
Expand Down Expand Up @@ -65,23 +66,36 @@ module output_interface

contains

procedure, public :: init
procedure, public :: add_to_output
procedure, public :: add_variables
procedure, public :: save_file
procedure, public :: set_domain
procedure, public :: set_restart_attribute
procedure, public :: set_restart_variable

procedure, private :: init
procedure, private :: init_variables
procedure, private :: increase_var_capacity
end type

interface

!>----------------------------------------------------------
!! Initialize the object: set domain, add variables, set restart variable
!!
!!----------------------------------------------------------
module subroutine init(this, domain, options, file_date_format)
implicit none
class(output_t), intent(inout) :: this
type(domain_t), intent(in) :: domain
type(options_t), intent(in) :: options
character(len=49), intent(in) :: file_date_format
end subroutine

!>----------------------------------------------------------
!! Initialize the object (e.g. allocate the variables array)
!!
!!----------------------------------------------------------
module subroutine init(this)
module subroutine init_variables(this)
implicit none
class(output_t), intent(inout) :: this
end subroutine
Expand All @@ -106,10 +120,10 @@ module subroutine set_domain(this, domain)
end subroutine

!>----------------------------------------------------------
!! Set the restart attribute to be used when writing global
!! Set the restart variable to be used when writing global
!! attributes
!!----------------------------------------------------------
module subroutine set_restart_attribute(this, restart_time)
module subroutine set_restart_variable(this, restart_time)
implicit none
class(output_t), intent(inout) :: this
character(len=25), intent(in) :: restart_time
Expand Down
26 changes: 19 additions & 7 deletions src/io/output_obj.f90
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,31 @@

contains

module subroutine init(this, domain, options, file_date_format)
implicit none
class(output_t), intent(inout) :: this
type(domain_t), intent(in) :: domain
type(options_t), intent(in) :: options
character(len=49), intent(in) :: file_date_format
call this%set_domain(domain)
call this%add_variables(options%vars_for_restart, domain)
call this%set_restart_variable(options%parameters%restart_time%as_string(file_date_format))
end subroutine init

module subroutine set_domain(this, domain)
class(output_t), intent(inout) :: this
type(domain_t), intent(in) :: domain
integer :: i

if (.not.this%is_initialized) call this%init()
if (.not.this%is_initialized) call this%init_variables()

do i=1,domain%info%n_attrs
call this%add_attribute(domain%info%attributes(i)%name, domain%info%attributes(i)%value)
enddo

end subroutine

module subroutine set_restart_attribute(this, restart_time)
module subroutine set_restart_variable(this, restart_time)
class(output_t), intent(inout) :: this
character(len=25), intent(in) :: restart_time

Expand All @@ -28,14 +39,14 @@ module subroutine set_restart_attribute(this, restart_time)
else
this%restarted_from = restart_time
end if
end subroutine set_restart_attribute
end subroutine set_restart_variable


module subroutine add_to_output(this, variable)
class(output_t), intent(inout) :: this
type(variable_t), intent(in) :: variable

if (.not.this%is_initialized) call this%init()
if (.not.this%is_initialized) call this%init_variables()

if (associated(variable%data_2d).or.associated(variable%data_2dd).or.associated(variable%data_3d)) then

Expand All @@ -56,7 +67,7 @@ module subroutine save_file(this, filename, current_step, time)
type(Time_type), intent(in) :: time
integer :: err

if (.not.this%is_initialized) call this%init()
if (.not.this%is_initialized) call this%init_variables()

! open file
this%filename = filename
Expand Down Expand Up @@ -306,7 +317,8 @@ subroutine add_global_attributes(this)
character(len=64) :: err
integer :: ncid

! if not creating the file, only update restarted_from attribute
! if not creating the file, only update restarted_from attribute. It
! could be opening a previous file whose restart needs to updated
if (this%creating .eqv. .false.) then
call check(nf90_put_att(this%ncfile_id, NF90_GLOBAL, "restarted_from", this%restarted_from))
return
Expand Down Expand Up @@ -533,7 +545,7 @@ subroutine setup_variable(this, var)

end subroutine setup_variable

module subroutine init(this)
module subroutine init_variables(this)
implicit none
class(output_t), intent(inout) :: this

Expand Down
9 changes: 2 additions & 7 deletions src/main/driver.f90
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,8 @@ program icar
if (this_image()==1) print*," frames per output file= ", options%parameters%frames_per_outfile
end if

call restart_dataset%set_domain(domain)
call restart_dataset%add_variables(options%vars_for_restart, domain)
call restart_dataset%set_restart_attribute(options%parameters%restart_time%as_string(file_date_format))

call output_dataset%set_domain(domain)
call output_dataset%add_variables(options%output_options%vars_for_output, domain)
call output_dataset%set_restart_attribute(options%parameters%restart_time%as_string(file_date_format))
call restart_dataset%init(domain, options, file_date_format)
call output_dataset%init(domain, options, file_date_format)

if (options%parameters%restart) then
if (this_image()==1) write(*,*) "Reading restart data"
Expand Down
2 changes: 1 addition & 1 deletion src/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ $(BUILD)restart.o: $(IO)restart.f90 $(BUILD)restart_h.o $(BUILD)time_h.o $(BUILD

$(BUILD)output_h.o: $(IO)output_h.f90 $(BUILD)icar_constants.o $(BUILD)variable_h.o $(BUILD)grid_h.o $(BUILD)meta_data_h.o $(BUILD)domain_h.o

$(BUILD)output_obj.o: $(IO)output_obj.f90 $(BUILD)output_h.o $(BUILD)default_output_metadata.o $(BUILD)time_h.o
$(BUILD)output_obj.o: $(IO)output_obj.f90 $(BUILD)output_h.o $(BUILD)default_output_metadata.o $(BUILD)time_h.o $(BUILD)options_h.o


$(BUILD)boundary_h.o: $(OBJECTS)boundary_h.f90 $(BUILD)options_h.o \
Expand Down

0 comments on commit 862bb28

Please sign in to comment.