source: trunk/bindings/swig/nxintertest.tcl @ 1822

Revision 211, 4.6 KB checked in by nexus, 9 years ago (diff)
  • Fixed a bug which caused foreign HDF-5's not to be read properly
  • Fixed a bug in NXgetnextentry which prevented reinitialising searches and nested searches.
  • Adapted the jnexus stuff to NAPI-2.0
  • Added the swig interface to NeXus to the source tree
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1#-------------------------------------------------------------------------
2# Test program for the nxinter interface. Also example usage.
3#
4# copyright: GPL
5#
6# Mark Koennecke, October 2002
7#------------------------------------------------------------------------
8
9#load ./nxinter.so
10
11#------------- testing dataset interface
12set ds [create_nxds 2 $NX_FLOAT32 3 3]
13
14put_nxds_value $ds 1 0 0
15put_nxds_value $ds 1 1 1
16put_nxds_value $ds 1 2 2
17
18puts stdout "Testing dataset interface "
19puts stdout [format "rank = %d" [get_nxds_rank $ds]]
20puts stdout [format "type = %d" [get_nxds_type $ds]]
21puts stdout [format "dim1 = %d" [get_nxds_dim $ds 1]]
22
23proc printDS {ds} {
24for {set i 0} {$i < 3} {incr i} {
25    puts stdout " "
26    for {set j 0} {$j < 3} {incr j} {
27        puts -nonewline stdout [format " %f" [get_nxds_value $ds $i $j]]
28    }
29}
30puts stdout "     "
31}
32
33printDS $ds
34puts stdout "Hmmmmmmmhhh....... seems OK"
35
36#-------------- prepare a dimension dataset 
37set dimds [create_nxds 1 $NX_INT32 2]
38put_nxds_value $dimds 3 0
39put_nxds_value $dimds 3 1
40
41#--------- prepare slabbing slabber dimensions
42set start [create_nxds 1 $NX_INT32 2]
43put_nxds_value $start 0 0
44put_nxds_value $start 0 1
45
46
47#----------------------------------- write tests
48puts stdout "Testing writing ..........."
49
50set fd [nx_open "nxinter.hdf" $NXACC_CREATE5]
51puts stdout [format "Opening file worked: %s" $fd]
52
53#---------- write an attribute.....
54set tds [create_text_nxds "Rosa Waschmaschinen sind hip"]
55puts stdout [format "Writing SuperDuper = %s" [get_nxds_text $tds]]
56puts stdout [format "Writing attribute results in: %d " \
57        [nx_putattr $fd "SuperDuper" $tds]]
58drop_nxds $tds
59
60#----------- making groups....
61set status [nx_makegroup $fd fish NXentry]
62if {$status == 1} {
63    puts stdout "Creating vGroup worked"
64}
65
66set status [nx_opengroup $fd fish NXentry]
67if {$status == 1} {
68    puts stdout "Opening vGroup worked"
69}
70
71set lnk [nx_getgroupID $fd]
72puts stdout [format "groupID determined to: %s" $lnk]
73
74#------------ writing tata
75puts stdout "Test Writing data....."
76puts stdout [nx_makedata $fd "fish" 2 $NX_FLOAT32 $dimds]
77puts stdout [nx_opendata $fd "fish"]
78puts stdout [nx_putdata $fd $ds]
79set lnk [nx_getdataID $fd]
80puts stdout $lnk
81puts stdout [nx_closedata $fd]
82
83#--------------- testing slabbed tata writing
84puts stdout "Testing  writing in slabs"
85put_nxds_value $dimds 6 0
86puts stdout [format "Dimensions for slab test: %f, %f"  \
87        [get_nxds_value $dimds 0] [get_nxds_value $dimds 1]]
88 
89puts stdout [nx_makedata $fd "fish2" 2 $NX_FLOAT32 $dimds]
90puts stdout [nx_opendata $fd "fish2"]
91puts stdout [nx_putslab  $fd $ds $start]
92put_nxds_value $start 3 0
93puts stdout [nx_putslab  $fd $ds $start]
94puts stdout [nx_closedata $fd]
95puts stdout "Finished Writing Slabs........."
96
97puts stdout [format "Linking = %d" [nx_makelink $fd $lnk]]
98
99set status [nx_closegroup $fd]
100if {$status == 1} {
101    puts stdout "Closing vGroup worked"
102}
103
104
105nx_close $fd
106puts stdout "Closed file"
107#---------------- finished writing tests
108
109
110#---------------- trying to read
111puts stdout "Testing Reading files"
112
113set fd [nx_open "nxinter.hdf" $NXACC_READ]
114puts stdout "Opening file for reading worked"
115
116set run 1
117
118#----------------- printing group content
119puts stdout "Group directory listing"
120while {$run == 1} {
121    set entry [nx_getnextentry $fd / ]
122    if { [string length $entry] < 2 } {
123        set run 0
124    } else {
125        puts stdout $entry
126    }
127}
128#--------- printing attributes
129puts stdout "Attributes"
130set run 1
131while {$run == 1} {
132    set entry [nx_getnextattr $fd / ]
133    puts stdout $entry
134    if { [string length $entry] < 2 } {
135        set run 0
136    } 
137}
138
139set rds [nx_getattr $fd "SuperDuper" $NX_CHAR 30]
140puts stdout $rds
141if {[string compare $rds NULL] != 0} {
142    puts stdout [format "SuperDuper = %s" [get_nxds_text $rds]]
143}
144drop_nxds $rds
145
146#---------------- reading tata
147puts stdout [nx_opengroup $fd fish NXentry]
148puts stdout [nx_opendata $fd "fish"]
149set rds [nx_getdata $fd]
150puts stdout $rds
151
152puts stdout "Read data should be a 3x3 unity matrix"
153printDS $rds
154
155puts stdout [nx_closedata $fd]
156
157#----------- reading slabbed data
158puts stdout "Testing slabbed reading......"
159puts stdout [nx_opendata $fd "fish2"]
160set ids [nx_getinfo $fd]
161puts stdout [format "fish2: type %f, rank %f, d1 %f, d2 %f" \
162        [get_nxds_value $ids 0] [get_nxds_value $ids 1] \
163        [get_nxds_value $ids 2] [get_nxds_value $ids 3]]
164drop_nxds $ids
165
166put_nxds_value $dimds 3 0
167set r1 [nx_getslab $fd $start $dimds]
168printDS $r1
169put_nxds_value $start 0 0
170set r2 [nx_getslab $fd $start $dimds]
171printDS $r2
172puts stdout [nx_closedata $fd]
173
174puts stdout [nx_closegroup $fd]
175puts stdout [nx_close $fd]
176
177#--------------- dropping datasets: do not forget!!!
178drop_nxds $ds
179drop_nxds $rds
180drop_nxds $dimds
181
182
183
184
185
186
187
188
189
190
191
Note: See TracBrowser for help on using the repository browser.