[ Bas Couwenberg ]
[ Debian Janitor ]
New upstream snapshot.
Debian Janitor
2 years ago
0 | *~ | |
1 | blib* | |
2 | Makefile.old | |
3 | MYMETA.yml | |
4 | MYMETA.json | |
5 | Makefile | |
6 | config.log | |
7 | config.status | |
8 | .libs | |
9 | libtool | |
10 | pm_to_blib* | |
11 | *.tar.gz | |
12 | *.o | |
13 | *.lo | |
14 | *.la | |
15 | *.so | |
16 | PDL-IO-Matlab* | |
17 | Matlab.pm | |
18 | Matlab.c | |
19 | Matlab.xs | |
20 | Matlab.bs | |
21 | *.mat | |
22 | ||
23 | matio-*/matio.pc | |
24 | matio-*/src/matioConfig.h | |
25 | matio-*/src/matio_pubconf.h | |
26 | matio-*/src/stamp-h1 | |
27 | matio-*/src/stamp-h2 | |
28 | matio-*/test/atconfig |
0 | ||
1 | # | |
2 | # GENERATED WITH PDL::PP! Don't modify! | |
3 | # | |
4 | package PDL::IO::Matlab; | |
5 | ||
6 | our @EXPORT_OK = qw(matlab_read matlab_write matlab_print_info ); | |
7 | our %EXPORT_TAGS = (Func=>[@EXPORT_OK]); | |
8 | ||
9 | use PDL::Core; | |
10 | use PDL::Exporter; | |
11 | use DynaLoader; | |
12 | ||
13 | ||
14 | ||
15 | our $VERSION = '0.006'; | |
16 | our @ISA = ( 'PDL::Exporter','DynaLoader' ); | |
17 | push @PDL::Core::PP, __PACKAGE__; | |
18 | bootstrap PDL::IO::Matlab $VERSION; | |
19 | ||
20 | ||
21 | ||
22 | ||
23 | ||
24 | =head1 NAME | |
25 | ||
26 | PDL::IO::Matlab -- Read and write Matlab format data files. | |
27 | ||
28 | =head1 DESCRIPTION | |
29 | ||
30 | This module provides routines to read and write pdls to and from | |
31 | data files in Matlab formats. The module uses the matio C library. | |
32 | Both functional and OO interface are provided. | |
33 | ||
34 | Only real, multi-dimensional arrays corresponding to PDL data types are supported. | |
35 | Compression for both reading and writing is supported. | |
36 | ||
37 | See the section L</CAVEATS> for important information on potential problems when using | |
38 | this module. | |
39 | ||
40 | =head1 SYNOPSIS | |
41 | ||
42 | use PDL; | |
43 | use PDL::IO::Matlab qw( matlab_read matlab_write matlab_print_info); | |
44 | ||
45 | # write two pdls in matlab 5 format | |
46 | matlab_write('file.dat', $x, $y); | |
47 | ||
48 | # read an array of ndarrays | |
49 | # from file in matlab 4, 5, or 7.3 format. | |
50 | my @pdls = matlab_read('file.dat'); | |
51 | ||
52 | # write pdl in matlab 7.3 format. | |
53 | matlab_write('file.dat', 'MAT73', $x); | |
54 | ||
55 | matlab_print_info('file.dat'); | |
56 | ||
57 | =cut | |
58 | ||
59 | $PDL::onlinedoc->scan(__FILE__) if $PDL::onlinedoc; | |
60 | ||
61 | use strict; | |
62 | use warnings; | |
63 | ||
64 | use PDL::LiteF; | |
65 | use PDL::NiceSlice; | |
66 | use PDL::Options; | |
67 | use Data::Dumper; | |
68 | ||
69 | ||
70 | ||
71 | ||
72 | ||
73 | ||
74 | ||
75 | ||
76 | my %Format_list = ( | |
77 | MAT73 => 0, | |
78 | MAT5 => 1, | |
79 | MAT4 => 2 | |
80 | ); | |
81 | ||
82 | my %Inv_format_list = ( | |
83 | 0 => 'MAT73', | |
84 | 1 => 'MAT5', | |
85 | 2 => 'MAT4' | |
86 | ); | |
87 | ||
88 | # non-OO functions | |
89 | ||
90 | =head1 FUNCTIONS | |
91 | ||
92 | The functional interface. | |
93 | ||
94 | =head2 B<matlab_read> | |
95 | ||
96 | =head3 Usage | |
97 | ||
98 | Return all arrays in C<$filename> | |
99 | ||
100 | @pdls = matlab_read($filename); | |
101 | @pdls = matlab_read($filename, {OPTIONS}); | |
102 | ||
103 | Return first array in C<$filename> | |
104 | ||
105 | $x = matlab_read($filename); | |
106 | ||
107 | Do not automatically convert C<1xn> and C<nx1> arrays | |
108 | to 1-d arrays. | |
109 | ||
110 | @pdls = matlab_read($filename, { onedr => 0 } ); | |
111 | ||
112 | Reads all data in the file C<$filename>. | |
113 | Formats 4, 5, and 7.3 are supported. Options | |
114 | are passed to L</B<new>>. | |
115 | ||
116 | =cut | |
117 | ||
118 | sub matlab_read { | |
119 | my ($filename,$opts) = @_; | |
120 | my $mat = PDL::IO::Matlab->new($filename, '<', $opts || {}); | |
121 | my @res = $mat->read_all; | |
122 | $mat->close; | |
123 | wantarray ? @res : $res[0]; | |
124 | } | |
125 | ||
126 | ||
127 | =head2 B<matlab_write> | |
128 | ||
129 | =head3 Usage | |
130 | ||
131 | matlab_write($filename,$x1,$x2,...); | |
132 | matlab_write($filename,$format,$x1,$x2,...); | |
133 | ||
134 | Automatically convert C<n> element, 1-d ndarrays to C<1xn> matlab | |
135 | variables. | |
136 | ||
137 | matlab_write($filename,$x1,$x2,..., {onedw => 1} ); | |
138 | ||
139 | Automatically convert to C<nx1> matlab | |
140 | variables. | |
141 | ||
142 | matlab_write($filename,$x1,$x2,..., {onedw => 2} ); | |
143 | ||
144 | Use zlib compression | |
145 | ||
146 | matlab_write($filename,$x1,$x2,..., {compress => 1} ); | |
147 | ||
148 | This method writes pdls C<$x1>, C<$x2>,.... If present, C<$format> | |
149 | must be either C<'MAT5'> or C<'MAT73'>. | |
150 | ||
151 | =cut | |
152 | ||
153 | sub matlab_write { | |
154 | my @strings; | |
155 | my @hashes; | |
156 | my @refs; | |
157 | while(@_) { | |
158 | my $v = shift; | |
159 | if ( ref($v) ) { | |
160 | if ( ref($v) eq 'HASH' ) { | |
161 | push @hashes, $v; | |
162 | } | |
163 | else { | |
164 | push @refs, $v; | |
165 | } | |
166 | } | |
167 | else { | |
168 | push @strings, $v; | |
169 | } | |
170 | } | |
171 | barf 'matlab_write: ' . scalar(@strings) . | |
172 | ' string arguments given. One or two expected.' | |
173 | if @strings < 1 or @strings > 2 ; | |
174 | my $filename = $strings[0]; | |
175 | my $format = $strings[1] || 'MAT5'; | |
176 | my $opth = { format => $format }; | |
177 | foreach (keys %{$hashes[0]}) { $opth->{$_} = $hashes[0]->{$_} } | |
178 | my $mat = PDL::IO::Matlab->new($filename, '>', $opth); | |
179 | $mat->write(@refs) if @refs; | |
180 | $mat->close; | |
181 | scalar(@refs); | |
182 | } | |
183 | ||
184 | =head2 B<matlab_print_info> | |
185 | ||
186 | =head3 Usage | |
187 | ||
188 | # print names and dimensions of variables. | |
189 | matlab_print_info($filename); | |
190 | # also print a small amount of the data. | |
191 | matlab_print_info($filename, { data => 1 }); | |
192 | # This does the same thing. | |
193 | matlab_print_info($filename, data => 1 ); | |
194 | ||
195 | Print information about the contents of the matlab file C<$filename>, | |
196 | including the name, dimension and class type of the variables. | |
197 | ||
198 | =cut | |
199 | ||
200 | sub matlab_print_info { | |
201 | my $name = shift; | |
202 | my $mat = PDL::IO::Matlab->new($name, '<'); | |
203 | $mat->print_all_var_info(@_); | |
204 | $mat->close; | |
205 | } | |
206 | ||
207 | =head1 METHODS | |
208 | ||
209 | =head2 B<new> | |
210 | ||
211 | =head3 Usage | |
212 | ||
213 | # open for writing | |
214 | $mat = PDL::IO::Matlab->new('file.dat', '>', {format => 'MAT5'}); | |
215 | ||
216 | # default format is MAT5 | |
217 | $mat = PDL::IO::Matlab->new('file.dat', '>'); | |
218 | ||
219 | # may use 'w' or '>' | |
220 | $mat = PDL::IO::Matlab->new('file.dat', 'w'); | |
221 | ||
222 | # supply header | |
223 | $mat = PDL::IO::Matlab->new('file.dat', '>', { header => 'some text'} ); | |
224 | ||
225 | # read-write with rw or <> | |
226 | $mat = PDL::IO::Matlab->new('file.dat', 'rw'); | |
227 | ||
228 | # open for reading | |
229 | $mat = PDL::IO::Matlab->new('file.dat', '<'); | |
230 | ||
231 | =head3 Options | |
232 | ||
233 | =over | |
234 | ||
235 | =item format | |
236 | ||
237 | Either C<'MAT5'> or C<'MAT73'>. | |
238 | ||
239 | =item compress | |
240 | ||
241 | Either C<1> for yes, or C<0> for no. | |
242 | ||
243 | =item header | |
244 | ||
245 | A header (a string) to write into the file. | |
246 | ||
247 | =item namekey | |
248 | ||
249 | A hash key that will be used to store the matlab name | |
250 | for a variable read from a file in the header of an ndarray. | |
251 | The default value is 'NAME'. Thus, the name can be accessed | |
252 | via C<< $pdl->hdr->{NAME} >>. | |
253 | ||
254 | =item varbasew | |
255 | ||
256 | The base of the default matlab variable name that will be | |
257 | written in the matlab file along with each ndarray. An | |
258 | integer will be appended to the base name. This integer is | |
259 | initialized to zero and is incremented after writing each | |
260 | variable. | |
261 | ||
262 | =back | |
263 | ||
264 | The option C<compress> enables zlib compression if the zlib library | |
265 | is available and if the data file format is C<'MAT5'>. | |
266 | ||
267 | =cut | |
268 | ||
269 | sub new { | |
270 | my $class = shift; | |
271 | my ($filename,$mode,$iopts) = @_; | |
272 | my $opt = new PDL::Options( | |
273 | { | |
274 | format => undef, | |
275 | header => undef, | |
276 | namekey => 'NAME', | |
277 | varbasew => 'variable', | |
278 | onedw => 1, | |
279 | onedr => 1, | |
280 | compress => 0 | |
281 | }); | |
282 | $iopts ||= {}; | |
283 | ||
284 | my $obj = $opt->options($iopts); | |
285 | ||
286 | my %exobj = ( | |
287 | filename => undef, | |
288 | mode => undef, | |
289 | handle => undef, | |
290 | wvarnum => 0, | |
291 | ); | |
292 | ||
293 | foreach (keys %exobj) { $obj->{$_} = $exobj{$_} }; | |
294 | ||
295 | bless $obj, $class; | |
296 | ||
297 | $obj->set_filename($filename) if $filename; | |
298 | ||
299 | if ( defined $mode ) { | |
300 | if ($mode eq 'r' or $mode eq '<') { | |
301 | $obj->set_mode('r'); | |
302 | } | |
303 | elsif ($mode eq 'w' or $mode eq '>') { | |
304 | $obj->set_mode('w'); | |
305 | } | |
306 | elsif ($mode eq 'rw' or $mode eq '<>') { | |
307 | $obj->set_mode('rw'); | |
308 | } | |
309 | else { | |
310 | barf "PDL::IO::Matlab::open unknown mode '$mode'"; | |
311 | } | |
312 | } | |
313 | elsif (defined $filename) { | |
314 | barf("PDL::IO::Matlab::new filename given, but no access mode."); | |
315 | } | |
316 | barf("PDL::IO::Matlab::new unknown file format") | |
317 | if defined $obj->{format} and not exists $Format_list{$obj->{format}}; | |
318 | $obj->open() if defined $filename; | |
319 | $obj; | |
320 | } | |
321 | ||
322 | # may want to keep track of state at some point, | |
323 | # an automatically close. | |
324 | sub DESTROY { | |
325 | my $self = shift; | |
326 | # $self->close; | |
327 | } | |
328 | ||
329 | sub open { | |
330 | my $self = shift; | |
331 | my $mode = $self->get_mode(); | |
332 | my $filename = $self->get_filename(); | |
333 | my $handle; | |
334 | if ( $mode eq 'r' ) { | |
335 | $handle = _mat_open_read($filename); | |
336 | } | |
337 | elsif ( $mode eq 'w' ) { | |
338 | $self->get_format || $self->set_format('MAT5'); | |
339 | my $header = $self->get_header(); | |
340 | my $header_flag = defined $header ? 1 : 0; | |
341 | $header = '' unless defined $header; | |
342 | $handle = _mat_create_ver( | |
343 | $filename, $header, $Format_list{$self->get_format}, $header_flag); | |
344 | } | |
345 | elsif ( $mode eq 'rw' ) { | |
346 | $handle = _mat_open_read_write($filename); | |
347 | } | |
348 | else { | |
349 | barf "PDL::IO::Matlab::open unknown mode '$mode'"; | |
350 | } | |
351 | barf "PDL::IO::Matlab::open Can't open '$filename' in mode $mode" unless $handle; | |
352 | $self->set_handle($handle); | |
353 | $self->get_format || $self->set_format($self->get_version); | |
354 | $self; | |
355 | } | |
356 | ||
357 | =head2 B<close> | |
358 | ||
359 | =head3 Usage | |
360 | ||
361 | $mat->close; | |
362 | ||
363 | Close matlab file and free memory associated with C<$mat>. | |
364 | ||
365 | =cut | |
366 | ||
367 | sub close { | |
368 | my $self = shift; | |
369 | _mat_close($self->get_handle() ); | |
370 | $self; | |
371 | } | |
372 | ||
373 | =head2 B<read_next> | |
374 | ||
375 | =head3 Usage | |
376 | ||
377 | my $x = $mat->read_next; | |
378 | print "End of file\n" unless ref($x); | |
379 | ||
380 | my ($err,$x) = $mat->read_next; | |
381 | print "End of file\n" if $err; | |
382 | ||
383 | Read one pdl from file associated with object C<$mat>. | |
384 | ||
385 | =cut | |
386 | ||
387 | sub read_next { | |
388 | my $self = shift; | |
389 | my ($pdl,$matlab_name) = _convert_next_matvar_to_pdl($self->get_handle, | |
390 | $self->get_onedr); | |
391 | my $err = ref($pdl) ? 0 : 1; | |
392 | $pdl->hdr->{$self->get_namekey} = $matlab_name if defined $matlab_name; | |
393 | return ($err,$pdl); | |
394 | } | |
395 | ||
396 | =head2 B<read_all> | |
397 | ||
398 | =head3 Usage | |
399 | ||
400 | my @pdls = $mat->read_all; | |
401 | ||
402 | Read all remaining pdls from file associated with object C<$mat>. | |
403 | ||
404 | =cut | |
405 | ||
406 | sub read_all { | |
407 | my $self = shift; | |
408 | my @res; | |
409 | while(1) { | |
410 | my ($err,$pdl) = read_next($self); | |
411 | last if $err; | |
412 | push @res, $pdl; | |
413 | } | |
414 | @res; | |
415 | } | |
416 | ||
417 | =head2 B<write> | |
418 | ||
419 | =head3 Usage | |
420 | ||
421 | $x2->hdr->{NAME} = 'variablename'; | |
422 | ||
423 | $mat->write($x1,$x2,...); | |
424 | ||
425 | $mat->write($x1,$x2,...,{OPTIONS}); | |
426 | ||
427 | Append pdls to open file associated with C<$mat>. | |
428 | ||
429 | If an ndarray has a matlab name stored in the header | |
430 | it will be used as the matlab name written to the file | |
431 | with this ndarray. The key is in C<< $pdl->{namekey} >>, | |
432 | with default value C<'NAME'>. If the name is not in | |
433 | the ndarray's header, then a default value will be used. | |
434 | ||
435 | =head3 Options | |
436 | ||
437 | =over | |
438 | ||
439 | =item onedw | |
440 | ||
441 | In order to write a file that is compatible with Matlab and Octave, | |
442 | C<onedw> must be either C<1> or C<2>. If C<onedw> is C<1> then a 1-d | |
443 | pdl of length n is written as a as an C<nx1> pdl (a C<1xn> matlab | |
444 | variable). If C<onedw> is C<2> then the output ndarray is C<1xn> and | |
445 | the matlab variable C<nx1>. If C<onedw> is zero (the default), then | |
446 | the 1-d pdl is written as a 1-d ndarray. In the last case, Octave will | |
447 | print an error and fail to read the variable. | |
448 | ||
449 | =item compress | |
450 | ||
451 | If C<compress> is C<1> then zlib compression is used, if the library | |
452 | is available and if the format is C<'MAT5'>. | |
453 | ||
454 | =back | |
455 | ||
456 | =cut | |
457 | ||
458 | sub _make_write_var_name { | |
459 | my $self = shift; | |
460 | my $varname = $self->get_varbasew . $self->get_wvarnum; | |
461 | $self->set_wvarnum($self->get_wvarnum + 1); | |
462 | $varname; | |
463 | } | |
464 | ||
465 | sub write { | |
466 | my $self = shift; | |
467 | my @pdls; | |
468 | my @hashes; | |
469 | while (@_) { | |
470 | my $arg = shift; | |
471 | if (ref($arg) eq 'HASH') { | |
472 | push @hashes, $arg; | |
473 | } | |
474 | else { | |
475 | push @pdls, $arg; | |
476 | } | |
477 | } | |
478 | # my %opts = parse( {onedw => 0 }, @hashes ? $hashes[0] : {} ); | |
479 | my $opts = @hashes ? $hashes[0] : {} ; | |
480 | my $onedw = exists $opts->{onedw} ? $opts->{onedw} : $self->get_onedw; | |
481 | $onedw = 1 if $onedw == 0 and $self->get_format eq 'MAT73'; # else crash | |
482 | my $compress = exists $opts->{compress} ? $opts->{compress} : $self->get_compress; | |
483 | foreach (@pdls) { | |
484 | my $name = exists $_->hdr->{$self->get_namekey} ? | |
485 | $_->hdr->{$self->get_namekey} : $self->_make_write_var_name; | |
486 | _write_pdl_to_matlab_file($self->get_handle,$_, $name, $onedw, $compress); | |
487 | } | |
488 | return $self; | |
489 | } | |
490 | ||
491 | =head2 B<rewind> | |
492 | ||
493 | =head3 Usage | |
494 | ||
495 | $mat->rewind | |
496 | ||
497 | Reset pointer to the head of the file. | |
498 | ||
499 | =cut | |
500 | ||
501 | sub rewind { | |
502 | my $self = shift; | |
503 | _mat_rewind($self->get_handle); | |
504 | } | |
505 | ||
506 | =head2 B<get_filename> | |
507 | ||
508 | =head3 Usage | |
509 | ||
510 | $mat->get_filename | |
511 | ||
512 | Return name of file associated with C<$mat>. | |
513 | ||
514 | =cut | |
515 | ||
516 | =head2 B<get_header> | |
517 | ||
518 | =head3 Usage | |
519 | ||
520 | $mat->get_header | |
521 | ||
522 | Return the header string from the matlab data file associated with | |
523 | C<$mat>. | |
524 | ||
525 | =cut | |
526 | ||
527 | sub get_header { | |
528 | my $self = shift; | |
529 | return defined $self->{header} ? | |
530 | $self->{header} : defined $self->{handle} ? | |
531 | _mat_get_header($self->{handle}) : undef; | |
532 | } | |
533 | ||
534 | sub set_header { | |
535 | my $self = shift; | |
536 | $self->{header} = shift; | |
537 | } | |
538 | ||
539 | =head2 B<get_format> | |
540 | ||
541 | =head3 Usage | |
542 | ||
543 | $mat->get_format | |
544 | ||
545 | Return matlab data file format for file associated with | |
546 | C<$mat>. One of C<'MAT4'>, C<'MAT5'>, or C<'MAT73'>. | |
547 | ||
548 | =cut | |
549 | ||
550 | # I am not using this ?? | |
551 | # version here means file format, use get_format instead | |
552 | sub get_version { | |
553 | my $self = shift; | |
554 | my $val = _mat_get_version($self->get_handle); | |
555 | $Inv_format_list{$val}; | |
556 | } | |
557 | ||
558 | =head2 B<print_all_var_info> | |
559 | ||
560 | =head3 Usage | |
561 | ||
562 | $mat->print_all_var_info; | |
563 | ||
564 | # also print a small amount of data from each variable. | |
565 | $mat->print_all_var_info( data => 1 ); | |
566 | ||
567 | Print a summary of all data in the file associated | |
568 | with C<$mat> (starting from the next unread variable.) | |
569 | ||
570 | =cut | |
571 | ||
572 | sub print_all_var_info { | |
573 | my $self = shift; | |
574 | my $len = scalar(@_); | |
575 | my $user_options = {}; | |
576 | if ( $len == 1 ) { | |
577 | $user_options = $_[0]; | |
578 | } | |
579 | elsif ( $len > 1 ) { | |
580 | my %user_option_hash = @_; | |
581 | $user_options = \%user_option_hash; | |
582 | } | |
583 | my %opts = parse( {data => 0} , $user_options); | |
584 | my $printdata = $opts{data} ? 1 : 0; | |
585 | my $handle = $self->get_handle; | |
586 | _extra_matio_print_all_var_info($handle,$printdata); | |
587 | } | |
588 | ||
589 | ||
590 | ||
591 | ||
592 | ||
593 | sub get_handle { | |
594 | my $self = shift; | |
595 | barf 'PDL::IO::Matlab::get_handle: handle not defined.' unless | |
596 | defined $self->{handle}; | |
597 | $self->{handle}; | |
598 | } | |
599 | ||
600 | sub set_handle { | |
601 | my $self = shift; | |
602 | $self->{handle} = shift; | |
603 | } | |
604 | ||
605 | ||
606 | sub get_mode { | |
607 | my $self = shift; | |
608 | barf 'PDL::IO::Matlab::get_mode: mode not defined.' unless | |
609 | defined $self->{mode}; | |
610 | $self->{mode}; | |
611 | } | |
612 | ||
613 | sub set_mode { | |
614 | my $self = shift; | |
615 | $self->{mode} = shift; | |
616 | } | |
617 | ||
618 | ||
619 | sub get_filename { | |
620 | my $self = shift; | |
621 | barf 'PDL::IO::Matlab::get_filename: filename not defined.' unless | |
622 | defined $self->{filename}; | |
623 | $self->{filename}; | |
624 | } | |
625 | ||
626 | sub set_filename { | |
627 | my $self = shift; | |
628 | $self->{filename} = shift; | |
629 | } | |
630 | ||
631 | ||
632 | sub get_format { | |
633 | my $self = shift; | |
634 | $self->{format}; | |
635 | } | |
636 | ||
637 | sub set_format { | |
638 | my $self = shift; | |
639 | $self->{format} = shift; | |
640 | } | |
641 | ||
642 | ||
643 | sub get_varbasew { | |
644 | my $self = shift; | |
645 | barf 'PDL::IO::Matlab::get_varbasew: varbasew not defined.' unless | |
646 | defined $self->{varbasew}; | |
647 | $self->{varbasew}; | |
648 | } | |
649 | ||
650 | sub set_varbasew { | |
651 | my $self = shift; | |
652 | $self->{varbasew} = shift; | |
653 | } | |
654 | ||
655 | ||
656 | sub get_onedw { | |
657 | my $self = shift; | |
658 | barf 'PDL::IO::Matlab::get_onedw: onedw not defined.' unless | |
659 | defined $self->{onedw}; | |
660 | $self->{onedw}; | |
661 | } | |
662 | ||
663 | sub set_onedw { | |
664 | my $self = shift; | |
665 | $self->{onedw} = shift; | |
666 | } | |
667 | ||
668 | ||
669 | sub get_onedr { | |
670 | my $self = shift; | |
671 | barf 'PDL::IO::Matlab::get_onedr: onedr not defined.' unless | |
672 | defined $self->{onedr}; | |
673 | $self->{onedr}; | |
674 | } | |
675 | ||
676 | sub set_onedr { | |
677 | my $self = shift; | |
678 | $self->{onedr} = shift; | |
679 | } | |
680 | ||
681 | ||
682 | sub get_namekey { | |
683 | my $self = shift; | |
684 | barf 'PDL::IO::Matlab::get_namekey: namekey not defined.' unless | |
685 | defined $self->{namekey}; | |
686 | $self->{namekey}; | |
687 | } | |
688 | ||
689 | sub set_namekey { | |
690 | my $self = shift; | |
691 | $self->{namekey} = shift; | |
692 | } | |
693 | ||
694 | ||
695 | sub get_wvarnum { | |
696 | my $self = shift; | |
697 | barf 'PDL::IO::Matlab::get_wvarnum: wvarnum not defined.' unless | |
698 | defined $self->{wvarnum}; | |
699 | $self->{wvarnum}; | |
700 | } | |
701 | ||
702 | sub set_wvarnum { | |
703 | my $self = shift; | |
704 | $self->{wvarnum} = shift; | |
705 | } | |
706 | ||
707 | ||
708 | sub get_compress { | |
709 | my $self = shift; | |
710 | barf 'PDL::IO::Matlab::get_compress: compress not defined.' unless | |
711 | defined $self->{compress}; | |
712 | $self->{compress}; | |
713 | } | |
714 | ||
715 | sub set_compress { | |
716 | my $self = shift; | |
717 | $self->{compress} = shift; | |
718 | } | |
719 | ||
720 | ||
721 | =head1 ACCESSOR METHODS | |
722 | ||
723 | The following are additional accessor methods for the matlab file objects | |
724 | PDL::IO::Matlab. | |
725 | ||
726 | get_handle set_handle get_mode set_mode get_filename set_filename get_format set_format get_varbasew set_varbasew get_onedw set_onedw get_onedr set_onedr get_namekey set_namekey get_wvarnum set_wvarnum get_compress set_compress | |
727 | =cut | |
728 | ||
729 | ||
730 | ||
731 | ||
732 | =head1 CAVEATS | |
733 | ||
734 | =head2 complicating factors | |
735 | ||
736 | There are two complicating factors when using matlab files with PDL. | |
737 | First, matlab does not support one-dimensional vectors. Thus, a 1-d pdl | |
738 | must be represented as either a C<1 x n> of a C<n x 1> matlab variable. Second, | |
739 | matlab stores matrices in column-major order, while pdl stores them | |
740 | in row-major order. | |
741 | ||
742 | =over | |
743 | ||
744 | =item B<one-dimensional pdls> | |
745 | ||
746 | You can write 1-d pdls to a file with this module. This module can then read the | |
747 | file. But, Octave will fail to read the file and print an error message. | |
748 | See L</B<write>> for how this is handled. | |
749 | ||
750 | =item B<column- vs. row major> | |
751 | ||
752 | Data written by Octave (PDL) will be read by PDL (Octave) with indices transposed. | |
753 | On the todo list is an option to physically or logically transpose the data on | |
754 | reading and writing. | |
755 | ||
756 | =item B<Octave requires distinct matlab variable names> | |
757 | ||
758 | With this module, you may write more than one | |
759 | variable, each with the same name, (the matlab name; not the | |
760 | pdl identifier, or variable, name), to a file in MAT5 | |
761 | format. This module is then able to read all pdls from this file. | |
762 | But, Octave, when reading this file, will overwrite all but | |
763 | the last occurrence of the variable with the last | |
764 | occurrence. See the method L</B<write>>. | |
765 | ||
766 | Trying to write two pdls with the same matlab variable name in MAT73 format will cause | |
767 | an error. | |
768 | ||
769 | =back | |
770 | ||
771 | =head2 other missing features, bugs | |
772 | ||
773 | When trying to read an unsupported matlab data type from a file, this module will | |
774 | throw an error. Supporting other data types or optionally skipping them is on | |
775 | the todo list. | |
776 | ||
777 | Random access of variables in a file is on the todo list. The underlying B<matio> | |
778 | library supports this. | |
779 | ||
780 | This module is currently built with some hardcoded data from a PDL installation, that | |
781 | may contain platform-specific (linux) features. It may fail to | |
782 | build or function correctly when used on other platforms. | |
783 | ||
784 | =head1 AUTHOR | |
785 | ||
786 | John Lapeyre, C<< <jlapeyre at cpan.org> >> | |
787 | ||
788 | The matio library was written by Christopher C. Hulbert. | |
789 | ||
790 | =head1 LICENSE AND COPYRIGHT | |
791 | ||
792 | Copyright 2012 John Lapeyre. | |
793 | ||
794 | This program is free software; you can redistribute it and/or modify it | |
795 | under the terms of either: the GNU General Public License as published | |
796 | by the Free Software Foundation; or the Artistic License. | |
797 | ||
798 | See http://dev.perl.org/licenses/ for more information. | |
799 | ||
800 | The matio library included here is | |
801 | Copyright 2011 Christopher C. Hulbert. All rights reserved. | |
802 | See the file matio-1.5/COPYING in the source distribution | |
803 | of this module. | |
804 | ||
805 | =cut | |
806 | ||
807 | # broken | |
808 | #sub print_all_var_info_new { | |
809 | # my $self = shift; | |
810 | # my $handle = $self->get_handle; | |
811 | # _extra_matio_print_all_var_info($handle,1,10,10); | |
812 | #} | |
813 | ||
814 | ########################################################################### | |
815 | ||
816 | ||
817 | ||
818 | ; | |
819 | ||
820 | ||
821 | ||
822 | # Exit with OK status | |
823 | ||
824 | 1; | |
825 | ||
826 | ⏎ |
97 | 97 | README.pod |
98 | 98 | t/1-matlab.t |
99 | 99 | typemap |
100 | META.yml Module YAML meta-data (added by MakeMaker) | |
101 | META.json Module JSON meta-data (added by MakeMaker) | |
102 | GENERATED/PDL/IO/Matlab.pm mod=PDL::IO::Matlab pd=matlab.pd (added by pdlpp_mkgen) |
0 | ^\.git | |
1 | ^xt/ | |
2 | ||
3 | \.lo$ | |
4 | ||
5 | ~$ | |
6 | ^blib | |
7 | Makefile\.old$ | |
8 | MYMETA\.yml$ | |
9 | MYMETA\.json$ | |
10 | Makefile$ | |
11 | config\.log$ | |
12 | config\.status$ | |
13 | \.libs$ | |
14 | libtool$ | |
15 | pm_to_blib$ | |
16 | \.tar\.gz$ | |
17 | \.o$ | |
18 | \.lo$ | |
19 | \.la$ | |
20 | \.so$ | |
21 | PDL-IO-Matlab.*$ | |
22 | Matlab\.pm$ | |
23 | Matlab\.c$ | |
24 | Matlab\.xs$ | |
25 | Matlab\.bs$ | |
26 | ^[^/]*\.mat$ | |
27 | ||
28 | \.swp$ | |
29 | ||
30 | ^matio-.*/matio\.pc$ | |
31 | ^matio-.*/src/matioConfig\.h$ | |
32 | ^matio-.*/src/matio_pubconf\.h$ | |
33 | ^matio-.*/src/stamp-h1$ | |
34 | ^matio-.*/src/stamp-h2$ | |
35 | ^matio-.*/test/atconfig$ | |
36 | ^matio-.*/src/\.libs | |
37 | ||
38 | ^MANIFEST\.SKIP$ | |
39 | ||
40 | # broken code, don't distribute | |
41 | ^mat_var_print\.c |
0 | { | |
1 | "abstract" : "Read and write Matlab format data files.", | |
2 | "author" : [ | |
3 | "John Lapeyre <jlapeyre@cpan.org>" | |
4 | ], | |
5 | "dynamic_config" : 1, | |
6 | "generated_by" : "ExtUtils::MakeMaker version 7.44, CPAN::Meta::Converter version 2.150010", | |
7 | "license" : [ | |
8 | "unknown" | |
9 | ], | |
10 | "meta-spec" : { | |
11 | "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", | |
12 | "version" : 2 | |
13 | }, | |
14 | "name" : "PDL-IO-Matlab", | |
15 | "no_index" : { | |
16 | "directory" : [ | |
17 | "t", | |
18 | "inc" | |
19 | ] | |
20 | }, | |
21 | "prereqs" : { | |
22 | "build" : { | |
23 | "requires" : { | |
24 | "ExtUtils::MakeMaker" : "0" | |
25 | } | |
26 | }, | |
27 | "configure" : { | |
28 | "requires" : { | |
29 | "Devel::CheckLib" : "1.14", | |
30 | "ExtUtils::MakeMaker" : "6.64", | |
31 | "PDL" : "2.043" | |
32 | } | |
33 | }, | |
34 | "runtime" : { | |
35 | "requires" : { | |
36 | "PDL" : "2.043" | |
37 | } | |
38 | }, | |
39 | "test" : { | |
40 | "requires" : { | |
41 | "Test::More" : "0.88" | |
42 | } | |
43 | } | |
44 | }, | |
45 | "release_status" : "stable", | |
46 | "version" : "0.006", | |
47 | "x_serialization_backend" : "JSON::PP version 4.04" | |
48 | } |
0 | --- | |
1 | abstract: 'Read and write Matlab format data files.' | |
2 | author: | |
3 | - 'John Lapeyre <jlapeyre@cpan.org>' | |
4 | build_requires: | |
5 | ExtUtils::MakeMaker: '0' | |
6 | Test::More: '0.88' | |
7 | configure_requires: | |
8 | Devel::CheckLib: '1.14' | |
9 | ExtUtils::MakeMaker: '6.64' | |
10 | PDL: '2.043' | |
11 | dynamic_config: 1 | |
12 | generated_by: 'ExtUtils::MakeMaker version 7.44, CPAN::Meta::Converter version 2.150010' | |
13 | license: unknown | |
14 | meta-spec: | |
15 | url: http://module-build.sourceforge.net/META-spec-v1.4.html | |
16 | version: '1.4' | |
17 | name: PDL-IO-Matlab | |
18 | no_index: | |
19 | directory: | |
20 | - t | |
21 | - inc | |
22 | requires: | |
23 | PDL: '2.043' | |
24 | version: '0.006' | |
25 | x_serialization_backend: 'CPAN::Meta::YAML version 0.018' |
21 | 21 | # write two pdls in matlab 5 format |
22 | 22 | matlab_write('file.dat', $x, $y); |
23 | 23 | |
24 | # read an array of piddles | |
24 | # read an array of ndarrays | |
25 | 25 | # from file in matlab 4, 5, or 7.3 format. |
26 | 26 | my @pdls = matlab_read('file.dat'); |
27 | 27 | |
65 | 65 | matlab_write($filename,$x1,$x2,...); |
66 | 66 | matlab_write($filename,$format,$x1,$x2,...); |
67 | 67 | |
68 | Automatically convert C<n> element, 1-d piddles to C<1xn> matlab | |
68 | Automatically convert C<n> element, 1-d ndarrays to C<1xn> matlab | |
69 | 69 | variables. |
70 | 70 | |
71 | 71 | matlab_write($filename,$x1,$x2,..., {onedw => 1} ); |
141 | 141 | =item namekey |
142 | 142 | |
143 | 143 | A hash key that will be used to store the matlab name |
144 | for a variable read from a file in the header of a piddle. | |
144 | for a variable read from a file in the header of an ndarray. | |
145 | 145 | The default value is 'NAME'. Thus, the name can be accessed |
146 | 146 | via C<< $pdl->hdr->{NAME} >>. |
147 | 147 | |
148 | 148 | =item varbasew |
149 | 149 | |
150 | 150 | The base of the default matlab variable name that will be |
151 | written in the matlab file along with each piddle. An | |
151 | written in the matlab file along with each ndarray. An | |
152 | 152 | integer will be appended to the base name. This integer is |
153 | 153 | initialized to zero and is incremented after writing each |
154 | 154 | variable. |
202 | 202 | |
203 | 203 | Append pdls to open file associated with C<$mat>. |
204 | 204 | |
205 | If a piddle has a matlab name stored in the header | |
205 | If an ndarray has a matlab name stored in the header | |
206 | 206 | it will be used as the matlab name written to the file |
207 | with this piddle. The key is in C<< $pdl->{namekey} >>, | |
207 | with this ndarray. The key is in C<< $pdl->{namekey} >>, | |
208 | 208 | with default value C<'NAME'>. If the name is not in |
209 | the piddle's header, then a default value will be used. | |
209 | the ndarray's header, then a default value will be used. | |
210 | 210 | |
211 | 211 | =head3 Options |
212 | 212 | |
217 | 217 | In order to write a file that is compatible with Matlab and Octave, |
218 | 218 | C<onedw> must be either C<1> or C<2>. If C<onedw> is C<1> then a 1-d |
219 | 219 | pdl of length n is written as a as an C<nx1> pdl (a C<1xn> matlab |
220 | variable). If C<onedw> is C<2> then the output piddle is C<1xn> and | |
220 | variable). If C<onedw> is C<2> then the output ndarray is C<1xn> and | |
221 | 221 | the matlab variable C<nx1>. If C<onedw> is zero (the default), then |
222 | the 1-d pdl is written as a 1-d piddle. In the last case, Octave will | |
222 | the 1-d pdl is written as a 1-d ndarray. In the last case, Octave will | |
223 | 223 | print an error and fail to read the variable. |
224 | 224 | |
225 | 225 | =item compress |
95 | 95 | |
96 | 96 | static pdl* matvar_to_pdl (matvar_t * matvar, int onedr) { |
97 | 97 | int ndims = matvar->rank; |
98 | pdl * piddle; | |
98 | pdl * ndarray; | |
99 | 99 | int i, pdl_data_type; |
100 | 100 | PDL_Indx * dims; |
101 | 101 | if ( matvar->isComplex ) |
117 | 117 | if ( 0 > (pdl_data_type = matvar_class_to_pdl_type[matvar->class_type] )) { |
118 | 118 | fprintf(stderr, "matvar_to_pdl: matlab data class is '%s'\n",matvar_class_type_desc[matvar->class_type]); |
119 | 119 | barf("matvar_to_pdl: No pdl data type corresponding to this class type.");} |
120 | piddle = my_pdl_wrap(matvar->data, pdl_data_type, dims, ndims, | |
120 | ndarray = my_pdl_wrap(matvar->data, pdl_data_type, dims, ndims, | |
121 | 121 | delete_matvar_to_pdl_data, 0); |
122 | 122 | matvar->mem_conserve = 1; // prevent matio freeing memory for data |
123 | 123 | free(dims); |
124 | return piddle; | |
124 | return ndarray; | |
125 | 125 | } |
126 | 126 | |
127 | 127 | pdl * convert_next_matvar_to_pdl (mat_t * matfp, matvar_t ** matvar, int onedr) { |
135 | 135 | * pdl to matvar |
136 | 136 | *******************************************************/ |
137 | 137 | |
138 | matvar_t * pdl_to_matvar (pdl * piddle, char *varname, int onedw) { | |
139 | int ndims = piddle->ndims; | |
138 | matvar_t * pdl_to_matvar (pdl * ndarray, char *varname, int onedw) { | |
139 | int ndims = ndarray->ndims; | |
140 | 140 | matvar_t *matvar; |
141 | 141 | int i, matvar_class_type, matvar_data_type; |
142 | 142 | int opt = MAT_F_DONT_COPY_DATA; |
143 | 143 | size_t * dims; |
144 | 144 | int tmp; |
145 | 145 | dims = (size_t *)malloc(sizeof(size_t) * (ndims+1)); |
146 | for(i=0;i<ndims;i++) dims[i] = piddle->dims[i]; | |
146 | for(i=0;i<ndims;i++) dims[i] = ndarray->dims[i]; | |
147 | 147 | if (ndims == 1 ) { |
148 | 148 | if ( onedw == 1) { |
149 | 149 | ndims = 2; |
156 | 156 | dims[1] = tmp; |
157 | 157 | } |
158 | 158 | } |
159 | matvar_class_type = pdl_type_to_matvar_class[piddle->datatype]; | |
160 | matvar_data_type = pdl_type_to_matvar_type[piddle->datatype]; | |
159 | matvar_class_type = pdl_type_to_matvar_class[ndarray->datatype]; | |
160 | matvar_data_type = pdl_type_to_matvar_type[ndarray->datatype]; | |
161 | 161 | matvar = Mat_VarCreate(varname,matvar_class_type, matvar_data_type, |
162 | ndims, dims, piddle->data, opt); | |
162 | ndims, dims, ndarray->data, opt); | |
163 | 163 | free(dims); |
164 | 164 | return matvar; |
165 | 165 | } |
166 | 166 | |
167 | int write_pdl_to_matlab_file (mat_t *mat, pdl *piddle, char *varname, int onedw, | |
167 | int write_pdl_to_matlab_file (mat_t *mat, pdl *ndarray, char *varname, int onedw, | |
168 | 168 | int compress) { |
169 | 169 | matvar_t * matvar; |
170 | matvar = pdl_to_matvar(piddle,varname,onedw); | |
170 | matvar = pdl_to_matvar(ndarray,varname,onedw); | |
171 | 171 | int retval; |
172 | 172 | if ( compress == 1 ) retval = Mat_VarWrite(mat, matvar, MAT_COMPRESSION_ZLIB); |
173 | 173 | else retval = Mat_VarWrite(mat, matvar, MAT_COMPRESSION_NONE); |
0 | libpdl-io-matlab-perl (0.006-3) UNRELEASED; urgency=medium | |
0 | libpdl-io-matlab-perl (0.006+git20210508.1.cfa66b3-1) UNRELEASED; urgency=medium | |
1 | 1 | |
2 | [ Bas Couwenberg ] | |
2 | 3 | * Team upload. |
3 | 4 | * Bump Standards-Version to 4.6.0, no changes. |
4 | 5 | |
5 | -- Bas Couwenberg <sebastic@debian.org> Wed, 08 Sep 2021 17:58:24 +0200 | |
6 | [ Debian Janitor ] | |
7 | * New upstream snapshot. | |
8 | ||
9 | -- Bas Couwenberg <sebastic@debian.org> Wed, 08 Sep 2021 23:10:12 -0000 | |
6 | 10 | |
7 | 11 | libpdl-io-matlab-perl (0.006-2) unstable; urgency=medium |
8 | 12 |
0 | /* | |
1 | * DOES NOT WORK. probably because it is not compiled with the | |
2 | * rest of the libary | |
3 | * A modified version of the library function Mat_VarPrint2 | |
4 | * This allows to choose the number of columns and rows to | |
5 | * be printed | |
6 | */ | |
7 | ||
8 | /** @brief Prints the variable information | |
9 | * | |
10 | * Prints to stdout the values of the @ref matvar_t structure | |
11 | * @ingroup MAT | |
12 | * @param matvar Pointer to the matvar_t structure | |
13 | * @param printdata set to 1 if the Variables data should be printed, else 0 | |
14 | */ | |
15 | void | |
16 | Mat_VarPrint2( matvar_t *matvar, int printdata, int max_cols, int max_rows ) | |
17 | { | |
18 | size_t nmemb; | |
19 | int i, j; | |
20 | const char *class_type_desc[16] = {"Undefined","Cell Array","Structure", | |
21 | "Object","Character Array","Sparse Array","Double Precision Array", | |
22 | "Single Precision Array", "8-bit, signed integer array", | |
23 | "8-bit, unsigned integer array","16-bit, signed integer array", | |
24 | "16-bit, unsigned integer array","32-bit, signed integer array", | |
25 | "32-bit, unsigned integer array","64-bit, signed integer array", | |
26 | "64-bit, unsigned integer array"}; | |
27 | const char *data_type_desc[23] = {"Unknown","8-bit, signed integer", | |
28 | "8-bit, unsigned integer","16-bit, signed integer", | |
29 | "16-bit, unsigned integer","32-bit, signed integer", | |
30 | "32-bit, unsigned integer","IEEE 754 single-precision","RESERVED", | |
31 | "IEEE 754 double-precision","RESERVED","RESERVED", | |
32 | "64-bit, signed integer","64-bit, unsigned integer", "Matlab Array", | |
33 | "Compressed Data","Unicode UTF-8 Encoded Character Data", | |
34 | "Unicode UTF-16 Encoded Character Data", | |
35 | "Unicode UTF-32 Encoded Character Data","","String","Cell Array", | |
36 | "Structure"}; | |
37 | ||
38 | if ( matvar == NULL ) | |
39 | return; | |
40 | if ( matvar->name ) | |
41 | printf(" Name: %s\n", matvar->name); | |
42 | printf(" Rank: %d\n", matvar->rank); | |
43 | if ( matvar->rank == 0 ) | |
44 | return; | |
45 | printf("Dimensions: %zu",matvar->dims[0]); | |
46 | nmemb = matvar->dims[0]; | |
47 | for ( i = 1; i < matvar->rank; i++ ) { | |
48 | printf(" x %zu",matvar->dims[i]); | |
49 | nmemb *= matvar->dims[i]; | |
50 | } | |
51 | printf("\n"); | |
52 | printf("Class Type: %s",class_type_desc[matvar->class_type]); | |
53 | if ( matvar->isComplex ) | |
54 | printf(" (complex)"); | |
55 | printf("\n"); | |
56 | if ( matvar->data_type ) | |
57 | printf(" Data Type: %s\n", data_type_desc[matvar->data_type]); | |
58 | ||
59 | if ( MAT_C_STRUCT == matvar->class_type ) { | |
60 | matvar_t **fields = (matvar_t **)matvar->data; | |
61 | int nfields = matvar->internal->num_fields; | |
62 | if ( nmemb*nfields > 0 ) { | |
63 | printf("Fields[%zu] {\n", nfields*nmemb); | |
64 | for ( i = 0; i < nfields*nmemb; i++ ) { | |
65 | if ( NULL == fields[i] ) { | |
66 | printf(" Name: %s\n Rank: %d\n", | |
67 | matvar->internal->fieldnames[i%nfields],0); | |
68 | } else { | |
69 | Mat_VarPrint(fields[i],printdata); | |
70 | } | |
71 | } | |
72 | printf("}\n"); | |
73 | } else { | |
74 | printf("Fields[%d] {\n", nfields); | |
75 | for ( i = 0; i < nfields; i++ ) | |
76 | printf(" Name: %s\n Rank: %d\n", | |
77 | matvar->internal->fieldnames[i],0); | |
78 | printf("}\n"); | |
79 | } | |
80 | return; | |
81 | } else if ( matvar->data == NULL || matvar->data_size < 1 ) { | |
82 | return; | |
83 | } else if ( MAT_C_CELL == matvar->class_type ) { | |
84 | matvar_t **cells = (matvar_t **)matvar->data; | |
85 | int ncells = matvar->nbytes / matvar->data_size; | |
86 | printf("{\n"); | |
87 | for ( i = 0; i < ncells; i++ ) | |
88 | Mat_VarPrint(cells[i],printdata); | |
89 | printf("}\n"); | |
90 | return; | |
91 | } else if ( !printdata ) { | |
92 | return; | |
93 | } | |
94 | printf("{\n"); | |
95 | ||
96 | if ( matvar->rank > 2 ) { | |
97 | printf("I can't print more than 2 dimensions\n"); | |
98 | } else if ( matvar->rank == 1 && matvar->dims[0] > max_rows ) { | |
99 | printf("I won't print more than %d elements in a vector\n",max_rows); | |
100 | } else if ( matvar->rank==2 ) { | |
101 | switch( matvar->class_type ) { | |
102 | case MAT_C_DOUBLE: | |
103 | case MAT_C_SINGLE: | |
104 | #ifdef HAVE_MAT_INT64_T | |
105 | case MAT_C_INT64: | |
106 | #endif | |
107 | #ifdef HAVE_MAT_UINT64_T | |
108 | case MAT_C_UINT64: | |
109 | #endif | |
110 | case MAT_C_INT32: | |
111 | case MAT_C_UINT32: | |
112 | case MAT_C_INT16: | |
113 | case MAT_C_UINT16: | |
114 | case MAT_C_INT8: | |
115 | case MAT_C_UINT8: | |
116 | { | |
117 | size_t stride = Mat_SizeOf(matvar->data_type); | |
118 | if ( matvar->isComplex ) { | |
119 | mat_complex_split_t *complex_data = matvar->data; | |
120 | char *rp = complex_data->Re; | |
121 | char *ip = complex_data->Im; | |
122 | for ( i = 0; i < matvar->dims[0] && i < max_rows; i++ ) { | |
123 | for ( j = 0; j < matvar->dims[1] && j < max_cols; j++ ) { | |
124 | size_t idx = matvar->dims[0]*j+i; | |
125 | Mat_PrintNumber(matvar->data_type,rp+idx*stride); | |
126 | printf(" + "); | |
127 | Mat_PrintNumber(matvar->data_type,ip+idx*stride); | |
128 | printf("i "); | |
129 | } | |
130 | if ( j < matvar->dims[1] ) | |
131 | printf("..."); | |
132 | printf("\n"); | |
133 | } | |
134 | if ( i < matvar->dims[0] ) | |
135 | printf(".\n.\n.\n"); | |
136 | } else { | |
137 | char *data = matvar->data; | |
138 | for ( i = 0; i < matvar->dims[0] && i < max_rows; i++ ) { | |
139 | for ( j = 0; j < matvar->dims[1] && j < max_cols; j++ ) { | |
140 | size_t idx = matvar->dims[0]*j+i; | |
141 | Mat_PrintNumber(matvar->data_type, | |
142 | data+idx*stride); | |
143 | printf(" "); | |
144 | } | |
145 | if ( j < matvar->dims[1] ) | |
146 | printf("..."); | |
147 | printf("\n"); | |
148 | } | |
149 | if ( i < matvar->dims[0] ) | |
150 | printf(".\n.\n.\n"); | |
151 | } | |
152 | break; | |
153 | } | |
154 | case MAT_C_CHAR: | |
155 | { | |
156 | char *data = matvar->data; | |
157 | if ( !printdata ) | |
158 | break; | |
159 | for ( i = 0; i < matvar->dims[0]; i++ ) { | |
160 | j = 0; | |
161 | for ( j = 0; j < matvar->dims[1]; j++ ) | |
162 | printf("%c",data[j*matvar->dims[0]+i]); | |
163 | printf("\n"); | |
164 | } | |
165 | break; | |
166 | } | |
167 | case MAT_C_SPARSE: | |
168 | { | |
169 | mat_sparse_t *sparse; | |
170 | size_t stride = Mat_SizeOf(matvar->data_type); | |
171 | #if !defined(EXTENDED_SPARSE) | |
172 | if ( MAT_T_DOUBLE != matvar->data_type ) | |
173 | break; | |
174 | #endif | |
175 | sparse = matvar->data; | |
176 | if ( matvar->isComplex ) { | |
177 | mat_complex_split_t *complex_data = sparse->data; | |
178 | char *re,*im; | |
179 | re = complex_data->Re; | |
180 | im = complex_data->Im; | |
181 | for ( i = 0; i < sparse->njc-1; i++ ) { | |
182 | for (j = sparse->jc[i]; | |
183 | j<sparse->jc[i+1] && j<sparse->ndata;j++ ) { | |
184 | printf(" (%d,%d) ",sparse->ir[j]+1,i+1); | |
185 | Mat_PrintNumber(matvar->data_type,re+j*stride); | |
186 | printf(" + "); | |
187 | Mat_PrintNumber(matvar->data_type,im+j*stride); | |
188 | printf("i\n"); | |
189 | } | |
190 | } | |
191 | } else { | |
192 | char *data; | |
193 | data = sparse->data; | |
194 | for ( i = 0; i < sparse->njc-1; i++ ) { | |
195 | for (j = sparse->jc[i]; | |
196 | j<sparse->jc[i+1] && j<sparse->ndata;j++ ){ | |
197 | printf(" (%d,%d) ",sparse->ir[j]+1,i+1); | |
198 | Mat_PrintNumber(matvar->data_type,data+j*stride); | |
199 | printf("\n"); | |
200 | } | |
201 | } | |
202 | } | |
203 | break; | |
204 | } /* case MAT_C_SPARSE: */ | |
205 | } /* switch( matvar->class_type ) */ | |
206 | } | |
207 | ||
208 | printf("}\n"); | |
209 | ||
210 | return; | |
211 | } |
61 | 61 | # write two pdls in matlab 5 format |
62 | 62 | matlab_write('file.dat', $x, $y); |
63 | 63 | |
64 | # read an array of piddles | |
64 | # read an array of ndarrays | |
65 | 65 | # from file in matlab 4, 5, or 7.3 format. |
66 | 66 | my @pdls = matlab_read('file.dat'); |
67 | 67 | |
144 | 144 | matlab_write($filename,$x1,$x2,...); |
145 | 145 | matlab_write($filename,$format,$x1,$x2,...); |
146 | 146 | |
147 | Automatically convert C<n> element, 1-d piddles to C<1xn> matlab | |
147 | Automatically convert C<n> element, 1-d ndarrays to C<1xn> matlab | |
148 | 148 | variables. |
149 | 149 | |
150 | 150 | matlab_write($filename,$x1,$x2,..., {onedw => 1} ); |
260 | 260 | =item namekey |
261 | 261 | |
262 | 262 | A hash key that will be used to store the matlab name |
263 | for a variable read from a file in the header of a piddle. | |
263 | for a variable read from a file in the header of an ndarray. | |
264 | 264 | The default value is 'NAME'. Thus, the name can be accessed |
265 | 265 | via C<< $pdl->hdr->{NAME} >>. |
266 | 266 | |
267 | 267 | =item varbasew |
268 | 268 | |
269 | 269 | The base of the default matlab variable name that will be |
270 | written in the matlab file along with each piddle. An | |
270 | written in the matlab file along with each ndarray. An | |
271 | 271 | integer will be appended to the base name. This integer is |
272 | 272 | initialized to zero and is incremented after writing each |
273 | 273 | variable. |
439 | 439 | |
440 | 440 | Append pdls to open file associated with C<$mat>. |
441 | 441 | |
442 | If a piddle has a matlab name stored in the header | |
442 | If an ndarray has a matlab name stored in the header | |
443 | 443 | it will be used as the matlab name written to the file |
444 | with this piddle. The key is in C<< $pdl->{namekey} >>, | |
444 | with this ndarray. The key is in C<< $pdl->{namekey} >>, | |
445 | 445 | with default value C<'NAME'>. If the name is not in |
446 | the piddle's header, then a default value will be used. | |
446 | the ndarray's header, then a default value will be used. | |
447 | 447 | |
448 | 448 | =head3 Options |
449 | 449 | |
454 | 454 | In order to write a file that is compatible with Matlab and Octave, |
455 | 455 | C<onedw> must be either C<1> or C<2>. If C<onedw> is C<1> then a 1-d |
456 | 456 | pdl of length n is written as a as an C<nx1> pdl (a C<1xn> matlab |
457 | variable). If C<onedw> is C<2> then the output piddle is C<1xn> and | |
457 | variable). If C<onedw> is C<2> then the output ndarray is C<1xn> and | |
458 | 458 | the matlab variable C<nx1>. If C<onedw> is zero (the default), then |
459 | the 1-d pdl is written as a 1-d piddle. In the last case, Octave will | |
459 | the 1-d pdl is written as a 1-d ndarray. In the last case, Octave will | |
460 | 460 | print an error and fail to read the variable. |
461 | 461 | |
462 | 462 | =item compress |
969 | 969 | XPUSHs(s); |
970 | 970 | |
971 | 971 | int |
972 | _write_pdl_to_matlab_file (mat, piddle, varname, oned, compress) | |
972 | _write_pdl_to_matlab_file (mat, ndarray, varname, oned, compress) | |
973 | 973 | mat_t * mat |
974 | pdl * piddle | |
974 | pdl * ndarray | |
975 | 975 | char * varname |
976 | 976 | int oned |
977 | 977 | int compress |
978 | 978 | CODE: |
979 | RETVAL = write_pdl_to_matlab_file (mat, piddle, varname, oned, compress); | |
979 | RETVAL = write_pdl_to_matlab_file (mat, ndarray, varname, oned, compress); | |
980 | 980 | OUTPUT: |
981 | 981 | RETVAL |
982 | 982 |
0 | use Test::More tests => 1; | |
1 | ||
2 | use strict; | |
3 | use warnings; | |
4 | ||
5 | use CPAN::Changes; | |
6 | use Data::Dumper; | |
7 | ||
8 | my $changes = CPAN::Changes->load('Changes'); | |
9 | ||
10 | ok($changes); | |
11 | ||
12 | my @releases = map { +{ $_->version => $_->date } } $changes->releases; | |
13 | ||
14 | note Dumper \@releases; | |
15 | ||
16 | done_testing; |
0 | use strict; | |
1 | use warnings; | |
2 | use Test::More; | |
3 | use ExtUtils::Manifest; | |
4 | ||
5 | unless ( $ENV{RELEASE_TESTING} ) { | |
6 | plan( skip_all => "Author tests not required for installation" ); | |
7 | } | |
8 | plan tests => 2; | |
9 | ||
10 | is_deeply [ ExtUtils::Manifest::manicheck() ], [], 'missing'; | |
11 | is_deeply [ ExtUtils::Manifest::filecheck() ], [], 'extra'; |
0 | use strict; | |
1 | use warnings; | |
2 | use Test::More; | |
3 | ||
4 | unless ( $ENV{RELEASE_TESTING} ) { | |
5 | plan( skip_all => "Author tests not required for installation" ); | |
6 | } | |
7 | ||
8 | # Ensure a recent version of Test::Pod | |
9 | my $min_tp = 1.22; | |
10 | eval "use Test::Pod $min_tp"; | |
11 | plan skip_all => "Test::Pod $min_tp required for testing POD" if $@; | |
12 | ||
13 | all_pod_files_ok(); |