[0ad34b]: t / attribPDL.t  Maximize  Restore  History

Download this file

147 lines (111 with data), 3.5 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
use PDL;
use PDL::Char;
use PDL::IO::HDF5;
use PDL::Types;
# Test case for HDF5 attributes that are pdls
# This is a new feature as-of version 0.64
#
print "1..13\n";
my $testNo = 1;
my $filename = "newFile.hd5";
# get rid of filename if it already exists
unlink $filename if( -e $filename);
my $hdf5 = new PDL::IO::HDF5($filename);
# Create pdls to store:
my $pchar = PDL::Char->new( [['abc', 'def', 'ghi'],['jkl', 'mno', 'pqr']] );
my $bt=pdl([[1.2,1.3,1.4],[1.5,1.6,1.7],[1.8,1.9,2.0]]);
my $group=$hdf5->group('Radiometric information');
# Store a dataset
my $dataset=$group->dataset('SP_BT');
$dataset->set($bt);
# Store a scalar and pdl attribute
$dataset->attrSet('UNITS'=>'K');
$dataset->attrSet('NUM_COL'=>pdl(long,[[1,2,3],[4,5,6]]));
$dataset->attrSet('NUM_COLLONG'=>pdl(longlong,[[123456789123456784,2,3],[4,5,6]]));
$dataset->attrSet('NUM_ROW'=>$pchar);
$dataset->attrSet('SCALING'=>'pepe');
$dataset->attrSet('OFFSET'=>pdl(double,[0.0074]));
$dataset->attrSet('ID'=>pdl(long,87));
$dataset->attrSet('IDLONG'=>pdl(longlong,123456789123456784));
$dataset->attrSet('TEMPERATURE'=>pdl(double,3.1415927));
# Set group attribute
$group->attrSet('GroupPDLAttr'=>pdl(long,[[1,2,3],[4,5,6]]));
######## Now Read HDF5 file #####
my $hdf2= new PDL::IO::HDF5($filename);
my $group2=$hdf2->group('Radiometric information');
my $dataset2=$group2->dataset('SP_BT');
my $expected;
$expected = '
[
[1.2 1.3 1.4]
[1.5 1.6 1.7]
[1.8 1.9 2]
]
';
my $bt2=$dataset2->get();
#print "expoected = '$bt2'\n";
ok($testNo++, "$bt2" eq $expected);
$expected = 'K';
my ($units)=$dataset2->attrGet('UNITS');
#print "units '$units'\n";
ok($testNo++, $units eq $expected);
$expected = '
[
[1 2 3]
[4 5 6]
]
';
my ($numcol)=$dataset2->attrGet('NUM_COL');
#print "numcol '$numcol'\n";
ok($testNo++, "$numcol" eq $expected);
ok($testNo++, (ref($numcol) && $numcol->isa('PDL')) );
$expected = '123456789123456784 2 3 4 5 6';
my ($numcollong)=$dataset2->attrGet('NUM_COLLONG');
#print "numcollong '$numcollong'\n";
ok($testNo++, sprintf("%18i %18i %18i %18i %18i %18i",$numcollong->list()) eq $expected);
$expected = "[
[ 'abc' 'def' 'ghi' ]
[ 'jkl' 'mno' 'pqr' ]
]
";
my ($numrow)=$dataset2->attrGet('NUM_ROW');
#print "numrow '$numrow'\n";
ok($testNo++, "$numrow" eq $expected);
$expected = 'pepe';
my ($scaling)=$dataset2->attrGet('SCALING');
#print "scaling '$scaling\n";
ok($testNo++, $scaling eq $expected);
$expected = '[0.0074]';
my ($offset)=$dataset2->attrGet('OFFSET');
#print "offset '$offset'\n";
ok($testNo++, "$offset" eq $expected);
$expected = '87';
my ($id)=$dataset2->attrGet('ID');
#print "id '$id'\n";
ok($testNo++, "$id" eq $expected);
$expected = '123456789123456784';
my ($idlong)=$dataset2->attrGet('IDLONG');
#print "idlong '$idlong'\n";
ok($testNo++, "$idlong" eq $expected);
$expected = '3.1415927';
my ($temperature)=$dataset2->attrGet('TEMPERATURE');
#print "temperature '$temperature'\n";
ok($testNo++, "$temperature" eq $expected);
# Check Group PDL Attribute
$expected = '
[
[1 2 3]
[4 5 6]
]
';
my ($numcol2)=$group2->attrGet('GroupPDLAttr');
#print "numcol '$numcol'\n";
ok($testNo++, "$numcol2" eq $expected);
ok($testNo++, (ref($numcol2) && $numcol2->isa('PDL')) );
# Testing utility functions:
sub ok {
my $no = shift ;
my $result = shift ;
print "not " unless $result ;
print "ok $no\n" ;
}

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks