doc-fred-ref
  • Introduction
  • Symbols
  • A
  • B
  • C
  • D
  • E
  • F
  • G
  • H
  • I
  • J
  • L
  • M
  • N
  • O
  • P
    • P Index
    • pair-expression
    • parameters
    • parent
    • partial_sums()
    • partner
    • percentile()
    • poisson()
    • pop()
    • pow()
    • preferential_attachment_network()
    • prev_state()
    • print()
    • print_csv()
      • Synopsis
      • Description
      • Parameters
      • Examples
      • See Also
    • print_file()
    • prob()
    • prod()
    • push()
  • Q
  • R
  • S
  • T
  • U
  • V
  • W
  • Y
doc-fred-ref
  • Starts with P
  • print_csv()
  • Edit on GitHub

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

See Also

open_csv() print() print_file() read_agent_file()

Previous Next

© Copyright 2021, Epistemix Inc.. Revision a994bf50.

Built with Sphinx using a theme provided by Read the Docs.
Read the Docs v: dev8
Versions
latest
dev8
Downloads
pdf
html
epub
On Read the Docs
Project Home
Builds