-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstataread.h
158 lines (126 loc) · 3.05 KB
/
stataread.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
* PHP Stata Extension
* Copyright (C) 2014 Adrian Montero
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, a copy is available at
* http://www.gnu.org/licenses/gpl-2.0.html
*/
#ifndef STATAREAD_H
#define STATAREAD_H
#include <stdio.h>
#include <stdlib.h> /* for abs */
#include <errno.h>
#include "swap_bytes.h"
#include <math.h>
#include <string.h>
#include <limits.h>
#include <string.h>
#include <jansson.h>
#include <time.h>
/* versions */
#define VERSION_5 0x69
#define VERSION_6 'l'
#define VERSION_7 0x6e
#define VERSION_7SE 111
#define VERSION_8 113
#define VERSION_114 114
#define VERSION_115 115
#define STATA_FLOAT 'f'
#define STATA_DOUBLE 'd'
#define STATA_INT 'l'
#define STATA_SHORTINT 'i'
#define STATA_BYTE 'b'
#define STATA_SE_STRINGOFFSET 0
#define STATA_SE_FLOAT 254
#define STATA_SE_DOUBLE 255
#define STATA_SE_INT 253
#define STATA_SE_SHORTINT 252
#define STATA_SE_BYTE 251
#define STATA_STRINGOFFSET 0x7f
#define STATA_BYTE_NA 127
#define STATA_SHORTINT_NA 32767
#define STATA_INT_NA 2147483647
#define STATA_FLOAT_NA pow(2.0, 127)
#define STATA_DOUBLE_NA pow(2.0, 1023)
#define NA_INTEGER (-2147483648)
#define CN_TYPE_BIG 1
#define CN_TYPE_LITTLE 2
#define CN_TYPE_IEEEL CN_TYPE_LITTLE
#define CN_TYPE_NATIVE CN_TYPE_IEEEL
typedef union
{
double value;
unsigned int word[2];
} ieee_double;
#ifdef WORDS_BIGENDIAN
static int hw = 0;
static int lw = 1;
#else /* !WORDS_BIGENDIAN */
static int hw = 1;
static int lw = 0;
#endif /* WORDS_BIGENDIAN */
//#define NA_REAL R_ValueOfNA()
double NA_REAL();
struct StataLabel
{
struct StataLabel * next;
char *name;
int value;
char *string;
};
struct StataObservationData
{
int n;
struct StataObservationData * next;
union
{
double d;
int i;
char string[256];
} value;
};
struct StataObservation
{
int n;
struct StataObservationData * data;
struct StataObservation * next;
};
struct StataVariable
{
struct StataVariable * next;
int valueType;
union
{
double d;
int i;
char string[256];
} value;
char * name;
char * vfmt;
char * vlabels;
char * dlabels;
};
struct StataDataFile
{
int version;
int nvar;
int nobs;
char *datalabel;
char *timestamp;
struct StataObservation * observations;
struct StataVariable * variables;
int nlabels;
struct StataLabel * labels;
};
#endif