[58ab2f]: t / total.t  Maximize  Restore  History

Download this file

202 lines (119 with data), 4.8 kB

  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
use PDL;
use PDL::Char;
use PDL::IO::HDF5;
use PDL::Types;
# Script to test the PDL::IO::HDF5 objects together in the
# way they would normally be used
#
# i.e. the way they would normally be used as described
# in the PDL::IO::HDF5 synopsis
use Test::More tests => 33;
# New File Check:
my $filename = "total.hdf5";
# get rid of filename if it already exists
unlink $filename if( -e $filename);
my $hdfobj;
ok($hdfobj = new PDL::IO::HDF5($filename));
# Set attribute for file (root group)
ok($hdfobj->attrSet( 'attr1' => 'dudeman', 'attr2' => 'What??'));
# Try Setting attr for an existing attr
ok($hdfobj->attrSet( 'attr1' => 'dudeman23'));
# Add a attribute and then delete it
ok($hdfobj->attrSet( 'dummyAttr' => 'dummyman',
'dummyAttr2' => 'dummyman'));
ok($hdfobj->attrDel( 'dummyAttr', 'dummyAttr2' ));
# Get list of attributes
my @attrs = $hdfobj->attrs;
ok(join(",",sort @attrs) eq 'attr1,attr2' );
# Get a list of attribute values
my @attrValues = $hdfobj->attrGet(sort @attrs);
ok(join(",",@attrValues) eq 'dudeman23,What??' );
# print "Attr Values = '".join("', '",@attrValues)."'\n";
##############################################
# Create a dataset in the root group
my $dataset = $hdfobj->dataset('rootdataset');
my $pdl = sequence(5,4);
ok($dataset->set($pdl) );
# print "pdl written = \n".$pdl."\n";
# Create String dataset using PDL::Char
my $dataset2 = $hdfobj->dataset('charData');
my $pdlChar = new PDL::Char( [ ["abccc", "def", "ghi"],["jkl", "mno", 'pqr'] ] );
ok($dataset2->set($pdlChar));
my $pdl2 = $dataset->get;
# print "pdl read = \n".$pdl2."\n";
ok((($pdl - $pdl2)->sum) < .001 );
my @dims = $dataset->dims;
ok( join(", ",@dims) eq '5, 4' );
# Get a list of datasets (should be two)
my @datasets = $hdfobj->datasets;
ok( scalar(@datasets) == 2 );
#############################################
my $group = $hdfobj->group("mygroup");
my $subgroup = $group->group("subgroup");
### Try a non-deault data-set type (float) ####
# Create a dataset in the subgroup
$dataset = $subgroup->dataset('my dataset');
$pdl = sequence(5,4)->float; # Try a non-default data type
ok( $dataset->set($pdl) );
# print "pdl written = \n".$pdl."\n";
$pdl2 = $dataset->get;
# print "pdl read = \n".$pdl2."\n";
ok( (($pdl - $pdl2)->sum) < .001 );
# Check for the PDL returned being a float
ok( ($pdl->get_datatype - $PDL_F) < .001 );
# Get a hyperslab
$pdl = $dataset->get(pdl([0,0]), pdl([4,0])); # Get the first vector of the PDL
# Check to see if the dims are as expected.
my @pdlDims = $pdl->dims;
ok( ($pdlDims[0] == 5) && ($pdlDims[1] == 1));
### Try a non-deault data-set type (int/long) ####
# Create a dataset in the subgroup
$dataset = $subgroup->dataset('my dataset2');
$pdl = sequence(5,4)->long; # Try a non-default data type
ok( $dataset->set($pdl) );
# print "pdl written = \n".$pdl."\n";
$pdl2 = $dataset->get;
# print "pdl read = \n".$pdl2."\n";
ok( (($pdl - $pdl2)->sum) < .001 );
# Check for the PDL returned being a int/long
ok( ($pdl->get_datatype - $PDL_L) < .001 );
################ Set Attributes at the Dataset Level ###############
# Set attribute for group
ok( $dataset->attrSet( 'attr1' => 'DSdudeman', 'attr2' => 'DSWhat??'));
# Try Setting attr for an existing attr
ok($dataset->attrSet( 'attr1' => 'DSdudeman23'));
# Add a attribute and then delete it
ok( $dataset->attrSet( 'dummyAttr' => 'dummyman',
'dummyAttr2' => 'dummyman'));
ok( $dataset->attrDel( 'dummyAttr', 'dummyAttr2' ));
# Get list of attributes
@attrs = $dataset->attrs;
ok( join(",",sort @attrs) eq 'attr1,attr2' );
# Get a list of attribute values
@attrValues = $dataset->attrGet(sort @attrs);
ok( join(",",@attrValues) eq 'DSdudeman23,DSWhat??' );
################ Set Attributes at the Group Level ###############
# Set attribute for group
ok( $group->attrSet( 'attr1' => 'dudeman', 'attr2' => 'What??'));
# Try Setting attr for an existing attr
ok($group->attrSet( 'attr1' => 'dudeman23'));
# Add a attribute and then delete it
ok( $group->attrSet( 'dummyAttr' => 'dummyman',
'dummyAttr2' => 'dummyman'));
ok( $group->attrDel( 'dummyAttr', 'dummyAttr2' ));
# Get list of attributes
@attrs = $group->attrs;
ok( join(",",sort @attrs) eq 'attr1,attr2' );
# Get a list of datasets (should be none)
@datasets = $group->datasets;
ok( scalar(@datasets) == 0 );
# Create another group
my $group2 = $hdfobj->group("dude2");
# Get a list of groups in the root group
my @groups = $hdfobj->groups;
# print "Root group has these groups '".join(",",sort @groups)."'\n";
ok( join(",",sort @groups) eq 'dude2,mygroup' );
# Get a list of groups in group2 (should be none)
@groups = $group2->groups;
ok( scalar(@groups) == 0 );
# print "completed\n";