[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: simple question about bytes




rappold <rappold@zedat.fu-berlin.de> writes:
> 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)>

The byte() function converts a string to a byte array.  In this case
the byte array has a length of one.

Which gets me to my second point.  For some reason, conditional
expressions are not acceptable by IDL if they are 1-element arrays.
The remedy is the following:

     WHILE ((first_byte(0) LT 48b) AND (first_byte(0) GT 57b)) DO BEGIN

Which gets me to my third point.  You don't seem to be recalculating
first_byte in the loop.  You will probably end up reading the whole
file before failing.

Good luck,

Craig

-- 
--------------------------------------------------------------------------
Craig B. Markwardt, Ph.D.         EMAIL:    craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
--------------------------------------------------------------------------