From GridLAB-D Wiki
Jump to: navigation, search

The CSV reader class is a helper object for the climate class in the Climate module. It is used to override the normal file-parsing behavior, which reads the input file in as a TMY2 file, and instead reads its file in as a series of comma-separated values.

CSV reader behavior

The CSV reader is intentionally designed to have no active components. It does nothing during the create, init, and sync steps.

CSV reader actors

Climate object

The CSV reader is used similar to a puppet by a climate object. If a climate object specifies that it is using a CSV reader, that it is reading in a .csv file, it will either use the CSV reader object referenced in its reader property, or a new reader object if a reference does not exist. The climate object will then call upon the CSV reader to parse the CSV file, which will create a list of time-ordered weather objects. When the climate object updates, it requests data from the CSV reader, which will identify which indexed row is appropriate for the current time and date, then copy the current weather data into the calling climate object.

Input file

The input file is expected to be formatted with three types of lines: comments, class data, and weather data.

Class Data

The CSV reader input file can contain inputs for the public properties of the CSV reader class. Any line with the format


will be used to fill the specified value into the named property. The name will be read up to the equality sign, and the value will be read to the end of the line.


Any line in the CSV file that immediately begins with the hash symbol, #, will be treated as a comment and disregarded.

Weather Header

If the CSV reader has not yet found or not pre-defined the column header, the first line that is not a comment and is not setting a class property will be interpreted as the property to reference for each column of data within the CSV reader. These property names must be separated with commas, and with no extraneous white space.

Weather Data

When the parser has a column header, any line that is not a comment or a class property is read as weather data. The first value is a timestamp, and any following values fill in the column that corresponds with the names provided in the header. The timestamp format can be manually set with a formatted scan string (see scanf()), otherwise will default to "%d:%d:%d:%d:%d". The input timestamp will read as many tokens as it is able, and will taken them in order as the month, day, hour, minute, and second of a year to fill in the associated values as the current weather data. Lines of weather data should be chronologically sequential; if the data's timestamp is earlier than the previous timestamp, it will be ignored and discarded.



The entry index number that the reader is using for the current weather values.


The name of the city the weather data is associated with.


The name of the state that the city is in for the associated weather data.


The whole degree latitude for the location that this weather data was recorded. North values are positive, south values are negative.


The sub-degree minutes of latitude for the location that this weather data was recorded.


The whole degree longitude for the location that this weather data was recorded. West values are negative, east values are positive.


The sub-degree minutes of longitude for the location that this weather data was recorded.


The highest observed temperature in the data set.


The highest observed solar input recorded in the data set.


The current state of the weather reader.


The file has not been opened and no data has been read.


The file has been opened and the data is either in the process of being read and processed, or is currently being used by the parent climate object.


The file was opened, but an error occurred while reading and parsing the file. The file has been closed and the reader is not usable by the system.


The string format to use for reading in timestamps from the file. By default, the format is "%d:%d:%d:%d:%d". The order of the values is the month, day, hour, minute, then second that the associated weather data will be used. The same dates are used for multiple years; individual years cannot be specified. Any value that is omitted defaults to zero, thus applying the value to the entirety of the omitted interval. Alternate formats must preserve the interval ordering, but may alter the format so long as up to five integers are read in.


The timezone the weather data's source city is in. Should be a three-letter code, akin to "GMT", "PST", or "EDT".


A list of headers for the columns. Each column name must match a property name in the weather object, else an error will occur. If this property is omitted, the parser will use the first line that is not a property definition and is not a comment as the column headers.


The name of the CSV file to read weather data from.


The CSV reader has no published functions.

Example model

This model is a representative model of what a csv reader object and csv reader file might look like:

module climate;
object csv_reader{
       name CsvReader;
       filename weather.csv;
object climate{
       name MyClimate;
       tmyfile weather.csv;
       reader CsvReader;

and the csv reader file looks like:

// Weather changes state every 15-minutes and is only specifying temperature and humidity
#sample weather CSV file