Skip to content

Commit

Permalink
chore(read_lines): safer variable scoping
Browse files Browse the repository at this point in the history
This commit eliminates a "questionable code" warning from the NAG
compiler regarding use of a non-local variable as a loop index.
  • Loading branch information
rouson committed Jul 21, 2024
1 parent ab24858 commit f658a8b
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/julienne/julienne_file_s.f90
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,21 @@ function line_count(file_unit) result(num_lines)
function line_lengths(file_unit) result(lengths)
integer, intent(in) :: file_unit
integer, allocatable :: lengths(:)
integer io_status
integer io_status, l
character(len=1) c

associate(num_lines => line_count(file_unit))

allocate(lengths(num_lines), source = 0)
rewind(file_unit)

do line_num = 1, num_lines
do l = 1, num_lines
do
read(file_unit, '(a)', advance='no', iostat=io_status, iomsg=error_message) c
associate(eliminate_nagfor_warning => c) ! eliminates "variable c set but never referenced" warning
associate(eliminate_unused_variable_warning => c) ! eliminate NAG compiler "variable c set but never referenced" warning
end associate
if (io_status==iostat_eor .or. io_status==iostat_end) exit
lengths(line_num) = lengths(line_num) + 1
lengths(l) = lengths(l) + 1
end do
end do

Expand Down

0 comments on commit f658a8b

Please sign in to comment.