Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Fortran 'read' statement question
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  10 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
jj_76  
View profile  
 More options Jun 17 2008, 1:29 pm
Newsgroups: comp.lang.fortran
From: jj_76 <krav...@yahoo.com>
Date: Tue, 17 Jun 2008 10:29:19 -0700 (PDT)
Local: Tues, Jun 17 2008 1:29 pm
Subject: Fortran 'read' statement question
hi,

I have the following data format:

 Date:       1997  2 21.0   dE/E:  1.34138E-07   dL/L:  2.61358E-15
 Date:       1998  7  6.0   dE/E:  8.72011E-08   dL/L:  5.22716E-15
 Date:       1999 11 18.0   dE/E:  1.25871E-07   dL/L:  3.92037E-15
 Date:       2001  4  1.0   dE/E:  2.85034E-08   dL/L:  4.29374E-15
 Date:       2002  8 14.0   dE/E:  1.42615E-07   dL/L:  1.86684E-15

When I try to read this data using the following 'read' statement, it
is not reading beyond 'dE'. It does not print anything beyond the 'dE'
in the above file (i.e, starting from '/')....My 'read' statement and
output is below:

 read(10,*)test1,test2,test3,test4,test5,test6
 print *,test1,test2,test3,test4,test5,test6

output:
Date: 1997  2 21.0 dE
Date: 1998  7  6.0  dE
Date: 1999 11 18.0 dE
Date: 2001  4  1.0  dE
Date: 2002  8 14.0 dE

Any help is appreciated
Thanks


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
dpb  
View profile  
 More options Jun 17 2008, 1:55 pm
Newsgroups: comp.lang.fortran
From: dpb <n...@non.net>
Date: Tue, 17 Jun 2008 12:55:56 -0500
Local: Tues, Jun 17 2008 1:55 pm
Subject: Re: Fortran 'read' statement question
jj_76 wrote:

...snip example of attempting list-directed read on data file w/ "/"
character in record...

...

"If a slash ( / ) is encountered during execution, the READ statement is
terminated, and any remaining input list items are unchanged."

You need an explicit FORMAT statement.

--


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Richard Maine  
View profile  
 More options Jun 17 2008, 2:09 pm
Newsgroups: comp.lang.fortran
From: nos...@see.signature (Richard Maine)
Date: Tue, 17 Jun 2008 11:09:34 -0700
Local: Tues, Jun 17 2008 2:09 pm
Subject: Re: Fortran 'read' statement question

dpb <n...@non.net> wrote:
> jj_76 wrote:
> ...snip example of attempting list-directed read on data file w/ "/"
> character in record...

> ...

> "If a slash ( / ) is encountered during execution, the READ statement is
> terminated, and any remaining input list items are unchanged."

> You need an explicit FORMAT statement.

Yes. Though that's a slight PITA for data like that shown, which appears
to be blank delimitted instead of in fixed field widths.

My recommended approach for data like this (assuming that doing
something like changing the input data format isn't an option - quotes
would solve it easily for example) is:

1. Read the whole line into a character string using "A" format.

2. Separate the fields by searching for the blank delimitters. Make use
of the INDEX, SCAN, and/or VERIFY intrinsics to do so. I've got my own
subroutine that I use for such things, but it in turn uses other of my
utility procedures. Probably about as easy to roll your own; it isn't
very hard. Most people that do a lot of Fortran input parsing probably
have one in their toolbox of handy routines.

3. Use an internal list-directed read to decode the data from each field
(except for the character fields, which don't need any further
decoding).

--
Richard Maine                    | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle           |  -- Mark Twain


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
jj_76  
View profile  
 More options Jun 17 2008, 2:41 pm
Newsgroups: comp.lang.fortran
From: jj_76 <krav...@yahoo.com>
Date: Tue, 17 Jun 2008 11:41:28 -0700 (PDT)
Local: Tues, Jun 17 2008 2:41 pm
Subject: Re: Fortran 'read' statement question
On Jun 17, 1:55 pm, dpb <n...@non.net> wrote:

> jj_76 wrote:

> ...snip example of attempting list-directed read on data file w/ "/"
> character in record...

> ...

> "If a slash ( / ) is encountered during execution, the READ statement is
> terminated, and any remaining input list items are unchanged."

> You need an explicit FORMAT statement.

> --

Thanks...FORMAT statement worked !

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Giles  
View profile  
 More options Jun 17 2008, 2:50 pm
Newsgroups: comp.lang.fortran
From: "James Giles" <jamesgi...@worldnet.att.net>
Date: Tue, 17 Jun 2008 18:50:09 GMT
Local: Tues, Jun 17 2008 2:50 pm
Subject: Re: Fortran 'read' statement question

