| Libgretl Reference Manual |
|---|
dataiodataio — |
enum GretlDataFormat; enum GretlFileType; enum DataClearCode; enum DataOpenCode; enum GretlVarnameError; #define WORKSHEET_IMPORT (f) #define free_datainfo (p) #define DBNA #define GRETL_SCALAR_DIGITS int dateton (const char *date, const DATAINFO *pdinfo); char* ntodate (char *datestr, int nt, const DATAINFO *pdinfo); char* ntodate_full (char *datestr, int t, const DATAINFO *pdinfo); int get_info (const char *hdrfile, PRN *prn); int get_precision (const double *x, int n, int placemax); double get_date_x (int pd, const char *obs); int write_data (const char *fname, const int *list, const double **Z, const DATAINFO *pdinfo, gretlopt opt, PATHS *ppaths); int data_report (const DATAINFO *pdinfo, PATHS *ppaths, PRN *prn); int is_gzipped (const char *fname); int gretl_is_pkzip_file (const char *fname); void gz_switch_ext (char *targ, char *src, char *ext); int merge_data (double ***pZ, DATAINFO *pdinfo, double **addZ, DATAINFO *addinfo, PRN *prn); int gretl_get_data (double ***pZ, DATAINFO **ppdinfo, char *datfile, PATHS *ppaths, DataOpenCode ocode, PRN *prn); int open_nulldata (double ***pZ, DATAINFO *pdinfo, int data_status, int length, PRN *prn); int import_csv (double ***pZ, DATAINFO **ppdinfo, const char *fname, PRN *prn); int import_octave (double ***pZ, DATAINFO **ppdinfo, const char *fname, PRN *prn); int import_box (double ***pZ, DATAINFO **ppdinfo, const char *fname, PRN *prn); int import_other (double ***pZ, DATAINFO **ppdinfo, int ftype, const char *fname, PRN *prn); int add_obs_markers_from_file (DATAINFO *pdinfo, const char *fname); GretlFileType detect_filetype (char *fname, PATHS *ppaths, PRN *prn); int check_varname (const char *varname); int check_atof (const char *numstr); int transpose_data (double ***pZ, DATAINFO *pdinfo);
typedef enum {
GRETL_DATA_FLOAT = 1, /* single-precision binary data */
GRETL_DATA_DOUBLE, /* double-precision binary data */
GRETL_DATA_OCTAVE, /* data in Gnu Octave format */
GRETL_DATA_CSV, /* data in Comma Separated Values format */
GRETL_DATA_R, /* data in Gnu R format */
GRETL_DATA_R_TS, /* data in Gnu R format (time series) */
GRETL_DATA_GZIPPED, /* gzipped data */
GRETL_DATA_TRAD, /* traditional (ESL-style) data */
GRETL_DATA_DAT, /* data in PcGive format */
GRETL_DATA_DB, /* gretl native database format */
GRETL_DATA_JM /* JMulti ascii data */
} GretlDataFormat;
typedef enum {
GRETL_NATIVE_DATA, /* gretl native format data file */
GRETL_XML_DATA, /* gretl xml format data file */
GRETL_CSV_DATA, /* comma-separated data file */
GRETL_BOX_DATA, /* BOX1 format data file */
GRETL_OCTAVE, /* GNU octave ascii data file */
GRETL_GNUMERIC, /* gnumeric workbook data */
GRETL_EXCEL, /* MS Excel spreadsheet data */
GRETL_WF1, /* Eviews workfile data */
GRETL_DTA, /* Stata .dta data */
GRETL_SCRIPT, /* file containing gretl commands */
GRETL_SESSION, /* zipped session file */
GRETL_NATIVE_DB, /* gretl database */
GRETL_NATIVE_DB_WWW, /* gretl database, accessed via internet */
GRETL_RATS_DB, /* RATS 4.0 database */
GRETL_PCGIVE_DB, /* PcGive bn7/in7 pair */
GRETL_JMULTI, /* JMulTi data file */
GRETL_UNRECOGNIZED /* none of the above */
} GretlFileType;
typedef enum {
CLEAR_FULL, /* fully clear the dataset */
CLEAR_SUBSAMPLE /* dataset is sub-sampled: clear partially */
} DataClearCode;
typedef enum {
DATA_NONE, /* no dataset is currently open */
DATA_CLEAR, /* dataset is open: dataset info should be cleared */
DATA_APPEND /* dataset is open: attempt to append new data */
} DataOpenCode;
typedef enum {
VARNAME_RESERVED = 1, /* vername is a gretl reserved name */
VARNAME_FIRSTCHAR, /* first character is not alphabetical */
VARNAME_BADCHAR /* illegal character in second or subsequent place */
} GretlVarnameError;
int dateton (const char *date,
const DATAINFO *pdinfo);
Given a "current" date string, a periodicity, and a starting date string, returns the observation number corresponding to the current date string, counting from zero.
date : |
string representation of date for processing. |
pdinfo : |
pointer to data information struct. |
| Returns : | integer observation number. |
char* ntodate (char *datestr,
int nt,
const DATAINFO *pdinfo);
print to datestr the calendar representation of observation
number nt.
datestr : |
string to which date is to be printed. |
nt : |
an observation number (zero-based). |
pdinfo : |
data information struct. |
| Returns : | the observation string. |
char* ntodate_full (char *datestr,
int t,
const DATAINFO *pdinfo);
datestr : |
|
t : |
|
pdinfo : |
|
| Returns : |
int get_info (const char *hdrfile,
PRN *prn);
print to prn the informative comments contained in the given
data file (if any).
hdrfile : |
name of data header file |
prn : |
gretl printing struct. |
| Returns : | 0 on successful completion, non-zero on error or if there are no informative comments. |
int get_precision (const double *x,
int n,
int placemax);
Find the number of decimal places required to represent a given data series uniformly.
x : |
data vector. |
n : |
length of x. |
placemax : |
maximum number of decimal places to try. |
| Returns : | the required number of decimal places. |
int write_data (const char *fname,
const int *list,
const double **Z,
const DATAINFO *pdinfo,
gretlopt opt,
PATHS *ppaths);
Write out a data file containing the values of the given set of variables.
fname : |
name of file to write. |
list : |
list of variables to write. |
Z : |
data matrix. |
pdinfo : |
data information struct. |
opt : |
option flag indicating format in which to write the data. |
ppaths : |
pointer to paths information (should be NULL when not called from gui). |
| Returns : | 0 on successful completion, non-zero on error. |
int data_report (const DATAINFO *pdinfo, PATHS *ppaths, PRN *prn);
Write out a summary of the content of the current data set.
pdinfo : |
data information struct. |
ppaths : |
path information struct. |
prn : |
gretl printing struct. |
| Returns : | 0 on successful completion, non-zero on error. |
int is_gzipped (const char *fname);
Determine if the given file is gzipped.
fname : |
filename to examine. |
| Returns : | 1 in case of a gzipped file, 0 if not gzipped or inaccessible. |
void gz_switch_ext (char *targ,
char *src,
char *ext);
Copy src filename to targ, without the existing suffix (if any),
and adding the supplied extension or suffix.
targ : |
target or "output" filename (must be pre-allocated). |
src : |
"source or "input" filename. |
ext : |
suffix to add to filename. |
int merge_data (double ***pZ,
DATAINFO *pdinfo,
double **addZ,
DATAINFO *addinfo,
PRN *prn);
Attempt to merge the content of a newly opened data file into gretl's current working data set.
pZ : |
pointer to data set. |
pdinfo : |
data information struct. |
addZ : |
new data set to be merged in. |
addinfo : |
data information associated with addZ.
|
prn : |
print struct to accept messages. |
| Returns : | 0 on successful completion, non-zero otherwise. |
int gretl_get_data (double ***pZ,
DATAINFO **ppdinfo,
char *datfile,
PATHS *ppaths,
DataOpenCode ocode,
PRN *prn);
Read data from file into gretl's work space, allocating space as required.
pZ : |
pointer to data set. |
ppdinfo : |
pointer to data information struct. |
datfile : |
name of file to try. |
ppaths : |
path information struct. |
ocode : |
DATA_NONE, DATA_CLEAR or DATA_APPEND.
|
prn : |
where messages should be written. |
| Returns : | 0 on successful completion, non-zero otherwise. |
int open_nulldata (double ***pZ,
DATAINFO *pdinfo,
int data_status,
int length,
PRN *prn);
Create an empty "dummy" data set, suitable for Monte Carlo simulations.
pZ : |
pointer to data set. |
pdinfo : |
data information struct. |
data_status : |
indicator for whether a data file is currently open in gretl's work space (1) or not (0). |
length : |
desired length of data series. |
prn : |
gretl printing struct. |
| Returns : | 0 on successful completion, non-zero otherwise. |
int import_csv (double ***pZ,
DATAINFO **ppdinfo,
const char *fname,
PRN *prn);
Open a Comma-Separated Values data file and read the data into the current work space.
pZ : |
pointer to data set. |
ppdinfo : |
pointer to data information struct. |
fname : |
name of CSV file. |
prn : |
gretl printing struct (can be NULL). |
| Returns : | 0 on successful completion, non-zero otherwise. |
int import_octave (double ***pZ,
DATAINFO **ppdinfo,
const char *fname,
PRN *prn);
Open a GNU octave ascii data file (matrix type) and read the data into the current work space.
pZ : |
pointer to data set. |
ppdinfo : |
pointer to data information struct. |
fname : |
name of GNU octave ascii data file. |
prn : |
gretl printing struct (can be NULL). |
| Returns : | 0 on successful completion, non-zero otherwise. |
int import_box (double ***pZ,
DATAINFO **ppdinfo,
const char *fname,
PRN *prn);
Open a BOX1 data file (as produced by the US Census Bureau's Data Extraction Service) and read the data into the current work space.
pZ : |
pointer to data set. |
ppdinfo : |
pointer to data information struct. |
fname : |
name of BOX1 file. |
prn : |
gretl printing struct. |
| Returns : | 0 on successful completion, non-zero otherwise. |
int import_other (double ***pZ,
DATAINFO **ppdinfo,
int ftype,
const char *fname,
PRN *prn);
Open a ...
pZ : |
pointer to data set. |
ppdinfo : |
pointer to data information struct. |
ftype : |
type of data file. |
fname : |
name of file. |
prn : |
gretl printing struct. |
| Returns : | 0 on successful completion, non-zero otherwise. |
int add_obs_markers_from_file (DATAINFO *pdinfo, const char *fname);
Read case markers (strings of OBSLEN - 1 characters or less that identify
the observations) from a file, and associate them with the
current data set. The file should contain one marker per line,
with a number of lines equal to the number of observations in
the current data set.
pdinfo : |
data information struct. |
fname : |
name of file containing case markers. |
| Returns : | 0 on successful completion, non-zero otherwise. |
GretlFileType detect_filetype (char *fname, PATHS *ppaths, PRN *prn);
Attempt to determine the type of a file to be opened in gretl: data file (of various formats), or command script.
fname : |
name of file to examine. |
ppaths : |
path information struct. |
prn : |
gretl printing struct. |
| Returns : | integer code indicating the type of file. |
int check_varname (const char *varname);
Check a variable/object name for legality: the name must start with a letter, and be composed of letters, numbers or the underscore character, and nothing else.
varname : |
putative name for variable (or object). |
| Returns : | 0 if name is OK, non-zero if not. |
int check_atof (const char *numstr);
numstr : |
string to check. |
| Returns : | 0 if numstr is blank, or is a valid string representation
of a floating point number, else 1.
|
int transpose_data (double ***pZ,
DATAINFO *pdinfo);
Attempts to transpose the current dataset, so that each variable becomes interpreted as an observation and each observation as a variable. This will not work if the dataset contains scalar variables.
pZ : |
pointer to data array. |
pdinfo : |
pointer to dataset information struct. |
| Returns : | 0 on success, non-zero error code on error. |
| << Data input and output | gretl_xml >> |