<?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: BUG in Fortran I/O (?) in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/BUG-in-Fortran-I-O/m-p/915194#M84126</link>
    <description>&lt;P&gt;Thanks to everyone for their help, especially Dr. Fortran and Gvautier.&lt;/P&gt;
&lt;P&gt;The SEQUENCE statement solved the problem.&lt;/P&gt;
&lt;P&gt;Here is the way I type the three main records of the input WAV file. This is not a complete set - I focused on the record types most likely to be encountered in Windows/XP systems.&lt;/P&gt;
&lt;P&gt;You could make the SAMPLESarray smaller, then read them in sequentially if desired.&lt;/P&gt;
&lt;P&gt;See attached file - - -&lt;/P&gt;</description>
    <pubDate>Wed, 05 Mar 2008 19:14:04 GMT</pubDate>
    <dc:creator>johnculp</dc:creator>
    <dc:date>2008-03-05T19:14:04Z</dc:date>
    <item>
      <title>BUG in Fortran I/O (?)</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/BUG-in-Fortran-I-O/m-p/915187#M84119</link>
      <description>&lt;P&gt;Hi Dr. Fortran;&lt;/P&gt;
&lt;P&gt;Maybe there is a logical explanation for what's going on here.&lt;/P&gt;
&lt;P&gt;I read a recent thread between you and BLUEYEDTAM about reading sequential data from a binary file. I have a similar problem, so I tried your suggestion.&lt;/P&gt;
&lt;P&gt;Suppose we have:&lt;/P&gt;&lt;B&gt;&lt;FONT color="#0000ff" size="2"&gt;
&lt;P&gt;&lt;FONT color="#ff1493"&gt;type&lt;/FONT&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;FONT&gt;&lt;/FONT&gt;&lt;FONT color="#ff1493"&gt;&lt;FONT size="2"&gt; chk3 &lt;/FONT&gt;&lt;FONT size="2"&gt;! data chunk (has actual waveform samples)&lt;P&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt;
&lt;P&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;B&gt;&lt;FONT size="2"&gt;&lt;FONT color="#ff1493"&gt; integer*4&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;FONT&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt;&lt;FONT color="#ff1493"&gt; hdr&lt;/FONT&gt;&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;B&gt;&lt;FONT size="2"&gt;&lt;FONT color="#ff1493"&gt; integer*4&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;FONT&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt;&lt;FONT color="#ff1493"&gt; ndbyte&lt;/FONT&gt;&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;B&gt;&lt;FONT size="2"&gt;&lt;FONT color="#ff1493"&gt;end&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;FONT&gt;&lt;/FONT&gt;&lt;FONT color="#ff1493"&gt;&lt;FONT size="2"&gt; &lt;/FONT&gt;&lt;B&gt;&lt;FONT size="2"&gt;type&lt;P&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt;
&lt;P&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt;&lt;FONT color="#ff1493"&gt;type (chk3)::chunk3&lt;/FONT&gt;&lt;P&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color="#ff1493" size="2"&gt;
&lt;P&gt;! execution - OPEN INPUT .WAV FILE&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;B&gt;&lt;FONT size="2"&gt;&lt;FONT color="#ff1493"&gt;open&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;FONT&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt;&lt;FONT color="#ff1493"&gt;(3,file=fn,readonly,form='binary',convert='big_endian')&lt;/FONT&gt;&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Now with this READ statement, we get the right results when I print out chk3.hdr and chk3.ndbyte.&lt;/P&gt;
&lt;P&gt;It is supposed to read in 8 bytes from unit 3, two integers in reverse order:&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff1493"&gt;read(3)chk3&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;BUT - - If I do it this way:&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff1493"&gt;read(3)chk3.hdr,chk3.ndbyte&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;I get theWRONG values for chk3.hdr and chk3.ndbyte&lt;/P&gt;
&lt;P&gt;It acts like it's skipping over data bytes.&lt;/P&gt;
&lt;P&gt;In this second case, I'm also reading two values of 4 bytes each, so why would the results be any different? Isn't the idea to read in sequential bytes without skipping any data?&lt;/P&gt;
&lt;P&gt;Thanks, John&lt;/P&gt;&lt;/FONT&gt;</description>
      <pubDate>Mon, 03 Mar 2008 19:04:17 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/BUG-in-Fortran-I-O/m-p/915187#M84119</guid>
      <dc:creator>johnculp</dc:creator>
      <dc:date>2008-03-03T19:04:17Z</dc:date>
    </item>
    <item>
      <title>Re: BUG in Fortran I/O (?)</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/BUG-in-Fortran-I-O/m-p/915188#M84120</link>
      <description>I'm somewhat baffled that you get the "right" results when you read the whole structure (I assume you meant chunk3 in the read and not chk3, though this error leads me to wonder if you're accurately describing the problem.) As documented, CONVERT= is ignored when a derived type/structure variable is read. Could it be that the data isn't big-endian after all?&lt;BR /&gt;&lt;BR /&gt;What I would like to see is a hex dump of the first few records of the file. One way you can see this is to open the data file in Visual Studio. And then a short but complete program that reads a record or two and prints the hex values of the data read.&lt;BR /&gt;&lt;BR /&gt;My guess is that the actual behavior is different from your description. Ignoring the variable name error, the code you posted would read the first 8 bytes "raw" when chunk3 was used, and two big-endian 4-byte integers, byte-swapped on input, when the components were used.&lt;BR /&gt;&lt;BR /&gt;What wrote this data file? Was it a Fortran program? On which platform? Or is it a Windows-style audio .wav?&lt;BR /&gt;&lt;BR /&gt;P.S. Can I convince you to use % instead of . as a field separator when using derived types?&lt;BR /&gt;</description>
      <pubDate>Mon, 03 Mar 2008 19:54:21 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/BUG-in-Fortran-I-O/m-p/915188#M84120</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2008-03-03T19:54:21Z</dc:date>
    </item>
    <item>
      <title>Re: BUG in Fortran I/O (?)</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/BUG-in-Fortran-I-O/m-p/915189#M84121</link>
      <description>&lt;P&gt;Hi again;&lt;/P&gt;
