ascii-template [message #44137] |
Wed, 18 May 2005 03:01  |
Lasse Clausen
Messages: 22 Registered: August 2001
|
Junior Member |
|
|
greetings.
i am reading and writing a lot of ascii text files with data. it works
like this:
1) i write data in columns into a ascii file
2) i use a self implemented function which uses ASCII_TEMPLATE and SAVE to
save an ascii template which contains the names of the columns in the data
file
3) when reading the data i use RESTORE to restore the template and use it
in the READ_ASCII function.
in the course of my work this format of the ascii data file changes. new
columns appear, other columns disappear. everytime that happens i have to
use my SAVE_ASCII_TEMPLATE function to make a whole new template which is
annoying if the data file now contains 25 columns instead of 26 because i
have to type in the names of the 25 columns again although they haven't
changed.
does anybody know if i can directly manipulate the saved ascii template?
the documentation of the structure ASCII_TEMPLATE produces is rather poor.
thank you very much
lasse clausen
|
|
|
Re: ascii-template [message #44195 is a reply to message #44137] |
Sun, 22 May 2005 12:14  |
Justin[4]
Messages: 2 Registered: March 2005
|
Junior Member |
|
|
If your files are reasonably simple (space or tab delimited) I would
avoid the use of ascii_template altogether and use a structure to define
what each line looks like, replicate the line and readf it into an array.
E.g. for 4 columns (3 integers and a float) use:
line = {year:0, month:0, day:0, temperature:0.0}
num_lines = 1000 ; Could use file_lines or similar to count the lines here
data = REPLICATE(line, num_lines) ;Make array to hold data
OPENR, lun, filename, /GET_LUN
READF, lun, data ;Read in all the data
FREE_LUN, lun ;Close file
PRINT, data[100].temperature ; Print the 101st temp
Then as your file changes just change the definition of the line
structure. Of course if you have a complicated file structure you'll need
to stick with the flexibility (and complexity) of READ_ASCII.
HTH
Justin
On Wed, 18 May 2005 12:01:32 +0200, Lasse Clausen wrote:
> greetings.
> in the course of my work this format of the ascii data file changes. new
> columns appear, other columns disappear. everytime that happens i have to
> use my SAVE_ASCII_TEMPLATE function to make a whole new template which is
> annoying if the data file now contains 25 columns instead of 26 because i
> have to type in the names of the 25 columns again although they haven't
> changed.
|
|
|