In this case, why not use your step 1, but then replace all the '/'
characters with something else ('÷' say)?  Then read the whole
buffer with internal list-directed.  To be sure, there also isn't
a REPLACE intrinsic.  But, as you say, it's fairly easy to roll your
own.  No sense reproducing the kind of parsing list-directed
already does.

--
J. Giles

"I conclude that there are two ways of constructing a software
design: One way is to make it so simple that there are obviously
no deficiencies and the other way is to make it so complicated
that there are no obvious deficiencies."   --  C. A. R. Hoare

"Simplicity is prerequisite for reliability"  -- E. W. Dijkstra


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Richard Maine  
View profile  
 More options Jun 17 2008, 3:10 pm
Newsgroups: comp.lang.fortran
From: nos...@see.signature (Richard Maine)
Date: Tue, 17 Jun 2008 12:10:00 -0700
Subject: Re: Fortran 'read' statement question

James Giles <jamesgi...@worldnet.att.net> wrote:
> In this case, why not use your step 1, but then replace all the '/'
> characters with something else ('÷' say)?  Then read the whole
> buffer with internal list-directed.

That would also work.

--
Richard Maine                    | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle           |  -- Mark Twain


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
jj_76  
View profile  
 More options Jun 17 2008, 3:16 pm
Newsgroups: comp.lang.fortran
From: jj_76 <krav...@yahoo.com>
Date: Tue, 17 Jun 2008 12:16:26 -0700 (PDT)
Local: Tues, Jun 17 2008 3:16 pm
Subject: Re: Fortran 'read' statement question

> 1. Read the whole line into a character string using "A" format.

--------------

That's exactly what I did. I read the whole thing into a character
string and converted the required numbers into floats:

character(len=67)::test1
real *8 frac

read(10,100)test1
read(test1(36:46),fmt='(f11.9)')frac

100 format(a67)

thanks for the help.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
dpb  
View profile  
 More options Jun 17 2008, 3:40 pm
Newsgroups: comp.lang.fortran
From: dpb <n...@non.net>
Date: Tue, 17 Jun 2008 14:40:12 -0500
Local: Tues, Jun 17 2008 3:40 pm
Subject: Re: Fortran 'read' statement question

jj_76 wrote:
>> 1. Read the whole line into a character string using "A" format.
> --------------

> That's exactly what I did. I read the whole thing into a character
> string and converted the required numbers into floats:

> character(len=67)::test1
> real *8 frac

> read(10,100)test1
> read(test1(36:46),fmt='(f11.9)')frac

> 100 format(a67)

If that was all that was needed, the following would be somewhat easier
ways (for the future)...

read(10,'(A)') test1
read(test1(36:46),*) frac

a)  The simple "A" format will read the length of the variable w/o a
precise count, and
b( The substring selection eliminates the "/" problem character so you
can use list-directed formatting again.

Or, since it was a fixed-column file, you could simply skip the required
number of columns something like

read(10,'(35X,E11.5)') frac

Or, as Richard and James pointed out, a little alternative work in one
of a couple of ways could leave you w/ being able to use the
list-directed i/o, too.

--


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
relaxmike  
View profile  
 More options Jun 18 2008, 9:46 am
Newsgroups: comp.lang.fortran
From: relaxmike <michael.bau...@gmail.com>
Date: Wed, 18 Jun 2008 06:46:00 -0700 (PDT)
Subject: Re: Fortran 'read' statement question
Hi,

In that particular situation, I would personally not try to
find a suitable fortran format to read the data.
That way of doing imply that each file requires its own parser,
which is at the exact opposite of current software practices.
Instead, I would turn the file into a standard data format,
and directly use a component to read that format.
For example, it would be easy to transform the previous data into
a csv data file and use a csv fortran component, isn'it ?

Regards,

Michaėl


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
robin  
View profile  
 More options Jun 28 2008, 12:01 am
Newsgroups: comp.lang.fortran
From: "robin" <robi...@bigpond.com>
Date: Sat, 28 Jun 2008 04:01:42 GMT
Local: Sat, Jun 28 2008 12:01 am
Subject: Re: Fortran 'read' statement question
"Richard Maine" <nos...@see.signature> wrote in message

news:1iiohra.17ipynwti92b0N%nospam@see.signature...

> James Giles <jamesgi...@worldnet.att.net> wrote:

> > In this case, why not use your step 1, but then replace all the '/'
> > characters with something else ('÷' say)?  Then read the whole
> > buffer with internal list-directed.

> That would also work.

Not if the line already has the character '÷' in it.

However, this difficulty can be overcome by
keeping a record of which characters were replaced,
and then later re-instating the altered ones.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »