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

Home » Public Forums » archive » Re: how to link the strname with the same name of variables
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: how to link the strname with the same name of variables [message #67275 is a reply to message #67273] Tue, 14 July 2009 05:23 Go to previous messageGo to previous message
Tony is currently offline  Tony
Messages: 6
Registered: March 2009
Junior Member
On Jul 13, 8:35 pm, mengran <mengra...@gmail.com> wrote:
> 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

My first thought (let me know if I didn't read your code well
enough :) is the 'execute' command. You could do something like this:

> for i=0,4 do begin
> openw,unit,outFl[i],/get_lun
diditwork=execute('writeu,'+string(unit)+','+ref[i]) ;only can
output the string but not the real

I didn't actually try that code, but you get the idea :) Check out
'execute' in the IDL help

Tony
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: file_info not detecting write-protected files under windows (bug?)
Next Topic: how to link the strname with the same name of variables

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

Current Time: Sat Oct 11 06:38:09 PDT 2025

Total time taken to generate the page: 1.03871 seconds