ReadFromFile

Syntax

ReadFromFile(FileName, [YearColumn, {TimeSliceColumn,} ValueColumn, Format])

Summary

Reads values from an external comma separated value (.CSV) file into a variable.  The function can be used to read in both time-sliced and non time-sliced data.

If no path is specified with the filename, the file is expected to be located in the current Area folder (normally located under Documents\LEAP Areas).  Years must be values between 1800 and 2500 and must be in ascending chronological order in the CSV file.  Timeslices must be specified as the names of time slices as specified in the General: Timeslices screen. For any single year it is advised (but not required) that you specify values for every time slice defined in LEAP.

You can optionally specify the column numbers for the years, values and time slices (for a time sliced variable).  The first column in the file is column 1.  If omitted, LEAP will expect to find years in column 1, time slice names in column 2 and values in column 3.  If any problems are encountered while reading the data such as invalid years, invalid time slice names or non-numeric data, then LEAP will return an error.

With the final optional Format parameter, you can specify the format of the numbers in the CSV file.  By default Windows assumes that numbers are formatted to match the settings on the PC where you are running LEAP. Check the Windows: Control Panel: Region and Language settings to view the settings on your PC. If the numbers and delimiter/separator characters are specified using UK/USA formatting (i.e. using commas for separators and a period for decimals, enter UK or US for the format parameter.  If the numbers are formatted using international formatting (i.e. using a semi-colon for separators and a comma for decimals, then enter INT for the format parameter).  These parameters are not case sensitive.  Unless the CSV file's numbers are formatted differently from the format on your PC then you will not need to specify the format parameter.  All numbers in the CSV file must be written without any separators for thousands, millions, etc.  For example: "1234.56" rather than "1,234.56".

Example

You want to read the values for a non-time-sliced variable from a CSV file named "data.txt" located in your area folder.  The file contents look like this (encoded as a standard ASCII text file).  In that file, column one contains the year identifier and column 3 contains the values for the variable you want to specify (starting with value 1.234).  Notice that the file is in US English format with commas as the list separator characters and a period as the decimal separator.  Note also that a comma is NOT required at the end of each line. It is also important that the values do not contain any separator characters for thousands/millions, etc.  (e.g. "13456.23", not  "13,456.23").

1970, 7.62, 1.234

1990, 7.95, 2.2845

2000, 8.04, 3.0156

2010, 8.76, 5.653

2020, 9.03, 2.765476

2025, 9.81, 4.823764

2030, 10.005, 10.287364

2040, 11.87, 12.876

2050, 13.62, 20.987

To read these values in, you would use the expression ReadFromFile(Data.txt, 1, 3)