file.close
Syntax
- v = file.close(<f>)
Close a file. The most recently opened file is closed if no arguments are provided.
Returns: v - void return Arguments: f - optional file pointer
Example
model new
model largestrain off
fish define setup
global a_size = 20
global IO_READ = 0
global IO_WRITE = 1
global IO_FISH = 0
global IO_ASCII = 1
global filename = 'junk.dat'
end
@setup
;
fish define io
array aa(a_size) bb(a_size)
;
; ASCII I/O TEST ------------------
local status = file.open(filename, IO_WRITE, IO_ASCII)
aa(1) = 'Line 1 ... Fred'
aa(2) = 'Line 2 ... Joe'
aa(3) = 'Line 3 ... Roger'
status = file.write(aa,3)
status = file.close
status = file.open(filename, IO_READ, IO_ASCII)
status = file.read(bb, a_size)
if status # 3 then
local oo = io.out(' Bad number of lines')
endif
status = file.close
;
; now check results...
loop local n (1,3)
if string.token(bb(n), 2) # n then
oo = io.out(' Bad 2nd item in loop ' + string(n))
exit
endif
endloop
;
if string.token.type(bb(3),4) # 3 then
oo = io.out(' Not a string')
exit
endif
;
; FISH I/O TEST -----------------
status = file.open(filename, IO_WRITE, IO_FISH)
local funny_int = 1234567
local funny_float = 1.2345e6
aa(1) = '---> All tests passed OK'
aa(2) = funny_int
aa(3) = funny_float
;
status = file.write(aa,3)
status = file.close
status = file.open(filename, IO_READ, IO_FISH)
status = file.read(bb, 3)
status = file.close
;
; now check results...
if type(bb(1)) # 3 then
oo = io.out(' Bad FISH string read/write')
exit
endif
if bb(2) # funny_int then
oo = io.out(' Bad FISH integer read/write')
exit
endif
if bb(3) # funny_float then
oo = io.out(' Bad FISH float read/write')
exit
endif
oo = io.out(bb(1)) ; (should be a good message)
command
sys "del junk.dat"
endcommand
end
;
@io
Was this helpful? ... | PFC 6.0 © 2019, Itasca | Updated: Nov 19, 2021 |