Top |
The following data handling functions are basically internal to gretl and not in a state where they can be readily documented as public APIs.
int dateton (const char *date
,const DATASET *dset
);
Determines the observation number corresponding to date
,
relative to dset
. It is an error if date
represents an
observation that lies outside of the full data range
specified in dset
.
int merge_dateton (const char *date
,const DATASET *dset
);
Works just as dateton()
, except that for this function it
is not an error if date
represents an observation that
lies beyond the data range specified in dset
. This is
inended for use when merging data, or when creating a new
dataset.
char * ntolabel (char *datestr
,int t
,const DATASET *dset
);
Prints to datestr
(which must be at least OBSLEN bytes)
the calendar representation of observation number t
.
int get_subperiod (int t
,const DATASET *dset
,int *err
);
For "seasonal" time series data (in a broad sense),
determines the sub-period at observation t
. The "sub-period"
might be a quarter, month, hour or whatever. The value
returned is zero-based (e.g. first quarter = 0).
If the data are not "seasonal", 0 is returned and if
err
is non-NULL it receives a non-zero error code.
int get_precision (const double *x
,int n
,int placemax
);
Find the number of decimal places required to represent a given data series uniformly and accurately, if possible.
int write_data (const char *fname
,int *list
,const DATASET *dset
,gretlopt opt
,PRN *prn
);
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 (or |
|
dset |
dataset struct. |
|
opt |
option flag indicating format in which to write the data. |
|
prn |
gretl printer or NULL. |
int gui_write_data (const char *fname
,int *list
,const DATASET *dset
,gretlopt opt
);
gretlopt
get_merge_opts (gretlopt opt
);
just those components of opt
(if any) that
can be passed to merge_or_replace_data()
; may be
useful when calling that function in the context
of a command only some of whose options should be
forwarded.
int merge_or_replace_data (DATASET *dset0
,DATASET **pdset1
,gretlopt opt
,PRN *prn
);
Given a newly-created dataset, pointed to by pdset1
, either
attempt to merge it with dset0
, if the original data array
is non-NULL, or replace the content of the original pointer
with the new dataset.
In case merging is not successful, the new dataset is destroyed.
int gretl_get_data (char *fname
,DATASET *dset
,gretlopt opt
,PRN *prn
);
Read "native" data from file into gretl's work space,
allocating space as required. This function handles
both native XML data format and native binary format.
It also handles incomplete information: it can perform
path-searching on fname
, and will try adding the .gdt
or .gdtb extension to fname
if this is not given.
Note that a more straightforward function for reading a
native gretl data file, given the correct path, is
gretl_read_gdt()
.
The only applicable option is that opt
may contain
OPT_T when appending data to a panel dataset: in
that case we try to interpret the new data as time
series, in common across all panel units. In most
cases, just give OPT_NONE.
int open_nulldata (DATASET *dset
,int data_status
,int length
,gretlopt opt
,PRN *prn
);
Create an empty "dummy" data set, suitable for simulations.
int import_spreadsheet (const char *fname
,GretlFileType ftype
,int *list
,char *sheetname
,DATASET *dset
,gretlopt opt
,PRN *prn
);
Open a data file of a type that requires a special plugin.
Acceptable values for ftype
are GRETL_GNUMERIC
,
GRETL_XLS
, GRETL_XLSX
and GRETL_ODS
.
fname |
name of file. |
|
ftype |
type of data file. |
|
list |
list of parameters for spreadsheet import, or NULL. |
|
sheetname |
name of specific worksheet, or NULL. |
|
dset |
dataset struct. |
|
opt |
option flag; see |
|
prn |
gretl printing struct. |
int import_other (const char *fname
,GretlFileType ftype
,DATASET *dset
,gretlopt opt
,PRN *prn
);
Open a data file of a type that requires a special plugin.
fname |
name of file. |
|
ftype |
type of data file. |
|
dset |
pointer to dataset struct. |
|
opt |
option flag; see |
|
prn |
gretl printing struct. |
int gretl_read_purebin (const char *fname
,DATASET *dset
,gretlopt opt
,PRN *prn
);
int add_obs_markers_from_file (DATASET *dset
,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.
int add_var_labels_from_file (DATASET *dset
,const char *fname
);
Read descriptive variables for labels (strings of MAXLABEL
- 1
characters or less) from a file, and associate them with the
current data set. The file should contain one label per line,
with a number of lines equal to the number of variables in
the current data set, excluding the constant.
int save_var_labels_to_file (const DATASET *dset
,const char *fname
);
Writes to fname
the descriptive labels for the series in
the current dataset.
GretlFileType detect_filetype (char *fname
,gretlopt opt
);
Attempts to determine the type of a file to be opened in gretl:
data file (of various formats), or command script. If OPT_P
is given, the fname
argument must be an array of length
at least MAXLEN
: a path may be prepended and in some cases
an extension may be appended.
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.
int
transpose_data (DATASET *dset
);
Attempts to transpose the current dataset, so that each variable becomes interpreted as an observation and each observation as a variable.
void dataset_add_import_info (DATASET *dset
,const char *fname
,GretlFileType type
);
On successful import of data from some "foreign" format, add a note to the "descrip" member of the new dataset saying where it came from and when.