bio-affy 0.1.0.alpha.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. data/.document +5 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +15 -0
  4. data/Gemfile.lock +32 -0
  5. data/LICENSE.txt +20 -0
  6. data/README.rdoc +33 -0
  7. data/Rakefile +77 -0
  8. data/VERSION +1 -0
  9. data/bin/bio-affy +80 -0
  10. data/bio-affy.gemspec +128 -0
  11. data/ext/DESCRIPTION +11 -0
  12. data/ext/HISTORY +3 -0
  13. data/ext/LICENSE +456 -0
  14. data/ext/NAMESPACE +2 -0
  15. data/ext/R/check.cdf.type.R +18 -0
  16. data/ext/R/read.cdffile.list.R +23 -0
  17. data/ext/R/read.celfile.R +11 -0
  18. data/ext/R/read.celfile.header.R +37 -0
  19. data/ext/R/read.probematrices.R +29 -0
  20. data/ext/README_BIOLIB +36 -0
  21. data/ext/aclocal.m4 +32 -0
  22. data/ext/configure +4898 -0
  23. data/ext/configure.in +51 -0
  24. data/ext/man/check.cdf.type.Rd +22 -0
  25. data/ext/man/read.cdffile.list.Rd +20 -0
  26. data/ext/man/read.celfile.Rd +23 -0
  27. data/ext/man/read.celfile.header.Rd +22 -0
  28. data/ext/man/read.celfile.probeintensity.matrices.Rd +31 -0
  29. data/ext/src/CMakeLists.txt +39 -0
  30. data/ext/src/Makevars.in +3 -0
  31. data/ext/src/Makevars.win +2 -0
  32. data/ext/src/Rakefile +43 -0
  33. data/ext/src/biolib_affyio.c +416 -0
  34. data/ext/src/biolib_affyio.h +132 -0
  35. data/ext/src/biolib_affyio.o +0 -0
  36. data/ext/src/fread_functions.c +871 -0
  37. data/ext/src/fread_functions.h +60 -0
  38. data/ext/src/fread_functions.o +0 -0
  39. data/ext/src/libaffyext.so +0 -0
  40. data/ext/src/mkrf.log +11 -0
  41. data/ext/src/mkrf_conf.rb +6 -0
  42. data/ext/src/read_abatch.c +5484 -0
  43. data/ext/src/read_abatch.h +63 -0
  44. data/ext/src/read_abatch.o +0 -0
  45. data/ext/src/read_bpmap.c +888 -0
  46. data/ext/src/read_bpmap.o +0 -0
  47. data/ext/src/read_cdf.h +347 -0
  48. data/ext/src/read_cdf_xda.c +1342 -0
  49. data/ext/src/read_cdf_xda.o +0 -0
  50. data/ext/src/read_cdffile2.c +1576 -0
  51. data/ext/src/read_cdffile2.o +0 -0
  52. data/ext/src/read_celfile_generic.c +2061 -0
  53. data/ext/src/read_celfile_generic.h +33 -0
  54. data/ext/src/read_celfile_generic.o +0 -0
  55. data/ext/src/read_clf.c +870 -0
  56. data/ext/src/read_clf.o +0 -0
  57. data/ext/src/read_generic.c +1446 -0
  58. data/ext/src/read_generic.h +144 -0
  59. data/ext/src/read_generic.o +0 -0
  60. data/ext/src/read_pgf.c +1337 -0
  61. data/ext/src/read_pgf.o +0 -0
  62. data/lib/bio-affy.rb +5 -0
  63. data/lib/bio/affy.rb +7 -0
  64. data/lib/bio/affyext.rb +23 -0
  65. data/lib/bio/libaffyext.so +0 -0
  66. data/spec/bio-affy_spec.rb +22 -0
  67. data/spec/spec_helper.rb +13 -0
  68. data/test/data/affy/GSM103328.CEL.gz +0 -0
  69. data/test/data/affy/GSM103329.CEL.gz +0 -0
  70. data/test/data/affy/GSM103330.CEL.gz +0 -0
  71. data/test/data/affy/MG_U74Av2.CDF.gz +0 -0
  72. metadata +190 -0
