<?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 Re: Read statements (any suggestion is appreciated) in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Read-statements-any-suggestion-is-appreciated/m-p/830585#M52261</link>
    <description>I'm not sure how the Fortran internal READ will treat CRLFs (CHAR(13)//CHAR(10) or 
) within the string -- you can try it yourself&lt;BR /&gt;&lt;BR /&gt;Alternatively, instead of internal read, you can use Windows pipes to redirect the standard input and/or output. Please see the attached example -- it uses two different processes ("main" launching "submodule") to establish "talking" through the pipe, but it should work with a dll as well. The only change it would require in the Fortran code is to replace READ(Unit,...) with READ(*,...).&lt;BR /&gt;</description>
    <pubDate>Wed, 28 Mar 2007 10:49:58 GMT</pubDate>
    <dc:creator>Jugoslav_Dujic</dc:creator>
    <dc:date>2007-03-28T10:49:58Z</dc:date>
    <item>
      <title>Read statements (any suggestion is appreciated)</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Read-statements-any-suggestion-is-appreciated/m-p/830582#M52258</link>
      <description>&lt;P&gt;Hello all:&lt;/P&gt;
&lt;P&gt;I have a weird problem - and I am having difficulty solving it. I hope someone can help me.&lt;/P&gt;
&lt;P&gt;I have a Fortran engine (compiled in Visual Fortran) which does mathemtical calculataions (Finite element analysis). The engine takes a text file for input data by reading the file using "read" commands. For a single run (i.e. one file one analysis), this is working like a charm.&lt;/P&gt;
&lt;P&gt;The problem is that I am now solving a nonlinear problem which requires thousands of cases to be run. For this, I recomplied the fortran engine as a DLL, and I wrote C++ program to call the DLL each time it needs to run it (The c++ engine is creating a text file each time it needs to run the engine). The problem is that the reading and writing to the text file is making the process so inefficent that I have to spend a couple of days running a single nonlinear problem. The bottleneck is reading and writing the files to the hard drive.&lt;/P&gt;
&lt;P&gt;So I changed the c++ program such that it passes the input data to the Fortran engine as a string (formatted exactly like the text file.) However, at this point I don't know what to do. The Fortran engine is programmed to read the data from a text file using the read statements. It is going to be very challenging to modify my Fortran source code, so I am looking for the least intrusive way of handling this problem. My specific question is :&lt;/P&gt;
&lt;P&gt;"Is there a way that the read stetements can be fooled to read from a unit in the memory (other than the text file, i.e. the string that I am passing from the C++ code)? If there is, then I don't need to change anything, and just point the input unit to that direction. &lt;/P&gt;
&lt;P&gt;If this is not possible, what is the easiest way of handling this problem? &lt;/P&gt;
&lt;P&gt;I am in desperate need to solve this problem ASAP. Any advice is appreciated.&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;
&lt;P&gt;Burki&lt;/P&gt;</description>
      <pubDate>Tue, 27 Mar 2007 23:41:03 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Read-statements-any-suggestion-is-appreciated/m-p/830582#M52258</guid>
      <dc:creator>intelisgor</dc:creator>
      <dc:date>2007-03-27T23:41:03Z</dc:date>
    </item>
    <item>
      <title>Re: Read statements (any suggestion is appreciated)</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Read-statements-any-suggestion-is-appreciated/m-p/830583#M52259</link>
      <description>&lt;P&gt;You can't "redirect" the READ but you can replace the unit number with the name of a character variable and it will "read" from that without other changes.This is a standard Fortran feature called "internal I/O". If the text is multiple lines, you'll have to create a character array with one element per "record".&lt;/P&gt;</description>
      <pubDate>Wed, 28 Mar 2007 00:19:31 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Read-statements-any-suggestion-is-appreciated/m-p/830583#M52259</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2007-03-28T00:19:31Z</dc:date>
    </item>
    <item>
      <title>Re: Read statements (any suggestion is appreciated)</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Read-statements-any-suggestion-is-appreciated/m-p/830584#M52260</link>
      <description>&lt;P&gt;Dear Steve,&lt;/P&gt;
