Skip to content

Commit

Permalink
feat(file_t): output to file with character name
Browse files Browse the repository at this point in the history
This commit converts the write_lines name to be a generic binding
on the file_t derived type with two corresponding private specific
type-bound procedures: one with string_t file_name dummy argument
and one with a character(len=*) file_name dummy argument.
  • Loading branch information
rouson committed Feb 24, 2025
1 parent d108a36 commit 1728e78
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
14 changes: 11 additions & 3 deletions src/julienne/julienne_file_m.f90
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
! Copyright (c) 2024, The Regents of the University of California and Sourcery Institute
! Terms of use are as specified in LICENSE.txt
module julienne_file_m
!! A representation of a file as an object
!! a representation of a file as an object
use julienne_string_m, only : string_t

private
public :: file_t

type file_t
!! encapsulate a ragged-edged array of character variables supporting input/output services
private
type(string_t), allocatable :: lines_(:)
contains
procedure :: lines
procedure :: write_lines
generic :: write_lines => to_file_with_string_t_file_name, to_file_with_character_file_name
procedure, private :: to_file_with_string_t_file_name, to_file_with_character_file_name
end type

interface file_t
Expand Down Expand Up @@ -45,12 +47,18 @@ pure module function lines(self) result(my_lines)
type(string_t), allocatable :: my_lines(:)
end function

impure elemental module subroutine write_lines(self, file_name)
impure elemental module subroutine to_file_with_string_t_file_name(self, file_name)
implicit none
class(file_t), intent(in) :: self
type(string_t), intent(in), optional :: file_name
end subroutine

impure elemental module subroutine to_file_with_character_file_name(self, file_name)
implicit none
class(file_t), intent(in) :: self
character(len=*), intent(in), optional :: file_name
end subroutine

end interface

end module julienne_file_m
6 changes: 5 additions & 1 deletion src/julienne/julienne_file_s.F90
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
my_lines = self%lines_
end procedure

module procedure write_lines
module procedure to_file_with_character_file_name
call self%write_lines(string_t(file_name))
end procedure

module procedure to_file_with_string_t_file_name

integer file_unit, io_status, l

Expand Down

0 comments on commit 1728e78

Please sign in to comment.