&lt;P&gt;You're right, it was chunk3 in the actual program, not chk3.&lt;/P&gt;
&lt;P&gt;When I read in the &lt;STRONG&gt;entire record&lt;/STRONG&gt; at once, it does the proper conversion for &lt;STRONG&gt;all&lt;/STRONG&gt; the data fields within it.&lt;/P&gt;
&lt;P&gt;As for the documentation, I looked under the OPEN statement under CONVERT, but there is no mention of the usage &lt;STRONG&gt;within &lt;/STRONG&gt;data records, i.e. with"." or % fields. So, where is the documentation you arereferring to? Are you saying that it can't doany conversions under those conditions?&lt;/P&gt;
&lt;P&gt;Wouldn't that kill the usefulness of having record structures?&lt;/P&gt;
&lt;P&gt;I'll generate a test case, to try to pinpoint the bevahior I'm referring to.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Mar 2008 00:23:56 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/BUG-in-Fortran-I-O/m-p/915189#M84121</guid>
      <dc:creator>johnculp</dc:creator>
      <dc:date>2008-03-04T00:23:56Z</dc:date>
    </item>
    <item>
      <title>Re: BUG in Fortran I/O (?)</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/BUG-in-Fortran-I-O/m-p/915190#M84122</link>
      <description>&lt;P&gt;I spent a few hours generating a special test case. This console application writes out a specified number of records, and reads them back in three different ways, and compares the results.The first test passes, but the other two tests fail for every single value put into the records.&lt;/P&gt;
&lt;P&gt;The documentation says that "binary files don't have any internal structure." I take that to mean that the length of each record is merely the sum of thelength of its data elements.&lt;/P&gt;
&lt;P&gt;Anyway, this should underscore that the Fortran I/O is not consistent with itself. The original file we are processing is a WAV file, and they specify that the values are written out in reverse order. Curiously enough, the tests fail whether the conversionsare "big_endian" or "little_endian." &lt;/P&gt;
&lt;P&gt;I suspect what's happening is that record pointers somehow get corrupted when I read the data elements in one at a time. It shouldn't matter how they're read in, whether one at a time, or the whole record at once..&lt;/P&gt;</description>
      <pubDate>Tue, 04 Mar 2008 02:56:23 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/BUG-in-Fortran-I-O/m-p/915190#M84122</guid>
      <dc:creator>johnculp</dc:creator>
      <dc:date>2008-03-04T02:56:23Z</dc:date>
    </item>
    <item>
      <title>Re: BUG in Fortran I/O (?)</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/BUG-in-Fortran-I-O/m-p/915191#M84123</link>
      <description>&lt;P&gt;I did a little more research on this - - -&lt;/P&gt;
