is_file_open()
Determines whether a file was previously opened.
Synopsis
is_file_open(filename)
Description
This function checks whether the given filename has been opened by the open_file() function.
Parameters
filename
The name of a file.
Returns
Returns \(1\) (true
) if the given filename
has already been
opened by a prior call to open_file()
; and \(0\) (false
) otherwise.
Examples
Here is a simply program demonstrating the use of this function. The
PRINT_CENTENARIANS
condition puts any agents over \(99\) years old
into the PrintAgentData
state where basic agent data is printed out
during each time step (each simulation hour).
simulation {
locations = Jefferson_County_PA
start_date = 2022-Jan-01
end_date = 2022-Jan-03
}
condition PRINT_CENTENARIANS {
start_state = Start
state Start {
if (is_file_open(out.csv) == false) then open_file(out.csv, Run, ID, SimDay, Hour, RealAge)
wait(0)
if (age > 99) then next(PrintAgentData)
default(Excluded)
}
state PrintAgentData {
print_file(out.csv, sim_run, id, sim_day, hour, real_age)
wait(1)
next(PrintAgentData)
}
}