 |
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
mecej4
Joined: 31 Oct 2006 Posts: 1899
|
Posted: Sat Feb 24, 2024 6:53 pm Post subject: Puzzling error reports for short correct program |
|
|
The short program below was constructed to display a problem that I had with building and running the Hydrotherm program ( https://volcanoes.usgs.gov/software/hydrotherm/ ) with FTN95, 32 or 64 bit.
The problem concerns a section of code that takes an input text file, strips out lines beginning with '#' (in col. 1), and displays the lines that remain.
Code: | program rcomment
! Purpose: Reads the input file,
! strips out the comment lines (# in col. 1), and
! displays the remaining lines
IMPLICIT NONE
integer, parameter :: fuinc=11!, fuins=12
CHARACTER(10) :: buffer
CHARACTER(len=:), ALLOCATABLE :: aline
INTEGER :: record_length
INTEGER :: string_size, lno
! ------------------------------------------------------------------------
!
open(fuinc,file='dat.in' , form='formatted', status='old')
lno=0
DO
! Determine the length of a record (a line of the input data file) by
! reading 10 characters at a time (without advancing to next record)
! until end of record (EOR) is reached.
record_length = 0
DO
READ (fuinc, '(a)', ADVANCE='NO', SIZE=string_size, EOR=10, &
END=20) buffer ! read is done only to find line size, buffer discarded
record_length = record_length + 10
END DO
10 record_length = record_length + string_size
! If the record is not empty, allocate a character string and reread
! the record into the character string.
IF (record_length > 0) THEN
ALLOCATE (CHARACTER(LEN=record_length) :: aline)
BACKSPACE (fuinc)
READ (fuinc, '(a)') aline
! If the line is not a comment line, write it to the temporary
! input file
lno=lno+1
IF (aline(1:1) /= '#') THEN
print 100,lno,record_length,aline
100 format(2i4,' |',A,'|')
END IF
DEALLOCATE (aline)
END IF
END DO
20 close(fuinc)
END program |
The input data file, 'dat.in':
Code: | # .. VER3.2: title line 2
TITLE One-Cell Problem - Constant-Enthalpy Injection
VER3.2
# DIMENSIONS
# .. nx[I],ny[I],nz[I],tmstr,iyear[I]
1, 1, 1, 0.0, 1
# TIME STEP |
The expected output (correctly delivered by Gfortran, etc.):
Code: | 2 53 |TITLE One-Cell Problem - Constant-Enthalpy Injection|
3 6 |VER3.2|
6 32 |1, 1, 1, 0.0, 1| |
With /check, the FTN95-compiled EXE reports " RCOMMENT - Error 69, Invalid record length in file stripcmt.f90 at line 31 [+0298]". With /check /64, the error message is similar.
I recognise that the method used by the original authors in the large code- read an input line in chunks of 10 characters with ADVANCE='NO' until EOL to find the length of the input line, allocate a character variable of just the right length, then BACKSPACE and reread the same line into the newly allocated variable -- can be replaced by something more efficient as well as simple, but that is not the point of this post. |
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8145 Location: Salford, UK
|
Posted: Mon Feb 26, 2024 9:36 am Post subject: |
|
|
mecej4
Thank you for the feedback. At first sight it looks like BACKSPACE for FTN95 is not working in the same way as BACKSPACE for gFortran in this context.
At the moment I don't know what the Standard has to say about this but I will make a note that this needs investigating. |
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8145 Location: Salford, UK
|
Posted: Wed Mar 05, 2025 4:25 pm Post subject: |
|
|
A preliminary investigation reveals that there are two issues to fix here.
1) The field width of aline is not passed correctly when aline is ALLOCATEd.
A temporary work-around is to avoid ALLOCATE in this context.
2) READ(END=20) is not working when the final line of the data file is not terminated with a carriage return. |
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8145 Location: Salford, UK
|
Posted: Tue Mar 11, 2025 1:20 pm Post subject: |
|
|
Both of these issues have now been fixed for the next release of FTN95 and the DLLs. |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|