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

Home » Public Forums » archive » Re: variable types
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: variable types [message #11011 is a reply to message #10993] Fri, 20 February 1998 00:00 Go to previous messageGo to previous message
Martin Schultz is currently offline  Martin Schultz
Messages: 515
Registered: August 1997
Senior Member
David R. Klassen wrote:
>
> I'm in the process of writing a quick and dirty program to
> go through a text file and grab the lines that are ordered
> pairs of numbers and plot them. The problem comes with the
> fact that some of these data files have a line or two of
> text at the top.
>
> When I read each line of the file I parse it along white-spaces
> or tabs uisng the PARTS function (no problem so far). Then I
> assign the first two parts to my x and y arrays. The problem
> is that if the line read was a line of text, the parts can not
> be converted from string type to float type (it turns out that
> a string ' 13.456' *can* be turned into a float=13.456).
>
> My question: is there a way to test the variable type before
> I make the assignments?
>

yes, you will probably have to read in your line as string (it is really
a pity that the '$' format code does not work during input !), then you
can either go David's way to catch the error or test for a number
yourself:
readf,s [,format='(A)']
test = strpos('0123456789.+-',strmid(strtrim(s,1),0,1)) ge 0

Fortran data files sometimes use a line format like
N x1 x2 x3 ... xN, so you need to extract the first number
before you can read the others. In these cases, you should also read
the line into a string, [test the first character for a number] and
then extract the numbers using READS.

Regards,
Martin.

------------------------------------------------------------ -------
Dr. Martin Schultz
Department for Earth&Planetary Sciences, Harvard University
186 Pierce Hall, 29 Oxford St., Cambridge, MA-02138, USA

phone: (617)-496-8318
fax : (617)-495-4551

e-mail: mgs@io.harvard.edu
IDL-homepage: http://www-as.harvard.edu/people/staff/mgs/idl/
------------------------------------------------------------ -------
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: Re: PrintScreen
Next Topic: Re: general matrix multiplication

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

Current Time: Sun Oct 12 12:10:56 PDT 2025

Total time taken to generate the page: 2.95776 seconds