Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Including apostrophes in a READ

Stuart_M_
Beginner
638 Views
Hi folks

I need to read the following into variable from a text file: 'xml_input'C

The read needs to include the apostrophes and the C appended on the end, yet a simple READ of the line only returns the text within the apostrophes. I'm assuming the READ statement is ignoring the apostrophes and assuming that they are simply indicative of the boundaries of the text of interest. In our case they are not, and I need to include them as well as what appears outside of the apostrophes, in this case the "C".

Anyone know a sneaky way to achieve this?

Many thanks!
0 Kudos
4 Replies
TimP
Honored Contributor III
638 Views
If you have tried only list-directed read, you'll probably need to read the entire line to a CHARACTER string usng A format, then find your string and copy it out by a CHARACTER assignment. Not very sneaky, somewhat old-fashioned.
0 Kudos
DavidWhite
Valued Contributor II
638 Views
Quoting - tim18
If you have tried only list-directed read, you'll probably need to read the entire line to a CHARACTER string usng A format, then find your string and copy it out by a CHARACTER assignment. Not very sneaky, somewhat old-fashioned.
Are you able to embed the string in double-quotes (")

If so, you can use the DELIM attribute on the READ so that the single-quotes are ignored as text delimiters.

David
0 Kudos
Steven_L_Intel1
Employee
638 Views
You cannot use list-directed input for this. I would agree with Tim's advice - read the whole line into a character variable and then "parse" it yourself, looking for delimiters that are correct for your line's syntax. It doesn't match anything Fortran can provide for you automatically.
0 Kudos
Stuart_M_
Beginner
638 Views
Thanks everyone

I eventually used a formatted read (A) that picked up all the necessary characters. Thanks very much for the help :-)
0 Kudos
Reply