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

Home » Public Forums » archive » how to link the strname with the same name of variables
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
how to link the strname with the same name of variables [message #67281] Mon, 13 July 2009 17:35 Go to next message
mengran is currently offline  mengran
Messages: 5
Registered: March 2009
Junior Member
Hi,everyone.

I want to output a batch of variables to different files, and the
variable names like c1, c2,c3,,,,. I use the arrstring to save the
variable names and get the real variable data from different bands of
a image. The problem confused me is that it is not possible to output
the variable in a for loop, although the elements of strarr have the
same name as the true variable names. There must be some skills that I
do not know, could you tell them to me please?Thanks a lot!
best wishes,
mengran
pro sub_test
Path_08 = 'D:\mengr_2\spot_vege\2008_byte\project_pof'
Path_99 = 'D:\mengr_2\spot_vege\1999_byte\project_pof'
out_path='D:\mengr_2\sub'
outFl = strarr(5) & ref = strarr(5)
for i=1,5 do begin
outFl[i-1] = strjoin([out_path, strtrim(string(i), 2), '.img']) ;the
full path of output files
; outh = strjoin([out_path, strtrim(string(i), 2)])
ref[i-1] = strjoin(['c', strtrim(string(i), 2)]) ; the output
variable names
endfor
;get the data to variables
envi_open_file,Path_08,r_fid = fid1
envi_file_query,fid1,nb = nb1, ns = ns1, nl = nl1, dims = dims1
a1 = ENVI_GET_DATA(fid = fid1,pos = [0], dims = dims1)
a2 = ENVI_GET_DATA(fid = fid1,pos = [1], dims = dims1)
a3 = ENVI_GET_DATA(fid = fid1,pos = [3], dims = dims1)
a4 = ENVI_GET_DATA(fid = fid1,pos = [5], dims = dims1)
a5 = ENVI_GET_DATA(fid = fid1,pos = [7], dims = dims1)
map_info = envi_get_map_info(fid = fid1)
proj = ENVI_GET_PROJECTION(FID = fid1)
envi_open_file,Path_99,r_fid = fid2
envi_file_query,fid2,nb = nb2, ns = ns2, nl = nl2, dims = dims2,
INTERLEAVE = INTERLEAVE
b1 = ENVI_GET_DATA(fid = fid2,pos = [0], dims = dims2)
b2 = ENVI_GET_DATA(fid = fid2,pos = [1], dims = dims2)
b3 = ENVI_GET_DATA(fid = fid2,pos = [3], dims = dims2)
b4 = ENVI_GET_DATA(fid = fid2,pos = [5], dims = dims2)
b5 = ENVI_GET_DATA(fid = fid2,pos = [7], dims = dims2)
c1 = fltarr(ns1,nl1) & c2 = fltarr(ns1,nl1)& c3 = fltarr(ns1,nl1)& c4
= fltarr(ns1,nl1)& c5 = fltarr(ns1,nl1)
for k = 0,ns1-1 do begin
for j = 0,nl1-1 do begin
do something
endfor
endfor

for i=0,4 do begin
openw,unit,outFl[i],/get_lun
writeu,unit,ref[i] ;only can output the string but not the real
data
free_lun,unit
ENVI_SETUP_HEAD, map_info=map_info, data_type = 4, nb=1,ns = ns1,nl
= nl1,offset = 0,INTERLEAVE = INTERLEAVE,FNAME=outFl[i]
endfor
;it works like this way, ~~~~(>_<)~~~~
;openw,unit,outFl[0],/get_lun
;writeu,unit,c1
;free_lun,unit
;openw,unit,outFl[1],/get_lun
;writeu,unit,c2
;free_lun,unit
;openw,unit,outFl[2],/get_lun
;writeu,unit,c3
;free_lun,unit
;openw,unit,outFl[3],/get_lun
;writeu,unit,c4
;free_lun,unit
;openw,unit,outFl[4],/get_lun
;writeu,unit,c5
;free_lun,unit

end
Re: how to link the strname with the same name of variables [message #67365 is a reply to message #67281] Tue, 14 July 2009 12:26 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Jean H. writes:

> hum, an array of pointers would be suitable in this case

Simple, Jean, simple. Perhaps it's time to re-read
Occum's Razor:

http://en.wikipedia.org/wiki/Occam's_razor

Cheers,

David

--
David Fanning, Ph.D.
Coyote's Guide to IDL Programming (www.dfanning.com)
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: how to link the strname with the same name of variables
Next Topic: Colorado Wildflowers

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

Current Time: Wed Oct 08 15:28:15 PDT 2025

Total time taken to generate the page: 0.00568 seconds