IDL 初学教程(一)

后续会继续出idl的学习教程,欢迎持续关注哦,(主要是学习ENVI/IDL呢~)

1.初识idl(特点)

1.具有高级图像处理功能(2D/3D绘图,地图投影转换函数)
2.提供可学习的demo源码文件(使用方法见下)
3.基于矩阵运算,提供基础数学库+IMSL数学库+小波工具箱
4.可发布成可执行程序(.sav和.exe)

2.基础知识点(冷门知识点)

1.pro文件

IDL创建一个工作空间,工作空间下可有多个工程文件,一个工程文件里可写多个pro过程,但必须有一个pro过程与工程文件同名
关键关键: pro过程保存的文件名必须和程序中所写的pro 后名称一致。否则编译失败,也不可运行。

2.中文乱码情况

如果相关IDL程序是写界面,且界面上包括中文字符,如果运行出现乱码,修改方式:
窗口----首选项----常规----工作空间----文本文件编码, 在这里改成GBK 或者手输 GBK2312

3.添加作者信息(文件、程序注释)

给自己的idl程序加作者信息等:源码----添加文件注释/添加程序注释
修改默认格式:窗口----首选项----IDL----IDLdoc
修改时可添加变量(在下拉栏的最后)
eg:我的

  ;+
  ; Description:
  ;    Describe the procedure.
  ; Author: ${user}
  ; date: ${date}
  ;-

效果:
在这里插入图片描述

4.调试(打断点/逐语句/逐过程)

1.打断点(在程序行前双击),出现下图红点,运行程序会在红点位置暂停
在这里插入图片描述
2.逐语句执行程序:IDL界面翻译为‘
3.逐过程执行程序:IDL翻译成‘跳出
在这里插入图片描述

5.帮助用法(help)

1.在命令行直接输入 ?函数名,会跳转到函数的介绍页面,可查看函数的调用格式以及关键字的使用
2. 鼠标左键选中待查询函数名,点击界面上方 帮助----选中项目帮助

6.变量值

1.在程序运行后,在变量名是哪个悬停,可查看变量值
2.在IDL界面左侧,变量查看器查看,也可在 窗口----变量查看器,进行查看

7.IDL 自带demo

在命令行直接输入demo,回车即可,双击pro文件即可查看运行情况。选中pro文件后,下方可见demo的源码文件

8.换行符

1) $
示例:

IDL> print,$
> 'lizijia'
lizijia
IDL> 

2)string(13B)

IDL> 'li'+string(13B)+'zi'
li
zi

3)字符串数组

IDL> a=strarr(2)
IDL> a[0]='li'
IDL> a[1]='hua'
IDL> a
li
hua
IDL> dialog_message(a)

9.大小写

IDL语言是不区分大小写的,但是在作为字符串时,是区分大小写的。

10.编译成可执行程序(.sav或者.exe)

1.编译成 .sav文件
步骤:
1)重置
2)编译

3)命令行输入:

save,filename='D:\lizijia.sav',/routines

注意:默认软件默认resolve_all 是勾选的,具体可见,工程名,右键,属性----工程构建属性----resolve_all(会把IDL自带的一些程序也编译进去,使用方便)

2.编译成 .exe文件
步骤:
1)重置(也可不重置)
2)编译
3)命令行输入:

make_rt,'test','D:\idl_test'

test为输出exe的名字,'D:\idl_test’为输出路径
注意:
a.在得到的exe文件夹里面,可把自己电脑IDL的license文件拷贝进去,这样就不会出现虚拟机的界面,
b.在文件.ini 的文件里,吧dialog 字符下面的show=TRUE,改成show=FALSE,就不会出现最前面的click to continue 的界面

11 局部变量和全局变量

idl 中有已经设定好的系统变量,为全局变量,而自己写的变量一般都是局部变量。
在这里插入图片描述
那怎么自定义全局变量呢?
1.在命令行中定义系统变量,回车执行后,会在系统变量里找到自己定义的系统变量,(但是并非所有的程序都要用到该变量,所以如果系统变量定义过多,会增加系统内存,不推荐使用)

IDL> defsysv,'!li',10
IDL> 

在这里插入图片描述
2. 定义公共区common

12 pro和function的使用

13. file_nasename()和file_dirname

已知文件绝对路径为:
D:\cbs\georeferenced_img\DS1110-1118DF025_rec_geocoding_1s_match.tif

IDL> file_basename('D:\cbs\georeferenced_img\DS1110-1118DF025_rec_geocoding_1s_match.tif')
DS1110-1118DF025_rec_geocoding_1s_match.tif
IDL> file_dirname('D:\cbs\georeferenced_img\DS1110-1118DF025_rec_geocoding_1s_match.tif')
D:\cbs\georeferenced_img
ENVI> 
### IDL Programming Beginner Tutorial Part 2 In continuation of the initial introduction to IDL (Interactive Data Language), this section delves deeper into practical aspects and more advanced features that beginners should familiarize themselves with. #### Understanding Basic Syntax Further Beyond simple variable declarations, understanding how control structures work is essential. For loops provide a way to execute code multiple times based on conditions: ```idl for i=0,9 do begin print, 'Iteration number ', i endfor ``` Control statements like `if` allow conditional execution which can be combined using logical operators such as AND (`and`) or OR (`or`). This enables complex decision-making within programs[^1]. #### Working With Arrays Arrays are fundamental data structures in IDL used for storing collections of elements. Creating an array involves specifying its dimensions along with initialization values when necessary: ```idl arr = fltarr(3, 3) ; Creates a floating-point array filled with zeros. print, arr ``` Operations over arrays include mathematical computations where entire operations apply element-wise without explicit looping constructs required by some other languages: ```idl a = [1., 2., 3.] b = [4., 5., 6.] c = a + b ; Element-by-element addition resulting in another vector c=[5.,7.,9.] print,c ``` #### Plotting Basics Visualization plays a crucial role in scientific computing applications written in IDL. Simple plots help visualize trends found inside datasets easily through commands provided directly from the command line interface or scripts alike: ```idl x = findgen(100)/100.*2*!pi y = sin(x) plot,x,y,title='Sine Wave',xlabel='X Axis Label',ylabel='Y Axis Label' ``` This plot function creates graphical representations quickly while allowing customization via parameters passed during invocation including titles and axis labels among others.
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值