<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic I'm not sure what's going on in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/CreateFile-will-not-always-open-an-excisting-file/m-p/1038085#M112322</link>
    <description>&lt;P&gt;I'm not sure what's going on here. Could you try changing the dwFlagsAndAttributes argument from 0 to perhaps FILE_ATTRIBUTE_NORMAL or FILE_ATTRIBUTE_READONLY? Probably won't do any good, though. Could you show us how you set the value of szFileName? That seems to be the most likely problem, for example if you forgot to include the trailing ACHAR(0). Also, when the function fails print out the value returned by GetLastError() because that can be illuminating sometimes.&lt;/P&gt;</description>
    <pubDate>Tue, 28 Oct 2014 14:13:25 GMT</pubDate>
    <dc:creator>JVanB</dc:creator>
    <dc:date>2014-10-28T14:13:25Z</dc:date>
    <item>
      <title>CreateFile will not always open an excisting file</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/CreateFile-will-not-always-open-an-excisting-file/m-p/1038084#M112321</link>
      <description>&lt;P&gt;Hallo,&lt;/P&gt;
&lt;P&gt;I use the function shown below to load textfiles to a buffer for later to show the text in a text box.&lt;/P&gt;
&lt;P&gt;Usually it works fine, but in some cases the file can not be opened (handle hFile=0) and the no text is read. As a test I have tried&lt;/P&gt;
&lt;P&gt;to open and the close the file&amp;nbsp; ( by the standard Open /Close&amp;nbsp; Fortran statements) before I apply the CreateFile function to ensure the file is&lt;/P&gt;
&lt;P&gt;not locked somwhere else in the program.&amp;nbsp; Open/close is ok, but the CreateFile function do not always succed in opening it.&lt;/P&gt;
&lt;P&gt;When I open the textfile with Notepad, it always looks OK.&lt;/P&gt;
&lt;P&gt;Looking forward to get a clue from somebody out there....&lt;/P&gt;
&lt;P&gt;Reidar&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;h&lt;STRONG&gt;File = CreateFile(szFileName, GENERIC_READ, FILE_SHARE_READ, &amp;amp;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&lt;STRONG&gt;NULL, OPEN_EXISTING, 0, NULL)&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Oct 2014 10:54:56 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/CreateFile-will-not-always-open-an-excisting-file/m-p/1038084#M112321</guid>
      <dc:creator>reidar</dc:creator>
      <dc:date>2014-10-28T10:54:56Z</dc:date>
    </item>
    <item>
      <title>I'm not sure what's going on</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/CreateFile-will-not-always-open-an-excisting-file/m-p/1038085#M112322</link>
      <description>&lt;P&gt;I'm not sure what's going on here. Could you try changing the dwFlagsAndAttributes argument from 0 to perhaps FILE_ATTRIBUTE_NORMAL or FILE_ATTRIBUTE_READONLY? Probably won't do any good, though. Could you show us how you set the value of szFileName? That seems to be the most likely problem, for example if you forgot to include the trailing ACHAR(0). Also, when the function fails print out the value returned by GetLastError() because that can be illuminating sometimes.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Oct 2014 14:13:25 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/CreateFile-will-not-always-open-an-excisting-file/m-p/1038085#M112322</guid>
      <dc:creator>JVanB</dc:creator>
      <dc:date>2014-10-28T14:13:25Z</dc:date>
    </item>
    <item>
      <title>FUNCTION open_the_file</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/CreateFile-will-not-always-open-an-excisting-file/m-p/1038086#M112323</link>
      <description>&lt;P&gt;[fortran]&lt;/P&gt;

