Re: problem using strsplit [message #33656 is a reply to message #33523] |
Sat, 11 January 2003 13:38   |
R.Bauer
Messages: 1424 Registered: November 1998
|
Senior Member |
|
|
Brian wrote:
> I am relatively new to IDL and am probably missing something very
> obvious. I am reading in an ascii tab separated file into a string
> array. I know how many rows the file will contain but not how many
> columns hence the string array.
> I then try to use strsplit to separate all the columns but have an
> error - it seems that the columns are not seen as separate.
> Code and example file below.
>
> Any ideas would be useful,
> Thanks
> Brian Appleby
> Geophysicist
> BrianA@Zetica.com
>
Dear Brian
You can use our file reading routine,
It determines itselfs almost all parameter for file reading of an array
orientaded data file, with or without some comments in the header or at the
end.
http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_source/idl _html/dbase/download/read_data_file.tar.gz
idl binary
http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_source/idl _html/dbase/download/read_data_file.sav
for further routine and licensing lease have a look at
http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_lib_intro. html
If you don't like using these routines you can examine the number of columns
by counting the separator.
no_of_scans=5
OPENR, lun, 'file2.txt', / GET_LUN
rawdata=StrArr(no_of_scans)
ReadF,lun,rawdata
free_lun,lun
line=strtrim(strcompress(rawdata[0]),2)
; strcompress compresses blanks to one blank
; strim ,2 trailing blanks are removed
ix=where(byte(line) eq 32b,n)
n_columns=n+1
data=make_array(/long,value=-999,no_of_scans,n_columns)
reads,rawdata,data
; reads is doing the thing you like to do by strsplit I believe
In principle this is what read_data_file did, there is a bit more
source included to find comments at the beginning or ending so the number of
data lines could be internal calculated and
there is some source to determine or use the type of the numbers,
regards
Reimar
>
> pro test_ascii_reader
> ;setup some variable values to allow easy alteration if needed later
> no_of_scans=1000
> max_traces=1000
>
> ; open and read any ascii file with data/headers on single lines into
> ; a string array to be split later depending on type of data
> OPENR, lun, 'file2.txt', / GET_LUN
> rawdata=StrArr(no_of_scans)
> Point_Lun, lun, 0
> ReadF,lun,rawdata
> help,rawdata
>
> split_columns=STRSPLIT(rawdata,' ',/EXTRACT)
> help,split_columns
> end
>
>
>
> file2.txt - example data
> 65408 65408 65408 65408 65408
> 28800 28800 28800 28800 28800
> 32896 32896 32896 32896 32896
> 33152 33152 33152 33152 33152
> 33152 33152 33152 33152 33152
--
Forschungszentrum Juelich
email: R.Bauer@fz-juelich.de
http://www.fz-juelich.de/icg/icg-i/
============================================================ ======
a IDL library at ForschungsZentrum Juelich
http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_lib_intro. html
|
|
|