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 #85380 is a reply to message #85379] Mon, 29 July 2013 18:39 Go to previous messageGo to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Heinz Stege writes:

> Below is an example with some Explanations.

OK, here is my data file, save in a file bad_data.txt. If you put this
in a text editor, you will see the columns are all left aligned.

hole_id from to Pr_1 Pr_2
2006/1 6 8.2 39.23 0.09
2006/1 12.25 14 39.16 12.06
2006/2A 2 5.9 59.17 0.42
2006/2A 5.9 8.7 51.02 0.61
2006/2A 8.7 11.7 49.8 0.97

Here is the code I am using. A combination of Philip's code and yours,
modified a bit to strip the header off.

;***************************************************
nLines = FILE_LINES(filename)
OPENR, lun, filename, /GET_LUN
header = ""
word = STRARR(nLines-1)
READF, lun, header, word
FREE_LUN, lun

mylist = strsplit(word,/extract)
myarr = mylist.toarray()

struct = {date:"", from:0.0, to:0.0, pr1:0.0, pr2:0.0}
data = Replicate(struct, nLines-1)

; Loop over all columns but the last one:
for i=0,nColumns-2 do begin
;
; Get the end positions of the first column
pos=strpos(word,' ')
;
; Put the first column into the i-th tag of the structure
data.(i)=strmid(word,0,transpose(pos))
;
; Remove the first column (and trailing blanks) from the input
; array
word=strtrim(strmid(word,transpose(pos)),1)
;
; Continue the loop with the next column
end
;
; Copy the last column into the structure
data.(nColumns-1)=word
;
; Check the result
print,'This is the result structure:'
for i=0,nLines-2 do print,data[i]
;

END
;***************************************************


Here are my results when I run the program:

This is the result structure:
{ 2006/1 0.000000 0.000000 0.000000 6.00000}
{ 2006/1 0.000000 0.000000 0.000000 12.2500}
{ 2006/2A 0.000000 0.000000 0.000000 2.00000}
{ 2006/2A 0.000000 0.000000 0.000000 5.90000}
{ 2006/2A 0.000000 0.000000 0.000000 8.70000}

What am I doing wrong?

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
[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: Sat Oct 11 05:13:42 PDT 2025

Total time taken to generate the page: 0.40218 seconds