Seppo Mustonen : Programming Survo in C

Functions in library SURVO.LIB

create_newvar
Summary

int create_newvar(data,name,type)
SURVO_DATA *data; /* pointer to data structure */
char *name;       /* name of new variable */
char type;        /* type 1,2,4,8 or S of new var. */
int len;          /* length of field (S type only) */
Description

The create_newvar function creates a new variable with the name name and of the type type for data data which has to be opened by data_open2 of the form data_open2(name,data,1,0,0); .

The length of the field in case of a string (S) variable, is given by len. In numeric variables the length is determined by type and len is not used.

Return Value

create_newvar returns the index (0,1,2,...,data->m-1) of the new variable and -1 if there is no room for new variables or the data representation does not permit creation of new variables.

See Also

data_save

Example

int i;
long j;
SURVO_DATA dat;

i=data_open2("TEST",&dat,1,0,0);
if (i<0) return;
i=create_newvar(&dat,"COUNT",'2');
if (i>=0)
    for (j=1L; j<=dat.n; ++j)
        data_save(&dat,j,3,MISSING8);

/* open TEST, create a new variable COUNT of
   integer type and save missing values in it. */


Front page of Survo C libraries