read CSV data consistently from string or file
Jerry DeLisle
jvdelisle@charter.net
Sat Oct 13 19:43:00 GMT 2018
On 10/13/18 9:23 AM, Jerry DeLisle wrote:
> On 10/12/18 4:52 PM, Jerry DeLisle wrote:
>> On 10/12/18 1:10 PM, Browning, Robert S IV ERDC-RDE-GSL-MS CIV wrote:
>>> I am needing to read in a text file that contains numerical data
>>> separated by keywords. Because of the keywords, I need to read each
>>> line in as text first and test if itâs a keyword, and then call the
>>> appropriate subroutine based on the keyword value. Within the
>>> subroutines I also need to read each line as text first so I can stop
>>> the subroutine when the next keyword is found.
>>> The numerical data can be in either fixed format or
>>> comma-separated-value (CSV) format. In the CSV data, a zero could be
>>> represented by a pair of commas with no number between them.
>>> The issue I have encountered is that the read statement appears to
>>> behave differently when it is reading from a character string than
>>> when it is reading directly from the input file. If I were able to
>>> read directly from the input file, then a simple formatted read
>>> statement does everything I need. But if I am reading from a string,
>>> then things get a bit more complicated.
>>
>> Hi Robert,
>>
>> This may be a known bug. It sounds familiar. Let me do some checking.
>>
>> Fortranners, if I confirm this is the bug I think it is, I think I can
>> squeeze some time to fix it.
>>
>> Jerry
>>
>
> I am fairly certain this is PR78351. As far as we can tell the code is
> non-conforming Fortran but the use of comma to terminate a read has been
> around forever and gfortran supported this before. It was my breakage
> in my endeavors to improve string I/O performance. I feel obligated at
> this point to set it straight.
>
> Jerry
>
The patch attached to pr78351 fixes this and regression tests cleanly.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78351
I am wondering if I should put the check behind some condition related
to the standards to avoid the extra string scan or just leave it as is
in the patch.
Regards,
Jerry
More information about the Fortran
mailing list