Re: Ascii-import [message #32023] |
Tue, 10 September 2002 07:38  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Reimar Bauer (R.Bauer@fz-juelich.de) writes:
> I know, I was the author, long time ago.
Well, there you go. Even then your programs had the
stamp of timeless elegance. :-)
I'll be recommending this in the future, rather than
my bone-headed, brute-force method. :-(
Cheers,
David
--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|
|
Re: Ascii-import [message #32025 is a reply to message #32024] |
Tue, 10 September 2002 06:58   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Thomas Jordi (tschordi@giub.unibe.ch) writes:
> Thanks to both of you. As the ascii_read didn't work I first posted,
> then thought.
> This is how i finally resolved it (with w eq filename):
>
> OPENR, unit10, w, /GET_LUN
> buf=''
> count=0
> WHILE (NOT EOF(unit10)) DO BEGIN
> READF, unit10, buf
> count=count+1
> ENDWHILE
> CLOSE, unit10 & FREE_LUN, unit10
> img=STRARR(count)
> OPENR, unit9, w, /GET_LUN
> READF, unit9, img
> CLOSE, unit9 & FREE_LUN, unit9
>
> some sort of countrows...
That's pretty much it. :-)
You don't need to use the CLOSE statement, by the way.
FREE_LUN will both close and free the logical unit number.
CLOSE is only required for those logical unit numbers you
assign directly, not those you obtain with GET_LUN or the
GET_LUN keyword.
Cheers,
David
--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|
Re: Ascii-import [message #32027 is a reply to message #32025] |
Tue, 10 September 2002 06:40   |
Thomas Jordi
Messages: 5 Registered: August 2002
|
Junior Member |
|
|
> There are much easier ways to read this kind of data
> than READ_ASCII. Here is an example using the COUNT_ROWS
> program you can find on my web page:
>
> num_rows = Count_Rows(filename)
> data = StrArr(num_rows)
> OpenR, lun, filename, /Get_Lun
> ReadF, lun, data
> Free_Lun, lun
>
Thanks to both of you. As the ascii_read didn't work I first posted,
then thought.
This is how i finally resolved it (with w eq filename):
OPENR, unit10, w, /GET_LUN
buf=''
count=0
WHILE (NOT EOF(unit10)) DO BEGIN
READF, unit10, buf
count=count+1
ENDWHILE
CLOSE, unit10 & FREE_LUN, unit10
img=STRARR(count)
OPENR, unit9, w, /GET_LUN
READF, unit9, img
CLOSE, unit9 & FREE_LUN, unit9
some sort of countrows...
tnx again
Thomas
> Cheers,
>
> David
> --
> David W. Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Phone: 970-221-0438, E-mail: david@dfanning.com
> Coyote's Guide to IDL Programming: http://www.dfanning.com/
> Toll-Free IDL Book Orders: 1-888-461-0155
--
�`����,��,�`ï¿½ï ¿½ï¿½ï¿½,�
Thomas Jordi
Geographisches Institut
Universitaet Bern
Hallerstrasse 12
3012 Bern
tschordi@giub.unibe.ch
�`����,��,�`ï¿½ï ¿½ï¿½ï¿½
|
|
|
|
Re: Ascii-import [message #32030 is a reply to message #32029] |
Tue, 10 September 2002 06:00   |
R.Bauer
Messages: 1424 Registered: November 1998
|
Senior Member |
|
|
David Fanning wrote:
> Thomas Jordi (tschordi@giub.unibe.ch) writes:
>
>
>> it may sound dumb but i have problems importing ascii.
>> The file I want to import looks like this
>>
>> /path/filename.file
>> /path/filename.file
>> ...
>>
>> when using the toolbar button, I get the desired input, a struct
>> containg a field with as much strings as lines in the file.
>> But i like to use the ascii_read function, and this just doesnt work.
>> Well, it does work with a template, but then again I'm using this
>> graphical interface which I dont want to use.
>>
>> There isn't a keyword in the read_ascii function, to say only on record
>> per row, each row is a recrod, at least I dont find it. Perhaps it has
>> something to do with the fact, that I want to import strings and not
>> integers.
>>
>> any help would be appreciated
>
>
> There are much easier ways to read this kind of data
> than READ_ASCII. Here is an example using the COUNT_ROWS
> program you can find on my web page:
>
> num_rows = Count_Rows(filename)
> data = StrArr(num_rows)
> OpenR, lun, filename, /Get_Lun
> ReadF, lun, data
> Free_Lun, lun
>
> Cheers,
>
> David
Dear David,
I believe you are telling from
http://www.dfanning.com/tip_examples/file_line.pro
or whats the difference.
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/icg-i/idl_icglib/idl_lib_intro. html
============================================================ =======
|
|
|
Re: Ascii-import [message #32031 is a reply to message #32030] |
Tue, 10 September 2002 05:59   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Thomas Jordi (tschordi@giub.unibe.ch) writes:
> it may sound dumb but i have problems importing ascii.
> The file I want to import looks like this
>
> /path/filename.file
> /path/filename.file
> ...
>
> when using the toolbar button, I get the desired input, a struct
> containg a field with as much strings as lines in the file.
> But i like to use the ascii_read function, and this just doesnt work.
> Well, it does work with a template, but then again I'm using this
> graphical interface which I dont want to use.
>
> There isn't a keyword in the read_ascii function, to say only on record
> per row, each row is a recrod, at least I dont find it. Perhaps it has
> something to do with the fact, that I want to import strings and not
> integers.
>
> any help would be appreciated
There are much easier ways to read this kind of data
than READ_ASCII. Here is an example using the COUNT_ROWS
program you can find on my web page:
num_rows = Count_Rows(filename)
data = StrArr(num_rows)
OpenR, lun, filename, /Get_Lun
ReadF, lun, data
Free_Lun, lun
Cheers,
David
--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|
Re: Ascii-import [message #32032 is a reply to message #32031] |
Tue, 10 September 2002 04:34   |
R.Bauer
Messages: 1424 Registered: November 1998
|
Senior Member |
|
|
Thomas Jordi wrote:
> it may sound dumb but i have problems importing ascii.
> The file I want to import looks like this
>
> /path/filename.file
> /path/filename.file
> ...
>
> when using the toolbar button, I get the desired input, a struct
> containg a field with as much strings as lines in the file.
> But i like to use the ascii_read function, and this just doesnt work.
> Well, it does work with a template, but then again I'm using this
> graphical interface which I dont want to use.
>
> There isn't a keyword in the read_ascii function, to say only on record
> per row, each row is a recrod, at least I dont find it. Perhaps it has
> something to do with the fact, that I want to import strings and not
> integers.
>
> any help would be appreciated
>
> tschordi
Dear Thomas,
you can try my read_data_file function.
This function determines itselfs data files.
In this version it's able to read all tabulars where data columns are
numbers. If you have strings in your columns I can sent the new version
to you. It separates itselfs header comments before the tabular and past
the tabular. The type is set to double by default. If you like to have
float you can use the /floyt keyword. If you like to see an assistant
program you can use /assist. More is described in the routine.
http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_source/idl _html/dbase/download/read_data_file.tar.gz
or as IDL 5.5 binary
http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_source/idl _html/dbase/download/read_data_file.sav
x=read_data_file('/path/filename.file')
The result is a structure
help,x,/str
For further routines and licensing please have a look at
http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_lib_intro. html
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/icg-i/idl_icglib/idl_lib_intro. html
============================================================ =======
|
|
|
Re: Ascii-import [message #32070 is a reply to message #32027] |
Thu, 12 September 2002 08:06  |
thompson
Messages: 584 Registered: August 1991
|
Senior Member |
|
|
Thomas Jordi <tschordi@giub.unibe.ch> writes:
>> There are much easier ways to read this kind of data
>> than READ_ASCII. Here is an example using the COUNT_ROWS
>> program you can find on my web page:
>>
>> num_rows = Count_Rows(filename)
>> data = StrArr(num_rows)
>> OpenR, lun, filename, /Get_Lun
>> ReadF, lun, data
>> Free_Lun, lun
>>
> Thanks to both of you. As the ascii_read didn't work I first posted,
> then thought.
> This is how i finally resolved it (with w eq filename):
> OPENR, unit10, w, /GET_LUN
> buf=''
> count=0
> WHILE (NOT EOF(unit10)) DO BEGIN
> READF, unit10, buf
> count=count+1
> ENDWHILE
> CLOSE, unit10 & FREE_LUN, unit10
> img=STRARR(count)
> OPENR, unit9, w, /GET_LUN
> READF, unit9, img
> CLOSE, unit9 & FREE_LUN, unit9
> some sort of countrows...
> tnx again
> Thomas
You can also do this in one pass through the file with something like the
following.
OPENR, unit10, w, /GET_LUN
buf=''
count=0
WHILE (NOT EOF(unit10)) DO BEGIN
READF, unit10, buf
count=count+1
if count eq 1 then img = buf else img = [img, buf]
ENDWHILE
FREE_LUN, unit10
William Thompson
|
|
|