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

Home » Public Forums » archive » ASCII import
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
ASCII import [message #48004] Sun, 26 March 2006 11:56 Go to next message
none is currently offline  none
Messages: 6
Registered: March 2006
Junior Member
Hi, i have to import a number of ASCII .txt files and save them as ENVI
standard images, but I can not found any IDL script able to do this; do
you know which is the code ENVI uses to to open generic format-ASCII
data ?
thanks
m
Re: ASCII import [message #48095 is a reply to message #48004] Tue, 28 March 2006 17:19 Go to previous messageGo to next message
none is currently offline  none
Messages: 6
Registered: March 2006
Junior Member
well jeff, thanks for your patience...
the file is made of 5,760,000 numbers, resulting in an image of 2400
columns * 2400 rows. the second number should be the pixel [0,1] and so
on, till the number #2401 that becomes the pixel [1,1].
thanks
marco
Re: ASCII import [message #48096 is a reply to message #48004] Tue, 28 March 2006 16:12 Go to previous messageGo to next message
Jeff N. is currently offline  Jeff N.
Messages: 120
Registered: April 2005
Senior Member
Ok, so now I think we're getting somewhere. What are the dimensions of
the final image though? Is it supposed to be a one column image as
well - so that the single column of ASCII input becomes a single column
image on output? If not, how do you know how to fill the output image?
Assuming that the first number in the text file is the value for pixel
[0,0], is the second number in the file for pixel [0,1], or is it for
[1,0], etc? You have to be able to describe all of this, which is why
it's impossible to just have one function that reads any ASCII file :)

Jeff



none wrote:
> hi jeff, thanks for replying; well, the txt file just consist of 1
> column of numbers, without semicolumns or commas separating them, and
> it should yield a one-band image, double precision data type.
> it looks like something like this..
> 0.3798
> -0.0277
> -0.0357
> -0.0287
> -0.0550
> -0.0415
> -0.0666
> -0.0868
> -0.0823
> -0.1248
>
> thanks
> marco
Re: ASCII import [message #48109 is a reply to message #48004] Tue, 28 March 2006 11:19 Go to previous messageGo to next message
none is currently offline  none
Messages: 6
Registered: March 2006
Junior Member
hi jeff, thanks for replying; well, the txt file just consist of 1
column of numbers, without semicolumns or commas separating them, and
it should yield a one-band image, double precision data type.
it looks like something like this..
0.3798
-0.0277
-0.0357
-0.0287
-0.0550
-0.0415
-0.0666
-0.0868
-0.0823
-0.1248

thanks
marco
Re: ASCII import [message #48128 is a reply to message #48004] Mon, 27 March 2006 21:19 Go to previous messageGo to next message
Jeff N. is currently offline  Jeff N.
Messages: 120
Registered: April 2005
Senior Member
Well, see here's the thing: there is no magic function to do this.
That's b/c there's lots of ways to organize data in an ASCII file, and
how you read the file obviously depends on how the file is set up. Why
don't you have a look at one of these ASCII files and describe the
format for us, then maybe we can help :)

Jeff
Re: ASCII import [message #48131 is a reply to message #48004] Mon, 27 March 2006 15:43 Go to previous messageGo to next message
none is currently offline  none
Messages: 6
Registered: March 2006
Junior Member
hi mike thanks a lot; it helps a lot, but what i am still missing is
the function to convert an ascii file in an ENVI format;
any clue ?
thanks
marco
Re: ASCII import [message #48178 is a reply to message #48004] Wed, 29 March 2006 14:12 Go to previous message
none is currently offline  none
Messages: 6
Registered: March 2006
Junior Member
grazie lorenzo,
thanks a lot, it seems to work
buona giornata
marco
Re: ASCII import [message #48186 is a reply to message #48095] Wed, 29 March 2006 07:16 Go to previous message
lbusett@yahoo.it is currently offline  lbusett@yahoo.it
Messages: 30
Registered: February 2006
Member
Hi Marco,

What about something like this ?

pro multiple_conversion

; Define image dimensions

n_col = 2400L
n_row = 2400L
arr_dim = n_col*n_row
tmp_array = fltarr (arr_dim)

; Select Input Files

file_list = dialog_pickfile ( title = 'Select files to convert',
/multiple_files)

; Begin the for loop to convert each file

for file = 0, n_elements(file_list-1) do begin

openr, in_lun, file_list [file], /get_lun ; Open the file
readf, in_lun, tmp_array ; Store data in a temporary array

;"Create" a square image from tmp_array

tmp_image = reform (tmp_array, n_col,n_row)
out_filename = file_list[file] + '_envi' ; Define output file

; Write envi output file
ENVI_WRITE_ENVI_FILE, tmp_image, out_name=out_filename free_lun,
in_lun
endfor
end

I didn't test it, so it's possible that it doesn't work, but I think
that this is a possible approach: Just select the files that you need
to convert, then read one file at a time with a simple READF
instruction, "reform" the data into a square matrix and write an output
with the ENVI dedicated write function (ENVI_WRITE_ENVI_FILE). You just
have to be sure that there is no header in your .txt files: otherwise,
you have to skip the header lines before you read "tmp_array".

Hope this helps,

Lorenzo



none wrote:
> well jeff, thanks for your patience...
> the file is made of 5,760,000 numbers, resulting in an image of 2400
> columns * 2400 rows. the second number should be the pixel [0,1] and so
> on, till the number #2401 that becomes the pixel [1,1].
> thanks
> marco
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: map_set, !map, !x, !p.position (and behind this curtain, !x.*)
Next Topic: A New error msg, for me: % Variable is undefined: <UNDEFINED>

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

Current Time: Wed Oct 08 14:56:17 PDT 2025

Total time taken to generate the page: 0.00503 seconds