|
|
Up |
|
|
  |
Author: brubru Date: May 13, 2008 00:50
Hello,
I have the folowing problem :
My data file contains one or more blocks composed of a title and a set
of numerical data. After one block it reads an other:
how to stop the calculation if I encounter a line of numerical data
instead of a title. I consider a title as it contains at least one non
numerical character (for example Case Nr3 a=1.2, b=6., c=80.)
Thanks for your help
Bernard Bru
|
| |
|
| | 14 Comments |
|
  |
Author: e p chandlere p chandler Date: May 13, 2008 02:21
On May 13, 3:50 am, bru wrote:
> Hello,
>
> I have the folowing problem :
>
> My data file contains one or more blocks composed of a title and a set
> of numerical data. After one block it reads an other:
>
> how to stop the calculation if I encounter a line of numerical data
> instead of a title. I consider a title as it contains at least one non
> numerical character (for example Case Nr3 a=1.2, b=6., c=80.)
>
> Thanks for your help
>
> Bernard Bru
This is a FAQ for which the answer is probably "use an internal read".
First read each record into a character variable. Examine the
character variable. Process appropriately. Read data - replacing the
usual unit specifier with the name of the character variable.
|
| Show full article (0.83Kb) |
|
| | no comments |
|
  |
Author: TerenceTerence Date: May 13, 2008 02:49
When in doubt about file contents, I process the file using direct
access in blocks of any suitable size, or else read using unformatted
binary mode.
Either way I then scan the input data for cr-lf then (to solve your
problem) see if any character ocur which cannot be part of numeric
data, between the first and last positions of this reoord.
This assumes the data is formatted and psesses a cr-lf or at least an
lf character. If not there has to either an end-of-record marker or
the equivalent, or the use of fixed length unformatted records (in
which case the use of direct access seems to be indicated).
|
| |
| no comments |
|
  |
