READF data containing numbers and strings [message #30997] |
Wed, 29 May 2002 18:39  |
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  |
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
============================================================ =======
|
|
|
|