&lt;P&gt;Thank you for your reply - this is probably my answer. One question though... I have hundreds of lines, each is read by a seperate formatted READ statement. Will "line breaks" be considered as the end of record and be enough for the READ statement to recognize it as an array? Or should I pre-process the data so that they are stored in an array?&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Burki&lt;/P&gt;&lt;PRE class="ScreenText"&gt;&lt;A name="pgfId-9470"&gt;&lt;/A&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Mar 2007 02:46:11 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Read-statements-any-suggestion-is-appreciated/m-p/830584#M52260</guid>
      <dc:creator>intelisgor</dc:creator>
      <dc:date>2007-03-28T02:46:11Z</dc:date>
    </item>
    <item>
      <title>Re: Read statements (any suggestion is appreciated)</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Read-statements-any-suggestion-is-appreciated/m-p/830585#M52261</link>
      <description>I'm not sure how the Fortran internal READ will treat CRLFs (CHAR(13)//CHAR(10) or 
) within the string -- you can try it yourself&lt;BR /&gt;&lt;BR /&gt;Alternatively, instead of internal read, you can use Windows pipes to redirect the standard input and/or output. Please see the attached example -- it uses two different processes ("main" launching "submodule") to establish "talking" through the pipe, but it should work with a dll as well. The only change it would require in the Fortran code is to replace READ(Unit,...) with READ(*,...).&lt;BR /&gt;</description>
      <pubDate>Wed, 28 Mar 2007 10:49:58 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Read-statements-any-suggestion-is-appreciated/m-p/830585#M52261</guid>
      <dc:creator>Jugoslav_Dujic</dc:creator>
      <dc:date>2007-03-28T10:49:58Z</dc:date>
    </item>
    <item>
      <title>Re: Read statements (any suggestion is appreciated)</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Read-statements-any-suggestion-is-appreciated/m-p/830586#M52262</link>
      <description>&lt;P&gt;Fortran wil l not recognize the CR-LF pairs in the string as record delimiters. If you can convert the string into a CHARACTER array (with a length of each element sufficient to hold a line), one element per line (requires some added code to split out the records), then each element will be treated as if it were a separate line.&lt;/P&gt;
&lt;P&gt;Jugoslav's pipe suggestion is good too.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Mar 2007 15:52:22 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Read-statements-any-suggestion-is-appreciated/m-p/830586#M52262</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2007-03-28T15:52:22Z</dc:date>
    </item>
    <item>
      <title>Re: Read statements (any suggestion is appreciated)</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Read-statements-any-suggestion-is-appreciated/m-p/830587#M52263</link>
      <description>What are the contents of these 'text files'? Numerical only, or mixed alphanumeric?</description>
      <pubDate>Wed, 28 Mar 2007 16:14:48 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Read-statements-any-suggestion-is-appreciated/m-p/830587#M52263</guid>
      <dc:creator>anthonyrichards</dc:creator>
      <dc:date>2007-03-28T16:14:48Z</dc:date>
    </item>
    <item>
      <title>Re: Read statements (any suggestion is appreciated)</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Read-statements-any-suggestion-is-appreciated/m-p/830588#M52264</link>
      <description>They are alfanumeric. However, when I read them in the fortran engine I read them as text lines and extract the numeric values myself. So they can be considered as text lines.</description>
      <pubDate>Wed, 28 Mar 2007 21:42:41 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Read-statements-any-suggestion-is-appreciated/m-p/830588#M52264</guid>
      <dc:creator>intelisgor</dc:creator>
      <dc:date>2007-03-28T21:42:41Z</dc:date>
    </item>
    <item>
      <title>Re: Read statements (any suggestion is appreciated)</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Read-statements-any-suggestion-is-appreciated/m-p/830589#M52265</link>
      <description>&lt;P&gt;Thank you &lt;STRONG&gt;Jugoslav:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;I think this is a good idea as well. The only worry I have is about piping. I am calling the engine (exe) from Visual C++ using the shell command. For the dll version, I use the regular dll call. &lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Let's say I am usig the exe (through shell command)... How can I pipe the data file intothe engine withinVC++. I haveused Pipe before, but not within the source code - only on the console.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Thanks,&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Burkan&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Mar 2007 21:50:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Read-statements-any-suggestion-is-appreciated/m-p/830589#M52265</guid>
      <dc:creator>intelisgor</dc:creator>
      <dc:date>2007-03-28T21:50:00Z</dc:date>
    </item>
    <item>
      <title>Re: Read statements (any suggestion is appreciated)</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Read-statements-any-suggestion-is-appreciated/m-p/830590#M52266</link>
      <description>&lt;P&gt;Hi Steve,&lt;/P&gt;
&lt;P&gt;The problem is that the length of each record is notfixed. So I would not know how to create a character array. If I could do this it would be perfect since I donl;t have to change the code. &lt;/P&gt;
&lt;P&gt;Burki&lt;/P&gt;</description>
      <pubDate>Wed, 28 Mar 2007 22:00:56 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Read-statements-any-suggestion-is-appreciated/m-p/830590#M52266</guid>
      <dc:creator>intelisgor</dc:creator>
      <dc:date>2007-03-28T22:00:56Z</dc:date>
    </item>
    <item>
      <title>Re: Read statements (any suggestion is appreciated)</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Read-statements-any-suggestion-is-appreciated/m-p/830591#M52267</link>
      <description>You would declare the character array with a character length long enough to hold the longest record. Pad the end of shorter records with blanks. It's easy to put together a loop that looks for the next CR-LF pair and copies the string into an array element.</description>
      <pubDate>Wed, 28 Mar 2007 23:10:39 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Read-statements-any-suggestion-is-appreciated/m-p/830591#M52267</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2007-03-28T23:10:39Z</dc:date>
    </item>
    <item>
      <title>Re: Read statements (any suggestion is appreciated)</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Read-statements-any-suggestion-is-appreciated/m-p/830592#M52268</link>
      <description>&lt;P&gt;Or in lieu of copying records you can use subscripts into the string. After every extraction advance the pointer into the string to the character index following the next line feed (char(10)).&lt;/P&gt;
&lt;P&gt;ReadPtr = 1! initialization&lt;BR /&gt;...&lt;BR /&gt;100 continue ! Read next "line"&lt;BR /&gt;if(ReadPtr .eq. 0) goto 999! eof&lt;BR /&gt;read(buffer(ReadPtr:), fmt) args, ...&lt;BR /&gt;ReadPtr = SCAN(buffer(ReadPtr:),char(10))&lt;BR /&gt;if(ReadPtr .ne. 0) ReadPtr=ReadPtr+1! get ready for next time&lt;BR /&gt;... ! store the data wherever&lt;BR /&gt;goto 100&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Mar 2007 23:36:05 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Read-statements-any-suggestion-is-appreciated/m-p/830592#M52268</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2007-03-28T23:36:05Z</dc:date>
    </item>
    <item>
      <title>Re: Read statements (any suggestion is appreciated)</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Read-statements-any-suggestion-is-appreciated/m-p/830593#M52269</link>
      <description>&lt;P&gt;Thanks a lot to everyone. Steve's sugegstion worked like a charm. You guy are great...&lt;/P&gt;</description>
      <pubDate>Thu, 29 Mar 2007 01:56:57 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Read-statements-any-suggestion-is-appreciated/m-p/830593#M52269</guid>
      <dc:creator>intelisgor</dc:creator>
      <dc:date>2007-03-29T01:56:57Z</dc:date>
    </item>
    <item>
      <title>Re: Read statements (any suggestion is appreciated)</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Read-statements-any-suggestion-is-appreciated/m-p/830594#M52270</link>
      <description>I'm glad that your problem is solved (wow, that was fast), just to reply to your previous question related with pipes (perhaps for the future): take a look at the source code of the main program -- it's just a few pipe creation and handle redirecting APIs, easily translatable to C++. &lt;BR /&gt;&lt;BR /&gt;Once you redirect your own standard output to the pipe using &lt;FONT face="Courier New" size="2"&gt;SetStdHandle(STD_OUTPUT_HANDLE)&lt;/FONT&gt;, you can just use printf to write to the pipe; once you do it, the child process will "wake up" and &lt;FONT face="Courier New" size="2"&gt;READ(*)&lt;/FONT&gt; those same data each time you write a record into the pipe. If you don't want to redirect your own standard output of the main application, you can use &lt;FONT face="Courier New" size="2"&gt;WriteFile&lt;/FONT&gt; or &lt;FONT face="Courier New" size="2"&gt;_fdopen&lt;/FONT&gt; followed by &lt;FONT face="Courier New" size="2"&gt;fprintf&lt;/FONT&gt;. &lt;BR /&gt;&lt;BR /&gt;(Actually, Fortran basically lacks the equivalent of _fdopen, which triggered this thread. &lt;FONT face="Courier New" size="2"&gt;_fdopen&lt;/FONT&gt; is, IIRC a VC++ extension. There is, however, a similar VF extension -- see docs on &lt;FONT face="Courier New" size="2"&gt;USEROPEN &lt;/FONT&gt;specifier of &lt;FONT face="Courier New" size="2"&gt;OPEN &lt;/FONT&gt;statement).&lt;BR /&gt;</description>
      <pubDate>Thu, 29 Mar 2007 08:41:02 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Read-statements-any-suggestion-is-appreciated/m-p/830594#M52270</guid>
      <dc:creator>Jugoslav_Dujic</dc:creator>
      <dc:date>2007-03-29T08:41:02Z</dc:date>
    </item>
    <item>
      <title>Re: Read statements (any suggestion is appreciated)</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Read-statements-any-suggestion-is-appreciated/m-p/830595#M52271</link>
      <description>&lt;P&gt;Thanks. This is useful stuff...&lt;/P&gt;
