IDL程序发布
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
IDL程序发布
IDL程序发布 (1)
一、例子入门 (1)
二、深入发布核心 (3)
1、ENVI二次开发与发布 (3)
2、删减文件 (3)
3、作为ENVI扩展 (4)
附:程序源码 (6)
1、test.pro (6)
2、lanix_Software_Porject_gui(一) (6)
3、lanix_Software_Porject_gui(二) (14)
一、例子入门
1、编写源代码,在IDL中运行
源程序运行结果
;test.pro
pro test
a = dialog_message('test');
end
命令行
IDL>.compile,test.pro
IDL>test
2
运行代码
ENVI> .RESET_SESSION
IDL> .compile test.pro
% Compiled module: TEST.
IDL> Resolve_All, /continue_on_error, skip_routines='envi'
% Compiled module: RESOLVE_ALL.
IDL> save,file='c:\test.sav',/routines
运行效果相同。
3
运行代码
IDL> .RESET_SESSION
IDL> .compile test.pro
% Compiled module: TEST.
IDL> Resolve_All, /continue_on_error, skip_routines='envi'
% Compiled module: RESOLVE_ALL.
IDL> save,file='c:\test.sav',/routines
IDL> make_rt,'test','C:\test1',savefile = 'c:\test.sav',/vm make_dist routine finished. See log file: C:\test1\test\log.txt
不显示虚拟机界面
用记事本打开“test.ini".
[DIALOG]
Show=true ;改成false
BackColor=&H6B1F29
Caption=IDL Virtual Machine Application
Picture=.\splash.bmp
DefaultAction=.\IDL80\bin\bin.x86\idlrt.exe -vm=test.sav
[BUTTON1]
Show=True
Caption=test
Action=.\idlrt.exe -rt=exportdemo.sav ;rt改成em
二、深入发布核心
1、ENVI二次开发与发布
如果IDL程序中嵌入ENVI函数,发布比较麻烦。
有两点需要注意:一是程序编写,二是程序打包。
(程序可参见lanix_Software_Porject_gui(一))
①程序编写:是否调用了ENVI函数只能要求IDL+ENVI共同开发?其时不必,对于每个调用ENVI函数的过程pro,按如下形式编写,只启动IDL则可。
compile_opt idl2 ;开头
envi,/restore_base_save_files ;第一个ENVI函数前,加载ENVI函数
envi_batch_init, log_file=outPath+'batch.txt';save log file
……
函数体
……
envi_batch_exit ;最后一个ENVI函数后,退出ENVI函数,可不写
②程序打包:就编译,存SA VE文件,转EXE程序。
IDL> .RESET_SESSION ;重置当前环境
IDL> .compile NAME.pro
% Compiled module: TEST.
IDL> Resolve_All, /continue_on_error, skip_routines='envi'
% Compiled module: RESOLVE_ALL.
IDL> save,file='c:\test.sav',/routines
IDL> make_rt,'FOLDER','PATH',savefile = 'PATH\NAME.sav',/vm
2、删减文件
可以删除一些无用的资源及类库。
最后的保留文件如下:
lanix_Software_Porject_gui:
log.txt、<DIR>IDL80、lanix_Software_Porject_gui.sav、idl.ico、splash.bmp、
lanix_Software_Porject_gui.ini、anix_Software_Porject_gui.exe
lanix_Software_Porject_gui\IDL80\bin\bin.x86:
idl.dll、idlrt.exe、idlrt_admin.exe、osmesa6_2.dll、ug3220.dll、MesaGL6_2.dll、MesaGLU6_2.dll、freetype2_3_6.dll
lanix_Software_Porject_gui\IDL80\lib\hook:
idlrtmain.sav、ittlicense.sav
最好在make_rt出的包下删减,不然会有证书许可问题。
3、作为ENVI扩展
用IDL编写的程序可以作为ENVI的扩展加入ENVI中使用。
在介绍具体方法前先介绍两个ENVI的组成。
ENVI存放在\ITT\IDL\IDL80\products\envi48,其中envi48\menu\envi.men(可用记事本打开)是界面构成。
在“1 {About ENVI} {about envi} {envi_menu_event}”中,“1”对应菜单等级,之后分别是{界面显示名} {程序识别名} {调用过程名}。
我们可以选择适应的菜单级别建立自己的扩展程序。
另外,\envi48\save存放默认的过程文件,\envi48\save_add存放拓展的过程文件。
步骤一:
\envi48\save_add下存放:
“lanix_Software_Porject_gui.sav”(一)
envi48\menu\envi.men写入:
0 {Lanix}
1 {lanix_software_projet_gui} {lanix_software_projet_gui} {lanix_Software_Porject_gui}
重启ENVI后可见ENVI主菜单改变:
步骤二:
但实际上是运行不了的,应用“lanix_Software_Porject_gui.sav”(一)是一个GUI界面,是个TOP_BASE,可考虑ENVI调用一个“.sav”文件,再在“.sav”在调用
lanix_Software_Porject_gui.exe。
调用方法的函数参见3、lanix_Software_Porject_gui(二)。
spawn是模拟cmd的一个函数,但它有时直接调用“.exe”时会出错,可通过建立“.exe”的快捷方式再调用。
运行结果相同,按步骤一进行。
ENVI运行“lanix_Software_Porject_gui.sav”(二),“lanix_Software_Porject_gui.sav”(二)再调用“lanix_Software_Porject_gui.exe”(一)。
附:程序源码
1、test.pro
;test.pro
pro test
a = dialog_message('test');
end
2、lanix_Software_Porject_gui(一)
;lanix_Software_Porject_gui
pro LANIX_SOWTWARE_PORJECT_GUI_EVENT,ev
catch,err
if err ne0then goto,lasts
lasts:
end
pro lanix_Software_Porject_gui
DEVICE,GET_SCREEN_SIZE = dims
Btop = WIDGET_BASE(xoffset = dims[0]/5, yoffset = dims[1]/10,$
xsize = dims[0]*2/3, ysize = dims[1]*2/3, title = 'Lanix_Software_Project',$
mbar = SysMenuBar,/column,tlb_frame_attr=1)
;--------Begin System Menu Bar----------
FileMenu = WIDGET_BUTTON(SysMenuBar,value = '&File',/menu)
OpenB = WIDGET_BUTTON(FileMenu,value = '&Open',event_pro = 'openpro')
SaveB = WIDGET_BUTTON(FileMenu,value = '&Save',event_pro = 'savepro')
SaveasB = WIDGET_BUTTON(FileMenu,Value = '&Save As',event_pro = 'SaveAspro')
ExitB = WIDGET_BUTTON(FileMenu,value = '&Exit',event_pro = 'exitpro',/separator)
SoftMenu = WIDGET_BUTTON(SysMenuBar,value = '&Soft',/menu)
Proj1 = WIDGET_BUTTON(SoftMenu,value = '&JpgToImg',event_pro = 'lanix_covert_jpgtoimg')
Proj2 = WIDGET_BUTTON(SoftMenu,value = '&Mosaic',event_pro = 'lanix_mosaic')
HelpMenu = WIDGET_BUTTON(SysMenuBar,value = '&Help',/menu)
InfoB = WIDGET_BUTTON(HelpMenu,value = '&Author',event_pro =
'authorpro')
;-------Finish System Menu Bar------
;-------Begin Lable/Text----------
B11 = WIDGET_BASE(Btop,/column)
StrLabel = WIDGET_LABEL(B11,value = 'Lanix_Software_Project',$ xsize = dims[0]*2/3-20,/align_center,/sunken_frame)
B12 = WIDGET_BASE(Btop,xsize = dims[0]*2/3-10,/column)
StrText = WIDGET_TEXT(B12,value = 'Lanix_Software_Project',$
ysize = dims[1]*2/3-100,/editable,/scroll)
;-------Finish Lable/Text----------
WIDGET_CONTROL,Btop,/REALIZE
pState = PTR_NEW({StrLabel:StrLabel,StrText:StrText})
WIDGET_CONTROL,Btop,SET_UVALUE = pState
XMANAGER,'lanix_Sowtware_Porject_gui',Btop
end
;-----------------
pro openpro,ev
catch,err
if err ne0then goto,lasts
filters = [ '*.txt']
fname = dialog_pickfile(/read,/must_exist,FILTER = filters)
str = ''
cur = ''
openr,lun,fname,/get_lun
if NOT EOF(lun) then begin
readf,lun,cur
str = cur
endif
WHILE NOT EOF(lun) DO BEGIN
readf,lun,cur
str =[str,cur]
ENDWHILE
free_lun,lun
WIDGET_CONTROL,ev.top,GET_UVALUE = pState
WIDGET_CONTROL,(*pState).StrText,SET_VALUE = str
WIDGET_CONTROL,(*pState).StrLabel,SET_VALUE = fname
WIDGET_CONTROL,ev.top,SET_UVALUE = pState
lasts:
end
pro savepro,ev
catch,err
if err ne0then goto,lasts
WIDGET_CONTROL,ev.top,GET_UVALUE = pState
WIDGET_CONTROL,(*pState).StrText,GET_VALUE = str WIDGET_CONTROL,(*pState).StrLabel,GET_VALUE = fname finfo = file_info(fname)
if finfo.exists then begin
openw,lun,fname,/get_lun
printf,lun,str,format = '(1A)'
free_lun,lun
endif else begin
fname = dialog_pickfile(/write)
openw,lun,fname,/get_lun
printf,lun,str,format = '(1A)'
free_lun,lun
endelse
WIDGET_CONTROL,(*pState).StrLabel,SET_VALUE = fname WIDGET_CONTROL,ev.top,SET_UVALUE = pState
lasts:
end
pro saveaspro,ev
catch,err
if err ne0then goto,lasts
WIDGET_CONTROL,ev.top,GET_UVALUE = pState
WIDGET_CONTROL,(*pState).StrText,GET_VALUE = str
fname = dialog_pickfile(/write)
openw,lun,fname,/get_lun
printf,lun,str,format = '(1A)'
free_lun,lun
WIDGET_CONTROL,(*pState).StrLabel,SET_VALUE = fname WIDGET_CONTROL,ev.top,SET_UVALUE = pState
lasts:
end
pro exitpro,ev
WIDGET_CONTROL,ev.top,/destroy
end
;-----------------
pro lanix_covert_jpgtoimg,event
compile_opt idl2
catch, err
if err ne0then goto,lasts
LabelInput:
inPath = DIALOG_PICKFILE(/director,title = 'the image input')
if inPath EQ''then begin
Dlg = dialog_message('Choose folder against?',/Cancel) if Dlg EQ'OK'then begin
goto,LabelInput
endif else begin
if Dlg EQ'Cancel'then return
endelse
endif
LabelOutput:
outPath = DIALOG_PICKFILE(/director,title = 'the image output') if outPath EQ''then begin
Dlg = dialog_message('Choose folder against?',/Cancel) if Dlg EQ'OK'then begin
goto,LabelOutput
endif else begin
if Dlg EQ'Cancel'then return
endelse
endif
envi,/restore_base_save_files ;setup envi savefile
envi_batch_init, log_file=outPath+'batch.txt';save log file
file_list = FILE_SEARCH(inPath,'*.jpg')
nFile = N_ELEMENTS(file_list)
envi_report_init, ['Convert......'], title='Mosaic Bar', base=base envi_report_inc, base, nFile
for i=0L,nFile-1do BEGIN
envi_report_stat, base, i, nFile
envi_report_inc, base,float(nFile)/i
fname = file_list[i]
fbasename=FILE_BASENAME(fname,'.jpg')
imgF = outPath+fbasename+'.img'
read_jpeg,fname,imgA,order=1
get_lun,lun
openw,lun,imgF
writeu,lun,imgA
free_lun,lun
jgwF = inPath+fbasename+'.jgw'
catch,err
GET_LUN,j
OPENR,j,jgwF
READF,j,f1,f2,f3,f4,f5,f6
mc = [0.0D, 0.0D,f5,f6]
ps=[f1,-f4]
close,j
free_lun,j
proj = envi_proj_create(/geographic)
mapinfo = envi_map_info_create(name='Geographic',/geographic,mc=mc,$
ps=ps,proj=proj)
ENVI_SETUP_HEAD, fname=imgF, ns=256, nl=256, nb=3, interleave=2,$
data_type=1,offset=0,map_info = mapinfo,/write, /open ENDFOR
envi_report_init, base=base, /finish
lasts:
End
;mosaic_pc_lanix.pro
;write by pengchen and lanix
pro lanix_mosaic,event
compile_opt idl2
catch, err
if err ne0then goto,lasts
;search img file
LabelInput:
inPath = DIALOG_PICKFILE(/director,title = 'the imgfile to mosaic') if inPath EQ''then begin
Dlg = dialog_message('Choose folder against?',/Cancel) if Dlg EQ'OK'then begin
goto,LabelInput
endif else begin
if Dlg EQ'Cancel'then return
endelse
endif
file_list = file_search(inPath,'*.img')
nFile=n_elements(file_list)
;search output folder
LabelOutput:
outPath = DIALOG_PICKFILE(/director,title = 'the folder for output')
if outPath EQ''then begin
Dlg = dialog_message('Choose folder against?',/Cancel) if Dlg EQ'OK'then begin
goto,LabelOutput
endif else begin
if Dlg EQ'Cancel'then return
endelse
endif
;--------------------------------------
envi,/restore_base_save_files ;setup envi savefile
envi_batch_init, log_file=outPath+'batch.txt';save log file
;init the paraments for 'mosaic doit'
dims= indgen(5,nfile) ;line 66
fid = indgen(nfile) ;line 65
pos = indgen(3,nfile) & pos[0,*] = 0& pos[1,*] = 1& pos[2,*] = 2; x0 = replicate(0,nfile)
y0 = replicate(0,nfile)
xsize = 0
ysize = 0
pixel_size = [1.,1.]
use_see_through = replicate(0L,nfile)
see_through_val = replicate(1L,nfile)
;init help elements
i_ns = 0
i_nl = 0
fbasename = file_basename(file_list[0],'.img')
iPos = strpos(fbasename,'-')
line1 = strmid(fbasename,0,ipos)
a = where(strpos(file_list,line1)>0,nfileperrow) ;calc number of file per row
;envi_report_*,the bar to show the work finished
envi_report_init, ['Mosaic......'], title='Mosaic Bar', base=base envi_report_inc, base, nFile
for i = 0,nfile-1do begin;calc the parameter for each imgfile envi_report_stat, base, i, nFile
envi_report_inc, base,float(nFile)/i
;the i-ed imgfile
fname = file_list[i]
envi_open_file,fname,r_fid=i_fid
fid[i] = i_fid
;calc the x|ysize and x|y0
if(i eq0) then begin
x0[i] = 1
y0[i] = 1
envi_file_query,i_fid, ns=i_ns, nl=i_nl
dims[*,i] = [-1,0, i_ns-1,0, i_nl-1]
ysize = i_nl
xsize = i_ns
endif else begin
if ((i mod nfileperrow) eq0 ) then begin
x0[i] = 1
y0[i] = y0[i-1] + i_nl
endif else begin
x0[i] = x0[i-1] + i_ns
y0[i] = y0[i-1]
xsize = xsize > (x0[i]+i_ns-1)
ysize = ysize > (y0[i]+i_nl-1)
endelse
envi_file_query,i_fid, ns=i_ns, nl=i_nl
dims[*,i] = [-1,0, i_ns-1,0, i_nl-1]
endelse
endfor
out_name = outPath + 'testimg.img'
envi_doit,'mosaic_doit',fid = fid,pos=pos,dims=dims,out_name=out_name,xsize = xsize,ysize = ysize,x0=x0,y0=y0,georef = 0,$
out_dt = 1,pixel_size=pixel_size,background=255,see_through_val=see_throug
h_val,use_see_through = use_see_through
envi_batch_exit
;----------------------------------------
;create the head file
fhdr = outPath + 'testimg.hdr'
get_lun,lun
openr,lun,fhdr
info = ''
for i=1,7do begin
cur = ''
readf,lun,cur
info =info+string(13b)+cur
endfor
free_lun,lun
fhdr1 = inPath + fbasename +'.hdr'
get_lun,lun1
openr,lun1,fhdr1
for i=1,7do begin
cur = ''
readf,lun1,cur
endfor
WHILE NOT EOF(lun1) DO BEGIN
cur = ''
readf,lun1,cur
info =info+string(13b)+cur
ENDWHILE
free_lun,lun1
ext = strsplit(info,string(13b),/extract) get_lun,lun2
openw,lun2,fhdr
for i=0, n_elements(ext)-1do begin
printf,lun2,ext[i]
endfor
free_lun,lun2
;creat the jpeg file from img
readImgArray,out_name,dataA=dataA
fjpg = outPath + 'testimg.jpg'
write_image,fjpg,'jpeg',dataA
envi_report_init, base=base, /finish
lasts:
end
;get the array of imgfile
pro readImgArray,fname,dataA = dataA
catch,err
if err NE0then return
envi_open_file,fname,r_fid=fid,/NO_REALIZE envi_file_query,fid,nb=nb,ns=ns,
nl=nl,interleave=itl,data_type=dtype
switch itl of
0:begin
dataA = make_array(ns,nl,nb,type=dtype)
end
1:begin
dataA = make_array(ns,nb,nl,type=dtype)
end
2:begin
dataA = make_array(nb,ns,nl,type=dtype)
end
endswitch
openr,lun,fname,/get_lun
readu,lun,dataA
free_lun,lun
return
end
;-----------------
pro authorpro,ev
dlg = DIALOG_MESSAGE('AUTHOR:Lanix'+String(13b)+'Tutor:QuYonghua'+Strin
g(13b)+$
systime(),title = 'Version',/information)
end
3、lanix_Software_Porject_gui(二)
;lanix_Software_Porject_gui
pro lanix_Software_Porject_gui,ev
fpath = !dir
fpath += path_sep()+'products'+path_sep()+'envi48'+path_sep()+$ 'save_add'+path_sep()
fname = fpath + 'lanix_Software_Porject_gui'
fname = '"'+fname+'"'
spawn,fname
end。