Re: Writing a modified .txt file issue [message #85379 is a reply to message #85377] |
Mon, 29 July 2013 17:54   |
Heinz Stege
Messages: 189 Registered: January 2003
|
Senior Member |
|
|
On Mon, 29 Jul 2013 17:18:31 -0600, David Fanning wrote:
> I can't get this code by Heinz to work at all:
>
Below is an example with some Explanations.
Cheers, Heinz
; Here is a string array which could come from a file:
nLines=10
word='text'+strtrim(indgen(nLines)+1,2)+$
string(findgen(nLines)*2.+100.)+$
string(lindgen(nLines)*5L+200L)
print,'This is our input:'
print,word,form='(a)'
;
; Make a structure for the result:
nColumns=3
struct={text:'',float:0.,long:0L}
data=replicate(struct,nLines)
;
; 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-1 do print,data[i]
;
end
|
|
|