IDL command line arguments

本文介绍如何在启动IDL时使用-arg和-args命令行选项来传递参数,并通过COMMAND_LINE_ARGS函数获取这些参数。这允许将特殊的应用定义值传递给用IDL语言编写的程序。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

-arg

Syntax: -arg value

Specifies a single command line option to be saved for later access via the COMMAND_LINE_ARGS function. The value string is saved. Multiple -arg switches are allowed; the values are saved in the order specified. The -arg option can be used to pass program-specific information from the command line to IDL programs.

-args

Syntax: -args value1 value2 ... valueN

Specifies one or more command line options to be saved for later access via the COMMAND_LINE_ARGS function. When IDL sees the -args option, it takes any command-line arguments that follow it and saves them all. There can only be one -args option on an IDL command line, and it is always the final option. The -args switch can be used with the -arg switch; if both switches are specified, occurrences of -arg must come first, and the values specified by -args are saved following any values specified by -arg.


The COMMAND_LINE_ARGS function returns strings supplied by the user when IDL was started with the -arg or -args command line options. If either of these options is specified at the command line when IDL is started, IDL saves them without examining their values or attaching any special meaning to them.


Note
The shell performs its normal interpretation of wildcards and shell metacharacters before the values of the -arg or -args command line options are passed to IDL.

Strings specified at the command line can be retrieved at any time within the IDL session via the COMMAND_LINE_ARGS function. This mechanism can be used to pass special application-defined values to a program written in the IDL language.

Syntax

Result = COMMAND_LINE_ARGS( [, COUNT=variable] )

Return Value

If any -arg or -args options were specified at the command line when IDL was started, COMMAND_LINE_ARGS returns a string array containing the specified values, one value per element. The values are returned in the order specified by the user on the command line. If no such options were specified, a NULL scalar string is returned.

Keywords

COUNT

Set this keyword equal to a named variable that will contain the number of retrieved arguments. If no arguments were specified, the variable will contain 0.


The COMMAND_LINE_ARGS routine was introduced in IDL 6.2, allowing IDL programs to access command line args passed to IDL when starting it. For example, to pass command line arguments into the MYPROGRAM routine, call IDL like below:

$ idl -e "myprogram" -args a b c

Then, in MYPROGRAM, the command line arguments could be retrieved with:

args = command_line_args()

The args string array would contain “a”, “b”, and “c”. To make it more convenient to launch IDL this way, you can create a script that calls IDL in the proper way, passing arguments of the script to arguments listed after the -args in the IDL call. If you name the wrapper script myprogram also, your calls would look like:

$ myprogram a b c


IDL大数据分块实例代码,值得学习。 PRO WRITEREADHDF ;创建隐藏tlb,目的为了显示进度条 wtlb = WIDGET_BASE(map = 0) WIDGET_CONTROL,wtlb,/realize ;tlb居中显示 CENTERTLB,wtlb ;创建进度条 process = IDLITWDPROGRESSBAR( TIME=0,$ GROUP_LEADER=wtlb, $ TITLE='测试分块保存HDF... 请等待') IDLITWDPROGRESSBAR_SETVALUE, process, 0 ;源数据及相关信息 image = DIST(6000) ;求出数据范围 myRANGE=[MAX(image,min=min_xray),min_xray] dims = SIZE(image,/dimension) ;块大小 tileSize = [1024, 1024] ;初始化写入HDF数据 filename = 'c:\test.hdf' sd_id=HDF_SD_START(filename,/CREATE) ; sds_id=HDF_SD_CREATE(sd_id,'largeWrite', $ [dims[0],dims[1]],/FLOAT) ; HDF_SD_SETINFO,sds_id,FILL=0.0,LABEL='data', $ UNIT='float',$ RANGE=myRANGE ; ; Write labels to each of the dimension HDF_SD_DIMSET,HDF_SD_DIMGETID(sds_id,0),NAME='Width',LABEL='Width of data' HDF_SD_DIMSET,HDF_SD_DIMGETID(sds_id,1),NAME='Height',LABEL='Height of data' ;xn和yn分别是行、列的初始循环次数 xn = 0 yn = 0 ;计算循环次数,- 目的为了进度条正确显示 IF(dims[1]/tileSize[1] EQ 0 )AND(dims[0]/tileSize[0] EQ 0) THEN BEGIN TotalNum = 1 ENDIF ELSE IF(dims[1]/tileSize[1] EQ 0 ) THEN BEGIN TotalNum = FIX(dims[0]/tileSize[0])+1 ENDIF ELSE IF(dims[0]/tileSize[0] EQ 0 ) THEN BEGIN TotalNum = FIX(dims[1]/tileSize[1])+1 ENDIF ELSE TotalNum = (FIX(dims[1]/tileSize[1])+1)*(FIX(dims[0]/tileSize[0])+1) ; 更新下进度条 IDLITWDPROGRESSBAR_SETVALUE, process, 1 DoneNum = 0 UpRate = 99/TotalNum ;分别在水平和竖直方向循环 WHILE(yn LT FIX(dims[1]/tileSize[1])) DO BEGIN WHILE(xn LT FIX(dims[0]/tileSize[0])) DO BEGIN ;计算存储的数据块位置 loc = [tileSize[0]*xn,tileSize[1]*yn] ;提取数据相应位置数据 wtImg = image[loc[0]:(loc[0]+tilesize[0]-1),loc[1]:(loc[1]+tilesize[1]-1)] ;写入HDF文件中 HDF_SD_ADDDATA, sds_id, wtImg, $ START=loc, COUNT=tileSize xn++ ;更新进度条 DoneNum = DoneNum+1 IDLITWDPROGRESSBAR_SETVALUE, process, 1+UpRate*DoneNum ENDWHILE ; IF(dims[0] GT tileSize[0]*xn)THEN BEGIN ;计算存储的数据块位置 loc = [tileSize[0]*xn,tileSize[1]*yn] ;提取数据相应位置数据 wtImg = image[loc[0]:(dims[0]-1),loc[1]:(loc[1]+tilesize[1]-1)] ;写入HDF文件中,注意count的变化 HDF_SD_ADDDATA, sds_id, wtImg, $ START=loc, COUNT=SIZE(wtImg,/dimension) ENDIF ; xn = 0 yn++ ;更新进度条 DoneNum = DoneNum+1 IDLITWDPROGRESSBAR_SETVALUE, process, 1+UpRate*DoneNum ENDWHILE ; 最后一行不完整的部分 IF(dims[1] GT tileSize[1]*yn)THEN BEGIN xn = 0 WHILE(xn LT FIX(dims[0] /tileSize[0])) DO BEGIN ;计算存储的数据块位置 loc = [tileSize[0]*xn,tileSize[1]*yn] ;提取数据相应位置数据 wtImg = image[loc[0]:(dims[0]-1),loc[1]:(dims[1]-1)] ;写入HDF文件中 HDF_SD_ADDDATA, sds_id, wtImg, $ START=loc, COUNT=SIZE(wtImg,/dimension) xn++ ;更新进度条 DoneNum = DoneNum+1 IDLITWDPROGRESSBAR_SETVALUE, process, 1+UpRate*DoneNum ENDWHILE ENDIF ;关闭HDF HDF_SD_ENDACCESS,sds_id HDF_SD_END,sd_id IDLITWDPROGRESSBAR_SETVALUE, process, 100 ;销毁没用的 WAIT,0.3 WIDGET_CONTROL,process,/Destroy WIDGET_CONTROL, wtlb,/DESTROY END
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值