文件处理

来自ArcoWiki
跳转至: 导航搜索

Write to file

The command WRITE/ is used to write and store data in an open file.
$$ Example of Write Command

DECL/CHAR,50,filnm,elnm
DECL/INTGR,i
DECL/DOUBLE,xx,yy,zz
TEXT/QUERY,(filnm),50,A,L,'insert file name'
filnm=ASSIGN/CONCAT('C:\',filnm,'.TXT')
DID(F1)=DEVICE/STOR,filnm


$$ This is to create some dummy points.

F(POI_1)=FEAT/POINT,CART, 1.111,2.222,3.333, 0,0,0
F(POI_2)=FEAT/POINT,CART, 4.444,5.555,6.666, 0,0,0
F(POI_3)=FEAT/POINT,CART, 7.777,8.888,9.999, 0,0,0
FA(POI_1)=FEAT/POINT,CART, 1.111,2.222,3.333, 0,0,0
FA(POI_2)=FEAT/POINT,CART, 4.444,5.555,6.666, 0,0,0
FA(POI_3)=FEAT/POINT,CART, 7.777,8.888,9.999, 0,0,0


$$ This row opens the file as an output device.

OPEN/DID(F1),DIRECT,OUTPUT,OVERWR
DO/i,1,3
$$ Get the values from points
elnm=ASSIGN/CONCAT('poi_',STR(i))
xx=OBTAIN/FA(@elnm),3
yy=OBTAIN/FA(@elnm),4
zz=OBTAIN/FA(@elnm),5
$$ Write command writes in the output file the required values
WRITE/DID(F1),xx
WRITE/DID(F1),yy
WRITE/DID(F1),zz
ENDDO
CLOSE/DID(F1)


Read from file

The command READ/ is used to get a value from an open file.

$$ Example of Read command

DECL/CHAR,50,filnm, result
DECL/CHAR,50,xyz
DECL/DOUBLE,xx,yy,zz
TEXT/QUERY,(filnm),50,A,L,'insert file name'
filnm=ASSIGN/CONCAT('C:\',filnm,'.TXT')
DID(F1)=DEVICE/STOR,filnm

$$ This row opens the file as an input device.

OPEN/DID(F1),DIRECT,INPUT
$$ Read command reads values from the input file and declare a point
READ/DID(F1),xx
READ/DID(F1),yy
READ/DID(F1),zz
F(POI_10)=FEAT/POINT,CART, xx,yy,zz, 0,0,0
FA(POI_10)=FEAT/POINT,CART, xx,yy,zz, 0,0,0
$$ Read command reads values from the input file and declare a point
READ/DID(F1),xx
READ/DID(F1),yy
READ/DID(F1),zz
F(POI_20)=FEAT/POINT,CART, xx,yy,zz, 0,0,0
FA(POI_20)=FEAT/POINT,CART, xx,yy,zz, 0,0,0
$$ Read command reads values from the input file and declare a point
READ/DID(F1),xx
READ/DID(F1),yy
READ/DID(F1),zz
F(POI_30)=FEAT/POINT,CART, xx,yy,zz, 0,0,0
FA(POI_30)=FEAT/POINT,CART, xx,yy,zz, 0,0,0
result=ASSIGN/CONCAT(STR(xx),' , ',STR(yy),' , ',STR(zz))
TEXT/OPER,result
CLOSE/DID(F1)