-
Notifications
You must be signed in to change notification settings - Fork 0
/
hdfb.pro
6029 lines (5056 loc) · 155 KB
/
hdfb.pro
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
;*************************************************************************
; Copyright (c) 2002 The University of Chicago, as Operator of Argonne
; National Laboratory.
; Copyright (c) 2002 The Regents of the University of California, as
; Operator of Los Alamos National Laboratory.
; This file is distributed subject to a Software License Agreement found
; in the file LICENSE that is included with this distribution.
;*************************************************************************
@xdr_open.pro
@PS_open.pro
@panimage.pro
@wc.pro
@iplot1d.pro
;@idlitparameterset__define.pro
;@idlitdatacontainer__define.pro
;@idlitvisroi__define.pro
@h5b.pro
PRO HDFSDSDATA_Flipfiles,nametag=nametag,Event,one=one
; Flip all the hdf file found in the data directory
; one - display only the first image found in a file otherwise
; display everyone found in a file
; nametag - specify the search tagname of the data image, default is
; 'data'
COMMON HDF_QUERY_BLOCK,HDF_Query,HDF_Query_id
if keyword_set(nametag) eq 0 then nametag = 'data'
if HDF_Query.fpath eq '' then return
files = file_search(HDF_Query.fpath+'*',/mark)
num = n_elements(files)
HDF_Query.filenos[1] = num-1
if HDF_Query.filenos[0] lt num then HDF_Query.filenos[0] = num
WSET,HDF_Query_id.draw1
FOR i=0,num-1 DO BEGIN
HDFSDSDATA_checkfile,files(i),Event,/seloff
if HDF_Query.file eq files(i) then begin
for seqno=HDF_Query.NUMSDS-1,0,-1 do begin
sds_id = HDF_SD_SELECT(HDF_Query.sd_id,seqno)
HDF_SD_GETINFO,sds_id, LABEL=Ti, UNIT=read_unit, NAME=n
;print,files(i),' ,',nametag,' ,',n
if strpos(n,nametag) ge 0 then begin
HDF_SD_GETDATA,SDS_ID,Data
HDF_Query.tname= n
HDF_Query.seqno = seqno
*HDF_Query.data = data
sz = size(data)
if sz(0) eq 2 then begin
y1 = min(data)
y2 = max(data)
newdata = fix(float(Data-y1)/(y2-y1)*!d.table_size)
erase
TV,congrid(newdata,!d.x_size/2,!d.y_size-20)
xyouts, 0.6*!d.x_size, 0.5*!d.y_size, HDF_Query.classname,/DEVICE
end
if keyword_set(one) then break
end
HDF_SD_ENDACCESS,sds_id
end
end
END
END
PRO SDS_CONST_Event, Event
COMMON HDF_QUERY_BLOCK,HDF_Query,HDF_Query_id
widget_control, Event.top, get_uvalue=sds_const_state,/no_copy
WIDGET_CONTROL,Event.Id,GET_UVALUE=Ev
CASE Ev OF
'SDS_CONST_1DARRAY': BEGIN
WIDGET_CONTROL,sds_const_state.sel1ID,GET_VALUE=st
if strlen(strtrim(st,2)) gt 0 then begin
parse_num,st,res
id = where(res lt HDF_Query.numSDS)
if res(0) lt HDF_Query.numSDS and res(0) ge 0 then begin
SDS_multi1d,seq=res(id),data=data,dname=dname,error=error ;,/echo
if error eq 0 then begin
sz = size(data)
if HDF_Query.naxis gt 1 then x = *HDF_Query.yarr else $
x = *HDF_Query.xarr
if sz(1) ne n_elements(x) then x = *HDF_Query.yarr
if sz(1) eq n_elements(x) then $
plot1d,x,data,legend=dname,Group=Event.top else $
plot1d,data,legend=dname,Group=Event.top,xtitle='Index #'
end
endif else begin
st = ['Error: Invalid SDS # entered!', '', $
'Valid SDS # : [0-'+strtrim(HDF_Query.NUMSDS-1,2)+']']
r = dialog_message(/error,st)
end
end
END
'SDS_CONST_2DARRAY': BEGIN
WIDGET_CONTROL,sds_const_state.sel2ID,GET_VALUE=st
if strlen(st) gt 0 then begin
parse_num,st,res
id = where(res lt HDF_Query.numSDS)
if res(0) lt HDF_Query.numSDS and res(0) ge 0 then begin
SDS_multi2d,seq=res(id),data=data,dname=dname,/echo
endif else begin
st = ['Error: Invalid SDS # entered!', '', $
'Valid SDS # : [0-'+strtrim(HDF_Query.NUMSDS-1,2)+']']
r = dialog_message(/error,st)
end
end
END
'SDS_CONST_2DARRAY2': BEGIN
WIDGET_CONTROL,sds_const_state.sel2ID,GET_VALUE=st
if strtrim(st,2) gt 1 then begin
parse_num,st,res
id = where(res lt HDF_Query.numSDS)
if res(0) lt HDF_Query.numSDS and res(0) ge 0 then begin
SDS_multi2d,seq=res(id),data=data,dname=dname
endif else begin
st = ['Error: Invalid SDS # entered!', '', $
'Valid SDS # : [0-'+strtrim(HDF_Query.NUMSDS-1,2)+']']
r = dialog_message(/error,st)
end
sz = size(data)
if sz(0) eq 3 then begin
xarr = *HDF_Query.xarr
yarr = *HDF_Query.yarr
if n_elements(xarr) eq sz(1) then begin
if n_elements(yarr) ne sz(2) then $
image2d,data,xdescs='Index #',ydescs='Index #',zdescs=dname,/seqnm,Group=Event.top else $
image2d,data,xarr,yarr,zdescs=dname,/seqnm,Group=Event.top
endif else begin
if n_elements(yarr) eq sz(1) then begin
if n_elements(xarr) eq sz(2) then $
image2d,data,yarr,xarr,zdescs=dname,/seqnm,Group=Event.top else $
image2d,data,xdescs='Index #',ydescs='Index #',zdescs=dname,/seqnm,Group=Event.top
endif else image2d,data,xdescs='Index #',ydescs='Index #',zdescs=dname,/seqnm,Group=Event.top
end
end
end
END
'SDS_CONST_DONE': BEGIN
WIDGET_CONTROL,Event.top,/DESTROY
return
END
ENDCASE
widget_control, Event.top, set_uvalue=sds_const_state,/no_copy
END
PRO SDS_construct, GROUP=Group
if XRegistered('SDS_CONST') then return
IF N_ELEMENTS(Group) EQ 0 THEN GROUP=0
junk = { CW_PDMENU_S, flags:0, name:'' }
SDS_CONST = WIDGET_BASE(GROUP_LEADER=Group, $
ROW=1, $
MAP=1, $
TITLE='SDS CONSTRUCT MULTIPLE ARRAYS', $
UVALUE='SDS_CONST')
BASE2 = WIDGET_BASE(SDS_CONST, $
COLUMN=1, $
MAP=1, $
UVALUE='BASE2')
lab1 = widget_label(BASE2,value='Please refer SDS scroll list for data array dimension ',/align_left)
lab1 = widget_label(BASE2,value=' Only same dimension 1D/2D data can be entered together')
lab1 = widget_label(BASE2,value=' e.g. range of seq # : 47-100',/align_left)
lab1 = widget_label(BASE2,value=' e.g. comma seperated seq # : 4,5,10-15',/align_left)
lab1 = widget_label(BASE2,value=' Entered values are accepted with <CR>',/align_left)
FieldVal714 = [ $
'' ]
BASE3 = WIDGET_BASE(BASE2, /ROW, MAP=1, UVALUE='BASE3')
FIELD3 = CW_FIELD( BASE3,VALUE=FieldVal714, $
ROW=1, $
STRING=1, $
RETURN_EVENTS=1, $
TITLE='1D seq#:', $
UVALUE='SDS_CONST_1DARRAY', $
XSIZE=35)
; BUTTON3 = WIDGET_BUTTON( BASE3,UVALUE='SDS_CONST_1DARRAY',VALUE='PLOT1D... ')
BASE4 = WIDGET_BASE(BASE2, /ROW, MAP=1, UVALUE='BASE4')
FIELD4 = CW_FIELD( BASE4,VALUE='', $
ROW=1, $
STRING=1, $
RETURN_EVENTS=1, $
TITLE='2D seq#:', $
UVALUE='SDS_CONST_2DARRAY', $
XSIZE=35)
BUTTON4_1 = WIDGET_BUTTON( BASE4,UVALUE='SDS_CONST_2DARRAY2',VALUE='IMAGE2D...')
BUTTON5 = WIDGET_BUTTON( BASE2, $
UVALUE='SDS_CONST_DONE', $
VALUE='Done')
sds_const_state = { base: SDS_CONST,$
sel1ID : FIELD3, $
sel2ID : FIELD4 $
}
WIDGET_CONTROL, SDS_CONST, /REALIZE
widget_control, SDS_CONST, set_uvalue=sds_const_state
XMANAGER, 'SDS_CONST', SDS_CONST
END
PRO SDS_multi1d,seq1,seq2,seq=seq,data=data,dname=dname,error=error,echo=echo
;+
; SDS_MULTI1D,[seq1,seq2 / seq=seq] ,data=data,dname=dname[,echo=echo]
;
; Construct the 1D data array from a set of SDS 1D data.
;
; INPUT:
; seq1 - specify the start seq # for SDS 1D vector data
; seq2 - specify the end seq # for SDS 1D vector data
; KEYWORD:
; seq - list of zero based SDS seq number instead of seq1,seq2
; data - return the constructed 1D vector array
; dname - return the name attribute array for the returned vector array
; echo - plot1d to be called for constructed 1D vector array
; RESTRICTION:
; All SDS 1D vector data must be from a same scan which has the
; same dimension size.
; EXAMPLE:
; SDS_MULTI1D,seq1=6,seq2=46,/echo
;-
COMMON HDF_QUERY_BLOCK,HDF_Query,HDF_Query_id
error=0
if keyword_set(seq) eq 0 and n_elements(seq2) then begin
nd = seq2-seq1+1
seq = indgen(nd)+seq1
endif else begin
nd = n_elements(seq)
end
dname = strarr(nd)
for i=0,nd-1 do begin
SDS,v,seqno=seq(i)
sz = size(v)
if sz(0) eq 1 then begin
if i eq 0 then begin
L = 0
data = make_array(sz(1),nd)
nl = sz(1)
data(*,L) = v(*)
dname(L) = HDF_Query.tname
endif else begin
if n_elements(data) eq 0 then begin
r = dialog_message('Not 1D data selected',/error)
error=-1
return
end
if sz(1) eq nl then begin
L = L+1
data(*,L) = v(*)
dname(L) = HDF_Query.tname
end
end
end
end
if n_elements(data) eq 0 then begin
r = dialog_message('Not 1D data selected',/error)
error=-1
return
end
data = data(*,0:L)
dname = dname(0:L)
if keyword_set(echo) then plot1d,data,legend=dname
END
PRO SDS_multi2d,seq1,seq2,seq=seq,data=data,dname=dname,echo=echo
;+
; SDS_MULTI2D,[seq1,seq2 / seq=seq],data=data,dname=dname[,echo=echo]
;
; Construct the 2D iamge array from a set of SDS 2D image data.
;
; INPUT:
; seq1 - required, specify the start seq # for SDS 2D image data
; seq2 - required, specify the end seq # for SDS 2D image data
; KEYWORD:
; seq - specify list of seq # instead of range of seq1,seq2
; data - return the constructed 2D image array
; dname - return the name attribute array for the returned image array
; echo - panimage to be called for constructed 2D image array
; RESTRICTION:
; All SDS 2D image data must be from a same scan which has the
; same dimension size.
; EXAMPLE:
; SDS_MULTI2D,seq1=47,seq2=130,/echo
;-
COMMON HDF_QUERY_BLOCK,HDF_Query,HDF_Query_id
if keyword_set(seq) eq 0 then begin
nd = seq2-seq1+1
seq = indgen(nd)+seq1
endif else begin
nd = n_elements(seq)
end
dname = strarr(nd)
tvlct,r,g,b,/get
rgb = reform([r,g,b],256,3)
for i=0,nd-1 do begin
SDS,v,seqno=seq(i)
sz = size(v)
if sz(0) eq 2 then begin
if i eq 0 then begin
L = 0
data = make_array(sz(1),sz(2),nd)
nl = n_elements(v)
data(*,*,L) = v(*,*)
dname(L) = HDF_Query.tname
endif else begin
if n_elements(data) eq 0 then begin
r = dialog_message('Not 2D data selected',/error)
return
end
if n_elements(v) eq nl then begin
L = L+1
data(*,*,L) = v(*,*)
dname(L) = HDF_Query.tname
end
end
end
end
if n_elements(data) eq 0 then begin
r = dialog_message('Not 2D data selected',/error)
return
end
data = data(*,*,0:L)
dname = dname(0:L)
if keyword_set(echo) then begin
det_def = make_array(nd,value=1)
panimage,data,det_def,numd=10,detnm=dname
; panimage_sel,data,det_def,detnm=dname
end
END
PRO SDS,DATA,seqno=seqno
;+
; NAME:
; SDS
;
; PURPOSE:
; This routine allows the hdfb user to extract the desired SDS data
; array variable from the currently opened HDF/NEXUS file which can
; be any type of SDS data supported by hdfb.
;
; CALLING SEQUENCE:
; SDS, DATA [,SEQNO=i]
;
; OUTPUT:
; DATA: Variable to return the extracted SDS data array
;
; KEYWORD PARAMETERS:
; SEQNO=i: Specify the desired zero-based SDS sequence number in the
; opened HDF file, if not specified, the current SDS data
; in the core will be returned
;
; COMMON BLOCKS:
; HDF_QUERY_BLOCK
;
; SIDE EFFECTS:
; The max and min value will be shown as the default comment.
;
; RESTRICTIONS:
; The input HDF/NEXUS file must be already opened by the hdfb browser,
; and it should contains SDS data set(s) on it.
;
; EXAMPLES:
; Example 1 - Extract the current SDS set as variable 'IM'
;
; SDS, IM
;
; Example 2 - Extract the 8th set SDS from the opened HDF file
;
; SDS, DATA, seqno=7
;
;-
COMMON HDF_QUERY_BLOCK,HDF_Query,HDF_Query_id
; extract current SDS data or specified by the input seqno
if n_elements(seqno) then begin
if seqno lt HDF_Query.NUMSDS then begin
sds_id = HDF_SD_SELECT(HDF_Query.sd_id,seqno)
HDF_SD_GETINFO,sds_id, LABEL=Ti, UNIT=read_unit, NAME=n
HDF_SD_GETDATA,SDS_ID,Data
;print,'NAME=',n
HDF_Query.tname= n
HDF_SD_ENDACCESS,sds_id
;
HDF_Query.seqno = seqno
*HDF_Query.data = data
endif else begin
st = ['Error: Invalid SDS # entered!', '', $
'Valid SDS # : [0-'+strtrim(HDF_Query.NUMSDS-1,2)+']']
r = dialog_message(/error,st)
end
return
end
A = ptr_valid(1,/cast)
if n_elements(*A) eq 0 then begin
st = ['Usage: SDS, DATA [,SEQNO=i]','','where','', $
'DATA - output variable, returns the current SDS data array', $
'SEQNO=i - keyword to specify the zero-based SDS seqno']
r = dialog_message(/error,st)
return
end
DATA = *A
END
PRO SDSVGname,names
COMMON HDF_QUERY_BLOCK,HDF_Query,HDF_Query_id
if n_params() eq 0 then begin
str=['Usage: Obj->[NX::]SDSVGname, names' $
]
xdisplayfile,text=str,title='NX::SDSVGname,names'
return
end
; fid = HDF_OPEN(self.file)
fid = HDF_Query.fid
; sd_id = HDF_SD_START(self.file)
sd_id = HDF_Query.sd_id
vgroup = -1
sds_vgname = ''
for j=0,HDF_Query.numVG-1 do begin
vgroup = HDF_VG_GETID(fid,vgroup)
vg_id = HDF_VG_ATTACH(fid,vgroup)
HDF_VG_GETINFO,vg_id,class=class,name=name,nentries=num_entries
if num_entries ge 1 then begin
HDF_VG_GETTRS,vg_id,tags,refs
id = -1
for i = 0,num_entries-1 do begin
if tags(i) eq 720 then begin
seq = HDF_SD_REFTOINDEX(sd_id,refs(i))
sd_ids = HDF_SD_SELECT(sd_id,seq)
HDF_SD_GETINFO,sd_ids, name=dname
if sds_vgname(0) eq '' then $
sds_vgname = name+'=>'+dname else $
sds_vgname = [sds_vgname, name + '=>' + dname]
HDF_SD_ENDACCESS,sd_ids
end
end
end
HDF_VG_DETACH,vg_id
end
; HDF_SD_END,sd_id
; HDF_CLOSE,fid
names= sds_vgname
help,sds_vgname
print,names
END
PRO DumpHDFData, filename,startno, view=view, waittime=waittime
COMMON HDF_QUERY_BLOCK,HDF_Query,HDF_Query_id
IF N_ELEMENTS(filename) EQ 0 THEN begin
print,''
print,'DumpHDFData dumps the SDS contents of a HDF file'
print,''
print,'USAGE: DumpHDFData,filename,startno [,/view]'
print,'INPUT:'
print,' filename - required intput HDF SDS file'
print,'KEYWORD:'
print,' /VIEW - optional, if specified then the plot of data'
print,' will be displayed too'
print,''
return
end
wtime = 1.0
if keyword_set(waittime) then begin
print,waittime
if waittime gt 0.5 then wtime = waittime
end
; See if there is anything there to read
HDF_DFSD_GETINFO, filename, NSDS=NumSDS
print,'NumSDS=',NumSDS
IF NumSDS LT 1 THEN begin
Message, "No Scientific Data Sets in File"
return
end
; Find out about the first SDS
is = startno
HDF_DFSD_SETINFO, /RESTART
str = string(replicate(32b,80))
if is gt 0 then begin
for i=0,is-1 do begin
HDF_DFSD_GETDATA, filename, SData, /GET_DIMS, /GET_TYPE
end
end
;
; the new hdf_sd_ function is used instead of old HDF_DFSD
;
st0=string(replicate(32b,240))
st = [' SD # TYPE NATTR NDIMS DIMS NAME FORMAT LABEL COORDSYS UNIT DATA (***First line of print data buffer***)']
WIDGET_CONTROL,HDF_Query_id.terminal,BAD_ID=bad,SET_VALUE=st
for i=is, NumSDS-1 do begin
sds_id = HDF_SD_SELECT(HDF_Query.sd_id,i)
HDF_SD_GETINFO,sds_id,dims=d,format=fm,label=lb,natts=na,ndims=nd, $
coordsys=cs, NAME=n, $
type=ty,unit=unit
HDF_SD_GETDATA,sds_id,SData
s = size(SData)
no = s(0)
; print,'Data Set #',i,', LABEL=',lb,', UNIT=',unit & help,data
if no lt 1 then no = 1
dim = make_array(no)
dim = s(1:no)
type = s(n_elements(s)-2)
st = st0
strput,st,strtrim(i,1),3
strput,st,ty,10
strput,st,strtrim(string(na,/print),1),20
strput,st,strtrim(string(nd,/print),1),30
st1='('
for k=0,nd-1 do begin
st1 = st1+' '+strtrim(d(k),2)
end
st1=st1+ ' )'
strput,st,strtrim(st1,2),40
if strlen(n) gt 0 then strput,st,n,56
if strlen(fm) gt 0 then strput,st,fm,80
if strlen(lb) gt 0 then strput,st,lb,100
if strlen(cs) gt 0 then strput,st,cs,120
if strlen(unit) gt 0 then strput,st,unit,130
; dump only first six number from the data array
catch,error_status
if error_status ne 0 then begin
help,!error_state,/st
help,sdata
print,sdata
return
end
if n_elements(sdata) ge 6 then temps=sdata(0:5) else temps=sdata
if HDF_Query.byte eq 0 then tempdata = string(string(temps),/print) else $
tempdata = string(temps,/print)
strput,st,strtrim(tempdata(0),2),141
WIDGET_CONTROL,HDF_Query_id.terminal,BAD_ID=bad,SET_VALUE=strtrim(st,2)
if keyword_set(view) then begin
erase
chk_no = n_elements(chk)
if (chk_no-2) ge 0 then chk_type = chk(chk_no-2)
if chk_type eq 1 then vdata=string(SData) else $
vdata = string(SData,/print)
WIDGET_CONTROL,HDF_Query_id.terminal,BAD_ID=bad,SET_VALUE=vdata
Print,'Displaying SData ' + unit
CASE no OF
1: BEGIN
HDF_DFSD_DIMGET,0, LABEL=xl, UNIT=xu
y1=min(data)
y2=max(data)
dy = 0.1 * (y2-y1)
if dy eq 0 then dy = 1
if type ne 1 then begin
plot, YRANGE=[y1-dy,y2+dy], data, POS=[0.15,0.2,0.8,0.9], $
xtitle=xl+' '+xu
endif else begin
; if type eq 1 then print,string(data)
plot,[-1,-1],XStyle=4,YStyle=4
xyouts, 0.2*!d.x_size, 0.25*!d.y_size, string(data),/DEVICE
end
END
2: BEGIN
HDF_DFSD_DIMGET,0, LABEL=xl, UNIT=xu
HDF_DFSD_DIMGET,1, LABEL=yl, UNIT=yu
y1=min(data)
y2=max(data)
!p.multi(0)=!p.multi(1)
if !d.n_colors gt !d.table_size then device,decomposed=0
; TVSCL, Data
newdata = fix(float(Data-y1)/(y2-y1)*!d.table_size)
TV,congrid(newdata,!d.x_size/2,!d.y_size-20)
!p.multi(0)=!p.multi(1)-1
surface, Data, zrange=[y1,y2*1.5]
; if type eq 1 then begin
; for j=0,dim(1)-1 do begin
; str=data(0:dim(0)-1,j)
; print,string(str)
; end
; end
END
ENDCASE
XYOUTS, !d.x_size/2, !d.y_size - 20, ALIGNMENT=0.5, /DEVICE, $
STRING(title)
XYOUTS, !d.x_size/2, !d.y_size - 40, ALIGNMENT=0.5, /DEVICE, $
STRING(unit)
;
HDF_Query.seqno = i
WIDGET_CONTROL,HDF_Query_id.seqno,SET_VALUE=i
; print,'Enter <CR> to continue, enter q to stop'
WIDGET_CONTROL,HDF_Query_id.terminal,BAD_ID=bad, $
SET_VALUE='Enter <CR> to continue, enter q to stop'
st = ''
read,st
if st eq 'q' then begin
; print,' Dump stopped!'
WIDGET_CONTROL,HDF_Query_id.terminal,BAD_ID=bad, $
SET_VALUE=' Dump stopped !'
return
end
end
end
WIDGET_CONTROL,HDF_Query_id.terminal,BAD_ID=bad, $
SET_VALUE='*** End of Dump HDF SD Data!'
WIDGET_CONTROL,HDF_Query_id.terminal,BAD_ID=bad,GET_VALUE=st
openw,unit,'hdf_data.txt',/get_lun
printf,unit,st
free_lun,unit
close,unit
HDF_SD_ENDACCESS,sds_id
END
PRO hdf_search_unitstring,filename,unitstring,recno,data
COMMON HDF_QUERY_BLOCK,HDF_Query,HDF_Query_id
if strlen(strtrim(unitstring,2)) lt 1 then return
if filename ne HDF_Query.file then begin
st=['Error: You have to load the HDF file in first']
HDF_scrolltext,st,60,3
return
end
if n_elements(recno) eq 0 then recno = 1
; See if there is anything there to read
IF HDF_Query.numSDS LT 1 THEN begin
HDF_scrolltext, "No Scientific Data Sets in File"
return
end
if recno ge HDF_Query.numSDS then begin
HDF_scrolltext,'Error: there are only'+HDF_Query.numSDS+' sets of SDS data',60,3
return
end
; We need to fetch the Name of the data
found = -1
i = recno
while found eq -1 and i lt HDF_Query.numSDS do begin
sds_id = HDF_SD_SELECT(HDF_Query.sd_id,i)
HDF_SD_GETINFO, sds_id, LABEL=Title, UNIT=read_unit, NAME=nm
found = strpos(strupcase(nm),strupcase(unitstring))
if i ge HDF_Query.numSDS then begin
st=[ 'Error: Could not find Search string: ', $
' " '+unitstring + ' "', $
' in the HDF file: '+filename]
HDF_scrolltext,st,60,3
recno = -1 ; not found
HDF_SD_ENDACCESS,sds_id
return
end
if found eq -1 then i = i+1
HDF_SD_ENDACCESS,sds_id
end
recno = i+1
HDF_Query.tname= nm
HDF_Query.seqno = recno
;help,data,read_unit,Title,recno,nm,found
if found eq -1 then return
ReadHDFOneRecord,filename,data,/view
END
PRO ReadHDFOneRecord, filename, data, view=view
COMMON HDF_QUERY_BLOCK,HDF_Query,HDF_Query_id
WSET,HDF_Query_id.draw1
erase
IF N_ELEMENTS(filename) EQ 0 THEN begin
print,'USAGE: ReadHDFOneRecord, filename, data [,/view]'
print,' Read next set of SDS data from the current positon'
print,'INPUT: '
print,' filename - HDF filename'
print,'OUTPUT:'
print,' data - the SDS data array returned'
print,'KEYWORD:'
print,' /VIEW - optional, if it is specified, the data will be displayed'
print,''
return
end
if HDF_Query.seqno gt HDF_Query.maxno then begin
HDF_Scrolltext,'Error: End of SDS record reached!',60,3
HDF_Query.seqno = 0
return
end
if HDF_Query.numSDS lt 1 then begin
HDF_Scrolltext,'Error: no SDS data available!',60,3
return
end
WIDGET_CONTROL,/HOURGLASS
title=''
;=====
sds_id = HDF_SD_SELECT(HDF_Query.sd_id,HDF_Query.seqno)
HDF_SD_GETINFO,sds_id, LABEL=Ti, UNIT=read_unit, NAME=n
HDF_SD_GETDATA,SDS_ID,Data
;print,'NAME=',n
HDF_Query.tname= n
HDF_SD_ENDACCESS,sds_id
;=====
*HDF_Query.data = Data
;print,'RECNO',HDF_Query.seqno
;help,Data
if keyword_set(attr) then begin
Title = Ti
print,'___LABEL= ',Title
print,'____UNIT= ',read_unit
end
;print,data
;print,'---------'
s = size(Data)
no = s(0)
;help,s
if no gt 0 then begin
dim = make_array(no)
dim = s(1:no)
end
type = s(n_elements(s)-2)
erase
; Print,'Displaying Data ' + read_unit
xl='' & xu=''
CASE no OF
0: BEGIN
plot,[-1,-1],XStyle=4,YStyle=4
xyouts, 0.2*!d.x_size, 0.25*!d.y_size, string(data),/DEVICE
END
1: BEGIN
old_win = !d.window
!p.multi = [0,1,0,0,0]
y1=min(data)
y2=max(data)
dy = 0.1 * (y2-y1)
if dy eq 0 then dy = y1*0.1
if type ne 1 then begin
if s(1) eq 1 then begin
plot,[-1,-1],XStyle=4,YStyle=4
xyouts, 0.2*!d.x_size, 0.25*!d.y_size, string(data),/DEVICE
endif else begin
plot,YRANGE=[y1-dy,y2+dy],data,POS=[0.15,0.2,0.8,0.9], $
XStyle=1,YStyle=1
end
endif else begin
plot,[-1,-1],XStyle=4,YStyle=4
xyouts, 0.2*!d.x_size, 0.25*!d.y_size, string(data),/DEVICE
end
END
2: BEGIN
if type eq 1 then begin
plot,[-1,-1],XStyle=4,YStyle=4
yloc = 0.9*!d.y_size
for j=0,dim(1)-1 do begin
yloc = yloc - !d.y_ch_size
if yloc ge 0 then begin
str=data(0:dim(0)-1,j)
xyouts, 0.2*!d.x_size, yloc, string(str),/DEVICE
end
end
endif else begin
y1=min(data)
y2=max(data)
old_win = !d.window
!p.multi = [0,2,0,0,0]
!p.multi(0)=!p.multi(1)
if !d.n_colors gt !d.table_size then device,decomposed=0
; TVSCL, CONGRID(data,!d.x_size/2, !d.y_size-20)
newdata = fix(float(data-y1)/(y2-y1)*!d.table_size)
TV,congrid(newdata,!d.x_size/2,!d.y_size-20)
!p.multi(0)=!p.multi(1)-1
surface, Data , zrange=[y1,y2*1.5]
end
END
3: BEGIN
plot,[-1,-1],XStyle=4,YStyle=4
y1=min(data)
y2=max(data)
wide = 50
left = 30
bott = 50
space = 10+wide
ht = HDF_Query_id.draw_ysize
old_win = !d.window
!p.multi = 0
; only show first 12 images from the 3D data array
last = dim(2) - 1
if last gt 11 then last = 11
for i=0,last do begin
id = i/6
ip = i mod 6
x0 = ip*space+left
y0 = ht -left - (id+1)*space
temp = congrid(data(*,*,i),wide,wide)
TVSCL,temp,x0,y0
; temp = fix(float(temp-y1)/(y2-y1)*!d.table_size)
; TV,temp, ip*space+left, id*space+bott
end
END
ELSE: HDF_scrolltext,'No plot supported for'+string(no)+'D data',60,3
ENDCASE
str='RECNO ' + strtrim(HDF_Query.seqno,1) + ': ' + HDF_Query.tname
XYOUTS, !d.x_size/2, !d.y_size-10 , ALIGNMENT=0.5, /DEVICE, $
STRING(str), charsize=1
if keyword_set(attr) then begin
XYOUTS, !d.x_size/2, !d.y_size - 30, ALIGNMENT=0.5, /DEVICE, $
STRING(title), charsize=2
XYOUTS, !d.x_size/2, !d.y_size - 40, ALIGNMENT=0.5, /DEVICE, $
STRING(u), charsize=1
end
;
; if /VIEW is requested (separate Plot Window Option)
;
;if keyword_set(view) then begin
if HDF_Query.view eq 1 then begin
str='RECNO ' + strtrim(HDF_Query.seqno,1) + ': ' + HDF_Query.tname
sz = size(data)
old_win = !d.window
CASE no OF
0: BEGIN
plot1d,[-1,-1],XStyle=4,YStyle=4,title=title,xtitle=u
xyouts, 0.2*!d.x_size, 0.25*!d.y_size, string(data),/DEVICE
END
1: BEGIN
if type ne 1 and n_elements(data) gt 1 then begin
if HDF_Query.real and HDF_Query.naxis gt 0 then begin
if HDF_Query.naxis gt 1 then xv = *HDF_Query.yarr else $
xv = *HDF_Query.xarr
if sz(1) ne n_elements(xv) then xv = *HDF_Query.yarr
if n_elements(xv) eq sz(1) then $
plot1d,xv,data,title=str,wtitle=HDF_Query.file else $
plot1d,data,title=str,wtitle=HDF_Query.file,xtitle='Index #'
endif else begin
plot1d,data,title=str,wtitle=HDF_Query.file,xtitle='Index #'
end
endif else begin
plot1d,[-1,-1],XStyle=4,YStyle=4,title=title,xtitle=u
xyouts, 0.2*!d.x_size, 0.25*!d.y_size, string(data),/DEVICE
end
END
2: BEGIN
if HDF_Query.real and HDF_Query.naxis gt 0 then begin
nx = n_elements(*HDF_Query.xarr)
ny = n_elements(*HDF_Query.yarr)
if sz(1) eq nx and sz(2) eq ny then begin
xv = *HDF_Query.xarr
yv = *HDF_Query.yarr
end
if sz(1) eq ny and sz(2) eq nx then begin
yv = *HDF_Query.xarr
xv = *HDF_Query.yarr
end
if n_elements(xv) gt 0 then $
plot2d,data,xarr=xv,yarr=yv,itools=1,title=str,wtitle=HDF_Query.file else $
plot2d,data,itools=1,title=str,wtitle=HDF_Query.file, $
xtitle="Index #",ytitle="Index #"
endif else $
plot2d,data,itools=1,title=str,wtitle=HDF_Query.file, $
xtitle="Index #",ytitle="Index #"
END
3: BEGIN
xv = indgen(sz(1))
yv = indgen(sz(2))
zv = indgen(sz(3))
if HDF_Query.naxis gt 0 then begin
if sz(2) eq n_elements(*HDF_Query.xarr) then yv = *HDF_Query.xarr
if sz(3) eq n_elements(*HDF_Query.yarr) then zv = *HDF_Query.yarr
end
view3d_2d,data,0,xv,yv,zv,title=str ; ,/slicer3
END
ELSE: HDF_scrolltext,['Sorry, currently there is no separate plot window','supported for this type of data.'],60,3
ENDCASE
WSET,old_win
end
END
;
; convert byte array to strings
;
PRO BytesToStrings,inbyte,outstring,lrecl=lrecl,print=print
if n_elements(inbyte) eq 0 then begin
print,''
print,"BytesToStrings routine converts a byte array to a string array"
print," with the user specifyable lrecl."
print,''
print,"USAGE: BytesToStrings, inbyte, outstring [,lrecl=#,/print]
print,"INPUT:"
print,' inbyte - input byte array, required'
print,'OUTPUT:'
print,' outstring - output string array'
print,'KEYWORD:
print,' LRECL=# - specifies the output string length,'
print,' # default to 80 if not specified.'
print,' /PRINT - print the string array generated'
print,''
return
end
len = 80
if n_elements(lrecl) gt 0 then len = lrecl
s = size(inbyte)
no = s(1)/len
if s(1) gt (no*len) then no = no +1
outstring = make_array(no,/string,value=string(replicate(32b,len)))
for i=0,no-1 do begin
i1 = i*len & i2 = i1 + len - 1
if i2 gt (s(1)-1) then i2 = s(1)-1
outstring(i) = string(inbyte(i1:i2))
if keyword_set(print) then print,outstring(i)
end
END
;
; hdf_datatotext.pro
;
PRO subarray,data,y1,y2,x1,x2,newdata
if n_elements(data) eq 0 then begin
print,''
print,'SUBARRAY extracts a subarray from a given array'
print,''
print,'USAGE: subarray, data, y1, y2, x1, x2, newdata'
print,''
print,'INPUT:
print,' data - Input array
print,' y1 - Dimension 1 start index
print,' y2 - Dimension 1 end index
print,' x1 - Dimension 2 start index
print,' x2 - Dimension 2 end index
print,'OUTPUT:'
print,' newdata - Extracted sub-array
print,''