<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Approximatrix Forums — Error in OPEN FILE Statement - Bug or user error]]></title>
		<link>http://forums.approximatrix.com/viewtopic.php?id=458</link>
		<atom:link href="http://forums.approximatrix.com/extern.php?action=feed&amp;tid=458&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Error in OPEN FILE Statement - Bug or user error.]]></description>
		<lastBuildDate>Mon, 27 Apr 2015 16:01:23 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Error in OPEN FILE Statement - Bug or user error]]></title>
			<link>http://forums.approximatrix.com/viewtopic.php?pid=2036#p2036</link>
			<description><![CDATA[<p>Thanks Jeff, It worked.&nbsp; Moving ahead inch by inch with your help and others in this forum.&nbsp; Thanks again.&nbsp; Next I will be doing to interface this DLL in Excel VBA (my ultimate goal)</p>]]></description>
			<author><![CDATA[null@example.com (sheekom)]]></author>
			<pubDate>Mon, 27 Apr 2015 16:01:23 +0000</pubDate>
			<guid>http://forums.approximatrix.com/viewtopic.php?pid=2036#p2036</guid>
		</item>
		<item>
			<title><![CDATA[Re: Error in OPEN FILE Statement - Bug or user error]]></title>
			<link>http://forums.approximatrix.com/viewtopic.php?pid=2033#p2033</link>
			<description><![CDATA[<p>Suresh,</p><p>The problem you&#039;re seeing is because your strings are arrays of characters:</p><div class="codebox"><pre><code>CHARACTER*1, DIMENSION(100) :: FULLFILENAMEPATH</code></pre></div><p>and the <em>OPEN</em> statement actually expects a Fortran string, something like:</p><div class="codebox"><pre><code>CHARACTER(100) ::  FULLPATHSTR</code></pre></div><p>The reason you&#039;re seeing this incompatibility issue is because you&#039;re interfacing via a DLL using the <em>ISO_C_BINDING</em> features.&nbsp; The C language only defines strings as arrays of characters.&nbsp; Therefore, if receiving a string from C, it will be an array.&nbsp; To use this array as a string in Fortran, it would have to be converted using some custom functions.&nbsp; Some example functions are defined <a href="http://fortranwiki.org/fortran/show/String_Functions">here</a>:</p><div class="codebox"><pre><code>PURE FUNCTION Copy_a2s(a)  RESULT (s)    ! copy char array to string
    CHARACTER,INTENT(IN) :: a(:)
    CHARACTER(SIZE(a)) :: s
    INTEGER :: i
    DO i = 1,SIZE(a)
       s(i:i) = a(i)
    END DO
END FUNCTION Copy_a2s</code></pre></div><p>There would be an equivalent operation for copying the string (in Fortran) back to C, although, thanks to how Fortran stores strings, you normally don&#039;t have to actually perform this operation.</p><p>Moving string back and forth via a DLL can be a pain because Fortran simply handles strings differently than C.</p>]]></description>
			<author><![CDATA[null@example.com (jeff)]]></author>
			<pubDate>Mon, 27 Apr 2015 15:21:24 +0000</pubDate>
			<guid>http://forums.approximatrix.com/viewtopic.php?pid=2033#p2033</guid>
		</item>
		<item>
			<title><![CDATA[Re: Error in OPEN FILE Statement - Bug or user error]]></title>
			<link>http://forums.approximatrix.com/viewtopic.php?pid=2031#p2031</link>
			<description><![CDATA[<p>Thanks Davidb, It makes sense.&nbsp; I modified DLL to open the file in DLL (program logic requires that). However I get compilation error for DLL subroutine as follows in the open statement as follows:</p><p>Generating Makefile... Okay<br />==============================================================================<br />Compiling .\GEDATA.For<br />.\GEDATA.For:71.28:</p><p>&nbsp; &nbsp; &nbsp; FULLFILENAMEPATH=TRIM(FULLFILENAMEPATH)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1<br />Error: &#039;string&#039; argument of &#039;trim&#039; intrinsic at (1) must be a scalar<br />.\GEDATA.For:83.31:</p><p>&nbsp; &nbsp; &nbsp; &nbsp; OPEN (UNIT=OFFLUN,FILE=FULLFILENAMEPATH, STATUS=&#039;OLD&#039;)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1<br />Error: FILE tag at (1) must be scalar<br />.\GEDATA.For:213.29:</p><p>&nbsp; &nbsp; &nbsp; OPEN (UNIT=DATPRT,FILE=FULLFILENAMEPATH, STATUS=&#039;REPLACE&#039;)&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1<br />Error: FILE tag at (1) must be scalar<br />Error(E42): Last command making (build\GEDATA.o) returned a bad status<br />Error(E02): Make execution terminated</p><p>* Failed *</p><p>I am passing the filename and declaring as follows:</p><p>&nbsp; &nbsp; &nbsp; SUBROUTINE&nbsp; GEDATA ( OFFLUN, DBGLUN, DATPRT, FULLFILENAMEPATH,<br />&nbsp; &nbsp; &nbsp;1IRDWR,&nbsp; NRMAX, NCMAX,&nbsp; NROWS,&nbsp; NCOLS,<br />&nbsp; &nbsp; &nbsp;2STRROWNAM, STRCOLNAM, MATRIX, ROWRHS,<br />&nbsp; &nbsp; &nbsp;3LOWBND, UPPBND, OBJCOF, PSBASE, SOLN ) bind(c)</p><p>..<br />CHARACTER*1, DIMENSION(100) :: FULLFILENAMEPATH</p><p>OPEN (UNIT=OFFLUN,FILE=FULLFILENAMEPATH, STATUS=&#039;OLD&#039;)</p><p>I would appreciate any feedback as to why am I getting this error. <br />C</p>]]></description>
			<author><![CDATA[null@example.com (sheekom)]]></author>
			<pubDate>Mon, 27 Apr 2015 14:32:31 +0000</pubDate>
			<guid>http://forums.approximatrix.com/viewtopic.php?pid=2031#p2031</guid>
		</item>
		<item>
			<title><![CDATA[Re: Error in OPEN FILE Statement - Bug or user error]]></title>
			<link>http://forums.approximatrix.com/viewtopic.php?pid=2024#p2024</link>
			<description><![CDATA[<p>Your main program and your DLL have separate run-time environments. You cannot therefore pass the unit number. It won&#039;t work unfortunately.</p><p>You can pass the file name and use open in the DLL but the usual rule is to read your files in the main program and pass the values to the DLL.</p>]]></description>
			<author><![CDATA[null@example.com (davidb)]]></author>
			<pubDate>Thu, 23 Apr 2015 13:06:04 +0000</pubDate>
			<guid>http://forums.approximatrix.com/viewtopic.php?pid=2024#p2024</guid>
		</item>
		<item>
			<title><![CDATA[Re: Error in OPEN FILE Statement - Bug or user error]]></title>
			<link>http://forums.approximatrix.com/viewtopic.php?pid=2023#p2023</link>
			<description><![CDATA[<p>Thanks David,</p><p>That worked.&nbsp; However, I have another second step problem.&nbsp; I conect and open the datafile in main program and<br />pass the FORTRAN File Unit parameter via subroutine DLL argument and tried to read the file in the subroutine and it gives end file error like </p><p>COASTAL1.DAT&nbsp; &nbsp; &nbsp; &nbsp; <br /> TestGEDataDll Main Program&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1 G:\oms-Development\Version-VB6\Interfaces\omsLPIntf\Input\COASTAL1.DAT&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> Entering GEDATA DLL&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 20&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 25&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 30&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1 G:\oms-Development\Version-VB6\Interfaces\omsLPIntf\Input\COASTAL1.DAT&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />At line 89 of file .\GEDATA.For (unit = 20, file = &#039;fort.20&#039;)<br />Fortran runtime error: End of file</p><p>Does it mean I can not just pass the unit no in DLL but must pass the file name and connect in subroutine DLL and not connect in main progarm.</p>]]></description>
			<author><![CDATA[null@example.com (sheekom)]]></author>
			<pubDate>Wed, 22 Apr 2015 21:19:25 +0000</pubDate>
			<guid>http://forums.approximatrix.com/viewtopic.php?pid=2023#p2023</guid>
		</item>
		<item>
			<title><![CDATA[Re: Error in OPEN FILE Statement - Bug or user error]]></title>
			<link>http://forums.approximatrix.com/viewtopic.php?pid=2022#p2022</link>
			<description><![CDATA[<p>It is difficult to see what you are trying to do.</p><p>The line&nbsp; FILEPATH=TRIM(FILEPATH) does not strip out trailing blanks. This is because when the assignment is done, the compiler adds trailing blanks up to the dimension size, so you get back to where you started. Similarly there is no need to use repeat to get a string of blanks, just use&nbsp; FILENAMEPATH=&#039; &#039;.</p><p>So the following doesn&#039;t work as there are blanks in the file name</p><p>&nbsp; FILEPATH=TRIM(FILEPATH)<br />&nbsp; OPEN (UNIT=TESTDATA,<br />1FILE=FILEPATH// &#039;Input\TESTCASES.DAT&#039;, STATUS=&#039;OLD&#039;,<br />2 ACCESS=&#039;SEQUENTIAL&#039;, FORM=&#039;FORMATTED&#039;)</p><p>Instead, try the following with TRIM included in the open statement.</p><p>&nbsp; OPEN (UNIT=TESTDATA,<br />1FILE=TRIM(FILEPATH)// &#039;Input\TESTCASES.DAT&#039;, STATUS=&#039;OLD&#039;,<br />2 ACCESS=&#039;SEQUENTIAL&#039;, FORM=&#039;FORMATTED&#039;)</p>]]></description>
			<author><![CDATA[null@example.com (davidb)]]></author>
			<pubDate>Wed, 22 Apr 2015 20:25:44 +0000</pubDate>
			<guid>http://forums.approximatrix.com/viewtopic.php?pid=2022#p2022</guid>
		</item>
		<item>
			<title><![CDATA[Error in OPEN FILE Statement - Bug or user error]]></title>
			<link>http://forums.approximatrix.com/viewtopic.php?pid=2021#p2021</link>
			<description><![CDATA[<p>Hi All,</p><p>I am trying to pass filename as string variable in OPEN FILE statement as follows:</p><p>&nbsp; &nbsp; &nbsp; Program TestFileIOPgm<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; IMPLICIT NONE<br />&nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; CHARACTER*12 :: DATE, TIME<br />&nbsp; &nbsp; &nbsp; CHARACTER*10 :: OMSDATE, OMSTIME<br />&nbsp; &nbsp; &nbsp; CHARACTER (LEN=256) :: FILENAMEPATH<br />&nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; INTEGER :: DBGLUN,TESTDATA, IDFILE<br />&nbsp; &nbsp; &nbsp; CHARACTER(LEN=60) ::&nbsp; &nbsp;FILEPATH<br />&nbsp; &nbsp; &nbsp; CHARACTER*20 :: TESTDATANAME<br />&nbsp; &nbsp; &nbsp; CHARACTER(LEN=20) :: FLNAME<br />&nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; TESTDATA=15<br />&nbsp; &nbsp; &nbsp; DBGLUN=25</p><p>C&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp; &nbsp; &nbsp; FILEPATH=&#039;G:\oms-Development\Version-VB6\Interfaces\omsLPIntf\&#039;<br />&nbsp; &nbsp; &nbsp; FILEPATH=TRIM(FILEPATH)<br />&nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; FILENAMEPATH=REPEAT(&#039; &#039;,256)<br />&nbsp; &nbsp; &nbsp;<br />&nbsp; &nbsp; &nbsp; OPEN (UNIT=TESTDATA, <br />&nbsp; &nbsp; &nbsp;1FILE=&#039;G:\oms-Development\Version-VB6\Interfaces\omsLPIntf\&#039; <br />&nbsp; &nbsp; &nbsp;2// &#039;Input\&#039; // &#039;TESTCASES.DAT&#039;, STATUS=&#039;OLD&#039;,ACCESS=&#039;SEQUENTIAL&#039;, <br />&nbsp; &nbsp; &nbsp;3 FORM=&#039;FORMATTED&#039;)<br />&nbsp; &nbsp; &nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />C&nbsp; &nbsp; &nbsp;OPEN (UNIT=TESTDATA, <br />C&nbsp; &nbsp; 1FILE=FILEPATH// &#039;Input\TESTCASES.DAT&#039;, STATUS=&#039;OLD&#039;,<br />C&nbsp; &nbsp; 2 ACCESS=&#039;SEQUENTIAL&#039;, FORM=&#039;FORMATTED&#039;) <br />&nbsp; &nbsp; &nbsp;<br />&nbsp; &nbsp; &nbsp; OPEN (UNIT=DBGLUN,<br />&nbsp; &nbsp; &nbsp;1FILE=&#039;G:\oms-Development\Version-VB6\Interfaces\omsLPIntf\&#039; <br />&nbsp; &nbsp; &nbsp;2// &#039;Debug\&#039; // &#039;DEBUG-TEST.DAT&#039; , STATUS=&#039;REPLACE&#039;)<br />&nbsp; &nbsp; &nbsp;<br />&nbsp; &nbsp; &nbsp;<br />&nbsp; &nbsp; &nbsp; DO 8000 IDFILE = 1, 100<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; READ (TESTDATA,8001) TESTDATANAME<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WRITE(*,*) TESTDATANAME<br />8001&nbsp; &nbsp; &nbsp;FORMAT(A20)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FLNAME=TRIM(TESTDATANAME)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FILENAMEPATH=&#039;G:\oms-Development\Version-VB6\Interfaces\&#039;<br />&nbsp; &nbsp; &nbsp;1&nbsp; &nbsp; // &#039;omsLPIntf\&#039; // &#039;Input\&#039; // FLNAME<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IF (FLNAME .EQ. &#039;&#039;) GO TO 8002<br />&nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; CALL DATE_AND_TIME(DATE,TIME)<br />&nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; OMSDATE = DATE(1:4) // &quot;/&quot; // DATE(5:6) // &quot;/&quot; // DATE(7:8)<br />&nbsp; &nbsp; &nbsp; OMSTIME = TIME(1:2) // &quot;:&quot; // TIME(3:4) // &quot;:&quot; // TIME(5:6)<br />&nbsp; &nbsp; &nbsp;</p><p>&nbsp; &nbsp; &nbsp; WRITE (DBGLUN,50) FILEPATH,FLNAME,DATE(1:8),TIME(1:6)<br />&nbsp; &nbsp; &nbsp; <br />8002&nbsp; CONTINUE</p><p>8000&nbsp; CONTINUE </p><p>&nbsp; &nbsp; &nbsp; CLOSE(TESTDATA)<br />&nbsp; &nbsp; &nbsp; CLOSE(DBGLUN)</p><p>*<br />*---- FORMAT STATTEMENTS<br />*<br />&nbsp; &nbsp;50 FORMAT(2x,&#039;Input Data File Opened Successfully &#039;, A60,2X, A20,2X,<br />&nbsp; &nbsp; &nbsp;1 &quot; AT DATE/TIME&nbsp; &quot;, A8,2X,A6)</p><p>&nbsp; &nbsp; &nbsp; END PROGRAM TestFileIOPgm<br />&nbsp; &nbsp; &nbsp; <br />The above code when the filepath is hradcoded but if pass the variable as&nbsp; </p><p>&nbsp; <br />&nbsp; OPEN (UNIT=TESTDATA, <br /> 1FILE=FILEPATH// &#039;Input\TESTCASES.DAT&#039;, STATUS=&#039;OLD&#039;,<br /> 2 ACCESS=&#039;SEQUENTIAL&#039;, FORM=&#039;FORMATTED&#039;)</p><p>I get this error</p><p>&nbsp; At line 32 of file .\TestFileIOPgm.FOR (unit = 15, file = &#039;° &#039;)<br />Fortran runtime error: File &#039;G:\oms-Development\Version-VB6\Interfaces\omsLPIntf\&nbsp; &nbsp; &nbsp; &nbsp; Input\TESTCASES.DAT&#039; does not exist</p><p>It does not pickup the FullFileName in the file=?</p><p>What am I missing here.&nbsp; New user at learning f90 and had worked with Visual fortran with no problem.&nbsp; Please guide me.&nbsp; Would appreciate it.</p>]]></description>
			<author><![CDATA[null@example.com (sheekom)]]></author>
			<pubDate>Wed, 22 Apr 2015 19:08:44 +0000</pubDate>
			<guid>http://forums.approximatrix.com/viewtopic.php?pid=2021#p2021</guid>
		</item>
	</channel>
</rss>
