comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: simple question about bytes
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: simple question about bytes [message #16984] Thu, 02 September 1999 00:00
meron is currently offline  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"
Re: simple question about bytes [message #16985 is a reply to message #16984] Thu, 02 September 1999 00:00 Go to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
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
------------------------------------------------------------ --------------
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Copying an object
Next Topic: wheel-mouse

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 17:03:06 PDT 2025

Total time taken to generate the page: 0.00675 seconds