| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Parse::Tektronix::ISF; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 3 |  |  | 3 |  | 70529 | use warnings; | 
|  | 3 |  |  |  |  | 9 |  | 
|  | 3 |  |  |  |  | 112 |  | 
| 4 | 3 |  |  | 3 |  | 19 | use strict; | 
|  | 3 |  |  |  |  | 4 |  | 
|  | 3 |  |  |  |  | 105 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 | 3 |  |  | 3 |  | 18 | use Exporter; | 
|  | 3 |  |  |  |  | 16 |  | 
|  | 3 |  |  |  |  | 1895 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | our @ISA = qw(Exporter); | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | =head1 NAME | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | Parse::Tektronix::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::Tektronix::ISF; | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | my $foo = Parse::Tektronix::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::Tektronix::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::Tektronix::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::Tektronix::ISF::Read('filename.isf'); | 
| 75 |  |  |  |  |  |  | my ($x, $y) = @{$foo->{DATA}[999]}; | 
| 76 |  |  |  |  |  |  |  | 
| 77 |  |  |  |  |  |  | =cut | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | sub Read { | 
| 80 | 3 |  |  | 3 | 1 | 766 | my ($fn) = @_; | 
| 81 |  |  |  |  |  |  |  | 
| 82 | 3 |  |  |  |  | 61 | my $size = -s $fn; | 
| 83 | 3 |  |  |  |  | 6 | my $header; | 
| 84 | 3 |  |  |  |  | 7 | my $fileopen = 1; | 
| 85 | 3 | 100 |  |  |  | 112 | open F, $fn or return undef; | 
| 86 | 2 |  |  |  |  | 9 | binmode F; | 
| 87 | 2 |  |  |  |  | 55 | read F, $header, 269; | 
| 88 | 2 |  |  |  |  | 16 | $header =~ s/:WFMPRE://; | 
| 89 | 2 |  |  |  |  | 14 | $header =~ s/:CURVE//; | 
| 90 | 2 |  |  |  |  | 5 | my $h; | 
| 91 | 2 |  |  |  |  | 89 | %$h = ($header =~ /(\S+)\s+(.+?);/g); | 
| 92 |  |  |  |  |  |  |  | 
| 93 | 2 |  |  |  |  | 9 | my $datablock; | 
| 94 | 2 |  |  |  |  | 114 | read F, $datablock, 2*$h->{NR_PT}; | 
| 95 | 2 |  |  |  |  | 23853 | my @iy = unpack 'v*', $datablock; | 
| 96 | 20000 |  |  |  |  | 83349 | $h->{DATA} = [map { | 
| 97 | 2 |  |  |  |  | 2686 | [$h->{XZERO} + $h->{XINCR}*$_, | 
| 98 |  |  |  |  |  |  | $h->{YMULT}*($iy[$_] - $h->{YOFF})] | 
| 99 |  |  |  |  |  |  | } 0..$#iy]; | 
| 100 | 2 |  |  |  |  | 1410 | close F; | 
| 101 |  |  |  |  |  |  |  | 
| 102 | 2 |  |  |  |  | 2094 | 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 | 12 | my ($in, $out) = @_; | 
| 116 | 1 | 50 |  |  |  | 6 | unless ($out) { | 
| 117 | 1 |  |  |  |  | 3 | $out = $in; | 
| 118 | 1 |  |  |  |  | 9 | $out =~ s/isf$/csv/i; | 
| 119 |  |  |  |  |  |  | } | 
| 120 | 1 |  |  |  |  | 5 | my $h = Read($in); | 
| 121 | 1 | 50 |  |  |  | 282 | open F, ">$out" or return undef; | 
| 122 | 1 |  |  |  |  | 4 | for my $l (@{$h->{DATA}}) { | 
|  | 1 |  |  |  |  | 5 |  | 
| 123 | 10000 |  |  |  |  | 10339 | print F join(',', @{$l}),"\n"; | 
|  | 10000 |  |  |  |  | 49464 |  | 
| 124 |  |  |  |  |  |  | } | 
| 125 | 1 |  |  |  |  | 74 | close F; | 
| 126 | 1 |  |  |  |  | 4112 | 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::Tektronix::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::Tektronix::ISF |