Cell2Fire
A large-scale forest fire simulator.
Loading...
Searching...
No Matches
CSVReader Class Reference

Public Member Functions

 CSVReader (std::string filename, std::string delm=",")
 
std::vector< std::vector< std::string > > getData ()
 Reads and parses data from a CSV, ASCII or TIFF file into a 2D vector.
 
void printData (std::vector< std::vector< std::string > > &DF)
 print data contained in 2D vector to console row by row
 
void parseDF (inputs *df_ptr, std::vector< std::vector< std::string > > &DF, arguments *args_ptr, int NCells)
 Populates an instance of inputs using information contained in a 2D vector.
 
void parseNDF (std::vector< int > &NFTypes, std::vector< std::vector< std::string > > &DF, int NCells)
 Populates a vector of size NCells with fuel type number per cell.
 
void parsePROB (std::vector< float > &probabilities, std::vector< std::vector< std::string > > &DF, int NCells)
 Not currently supported. Populates a vector of size NCells with ignition probability per cell.
 
void parseWeatherDF (weatherDF *wt_ptr, arguments *args_ptr, std::vector< std::vector< std::string > > &DF, int WPeriods)
 
void parseIgnitionDF (std::vector< int > &ig, std::vector< std::vector< std::string > > &DF, int IgPeriods)
 
void parseForestDF (forestDF *frt_ptr, std::vector< std::vector< std::string > > &DF)
 
void parseHarvestedDF (std::unordered_map< int, std::vector< int > > &hc, std::vector< std::vector< std::string > > &DF, int HPeriods)
 
void parseBBODF (std::unordered_map< int, std::vector< float > > &bbo, std::vector< std::vector< std::string > > &DF, int NFTypes)
 
void printDF (inputs df)
 
void printWeatherDF (weatherDF wdf)
 

Public Attributes

std::string fileName
 
std::string delimeter
 

Constructor & Destructor Documentation

◆ CSVReader()

CSVReader::CSVReader ( std::string  filename,
std::string  delm = "," 
)

Creates an instance of CSVReader.

Parameters
filenamename of file to read
delmdelimiter of columns in file.

Member Function Documentation

◆ getData()

std::vector< std::vector< std::string > > CSVReader::getData ( )

Reads and parses data from a CSV, ASCII or TIFF file into a 2D vector.

Checks for the existence of the input file with either a .tif or .asc extension and processes it accordingly. If the file is in CSV format, it is read line by line and split using the specified delimiter. If the file is in ASCII format, the function reads the header separately before parsing the data. If the file is in TIFF format, it extracts metadata (e.g., grid dimensions, cell size, and coordinates) and reads raster data row by row.

Returns
A 2D vector of strings containing the parsed data.
  • For ASC and CSV files, each row is stored as a vector of strings.
  • For TIFF files, metadata is stored in the first few rows, followed by pixel values.
Exceptions
std::runtime_errorIf the file type is unsupported, memory allocation fails, or an error occurs during file reading.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ parseDF()

void CSVReader::parseDF ( inputs df_ptr,
std::vector< std::vector< std::string > > &  DF,
arguments args_ptr,
int  NCells 
)

Populates an instance of inputs using information contained in a 2D vector.

Populates the inputs object df_ptr with the information found in DF. If no value is provided for a variable, then a default one is used.

Parameters
df_ptrpointer to inputs object
DF2D vector with input data
args_ptrarray of inputted command line arguments
NCellsnumber of cells
Here is the caller graph for this function:

◆ parseNDF()

void CSVReader::parseNDF ( std::vector< int > &  NFTypes,
std::vector< std::vector< std::string > > &  DF,
int  NCells 
)

Populates a vector of size NCells with fuel type number per cell.

Parameters
NFTypesvector of fuel type per cell
DF2D vector of input data
NCellsnumber of cells
Here is the caller graph for this function:

◆ parsePROB()

void CSVReader::parsePROB ( std::vector< float > &  probabilities,
std::vector< std::vector< std::string > > &  DF,
int  NCells 
)

Not currently supported. Populates a vector of size NCells with ignition probability per cell.

This is not currently supported because ignition probability is not stored in DF.

Parameters
probabilitiesvector of ignition probability per cell
DF2D vector of input data
NCellsnumber of cells
Here is the caller graph for this function:

◆ printData()

void CSVReader::printData ( std::vector< std::vector< std::string > > &  DF)

print data contained in 2D vector to console row by row

Parameters
DF2D vector of strings
Here is the caller graph for this function:

The documentation for this class was generated from the following files: