gdrsclib
|
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include "datastruct.h"
Go to the source code of this file.
Functions | |
int | getdata (char *fname, struct datablock *dblock, struct appdata ad) |
Read a datablock from a formatted file. More... | |
int | getff (char *fname, struct fixedfactor *ff, char **name, int datacol, struct appdata ad) |
Read a fixedfactor from a formatted file. More... | |
int | getts (char *fname, struct timeseries *ts, struct appdata ad) |
Read a timeseries from a formatted file. More... | |
void | data2ff (struct datablock dblock, struct fixedfactor ff, int year, struct appdata ad) |
Get all values for a particular year from a datablock. More... | |
void | ff2data (struct fixedfactor ff, struct datablock dblock, int year, struct appdata ad) |
Put the values for a particular year into a datablock. More... | |
int | allocdata (struct datablock *dblock, struct appdata ad) |
Create a datablock in memory, using application-specific dimensions. More... | |
int | allocff (struct fixedfactor *ff, struct appdata ad) |
Create a fixedfactor in memory, of length = number of countries. More... | |
int | allocts (struct timeseries *ts, struct appdata ad) |
Create a timeseries in memory, of length = y_start - y_end + 1. More... | |
void | cleardata (struct datablock dblock) |
Free the memory taken up by a datablock. More... | |
void | clearff (struct fixedfactor ff) |
Free the memory taken up by a fixedfactor. More... | |
void | clearts (struct timeseries ts) |
Free the memory taken up by a timeseries. More... | |
int | writedb2delim (struct datablock dblock, char *fname, char delim, struct appdata ad) |
Convenience function to dump a datablock to a file. More... | |
int | writets2delim (struct timeseries ts, char *fname, char delim, struct appdata ad) |
Convenience function to dump a timeseries to a file. More... | |
int | writeff2delim (struct fixedfactor ff, char *fname, char delim, struct appdata ad) |
Convenience function to dump a fixedfactor to a file. More... | |
double | getval (struct datablock db, int row, int year, struct appdata ad) |
Get the data value from the datablock for specified row & year. More... | |
void | setval (struct datablock db, double val, int row, int year, struct appdata ad) |
Set a specific value in a datablock, specified by row and year. More... | |
double | gettsval (struct timeseries ts, int year, struct appdata ad) |
Get the value for a particular year from a timeseries. More... | |
void | settsval (struct timeseries ts, double val, int year, struct appdata ad) |
Set the value for a particular year in a timeseries. More... | |
double | getffval (struct fixedfactor ff, int row, struct appdata ad) |
Get a value for a specified row (country) from a fixedfactor. More... | |
void | setffval (struct fixedfactor ff, double val, int row, struct appdata ad) |
Set a value for a specified row (country) for a fixedfactor. More... | |
Create a datablock in memory, using application-specific dimensions.
dblock | Datablock to create |
ad | appdata structure with dimensions |
NaN
Definition at line 223 of file datastruct.c.
int allocff | ( | struct fixedfactor * | ff, |
struct appdata | ad | ||
) |
Create a fixedfactor in memory, of length = number of countries.
ff | Fixed factor to allocate and fill |
ad | appdata structure with dimensions |
NaN
Definition at line 254 of file datastruct.c.
int allocts | ( | struct timeseries * | ts, |
struct appdata | ad | ||
) |
Create a timeseries in memory, of length = y_start - y_end + 1.
ts | Time series to allocate and fill |
ad | appdata structure with dimensions |
NaN
Definition at line 278 of file datastruct.c.
void cleardata | ( | struct datablock | dblock | ) |
Free the memory taken up by a datablock.
dblock | Datablock to free |
Definition at line 305 of file datastruct.c.
void clearff | ( | struct fixedfactor | ff | ) |
Free the memory taken up by a fixedfactor.
ff | Fixed factor to free |
Definition at line 314 of file datastruct.c.
void clearts | ( | struct timeseries | ts | ) |
Free the memory taken up by a timeseries.
ts | Time series to free |
Definition at line 323 of file datastruct.c.
void data2ff | ( | struct datablock | dblock, |
struct fixedfactor | ff, | ||
int | year, | ||
struct appdata | ad | ||
) |
Get all values for a particular year from a datablock.
dblock | Data block, 2-d data structure |
ff | Fixed factor data structure |
year | Year to pull data from dblock |
ad | appdata structure with dimensions Fill in ff from one column of dblock |
Definition at line 190 of file datastruct.c.
void ff2data | ( | struct fixedfactor | ff, |
struct datablock | dblock, | ||
int | year, | ||
struct appdata | ad | ||
) |
Put the values for a particular year into a datablock.
ff | Fixed factor (that is, values for all countries for one year) to insert |
dblock | Datablock for which values are inserted |
year | Year where ff should be inserted into dblock |
ad | appdata structure with dimensions Overwrite column for year=year of dblock |
Definition at line 207 of file datastruct.c.
Read a datablock from a formatted file.
This file provides functions for manipulating the array data structures used by the calculator.
fname | Name of the text file |
dblock | Datablock to read into |
ad | appdata structure with dimensions |
Definition at line 40 of file datastruct.c.
int getff | ( | char * | fname, |
struct fixedfactor * | ff, | ||
char ** | name, | ||
int | datacol, | ||
struct appdata | ad | ||
) |
Read a fixedfactor from a formatted file.
fname | Name of the input file |
ff | Fixed factor data structure |
name | Name of the data column to read in: reads from file |
datacol | Index of the data column to read in |
ad | appdata structure with dimensions |
Definition at line 90 of file datastruct.c.
double getffval | ( | struct fixedfactor | ff, |
int | row, | ||
struct appdata | ad | ||
) |
Get a value for a specified row (country) from a fixedfactor.
ff | Fixed factor to read from |
row | Specified row (country index) |
ad | appdata structure with dimensions |
NaN
if out of bounds Definition at line 507 of file datastruct.c.
int getts | ( | char * | fname, |
struct timeseries * | ts, | ||
struct appdata | ad | ||
) |
Read a timeseries from a formatted file.
fname | Name of the input file |
ts | Time series data structure to fill in |
ad | appdata structure with dimensions |
Definition at line 150 of file datastruct.c.
double gettsval | ( | struct timeseries | ts, |
int | year, | ||
struct appdata | ad | ||
) |
Get the value for a particular year from a timeseries.
ts | Time series to read from |
year | Specified year |
ad | appdata structure with dimensions |
NaN
if out of bounds Definition at line 474 of file datastruct.c.
Get the data value from the datablock for specified row & year.
db | Datablock to get data from |
row | Specified row (country index) |
year | Specified year |
ad | appdata structure with dimensions |
NaN
if out of bounds Definition at line 432 of file datastruct.c.
void setffval | ( | struct fixedfactor | ff, |
double | val, | ||
int | row, | ||
struct appdata | ad | ||
) |
Set a value for a specified row (country) for a fixedfactor.
ff | Fixed factor to write to |
val | Value to set |
row | Row where value should be set |
ad | appdata structure with dimensions Set value at row "row" in ff |
Definition at line 524 of file datastruct.c.
void settsval | ( | struct timeseries | ts, |
double | val, | ||
int | year, | ||
struct appdata | ad | ||
) |
Set the value for a particular year in a timeseries.
ts | Time series to write to |
val | Value to set |
year | Year for which value should be set |
ad | appdata structure with dimensions Set value at year "year" in ts |
Definition at line 491 of file datastruct.c.
Convenience function to dump a datablock to a file.
dblock | Datablock to write |
fname | Filename to write to |
delim | Delimiter to use |
ad | appdata structure with dimensions |
Definition at line 337 of file datastruct.c.
int writeff2delim | ( | struct fixedfactor | ff, |
char * | fname, | ||
char | delim, | ||
struct appdata | ad | ||
) |
Convenience function to dump a fixedfactor to a file.
ff | Fixed factor to write |
fname | Filename to write to |
delim | Delimiter (currently ignored – just one column) |
ad | appdata structure with dimensions |
Definition at line 403 of file datastruct.c.
int writets2delim | ( | struct timeseries | ts, |
char * | fname, | ||
char | delim, | ||
struct appdata | ad | ||
) |
Convenience function to dump a timeseries to a file.
ts | Time series to write |
fname | Filename to write to |
delim | Delimiter to use |
ad | appdata structure with dimensions |
Definition at line 374 of file datastruct.c.