replica nfl jerseysreplica nfl jerseyssoccer jerseyreplica nfl jerseys forums.silverfrost.com :: View topic - outputting a blank line
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 

outputting a blank line

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



Joined: 22 Mar 2009
Posts: 14

PostPosted: Wed Aug 27, 2014 10:31 am    Post subject: outputting a blank line Reply with quote

I have a program that reads a text file line by line, making occasional adjustments, then outputting the (revised) line character by character.
This works fine except for completely blank lines. Using FMT="(/)" or WRITE(7,*) with no output list produces a single space character, not a totally blank line.
Back to top
View user's profile Send private message
Wilfried Linder



Joined: 14 Nov 2007
Posts: 314
Location: D�sseldorf, Germany

PostPosted: Wed Aug 27, 2014 11:46 am    Post subject: Reply with quote

Do you use lines of a fixed / constant length? Then you may do the following:

Code:
character*80   blankline  ! set 80 to the line length you need

blankline = char(32)

write(7,'(A80)')blankline


Hope this works
Wilfried
Back to top
View user's profile Send private message
skeptic



Joined: 22 Mar 2009
Posts: 14

PostPosted: Wed Aug 27, 2014 12:00 pm    Post subject: Reply with quote

I can reproduce lines consisting of n space characters, but not lines containing nothing at all.
Back to top
View user's profile Send private message
IanLambley



Joined: 17 Dec 2006
Posts: 506
Location: Sunderland

PostPosted: Wed Aug 27, 2014 12:33 pm    Post subject: Reply with quote

If you output via a list directed * format, then it will always output a space at the beginning of the line due to the old line printer codes where the frist character being a space meant print on next line, a + for overtype and a 1 for form feed.

try this:
Code:

character*80   blankline 
blankline = ' '

write(7,'(A)')trim(blankline)

This avoids trailing spaces including a single space at the beginning of a blank line.
Back to top
View user's profile Send private message Send e-mail
JohnCampbell



Joined: 16 Feb 2006
Posts: 2615
Location: Sydney

PostPosted: Wed Aug 27, 2014 2:39 pm    Post subject: Reply with quote

Ian,

My version of your code produced a single blank.
Code:
      character*80   blankline 
      integer*4 i
!
      open (11,file='blank.txt')
!
      blankline = ' '
!
      do i = 1,5
        write (11,'(A)') trim (blankline)
      end do
      write (11,11)
11    format (//'test line'/' '//)
      end


The only way I can definitely do it is to open a file as TRANSPARENT. The following example appears to work.
Code:
      character*80   blankline 
      integer*4 i
!
      open (11,file='blank.txt',ACCESS='TRANSPARENT', FORM='FORMATTED')
!
      blankline = ' '
!
      do i = 1,5
        write (11,'(A/)') trim (blankline)
      end do
      write (11,11)
11    format (//'test line'/' '//)
      end

John
Back to top
View user's profile Send private message
skeptic



Joined: 22 Mar 2009
Posts: 14

PostPosted: Thu Aug 28, 2014 11:26 am    Post subject: Reply with quote

Many thanks, John. It works exactly as you stated. The only drawback is, I believe, that TRANSPARENT is not a standard Fortran feature? However, it produces exactly what I needed.
Back to top
View user's profile Send private message
simon



Joined: 05 Jul 2006
Posts: 299

PostPosted: Thu Aug 28, 2014 5:31 pm    Post subject: Reply with quote

You could use ACCESS='STREAM' instead of TRANSPARENT. It does not appear to be available in FTN95, but is a F2003 standard, I believe.
Back to top
View user's profile Send private message
davidb



Joined: 17 Jul 2009
Posts: 560
Location: UK

PostPosted: Mon Sep 01, 2014 7:22 pm    Post subject: Reply with quote

The way to print a new line to an output unit that is opened for writing formatted data is to use an empty format specifier with an empty data list, that is:

Code:

write(10,'()')


This is fully standard compliant. No need for anything fancy or to jump though hoops to do this.
_________________
Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl
Back to top
View user's profile Send private message
JohnCampbell



Joined: 16 Feb 2006
Posts: 2615
Location: Sydney

PostPosted: Tue Sep 02, 2014 12:13 am    Post subject: Reply with quote

david,

write (10,'()') produces a single space character, not a totally blank line.
Back to top
View user's profile Send private message
davidb



Joined: 17 Jul 2009
Posts: 560
Location: UK

PostPosted: Tue Sep 02, 2014 6:59 am    Post subject: Reply with quote

Yes, FTN95 produces a record containing a blank character.

But this is possibly a bug in the FTN95 compiler; the standard mandates that an empty record should be written. It is permissible for the compiler to output a blank if page control is being used, but this should only be done when list-directed output is being used.

A related bug is that the following should produce 2 empty records but produces two records containing a blank character.

Code:

program writeblank
   open(10,file='result.txt')
   write(10,'("Line before blank lines")')

   ! This should produce two blank lines but doesn't
   write(10,'(/)')
   
   write(10,'("Line after blank lines")')
   close(10)
end program writeblank

_________________
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: 8208
Location: Salford, UK

PostPosted: Wed Jan 28, 2015 2:19 pm    Post subject: Reply with quote

This bug has now been fixed for the next release.
Back to top
View user's profile Send private message AIM Address
davidb



Joined: 17 Jul 2009
Posts: 560
Location: UK

PostPosted: Wed Jan 28, 2015 9:07 pm    Post subject: Reply with quote

Wow. I had forgotten about this one.

Thanks Paul. Lots of good changes coming in the next release I see Smile
_________________
Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl
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