Re: simple question about bytes [message #16984] |
Thu, 02 September 1999 00:00  |
meron
Messages: 51 Registered: July 1995
|
Member |
|
|
In article <37CEA812.98FA89F3@zedat.fu-berlin.de>, rappold <rappold@zedat.fu-berlin.de> writes:
> Hi,
>
> I want to check if a line in an ascii file starts with a number or
> character. My idea was to read the first character and convert it to
> "byte" and check if its in or out the range of '48b' and '58b'. The code
> example is :
>
> ; check for header
> header=''
> readf, lun, header
> firstchar=strmid(header,0,1)
> first_byte=byte(firstchar)
>
> no_head=0
> head_index=0
> WHILE ((first_byte LT 48b) AND (first_byte GT 57b)) DO BEGIN
> readf, lun, header ; reads next line
> head_index=head_index+1 ; counts header lines
> no_header =head_index
> ENDWHILE
> ...
>
> it compiles fine but on runtime I get the errormessage :
>
> Expression must be a scalar in this context: <BYTE Array(1)>
>
> How can I change the variable 'first_byte' from byte array to a byte
> scalar ?
>
OK, the problem is simple. The command
> first_byte=byte(firstchar)
Generates an array (of length 1, but still an array), something you
can easily ascertain by doing
print, size(first_byte)
The work around is also simple. Replace the offending line by
> first_byte=(byte(firstchar))(0)
Mati Meron | "When you argue with a fool,
meron@cars.uchicago.edu | chances are he is doing just the same"
|
|
|