1 /*
2  *  gretl -- Gnu Regression, Econometrics and Time-series Library
3  *  Copyright (C) 2001 Allin Cottrell and Riccardo "Jack" Lucchetti
4  *
5  *  This program is free software: you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation, either version 3 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  *
18  */
19 
20 #ifndef DATAIO_H
21 #define DATAIO_H
22 
23 #include <stdio.h>
24 #include <string.h>
25 
26 typedef enum {
27     GRETL_XML_DATA,       /* gretl XML data file (.gdt) */
28     GRETL_BINARY_DATA,    /* gretl_binary data file (.gdtb) */
29     GRETL_CSV,            /* comma-separated or other plain text data */
30     GRETL_OCTAVE,         /* GNU octave ascii data file */
31     GRETL_GNUMERIC,       /* gnumeric workbook data */
32     GRETL_XLS,            /* MS Excel spreadsheet data */
33     GRETL_XLSX,           /* MS Office Open XML spreadsheet data */
34     GRETL_ODS,            /* Open Document Spreadsheet data */
35     GRETL_WF1,            /* Eviews workfile data */
36     GRETL_DTA,            /* Stata .dta data */
37     GRETL_SAV,            /* SPSS .sav data */
38     GRETL_SAS,            /* SAS xport data file */
39     GRETL_JMULTI,         /* JMulTi data file */
40     GRETL_DATA_MAX,       /* -- place marker -- */
41     GRETL_SCRIPT,         /* file containing gretl commands */
42     GRETL_SESSION,        /* zipped session file */
43     GRETL_NATIVE_DB,      /* gretl database */
44     GRETL_NATIVE_DB_WWW,  /* gretl database, accessed via internet */
45     GRETL_RATS_DB,        /* RATS 4.0 database */
46     GRETL_PCGIVE_DB,      /* PcGive bn7/in7 pair */
47     GRETL_ODBC,           /* Open DataBase Connectivity */
48     GRETL_DBNOMICS,       /* DB.NOMICS access */
49     GRETL_MAP,            /* shapefile or GeoJSON */
50     GRETL_UNRECOGNIZED    /* none of the above */
51 } GretlFileType;
52 
53 typedef enum {
54     CLEAR_FULL,           /* fully clear the dataset */
55     CLEAR_SUBSAMPLE       /* dataset is sub-sampled: clear partially */
56 } DataClearCode;
57 
58 #define SPREADSHEET_IMPORT(f) (f == GRETL_XLS ||	\
59 			       f == GRETL_XLSX ||	\
60 			       f == GRETL_GNUMERIC ||	\
61 			       f == GRETL_ODS)
62 
63 #define OTHER_IMPORT(f) (f == GRETL_DTA ||	\
64                          f == GRETL_SAV ||	\
65 			 f == GRETL_SAS ||	\
66                          f == GRETL_JMULTI ||	\
67                          f == GRETL_OCTAVE ||	\
68 			 f == GRETL_WF1 ||	\
69 			 f == GRETL_MAP)
70 
71 #define free_datainfo(p) do { if (p != NULL) { clear_datainfo(p, 0); free(p); } \
72                             } while (0);
73 
74 #define DBNA  -999.0 /* missing value code for gretl databases */
75 
76 #define GRETL_SCALAR_DIGITS 12
77 
78 /* functions follow */
79 
80 int dateton (const char *date, const DATASET *dset);
81 
82 int merge_dateton (const char *date, const DATASET *dset);
83 
84 char *ntolabel (char *datestr, int t, const DATASET *dset);
85 
86 char *ntolabel_8601 (char *datestr, int t, const DATASET *dset);
87 
88 int get_subperiod (int t, const DATASET *dset, int *err);
89 
90 int get_precision (const double *x, int n, int placemax);
91 
92 double get_date_x (int pd, const char *obs);
93 
94 void date_maj_min (int t, const DATASET *dset, int *maj, int *min);
95 
96 int write_data (const char *fname, int *list, const DATASET *dset,
97 		gretlopt opt, PRN *prn);
98 
99 int gui_write_data (const char *fname, int *list, const DATASET *dset,
100 		    gretlopt opt);
101 
102 int is_gzipped (const char *fname);
103 
104 int gretl_is_pkzip_file (const char *fname);
105 
106 gretlopt get_merge_opts (gretlopt opt);
107 
108 int merge_or_replace_data (DATASET *dset0, DATASET **pdset1,
109 			   gretlopt opt, PRN *prn);
110 
111 int gretl_get_data (char *fname, DATASET *dset,
112 		    gretlopt opt, PRN *prn);
113 
114 int open_nulldata (DATASET *dset, int data_status,
115 		   int length, gretlopt opt, PRN *prn);
116 
117 int import_csv (const char *fname, DATASET *dset,
118 	        gretlopt opt, PRN *prn);
119 
120 int import_spreadsheet (const char *fname, GretlFileType ftype,
121 			int *list, char *sheetname,
122 			DATASET *dset, gretlopt opt, PRN *prn);
123 
124 int import_other (const char *fname, GretlFileType ftype,
125 		  DATASET *dset, gretlopt opt, PRN *prn);
126 
127 int gretl_read_purebin (const char *fname, DATASET *dset,
128 			gretlopt opt, PRN *prn);
129 
130 int add_obs_markers_from_file (DATASET *dset, const char *fname);
131 
132 int add_var_labels_from_file (DATASET *dset, const char *fname);
133 
134 int save_var_labels_to_file (const DATASET *dset, const char *fname);
135 
136 int dataset_has_var_labels (const DATASET *dset);
137 
138 int read_or_write_var_labels (gretlopt opt, DATASET *dset, PRN *prn);
139 
140 int read_or_write_obs_markers (gretlopt opt, DATASET *dset, PRN *prn);
141 
142 GretlFileType data_file_type_from_name (const char *fname);
143 
144 GretlFileType detect_filetype (char *fname, gretlopt opt);
145 
146 int check_varname (const char *varname);
147 
148 int check_identifier (const char *varname);
149 
150 int check_atof (const char *numstr);
151 
152 int check_atoi (const char *numstr);
153 
154 int transpose_data (DATASET *dset);
155 
156 void dataset_add_import_info (DATASET *dset, const char *fname,
157 			      GretlFileType type);
158 
159 int analyse_daily_import (const DATASET *dset, PRN *prn);
160 
161 void set_dset_matrix_target (gretl_matrix **pm);
162 
163 void *get_dset_matrix_target (void);
164 
165 #endif /* DATAIO_H */
166