Silverfrost Forums

Welcome to our forums

outputting a blank line

27 Aug 2014 9:31 #14516

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.

27 Aug 2014 10:46 #14517

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

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

blankline = char(32)

write(7,'(A80)')blankline

Hope this works Wilfried

27 Aug 2014 11:00 #14518

I can reproduce lines consisting of n space characters, but not lines containing nothing at all.

27 Aug 2014 11:33 #14519

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:

character*80   blankline  
blankline = ' '

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

This avoids trailing spaces including a single space at the beginning of a blank line.

27 Aug 2014 1:39 #14521

Ian,

My version of your code produced a single blank. character80 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. character80 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

28 Aug 2014 10:26 #14530

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.

28 Aug 2014 4:31 #14540

You could use ACCESS='STREAM' instead of TRANSPARENT. It does not appear to be available in FTN95, but is a F2003 standard, I believe.

1 Sep 2014 6:22 #14580

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:

write(10,'()')

This is fully standard compliant. No need for anything fancy or to jump though hoops to do this.

1 Sep 2014 11:13 #14582

david,

write (10,'()') produces a single space character, not a totally blank line.

2 Sep 2014 5:59 #14583

Yes, FTN95 produces a record containing a blank character.

[u:667394d655]But[/u:667394d655] 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.

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
28 Jan 2015 1:19 #15516

This bug has now been fixed for the next release.

28 Jan 2015 8:07 #15520

Wow. I had forgotten about this one.

Thanks Paul. Lots of good changes coming in the next release I see 😃

Please login to reply.