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 

Internal WRITE error goes undetected

 
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: 1186

PostPosted: Sun Jul 07, 2019 2:03 pm    Post subject: Internal WRITE error goes undetected Reply with quote

The following program does formatted writes of an integer to an internal file (i.e., a buffer) with three different variations. The second WRITE writes uses a field width of 4, which is adequate for the integer 123, but the resulting string is longer than the record length of the internal file, which is 3.

Code:
program asterisks
  character(3) str
  character(100) msg
  n=123
  print *,'Str Iostat Message'
  str='xyz'; msg=' - '; write(str,'(i0)',iostat=i,iomsg=msg) n
  write(*,10) str,i,trim(msg)
  str='xyz'; msg=' - '; write(str,'(i4)',iostat=i,iomsg=msg) n
  write(*,10) str,i,trim(msg)
  str='xyz'; msg=' - '; write(str,'(i2)',iostat=i,iomsg=msg) n
  write(*,10) str,i,trim(msg)
10 format(1x,A3,i5,4x,A)
end


I think that the second WRITE should yield a positive IOSTAT value, a suitable IOMSG, and leave the record unchanged. FTN95 8.51 (32 and 64-bit) returns IOSTAT = 0, instead, and the written record is incorrect.

Code:
 Str Iostat Message
 123    0
  12    0
 **     0


For the second case, Intel Fortran gives IOMSG='output statement overflows record, unit -5, file Internal Formatted Write'.
Back to top
View user's profile Send private message
davidb



Joined: 17 Jul 2009
Posts: 557
Location: UK

PostPosted: Sun Jul 07, 2019 5:54 pm    Post subject: Reply with quote

I agree this would be a useful additional run-time check. Though it is the programmer's responsibility to check such things.

The NAG and gfortran compilers also detect the error with the (I4) formatting at run-time.
_________________
Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Mon Jul 08, 2019 7:28 am    Post subject: Reply with quote

Thank you for this. I have made a note that it needs fixing.
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Mon Jul 08, 2019 10:08 am    Post subject: Reply with quote

This has now been fixed for the next release of the DLLs.

The iostat is 67 and the message is "Character buffer too small".
Back to top
View user's profile Send private message
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