-
Notifications
You must be signed in to change notification settings - Fork 0
/
NX__define.pro
2789 lines (2518 loc) · 80.5 KB
/
NX__define.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.
;*************************************************************************
;
; NX__define.pro
;
PRO NX::debug,on
; turn debug on/off with on equals 1/0
;+
; NAME:
; NX::DEBUG
;
; PURPOSE:
; This method turns on/off the display of the various NX methods.
;
; CALLING SEQUENCE:
; Obj->[NX::]Debug, On
;
; INPUT:
; On: Specifies display output on or off. On defaults to 1 implies
; debug is on. If 0 no display of the output will be shown.
;
; KEYWORDS:
; NOWIN: If specified, only the ASCII files will be created but the
; xdisplayfile window will not be shown.
;
; EXAMPLE:
; Turn the display of method output on for the NX HDF object v.
;
; v->Debug,1
;
; MODIFICATION HISTORY:
; Written by: Ben-chin Cha, Jun 19, 1998.
; xx-xx-xxxx comment
;-
self.debug = on
END
PRO NX::User,user_id,user_name,user_email
;+
; NAME:
; NX::USER
;
; PURPOSE:
; This method allows the NX user to get the user_id, user_name,
; and user_email from the Unix operating system.
;
; CALLING SEQUENCE:
; Obj->[NX::]User [,User_id, User_name, User_email]
;
; OUTPUT:
; User_ID: returns the user_id based on the system mailalias file
; User_name: returns the user_name corresponding to user_id
; User_email: returns the user_email corresponding to user_id
;
; KEYWORDS:
; None.
;
; RESTRICTION:
; The method uses the Unix command malias and the /home/oxygen/etc/mailalias
; file automaically figuring out the user_id, user_name, and user_email.
; For non Unix system it may need modification
;
; EXAMPLE:
; The NX object v only need to be defined once for a given HDF file in
; whole IDL session.
;
; v = obj_new('NX',file='1.hdf')
; v->User,user_id,user_name,user_email
;
; MODIFICATION HISTORY:
; Written by: Ben-chin Cha, May 4, 1998.
; xx-xx-xxxx comment
;-
;
user_name = ''
user_email = ''
user_id = getenv('USER') + '@'
CATCH, error_status
if error_status lt 0 then return
spawn,['malias',user_id],/NOSHELL, listing
ml = listing(2)
l2 = strpos(ml,user_id)
len = strlen(ml)
user_name = strtrim(strmid(ml,0,29),2)
user_email = strmid(ml,l2(0),len(0)-l2(0))
if strlen(user_name) gt 0 then self.user_name = user_name
if strlen(user_email) gt 0 then self.user_email = user_email
if self.debug then begin
print,'user_name: ',user_name
print,'user_email: ',user_email
end
END
PRO NX::Putfid,fids,file=file
;+
; NAME:
; NX::PUTFID
;
; PURPOSE:
; This method allows the user to add string array of file annotations to a
; HDF file.
;
; CALLING SEQUENCE:
; Obj->[NX::]Putfid, Fids [,File=file]
;
; INPUt:
; Fids: File annotation string array to be added to an NX HDF file.
;
; KEYWORDS:
; FILE: Specifies the destination HDF file instead of the default
; NX object.
;
; EXAMPLE:
; The NX object v needs to be defined for a HDF file if it is not
; defined yet in the IDL session.
;
; fids = ['This is the file annotation array.', $
; 'More lines of text....']
; v->Putfid,fids
;
; MODIFICATION HISTORY:
; Written by: Ben-chin Cha, Jun 19, 1998.
; xx-xx-xxxx comment
;-
;
filename = self.file
if keyword_set(file) then filename = file
if HDF_ISHDF(filename) eq 0 then begin
str = ['File: '+filename,'','Error: it is not a HDF file!']
xdisplayfile,text=str,title='NX::Putfid'
return
end
if n_elements(fids) eq 0 then begin
str = ['Usage: Obj->[NX::]Putfid, Fids [,File=file]', '',$
' Add file annotations to an existing HDF file.','', $
'INPUT:',$
' Fids - string array for file annotation', $
'KEYWORD:',$
' FILE - overrides the default destination HDF file']
xdisplayfile,text=str,title='NX::Putfid'
return
end
fid = HDF_OPEN(filename,/RDWR)
nfids = n_elements(fids)
for i=0, nfids-1 do begin
HDF_DFAN_ADDFID, filename, fids(i)
end
HDF_CLOSE,fid
END
PRO NX::Getfid,fids,file=file, nowin=nowin
;+
; NAME:
; NX::GETFID
;
; PURPOSE:
; This method allows the user to get string array of file annotations from
; the given NX HDF object or from a specified HDF file.
;
; CALLING SEQUENCE:
; Obj->[NX::]Getfid, Fids [,File=file]
;
; OUTPUT:
; Fids: Variable returns the file annotation string array.
;
; KEYWORDS:
; File: If specified, the given HDF file name override the default
; NX object file.
; Nowin: If specified, the popup window is suppressed.
;
; EXAMPLE:
; Obtains the file annotation for the NX object v.
;
; v->Getfid,fids
;
; MODIFICATION HISTORY:
; Written by: Ben-chin Cha, Jun 19, 1998.
; xx-xx-xxxx comment
;-
; get all file annotations
;
filename = self.file
if keyword_set(file) then filename=file
str0 = 'File: '+filename
fid = HDF_OPEN(filename)
if fid eq -1 then begin
xdisplayfile,text=[str0, '', 'Failed to open HDF file.']
return
end
HDF_DFAN_GETFID, filename, ids,/FIRST
if ids eq '' then begin
fids = [str0,'','NO File Annotation found']
endif else begin
fids=[str0,'','File Annotations:',ids]
while (ids ne '') do begin
HDF_DFAN_GETFID, filename, ids
fids = [fids,ids]
endwhile
end
HDF_CLOSE,fid
if self.debug then $
xdisplayfile,text=fids,title='NX::getfid,fids'
END
PRO NX::PutAttr,attr_name,attr_data,sds_name=sds_name,s_id=s_id,output=output,nowin=nowin
;+
; NAME:
; NX::PUTATTR
;
; PURPOSE:
; This method writes the global or SDS data attibute.
;
; CALLING SEQUENCE:
; Obj->[NX::]PutAttr, Attr_name, Attr_data [,Sds_name=sds_name]
; [,Output=output]
;
; INPUT:
; Attr_name: Specifies the attribute name to be written
; Attr_data: Specifies the attribute data to be written
;
; KEYWORDS:
; S_ID: Specifies the SD interface ID as returned by HDF_SD_START
; for global attribute, or HDF_SD_SELECT/HDF_SD_CREATE for
; SDS attribute. If S_ID is given, the SDS_name is ignored.
; SDS_name: Specifies the SDS set to be tagged, if not specified then
; writing the global attribute is assumed
; Output: If specified, it returns the output strings
; Nowin: If specified, no info window pops up
;
; EXAMPLE:
; Find the SDS data set name 'temperature', then tag with the attr_name
; 'primary' and attr_data of 1 for the HDF NX object v.
; The NX object v needs to be defined for a HDF file if it is not
; defined yet in the IDL session.
;
; attr_name = 'primary'
; attr_data = 1
; v->PutAttr,attr_name,attr_data,sds_name='temperature'
;
; MODIFICATION HISTORY:
; Written by: Ben-chin Cha, Jun 19, 1998.
; xx-xx-xxxx comment
;-
;
out1='NX::PutAttr'
if n_params() eq 0 then begin
str = ['Usage: Obj->[NX::]PutAttr, Attr_name, Attr_data [,S_id=s_id,sds_name=sds_name, Output=output,/Nowin] ','', $
'This method writes the global or SDS data attribute','',$
'INPUT', $
' Attr_name - attribute name ', $
' Attr_data - attribute data ', $
'KEYWORD', $
' S_ID - Specifies the SD interface ID as returned by HDF_SD_START', $
' for global, or HDF_SD_SELECT/HDF_SD_CREATE for SDS',$
' Sds_name - if specified, tags the specified SDS with attribute', $
' Nowin - if specified, no info window pops up', $
' Output - if specified, returns the info strings']
xdisplayfile,text=str,title=out1
return
end
filename = self.file
sd_id = hdf_sd_start(filename,/RDWR)
if keyword_set(s_id) then begin
; tag if sds_id is given
sds_id = long(s_id)
HDF_SD_ATTRSET,sds_id,attr_name,attr_data
index = HDF_SD_ATTRFIND(sds_id,attr_name)
if index ne -1 then begin
HDF_SD_ATTRINFO,sds_id,index,name=name,count=len,type=ty,data=data
end
output='Add attribute with Name : '+attr_name
goto, final_step
end
if keyword_set(sds_name) then begin
self->FindSDS,sds_name,seq,ref
sds_id = HDF_SD_SELECT(sd_id,seq)
HDF_SD_ATTRSET,sds_id,attr_name,attr_data
index = HDF_SD_ATTRFIND(sds_id,attr_name)
if index ne -1 then begin
HDF_SD_ATTRINFO,sds_id,index,name=name,count=len,type=ty,data=data
end
HDF_SD_ENDACCESS,sds_id
output='Add SDS attribute with Name : '+attr_name
endif else begin
HDF_SD_ATTRSET,sd_id,attr_name,attr_data
index = HDF_SD_ATTRFIND(sd_id,attr_name)
if index ne -1 then begin
HDF_SD_ATTRINFO,sd_id,index,name=name,count=len,type=ty,data=data
end
output='Add global attribute with Name : '+attr_name
end
final_step:
HDF_SD_END, sd_id
help,name,ty,len,data,output=out
output = [output,'' , out]
out = [string(string(data),/print)]
output = [output,'' , out]
if self.debug eq 0 or keyword_set(nowin) then return
xdisplayfile,text=output,title=out1
END
PRO NX::Getattr,name,data,S_id=s_id,output=output,nowin=nowin
;+
; NAME:
; NX::GETATTR
;
; PURPOSE:
; This method allows the user to get global or SDS attribute data for
; a specified attribute name from the NX HDF object.
;
; CALLING SEQUENCE:
; Obj->[NX::]Getattr, Name, Data [,S_id=s_id, Output=output]
;
; INPUT:
; Name: Attribute name to search for
;
; OUTPUT:
; Data: Returns the corresponding global attribute data
;
; KEYWORDS:
; S_ID: Specifies the SD interface ID as returned by HDF_SD_START
; for global, or HDF_SD_SELECT/HDF_SD_CREATE for SDS
; Output: Detailed info about the found attribute.
; Nowin: If specified, no info window pops up
;
; EXAMPLE:
; Example 1 finds the global attribute 'owner_name' for the NX object v.
; The NX object v needs to be defined for a HDF file if it is not
; defined yet in the IDL session.
;
; v->Getattr,'owner_name',data
;
; Example 2 finds the global attribute 'owner_name' using the S_id keyword:
;
; sd_id = hdf_sd_start(filename)
; v->Getattr,'owner_name',data,S_id=sd_id
;
; Example 3 finds the attribute data of the third set of SDS with
; attribute name 'primary' using the S_id keyword:
;
; sd_id = hdf_sd_start(filename)
; sds_id = hdf_sd_select(sd_id,2)
; v->Getattr,'primary',data, S_id=sds_id
;
; MODIFICATION HISTORY:
; Written by: Ben-chin Cha, Jun 19, 1998.
; xx-xx-xxxx comment
;-
;
out1='NX::getattr,name,data'
if n_params() eq 0 then begin
str = ['Usage: Obj->[NX::]GetAttr, Name, Data [,S_id=s_id, Output=output]','', $
'This method gets the global attribute for a given attribute name','',$
'INPUT', $
' Name - attribute name to search for', $
'OUTPUT', $
' Attdata - attribute data found for the given name', $
'KEYWORD', $
' S_ID - Specifies the SD interface ID as returned by HDF_SD_START', $
' for global, or HDF_SD_SELECT/HDF_SD_CREATE for SDS',$
' Nowin - no info window pops up if specified', $
' Output - detailed info about the found attibute data']
xdisplayfile,text=str,title=out1
return
end
data = ''
filename = self.file
if keyword_set(s_id) then begin
sd_id = long(s_id)
index = hdf_sd_attrfind(sd_id,name)
if index ne -1 then begin
hdf_sd_attrinfo,sd_id,index,name=nm,count=len,type=ty,data=data
end
output='Find attribute with Name : '+name
goto,final_step
end
sd_id = hdf_sd_start(filename,/rdwr)
index = hdf_sd_attrfind(sd_id,name)
if index ne -1 then begin
hdf_sd_attrinfo,sd_id,index,name=nm,count=len,type=ty,data=data
end
HDF_SD_END, sd_id
output='Find global attribute with Name : '+name
final_step:
help,nm,ty,len,data,output=out
output = [output,'' , out]
if self.debug eq 0 or keyword_set(nowin) then return
xdisplayfile,text=output,title=out1
END
PRO NX::Open,filename, gname=gname, gclass=gclass, $
create=create, append=append, $
location = location, $
user_name = user_name, $
user_email = user_email, $
user_phone = user_phone, $
user_fax= user_fax, $
program_name = program_name
;+
; NAME:
; NX::OPEN
;
; PURPOSE:
; This method opens any existing HDF or creates a new NX HDF file.
;
; CALLING SEQUENCE:
; Obj->[NX::]Open, File [, Gname=gname] [,Gclass=gclass]
; [,Program_name=program_name] [,Location=location]
; [,User_name=user_name] [,User_email=user_email]
; [,User_fax=user_fax] [,User_phone=user_phone ]
;
; INPUT:
; File: Specifies the HDF file name to be opened.
;
; KEYWORDS:
; Following keywords are used in NX HDF file creation.
;
; Create: It is required if the new HDF file to be created
; Gname: Specifies entry group name, default to 'entry_default'
; Gclass: Specifies entry group class name, default to 'NXdefault'
; Program_name: HDF file associated with program name
; Location: Experimental location, default to 'APS'
; User_name: Owner name, from the unix system malias
; User_email: Owner email address, from the unix system malias
; User_fax: Owner fax number
; User_phone: Owner phone number
;
; EXAMPLE:
; Example 1 creates the HDF file '1.hdf' with the default settings if
; file does not exist yet.
;
; v->Open,'1.hdf'
;
; MODIFICATION HISTORY:
; Written by: Ben-chin Cha, Jun 19, 1998.
; xx-xx-xxxx comment
;-
if n_elements(filename) eq 0 then begin
str = ['Usage: Obj->[NX::]Open, File, Gname=gname, Gclass=gclass,...', $
'','This method opens the HDF file specified by the filename. ',$
'If the entered file does not exist yet it will be created, the global ', $
'attribute and fileid description will be added based on the keyword', $
'specification. On the Unix system, if the keywords are not specified, ' ,$
'the appropriate default will be automatically figured out.', $
'','INPUT', $
' File - HDF file name', $
'KEYWORD', $
' Append - add new SDS or Group to the file', $
' Create - required, if a new hdf file to be created', $
' Gname - Default entry group name, e.g. entry_default', $
' Gclass - Default entry group class name, e.g. NXdefault', $
' Program_name - Associated program name', $
' location - Experimental location, default to APS', $
' User_name - Owner name, from the unix system malias ', $
' User_email - Owner email address, from the unix system malias', $
' User_fax - Owner fax number', $
' User_phone - Owner phone number']
xdisplayfile,text=str,title='NX::Open,file'
return
end
time0 = systime(1)
found = findfile(filename)
if found(0) eq '' then begin
; if gname gclass not given the APS default is assumed
; this section only hold true for aps
;
if keyword_set(gname) then default_entry = gname else $
default_entry='entry_default'
if keyword_set(gclass) then default_class = gclass else $
default_class='NXdefault'
if keyword_set(location) eq 0 then location = 'APS'
if keyword_set(program_name) eq 0 then $
program_name = self.version
if keyword_set(user_phone) then self.user_phone = user_phone else $
self.user_phone = ''
if keyword_set(user_name) then self.user_name = user_name else $
self.user_name = ''
if keyword_set(user_email) then self.user_email = user_email else $
self.user_email = ''
if keyword_set(user_fax) then self.user_fax = user_fax else $
self.user_fax = ''
self.file = filename
fid = HDF_OPEN(filename,/ALL)
HDF_CLOSE,fid
fid = HDF_OPEN(filename,/RDWR)
self.fid = fid
; Write global attributes only once
if self.user_name eq '' then begin
self->user,u_id,u_nm,u_em
self.user_name = u_nm
self.user_email = u_em
end
self->global_attribute
; Write the default entry & class
sd_id = HDF_SD_START(filename,/RDWR)
vg_id = HDF_VG_ATTACH(fid,-1,/WRITE)
HDF_VG_SETINFO,vg_id,name=default_entry,class=default_class
; write program_name attribute to the top group
; vg_tag = 1965
vg_tag = self.vg_tag
if strlen(location) gt 0 then begin
self->PutSDS,sid=sd_id,name='location',byte(location),index,ref
HDF_VG_ADDTR,vg_id,vg_tag,ref
end
if strlen(program_name) gt 0 then begin
self->PutSDS,sid=sd_id,name='program_name',byte(program_name),index,ref
HDF_VG_ADDTR,vg_id,vg_tag,ref
end
HDF_VG_DETACH,vg_id
HDF_SD_END,sd_id
print,'filename=',filename, ' created'
endif else begin
; print,'filename=',filename ,' already exists!'
if HDF_ISHDF(filename) eq 0 then begin
str = ['File: '+filename,'','Error: it is not a HDF file !']
xdisplayfile,text=str,title='NX::Open,filename'
return
end
if self.fid gt 0 then self->close
if keyword_set(append) then fid = HDF_OPEN(filename,/RDWR) else $
fid = HDF_OPEN(filename)
self.fid = fid
if self.debug eq 0 then return
time1 = systime(1)
print,'HDF open used time = ',time1-time0, ' seconds.'
end
END
PRO NX::global_attribute,user_name=user_name,user_mail=user_mail, $
user_email=user_email,user_phone=user_phone,user_fax=user_fax,$
user_history=user_history,user_desc=user_desc
; global attribute created by NX class including the following :
; owner_name, owner_mail,owner_email, owner_phone, owner_fax
; file_name, version, file_history
;+
; NAME:
; NX::GLOBAL_ATTRIBUTE
;
; PURPOSE:
; This method writes a new set of global attributes: file_name,
; version, owner_name, owner_mail, owner_email,owner_phone,
; owner_fax, file_history, experiment_description for the HDF
; file. If the HDF file is created by the NX object initialization
; which automatically calls this method.
;
; CALLING SEQUENCE:
; Obj->[NX::]Global_attribute
;
; ARGUMENTS:
; None.
;
; KEYWORDS:
; User_name Updates the user name if specified.
; User_mail Updates the user mail address if specified.
; User_email Updates the user email address if specified.
; User_phone Updates the user phone number if specified.
; User_fax Updates the user fax number if specified.
; User_history Updates the file history if specified.
; User_desc Updates file description if specified.
;
; RESTRICTION
; The total number of lines of description can not exceeds 100.
; Every set of global attribute includes owner's name, mail,email,
; phone, fax, history, and description.
;
; EXAMPLE:
; The NX object v needs to be defined for a HDF file if it is not
; defined yet in the IDL session.
;
; descs = ['line1 ...','line2...', ...]
; v->[NX::]Global_attribute,user_desc=descs,user_name='...'
;
; MODIFICATION HISTORY:
; Written by: Ben-chin Cha, Jun 19, 1998.
; xx-xx-xxxx comment
;-
filename = self.file
if HDF_ISHDF(filename) eq 0 then return
if keyword_set(user_name) then self.user_name = user_name
if keyword_set(user_mail) then self.user_mail = user_mail
if keyword_set(user_email) then self.user_email = user_email
if keyword_set(user_phone) then self.user_phone = user_phone
if keyword_set(user_fax) then self.user_fax = user_fax
if keyword_set(user_history) then $
self.user_history = self.user_history +string(10b)+ user_history
default:
sd_id = HDF_SD_START(filename,/RDWR)
HDF_SD_ATTRSET,sd_id,'file_name',filename
if self.version ne '' then $
HDF_SD_ATTRSET,sd_id,'version',self.version
if self.user_name ne '' then $
HDF_SD_ATTRSET,sd_id,'owner_name',self.user_name
if self.user_mail ne '' then $
HDF_SD_ATTRSET,sd_id,'owner_mail',self.user_mail
if self.user_email ne '' then $
HDF_SD_ATTRSET,sd_id,'owner_email',self.user_email
if self.user_phone ne '' then $
HDF_SD_ATTRSET,sd_id,'owner_phone',self.user_phone
if self.user_fax ne '' then $
HDF_SD_ATTRSET,sd_id,'owner_fax',self.user_fax
if self.user_history ne '' then $
HDF_SD_ATTRSET,sd_id,'file_history',self.user_history
HDF_SD_FILEINFO,sd_id,NumSDS,NumGAttr
HDF_SD_END,sd_id
; write file desc
if keyword_set(user_desc) then begin
crt = 10b ; linefeed
str = 'Owner Name: '+ self.user_name
descs = str
str = 'Owner Mail: '+ self.user_mail
descs = [descs,str]
str = 'Owner_email: ' + self.user_email
descs = [descs,str]
str = 'Owner_phone: ' + self.user_phone
descs = [descs,str]
str = 'Owner_fax: ' + self.user_fax
descs = [descs,str]
str = 'File_history :' + self.user_history
descs = [descs,str]
str = 'Experiment_description: '
descs = [descs,str]
descs = [descs , user_desc]
descs = descs + string(crt)
self.desc_nline = n_elements(descs)
self.user_desc = descs
self->putfid,self.user_desc(0:self.desc_nline - 1)
end
END
PRO NX::Close
;+
; NAME:
; NX::CLOSE
;
; PURPOSE:
; This method closes the currently opened HDF file by the NX object.
;
; CALLING SEQUENCE:
; Obj->[NX::]Close
;
; ARGUMENTS:
; None.
;
; KEYWORDS:
; None.
;
; EXAMPLE:
; Close the HDF file opened by the NX object v.
;
; v->Close
;
; MODIFICATION HISTORY:
; Written by: Ben-chin Cha, Jun 19, 1998.
; xx-xx-xxxx comment
;-
time2 = systime(1)
;HDF_SD_END,self.sd_id
if self.fid gt 0 then hdf_close,self.fid
self.fid = -1
if self.debug eq 0 then return
time3 = systime(1)
print,'HDF close used time = ',time3-time2, ' seconds.'
END
PRO NX::PutSDS, file=file, data, name=name, index, ref, $
sid=sid, range=range, unit=unit, format=format, $
coordsys=coordsys, label=label, caldata=caldata, fill=fill
;+
; NAME:
; NX::PUTSDS
;
; PURPOSE:
; This method allows the user to add a SDS data with few possible
; predefined data attributes. The destination file can be default NX
; object file or any valid HDF file specified by the keyword File.
;
; CALLING SEQUENCE:
; Obj->[NX::]PutSDS, Data,index,ref, Name=name, File=file, Range=range,
; Unit=unit, Format=format, Coordsys=coordsys, Label=label,
; Caldata=caldata, Fill=fill
;
; INPUT:
; Data: Scientific data set can be any of byte, short, long, float,
; double array.
;
; OUTPUT:
; Index: Created SD dataset index number
; Ref: SD reference number
;
; KEYWORDS:
; Sid: Specifies the opened SD interface ID for writing
; Name: Specifies the name attribute for SD data
; File: Specifies destination file, defaults to NX object file
; Range: Scientific data range [min,max]
; Unit: String
; Format: String
; Coordsys: String
; Label: String
; Caldata: Calibration array
; Fill: Fill data
;
; RESTRICTION:
; If no sid interface is used, the proper SD interface startup and closing
; is automatically taking cared by putSDS.
;
; If sid interface is used a user has to open the file with HDF_SD_START
; with /RDWR option before calling putSDS. At the end of all putSDS, a
; user has to explicitly close the SD interface by calling the HDF_SD_END.
;
; EXAMPLE:
; Example 1 write the image array to the HDF file opened by the NX object v.
;
; image=....
; v->PutSDS,image,name='Image_1'
;
; Example 2 write few image arrays to the HDF file opened by the NX object v
; through using the SD interface ID.
;
; sd_id = HDF_SD_START(self.file,/RDWR)
; v->PutSDS,Sid=sd_id,image1,name='Image_1'
; v->PutSDS,Sid=sd_id,image2,name='Image_2'
; v->PutSDS,Sid=sd_id,image3,name='Image_3'
; HDF_SD_END,sd_id
;
; MODIFICATION HISTORY:
; Written by: Ben-chin Cha, Jun 19, 1998.
; xx-xx-xxxx comment
;-
; write SD to any HDF file
;
str=['Usage: Obj->[NX::]PutSDS, Data, Name=name, File=file, ...','', $
'This method write SD data with given name to a destination HDF file', $
'Data can be byte, short, long, float, double array.' ,'' $
]
str=[str,' INPUT:']
str=[str,' Data - SD data to be written']
str=[str,' OUTPUT:']
str=[str,' Index - created SD dataset index number ']
str=[str,' Ref - SD reference number']
str=[str,' KEYWORD:']
str=[str,' Sid - Uses currently opened SD interface ID for writing']
str=[str,' Name - specifies the name attribute for SD data']
str=[str,' File - specifies destination file, defaults to NX object file']
str=[str,' Range - [min,max]']
str=[str,' Unit - string']
str=[str,' Format - string']
str=[str,' Coordsys - string']
str=[str,' Label - string']
str=[str,' Caldata - calibration array']
str=[str,' Fill - fill data']
if n_params() lt 1 then begin
xdisplayfile,text=str,title='NX::PutSDS,data,file=file,...'
return
end
if keyword_set(sid) eq 0 then begin
filename = self.file
if keyword_set(file) then filename = file
if HDF_ISHDF(filename) eq 0 then begin
str = ['File :'+filename, '', 'Error: it is not a HDF file!']
xdisplayfile,text=str,title='NX::PutSDS,data,file=file,...'
return
end
if n_elements(name) eq 0 then begin
str = ['Error:', 'Name attribute is required for this routine.','',$
str]
xdisplayfile,text=str,title="NX::PutSDS,data,Name=name,..."
return
end
sd_id = HDF_SD_START(filename,/RDWR)
endif else sd_id = sid
; write data
varName=string(name)
s = size(data)
num = n_elements(s)
type = s(num-2)
no = s(0)
if no gt 0 then dim = s(1:no) else dim = [s(num-1)]
CASE type OF
0: begin
print,'Undefined should never happened'
return
end
1: begin
sds_id = HDF_SD_CREATE(sd_id,varName,dim,/BYTE)
end
2: begin
sds_id = HDF_SD_CREATE(sd_id,varName,dim,/SHORT)
end
3: begin
sds_id = HDF_SD_CREATE(sd_id,varName,dim,/LONG)
end
4: begin
sds_id = HDF_SD_CREATE(sd_id,varName,dim,/FLOAT)
end
5: begin
sds_id = HDF_SD_CREATE(sd_id,varName,dim,/DOUBLE)
end
else: begin
print,'HDF_SD_WRITE Error: type not supported ',type
return
end
ENDCASE
if keyword_set(caldata) ne 0 then $
HDF_SD_SETINFO,sds_id,caldata=caldata
if keyword_set(range) ne 0 then $
HDF_SD_SETINFO,sds_id,range=range
if keyword_set(label) ne 0 then begin
if strlen(label) gt 0 then $
HDF_SD_SETINFO,sds_id,label=label
end
if keyword_set(format) ne 0 then begin
if strlen(format) gt 0 then $
HDF_SD_SETINFO,sds_id,format=format
end
if keyword_set(unit) ne 0 then begin
if strlen(unit) gt 0 then $
HDF_SD_SETINFO,sds_id,unit=unit
end
if keyword_set(coordsys) ne 0 then begin
if strlen(coordsys) gt 0 then $
HDF_SD_SETINFO,sds_id,coordsys=coordsys
end
if keyword_set(fill) ne 0 then begin
if strlen(fill) gt 0 then $
HDF_SD_SETINFO,sds_id,fill=fill
end
HDF_SD_ADDDATA,sds_id,data
ref = HDF_SD_IDTOREF(sds_id)
index = HDF_SD_REFTOINDEX(sd_id,ref)
HDF_SD_ENDACCESS,sds_id
if keyword_set(sid) then return
HDF_SD_END,sd_id
END
PRO NX::FindVg,seq,gid,output=str,name=name,class=class,nowin=nowin,seq_start=seq_start,seq_end=seq_end
;+
; NAME:
; NX::FINDVG
;
; PURPOSE:
; This method searches and prints out all the VGroups found which
; satisfy the search condition. The search condition can either
; by group name / group classname / group name and classname.
; This method can return the group sequence and groupid reference
; arrays.
;
; CALLING SEQUENCE:
; Obj->[NX::]FindVg, Seq, Gid, Name=name, Class=class, Output=output
;
; OUTPUT:
; Seq: Returns the array of matched group sequence id
; Gid: Returns the array of matched group reference id
;
; KEYWORDS:
; Seq_start: Specifies the start search group sequence #
; Seq_end: Specifies the end search group sequence #
; Name: Specifies the group name to search for
; Class: Specifies the class name to search for
; Output: If specified, it returns the output strings. If debug option
; is set the output display will be automatically popped up.
; Nowin: Suppresse the output window
;
; RESTRICTIOM
; The NX HDF file will be closed and re-opened by this method. This will
; gaurantee that the newly added groups will be found too.
;
; EXAMPLE:
; Example 1 finds the group seq numbers where group name contains the search
; string 'reactor'. Variable V is a previously defined NX HDF object.
;
; v->FindVg, name='reactor', seq, ref
;
; Example 2 finds the NX group seq numbers where group name contains the search
; string 'reactor' and class name contains the search string 'NXreactor'
;
; v->FindVg, name='reactor', class='NXreactor', seq, ref
;
; MODIFICATION HISTORY:
; Written by: Ben-chin Cha, Jun 19, 1998.
; xx-xx-xxxx comment
;-
; seq - sequence array for matched found
; gid - group ref array for the file
; given name and/or class string find the matched groups
; return found group ids
search = 0
if keyword_set(name) and keyword_set(class) then search = 3
if keyword_set(name) then search = 1
if keyword_set(class) then search = 2
if search eq 0 then begin