Author: glen herrmannsfeldtglen herrmannsfeldt Date: May 13, 2008 03:10
bru wrote:
> My data file contains one or more blocks composed of a title and a set
> of numerical data. After one block it reads an other:
> how to stop the calculation if I encounter a line of numerical data
> instead of a title. I consider a title as it contains at least one non
> numerical character (for example Case Nr3 a=1.2, b=6., c=80.)
If you already know when it should be data and title, and
are reading the title into a CHARACTER variable, all you need
to do is check that variable. Note that you should be careful
what is a non-numeric character, through. Especially, D and E
are often numeric characters, and maybe other letters.
(Q for quad precision on some systems.)
DO I=1,LEN_TRIM(S)
IF((S(I:I).GT.'9'.OR.S(I:I).LT.'0') .AND.
# (S(I:I).NE.'+'.AND.S(I:I).NE.'-'.AND.S(I:I).NE.'.'
# .AND.S(I:I).NE.'E')) GOTO 999
ENDDO
or use a table and index with ACHAR(S(I:I)) to test for
non-numeric characters.
|
| Show full article (1.00Kb) |
| no comments |
|
  |
Author: Arjen MarkusArjen Markus Date: May 13, 2008 05:13
On 13 mei, 12:10, glen herrmannsfeldt ugcs.caltech.edu> wrote:
> bru wrote:
>> My data file contains one or more blocks composed of a title and a set
>> of numerical data. After one block it reads an other:
>> how to stop the calculation if I encounter a line of numerical data
>> instead of a title. I consider a title as it contains at least one non
>> numerical character (for example Case Nr3 a=1.2, b=6., c=80.)
>
> If you already know when it should be data and title, and
> are reading the title into a CHARACTER variable, all you need
> to do is check that variable. Note that you should be careful
> what is a non-numeric character, through. Especially, D and E
> are often numeric characters, and maybe other letters.
> (Q for quad precision on some systems.)
>
> DO I=1,LEN_TRIM(S)
> IF((S(I:I).GT.'9'.OR.S(I:I).LT.'0') .AND.
> # (S(I:I).NE.'+'.AND.S(I:I).NE.'-'.AND.S(I:I).NE.'.'
> # .AND.S(I:I).NE.'E')) GOTO 999
> ENDDO ...
|
| Show full article (1.49Kb) |
| no comments |
|
  |
Author: brubru Date: May 13, 2008 06:59
Arjen Markus wrote:
> On 13 mei, 12:10, glen herrmannsfeldt ugcs.caltech.edu> wrote:
>
>>bru wrote:
>>
>>>My data file contains one or more blocks composed of a title and a set
>>>of numerical data. After one block it reads an other:
>>> how to stop the calculation if I encounter a line of numerical data
>>>instead of a title. I consider a title as it contains at least one non
>>>numerical character (for example Case Nr3 a=1.2, b=6., c=80.)
>>
>>If you already know when it should be data and title, and
>>are reading the title into a CHARACTER variable, all you need
>>to do is check that variable. Note that you should be careful
>>what is a non-numeric character, through. Especially, D and E
>>are often numeric characters, and maybe other letters.
>>(Q for quad precision on some systems.)
>>
>> DO I=1,LEN_TRIM(S)
>> IF((S(I:I).GT.'9'.OR.S(I:I).LT.'0') .AND. ...
|
| Show full article (1.63Kb) |
| no comments |
|
  |
Author: GaryScottGaryScott Date: May 13, 2008 07:12
On May 13, 2:50 am, bru wrote:
> Hello,
>
> I have the folowing problem :
>
> My data file contains one or more blocks composed of a title and a set
> of numerical data. After one block it reads an other:
>
> how to stop the calculation if I encounter a line of numerical data
> instead of a title. I consider a title as it contains at least one non
> numerical character (for example Case Nr3 a=1.2, b=6., c=80.)
>
> Thanks for your help
>
> Bernard Bru
If I have control over the file format, I generally mark up the data
file to indicate the type of data on each record (millions of ways to
do that). You could just begin each line with a process control text
string like:
|
| Show full article (1.27Kb) |
| no comments |
|
  |
Author: glen herrmannsfeldtglen herrmannsfeldt Date: May 13, 2008 10:18
GaryScott wrote:
(snip)
> If I have control over the file format, I generally mark up the data
> file to indicate the type of data on each record (millions of ways to
> do that). You could just begin each line with a process control text
> string like:
> Title: This is the title
> Data: a=1.2, b=6.0...
(snip)
> and so on. If you have a large number of these, it would probably be
> faster than scanning the entire line for valid/invalid characters.
I know many programs that have a title line, then many data
lines, then another title line (for the next batch) and
many data lines, etc. Title lines should be rare enough that
the time needed to scan one isn't significant, but if the count
of data lines is wrong, it is nice to know.
> You can add other types of data as well. If you want to confuse
> somebody, you can make it look like html...
|
| Show full article (1.27Kb) |
| no comments |
|
  |
Author: Arjen MarkusArjen Markus Date: May 13, 2008 12:45
On 13 mei, 15:59, bru wrote:
> Arjen Markus wrote:
>> On 13 mei, 12:10, glen herrmannsfeldt ugcs.caltech.edu> wrote:
>
>>>bru wrote:
>
>>>>My data file contains one or more blocks composed of a title and a set
>>>>of numerical data. After one block it reads an other:
>>>> how to stop the calculation if I encounter a line of numerical data
>>>>instead of a title. I consider a title as it contains at least one non
>>>>numerical character (for example Case Nr3 a=1.2, b=6., c=80.)
>
>>>If you already know when it should be data and title, and
>>>are reading the title into a CHARACTER variable, all you need
>>>to do is check that variable. Note that you should be careful
>>>what is a non-numeric character, through. Especially, D and E
>>>are often numeric characters, and maybe other letters.
>>>(Q for quad precision on some systems.)
>
>>> DO I=1,LEN_TRIM(S) ...
|
| Show full article (1.95Kb) |
| no comments |
|
  |
|
|
  |
Author: John HarperJohn Harper Date: May 13, 2008 15:12
>
>That should be easier with verify(). For instance:
>
>if ( verify(line, ' -+.1234567890eEdDqQ') > 0 ) then
> write(*,*) 'line contains characters that can''t appear in purely
>numerical data'
>endif
That doesn't distinguish between non-numerical data like 'e ' or
'Deed' and valid numbers like '1e0' or 1.D-2'
-- John Harper, School of Mathematics, Statistics and Computer Science,
Victoria University, PO Box 600, Wellington 6140, New Zealand
e-mail john.harper@ vuw.ac.nz phone (+64)(4)463 6780 fax (+64)(4)463 5045
|
| |
| no comments |
|
|
|
|