IDL与C语言用法比较

项目 IDL C
创建变量 var=1(type) type var=1
变量类型转换 var=type(var) (type)var
创建数组 arr=[1,2] arr[2]={1,2}
数组下标 arr[列号,行号] arr[行号][列号]
数组运算

1、arr1+arr2:两数组对应元素依次相加

2、arr+n:arr的元素依次加n

3、arr1#arr2(数组乘)、arr1##arr2(矩阵乘)

一般使用循环完成
运算符优先级别

1、(  )

2、*(指针)、^(指数)

3、*、/、#、##、Mod

4、+、-、>(取最大)、<(取最小)、Not(布尔非)

5、Lt、Gt、Le、Ge、Eq、Ne

6、And(与)、Xor(异或)、Or(或)

7、? :

8、=(赋值)

1、(  )、[](下标)

2、++、--、!、*、&

3、*、/、%

4、+、-

5、(1)<、>、<=、>=(较高)   (2)==、!=(较低)

6、(1)& 与(2)| 异或(3)^ 非(自高向低)

7、? :

8、=、+=、-=、*=、/=、%=

定义结构体

dot={name,x:value,y:value}

struct name

{

    int x;

    float y;

}dot;

定义指针

(1)pointer=ptr_new(x)(x有定义)

(2)pointer=ptr_new(/allocate_heap)(空)

type *pointer;

pointer=&x;(x有定义)

指针与数组

arr=[0,1,2]

pointer=ptr_new(arr)

arr[0]=(*pointer)[0]

int *pointer,a[10];

pointer=a;

则有:

*pointer=a[0]

*(pointer+1)=a[1]

......

if语句

if(condition) then begin

语句1

endif

 

else begin

语句2

endelse

 

if(condition)

{ 语句1; }

else

    语句2

while语句

while(condition) do begin

语句

endwhile

 

while(condition)

{ 语句; }

for语句

for i=初值,条件,步长 do begin

语句

endfor

 

for(i=初值;条件;步长)

{ 语句; }

switch语句

switch expression of

1:begin

    语句1

  end

......

n:begin

    语句n

  end

else 语句n+1

endswitch

 

switch(expression)

{

    case 1:语句1;

    ......

    case n:语句n;

    default:语句n+1;

}

case语句

case expression of

1:begin

    语句1

  end

......

n:begin

    语句n

  end

else 语句n+1

endcase

 

相当于:

switch(expression)

{

    case 1:语句1;break;

    ......

    case n:语句n;break;

    default:语句n+1

}

repeat语句

repeat begin

语句

endrep until condition

 

相当于:

do { 语句; }

while(condition);

 

文件包含

@filename

#include<filename>

格式输入

read,var,format='(Xn.m)'

scanf("%n.m",&var);

格式输出

print,var,format='(Xn.m)'

printf("%n.m",var);

文件操作

file=filepath('filename',subdir='路径')

openr

lun,file,/get_lun

free_lun,lun

 

FILE *fp

fp=fopen("filename","打开方式");

fclose(fp);

绘图

set_plot,'设备名'

window,/free

device,decomposed=1

color='xxxxxx'XL

plot,x,y,参数

#include<graphics.h>

......

int graphdrv=VGA;

int graphmode=VGAHI;

intgraph=(&graphdrv,&graphmode,"路径");

......