&lt;P&gt;FUNCTION open_the_file (fullpath, rwmode) RESULT (ihandl)&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;IMPLICIT NONE&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;INTEGER(HANDLE)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; :: ihandl&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;INTEGER&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;:: access&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;CHARACTER(LEN=*),INTENT(IN)&amp;nbsp;&amp;nbsp; &amp;nbsp;:: fullpath,rwmode&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;! Win32 file opens&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;IF (rwmode == 'R') THEN&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;access = GENERIC_READ&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;ELSE&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;access = IOR(GENERIC_READ,GENERIC_WRITE)&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;END IF&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;ihandl = CreateFile (fullpath,&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;amp;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; access,&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;amp;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; FILE_SHARE_READ,&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;amp;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NULL_SECURITY_ATTRIBUTES,&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;amp;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; OPEN_ALWAYS,&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;amp;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; FILE_ATTRIBUTE_NORMAL,&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;amp;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; NULL&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;)&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;IF (ihandl == INVALID_HANDLE_VALUE) THEN&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;! deal with failure&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;END IF&lt;BR /&gt;
	END FUNCTION open_the_file&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;[/fortran]&lt;/P&gt;</description>
      <pubDate>Wed, 29 Oct 2014 16:28:10 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/CreateFile-will-not-always-open-an-excisting-file/m-p/1038086#M112323</guid>
      <dc:creator>Paul_Curtis</dc:creator>
      <dc:date>2014-10-29T16:28:10Z</dc:date>
    </item>
    <item>
      <title>if(len_trim(fullpath) == len</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/CreateFile-will-not-always-open-an-excisting-file/m-p/1038087#M112324</link>
      <description>&lt;PRE class="brush:fortran;"&gt;if(len_trim(fullpath) == len(fullpath)) stop "No room for NULL"
fullpath(len_trim(fullpath):len_trim(fullpath)) = ACHAR(0)
! now do your CreateFile&lt;/PRE&gt;

&lt;P&gt;Jim Dempsey&lt;/P&gt;</description>
      <pubDate>Wed, 29 Oct 2014 16:54:55 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/CreateFile-will-not-always-open-an-excisting-file/m-p/1038087#M112324</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2014-10-29T16:54:55Z</dc:date>
    </item>
    <item>
      <title>Thank you for for your</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/CreateFile-will-not-always-open-an-excisting-file/m-p/1038088#M112325</link>
      <description>&lt;P&gt;Thank you for for your response,&lt;/P&gt;

&lt;P&gt;I modified the file name field&amp;nbsp;as shown below:&lt;/P&gt;

&lt;P&gt;hFile = CreateFile(&lt;STRONG&gt;trim(szFileName)//char(0), &lt;/STRONG&gt;GENERIC_READ, FILE_SHARE_READ, &amp;amp;&lt;/P&gt;

&lt;P&gt;and now it works fine,&lt;/P&gt;

&lt;P&gt;Reidar&lt;/P&gt;</description>
      <pubDate>Thu, 30 Oct 2014 08:52:25 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/CreateFile-will-not-always-open-an-excisting-file/m-p/1038088#M112325</guid>
      <dc:creator>reidar</dc:creator>
      <dc:date>2014-10-30T08:52:25Z</dc:date>
    </item>
    <item>
      <title>To remove potential confusion</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/CreateFile-will-not-always-open-an-excisting-file/m-p/1038089#M112326</link>
      <description>&lt;P&gt;To remove potential confusion of future reader of your code, I would suggest removing "sz" from szFileName as this indicates it is a zero (NULL) terminated string.&lt;/P&gt;

&lt;P&gt;hFile = CreateFile(&lt;STRONG&gt;trim(fullpath)//char(0), &lt;/STRONG&gt;GENERIC_READ, FILE_SHARE_READ, &amp;amp;&lt;/P&gt;

&lt;P&gt;Would not be confusing, and may in fact be what you have in your code.&lt;/P&gt;

&lt;P&gt;Jim Dempsey&lt;/P&gt;</description>
      <pubDate>Thu, 30 Oct 2014 12:36:21 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/CreateFile-will-not-always-open-an-excisting-file/m-p/1038089#M112326</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2014-10-30T12:36:21Z</dc:date>
    </item>
    <item>
      <title>Thanks Jim, yes, that's true,</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/CreateFile-will-not-always-open-an-excisting-file/m-p/1038090#M112327</link>
      <description>&lt;P&gt;Thanks Jim, yes, that's true, the zs could be confusing...&lt;/P&gt;
&lt;P&gt;BR&lt;/P&gt;
&lt;P&gt;Reidar&lt;/P&gt;</description>
      <pubDate>Tue, 04 Nov 2014 10:42:51 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/CreateFile-will-not-always-open-an-excisting-file/m-p/1038090#M112327</guid>
      <dc:creator>reidar</dc:creator>
      <dc:date>2014-11-04T10:42:51Z</dc:date>
    </item>
  </channel>
</rss>

