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

Home » Public Forums » archive » READF data containing numbers and strings
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
READF data containing numbers and strings [message #30997] Wed, 29 May 2002 18:39 Go to next message
Eric Vella is currently offline  Eric Vella
Messages: 8
Registered: April 1999
Junior Member
I need to read data from a file which contain lines with mixed variables
including strings, for example "1 2 text 3". I tried "READF, int1, int2,
str1, int3", but str1 gobbles up the rest of the line, leaving nothing for
int3. This happens even if I supply an explicit format like A4 for the
string. I can read the entire line into a single string, but then how do I
separate the variables? STR_SEP does not work, since the separation
character has to be a blank, and there can be multiple blanks between
variables. I am hoping there is something simple I am missing (as is
usually the case with IDL, simple only after you know the answer) ....
Re: READF data containing numbers and strings [message #31061 is a reply to message #30997] Mon, 03 June 2002 23:22 Go to previous message
R.Bauer is currently offline  R.Bauer
Messages: 1424
Registered: November 1998
Senior Member
Eric Vella wrote:
>
> I need to read data from a file which contain lines with mixed variables
> including strings, for example "1 2 text 3". I tried "READF, int1, int2,
> str1, int3", but str1 gobbles up the rest of the line, leaving nothing for
> int3. This happens even if I supply an explicit format like A4 for the
> string. I can read the entire line into a single string, but then how do I
> separate the variables? STR_SEP does not work, since the separation
> character has to be a blank, and there can be multiple blanks between
> variables. I am hoping there is something simple I am missing (as is
> usually the case with IDL, simple only after you know the answer) ....

Dear Eric

here is a small program which should explain itselfs.



pro test

s={var1:bytarr(2),var2:bytarr(3),var3:bytarr(4),var5:bytarr( 2)}
x=fileline('data.txt',bytarr=byt)
; x is the number of lines
; could be used to replicate s
reads,byt,s
n=n_tags(s)
For i=0,n-1 do $
if is_number(string(s.(i))) then print, float(string(s.(i))) $
else print, string(s.(i))
end

1.00000
2.00000
text
3.00000


Used routines from our library are:

http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_source/idl _html/dbase/download/fileline.tar.gz
http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_source/idl _html/dbase/download/is_number.tar.gz


regards
Reimar

--
Reimar Bauer

Institut fuer Stratosphaerische Chemie (ICG-I)
Forschungszentrum Juelich
email: R.Bauer@fz-juelich.de
------------------------------------------------------------ -------
a IDL library at ForschungsZentrum Juelich
http://www.fz-juelich.de/icg/icg1/idl_icglib/idl_lib_intro.h tml
============================================================ =======
Re: READF data containing numbers and strings [message #31065 is a reply to message #30997] Wed, 29 May 2002 19:15 Go to previous message
Mark Hadfield is currently offline  Mark Hadfield
Messages: 783
Registered: May 1995
Senior Member
"Eric Vella" <eric.vella.remove@kla-tencor.com> wrote in message
news:3cf5821f$1@nntp.kla-tencor.com...

> ...I can read the entire line into a single string, but then how do
> I separate the variables? STR_SEP does not work, since the
> separation character has to be a blank, and there can be multiple
> blanks between variables....

STRSPLIT can split on blocks of white space.

--
Mark Hadfield "Ka puwaha et tai nei, Hoea tatou"
m.hadfield@niwa.co.nz
National Institute for Water and Atmospheric Research (NIWA)
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: the length of line
Next Topic: Structure reforming

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

Current Time: Wed Oct 08 18:38:16 PDT 2025

Total time taken to generate the page: 0.00481 seconds