print_csv()
Print out personal agent variables to a specifed CSV file.
Synopsis
print_csv(filename, var_str1, var_str2, ...)
Description
This function will print out personal agent variables to a specified file in the order they are listed in the arguments.
Important: open_csv() must be called prior to calling print_csv
.
Also, the var_str arguments need to be surrounded in double-quotes ("
).
Parameters
filename
The file to write to.
var_str
The agent personal variable to print
Examples
agents.txt:
ID,age,sex
123,13,0
456,25,1
789,42,1
999,33,0
main.fred:
simulation {
locations = none
default_model = none
start_date = 2020-Jan-01
end_date = 2020-Jan-01
}
variables {
shared list new_agents_list
}
condition PrintCSV {
start_state = Agent_Start
meta_start_state = Meta_Start
state Meta_Start {
new_agents_list = read_agent_file(agents.txt)
read_agent_file(agents.txt)
open_csv(out.txt,"id","sex")
wait()
next()
}
state Agent_Start {
print_csv(out.txt,id,sex)
wait()
next()
}
}
The above FRED code prints the following file:
out.txt:
id,sex
123,0
456,1
789,1
999,0