Skip to content

print_csv

Syntax

print_csv("filename", var_str1, var_str2, ...)

Parameters

filename
The file to write to, surrounded by quotes.
var_str
A variable to print.

Description

This action will print out 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.

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")
        open_csv("out.txt","id","sex")
        wait()
        default()
    }

    state Agent_Start {
        print_csv("out.txt",id,sex)
        wait()
        default()
    }
}

The above FRED code prints the following file:

out.txt:

id,sex
123,0
456,1
789,1
999,0

See Also