Top |
Lists of integers are used in many contexts in libgretl, e.g. for holding the ID numbers of variables in a regression specification. A gretl "list" is simply an array of ints following a definite convention: the value at position 0 gives the number of elements that follow. The total number of ints in the list foo is therefore foo[0] + 1, and reading the substantive members of foo involves looping from position 1 to position foo[0].
int *
gretl_list_new (int nterms
);
Creates a newly allocated list with space for nterms
elements,
besides the leading element, which in a gretl list always
holds a count of the number of elements that follow. This
leading element is initialized appropriately. For example, if
nterms
= 4, space for 5 integers is allocated and the first
element of the array is set to 4. The other elements of
the list are initialized to 0.
int * gretl_list_resize (int **oldlist
,int nterms
);
Resizes the content of oldlist
to hold nterms
, and adjusts
the first element to reflect the new size. If the new
list is longer than the old, the extra elements are initialized
to zero.
int * gretl_list_append_term (int **plist
,int v
);
Resizes (or allocates from scratch) the content of plist
,
so that it can hold one extra element, and sets the last
element to v
.
int *
gretl_list_sort (int *list
);
Sorts the elements from position 1 to the end of list
in ascending order.
int *
gretl_null_list (void
);
Creates a newly allocated "list" with only one member, which is set to zero.
int * gretl_consecutive_list_new (int lmin
,int lmax
);
Creates a newly allocated list whose elements run from
lmin
to lmax
consecutively.
int ** gretl_list_array_new (int nlists
,int nterms
);
Creates an array of newly allocated lists, each of which as described
in connection with gretl_list_new()
.
void gretl_list_array_free (int **lists
,int nlists
);
Frees all the lists in lists
and also the top-level pointer.
int *
gretl_list_copy (const int *src
);
int * gretl_list_copy_from_pos (const int *src
,int pos
);
int * gretl_list_from_string (const char *str
,int *err
);
Reads a string containing a list of integers, separated by spaces and/or commas and possibly wrapped in parentheses, and constructs an array of these integers. The first element is the number of integers that follow. This function supports an abbreviation for consecutive (increasing) integers in the list, using the notation, e.g., "1-4" as shorthand for "1 2 3 4".
int * gretl_list_from_varnames (const char *str
,const DATASET *dset
,int *err
);
int * gretl_list_from_vector (const gretl_matrix *v
,const DATASET *dset
,int *err
);
Tries to interpret the matrix v
as a list of ID
numbers of series. This can work only if v
is a
vector, and all its elements have integer values
k satisfying 0 <= k < v, where v is the number
of series in dset
. In the special case where v
is a null matrix, an empty list is returned.
int * gretl_auxlist_from_vector (const gretl_matrix *v
,int *err
);
Unlike gretl_list_from_vector()
this function does not
require that the elements of v
are valid series IDs. They
may represent a set of orders.
int * gretl_list_from_matrix (const gretl_matrix *X
,const char *prefix
,DATASET *dset
,int *err
);
Tries to add the columns of X
to dset
as series, and
if successful constructs a list holding the added series.
numbers of series. This is possible only if the rows of
X
can be matched to observations in dset
.
char *
gretl_list_to_numeric_string (const int *list
);
Prints the given list
of integers into a newly
allocated string, separated by single spaces and with
one leading space.
char * gretl_list_to_string (const int *list
,const DATASET *dset
,int *err
);
allocated string representation of list
, with ID
numbers cashed out as series names (and with one leading
space), or NULL on failure. The list separator LISTSEP,
is accepted in the incoming list
, otherwise all terms
must be integers in the range 0 to the greatest current
series ID within dset
.
char * gretl_list_to_lags_string (const int *list
,int *err
);
Prints the given list
of integers into a newly
allocated string, enclosed by braces and separated by commas.
Will fail if list
contains any numbers greater than 998.
char * gretl_list_get_names (const int *list
,const DATASET *dset
,int *err
);
Prints the names of the members of list
of integers into
a newly allocated string, separated by commas.
char ** gretl_list_get_names_array (const int *list
,const DATASET *dset
,int *err
);
int in_gretl_list (const int *list
,int k
);
Checks whether k
is present among the members of list
,
in position 1 or higher.
int gretl_list_delete_at_pos (int *list
,int pos
);
Deletes the element at position pos
from list
and moves any
remaining elements forward. Decrements the value of the first,
counter, element of list
.
int gretl_list_purge_const (int *list
,const DATASET *dset
);
Checks list
from position 1 onward for the presence of a
variable whose valid values in sample all equal 1.0. If
such a variable is found, it is deleted from list
(that is,
any following elements are moved forward by one and list[0]
is decremented by 1).
int gretl_list_min_max (const int *list
,int *lmin
,int *lmax
);
Reads list
from position 1 onward and writes to lmin
and lmax
the minimum and maximum values among the elements
of the list. Reading stops at the end of the list or when
a list separator is encountered.
int * gretl_list_add (const int *orig
,const int *add
,int *err
);
Creates a list containing the union of elements of orig
and the elements of add
. If one or more elements of
add
were already present in orig
, the error code is
E_ADDDUP
.
int * gretl_list_plus (const int *l1
,const int *l2
,int *err
);
Creates a list containing all elements of l1
followed
by all elements of l2
. This differs from gretl_list_union()
in that some elements may end up being repeated in the
returned list.
int * gretl_list_union (const int *l1
,const int *l2
,int *err
);
Creates a list holding the union of l1
and l2
.
int * gretl_list_intersection (const int *l1
,const int *l2
,int *err
);
Creates a list holding the intersection of l1
and l2
.
int * gretl_list_append_list (int **pl1
,const int *l2
,int *err
);
Creates a list holding the intersection of l1
and l2
.
int * gretl_list_product (const int *X
,const int *Y
,DATASET *dset
,int *err
);
Creates a list holding the Cartesian product of X
and Y
.
int * gretl_list_omit (const int *orig
,const int *omit
,int minpos
,int *err
);
Creates a list containing the elements of orig
that are not
present in omit
. It is an error if the omit
list contains
members that are not present in orig
, and also if the omit
list contains duplicated elements.
orig |
an array of integers, the first element of which holds a count of the number of elements following. |
|
omit |
list of variables to drop. |
|
minpos |
minimum position to check. This should be 2 for a regular
regression list, to skip the dependent var in position 1; but in
other contexts it may be 1 to start from the first element of |
|
err |
pointer to receive error code. |
int * gretl_list_omit_last (const int *orig
,int *err
);
Creates a list containing all but the last element of orig
,
which must not contain LISTSEP and must contain at least
two members.
int * gretl_list_drop (const int *orig
,const int *drop
,int *err
);
Creates a list containing the elements of orig
that are not
present in drop
. Unlike gretl_list_omit()
, processing always
starts from position 1 in orig
, and it is not an error if
some members of drop
are not present in orig
, or if some
members of drop
are duplicated.
int gretl_list_diff (int *targ
,const int *biglist
,const int *sublist
);
Fills out targ
with the elements of biglist
, from position 2
onwards, that are not present in sublist
. It is assumed that
the variable ID number in position 1 (dependent variable) is the
same in both lists. It is an error if, from position 2 on,
sublist
is not a proper subset of biglist
. See also
gretl_list_diff_new.
int * gretl_list_diff_new (const int *biglist
,const int *sublist
,int minpos
);
biglist |
inclusive list. |
|
sublist |
subset of biglist. |
|
minpos |
position in lists at which to start. |
a newly allocated list including the elements of biglist
,
from position minpos
onwards, that are not present in sublist
,
again from minpos
onwards, or NULL on failure. Note that
comparison stops whenever a list separator is found; i.e. only
the pre-separator portions of the lists are compared.
int * gretl_list_build (const char *s
,const DATASET *dset
,int *err
);
Builds a list based on the specification in s
, which may include
the ID numbers of variables, the names of variables, and/or the
names of previously defined lists (all separated by spaces).
int gretl_list_add_list (int **targ
,const int *src
);
Adds src
onto the end of targ
. The length of targ
becomes the
sum of the lengths of the two original lists.
int gretl_list_insert_list (int **targ
,const int *src
,int pos
);
Inserts src
into targ
at pos
. The length of targ
becomes the
sum of the lengths of the two original lists.
int gretl_list_insert_list_minus (int **targ
,const int *src
,int pos
);
Inserts src
into targ
at pos
. The length of targ
becomes the
sum of the lengths of the two original lists minus one. This
can be useful if we were expecting to insert a single variable
but found we had to insert a list instead. Insertion of src
overwrites any entries in targ
beyond pos
(the expectation is
that this function will be called in the process of assembling
targ
, in left-to-right mode).
int reglist_check_for_const (int *list
,const DATASET *dset
);
Checks list
for an intercept term (a variable all of
whose valid values in sample are 1). If such a variable
is present, it is moved to position 2 in the list.
list |
regression list suitable for use with a gretl model (should not contain LISTSEP). |
|
dset |
dataset struct. |
int gretl_list_const_pos (const int *list
,int minpos
,const DATASET *dset
);
Checks list
for the presence, in position minpos
or higher, of
a variable whose valid values in sample all equal 1. This usually
amounts to checking whether a list of regressors includes
an intercept term.
int list_members_replaced (const MODEL *pmod
,const DATASET *dset
);
Checks whether any variable used in pmod
has been redefined
since the model in question was estimated.
int
gretl_list_separator_position (const int *list
);
list |
an array of integer variable ID numbers, the first element of which holds a count of the number of elements following. |
if list
contains the separator for compound
lists, LISTSEP, the position in list
at which this is found,
else 0. The search begins at position 1.
int
gretl_list_has_separator (const int *list
);
list |
an array of integer variable ID numbers, the first element of which holds a count of the number of elements following. |
1 if list
contains the separator for compound
lists, LISTSEP, else 0. The search begins at position 1.
int gretl_list_split_on_separator (const int *list
,int **plist1
,int **plist2
);
If list
contains the list separator, LISTSEP, creates two
sub-lists, one containing the elements of list
preceding
the separator and one containing the elements following
the separator. The sub-lists are newly allocated, and assigned
as the content of plist1
and plist2
respectively. Note, however,
that one or other of the sublists can be discarded by passing
NULL as the second or third argument.
int * gretl_lists_join_with_separator (const int *list1
,const int *list2
);
Concatenates the content of list2
onto list1
, after first
appending the list separator. It is acceptable that list1
be NULL, in which case the returned list is just list2
with the separator prepended. But it is not acceptable that
list2
be null; in that this function returns NULL.
int gretl_list_duplicates (const int *list
,GretlCmdIndex ci
);
Checks whether or not a gretl list contains duplicated elements.
Exactly what counts as duplication depends on the context of the
command in which list
will be used, which is given by ci
.
int
gretl_list_n_distinct_members (const int *list
);
the count of distinct elements in list from position 1 onward, not counting LISTSEP if present.
int * full_var_list (const DATASET *dset
,int *nvars
);
Creates a newly allocated list including all series in the
dataset that are not hidden variables, and are accessible
at the current level of function execution.
The return value is NULL in case either (a) allocation of
memory failed, or (b) the resulting list would be empty.
The caller can distinguish between these possibilities by
examining the value returned in nvars
, which will be zero if
and only if the resulting list would be empty. If this is
not of interest to the caller, nvars
may be given as NULL.
int gretl_list_set_midas (const int *list
,DATASET *dset
);
Attempts to set the MIDAS flag on the members of list
.
0 on success, non-zero code on failure.
void gretl_list_print (const int *list
,const DATASET *dset
,PRN *prn
);
Prints to prn
the given list
of variables, by name
if dset
is non-NULL otherwise by ID number.
int * varname_match_list (const DATASET *dset
,const char *pattern
,int *err
);
int * ellipsis_list (const DATASET *dset
,int v1
,int v2
,int *err
);