-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgh_hed.cpp
More file actions
144 lines (125 loc) · 3.18 KB
/
gh_hed.cpp
File metadata and controls
144 lines (125 loc) · 3.18 KB
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
#include "gh_core.h"
gh_hed::gh_hed(FILE * _fp)
{
fseek(_fp, 0, SEEK_SET);
unsigned int kind;
fread(& kind, 4, 1, _fp);
int shift = kind == 1179535682 ? 0x214 : 0x254;
int tag_size = kind == 1179535682 ? 9 : 40;
for(unsigned int i(0); i < gh::dim_qua; i++)
{
fseek(_fp, shift, SEEK_SET);
fread(& size[i], 2, 1, _fp);
size[i] &= 0xffff;
shift += 12;
//DEBUG("the size of dimension #%d is %d\n", i, size[i]);
}
att = new char *** [gh::dim_qua];
for(unsigned int i(0); i < gh::dim_qua; i++)
{
att[i] = new char ** [size[i]];
for(unsigned int j(0); j < size[i]; j++)
{
att[i][j] = new char * [3];
att[i][j][0] = new char [tag_size + 1];
att[i][j][1] = new char [gh::sht_size + 1];
att[i][j][2] = new char [gh::lng_size + 1];
}
}
//DEBUG("Hi 1\n");
int ja;
for(unsigned int i(0); i < gh::dim_qua; i++)
{
for(unsigned int j(0); j < size[i]; j++)
{
ja = i == gh::dim_qua - 1 ? size[i] - j - 1 : j;
fread(att[i][ja][0], tag_size, 1, _fp);
att[i][ja][0][tag_size] = '\0';
fseek(_fp, 3, SEEK_CUR);//tag gap
}
}
//DEBUG("Hi 2\n");
for(unsigned int i(0); i < gh::dim_qua; i++)
{
for(unsigned int j(0); j < size[i]; j++)
{
ja = i == gh::dim_qua - 1 ? size[i] - j - 1 : j;
fread(att[i][ja][2], gh::lng_size, 1, _fp);
att[i][ja][2][gh::lng_size] = '\0';
fread(att[i][ja][1], gh::sht_size, 1, _fp);
att[i][ja][1][gh::sht_size] = '\0';
}
}
//DEBUG("Hi 3\n");
}
gh_hed::~gh_hed()
{
for(unsigned int i(0); i < gh::dim_qua; i++)
{
for(unsigned int j(0); j < size[i]; j++)
{
for(int k(0); k < 3; k++)
{
delete [] att[i][j][k];
}
delete [] att[i][j];
}
delete [] att[i];
}
delete [] att;
}
unsigned int gh_hed::get(unsigned int _dim_num, const char * _tag)
{
if(_dim_num >= gh::dim_qua)
{
ERROR
printf("header: There is no dimension # %d in database...\n\n", _dim_num);
return gh::wrong_number;
}
for(unsigned int i(0); i < size[_dim_num]; i++) if(!strcmp(_tag, att[_dim_num][i][0])) return i;
ERROR
printf("header: There is no tag %s in dimension # %d...\n\n", _tag, _dim_num);
return gh::wrong_number;
}
unsigned int gh_hed::get(unsigned int _dim_num, unsigned int _item_num)
{
//DEBUG("_dim_num: %d,_item_num: %d \n", _dim_num,_item_num);
if(_dim_num >= gh::dim_qua)
{
ERROR
printf("header: There is no dimension # %d in database...\n\n", _dim_num);
return gh::wrong_number;
}
if((_item_num < 0) || (_item_num >= size[_dim_num]))
{
ERROR
printf("header: There is no item %d in dimension # %d...\n\n", _item_num, _dim_num);
return gh::wrong_number;
}
//DEBUG("Hi there... dim: %d, item: %d\n", _dim_num, _item_num);
return _item_num;
}
void gh_hed::log(const char * _hed_name)
{
char log_name[350];
strcpy(log_name, _hed_name);
char * a = 0;
while((a = strchr(log_name, '/'))) * a = '_';
if((a = strrchr(log_name, '.'))) * a = '\0';
strcat(log_name, ".hed.log");
FILE * fp = fopen(log_name, "w");
if(!fp)
{
ERROR;
printf("gh_core:Cannot find the \"./rep\" directory\n");
return;
}
for(unsigned int i(0); i < gh::dim_qua; i++)
{
for(unsigned int j(0); j < size[i]; j++)
{
fprintf(fp, "%7d %-11s %-41s %-80s\n", j, att[i][j][0], att[i][j][1], att[i][j][2]);
}
}
fclose(fp);
}