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

Home » Public Forums » archive » Writing a modified .txt file issue
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Writing a modified .txt file issue [message #85370 is a reply to message #85368] Mon, 29 July 2013 13:03 Go to previous messageGo to previous message
Phillip Bitzer is currently offline  Phillip Bitzer
Messages: 223
Registered: June 2006
Senior Member
I also have an ASCII data file that contains both numeric and string columns. I'm not a fan. What I'm doing now is read the whole thing in as a string array:

nLines = FILE_LINES(filename)
OPENR, lun, filename, /GET_LUN
word = STRARR(nLines)
READF, lun, word
FREE_LUN, lun

Then, I loop through each line, using STR_SPLIT to divvy up the fields at the space that separates the columns, and throw them into the output structure (not defined here for simplicity)

FOR i=0L, nLines-1 DO BEGIN
this_row = STRSPLIT(word[i], ' ', /extract)
data[i].date = this_row[0]
data[i].time = this_row[1]
data[i].latitude = DOUBLE(this_row[2])
data[i].longitude = DOUBLE(this_row[3])
....
ENDFOR

I have been looking for a better/more efficient way of doing this. Can't seem to find a good way, but maybe Coyote has cooked up something :-) ReadCol works about as quickly as my code.

I should mention that there are several string columns mixed up amongst the numeric columns. Yuck.

For the output, Hakan, I would say those numbers *do* match, although they might be formatted differently. You'll want to use the FORMAT keyword, however you're writing the file back out if you want to match the numbers/decimal places/etc.

A simple example:
IDL> a = 13.2
IDL> PRINT, a
13.2000
IDL> PRINT, a, format='(F5.2)'
13.20
IDL> PRINT, a, format='(F4.1)'
13.2

You would do something similar using PRINTF.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Find all user-defined structure definitions
Next Topic: Multiple plots with plot function

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

Current Time: Fri Oct 10 14:04:48 PDT 2025

Total time taken to generate the page: 1.28383 seconds