import Subroutine

private impure subroutine import(this, file_name, dim_colors)

Type Bound

format_lut

Arguments

Type IntentOptional Attributes Name
class(format_lut), intent(inout) :: this
character(len=*), intent(in) :: file_name
integer, intent(in) :: dim_colors

Calls

proc~~import~~CallsGraph proc~import format_lut%import proc~allocate_colors format_lut%allocate_colors proc~import->proc~allocate_colors proc~set_dim_colors format_lut%set_dim_colors proc~import->proc~set_dim_colors proc~set_num_colors format_lut%set_num_colors proc~import->proc~set_num_colors

Source Code

   impure subroutine import(this, file_name, dim_colors)
      class(format_lut), intent(inout) :: this
      character(*),      intent(in)    :: file_name
      integer,           intent(in)    :: dim_colors
      integer, dimension(1,dim_colors) :: temp
      integer                          :: nunit, iostat, num_rows, i
      logical :: file_exists
      integer, dimension(dim_colors) :: buffer

      inquire(file=file_name//'.lut', exist=file_exists)
      if (file_exists) then
      open(newunit=nunit, file=file_name//'.lut', status='old', action='read', iostat=iostat)
      if (iostat /= 0) error stop 'Error opening the file.'
         num_rows = 0
         do
            read(nunit, *, iostat=iostat) temp(:,:)
            if (iostat /= 0) exit
            num_rows = num_rows + 1
         end do
         call this%set_num_colors(num_rows)
         call this%set_dim_colors(dim_colors)
         call this%allocate_colors()
         rewind(nunit)
         do i = 1, num_rows
            read(nunit, *) buffer
            this%colors(i,:) = buffer 
         end do
      close(nunit)
      else
         error stop 'File '//file_name//'.lut'//' does not exist!'
      end if
   end subroutine import