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.
outputting a blank line
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
I can reproduce lines consisting of n space characters, but not lines containing nothing at all.
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.
Ian,
My version of your code produced a single blank.
character80 blankline
integer4 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
integer4 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
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.
You could use ACCESS='STREAM' instead of TRANSPARENT. It does not appear to be available in FTN95, but is a F2003 standard, I believe.
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.
david,
write (10,'()') produces a single space character, not a totally blank line.
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
This bug has now been fixed for the next release.
Wow. I had forgotten about this one.
Thanks Paul. Lots of good changes coming in the next release I see 😃