# open_file()

Open a file for printing.

## Synopsis

open_file(filename, header1, header2, ...)


## Description

This function opens a file for printing, and must be called before the print_file() function can be used. It is an error to call this function on the same file more than once, so using the function is_file_open() is recommended to verify that the file is not already open.

The file is opened in a CSV directory within the current RUN directory. That is, if FRED_RESULTS is the location of the FRED results directory, then a file out.csv during Run $$1$$ of Job $$17$$ would be opened as the file \${FRED_RESUltS}/JOB/17/OUT/RUN1/CSV/out.csv.

## Parameters

filename

The name of the file to open for printing (no quotes)

header1, header2, ...

A comma-separate list of header names to place at the start of the file. These are written as the first line of the file separated by commas as the CSV header for the file. Each header name must be a non-empty string of alphanumeric and underscore characters.

## Returns

This function has no return value.

## 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)
}
}


## Errors

It is a run-time error to call open_file() more than once on the same file.

## Notes

This function was originally called open(), which is no deprecated.