<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Approximatrix Forums — Strange GFortran problem suppressing CR]]></title>
	<link rel="self" href="https://forums.approximatrix.com/extern.php?action=feed&amp;tid=307&amp;type=atom" />
	<updated>2014-01-24T08:20:42Z</updated>
	<generator>PunBB</generator>
	<id>https://forums.approximatrix.com/viewtopic.php?id=307</id>
		<entry>
			<title type="html"><![CDATA[Re: Strange GFortran problem suppressing CR]]></title>
			<link rel="alternate" href="https://forums.approximatrix.com/viewtopic.php?pid=1240#p1240" />
			<content type="html"><![CDATA[<p>In my case, non-advancing IO works very well using GNU-gfortran (and also 5 or 6 other different compilers). The only important thing is to flush the unit to be sure that data is written.</p><p>&nbsp; &nbsp; &nbsp;call flush(LU)</p><p>is a standard call in gfortran and should remedy your problem. Put it immediately after a non-advancing write.</p><p>BTW, I never tried&nbsp; the environment variable GFORTRAN_UNBUFFERED_ALL, it should effectively have the same effect but it has the drawback to be global.</p>]]></content>
			<author>
				<name><![CDATA[ecanot]]></name>
				<uri>https://forums.approximatrix.com/profile.php?id=3380</uri>
			</author>
			<updated>2014-01-24T08:20:42Z</updated>
			<id>https://forums.approximatrix.com/viewtopic.php?pid=1240#p1240</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Strange GFortran problem suppressing CR]]></title>
			<link rel="alternate" href="https://forums.approximatrix.com/viewtopic.php?pid=1236#p1236" />
			<content type="html"><![CDATA[<p>Honestly, John, I haven&#039;t used it too much myself.&nbsp; It does allow a more direct way to access files, but you lose the ability to specify formatting directly.&nbsp; I don&#039;t think anyone would argue that text output and manipulation is not one of Fortran&#039;s strong points.</p>]]></content>
			<author>
				<name><![CDATA[jeff]]></name>
				<uri>https://forums.approximatrix.com/profile.php?id=2</uri>
			</author>
			<updated>2014-01-23T17:23:36Z</updated>
			<id>https://forums.approximatrix.com/viewtopic.php?pid=1236#p1236</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Strange GFortran problem suppressing CR]]></title>
			<link rel="alternate" href="https://forums.approximatrix.com/viewtopic.php?pid=1234#p1234" />
			<content type="html"><![CDATA[<p>Thanks Jeff - that&#039;s a very interesting solution.&nbsp; I haven&#039;t come across&nbsp; &#039;access=&quot;stream&quot; &#039; before.&nbsp; <br />Very useful tip.<br />---<br />John</p>]]></content>
			<author>
				<name><![CDATA[JohnWasilewski]]></name>
				<uri>https://forums.approximatrix.com/profile.php?id=102</uri>
			</author>
			<updated>2014-01-22T23:00:45Z</updated>
			<id>https://forums.approximatrix.com/viewtopic.php?pid=1234#p1234</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Strange GFortran problem suppressing CR]]></title>
			<link rel="alternate" href="https://forums.approximatrix.com/viewtopic.php?pid=1233#p1233" />
			<content type="html"><![CDATA[<p>John,</p><p>Non-advancing IO in Fortran using the traditional output techniques has always been hit-or-miss in my experience.&nbsp; There isn&#039;t a really &quot;official&quot; way to do so using Fortran 90/95.</p><p>You can, however, use Fortran 2003&#039;s <strong>stream</strong> access techniques.&nbsp; It requires a bit more programming, but that&#039;s no surprise.&nbsp; Here&#039;s an example program that does exactly what you want:</p><div class="codebox"><pre><code>program streamio
implicit none

    Print *, &quot;Running&quot;

    open(unit=115, file=&quot;test.txt&quot;, access=&quot;stream&quot;, status=&quot;replace&quot;, &amp;
         form=&quot;unformatted&quot;)

    write(115) &quot;Testing indents&quot;//NEW_LINE(&#039;0&#039;)
    
    call indent(115, 3)
    
    write(115) &quot;I&#039;m three spaces in...&quot;//NEW_LINE(&#039;0&#039;)
    
    call indent(115, 5)
    
    write(115) &quot;I&#039;m five spaces in...&quot;//NEW_LINE(&#039;0&#039;)
    
    call indent(115, 7)
    
    write(115) &quot;I&#039;m seven spaces in...&quot;//NEW_LINE(&#039;0&#039;)
    
    close(115)
    
    Print *, &quot;Done&quot;

contains

    subroutine indent(lu, spaces)
    implicit none
    
    integer::lu, spaces
    
        write(lu) repeat(&#039; &#039;, spaces)
    
    end subroutine indent

end program streamio</code></pre></div><p>There are a few things to note.&nbsp; First, I&#039;ve opened the file with <em>access=&quot;stream&quot;</em>, which is new.&nbsp; &nbsp;Second, all my <em>write</em> calls have only a unit number, no format information.&nbsp; It will fail if you even include a <strong>*</strong> format specifier.&nbsp; Third, I have to explicitly append new line characters to all my strings to advance one line.</p><p>Let me know what you think of the above.&nbsp; It might be workable in your case.</p>]]></content>
			<author>
				<name><![CDATA[jeff]]></name>
				<uri>https://forums.approximatrix.com/profile.php?id=2</uri>
			</author>
			<updated>2014-01-22T01:46:10Z</updated>
			<id>https://forums.approximatrix.com/viewtopic.php?pid=1233#p1233</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Strange GFortran problem suppressing CR]]></title>
			<link rel="alternate" href="https://forums.approximatrix.com/viewtopic.php?pid=1232#p1232" />
			<content type="html"><![CDATA[<p>I&#039;d also tried that.&nbsp; <br />Nothing worked.</p><p>I&#039;ve altered the code to avoid the problem but it&#039;s a strange one.<br />I wondered if anyone else had experienced anything similar.<br />---<br />J.</p>]]></content>
			<author>
				<name><![CDATA[JohnWasilewski]]></name>
				<uri>https://forums.approximatrix.com/profile.php?id=102</uri>
			</author>
			<updated>2014-01-21T21:18:04Z</updated>
			<id>https://forums.approximatrix.com/viewtopic.php?pid=1232#p1232</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Strange GFortran problem suppressing CR]]></title>
			<link rel="alternate" href="https://forums.approximatrix.com/viewtopic.php?pid=1231#p1231" />
			<content type="html"><![CDATA[<p>Hi John. Try this.</p><div class="codebox"><pre><code>      SUBROUTINE INDENT(LU,nTAB)
C     --------------------------------------
C     Indent LU
C     jw / 13.08.04
C     jw / 21.01.14  last rev.

      INTEGER   LU, nTAB

      WRITE (LU,&#039;(A)&#039;, ADVANCE = &#039;NO&#039;) REPEAT(&#039; &#039;, nTab)

      RETURN
      END </code></pre></div><p>There is a single space in the first argument of REPEAT.</p>]]></content>
			<author>
				<name><![CDATA[davidb]]></name>
				<uri>https://forums.approximatrix.com/profile.php?id=3463</uri>
			</author>
			<updated>2014-01-21T19:09:08Z</updated>
			<id>https://forums.approximatrix.com/viewtopic.php?pid=1231#p1231</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Strange GFortran problem suppressing CR]]></title>
			<link rel="alternate" href="https://forums.approximatrix.com/viewtopic.php?pid=1230#p1230" />
			<content type="html"><![CDATA[<p>I&#039;m having great trouble with a short bit of Fortran code.</p><p>I have a library subroutine coded as follows.<br />Its purpose is to indent a line in readiness for further output.<br />The variable, LU, is the file unit of an open write file.</p><p><span style="color:blue"><br />&nbsp; &nbsp; &nbsp; SUBROUTINE INDENT(LU,nTAB)<br />C&nbsp; &nbsp; &nbsp;--------------------------------------<br />C&nbsp; &nbsp; &nbsp;Indent LU<br />C&nbsp; &nbsp; &nbsp;jw / 13.08.04<br />C&nbsp; &nbsp; &nbsp;jw / 21.01.14&nbsp; last rev.</span></p><p><span style="color:blue">&nbsp; &nbsp; &nbsp; INTEGER&nbsp; &nbsp;nTAB</span></p><p><span style="color:blue">&nbsp; &nbsp; &nbsp; DO iTAB=1,nTAB<br />C&nbsp; &nbsp; &nbsp; &nbsp; WRITE (LU,&#039;(&#039;&#039; &#039;&#039;,$)&#039;)<br />C&nbsp; &nbsp; &nbsp; &nbsp; WRITE (LU,&#039;(&#039;&#039; &#039;&#039;,$)&#039;)<br />C&nbsp; &nbsp; &nbsp; &nbsp; WRITE (LU,&#039;(A)&#039;, ADVANCE = &#039;NO&#039;) &#039; &#039;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WRITE (LU,&#039;(A,$)&#039;) &#039; &#039;<br />&nbsp; &nbsp; &nbsp; END DO</span></p><p><span style="color:blue">&nbsp; &nbsp; &nbsp; RETURN<br />&nbsp; &nbsp; &nbsp; END <br /></span></p><p>As will be apparent from the above, I&#039;ve made four attempts at achieving the same thing (three are commented out).</p><p>What happens is that it compiles OK but fails at runtime.<br />When I run the program, it does SOMETIMES work.<br />But then, on re-running immediately, it immediately fails.</p><p>From the debugger, I see that it always fails, by freezing, on the WRITE statements.<br />It tends to work (50% of the time) immediately after re-compiling/rebuilding.<br />It never works twice in a row.&nbsp; Mostly, it fails.</p><p>As far as I can see, my code is all correct.</p><p>I&#039;ve tried altering the environment variable <br />GFORTRAN_UNBUFFERED_ALL <br />between Y and N, and then back to Y.<br />This makes no difference.</p><p>Has anyone any ideas that would help me with this?<br />--- <br />John</p>]]></content>
			<author>
				<name><![CDATA[JohnWasilewski]]></name>
				<uri>https://forums.approximatrix.com/profile.php?id=102</uri>
			</author>
			<updated>2014-01-21T15:53:36Z</updated>
			<id>https://forums.approximatrix.com/viewtopic.php?pid=1230#p1230</id>
		</entry>
</feed>
