|
|
Up |
|
|
  |
Author: sk8terg1rlsk8terg1rl Date: Apr 8, 2007 11:30
Hi group, Happy Easter! :-)
I've been trying to read a line in an input file that has a mix of
characters & integers. The format can be assumed to be characters for
15 columns and a binary string of unknown/variable length.
The format of the input file 'test.txt':
|-CHARAC15-------|-----------INTEGER-----------.....
Binary string = 010101010 ....
The following test program fails:
Program test_format
Implicit None
Integer:: buffer
Integer, allocatable:: vector(:)
Character:: a15*15
buffer=1000
Allocate (vector(buffer))
Open (1,file='test.txt')
Read (1,*) a15, vector(1:10)
Print *, a15
print *, vector(1:10)
|
| Show full article (1.24Kb) |
|
| | 10 Comments |
|
  |
Author: BeliavskyBeliavsky Date: Apr 8, 2007 11:48
On Apr 8, 1:30 pm, "sk8terg1rl" yahoo.co.uk> wrote:
> Hi group, Happy Easter! :-)
>
> I've been trying to read a line in an input file that has a mix of
> characters & integers. The format can be assumed to be characters for
> 15 columns and a binary string of unknown/variable length.
>
> The format of the input file 'test.txt':
> |-CHARAC15-------|-----------INTEGER-----------.....
> Binary string = 010101010 ....
>
> The following test program fails:
You cleared the first hurdle of asking a good programming question by
posting what looks
like a complete code. But you didn't clear the 2nd
-- never say merely
that a program "fails" or "does not work" -- explain HOW it fails.
What output does it give, and how does that differ from what you want?
|
| |
|
| | no comments |
|
  |
Author: nospamnospam Date: Apr 8, 2007 12:07
sk8terg1rl yahoo.co.uk> wrote:
> The format of the input file 'test.txt':
> |-CHARAC15-------|-----------INTEGER-----------.....
> Binary string = 010101010 ....
>
> The following test program fails:
...
> Read (1,*) a15, vector(1:10)
Not surprising. There are no delimitters (blanks or commas) between the
integers. I can't imagine how one would expect the compiler to read your
mind to guess that you might mean to read each digit into a separate
integer. Anyway...
|
| Show full article (2.80Kb) |
| no comments |
|
  |
Author: James GilesJames Giles Date: Apr 8, 2007 12:20
sk8terg1rl wrote:
...
> Integer:: buffer
> Integer, allocatable:: vector(:)
> Character:: a15*15
> buffer=1000
> Allocate (vector(buffer))
> Open (1,file='test.txt')
> Read (1,*) a15, vector(1:10)
> Print *, a15
> print *, vector(1:10)
...
]> - If I change the Read statement to Read (1,'(a15,10000i1)') it works.
> However I want to read it in as free format if possible, so that if
> the binary string is longer than 10000 bits, my program won't cause
> problems.
> - Similarly for writing out large arrays...I don't want to have to
> specify "Write (1,'(a15,10000i1)')" as arrays larger than 10000 would
> get truncated.
> - Is there an easy way to get the program to initially parse test.txt, ...
|
| Show full article (2.29Kb) |
| no comments |
|
  |
Author: Dick HendricksonDick Hendrickson Date: Apr 8, 2007 12:28
sk8terg1rl wrote:
> Hi group, Happy Easter! :-)
>
> I've been trying to read a line in an input file that has a mix of
> characters & integers. The format can be assumed to be characters for
> 15 columns and a binary string of unknown/variable length.
>
> The format of the input file 'test.txt':
> |-CHARAC15-------|-----------INTEGER-----------.....
> Binary string = 010101010 ....
>
> The following test program fails:
> Program test_format
> Implicit None
>
> Integer:: buffer
> Integer, allocatable:: vector(:)
> Character:: a15*15
> buffer=1000
> Allocate (vector(buffer)) ...
|
| Show full article (3.04Kb) |
| no comments |
|
  |
|
|
  |
Author: sk8terg1rlsk8terg1rl Date: Apr 8, 2007 14:03
On 8 Apr, 19:07, nos...@see.signature (Richard Maine) wrote:
> sk8terg1rl yahoo.co.uk> wrote:
>> The format of the input file 'test.txt':
>> |-CHARAC15-------|-----------INTEGER-----------.....
>> Binary string = 010101010 ....
>
>> The following test program fails:
> ...
>> Read (1,*) a15, vector(1:10)
Hi Richard, thanks for replying.
> Not surprising. There are no delimitters (blanks or commas) between the
> integers. I can't imagine how one would expect the compiler to read your
> mind to guess that you might mean to read each digit into a separate
> integer. Anyway...
My answer to Beliavsky is with an input file which has delimiters. So
each binary bit occupies 3 columns (space/bit/space).
|
| Show full article (3.96Kb) |
| no comments |
|
|
|
|