<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Approximatrix Forums — Fortran question about READ(TxtLN,*)]]></title>
		<link>https://forums.approximatrix.com/viewtopic.php?id=275</link>
		<atom:link href="https://forums.approximatrix.com/extern.php?action=feed&amp;tid=275&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Fortran question about READ(TxtLN,*).]]></description>
		<lastBuildDate>Thu, 28 Nov 2013 21:30:53 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Fortran question about READ(TxtLN,*)]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=1096#p1096</link>
			<description><![CDATA[<p>Thanks again to both David and Édouard for their good tips.&nbsp; I knew whole arrays can now be initialised <br />with a simple Arrayname = 0 but I confess I didn&#039;t know that we could also initialise strings in a similar way.</p><p>It&#039;s great to get such on-the-button help so swiftly,<br />---- <br />John</p>]]></description>
			<author><![CDATA[null@example.com (JohnWasilewski)]]></author>
			<pubDate>Thu, 28 Nov 2013 21:30:53 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=1096#p1096</guid>
		</item>
		<item>
			<title><![CDATA[Re: Fortran question about READ(TxtLN,*)]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=1095#p1095</link>
			<description><![CDATA[<p>You don&#039;t need to use</p><div class="codebox"><pre><code>TxtLn = REPEAT(&quot; &quot;, 160)</code></pre></div><p>The following will also work since the assignment is automatically padded with spaces.</p><div class="codebox"><pre><code>TxtLn = &quot;&quot;</code></pre></div><p>If you don&#039;t want to use ERR= and END= which are essentially a GOTOs, you can use IOSTAT=code, and test for the value of code.</p><p>The values are compiler dependent but 0 always means no error, &lt; means end of file,<br />&gt; 0 means other error.</p>]]></description>
			<author><![CDATA[null@example.com (davidb)]]></author>
			<pubDate>Thu, 28 Nov 2013 19:44:37 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=1095#p1095</guid>
		</item>
		<item>
			<title><![CDATA[Re: Fortran question about READ(TxtLN,*)]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=1094#p1094</link>
			<description><![CDATA[<p>Very many thanks for that excellent and correct advice.</p>]]></description>
			<author><![CDATA[null@example.com (JohnWasilewski)]]></author>
			<pubDate>Thu, 28 Nov 2013 18:19:36 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=1094#p1094</guid>
		</item>
		<item>
			<title><![CDATA[Re: Fortran question about READ(TxtLN,*)]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=1093#p1093</link>
			<description><![CDATA[<p>John,</p><p>Use &quot;END=201&quot; in your READ statement, instead of &quot;ERR=201&quot;. It will work as expected.</p><p>The &quot;END=label&quot; optional argument must be use to detect an End-Of-File error, which is your case.</p><p>The &quot;ERR=label&quot; arg should be more appropriate when reading integers or floating point numbers<br />and you try to detect a corrupted file (e.g. trying to read an integer from a string containing only letters and not digits).</p><p>Regards,<br />Édouard</p>]]></description>
			<author><![CDATA[null@example.com (ecanot)]]></author>
			<pubDate>Thu, 28 Nov 2013 16:50:55 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=1093#p1093</guid>
		</item>
		<item>
			<title><![CDATA[Fortran question about READ(TxtLN,*)]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=1090#p1090</link>
			<description><![CDATA[<p>THIS IS A Q ABOUT FORTRAN, <br />NOT A Q ABOUT THE SF I.D.E.<br />-------------------------------------</p><br /><p>Can anyone help me with this slightly odd behaviour of FORTRAN?<br />I suspect the answer is very simple but I just can&#039;t see the wood for the trees.</p><p>I am trying to do something very simple:</p><p>&nbsp; &nbsp;1.&nbsp; read a line of data from an input file <br />&nbsp; &nbsp; &nbsp; &nbsp; into a text string buffer, and then </p><p>&nbsp; &nbsp;2.&nbsp; read values from the buffer into a list <br />&nbsp; &nbsp; &nbsp; &nbsp; of four INTEGER and one CHAR variables </p><br /><p>Here&#039;s the code<span style="color:blue"> <em><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;INTEGER&nbsp; &nbsp; &nbsp; &nbsp; IMem,iNode1,iNode2,iMTyp<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CHARACTER&nbsp; &nbsp;TxtLN*160<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TxtLN=REPEAT(&#039; &#039;,160)</em></span></p><p><span style="color:blue"><em>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;READ(LU,&#039;(A)&#039;) TxtLN<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;READ(TxtLN,*) IMem, iNode1, iNode2, iMTyp, Des </em></span></p><p>Here are some lines of data from <span class="bbu">the input file</span><strong><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1, 1, 2, 1,Roof btm chord<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2, 2, 3, 1,Roof btm chord<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;3, 0, 0, 0,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;4, 4, 5, 3,Roof btm chord<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;5, 5, 6, 3,Roof btm chord</strong></p><p>At runtime, the program loops through the code until it detects an EoF, or rather, it is supposed to do so.<br />What actually happens, however, is that it succeeds on lines 1 and 2 of the data but, as soon as it reaches line 3, it fails.&nbsp; Line 3 is, just as it seems, an incorrect line of data, and what I am trying to do here is to write code that traps data errors and deals with them.&nbsp; This is why I am reading each line of data into a text string buffer first.</p><p>What happens here is that, <br /><span style="color:blue"> <em>READ(LU,&#039;(A)&#039;) TxtLN </em></span> succeeds, and then<br /><span style="color:blue"> <em>READ(TxtLN,*) IMem, iNode1, iNode2, iMTyp, Des </em></span> fails.</p><p>During runtime, the program simply exits.<br />During debugging, it just stops and hangs.</p><p>I don&#039;t understand this at all because I would expect line 3 of the code to be accepted, resulting in data being entered into the variables, of<br />&nbsp; &nbsp; &nbsp;IMem=3<br />&nbsp; &nbsp; &nbsp;iNode1=0<br />&nbsp; &nbsp; &nbsp;iNode2=0<br />&nbsp; &nbsp; &nbsp;iMTyp=0<br />&nbsp; &nbsp; &nbsp;Des=&#039;&#039;&nbsp; (ie a string of zero length).</p><p>I have tried altering the code to this:<span style="color:blue"> <em><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;INTEGER&nbsp; &nbsp; &nbsp; &nbsp; IMem,iNode1,iNode2,iMTyp<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CHARACTER&nbsp; &nbsp;TxtLN*160<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TxtLN=REPEAT(&#039; &#039;,160)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;READ(LU,&#039;(A)&#039;) TxtLN<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TxtLN=TRIM(TxtLN)//REPEAT(&#039; &#039;,160-LEN_TRIM(TxtLN))</em></span></p><p><span style="color:blue"><em>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;READ(TxtLN,*,ERR=201) IMem,iNode1,iNode2,iMTyp,Des<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;GO TO 202</em></span></p><p><span style="color:blue"><em>201&nbsp; &nbsp; &nbsp; &nbsp; CONTINUE ! READ error<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IF(Imem*iNode1*iNode2*iMTyp.NE.0) THEN<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Des=Repeat(&#039; &#039;,31)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GO TO 202 ! ERR now fixed, so continue<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ELSE<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;EXIT<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; END IF</em></span></p><p><span style="color:blue"><em>202&nbsp; &nbsp; &nbsp; CONTINUE&nbsp; !ERR-free or ERR-corrected </em></span></p><p>This STILL FAILS.&nbsp; It gets as far as <br /><span style="color:blue"> <em>READ(TxtLN,*,ERR=201) IMem,iNode1,iNode2,iMTyp,Des</em></span> and then, instead of jumping to the error-trap at 201, it again just dies.</p><p>Does anyone have any ideas?<br />--- <br />John</p>]]></description>
			<author><![CDATA[null@example.com (JohnWasilewski)]]></author>
			<pubDate>Thu, 28 Nov 2013 10:57:11 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=1090#p1090</guid>
		</item>
	</channel>
</rss>
