Reading values sequentially 
Author Message
 Reading values sequentially

Hello, I have a quick question about reading text from a file. My file has
the format:
LABEL VALUE
Where LABEL is a string (size 16) and value is a real, integer or string.
I have tried reading them in with the format ('A, I') or ('A, F'), but it
never works. I am using the appropriate type depending on what type VALUE
is. What type of format should I use to read this data in? Also, is it
possible to specify a format that will read in a file that is '='
delimited? ie: LABEL=VALUE, and label can be anything under 16 chars. I'm
trying to develop a nice way to configure a program through these files.
Any help would be very much appreciated!


Mon, 01 Aug 2005 09:41:59 GMT  
 Reading values sequentially

Quote:

> Hello, I have a quick question about reading text from a file. My file has
> the format:
> LABEL VALUE
> Where LABEL is a string (size 16) and value is a real, integer or string.
> I have tried reading them in with the format ('A, I') or ('A, F'), but it
> never works.

Multiple problems with those formats.  First the quotes.  Why do you have
quotes at all?  If you were using a character string format then
'(a, i)' or '(a, f)' would be at least closer, but putting quotes inside
of the format itself isn't going to do anything at all like what you want.
Those formats don't have any edit descriptors at all - just a literal
string.

Second, I and F aren't legal edit descriptors, even when you fix the quote
problems.  The field widths that go with those edit descriptors are
*NOT* optional.  The field width is optional for the "A" edit descriptor.
In that case the field width is picked up from the length of the character
variable you are reading into.

I can't tell from your description exactly what the input data
actually looks like.  In particular, I can't tell whether it is in
fixed width fields or whether it is perhaps blank-delimitted.  For
fixed-width fields, you'd be ok after fixing the quotes and adding
the appropriate field widths.  For blank-delimitted fields, you'd
need a different approach - possibly list-directed read, if you
are using f90 and the string is guaranteed not to have "problematic"
characters; otherwise, it is a little harder.

--
Richard Maine
email: my last name at domain
domain: isomedia dot com



Mon, 01 Aug 2005 10:36:01 GMT  
 Reading values sequentially
Why dont you try namelist inputs? Namelist have the format :

You declare it in the code as

namelist / Namelist_Group / Variable1, Variable2

and you read it as

read(unit_num, Namelist_Group)

THe input file reads like this

&Namelist_Group
Variable1 = value
Variable2 = value
...
/

This takes care of all variable types etc.Any half way decent book should
explain in more detail.
ajs

Quote:

> Hello, I have a quick question about reading text from a file. My file has
> the format:
> LABEL VALUE
> Where LABEL is a string (size 16) and value is a real, integer or string.
> I have tried reading them in with the format ('A, I') or ('A, F'), but it
> never works. I am using the appropriate type depending on what type VALUE
> is. What type of format should I use to read this data in? Also, is it
> possible to specify a format that will read in a file that is '='
> delimited? ie: LABEL=VALUE, and label can be anything under 16 chars. I'm
> trying to develop a nice way to configure a program through these files.
> Any help would be very much appreciated!



Mon, 01 Aug 2005 18:36:02 GMT  
 Reading values sequentially

Quote:

> Hello, I have a quick question about reading text from a file. My file has
> the format:
> LABEL VALUE
> Where LABEL is a string (size 16) and value is a real, integer or string.
> I have tried reading them in with the format ('A, I') or ('A, F'), but it
> never works. I am using the appropriate type depending on what type VALUE
> is. What type of format should I use to read this data in? Also, is it
> possible to specify a format that will read in a file that is '='
> delimited? ie: LABEL=VALUE, and label can be anything under 16 chars. I'm
> trying to develop a nice way to configure a program through these files.
> Any help would be very much appreciated!

Why dont you try namelists to do this? Namelist inputs are meant to do
this very thing! Any book should have it.

ajs



Mon, 01 Aug 2005 20:58:07 GMT  
 Reading values sequentially

Quote:

> Why dont you try namelist inputs? Namelist have the format :

> You declare it in the code as

> namelist / Namelist_Group / Variable1, Variable2

> and you read it as

> read(unit_num, Namelist_Group)

> THe input file reads like this

> &Namelist_Group
> Variable1 = value
> Variable2 = value
> ...
> /

> This takes care of all variable types etc.Any half way decent book should
> explain in more detail.
> ajs


>> Hello, I have a quick question about reading text from a file. My file
>> has the format:
>> LABEL VALUE
>> Where LABEL is a string (size 16) and value is a real, integer or string.
>> I have tried reading them in with the format ('A, I') or ('A, F'), but it
>> never works. I am using the appropriate type depending on what type VALUE
>> is. What type of format should I use to read this data in? Also, is it
>> possible to specify a format that will read in a file that is '='
>> delimited? ie: LABEL=VALUE, and label can be anything under 16 chars. I'm
>> trying to develop a nice way to configure a program through these files.
>> Any help would be very much appreciated!

That's exactly what I needed. Thanks for the help guys!


Tue, 02 Aug 2005 10:45:01 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. URGENT reading file sequentially - driving me to despair

2. How to read a xml-file sequentially

3. Newbie: Implementation of methods sequentially

4. Sequentially processed procedures

5. VSAM: Accessing file sequentially and dynamically in same program

6. Can an object be pickled sequentially.

7. Newbie question: Run Win95 apps sequentially in PythonWin?

8. Q: Reading Return Value from AWK Program

9. Read last value

10. Read a value from an Environment setting (CLABUTTON,...)

11. search(read) string or value from email

12. How Can You Read A Windows Registry Value in Clarion 2.003

 

 
Powered by phpBB® Forum Software