&lt;P&gt;My problem is actually not fully solved. There is something wrong somewhere, but I cannot figure out.I created a 5 line data (20 charaters each) from my CV++ code, and passedthis to the DLL as a string. I want to test if my code will work. I take the data from VC++ with the variable "idata". Then I extract 20 character long substrings from "idata" and load them to a character array called "dummy". I am using dummy as an internal file and reading it with 5 read statements to a character array called "bummy" (simulating what I want to achive). Then, I write the contents of bummy to a textfile to see if theoperation was successful. I see 5 lines, but each line is the same (the first line is copied to all other four lines)...The problem is notin "dummy" array; it is propoerly pouplated with the right data line. the problem is with the read line. It seems that after each read,the cursor stays in the beginning o fthe line, and it keeps reading dummy[1]. Any help is appreciated. My test DLL is below.&lt;/P&gt;
&lt;P&gt;!&lt;BR /&gt;! FUNCTIONS/SUBROUTINES exported from VBINTERFACE.dll:&lt;BR /&gt;!VBINTERFACE - subroutine &lt;BR /&gt;!&lt;BR /&gt;subroutine VBINTERFACE(idata)&lt;/P&gt;
&lt;P&gt;! Expose subroutine VBINTERFACE to users of this DLL&lt;BR /&gt;!&lt;BR /&gt;!DEC$ ATTRIBUTES DLLEXPORT::VBINTERFACE&lt;BR /&gt;!DEC$ ATTRIBUTES STDCALL,REFERENCE,ALIAS:"vbInterface" :: vbInterface&lt;/P&gt;
&lt;P&gt;character dummy(5)*20&lt;BR /&gt;character bummy(5)*20&lt;BR /&gt;character*(*) idata&lt;BR /&gt;integer length&lt;/P&gt;
&lt;P&gt;length = len(idata) / 20&lt;/P&gt;
&lt;P&gt;do 10 i=1,length&lt;BR /&gt;dummy(i) = idata(20*(i-1)+1 : 20*i)&lt;BR /&gt;10continue&lt;/P&gt;
&lt;P&gt;read(dummy,*) bummy(1)&lt;BR /&gt;read(dummy,*) bummy(2)&lt;BR /&gt;read(dummy,*) bummy(3)&lt;BR /&gt;read(dummy,*) bummy(4)&lt;BR /&gt;read(dummy,*) bummy(5)&lt;BR /&gt;&lt;BR /&gt;open(1,file="testFILE")&lt;/P&gt;
&lt;P&gt;do 20 i=1,length&lt;BR /&gt;write(1,*) bummy(i)&lt;BR /&gt;20continue&lt;BR /&gt;&lt;BR /&gt;close(1) &lt;/P&gt;
&lt;P&gt;end subroutine VBINTERFACE&lt;/P&gt;</description>
      <pubDate>Thu, 29 Mar 2007 20:50:15 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Read-statements-any-suggestion-is-appreciated/m-p/830595#M52271</guid>
      <dc:creator>intelisgor</dc:creator>
      <dc:date>2007-03-29T20:50:15Z</dc:date>
    </item>
    <item>
      <title>Re: Read statements (any suggestion is appreciated)</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Read-statements-any-suggestion-is-appreciated/m-p/830596#M52272</link>
      <description>&lt;P&gt;Sorry, you can't do it quite that way. Each separate READ starts at the first element of dummy. What I was suggesting was more like this:&lt;/P&gt;
&lt;P&gt;read (dummy,*) bummy&lt;/P&gt;
&lt;P&gt;This reads all five elements of dummy and assigns the contents of each one to respective elements of bummy.&lt;/P&gt;
&lt;P&gt;I will caution you that reading character data with list-directed formatting can be a problem, especially if there is any punctuation. Rather than * use '(A)'.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Mar 2007 22:07:29 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Read-statements-any-suggestion-is-appreciated/m-p/830596#M52272</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2007-03-29T22:07:29Z</dc:date>
    </item>
  </channel>
</rss>