&lt;P&gt;If you look at the hex dump I generated, you'll see that the output records are padded with zeros, but not necessarily on the end. I at first thought that it was trying to make the length divisible by 8. But when I fixed the record length to be exactly 48 bytes, it stuck 16 extra zeros in each record, making the length 64 bytes. So apparently we don't have control over the length of each record.&lt;/P&gt;
&lt;P&gt;So apparently the only way to guarantee that you can read the data back in the way it was written, is to have the &lt;U&gt;exact same&lt;/U&gt; record sizes, and the &lt;U&gt;same&lt;/U&gt; record structure.&lt;/P&gt;
&lt;P&gt;It seems that putting in these random artifacts defeats the purpose of having a binary file. Usually when someone writes this type of file, they want a &lt;STRONG&gt;specific &lt;/STRONG&gt;structure, to be compatible with someone else's usage. For instance if I were writing a WAV file this way, I would not want the zero padding anywhere. Likewise, when I read in this type of file, I don't want it to skip around in some unpredictable manner.&lt;/P&gt;
&lt;P&gt;Is there a way to suppress this zero padding?&lt;/P&gt;
&lt;P&gt;Maybe this is all discussed somewhere, but I couldn't find it. Whether the conversion is "big endian" or "little endian" makes no difference, I get the same errors.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Mar 2008 17:37:44 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/BUG-in-Fortran-I-O/m-p/915191#M84123</guid>
      <dc:creator>johnculp</dc:creator>
      <dc:date>2008-03-04T17:37:44Z</dc:date>
    </item>
    <item>
      <title>Re: BUG in Fortran I/O (?)</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/BUG-in-Fortran-I-O/m-p/915192#M84124</link>
      <description>What you want is a SEQUENCE type. Add the line SEQUENCE after the "type recs" statement. Without that the compiler is free to add padding between misaligned components.&lt;BR /&gt;</description>
      <pubDate>Wed, 05 Mar 2008 03:10:28 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/BUG-in-Fortran-I-O/m-p/915192#M84124</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2008-03-05T03:10:28Z</dc:date>
    </item>
    <item>
      <title>Re: BUG in Fortran I/O (?)</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/BUG-in-Fortran-I-O/m-p/915193#M84125</link>
      <description>Hello&lt;BR /&gt;&lt;BR /&gt;The wav file format is based on variable length records.&lt;BR /&gt;&lt;BR /&gt;The first record must be declared as below :&lt;BR /&gt;&lt;PRE&gt;&lt;B&gt;&lt;FONT face="Courier New"&gt;type wave_file_header&lt;/FONT&gt;&lt;/B&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;B&gt;&lt;FONT face="Courier New"&gt;    character(4) riff&lt;/FONT&gt;&lt;/B&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;FONT face="Courier New"&gt;&lt;B&gt;  integer*4 size1&lt;BR /&gt;end type&lt;/B&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/FONT&gt;So you can read it simply with :&lt;BR /&gt;&lt;FONT face="Courier New"&gt;&lt;BR /&gt;&lt;B&gt;type (&lt;/B&gt;&lt;/FONT&gt;&lt;B&gt;&lt;FONT&gt;&lt;FONT face="Courier New"&gt;wave_file_header&lt;/FONT&gt;&lt;/FONT&gt;) :: wfh&lt;BR /&gt;open(1,file="filename.wav",access="direct")&lt;BR /&gt;&lt;FONT face="Courier New"&gt;read(1)wfh&lt;/FONT&gt;&lt;/B&gt;&lt;BR /&gt;&lt;BR /&gt;For a complet description see :&lt;BR /&gt;&lt;/PRE&gt;&lt;A href="http://www.sonicspot.com/guide/wavefiles.html"&gt;http://www.sonicspot.com/guide/wavefiles.html&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 05 Mar 2008 10:04:31 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/BUG-in-Fortran-I-O/m-p/915193#M84125</guid>
      <dc:creator>GVautier</dc:creator>
      <dc:date>2008-03-05T10:04:31Z</dc:date>
    </item>
    <item>
      <title>Re: BUG in Fortran I/O (?)</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/BUG-in-Fortran-I-O/m-p/915194#M84126</link>
      <description>&lt;P&gt;Thanks to everyone for their help, especially Dr. Fortran and Gvautier.&lt;/P&gt;
