submodule(diagnostics_lineout_m) diagnostics_lineout_params_s !! Parameters for the diagnostics module related to lineouts use error_handling_grillix_m, only: handle_error use status_codes_grillix_m, only : GRILLIX_ERR_NAMELIST use technical_constants_m, only : PATHLEN_MAX implicit none ! Local definition of parameters and setting of default values character(len=:), allocatable :: & lineout_select, & lineout_path namelist / diag_lineout / & lineout_select, & lineout_path contains module subroutine read_params_lineout(self, filepath) class(params_diag_lineout_t), intent(inout) :: self character(len=*), intent(in) :: filepath character(len=PATHLEN_MAX), parameter :: blank1024 = '' integer :: i, io_unit, io_error character(len=256) :: io_errmsg lineout_select = 'none' // blank1024 lineout_path = blank1024 io_unit = 22 open(unit = io_unit, file = filepath, status = 'old', action = 'read', & iostat = io_error, iomsg = io_errmsg) if (io_error /= 0) then call handle_error(io_errmsg, GRILLIX_ERR_NAMELIST, __LINE__, __FILE__) endif read(io_unit, nml = diag_lineout, & iostat = io_error, iomsg = io_errmsg) if (io_error /= 0) then call handle_error(io_errmsg, GRILLIX_ERR_NAMELIST, __LINE__, __FILE__) endif close(io_unit) self%lineout_select = trim(adjustl(lineout_select)) self%lineout_path = trim(adjustl(lineout_path)) ! Scan lineout file if ( self%lineout_select /= 'none' ) then open(unit = io_unit, file = self%lineout_path, status = 'old', & action = 'read', iostat = io_error, iomsg = io_errmsg) if (io_error /= 0) then call handle_error(io_errmsg, GRILLIX_ERR_NAMELIST, __LINE__, __FILE__) endif ! Read line by line read(io_unit, *, iostat = io_error, iomsg = io_errmsg) self%n_lineouts if (io_error /= 0) then call handle_error(io_errmsg, GRILLIX_ERR_NAMELIST, __LINE__, __FILE__) endif allocate(self%n_points(self%n_lineouts)) allocate(self%int_order(self%n_lineouts)) allocate(self%coords(self%n_lineouts)) allocate(self%lineout_names(self%n_lineouts)) ! Iterate over lineouts do i = 1, self%n_lineouts ! Read lineout name read(io_unit, *, iostat = io_error, iomsg = io_errmsg) & self%lineout_names(i) if (io_error /= 0) then call handle_error(io_errmsg, GRILLIX_ERR_NAMELIST, __LINE__, __FILE__) endif ! Read n_points and int_order read(io_unit, *, iostat = io_error, iomsg = io_errmsg) & self%n_points(i), self%int_order(i) if (io_error /= 0) then call handle_error(io_errmsg, GRILLIX_ERR_NAMELIST, __LINE__, __FILE__) endif ! Allocate coordinate array allocate(self%coords(i)%x(self%n_points(i))) allocate(self%coords(i)%y(self%n_points(i))) ! Read coordinates read(io_unit, *, iostat = io_error, iomsg = io_errmsg) & self%coords(i)%x if (io_error /= 0) then call handle_error(io_errmsg, GRILLIX_ERR_NAMELIST, __LINE__, __FILE__) endif read(io_unit, *, iostat = io_error, iomsg = io_errmsg) & self%coords(i)%y if (io_error /= 0) then call handle_error(io_errmsg, GRILLIX_ERR_NAMELIST, __LINE__, __FILE__) endif enddo endif close(io_unit) end subroutine module subroutine write_params_lineout(self, filepath) class(params_diag_lineout_t), intent(in) :: self character(len=*), intent(in), optional :: filepath integer :: io_unit, io_error character(len=256) :: io_errmsg lineout_path = self%lineout_path lineout_select = self%lineout_select if (present(filepath)) then io_unit = 20 open(unit = io_unit, file = filepath, status = 'unknown', & access = 'append', action = 'write', & iostat = io_error, iomsg = io_errmsg ) if (io_error /= 0) then call handle_error(io_errmsg, GRILLIX_ERR_NAMELIST, __LINE__, __FILE__) endif else io_unit = get_stdout() endif write(io_unit, nml = diag_lineout, & iostat = io_error, iomsg = io_errmsg) if (io_error /= 0) then call handle_error(io_errmsg, GRILLIX_ERR_NAMELIST, __LINE__, __FILE__) endif if (present(filepath)) then close(io_unit) endif end subroutine end submodule