File Coverage

blib/lib/Parse/ISF.pm
Criterion Covered Total %
statement 39 39 100.0
branch 4 6 66.6
condition n/a
subroutine 5 5 100.0
pod 2 2 100.0
total 50 52 96.1


line stmt bran cond sub pod time code
1             package Parse::ISF;
2              
3 3     3   72785 use warnings;
  3         7  
  3         103  
4 3     3   18 use strict;
  3         5  
  3         114  
5              
6 3     3   17 use Exporter;
  3         11  
  3         1848  
7              
8             our @ISA = qw(Exporter);
9              
10             =head1 NAME
11              
12             Parse::ISF - Parse the ISF file generated by certain models of
13             Tektronix oscillascope (TDS 3000, DPO 4000, etc)
14              
15             =head1 VERSION
16              
17             Version 0.0102
18              
19             =cut
20              
21             our $VERSION = '0.0103';
22              
23              
24             =head1 SYNOPSIS
25              
26             use Parse::ISF;
27              
28             my $foo = Parse::ISF::Read('filename.isf');
29             print $foo->{NR_PT}; # get number of data points
30             print $foo->{DATA}[100][1]; # get y coordinate of the 101st data point
31              
32             =cut
33              
34              
35             our %EXPORT_TAGS = ( 'all' => [ qw(
36             Read
37             ConvertToCSV
38             ) ] );
39              
40             our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
41              
42             our @EXPORT = qw(
43             );
44              
45              
46             =head1 EXPORT
47              
48             None by default.
49              
50             All functions can be exported by
51              
52             use Parse::ISF ':all';
53              
54             =head1 FUNCTIONS
55              
56             =head2 Read
57              
58             Takes one parameter as the name of the .isf file.
59              
60             Read data from file into a hash reference which contains all the
61             information in the header. For example, to get the number of data
62             points in a file:
63              
64             my $foo = Parse::ISF::Read('filename.isf');
65             print 'The file contains ', $foo->{NR_PT}, " points\n";
66             print 'x, y units : ', $foo->{XUNIT}, ',', $foo->{YUNIT}, "\n";
67             print 'info : ', $foo->{WFID}, "\n";
68              
69             In addition, the raw data are stored in the key 'DATA' as an array
70             reference, each element is a data point which is stored as an array
71             reference of (x, y) values. For example, to get the x, y value of the
72             1000th point:
73              
74             my $foo = Parse::ISF::Read('filename.isf');
75             my ($x, $y) = @{$foo->{DATA}[999]};
76              
77             =cut
78              
79             sub Read {
80 3     3 1 720 my ($fn) = @_;
81              
82 3         175 my $size = -s $fn;
83 3         8 my $header;
84 3         5 my $fileopen = 1;
85 3 100       92 open F, $fn or return undef;
86 2         8 binmode F;
87 2         53 read F, $header, 269;
88 2         15 $header =~ s/:WFMPRE://;
89 2         10 $header =~ s/:CURVE//;
90 2         5 my $h;
91 2         92 %$h = ($header =~ /(\S+)\s+(.+?);/g);
92              
93 2         10 my $datablock;
94 2         96 read F, $datablock, 2*$h->{NR_PT};
95 2         17758 my @iy = unpack 'v*', $datablock;
96 20000         78784 $h->{DATA} = [map {
97 2         2556 [$h->{XZERO} + $h->{XINCR}*$_,
98             $h->{YMULT}*($iy[$_] - $h->{YOFF})]
99             } 0..$#iy];
100 2         1219 close F;
101              
102 2         1906 return $h;
103            
104             }
105              
106             =head2 ConvertToCSV
107              
108             Takes two parameters, they are the input/output file names.
109              
110             Converts a .isf file to a .csv file.
111              
112             =cut
113              
114             sub ConvertToCSV {
115 1     1 1 10 my ($in, $out) = @_;
116 1 50       3 unless ($out) {
117 1         2 $out = $in;
118 1         6 $out =~ s/isf$/csv/i;
119             }
120 1         5 my $h = Read($in);
121 1 50       319 open F, ">$out" or return undef;
122 1         4 for my $l (@{$h->{DATA}}) {
  1         6  
123 10000         10270 print F join(',', @{$l}),"\n";
  10000         50158  
124             }
125 1         91 close F;
126 1         4392 1;
127             }
128              
129             =head1 SEE ALSO
130              
131             This module was inspired by the MATLAB program from John Lipp :
132             http://www.mathworks.com/matlabcentral/fileexchange/6247
133              
134             Tektronics provided isf to csv conversion program (.exe) at
135             http://www2.tek.com/cmswpt/swdetails.lotr?ct=SW&cs=sut&ci=5355&lc=EN
136              
137             =head1 AUTHOR
138              
139             Ruizhe Yang, C<< >>
140              
141             =head1 BUGS
142              
143             Please report any bugs or feature requests to C
144             rt.cpan.org>, or through the web interface at
145             L. I will
146             be notified, and then you'll automatically be notified of progress on
147             your bug as I make changes.
148              
149              
150              
151              
152             =head1 SUPPORT
153              
154             You can find documentation for this module with the perldoc command.
155              
156             perldoc Parse::ISF
157              
158              
159             You can also look for information at:
160              
161             =over 4
162              
163             =item * RT: CPAN's request tracker
164              
165             L
166              
167             =item * AnnoCPAN: Annotated CPAN documentation
168              
169             L
170              
171             =item * CPAN Ratings
172              
173             L
174              
175             =item * Search CPAN
176              
177             L
178              
179             =back
180              
181             =head1 COPYRIGHT & LICENSE
182              
183             Copyright 2009 Ruizhe Yang, all rights reserved.
184              
185             This program is free software; you can redistribute it and/or modify it
186             under the same terms as Perl itself.
187              
188             =cut
189              
190             1; # End of Parse::ISF