&lt;P&gt;The SEQUENCE statement solved the problem.&lt;/P&gt;
&lt;P&gt;Here is the way I type the three main records of the input WAV file. This is not a complete set - I focused on the record types most likely to be encountered in Windows/XP systems.&lt;/P&gt;
&lt;P&gt;You could make the SAMPLESarray smaller, then read them in sequentially if desired.&lt;/P&gt;
&lt;P&gt;See attached file - - -&lt;/P&gt;</description>
      <pubDate>Wed, 05 Mar 2008 19:14:04 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/BUG-in-Fortran-I-O/m-p/915194#M84126</guid>
      <dc:creator>johnculp</dc:creator>
      <dc:date>2008-03-05T19:14:04Z</dc:date>
    </item>
    <item>
      <title>Re: BUG in Fortran I/O (?)</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/BUG-in-Fortran-I-O/m-p/915195#M84127</link>
      <description>For the last one (DATA chunk), you must not integrate the samples in it.&lt;BR /&gt;&lt;BR /&gt;Declare and use as follow :&lt;BR /&gt;&lt;PRE&gt;&lt;FONT face="Courier New"&gt;! DATA chunk&lt;BR /&gt;    type t_chk3 ! data chunk (has actual waveform samples)&lt;BR /&gt;      sequence&lt;BR /&gt;      integer*4 hdr&lt;BR /&gt;      integer*4 ndbyte&lt;BR /&gt;    end type&lt;BR /&gt;&lt;BR /&gt;....&lt;BR /&gt;type (t_chk3) :: chk3&lt;BR /&gt;integer*2 samp2[allocatable](:)&lt;BR /&gt;&lt;/FONT&gt;&lt;FONT&gt;&lt;FONT face="Courier New"&gt;character samp1[allocatable](:)&lt;BR /&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;BR /&gt;....&lt;BR /&gt;&lt;FONT face="Courier New"&gt;read(nnn)chk3&lt;BR /&gt;&lt;/FONT&gt;if (chk2.bytes_per_sample.eq.2) then&lt;BR /&gt;    allocate(samp2(chk3.ndbyte/2))&lt;BR /&gt;    read(nnn)samp2&lt;BR /&gt;else&lt;BR /&gt;    allocate(samp2(chk3.ndbyte))&lt;BR /&gt;    read(nnn)samp2&lt;BR /&gt;endif&lt;BR /&gt;&lt;BR /&gt;G. Vautier&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 06 Mar 2008 07:09:31 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/BUG-in-Fortran-I-O/m-p/915195#M84127</guid>
      <dc:creator>GVautier</dc:creator>
      <dc:date>2008-03-06T07:09:31Z</dc:date>
    </item>
    <item>
      <title>Re: BUG in Fortran I/O (?)</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/BUG-in-Fortran-I-O/m-p/915196#M84128</link>
      <description>&lt;P&gt;Sure, I understand the need to disinguish between stereo and mono samples.&lt;/P&gt;
&lt;P&gt;What I do nowis read everything intoONE array, and for the stereo WAV files, I just pick out the alternate samples, odd going to one channel, and even going to the other.&lt;/P&gt;
&lt;P&gt;Seems to work OK so far, but maybe your approach works just as well, or better.&lt;/P&gt;
&lt;P&gt;I need to bone up on how to use the ALLOCATE statement.&lt;/P&gt;
&lt;P&gt;Yours; John&lt;/P&gt;</description>
      <pubDate>Sat, 08 Mar 2008 18:57:03 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/BUG-in-Fortran-I-O/m-p/915196#M84128</guid>
      <dc:creator>johnculp</dc:creator>
      <dc:date>2008-03-08T18:57:03Z</dc:date>
    </item>
    <item>
      <title>Re: BUG in Fortran I/O (?)</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/BUG-in-Fortran-I-O/m-p/915197#M84129</link>
      <description>Hello&lt;BR /&gt;&lt;BR /&gt;The problem is not for stereo files but for the range of wav sampling. It may be in1 byte (-128 to 127) or in 2 bytes. The 2 bytes sampling is the most common way.&lt;BR /&gt;&lt;BR /&gt;If the file is a stereo on, you must proceed like this :&lt;BR /&gt;&lt;PRE&gt;&lt;FONT face="Courier New"&gt;type t_stereo1&lt;BR /&gt;   sequence&lt;BR /&gt;   character left,right&lt;BR /&gt;end type&lt;BR /&gt;&lt;/FONT&gt;&lt;FONT&gt;&lt;FONT face="Courier New"&gt;&lt;BR /&gt;type t_stereo2&lt;BR /&gt;   sequence&lt;BR /&gt;   integer*2 left,right&lt;BR /&gt;end type&lt;BR /&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="Courier New"&gt;....&lt;BR /&gt;type (t_chk3) :: chk3&lt;BR /&gt;type (t_stereo1) :: samp1[allocatable](:)&lt;BR /&gt;&lt;/FONT&gt;&lt;FONT&gt;&lt;FONT face="Courier New"&gt;type (t_stereo2) :: &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT&gt;&lt;FONT face="Courier New"&gt;samp2[allocatable](:)&lt;BR /&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;BR /&gt;....&lt;BR /&gt;&lt;FONT face="Courier New"&gt;read(nnn)chk3&lt;BR /&gt;&lt;/FONT&gt;if (chk2.bytes_per_sample.eq.2) then&lt;BR /&gt;    allocate(samp2(chk3.ndbyte/2))&lt;BR /&gt;    read(nnn)samp2&lt;BR /&gt;else&lt;BR /&gt;    allocate(samp2(chk3.ndbyte))&lt;BR /&gt;    read(nnn)samp2&lt;BR /&gt;endif&lt;/PRE&gt;G. Vautier&lt;BR /&gt;</description>
      <pubDate>Sun, 09 Mar 2008 09:39:58 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/BUG-in-Fortran-I-O/m-p/915197#M84129</guid>
      <dc:creator>GVautier</dc:creator>
      <dc:date>2008-03-09T09:39:58Z</dc:date>
    </item>
  </channel>
</rss>

