read_place_file¶
Syntax¶
Parameters¶
file-name- The name of comma-separated file. The
file-namemay include the path to the file. place-type- The place type
Description¶
Read and internally store a list of places from a file.
This is a both Meta agent action and expression that reads a csv file with one line per new place with format:
The fields may occur in any order in the file. The type of each column is determined by the header line.
All fields are optional. If the ID field is missing or if a row specifies the ID value as 0, FRED will generate a unique place ID. If any other field is missing, FRED will assign a value of 0 to that attribute of the place.
Other fields are permitted in the file. If the header for a column correspsonds to a declared agent variable, and if the place-type has group agents, then the group agent associated with the place is assigned the value of the data field for the agent variable associated with the field. Otherwise, the column is ignored.
An error occurs if the file is not found.
Examples¶
In this example there are two files: 1) school.txt and 2) main.fred. The school.txt file contains user specified place information for a specific place type. On line 20 in main.fred, read_place_file ingests the data in school.txt and stores the IDs of the newly added places to new_places_list.
school.txt:
ID,LAT,LON,ELEV
314,40.5720110,-80.0287540,360.6687020
159,40.5305140,-80.2202550,352.7627710
265,40.4394250,-80.0530350,340.0347300
main.fred:
simulation {
locations = none
start_date = 2020-Jan-01
end_date = 2020-Jan-01
default_model = none
}
variables {
shared list new_places_list
new_places_list.output = 1
}
place School {
}
condition TEST {
start_state = Agent_Start
meta_start_state = Meta_Start
state Meta_Start {
new_places_list = read_place_file(school.txt, School)
open_file(id.txt,ID)
wait()
next()
}
state Agent_Start {
wait(1)
next(Agent_End)
}
state Agent_End {
print_file(id.txt,id)
wait()
next()
}
}