-
Notifications
You must be signed in to change notification settings - Fork 1
/
Read_VIIRS_SVI03.c
1198 lines (908 loc) · 39.1 KB
/
Read_VIIRS_SVI03.c
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <hdf5.h>
#include <hdf5_hl.h>
#define IMGSVFILE "SVI03_j01_d20190715_t1619591_e1621236_b08574_c20190715163933855645_cspp_dev.h5" // CSPP SDR 3.*
#define IMGSVGRP "All_Data/VIIRS-I3-SDR_All/"
int main(void){
/*************************
* Common Declarations *
*************************/
hid_t fileID, dsetID, dspaceID; /* Handles */
hid_t dTypeID;
herr_t status;
hsize_t dimSize[2];
char dsetName[100];
int rank,i,j,nRows,nCols;
int typeIdx;
htri_t H5_NativeTypes[18] = {
H5T_NATIVE_CHAR , // char
H5T_NATIVE_SCHAR , // signed char
H5T_NATIVE_UCHAR , // unsigned char
H5T_NATIVE_SHORT , // short
H5T_NATIVE_USHORT , // unsigned short
H5T_NATIVE_INT , // int
H5T_NATIVE_UINT , // unsigned
H5T_NATIVE_LONG , // long
H5T_NATIVE_ULONG , // unsigned long
H5T_NATIVE_LLONG , // long long
H5T_NATIVE_ULLONG , // unsigned long long
H5T_NATIVE_FLOAT , // float
H5T_NATIVE_DOUBLE , // double
H5T_NATIVE_LDOUBLE , // long double
H5T_NATIVE_HSIZE , // hsize_t
H5T_NATIVE_HSSIZE , // hssize_t
H5T_NATIVE_HERR , // herr_t
H5T_NATIVE_HBOOL // hbool_t
};
/*htri_t nativeType;*/
// Walk through the types and get their descriptions.
char *str;
size_t len;
typeIdx=0;
for (typeIdx=0;typeIdx<18;typeIdx++){
status = H5LTdtype_to_text(H5_NativeTypes[typeIdx], NULL, H5LT_DDL, &len);
str = (char *) malloc(len * sizeof(char));
status = H5LTdtype_to_text(H5_NativeTypes[typeIdx], str, H5LT_DDL, &len);
printf("String description for the type %d: %s\n",typeIdx,str);
free(str);
}
// Open the file as Read Only, and default File Access property list
fileID = H5Fopen(IMGSVFILE, H5F_ACC_RDONLY, H5P_DEFAULT);
/*****************************
* Read in the ModeGran dataset *
*****************************/
strcpy(dsetName,IMGSVGRP);
strcat(dsetName,"ModeGran");
printf("\nDataset name is : %s\n",dsetName);
// Get the dataset ID for the ModeGran dataset
dsetID = H5Dopen (fileID, dsetName, H5P_DEFAULT);
// Get dataspace and allocate memory for read buffer. This is a
// two dimensional dataset so the dynamic allocation must be done
// in steps.
dspaceID = H5Dget_space(dsetID);
// Get the number of dimensions, dimension sizes and maximum dimension
// sizes for the ModeGran dataset (through the associated dataspace)
rank = H5Sget_simple_extent_dims(dspaceID, dimSize, NULL);
printf("Rank of ModeGran dataset : %d\n",rank);
printf("Dimension sizes of ModeGran dataset : ");
for (i=0;i<rank;i++) printf("%llu\t",dimSize[i]);
// Allocate memory for our array
unsigned char ModeGran;
// Read the ModeGran dataset into the ModeGran array
status = H5Dread (dsetID, // dataset ID
H5T_NATIVE_UCHAR, // ident of memory datatype
H5S_ALL, // ident of memory dataspace
H5S_ALL, // ident of dataset's dataspace in file
H5P_DEFAULT, // File access properties
&ModeGran); // Pointer to buffer receiving data
printf("\nModeGran read status = %d\n",status);
printf("\nModeGran = ");
printf (" %4d", ModeGran);
//printf (" [ ");
//for (j=0; j<dimSize[0]; j++){
//printf (" %4d", ModeGran[j]);
//}
//printf (" ]\n");
// Free the ModeGran array pointers
// HDF Example Method
//free(ModeGran);
// Close and release ModeGran dataset and dataspace
status = H5Dclose (dsetID);
printf("\n\nClose ModeGran dataset status = %d\n",status);
status = H5Sclose (dspaceID);
printf("Close ModeGran dataspace status = %d\n",status);
printf ("\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
/*****************************************
* Read in the ModeScan dataset *
*****************************************/
strcpy(dsetName,IMGSVGRP);
strcat(dsetName,"ModeScan");
printf("\nDataset name is : %s\n",dsetName);
// Get the dataset ID for the ModeScan dataset
dsetID = H5Dopen (fileID, dsetName, H5P_DEFAULT);
// Get dataspace and allocate memory for read buffer. This is a
// two dimensional dataset so the dynamic allocation must be done
// in steps.
dspaceID = H5Dget_space(dsetID);
// Get the number of dimensions, dimension sizes and maximum dimension
// sizes for the ModeScan dataset (through the associated dataspace)
rank = H5Sget_simple_extent_dims(dspaceID, dimSize, NULL);
printf("Rank of ModeScan dataset : %d\n",rank);
printf("Dimension sizes of ModeScan dataset : ");
for (i=0;i<rank;i++) printf("%llu\t",dimSize[i]);
// Allocate memory for our array
unsigned char *ModeScan = (unsigned char *) malloc(dimSize[0] * sizeof(unsigned char));
// Read the ModeScan dataset into the ModeScan array
status = H5Dread (dsetID, // dataset ID
H5T_NATIVE_UCHAR, // ident of memory datatype
H5S_ALL, // ident of memory dataspace
H5S_ALL, // ident of dataset's dataspace in file
H5P_DEFAULT, // File access properties
ModeScan); // Pointer to buffer receiving data
printf("\nModeScan read status = %d\n",status);
printf("\nModeScan =\n");
printf (" [ ");
for (j=0; j<dimSize[0]; j++){
printf (" %4d", ModeScan[j]);
}
printf (" ]\n");
/*
* Free the ModeScan array pointers
*/
// HDF Example Method
free(ModeScan);
/*
* Close and release ModeScan dataset and dataspace
*/
status = H5Dclose (dsetID);
printf("\n\nClose ModeScan dataset status = %d\n",status);
status = H5Sclose (dspaceID);
printf("Close ModeScan dataspace status = %d\n",status);
printf ("\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
/*****************************************
* Read in the NumberOfBadChecksums dataset *
*****************************************/
strcpy(dsetName,IMGSVGRP);
strcat(dsetName,"NumberOfBadChecksums");
printf("\nDataset name is : %s\n",dsetName);
// Get the dataset ID for the NumberOfBadChecksums dataset
dsetID = H5Dopen (fileID, dsetName, H5P_DEFAULT);
// Get dataspace and allocate memory for read buffer. This is a
// two dimensional dataset so the dynamic allocation must be done
// in steps.
dspaceID = H5Dget_space(dsetID);
// Get the number of dimensions, dimension sizes and maximum dimension
// sizes for the NumberOfBadChecksums dataset (through the associated dataspace)
rank = H5Sget_simple_extent_dims(dspaceID, dimSize, NULL);
printf("Rank of NumberOfBadChecksums dataset : %d\n",rank);
printf("Dimension sizes of NumberOfBadChecksums dataset : ");
for (i=0;i<rank;i++) printf("%llu\t",dimSize[i]);
// Allocate memory for our array
int *NumberOfBadChecksums = (int *) malloc(dimSize[0] * sizeof(int));
// Read the NumberOfBadChecksums dataset into the NumberOfBadChecksums array
status = H5Dread (dsetID, // dataset ID
H5T_NATIVE_INT, // ident of memory datatype
H5S_ALL, // ident of memory dataspace
H5S_ALL, // ident of dataset's dataspace in file
H5P_DEFAULT, // File access properties
NumberOfBadChecksums); // Pointer to buffer receiving data
printf("\nNumberOfBadChecksums read status = %d\n",status);
printf("\nNumberOfBadChecksums =\n");
printf (" [ ");
for (j=0; j<dimSize[0]; j++){
printf (" %4d", NumberOfBadChecksums[j]);
}
printf (" ]\n");
// Free the NumberOfBadChecksums array pointers
// HDF Example Method
free(NumberOfBadChecksums);
// Close and release NumberOfBadChecksums dataset and dataspace
status = H5Dclose (dsetID);
printf("\n\nClose NumberOfBadChecksums dataset status = %d\n",status);
status = H5Sclose (dspaceID);
printf("Close NumberOfBadChecksums dataspace status = %d\n",status);
printf ("\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
/*****************************************
* Read in the NumberOfDiscardedPkts dataset *
*****************************************/
strcpy(dsetName,IMGSVGRP);
strcat(dsetName,"NumberOfDiscardedPkts");
printf("\nDataset name is : %s\n",dsetName);
// Get the dataset ID for the NumberOfDiscardedPkts dataset
dsetID = H5Dopen (fileID, dsetName, H5P_DEFAULT);
// Get dataspace and allocate memory for read buffer. This is a
// two dimensional dataset so the dynamic allocation must be done
// in steps.
dspaceID = H5Dget_space(dsetID);
// Get the number of dimensions, dimension sizes and maximum dimension
// sizes for the NumberOfDiscardedPkts dataset (through the associated dataspace)
rank = H5Sget_simple_extent_dims(dspaceID, dimSize, NULL);
printf("Rank of NumberOfDiscardedPkts dataset : %d\n",rank);
printf("Dimension sizes of NumberOfDiscardedPkts dataset : ");
for (i=0;i<rank;i++) printf("%llu\t",dimSize[i]);
// Allocate memory for our array
int *NumberOfDiscardedPkts = (int *) malloc(dimSize[0] * sizeof(int));
// Read the NumberOfDiscardedPkts dataset into the NumberOfDiscardedPkts array
status = H5Dread (dsetID, // dataset ID
H5T_NATIVE_INT, // ident of memory datatype
H5S_ALL, // ident of memory dataspace
H5S_ALL, // ident of dataset's dataspace in file
H5P_DEFAULT, // File access properties
NumberOfDiscardedPkts); // Pointer to buffer receiving data
printf("\nNumberOfDiscardedPkts read status = %d\n",status);
printf("\nNumberOfDiscardedPkts =\n");
printf (" [ ");
for (j=0; j<dimSize[0]; j++){
printf (" %4d", NumberOfDiscardedPkts[j]);
}
printf (" ]\n");
// Free the NumberOfDiscardedPkts array pointers
// HDF Example Method
free(NumberOfDiscardedPkts);
// Close and release NumberOfDiscardedPkts dataset and dataspace
status = H5Dclose (dsetID);
printf("\n\nClose NumberOfDiscardedPkts dataset status = %d\n",status);
status = H5Sclose (dspaceID);
printf("Close NumberOfDiscardedPkts dataspace status = %d\n",status);
printf ("\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
/*****************************************
* Read in the NumberOfMissingPkts dataset *
*****************************************/
strcpy(dsetName,IMGSVGRP);
strcat(dsetName,"NumberOfMissingPkts");
printf("\nDataset name is : %s\n",dsetName);
// Get the dataset ID for the NumberOfMissingPkts dataset
dsetID = H5Dopen (fileID, dsetName, H5P_DEFAULT);
// Get dataspace and allocate memory for read buffer. This is a
// two dimensional dataset so the dynamic allocation must be done
// in steps.
dspaceID = H5Dget_space(dsetID);
// Get the number of dimensions, dimension sizes and maximum dimension
// sizes for the NumberOfMissingPkts dataset (through the associated dataspace)
rank = H5Sget_simple_extent_dims(dspaceID, dimSize, NULL);
printf("Rank of NumberOfMissingPkts dataset : %d\n",rank);
printf("Dimension sizes of NumberOfMissingPkts dataset : ");
for (i=0;i<rank;i++) printf("%llu\t",dimSize[i]);
// Allocate memory for our array
int *NumberOfMissingPkts = (int *) malloc(dimSize[0] * sizeof(int));
// Read the NumberOfMissingPkts dataset into the NumberOfMissingPkts array
status = H5Dread (dsetID, // dataset ID
H5T_NATIVE_INT, // ident of memory datatype
H5S_ALL, // ident of memory dataspace
H5S_ALL, // ident of dataset's dataspace in file
H5P_DEFAULT, // File access properties
NumberOfMissingPkts); // Pointer to buffer receiving data
printf("\nNumberOfMissingPkts read status = %d\n",status);
printf("\nNumberOfMissingPkts =\n");
printf (" [ ");
for (j=0; j<dimSize[0]; j++){
printf (" %4d", NumberOfMissingPkts[j]);
}
printf (" ]\n");
// Free the NumberOfMissingPkts array pointers
// HDF Example Method
free(NumberOfMissingPkts);
// Close and release NumberOfMissingPkts dataset and dataspace
status = H5Dclose (dsetID);
printf("\n\nClose NumberOfMissingPkts dataset status = %d\n",status);
status = H5Sclose (dspaceID);
printf("Close NumberOfMissingPkts dataspace status = %d\n",status);
printf ("\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
/*****************************
* Read in the NumberOfScans dataset *
*****************************/
strcpy(dsetName,IMGSVGRP);
strcat(dsetName,"NumberOfScans");
printf("\nDataset name is : %s\n",dsetName);
// Get the dataset ID for the NumberOfScans dataset
dsetID = H5Dopen (fileID, dsetName, H5P_DEFAULT);
// Get the datatype ID for this dataset
dTypeID = H5Dget_type(dsetID);
// Get the equivalent NATIVE datatype ID
dTypeID = H5Tget_native_type(dTypeID,H5T_DIR_ASCEND);
// Determine the index of the desired type
typeIdx=0;
for (typeIdx=0;typeIdx<18;typeIdx++){
if (H5Tequal(dTypeID,H5_NativeTypes[typeIdx])) break;
}
// Get dataspace and allocate memory for read buffer. This is a
// two dimensional dataset so the dynamic allocation must be done
// in steps.
dspaceID = H5Dget_space(dsetID);
// Get the number of dimensions, dimension sizes and maximum dimension
// sizes for the NumberOfScans dataset (through the associated dataspace)
rank = H5Sget_simple_extent_dims(dspaceID, dimSize, NULL);
printf("Rank of NumberOfScans dataset : %d\n",rank);
printf("Dimension sizes of NumberOfScans dataset : ");
for (i=0;i<rank;i++)
printf("%llu\t",dimSize[i]);
// Allocate memory for our array
int NumberOfScans;
// Read the NumberOfScans dataset into the NumberOfScans array
status = H5Dread (dsetID, // dataset ID
dTypeID, // ident of memory datatype
H5S_ALL, // ident of memory dataspace
H5S_ALL, // ident of dataset's dataspace in file
H5P_DEFAULT, // File access properties
&NumberOfScans); // Pointer to buffer receiving data
printf("\nNumberOfScans read status = %d\n",status);
printf("\nNumberOfScans = ");
printf (" %4d", NumberOfScans);
// Close and release NumberOfScans dataset and dataspace
status = H5Dclose (dsetID);
printf("\n\nClose NumberOfScans dataset status = %d\n",status);
status = H5Sclose (dspaceID);
printf("Close NumberOfScans dataspace status = %d\n",status);
status = H5Tclose (dTypeID);
printf("Close NumberOfScans datatype status = %d\n",status);
printf ("\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
/*****************************
* Read in the PadByte1 dataset *
*****************************/
strcpy(dsetName,IMGSVGRP);
strcat(dsetName,"PadByte1");
printf("\nDataset name is : %s\n",dsetName);
// Get the dataset ID for the PadByte1 dataset
dsetID = H5Dopen (fileID, dsetName, H5P_DEFAULT);
// Get dataspace and allocate memory for read buffer. This is a
// two dimensional dataset so the dynamic allocation must be done
// in steps.
dspaceID = H5Dget_space(dsetID);
// Get the number of dimensions, dimension sizes and maximum dimension
// sizes for the PadByte1 dataset (through the associated dataspace)
rank = H5Sget_simple_extent_dims(dspaceID, dimSize, NULL);
printf("Rank of PadByte1 dataset : %d\n",rank);
printf("Dimension sizes of PadByte1 dataset : ");
for (i=0;i<rank;i++) printf("%llu\t",dimSize[i]);
// Allocate memory for our array
unsigned char *PadByte1 = (unsigned char *) malloc(dimSize[0] * sizeof(unsigned char));
// Read the PadByte1 dataset into the PadByte1 array
status = H5Dread (dsetID, // dataset ID
H5T_NATIVE_UCHAR, // ident of memory datatype
H5S_ALL, // ident of memory dataspace
H5S_ALL, // ident of dataset's dataspace in file
H5P_DEFAULT, // File access properties
PadByte1); // Pointer to buffer receiving data
printf("\nPadByte1 read status = %d\n",status);
printf("\nPadByte1 =\n");
printf (" [ ");
for (j=0; j<dimSize[0]; j++){
printf (" %4d", PadByte1[j]);
}
printf (" ]\n");
// Free the PadByte1 array pointers
// HDF Example Method
free(PadByte1);
// Close and release PadByte1 dataset and dataspace
status = H5Dclose (dsetID);
printf("\n\nClose PadByte1 dataset status = %d\n",status);
status = H5Sclose (dspaceID);
printf("Close PadByte1 dataspace status = %d\n",status);
printf ("\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
/*****************************************
* Read in the QF1_VIIRSI1SDR dataset *
*****************************************/
strcpy(dsetName,IMGSVGRP);
strcat(dsetName,"QF1_VIIRSIBANDSDR");
printf("\nDataset name is : %s\n",dsetName);
// Get the dataset ID for the QF1_VIIRSI1SDR dataset
dsetID = H5Dopen (fileID, dsetName, H5P_DEFAULT);
// Get dataspace and allocate memory for read buffer. This is a
// two dimensional dataset so the dynamic allocation must be done
// in steps.
dspaceID = H5Dget_space(dsetID);
// Get the number of dimensions, dimension sizes and maximum dimension
// sizes for the QF1_VIIRSI1SDR dataset (through the associated dataspace)
rank = H5Sget_simple_extent_dims(dspaceID, dimSize, NULL);
printf("Rank of QF1_VIIRSIBANDSDR dataset : %d\n",rank);
printf("Dimension sizes of QF1_VIIRSIBANDSDR dataset : ");
for (i=0;i<rank;i++)
printf("%llu\t",dimSize[i]);
nRows = dimSize[0];
nCols = dimSize[1];
// Allocate memory for our array
// HDF5 example method
unsigned char **QF1_VIIRSIBANDSDR = (unsigned char **) malloc(nRows * sizeof(unsigned char *));
QF1_VIIRSIBANDSDR[0] = (unsigned char *) malloc(nRows * nCols * sizeof(unsigned char));
for (i=1; i<nRows; i++)
QF1_VIIRSIBANDSDR[i] = QF1_VIIRSIBANDSDR[0] + i * nCols;
//Test Method 1
//int **QF1_VIIRSI1SDR = malloc(nRows * sizeof(int *));
//for(i = 0; i < nRows; i++)
//QF1_VIIRSI1SDR[i] = malloc(nCols * sizeof(int));
//Test Method 2
//int **QF1_VIIRSI1SDR = malloc(nRows * sizeof(int *));
//QF1_VIIRSI1SDR[0] = malloc(nRows * nCols * sizeof(int));
//for(i = 1; i < nRows; i++)
//QF1_VIIRSI1SDR[i] = QF1_VIIRSI1SDR[0] + i * nCols;
// Read the QF1_VIIRSI1SDR dataset into the QF1_VIIRSI1SDR array
status = H5Dread (dsetID, // dataset ID
H5T_NATIVE_UCHAR, // ident of memory datatype
H5S_ALL, // ident of memory dataspace
H5S_ALL, // ident of dataset's dataspace in file
H5P_DEFAULT, // File access properties
QF1_VIIRSIBANDSDR[0]); // Pointer to buffer receiving data
printf("\nQF1_VIIRSIBANDSDR read status = %d\n",status);
printf("\nQF1_VIIRSIBANDSDR =\n");
for (i=0; i<10; i++) {
printf (" [ ");
for (j=0; j<10; j++){
printf (" %4d", QF1_VIIRSIBANDSDR[i][j]);
//printf (" %4d", *(QF1_VIIRSIBANDSDR[i] + j));
}
printf (" ]\n");
}
// Free the QF1_VIIRSIBANDSDR array pointers
// HDF Example Method
free(QF1_VIIRSIBANDSDR[0]);
free(QF1_VIIRSIBANDSDR);
// Test Method 1
//for(i = 0; i < nRows; i++)
//free((void *)QF1_VIIRSI1SDR[i]);
//free((void *)QF1_VIIRSI1SDR);
// Test Method 2
//free((void *)QF1_VIIRSI1SDR[0]);
//free((void *)QF1_VIIRSI1SDR);
/*
* Close and release QF1_VIIRSI1SDR dataset and dataspace
*/
status = H5Dclose (dsetID);
printf("\n\nClose QF1_VIIRSIBANDSDR dataset status = %d\n",status);
status = H5Sclose (dspaceID);
printf("Close QF1_VIIRSIBANDSDR dataspace status = %d\n",status);
printf ("\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
/*****************************************
* Read in the QF2_SCAN_SDR dataset *
*****************************************/
strcpy(dsetName,IMGSVGRP);
strcat(dsetName,"QF2_SCAN_SDR");
printf("\nDataset name is : %s\n",dsetName);
// Get the dataset ID for the QF2_SCAN_SDR dataset
dsetID = H5Dopen (fileID, dsetName, H5P_DEFAULT);
// Get dataspace and allocate memory for read buffer. This is a
// two dimensional dataset so the dynamic allocation must be done
// in steps.
dspaceID = H5Dget_space(dsetID);
// Get the number of dimensions, dimension sizes and maximum dimension
// sizes for the QF2_SCAN_SDR dataset (through the associated dataspace)
rank = H5Sget_simple_extent_dims(dspaceID, dimSize, NULL);
printf("Rank of QF2_SCAN_SDR dataset : %d\n",rank);
printf("Dimension sizes of QF2_SCAN_SDR dataset : ");
for (i=0;i<rank;i++) printf("%llu\t",dimSize[i]);
// Allocate memory for our array
unsigned char *QF2_SCAN_SDR = (unsigned char *) malloc(dimSize[0] * sizeof(unsigned char));
// Read the QF2_SCAN_SDR dataset into the QF2_SCAN_SDR array
status = H5Dread (dsetID, // dataset ID
H5T_NATIVE_UCHAR, // ident of memory datatype
H5S_ALL, // ident of memory dataspace
H5S_ALL, // ident of dataset's dataspace in file
H5P_DEFAULT, // File access properties
QF2_SCAN_SDR); // Pointer to buffer receiving data
printf("\nQF2_SCAN_SDR read status = %d\n",status);
printf("\nQF2_SCAN_SDR =\n");
printf (" [ ");
for (j=0; j<dimSize[0]; j++){
printf (" %4d", QF2_SCAN_SDR[j]);
}
printf (" ]\n");
/*
* Free the QF2_SCAN_SDR array pointers
*/
// HDF Example Method
free(QF2_SCAN_SDR);
/*
* Close and release QF2_SCAN_SDR dataset and dataspace
*/
status = H5Dclose (dsetID);
printf("\n\nClose QF2_SCAN_SDR dataset status = %d\n",status);
status = H5Sclose (dspaceID);
printf("Close QF2_SCAN_SDR dataspace status = %d\n",status);
printf ("\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
/*****************************************
* Read in the QF3_SCAN_RDR dataset *
*****************************************/
strcpy(dsetName,IMGSVGRP);
strcat(dsetName,"QF3_SCAN_RDR");
printf("\nDataset name is : %s\n",dsetName);
// Get the dataset ID for the QF3_SCAN_RDR dataset
dsetID = H5Dopen (fileID, dsetName, H5P_DEFAULT);
// Get dataspace and allocate memory for read buffer. This is a
// two dimensional dataset so the dynamic allocation must be done
// in steps.
dspaceID = H5Dget_space(dsetID);
// Get the number of dimensions, dimension sizes and maximum dimension
// sizes for the QF3_SCAN_RDR dataset (through the associated dataspace)
rank = H5Sget_simple_extent_dims(dspaceID, dimSize, NULL);
printf("Rank of QF3_SCAN_RDR dataset : %d\n",rank);
printf("Dimension sizes of QF3_SCAN_RDR dataset : ");
for (i=0;i<rank;i++) printf("%llu\t",dimSize[i]);
// Allocate memory for our array
unsigned char *QF3_SCAN_RDR = (unsigned char *) malloc(dimSize[0] * sizeof(unsigned char));
// Read the QF3_SCAN_RDR dataset into the QF3_SCAN_RDR array
status = H5Dread (dsetID, // dataset ID
H5T_NATIVE_UCHAR, // ident of memory datatype
H5S_ALL, // ident of memory dataspace
H5S_ALL, // ident of dataset's dataspace in file
H5P_DEFAULT, // File access properties
QF3_SCAN_RDR); // Pointer to buffer receiving data
printf("\nQF3_SCAN_RDR read status = %d\n",status);
printf("\nQF3_SCAN_RDR =\n");
printf (" [ ");
for (j=0; j<dimSize[0]; j++){
printf (" %4d", QF3_SCAN_RDR[j]);
}
printf (" ]\n");
/*
* Free the QF3_SCAN_RDR array pointers
*/
// HDF Example Method
free(QF3_SCAN_RDR);
/*
* Close and release QF3_SCAN_RDR dataset and dataspace
*/
status = H5Dclose (dsetID);
printf("\n\nClose QF3_SCAN_RDR dataset status = %d\n",status);
status = H5Sclose (dspaceID);
printf("Close QF3_SCAN_RDR dataspace status = %d\n",status);
printf ("\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
/*****************************************
* Read in the QF4_SCAN_SDR dataset *
*****************************************/
strcpy(dsetName,IMGSVGRP);
strcat(dsetName,"QF4_SCAN_SDR");
printf("\nDataset name is : %s\n",dsetName);
// Get the dataset ID for the QF4_SCAN_SDR dataset
dsetID = H5Dopen (fileID, dsetName, H5P_DEFAULT);
// Get dataspace and allocate memory for read buffer. This is a
// two dimensional dataset so the dynamic allocation must be done
// in steps.
dspaceID = H5Dget_space(dsetID);
// Get the number of dimensions, dimension sizes and maximum dimension
// sizes for the QF4_SCAN_SDR dataset (through the associated dataspace)
rank = H5Sget_simple_extent_dims(dspaceID, dimSize, NULL);
printf("Rank of QF4_SCAN_SDR dataset : %d\n",rank);
printf("Dimension sizes of QF4_SCAN_SDR dataset : ");
for (i=0;i<rank;i++) printf("%llu\t",dimSize[i]);
// Allocate memory for our array
unsigned char *QF4_SCAN_SDR = (unsigned char *) malloc(dimSize[0] * sizeof(unsigned char));
// Read the QF4_SCAN_SDR dataset into the QF4_SCAN_SDR array
status = H5Dread (dsetID, // dataset ID
H5T_NATIVE_UCHAR, // ident of memory datatype
H5S_ALL, // ident of memory dataspace
H5S_ALL, // ident of dataset's dataspace in file
H5P_DEFAULT, // File access properties
QF4_SCAN_SDR); // Pointer to buffer receiving data
printf("\nQF4_SCAN_SDR read status = %d\n",status);
printf("\nQF4_SCAN_SDR =\n");
printf (" [ ");
for (j=0; j<dimSize[0]; j++){
printf (" %4d", QF4_SCAN_SDR[j]);
}
printf (" ]\n");
/*
* Free the QF4_SCAN_SDR array pointers
*/
// HDF Example Method
free(QF4_SCAN_SDR);
/*
* Close and release QF4_SCAN_SDR dataset and dataspace
*/
status = H5Dclose (dsetID);
printf("\n\nClose QF4_SCAN_SDR dataset status = %d\n",status);
status = H5Sclose (dspaceID);
printf("Close QF4_SCAN_SDR dataspace status = %d\n",status);
printf ("\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
/*****************************************
* Read in the QF5_GRAN_BADDETECTOR dataset *
*****************************************/
strcpy(dsetName,IMGSVGRP);
strcat(dsetName,"QF5_GRAN_BADDETECTOR");
printf("\nDataset name is : %s\n",dsetName);
// Get the dataset ID for the QF5_GRAN_BADDETECTOR dataset
dsetID = H5Dopen (fileID, dsetName, H5P_DEFAULT);
// Get dataspace and allocate memory for read buffer. This is a
// two dimensional dataset so the dynamic allocation must be done
// in steps.
dspaceID = H5Dget_space(dsetID);
// Get the number of dimensions, dimension sizes and maximum dimension
// sizes for the QF5_GRAN_BADDETECTOR dataset (through the associated dataspace)
rank = H5Sget_simple_extent_dims(dspaceID, dimSize, NULL);
printf("Rank of QF5_GRAN_BADDETECTOR dataset : %d\n",rank);
printf("Dimension sizes of QF5_GRAN_BADDETECTOR dataset : ");
for (i=0;i<rank;i++) printf("%llu\t",dimSize[i]);
// Allocate memory for our array
unsigned char *QF5_GRAN_BADDETECTOR = (unsigned char *) malloc(dimSize[0] * sizeof(unsigned char));
// Read the QF5_GRAN_BADDETECTOR dataset into the QF5_GRAN_BADDETECTOR array
status = H5Dread (dsetID, // dataset ID
H5T_NATIVE_UCHAR, // ident of memory datatype
H5S_ALL, // ident of memory dataspace
H5S_ALL, // ident of dataset's dataspace in file
H5P_DEFAULT, // File access properties
QF5_GRAN_BADDETECTOR); // Pointer to buffer receiving data
printf("\nQF5_GRAN_BADDETECTOR read status = %d\n",status);
printf("\nQF5_GRAN_BADDETECTOR =\n");
printf (" [ ");
for (j=0; j<dimSize[0]; j++){
printf (" %4d", QF5_GRAN_BADDETECTOR[j]);
}
printf (" ]\n");
/*
* Free the QF5_GRAN_BADDETECTOR array pointers
*/
// HDF Example Method
free(QF5_GRAN_BADDETECTOR);
/*
* Close and release QF5_GRAN_BADDETECTOR dataset and dataspace
*/
status = H5Dclose (dsetID);
printf("\n\nClose QF5_GRAN_BADDETECTOR dataset status = %d\n",status);
status = H5Sclose (dspaceID);
printf("Close QF5_GRAN_BADDETECTOR dataspace status = %d\n",status);
printf ("\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
/*****************************************
* Read in the Radiance dataset *
*****************************************/
strcpy(dsetName,IMGSVGRP);
strcat(dsetName,"Radiance");
printf("\nDataset name is : %s\n",dsetName);
// Get the dataset ID for the Radiance dataset
dsetID = H5Dopen (fileID, dsetName, H5P_DEFAULT);
// Get dataspace and allocate memory for read buffer. This is a
// two dimensional dataset so the dynamic allocation must be done
// in steps.
dspaceID = H5Dget_space(dsetID);
// Get the number of dimensions, dimension sizes and maximum dimension
// sizes for the Radiance dataset (through the associated dataspace)
rank = H5Sget_simple_extent_dims(dspaceID, dimSize, NULL);
printf("Rank of Radiance dataset : %d\n",rank);
printf("Dimension sizes of Radiance dataset : ");
for (i=0;i<rank;i++)
printf("%llu\t",dimSize[i]);
nRows = dimSize[0];
nCols = dimSize[1];
// Allocate memory for our array
// HDF5 example method
unsigned short **Radiance = (unsigned short **) malloc(nRows * sizeof(unsigned short *));
Radiance[0] = (unsigned short *) malloc(nRows * nCols * sizeof(unsigned short));
for (i=1; i<nRows; i++)
Radiance[i] = Radiance[0] + i * nCols;
//Test Method 1
//int **Radiance = malloc(nRows * sizeof(int *));
//for(i = 0; i < nRows; i++)
//Radiance[i] = malloc(nCols * sizeof(int));
//Test Method 2
//int **Radiance = malloc(nRows * sizeof(int *));
//Radiance[0] = malloc(nRows * nCols * sizeof(int));
//for(i = 1; i < nRows; i++)
//Radiance[i] = Radiance[0] + i * nCols;
// Read the Radiance dataset into the Radiance array
status = H5Dread (dsetID, // dataset ID
H5T_NATIVE_USHORT, // ident of memory datatype
H5S_ALL, // ident of memory dataspace
H5S_ALL, // ident of dataset's dataspace in file
H5P_DEFAULT, // File access properties
Radiance[0]); // Pointer to buffer receiving data
printf("\nRadiance read status = %d\n",status);
printf("\nRadiance =\n");
for (i=0; i<10; i++) {
printf (" [ ");
for (j=0; j<10; j++){
printf (" %4d", Radiance[i][j]);
//printf (" %4d", *(Radiance[i] + j));
}
printf (" ]\n");
}
// Free the Radiance array pointers
// HDF Example Method
//free(Radiance[0]);
//free(Radiance);
// Test Method 1
//for(i = 0; i < nRows; i++)
//free((void *)Radiance[i]);
//free((void *)Radiance);
// Test Method 2
//free((void *)Radiance[0]);
//free((void *)Radiance);
// Close and release HDF5 Radiance dataset and dataspace
status = H5Dclose (dsetID);
printf("\n\nClose Radiance dataset status = %d\n",status);
status = H5Sclose (dspaceID);
printf("Close Radiance dataspace status = %d\n",status);
printf ("\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
/*****************************************
* Read in the RadianceFactors dataset *
*****************************************/
strcpy(dsetName,IMGSVGRP);
strcat(dsetName,"RadianceFactors");
printf("\nDataset name is : %s\n",dsetName);
// Get the dataset ID for the RadianceFactors dataset
dsetID = H5Dopen (fileID, dsetName, H5P_DEFAULT);
// Get dataspace and allocate memory for read buffer. This is a
// two dimensional dataset so the dynamic allocation must be done
// in steps.
dspaceID = H5Dget_space(dsetID);
// Get the number of dimensions, dimension sizes and maximum dimension
// sizes for the RadianceFactors dataset (through the associated dataspace)
rank = H5Sget_simple_extent_dims(dspaceID, dimSize, NULL);
printf("Rank of RadianceFactors dataset : %d\n",rank);
printf("Dimension sizes of RadianceFactors dataset : ");
for (i=0;i<rank;i++) printf("%llu\t",dimSize[i]);
// Allocate memory for our array
float *RadianceFactors = (float *) malloc(dimSize[0] * sizeof(float));
// Read the RadianceFactors dataset into the RadianceFactors array
status = H5Dread (dsetID, // dataset ID
H5T_NATIVE_FLOAT, // ident of memory datatype
H5S_ALL, // ident of memory dataspace
H5S_ALL, // ident of dataset's dataspace in file
H5P_DEFAULT, // File access properties
RadianceFactors); // Pointer to buffer receiving data
printf("\nRadianceFactors read status = %d\n",status);
printf("\nRadianceFactors =\n");
printf (" [ ");
for (j=0; j<dimSize[0]; j++){
printf (" %11.6f", RadianceFactors[j]);
}
printf (" ]\n");
// Free the RadianceFactors array pointers
// HDF Example Method
//free(RadianceFactors);
// Close and release RadianceFactors dataset and dataspace
status = H5Dclose (dsetID);
printf("\n\nClose RadianceFactors dataset status = %d\n",status);
status = H5Sclose (dspaceID);
printf("Close RadianceFactors dataspace status = %d\n",status);
printf ("\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
// Allocate the array memory for the unscaled Radiances
float **Radiance_unscaled = (float **) malloc(nRows * sizeof(float *));
Radiance_unscaled[0] = (float *) malloc(nRows * nCols * sizeof(float));
for (i=1; i<nRows; i++)
Radiance_unscaled[i] = Radiance_unscaled[0] + i * nCols;
for (i=0; i<nRows; i++) {
for (j=0; j<nCols; j++){
Radiance_unscaled[i][j] = (float)Radiance[i][j]*RadianceFactors[0]
+ (float)RadianceFactors[1];
}
}
printf("\nRadiance (unscaled) =\n");
for (i=0; i<10; i++) {
printf (" [ ");
for (j=0; j<10; j++){
printf (" %11.6f", Radiance_unscaled[i][j]);
}
printf (" ]\n");
}
free(Radiance[0]);
free(Radiance);
free(RadianceFactors);