Binary file
@@ -0,0 +1,1446 @@
1
+ /*************************************************************
2
+ **
3
+ ** file: read_generic.c
4
+ **
5
+ ** Written by B. M. Bolstad <bmb@bmbolstad.com>
6
+ **
7
+ ** Aim is to read in Affymetrix files in the
8
+ ** "Command Console Generic Data" File Format
9
+ ** This format is sometimes known as the Calvin format
10
+ **
11
+ ** As with other file format functionality in affyio
12
+ ** gzipped files are accepted.
13
+ **
14
+ ** The implementation here is based upon openly available
15
+ ** file format information. The code here is not dependent or based
16
+ ** in anyway on that in the Fusion SDK.
17
+ **
18
+ **
19
+ ** History
20
+ ** Aug 25, 2007 - Initial version
21
+ ** Sep 9, 2007 - fix some compiler warnings.
22
+ ** Oct 25, 2007 - fix error in decode_UINT8_t
23
+ ** Jan 28, 2008 - fix read_generic_data_group/gzread_generic_data_group. Change bitwise OR (|) to logical OR (||)
24
+ ** Feb 11, 2008 - add #include for inttypes.h in situations that stdint.h might not exist
25
+ ** Feb 13, 2008 - add decode_MIME_value_toASCII which takes any MIME and attempts to convert to a string
26
+ ** Jul 29, 2008 - fix preprocessor directive error for WORDS_BIGENDIAN systems
27
+ ** Jan 15, 2008 - Fix VECTOR_ELT/STRING_ELT issues
28
+ **
29
+ *************************************************************/
30
+
31
+ #include <R.h>
32
+ #include <Rdefines.h>
33
+ #include <Rmath.h>
34
+ #include <Rinternals.h>
35
+
36
+ #define HAVE_STDINT_H
37
+
38
+ #ifdef HAVE_STDINT_H
39
+ #include <stdint.h>
40
+ #elif HAVE_INTTYPES_H
41
+ #include <inttypes.h>
42
+ #endif
43
+
44
+ #include <wchar.h>
45
+
46
+ #include <stdio.h>
47
+ #include <stdlib.h>
48
+
49
+
50
+ #include "fread_functions.h"
51
+
52
+ #include "read_generic.h"
53
+
54
+
55
+ static void Free_ASTRING(ASTRING *string){
56
+ Free(string->value);
57
+ string->len =0;
58
+ }
59
+
60
+
61
+ static void Free_AWSTRING(AWSTRING *string){
62
+ Free(string->value);
63
+ string->len =0;
64
+
65
+
66
+ }
67
+
68
+
69
+ static void Free_nvt_triplet(nvt_triplet *triplet){
70
+ Free_AWSTRING(&(triplet->name));
71
+ Free_ASTRING(&(triplet->value));
72
+ Free_AWSTRING(&(triplet->type));
73
+ }
74
+
75
+
76
+ static void Free_nvts_triplet(col_nvts_triplet *triplet){
77
+ Free_AWSTRING(&(triplet->name));
78
+
79
+ }
80
+
81
+
82
+
83
+
84
+
85
+ void Free_generic_data_header(generic_data_header *header){
86
+
87
+ int i;
88
+ generic_data_header *temp;
89
+
90
+ Free_ASTRING(&(header->data_type_id));
91
+ Free_ASTRING(&(header->unique_file_id));
92
+ Free_AWSTRING(&(header->Date_time));
93
+ Free_AWSTRING(&(header->locale));
94
+
95
+ for (i =0; i < header->n_name_type_value; i++){
96
+ Free_nvt_triplet(&(header->name_type_value[i]));
97
+ }
98
+ Free(header->name_type_value);
99
+
100
+ for (i=0; i < (header->n_parent_headers); i++){
101
+ temp = (generic_data_header *)header->parent_headers[i];
102
+ Free_generic_data_header(temp);
103
+ Free(temp);
104
+ }
105
+ if (header->parent_headers != 0)
106
+ Free(header->parent_headers);
107
+
108
+
109
+ }
110
+
111
+
112
+ void Free_generic_data_group(generic_data_group *data_group){
113
+
114
+
115
+ Free_AWSTRING(&(data_group->data_group_name));
116
+
117
+ }
118
+
119
+
120
+ void Free_generic_data_set(generic_data_set *data_set){
121
+
122
+ int i;
123
+
124
+ Free_AWSTRING(&(data_set->data_set_name));
125
+
126
+ for (i =0; i < data_set->n_name_type_value; i++){
127
+ Free_nvt_triplet(&(data_set->name_type_value[i]));
128
+ }
129
+ Free(data_set->name_type_value);
130
+
131
+ for (i=0; i < data_set->ncols; i++){
132
+ Free_nvts_triplet(&(data_set->col_name_type_value[i]));
133
+ }
134
+ Free(data_set->col_name_type_value);
135
+
136
+ for (i= 0; i < data_set->ncols; i++){
137
+ Free(data_set->Data[i]);
138
+ }
139
+ Free(data_set->Data);
140
+
141
+
142
+ }
143
+
144
+
145
+ static int fread_ASTRING(ASTRING *destination, FILE *instream){
146
+
147
+ fread_be_int32(&(destination->len),1,instream);
148
+ if (destination->len > 0){
149
+ destination->value = Calloc(destination->len+1,char);
150
+ fread_be_char(destination->value,destination->len,instream);
151
+ } else {
152
+ destination->value = 0;
153
+ }
154
+ return 1;
155
+ }
156
+
157
+
158
+
159
+ static int fread_AWSTRING(AWSTRING *destination, FILE *instream){
160
+
161
+ uint16_t temp; /* Affy file wchar_t are 16 bits, the platform may have 32 bit wchar_t (notatbly linux) */
162
+
163
+ int i;
164
+
165
+ fread_be_int32(&(destination->len),1,instream);
166
+ if ((destination->len) > 0){
167
+ destination->value = Calloc(destination->len+1,wchar_t);
168
+
169
+ for (i=0; i < destination->len; i++){
170
+ fread_be_uint16(&temp,1,instream);
171
+ destination->value[i] = (wchar_t)temp;
172
+ }
173
+ } else {
174
+ destination->value = 0;
175
+ }
176
+
177
+ return 1;
178
+ }
179
+
180
+
181
+ static int fread_nvt_triplet(nvt_triplet *destination, FILE *instream){
182
+
183
+ if (!(fread_AWSTRING(&(destination->name),instream)) ||
184
+ !(fread_ASTRING(&(destination->value),instream)) ||
185
+ !fread_AWSTRING(&(destination->type),instream)){
186
+ return 0;
187
+ }
188
+ return 1;
189
+ }
190
+
191
+
192
+ static int fread_nvts_triplet(col_nvts_triplet *destination, FILE *instream){
193
+
194
+ if (!(fread_AWSTRING(&(destination->name),instream)) ||
195
+ !(fread_be_uchar(&(destination->type), 1, instream)) ||
196
+ !(fread_be_int32(&(destination->size), 1, instream))){
197
+ return 0;
198
+ }
199
+ return 1;
200
+ }
201
+
202
+
203
+ /* The Value is MIME text/ASCII */
204
+
205
+ static char *decode_ASCII(ASTRING value){
206
+
207
+ char *return_value;
208
+
209
+ return_value = Calloc(value.len+1,char);
210
+
211
+ memcpy(return_value, value.value, value.len);
212
+
213
+
214
+ return return_value;
215
+ }
216
+
217
+
218
+
219
+ /* The value is MIME text/plain which means wchar (16bit) string */
220
+
221
+
222
+ static wchar_t *decode_TEXT(ASTRING value){
223
+
224
+ int i;
225
+
226
+ uint32_t len = value.len/ sizeof(uint16_t);
227
+ wchar_t* return_value = Calloc(len+1,wchar_t);
228
+ ASTRING temp;
229
+ uint16_t *contents;
230
+
231
+ temp.len = value.len;
232
+ temp.value = Calloc(value.len, char);
233
+ memcpy(temp.value, value.value,value.len);
234
+
235
+ contents = (uint16_t *)temp.value;
236
+
237
+ for (i=0; i < len; i++){
238
+ #ifndef WORDS_BIGENDIAN
239
+ contents[i]=(((contents[i]>>8)&0xff) | ((contents[i]&0xff)<<8));
240
+ #endif
241
+ return_value[i] = contents[i];
242
+ }
243
+ Free_ASTRING(&temp);
244
+
245
+ return return_value;
246
+ }
247
+
248
+
249
+ static int8_t decode_INT8_t(ASTRING value){
250
+
251
+ int8_t contents;
252
+
253
+ memcpy(&contents,value.value, sizeof(int8_t));
254
+
255
+ //#ifndef WORDS_BIGENDIAN
256
+ // contents=(((contents[i]>>8)&0xff) | ((contents[i]&0xff)<<8));//
257
+ //#endif
258
+
259
+
260
+ return contents;
261
+
262
+ }
263
+
264
+
265
+ static uint8_t decode_UINT8_t(ASTRING value){
266
+
267
+ uint8_t contents;
268
+
269
+ memcpy(&contents,value.value, sizeof(uint8_t));
270
+
271
+ //#ifndef WORDS_BIGENDIAN
272
+ //contents=(((contents[i]>>8)&0xff) | ((contents[i]&0xff)<<8));
273
+ //#endif
274
+ return contents;
275
+
276
+ }
277
+
278
+
279
+ static int16_t decode_INT16_t(ASTRING value){
280
+
281
+ int16_t contents;
282
+
283
+ memcpy(&contents,value.value, sizeof(int16_t));
284
+
285
+ #ifndef WORDS_BIGENDIAN
286
+ contents=(((contents>>8)&0xff) | ((contents&0xff)<<8));
287
+ #endif
288
+
289
+
290
+ return contents;
291
+
292
+ }
293
+
294
+
295
+ static uint16_t decode_UINT16_t(ASTRING value){
296
+
297
+ uint16_t contents;
298
+
299
+ memcpy(&contents,value.value, sizeof(uint16_t));
300
+
301
+ #ifndef WORDS_BIGENDIAN
302
+ contents=(((contents>>8)&0xff) | ((contents&0xff)<<8));
303
+ #endif
304
+ return contents;
305
+
306
+ }
307
+
308
+
309
+
310
+
311
+ static int32_t decode_INT32_t(ASTRING value){
312
+
313
+ int32_t contents;
314
+
315
+ memcpy(&contents,value.value, sizeof(int32_t));
316
+
317
+ #ifndef WORDS_BIGENDIAN
318
+ contents=(((contents>>24)&0xff) | ((contents&0xff)<<24) |
319
+ ((contents>>8)&0xff00) | ((contents&0xff00)<<8));
320
+ #endif
321
+
322
+
323
+ return contents;
324
+
325
+ }
326
+
327
+ static int32_t decode_UINT32_t(ASTRING value){
328
+
329
+ uint32_t contents;
330
+
331
+ memcpy(&contents,value.value, sizeof(uint32_t));
332
+
333
+ #ifndef WORDS_BIGENDIAN
334
+ contents=(((contents>>24)&0xff) | ((contents&0xff)<<24) |
335
+ ((contents>>8)&0xff00) | ((contents&0xff00)<<8));
336
+ #endif
337
+
338
+
339
+ return contents;
340
+
341
+ }
342
+
343
+ static float decode_float32(ASTRING value){
344
+
345
+
346
+ uint32_t contents;
347
+ float returnvalue;
348
+
349
+ memcpy(&contents,value.value, sizeof(uint32_t));
350
+
351
+ #ifndef WORDS_BIGENDIAN
352
+ contents=(((contents>>24)&0xff) | ((contents&0xff)<<24) |
353
+ ((contents>>8)&0xff00) | ((contents&0xff00)<<8));
354
+ #endif
355
+
356
+ memcpy(&returnvalue,&contents, sizeof(uint32_t));
357
+
358
+ return returnvalue;
359
+
360
+
361
+ }
362
+
363
+
364
+
365
+
366
+ AffyMIMEtypes determine_MIMETYPE(nvt_triplet triplet){
367
+ if (!wcscmp(triplet.type.value,L"text/x-calvin-float")){
368
+ return FLOAT32;
369
+ }
370
+
371
+ if (!wcscmp(triplet.type.value,L"text/plain")){
372
+ return PLAINTEXT;
373
+ }
374
+ if (!wcscmp(triplet.type.value,L"text/ascii")){
375
+ return ASCIITEXT;
376
+ }
377
+ if (!wcscmp(triplet.type.value,L"text/x-calvin-integer-32")){
378
+ return INT32;
379
+ }
380
+
381
+ if (!wcscmp(triplet.type.value,L"text/x-calvin-integer-16")){
382
+ return INT16;
383
+ }
384
+
385
+ if (!wcscmp(triplet.type.value,L"text/x-calvin-unsigned-integer-32")){
386
+ return UINT32;
387
+ }
388
+
389
+ if (!wcscmp(triplet.type.value,L"text/x-calvin-unsigned-integer-16")){
390
+ return INT16;
391
+ }
392
+
393
+ if (!wcscmp(triplet.type.value,L"text/x-calvin-integer-8")){
394
+ return INT8;
395
+ }
396
+ if (!wcscmp(triplet.type.value,L"text/x-calvin-unsigned-integer-8")){
397
+ return UINT8;
398
+ }
399
+ Rprintf("read_generic.c: Unknown MIME type encountered\n");
400
+
401
+ }
402
+
403
+
404
+
405
+
406
+
407
+
408
+ void *decode_MIME_value(nvt_triplet triplet, AffyMIMEtypes mimetype, void *result, int *size){
409
+
410
+ char *temp;
411
+ wchar_t *temp2;
412
+
413
+ if (mimetype == ASCIITEXT){
414
+ temp = decode_ASCII(triplet.value);
415
+ *size = strlen(temp);
416
+ result = temp;
417
+ return temp;
418
+ }
419
+
420
+ if (mimetype == PLAINTEXT){
421
+ temp2 = decode_TEXT(triplet.value);
422
+ *size = wcslen(temp2);
423
+ result = temp2;
424
+ return temp2;
425
+ }
426
+
427
+ if (mimetype == UINT8){
428
+ *size =1;
429
+ *(uint8_t *)result = decode_UINT8_t(triplet.value);
430
+ }
431
+
432
+ if (mimetype == INT8){
433
+ *size =1;
434
+ *(int8_t *)result = decode_INT8_t(triplet.value);
435
+ }
436
+
437
+ if (mimetype == UINT16){
438
+ *size =1;
439
+ *(uint16_t *)result = decode_UINT16_t(triplet.value);
440
+ }
441
+
442
+ if (mimetype == INT16){
443
+ *size =1;
444
+ *(int16_t *)result = decode_INT16_t(triplet.value);
445
+ }
446
+
447
+ if (mimetype == UINT32){
448
+ *size =1;
449
+ *(uint32_t *)result = decode_UINT32_t(triplet.value);
450
+ }
451
+
452
+ if (mimetype == INT32){
453
+ *size =1;
454
+ *(int32_t *)result = decode_INT32_t(triplet.value);
455
+ }
456
+
457
+ if (mimetype == FLOAT32){
458
+ *size =1;
459
+ *(float *)result = decode_float32(triplet.value);
460
+ }
461
+ return 0;
462
+ }
463
+
464
+
465
+
466
+ char *decode_MIME_value_toASCII(nvt_triplet triplet, AffyMIMEtypes mimetype, void *result, int *size){
467
+
468
+ char *temp;
469
+ wchar_t *temp2;
470
+
471
+
472
+ float temp_float;
473
+ uint8_t temp_uint8;
474
+ uint16_t temp_uint16;
475
+ uint32_t temp_uint32;
476
+ int8_t temp_int8;
477
+ int16_t temp_int16;
478
+ int32_t temp_int32;
479
+
480
+
481
+
482
+ if (mimetype == ASCIITEXT){
483
+ temp = decode_ASCII(triplet.value);
484
+ *size = strlen(temp);
485
+ result = temp;
486
+ return temp;
487
+ }
488
+
489
+ if (mimetype == PLAINTEXT){
490
+ temp2 = decode_TEXT(triplet.value);
491
+ temp = Calloc(triplet.value.len/2 +1, char);
492
+ wcstombs(temp,temp2,triplet.value.len/2 + 1);
493
+ *size = strlen(temp);
494
+ result = temp;
495
+ return temp;
496
+ }
497
+
498
+
499
+ /* 64 here is a bit hackish */
500
+ temp = Calloc(64,char);
501
+ if (mimetype == UINT8){
502
+ temp_uint8 = decode_UINT8_t(triplet.value);
503
+ sprintf(temp,"%u",temp_uint8);
504
+ *size = strlen(temp);
505
+ result = temp;
506
+ return temp;
507
+ }
508
+
509
+ if (mimetype == INT8){
510
+ temp_int8 = decode_INT8_t(triplet.value);
511
+ sprintf(temp,"%d",temp_int8);
512
+ *size = strlen(temp);
513
+ result = temp;
514
+ return temp;
515
+ }
516
+
517
+ if (mimetype == UINT16){
518
+ temp_uint16 = decode_UINT16_t(triplet.value);
519
+ sprintf(temp,"%u",temp_uint16);
520
+ *size = strlen(temp);
521
+ result = temp;
522
+ return temp;
523
+ }
524
+
525
+ if (mimetype == INT16){
526
+ temp_int16 = decode_INT16_t(triplet.value);
527
+ sprintf(temp,"%d",temp_int16);
528
+ *size = strlen(temp);
529
+ result = temp;
530
+ return temp;
531
+ }
532
+
533
+ if (mimetype == UINT32){
534
+ temp_uint32 = decode_UINT32_t(triplet.value);
535
+ sprintf(temp,"%u",temp_uint32);
536
+ *size = strlen(temp);
537
+ result = temp;
538
+ return temp;
539
+ }
540
+
541
+ if (mimetype == INT32){
542
+ temp_int32 = decode_INT32_t(triplet.value);
543
+ sprintf(temp,"%d",temp_int32);
544
+ *size = strlen(temp);
545
+ result = temp;
546
+ return temp;
547
+ }
548
+
549
+ if (mimetype == FLOAT32){
550
+ temp_float = decode_float32(triplet.value);
551
+ sprintf(temp,"%f",temp_float);
552
+ *size = strlen(temp);
553
+ result = temp;
554
+ return temp;
555
+ }
556
+ return 0;
557
+ }
558
+
559
+
560
+
561
+
562
+
563
+
564
+
565
+
566
+
567
+
568
+
569
+
570
+
571
+
572
+
573
+
574
+
575
+
576
+
577
+
578
+
579
+ nvt_triplet* find_nvt(generic_data_header *data_header,char *name){
580
+
581
+ nvt_triplet* returnvalue = 0;
582
+
583
+ wchar_t *wname;
584
+ int i;
585
+
586
+ int len = strlen(name);
587
+
588
+
589
+
590
+ wname = Calloc(len+1, wchar_t);
591
+
592
+
593
+ mbstowcs(wname, name, len);
594
+
595
+ for (i =0; i < data_header->n_name_type_value; i++){
596
+ if (wcscmp(wname, data_header->name_type_value[i].name.value) == 0){
597
+ returnvalue = &(data_header->name_type_value[i]);
598
+ break;
599
+ }
600
+ }
601
+
602
+ if (returnvalue == 0){
603
+ for (i =0; i < data_header->n_parent_headers; i++){
604
+ returnvalue = find_nvt((generic_data_header *)(data_header->parent_headers)[i],name);
605
+ if (returnvalue !=0){
606
+ break;
607
+ }
608
+ }
609
+ }
610
+
611
+ Free(wname);
612
+ return returnvalue;
613
+ }
614
+
615
+
616
+
617
+ int read_generic_file_header(generic_file_header* file_header, FILE *instream){
618
+
619
+ if (!fread_be_uchar(&(file_header->magic_number),1,instream)){
620
+ return 0;
621
+ }
622
+ if (file_header->magic_number != 59){
623
+ return 0;
624
+ }
625
+
626
+ if (!fread_be_uchar(&(file_header->version),1,instream)){
627
+ return 0;
628
+ }
629
+
630
+ if (file_header->version != 1){
631
+ return 0;
632
+ }
633
+
634
+ if (!fread_be_int32(&(file_header->n_data_groups),1,instream) ||
635
+ !fread_be_uint32(&(file_header->first_group_file_pos),1,instream)){
636
+ return 0;
637
+ }
638
+
639
+ return 1;
640
+ }
641
+
642
+
643
+
644
+
645
+
646
+ int read_generic_data_header(generic_data_header *data_header, FILE *instream){
647
+
648
+ int i;
649
+ generic_data_header *temp_header;
650
+
651
+
652
+ if (!fread_ASTRING(&(data_header->data_type_id), instream) ||
653
+ !fread_ASTRING(&(data_header->unique_file_id), instream) ||
654
+ !fread_AWSTRING(&(data_header->Date_time), instream) ||
655
+ !fread_AWSTRING(&(data_header->locale),instream)){
656
+ return 0;
657
+ }
658
+
659
+ if (!fread_be_int32(&(data_header->n_name_type_value),1,instream)){
660
+ return 0;
661
+ }
662
+
663
+ data_header->name_type_value = Calloc(data_header->n_name_type_value, nvt_triplet);
664
+
665
+ for (i =0; i < data_header->n_name_type_value; i++){
666
+ if (!fread_nvt_triplet(&data_header->name_type_value[i],instream)){
667
+ return 0;
668
+ }
669
+ }
670
+
671
+ if (!fread_be_int32(&(data_header->n_parent_headers),1,instream)){
672
+ return 0;
673
+ }
674
+
675
+ if (data_header->n_parent_headers > 0){
676
+ data_header->parent_headers = Calloc(data_header->n_parent_headers,void *);
677
+ } else {
678
+ data_header->parent_headers = 0;
679
+ }
680
+ for (i =0; i < data_header->n_parent_headers; i++){
681
+ temp_header = (generic_data_header *)Calloc(1,generic_data_header);
682
+ if (!read_generic_data_header(temp_header,instream)){
683
+ return 0;
684
+ }
685
+ data_header->parent_headers[i] = temp_header;
686
+ }
687
+ return 1;
688
+ }
689
+
690
+
691
+
692
+ int read_generic_data_group(generic_data_group *data_group, FILE *instream){
693
+
694
+ if (!fread_be_uint32(&(data_group->file_position_nextgroup),1,instream) ||
695
+ !fread_be_uint32(&(data_group->file_position_first_data),1,instream) ||
696
+ !fread_be_int32(&(data_group->n_data_sets),1,instream) ||
697
+ !fread_AWSTRING(&(data_group->data_group_name), instream)){
698
+ return 0;
699
+ }
700
+ return 1;
701
+
702
+ }
703
+
704
+
705
+
706
+ int read_generic_data_set(generic_data_set *data_set, FILE *instream){
707
+
708
+ int i;
709
+
710
+ if (!fread_be_uint32(&(data_set->file_pos_first),1,instream) ||
711
+ !fread_be_uint32(&(data_set->file_pos_last),1,instream) ||
712
+ !fread_AWSTRING(&(data_set->data_set_name), instream) ||
713
+ !fread_be_int32(&(data_set->n_name_type_value),1,instream)){
714
+ return 0;
715
+ }
716
+
717
+
718
+ data_set->name_type_value = Calloc(data_set->n_name_type_value, nvt_triplet);
719
+
720
+ for (i =0; i < data_set->n_name_type_value; i++){
721
+ if (!fread_nvt_triplet(&data_set->name_type_value[i],instream)){
722
+ return 0;
723
+ }
724
+ }
725
+
726
+ if (!fread_be_uint32(&(data_set->ncols),1,instream)){
727
+ return 0;
728
+ }
729
+
730
+ data_set->col_name_type_value = Calloc(data_set->ncols,col_nvts_triplet);
731
+
732
+ for (i =0; i < data_set->ncols; i++){
733
+ if (!fread_nvts_triplet(&data_set->col_name_type_value[i], instream)){
734
+ return 0;
735
+ }
736
+ }
737
+
738
+ if (!fread_be_uint32(&(data_set->nrows),1,instream)){
739
+ return 0;
740
+ }
741
+
742
+ data_set->Data = Calloc(data_set->ncols, void *);
743
+
744
+ for (i=0; i < data_set->ncols; i++){
745
+ switch(data_set->col_name_type_value[i].type){
746
+ case 0: data_set->Data[i] = Calloc(data_set->nrows,char);
747
+ break;
748
+ case 1: data_set->Data[i] = Calloc(data_set->nrows,unsigned char);
749
+ break;
750
+ case 2: data_set->Data[i] = Calloc(data_set->nrows,short);
751
+ break;
752
+ case 3: data_set->Data[i] = Calloc(data_set->nrows,unsigned short);
753
+ break;
754
+ case 4: data_set->Data[i] = Calloc(data_set->nrows,int);
755
+ break;
756
+ case 5: data_set->Data[i] = Calloc(data_set->nrows,unsigned int);
757
+ break;
758
+ case 6: data_set->Data[i] = Calloc(data_set->nrows,float);
759
+ break;
760
+ case 7: data_set->Data[i] = Calloc(data_set->nrows,double);
761
+ break;
762
+ case 8: data_set->Data[i] = Calloc(data_set->nrows,ASTRING);
763
+ break;
764
+ case 9: data_set->Data[i] = Calloc(data_set->nrows,AWSTRING);
765
+ break;
766
+ }
767
+
768
+ }
769
+ return 1;
770
+ }
771
+
772
+
773
+ int read_generic_data_set_rows(generic_data_set *data_set, FILE *instream){
774
+
775
+ int i,j;
776
+
777
+ for (i=0; i < data_set->nrows; i++){
778
+ for (j=0; j < data_set->ncols; j++){
779
+ switch(data_set->col_name_type_value[j].type){
780
+ case 0:
781
+ if (!fread_be_char(&((char *)data_set->Data[j])[i],1,instream)){
782
+ return 0;
783
+ }
784
+ break;
785
+ case 1:
786
+ if (!fread_be_uchar(&((unsigned char *)data_set->Data[j])[i],1,instream)){
787
+ return 0;
788
+ }
789
+ break;
790
+ case 2:
791
+ if (!fread_be_int16(&((short *)data_set->Data[j])[i],1,instream)){
792
+ return 0;
793
+ }
794
+ break;
795
+ case 3:
796
+ if (!fread_be_uint16(&((unsigned short *)data_set->Data[j])[i],1,instream)){
797
+ return 0;
798
+ }
799
+ break;
800
+ case 4:
801
+ if (!fread_be_int32(&((int32_t *)data_set->Data[j])[i],1,instream)){
802
+ return 0;
803
+ }
804
+ break;
805
+ case 5:
806
+ if (!fread_be_uint32(&((uint32_t *)data_set->Data[j])[i],1,instream)){
807
+ return 0;
808
+ }
809
+ break;
810
+ case 6:
811
+ if (!fread_be_float32(&((float *)data_set->Data[j])[i],1,instream)){
812
+ return 0;
813
+ }
814
+ break;
815
+ case 7:
816
+ if (!fread_be_double64(&((double *)data_set->Data[j])[i],1,instream)){
817
+ return 0;
818
+ }
819
+ break;
820
+ case 8:
821
+ if (!fread_ASTRING(&((ASTRING *)data_set->Data[j])[i], instream)){
822
+ return 0;
823
+ }
824
+ break;
825
+ case 9:
826
+ if (!fread_AWSTRING(&((AWSTRING *)data_set->Data[j])[i], instream)){
827
+ return 0;
828
+ };
829
+ break;
830
+ }
831
+ }
832
+ }
833
+ return 1;
834
+ }
835
+
836
+
837
+
838
+
839
+ /*****************************************************************************
840
+ **
841
+ **
842
+ ** Functionality for reading a generic format file which has been gzipped
843
+ **
844
+ **
845
+ *****************************************************************************/
846
+
847
+
848
+
849
+ static int gzread_ASTRING(ASTRING *destination, gzFile *instream){
850
+
851
+ gzread_be_int32(&(destination->len),1,instream);
852
+ if (destination->len > 0){
853
+ destination->value = Calloc(destination->len+1,char);
854
+ gzread_be_char(destination->value,destination->len,instream);
855
+ } else {
856
+ destination->value = 0;
857
+ }
858
+ return 1;
859
+ }
860
+
861
+
862
+
863
+ static int gzread_AWSTRING(AWSTRING *destination, gzFile *instream){
864
+
865
+ uint16_t temp; /* Affy file wchar_t are 16 bits, the platform may have 32 bit wchar_t (notatbly linux) */
866
+
867
+ int i;
868
+
869
+ gzread_be_int32(&(destination->len),1,instream);
870
+ if ((destination->len) > 0){
871
+ destination->value = Calloc(destination->len+1,wchar_t);
872
+
873
+ for (i=0; i < destination->len; i++){
874
+ gzread_be_uint16(&temp,1,instream);
875
+ destination->value[i] = (wchar_t)temp;
876
+ }
877
+ } else {
878
+ destination->value = 0;
879
+ }
880
+
881
+ return 1;
882
+ }
883
+
884
+
885
+ static int gzread_nvt_triplet(nvt_triplet *destination, gzFile *instream){
886
+
887
+ if (!(gzread_AWSTRING(&(destination->name),instream)) ||
888
+ !(gzread_ASTRING(&(destination->value),instream)) ||
889
+ !(gzread_AWSTRING(&(destination->type),instream))){
890
+ return 0;
891
+ }
892
+ return 1;
893
+ }
894
+
895
+
896
+
897
+ static int gzread_nvts_triplet(col_nvts_triplet *destination, gzFile *instream){
898
+
899
+ if (!(gzread_AWSTRING(&(destination->name),instream)) ||
900
+ !(gzread_be_uchar(&(destination->type), 1, instream)) ||
901
+ !(gzread_be_int32(&(destination->size), 1, instream))){
902
+ return 0;
903
+ }
904
+ return 1;
905
+ }
906
+
907
+
908
+ int gzread_generic_file_header(generic_file_header* file_header, gzFile *instream){
909
+
910
+ if (!gzread_be_uchar(&(file_header->magic_number),1,instream)){
911
+ return 0;
912
+ }
913
+ if (file_header->magic_number != 59){
914
+ return 0;
915
+ }
916
+
917
+ if (!gzread_be_uchar(&(file_header->version),1,instream)){
918
+ return 0;
919
+ }
920
+
921
+ if (file_header->version != 1){
922
+ return 0;
923
+ }
924
+
925
+ if (!gzread_be_int32(&(file_header->n_data_groups),1,instream) ||
926
+ !gzread_be_uint32(&(file_header->first_group_file_pos),1,instream)){
927
+ return 0;
928
+ }
929
+
930
+ return 1;
931
+ }
932
+
933
+
934
+
935
+
936
+ int gzread_generic_data_header(generic_data_header *data_header, gzFile *instream){
937
+
938
+ int i;
939
+
940
+ if (!gzread_ASTRING(&(data_header->data_type_id), instream) ||
941
+ !gzread_ASTRING(&(data_header->unique_file_id), instream) ||
942
+ !gzread_AWSTRING(&(data_header->Date_time), instream) ||
943
+ !gzread_AWSTRING(&(data_header->locale),instream)){
944
+ return 0;
945
+ }
946
+
947
+ if (!gzread_be_int32(&(data_header->n_name_type_value),1,instream)){
948
+ return 0;
949
+ }
950
+
951
+ data_header->name_type_value = Calloc(data_header->n_name_type_value, nvt_triplet);
952
+
953
+ for (i =0; i < data_header->n_name_type_value; i++){
954
+ if (!gzread_nvt_triplet(&data_header->name_type_value[i],instream)){
955
+ return 0;
956
+ }
957
+ }
958
+
959
+ if (!gzread_be_int32(&(data_header->n_parent_headers),1,instream)){
960
+ return 0;
961
+ }
962
+
963
+ data_header->parent_headers = Calloc(data_header->n_parent_headers,void *);
964
+
965
+ for (i =0; i < data_header->n_parent_headers; i++){
966
+ data_header->parent_headers[i] = (generic_data_header *)Calloc(1,generic_data_header);
967
+ if (!gzread_generic_data_header((generic_data_header *)data_header->parent_headers[i],instream)){
968
+ return 0;
969
+ }
970
+ }
971
+ return 1;
972
+ }
973
+
974
+
975
+
976
+
977
+
978
+ int gzread_generic_data_group(generic_data_group *data_group, gzFile *instream){
979
+
980
+ if (!gzread_be_uint32(&(data_group->file_position_nextgroup),1,instream) ||
981
+ !gzread_be_uint32(&(data_group->file_position_first_data),1,instream) ||
982
+ !gzread_be_int32(&(data_group->n_data_sets),1,instream) ||
983
+ !gzread_AWSTRING(&(data_group->data_group_name), instream)){
984
+ return 0;
985
+ }
986
+ return 1;
987
+
988
+ }
989
+
990
+
991
+
992
+
993
+
994
+ int gzread_generic_data_set(generic_data_set *data_set, gzFile *instream){
995
+
996
+ int i;
997
+
998
+ if (!gzread_be_uint32(&(data_set->file_pos_first),1,instream) ||
999
+ !gzread_be_uint32(&(data_set->file_pos_last),1,instream) ||
1000
+ !gzread_AWSTRING(&(data_set->data_set_name), instream) ||
1001
+ !gzread_be_int32(&(data_set->n_name_type_value),1,instream)){
1002
+ return 0;
1003
+ }
1004
+
1005
+
1006
+ data_set->name_type_value = Calloc(data_set->n_name_type_value, nvt_triplet);
1007
+
1008
+ for (i =0; i < data_set->n_name_type_value; i++){
1009
+ if (!gzread_nvt_triplet(&data_set->name_type_value[i],instream)){
1010
+ return 0;
1011
+ }
1012
+ }
1013
+
1014
+ if (!gzread_be_uint32(&(data_set->ncols),1,instream)){
1015
+ return 0;
1016
+ }
1017
+
1018
+ data_set->col_name_type_value = Calloc(data_set->ncols,col_nvts_triplet);
1019
+
1020
+ for (i =0; i < data_set->ncols; i++){
1021
+ if (!gzread_nvts_triplet(&data_set->col_name_type_value[i], instream)){
1022
+ return 0;
1023
+ }
1024
+ }
1025
+
1026
+ if (!gzread_be_uint32(&(data_set->nrows),1,instream)){
1027
+ return 0;
1028
+ }
1029
+
1030
+ data_set->Data = Calloc(data_set->ncols, void *);
1031
+
1032
+ for (i=0; i < data_set->ncols; i++){
1033
+ switch(data_set->col_name_type_value[i].type){
1034
+ case 0: data_set->Data[i] = Calloc(data_set->nrows,char);
1035
+ break;
1036
+ case 1: data_set->Data[i] = Calloc(data_set->nrows,unsigned char);
1037
+ break;
1038
+ case 2: data_set->Data[i] = Calloc(data_set->nrows,short);
1039
+ break;
1040
+ case 3: data_set->Data[i] = Calloc(data_set->nrows,unsigned short);
1041
+ break;
1042
+ case 4: data_set->Data[i] = Calloc(data_set->nrows,int);
1043
+ break;
1044
+ case 5: data_set->Data[i] = Calloc(data_set->nrows,unsigned int);
1045
+ break;
1046
+ case 6: data_set->Data[i] = Calloc(data_set->nrows,float);
1047
+ break;
1048
+ case 7: data_set->Data[i] = Calloc(data_set->nrows,double);
1049
+ break;
1050
+ case 8: data_set->Data[i] = Calloc(data_set->nrows,ASTRING);
1051
+ break;
1052
+ case 9: data_set->Data[i] = Calloc(data_set->nrows,AWSTRING);
1053
+ break;
1054
+ }
1055
+
1056
+ }
1057
+ return 1;
1058
+ }
1059
+
1060
+
1061
+
1062
+
1063
+ int gzread_generic_data_set_rows(generic_data_set *data_set, gzFile *instream){
1064
+
1065
+ int i,j;
1066
+
1067
+ for (i=0; i < data_set->nrows; i++){
1068
+ for (j=0; j < data_set->ncols; j++){
1069
+ switch(data_set->col_name_type_value[j].type){
1070
+ case 0:
1071
+ if (!gzread_be_char(&((char *)data_set->Data[j])[i],1,instream)){
1072
+ return 0;
1073
+ }
1074
+ break;
1075
+ case 1:
1076
+ if (!gzread_be_uchar(&((unsigned char *)data_set->Data[j])[i],1,instream)){
1077
+ return 0;
1078
+ }
1079
+ break;
1080
+ case 2:
1081
+ if (!gzread_be_int16(&((short *)data_set->Data[j])[i],1,instream)){
1082
+ return 0;
1083
+ }
1084
+ break;
1085
+ case 3:
1086
+ if (!gzread_be_uint16(&((unsigned short *)data_set->Data[j])[i],1,instream)){
1087
+ return 0;
1088
+ }
1089
+ break;
1090
+ case 4:
1091
+ if (!gzread_be_int32(&((int32_t *)data_set->Data[j])[i],1,instream)){
1092
+ return 0;
1093
+ }
1094
+ break;
1095
+ case 5:
1096
+ if (!gzread_be_uint32(&((uint32_t *)data_set->Data[j])[i],1,instream)){
1097
+ return 0;
1098
+ }
1099
+ break;
1100
+ case 6:
1101
+ if (!gzread_be_float32(&((float *)data_set->Data[j])[i],1,instream)){
1102
+ return 0;
1103
+ }
1104
+ break;
1105
+ case 7:
1106
+ if (!gzread_be_double64(&((double *)data_set->Data[j])[i],1,instream)){
1107
+ return 0;
1108
+ }
1109
+ break;
1110
+ case 8:
1111
+ if (!gzread_ASTRING(&((ASTRING *)data_set->Data[j])[i], instream)){
1112
+ return 0;
1113
+ }
1114
+ break;
1115
+ case 9:
1116
+ if (!gzread_AWSTRING(&((AWSTRING *)data_set->Data[j])[i], instream)){
1117
+ return 0;
1118
+ };
1119
+ break;
1120
+ }
1121
+ }
1122
+ }
1123
+ return 1;
1124
+ }
1125
+
1126
+
1127
+
1128
+
1129
+
1130
+
1131
+ /*****************************************************************************
1132
+ **
1133
+ ** TESTING FUNCTIONS
1134
+ **
1135
+ **
1136
+ **
1137
+ **
1138
+ ** The following functions are for testing purposes only they print contents
1139
+ ** of the generic format file to the screen
1140
+ **
1141
+ ******************************************************************************/
1142
+
1143
+
1144
+ static void print_file_header(generic_file_header header){
1145
+ Rprintf("%d\n",header.magic_number);
1146
+ Rprintf("%d\n",header.version);
1147
+ Rprintf("%d\n",header.n_data_groups);
1148
+ Rprintf("%d\n",header.first_group_file_pos);
1149
+ }
1150
+
1151
+
1152
+ static void print_ASTRING(ASTRING string){
1153
+ if (string.len > 0){
1154
+ Rprintf("%s",string.value);
1155
+ }
1156
+ }
1157
+
1158
+
1159
+ static void print_AWSTRING(AWSTRING string){
1160
+ if (string.len > 0){
1161
+ char *temp = Calloc(string.len+1,char);
1162
+ wcstombs(temp, string.value, string.len);
1163
+
1164
+ Rprintf("%s",temp);
1165
+
1166
+
1167
+ Free(temp);
1168
+ }
1169
+ }
1170
+
1171
+ static void print_decode_nvt_triplet(nvt_triplet triplet){
1172
+
1173
+ wchar_t *temp;
1174
+ char *temp2;
1175
+ // char Buffer[10000];
1176
+ int size;
1177
+
1178
+ int temp32;
1179
+ float tempfloat;
1180
+
1181
+
1182
+ // Rprintf("Size is %d\n",triplet.value.len);
1183
+ if (!wcscmp(triplet.type.value,L"text/x-calvin-float")){
1184
+ Rprintf("Its a float value is %f\n",decode_float32(triplet.value));
1185
+
1186
+ Rprintf("Now Trying it again. But using exposed function\n");
1187
+ decode_MIME_value(triplet, determine_MIMETYPE(triplet),&tempfloat,&size);
1188
+ Rprintf("Its a float value is %f\n",temp32);
1189
+ }
1190
+
1191
+ if (!wcscmp(triplet.type.value,L"text/ascii")){
1192
+ temp2 = decode_ASCII(triplet.value);
1193
+ Rprintf("Its a Ascii String value is %s\n",temp2);
1194
+ Free(temp2);
1195
+
1196
+ Rprintf("Now Trying it again. But using exposed function\n");
1197
+ temp2 = decode_MIME_value(triplet, determine_MIMETYPE(triplet),temp2,&size);
1198
+ Rprintf("Its a Ascii String value is %s with size %d\n",temp2, size);
1199
+ Free(temp2);
1200
+ }
1201
+
1202
+ if (!wcscmp(triplet.type.value,L"text/plain")){
1203
+ temp = decode_TEXT(triplet.value);
1204
+ temp2 = Calloc(triplet.value.len/2 +1, char);
1205
+ wcstombs(temp2,temp,triplet.value.len/2 + 1);
1206
+ Rprintf("Text/plain String is %s\n",temp2);
1207
+ Free(temp);
1208
+ Free(temp2);
1209
+
1210
+ Rprintf("Now Trying it again. But using exposed function\n");
1211
+
1212
+ temp = (wchar_t *)decode_MIME_value(triplet, determine_MIMETYPE(triplet),temp,&size);
1213
+ temp2 = Calloc(size +1, char);
1214
+ wcstombs(temp2,temp,size);
1215
+ Rprintf("Its a Text/plain string value is %s with size %d\n",temp2, size);
1216
+ Free(temp2);
1217
+ Free(temp);
1218
+ }
1219
+
1220
+ if (!wcscmp(triplet.type.value,L"text/x-calvin-integer-32")){
1221
+ Rprintf("Its a int32_t value is %d\n",decode_INT32_t(triplet.value));
1222
+
1223
+ Rprintf("Now Trying it again. But using exposed function\n");
1224
+
1225
+ decode_MIME_value(triplet, determine_MIMETYPE(triplet),&temp32,&size);
1226
+ Rprintf("Its a int32_t value is %d\n",temp32);
1227
+
1228
+ }
1229
+
1230
+ if (!wcscmp(triplet.type.value,L"text/x-calvin-integer-16")){
1231
+ Rprintf("Its a int16_t value is %d\n",decode_INT16_t(triplet.value));
1232
+ }
1233
+
1234
+ if (!wcscmp(triplet.type.value,L"text/x-calvin-unsigned-integer-32")){
1235
+ Rprintf("Its a uint32_t value is %d\n",decode_UINT32_t(triplet.value));
1236
+ }
1237
+
1238
+ if (!wcscmp(triplet.type.value,L"text/x-calvin-unsigned-integer-16")){
1239
+ Rprintf("Its a uint16_t value is %d\n",decode_UINT16_t(triplet.value));
1240
+ }
1241
+
1242
+ if (!wcscmp(triplet.type.value,L"text/x-calvin-integer-8")){
1243
+ Rprintf("Its a int8_t value is %d\n",decode_UINT8_t(triplet.value));
1244
+ }
1245
+ if (!wcscmp(triplet.type.value,L"text/x-calvin-unsigned-integer-8")){
1246
+ Rprintf("Its a uint8_t value is %d\n",decode_UINT8_t(triplet.value));
1247
+ }
1248
+
1249
+
1250
+
1251
+
1252
+
1253
+
1254
+ }
1255
+
1256
+
1257
+ static void print_nvt_triplet(nvt_triplet triplet){
1258
+
1259
+ print_AWSTRING(triplet.name);
1260
+ Rprintf(" ");
1261
+ // print_ASTRING(triplet.value);
1262
+ //Rprintf(" ");
1263
+ print_AWSTRING(triplet.type);
1264
+ //Rprintf("\n");
1265
+ print_decode_nvt_triplet(triplet);
1266
+ }
1267
+
1268
+ static void print_col_nvts_triplet(col_nvts_triplet triplet){
1269
+
1270
+ print_AWSTRING(triplet.name);
1271
+ Rprintf(" %d %d", triplet.type, triplet.size);
1272
+ Rprintf("\n");
1273
+ }
1274
+
1275
+ static void print_generic_header(generic_data_header header){
1276
+
1277
+ int i;
1278
+
1279
+ print_ASTRING(header.data_type_id);
1280
+ Rprintf("\n");
1281
+ print_ASTRING(header.unique_file_id);
1282
+ Rprintf("\n");
1283
+ print_AWSTRING(header.Date_time);
1284
+ Rprintf("\n");
1285
+ print_AWSTRING(header.locale);
1286
+ Rprintf("\n");
1287
+ Rprintf("%d\n", header.n_name_type_value);
1288
+
1289
+ for (i=0; i < header.n_name_type_value; i++){
1290
+ print_nvt_triplet(header.name_type_value[i]);
1291
+
1292
+ }
1293
+
1294
+ Rprintf("%d\n",header.n_parent_headers);
1295
+ if (header.n_parent_headers > 0){
1296
+ Rprintf("Printing Parental Headers\n");
1297
+ for (i =0; i < header.n_parent_headers; i++){
1298
+ print_generic_header(*(generic_data_header *)header.parent_headers[i]);
1299
+ }
1300
+ }
1301
+ }
1302
+
1303
+
1304
+ static void print_generic_data_group(generic_data_group data_group){
1305
+
1306
+ Rprintf("%d\n",data_group.file_position_nextgroup);
1307
+ Rprintf("%d\n",data_group.file_position_first_data);
1308
+ Rprintf("%d\n",data_group.n_data_sets);
1309
+ print_AWSTRING(data_group.data_group_name);
1310
+ Rprintf("\n");
1311
+ }
1312
+
1313
+
1314
+ static void print_generic_data_set(generic_data_set data_set){
1315
+ int i;
1316
+
1317
+ Rprintf("%d\n%d\n",data_set.file_pos_first,data_set.file_pos_last);
1318
+
1319
+ print_AWSTRING(data_set.data_set_name);
1320
+ Rprintf("\n");
1321
+ printf("%d\n",data_set.n_name_type_value);
1322
+
1323
+ for (i=0; i < data_set.n_name_type_value; i++){
1324
+ print_nvt_triplet(data_set.name_type_value[i]);
1325
+ }
1326
+
1327
+ printf("%d\n",data_set.ncols);
1328
+
1329
+ for (i=0; i < data_set.ncols; i++){
1330
+ print_col_nvts_triplet(data_set.col_name_type_value[i]);
1331
+ }
1332
+ Rprintf("%d\n",data_set.nrows);
1333
+ }
1334
+
1335
+
1336
+
1337
+ SEXP Read_Generic(SEXP filename){
1338
+
1339
+ int i,j;
1340
+
1341
+ SEXP return_value = R_NilValue;
1342
+
1343
+ FILE *infile;
1344
+
1345
+ generic_file_header my_header;
1346
+ generic_data_header my_data_header;
1347
+ generic_data_group my_data_group;
1348
+
1349
+ generic_data_set my_data_set;
1350
+
1351
+ const char *cur_file_name = CHAR(STRING_ELT(filename,0));
1352
+
1353
+ /* Pass through all the header information */
1354
+
1355
+ if ((infile = fopen(cur_file_name, "rb")) == NULL)
1356
+ {
1357
+ error("Unable to open the file %s\n",cur_file_name);
1358
+ return 0;
1359
+ }
1360
+
1361
+
1362
+
1363
+ read_generic_file_header(&my_header, infile);
1364
+ read_generic_data_header(&my_data_header, infile);
1365
+ read_generic_data_group(&my_data_group,infile);
1366
+ // read_generic_data_set(&my_data_set,infile);
1367
+ //read_generic_data_set_rows(&my_data_set,infile);
1368
+
1369
+ print_file_header(my_header);
1370
+ print_generic_header(my_data_header);
1371
+ print_generic_data_group(my_data_group);
1372
+ for (j=0; j < my_data_group.n_data_sets; j++){
1373
+ read_generic_data_set(&my_data_set,infile);
1374
+ print_generic_data_set(my_data_set);
1375
+ read_generic_data_set_rows(&my_data_set,infile);
1376
+ for (i =0; i < 1 ; i++){
1377
+ //printf("%f\n",((float *)my_data_set.Data[0])[i]);
1378
+ }
1379
+ // Free_generic_data_set(&my_data_set);
1380
+ fseek(infile, my_data_set.file_pos_last, SEEK_SET);
1381
+ Free_generic_data_set(&my_data_set);
1382
+ }
1383
+
1384
+ Free_generic_data_header(&my_data_header);
1385
+ Free_generic_data_group(&my_data_group);
1386
+
1387
+
1388
+ return return_value;
1389
+
1390
+ }
1391
+
1392
+
1393
+ SEXP gzRead_Generic(SEXP filename){
1394
+
1395
+ int i,j;
1396
+
1397
+ SEXP return_value = R_NilValue;
1398
+
1399
+ gzFile *infile;
1400
+
1401
+ generic_file_header my_header;
1402
+ generic_data_header my_data_header;
1403
+ generic_data_group my_data_group;
1404
+
1405
+ generic_data_set my_data_set;
1406
+
1407
+ const char *cur_file_name = CHAR(STRING_ELT(filename,0));
1408
+
1409
+ /* Pass through all the header information */
1410
+
1411
+ if ((infile = gzopen(cur_file_name, "rb")) == NULL)
1412
+ {
1413
+ error("Unable to open the file %s\n",cur_file_name);
1414
+ return 0;
1415
+ }
1416
+
1417
+
1418
+
1419
+ gzread_generic_file_header(&my_header, infile);
1420
+ gzread_generic_data_header(&my_data_header, infile);
1421
+ gzread_generic_data_group(&my_data_group,infile);
1422
+ // read_generic_data_set(&my_data_set,infile);
1423
+ //read_generic_data_set_rows(&my_data_set,infile);
1424
+
1425
+ print_file_header(my_header);
1426
+ print_generic_header(my_data_header);
1427
+ print_generic_data_group(my_data_group);
1428
+ for (j=0; j < my_data_group.n_data_sets; j++){
1429
+ gzread_generic_data_set(&my_data_set,infile);
1430
+ print_generic_data_set(my_data_set);
1431
+ gzread_generic_data_set_rows(&my_data_set,infile);
1432
+ for (i =0; i < 1 ; i++){
1433
+ //printf("%f\n",((float *)my_data_set.Data[0])[i]);
1434
+ }
1435
+ // Free_generic_data_set(&my_data_set);
1436
+ gzseek(infile, my_data_set.file_pos_last, SEEK_SET);
1437
+ Free_generic_data_set(&my_data_set);
1438
+ }
1439
+
1440
+ Free_generic_data_header(&my_data_header);
1441
+ Free_generic_data_group(&my_data_group);
1442
+
1443
+
1444
+ return return_value;
1445
+
1446
+ }