forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Puzzling error reports for short correct program

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
mecej4



Joined: 31 Oct 2006
Posts: 1886

PostPosted: Sat Feb 24, 2024 6:53 pm    Post subject: Puzzling error reports for short correct program Reply with quote

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
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7927
Location: Salford, UK

PostPosted: Mon Feb 26, 2024 9:36 am    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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