line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
2
|
|
|
|
|
|
|
#$Author: andrius $ |
3
|
|
|
|
|
|
|
#$Date: 2018-11-21 09:40:40 +0200 (Tr, 21 lapkr. 2018) $ |
4
|
|
|
|
|
|
|
#$Revision: 32 $ |
5
|
|
|
|
|
|
|
#$URL: svn+ssh://www.crystallography.net/home/coder/svn-repositories/jcamp-dx/tags/v0.02/lib/JCAMP/DX/ASDF.pm $ |
6
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
7
|
|
|
|
|
|
|
#* |
8
|
|
|
|
|
|
|
# Encoder/decoder for ASDF formats. |
9
|
|
|
|
|
|
|
#** |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
package JCAMP::DX::ASDF; |
12
|
|
|
|
|
|
|
|
13
|
5
|
|
|
5
|
|
500
|
use strict; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
136
|
|
14
|
5
|
|
|
5
|
|
22
|
use warnings; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
4872
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
require Exporter; |
17
|
|
|
|
|
|
|
our @ISA = qw( Exporter ); |
18
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
19
|
|
|
|
|
|
|
decode |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our $debug = 0; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub decode_FIX |
25
|
|
|
|
|
|
|
{ |
26
|
1
|
|
|
1
|
0
|
85
|
my( $line ) = @_; |
27
|
1
|
|
|
|
|
3
|
$line =~ s/^\s+//; |
28
|
1
|
|
|
|
|
5
|
$line =~ s/\s+$//; |
29
|
|
|
|
|
|
|
|
30
|
1
|
|
|
|
|
13
|
return split /\s+/, $line; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub decode_PAC |
34
|
|
|
|
|
|
|
{ |
35
|
2
|
|
|
2
|
0
|
5
|
my( $line ) = @_; |
36
|
2
|
|
|
|
|
8
|
$line =~ s/^\s+//; |
37
|
2
|
|
|
|
|
8
|
$line =~ s/\s+$//; |
38
|
|
|
|
|
|
|
|
39
|
2
|
|
|
|
|
20
|
my @elements = $line =~ /([ +-]?\d+)/g; |
40
|
2
|
|
|
|
|
6
|
return map { s/^[ +]//; $_ } @elements; |
|
20
|
|
|
|
|
38
|
|
|
20
|
|
|
|
|
42
|
|
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub decode_SQZ |
44
|
|
|
|
|
|
|
{ |
45
|
125
|
|
|
125
|
0
|
176
|
my( $line ) = @_; |
46
|
125
|
|
|
|
|
285
|
$line =~ s/\s+(\d)/+$1/g; |
47
|
125
|
|
|
|
|
187
|
$line =~ s/\s+-/-/g; |
48
|
|
|
|
|
|
|
|
49
|
125
|
|
|
|
|
166
|
$line =~ s/\@/+0/g; |
50
|
125
|
|
|
|
|
316
|
$line =~ s/([A-I])/'+' . (ord( $1 ) - ord( 'A' ) + 1)/ge; |
|
120
|
|
|
|
|
406
|
|
51
|
125
|
|
|
|
|
255
|
$line =~ s/([a-i])/-ord( $1 ) + ord( 'a' ) - 1/ge; |
|
6
|
|
|
|
|
15
|
|
52
|
125
|
|
|
|
|
200
|
return decode_DIF( $line ); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub decode_DIF |
56
|
|
|
|
|
|
|
{ |
57
|
126
|
|
|
126
|
0
|
216
|
my( $line ) = @_; |
58
|
126
|
|
|
|
|
158
|
my @elements; |
59
|
126
|
|
|
|
|
234
|
while( $line ) { |
60
|
4039
|
100
|
|
|
|
16570
|
if( $line =~ s/^\+// ) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
61
|
180
|
|
|
|
|
361
|
next; |
62
|
|
|
|
|
|
|
} elsif( $line =~ s/^(-?\d+)// ) { |
63
|
210
|
|
|
|
|
466
|
push @elements, int( $1 ); |
64
|
210
|
50
|
|
|
|
465
|
print STDERR "got $& -> $elements[-1]\n" if $debug; |
65
|
|
|
|
|
|
|
} elsif( $line =~ s/^%(\d*)// ) { |
66
|
65
|
50
|
|
|
|
151
|
push @elements, $elements[-1] + ($1 ne '' ? $1 : 0); |
67
|
65
|
50
|
|
|
|
163
|
print STDERR "got $& -> $elements[-1]\n" if $debug; |
68
|
|
|
|
|
|
|
} elsif( $line =~ s/^([J-R])(\d*)// ) { |
69
|
2211
|
|
50
|
|
|
6532
|
push @elements, $elements[-1] + |
70
|
|
|
|
|
|
|
((ord( $1 ) - ord( 'J' ) + 1) . ($2 // '')); |
71
|
2211
|
50
|
|
|
|
4647
|
print STDERR "got $& -> $elements[-1]\n" if $debug; |
72
|
|
|
|
|
|
|
} elsif( $line =~ s/^([j-r])(\d*)// ) { |
73
|
1373
|
|
50
|
|
|
4023
|
push @elements, $elements[-1] - |
74
|
|
|
|
|
|
|
((ord( $1 ) - ord( 'j' ) + 1) . ($2 // '')); |
75
|
1373
|
50
|
|
|
|
2951
|
print STDERR "got $& -> $elements[-1]\n" if $debug; |
76
|
|
|
|
|
|
|
} elsif( $line =~ s/^(.)// ) { |
77
|
0
|
|
|
|
|
0
|
warn "unrecognised symbol: $1"; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
126
|
|
|
|
|
912
|
return @elements; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub decode_DIFDUP |
84
|
|
|
|
|
|
|
{ |
85
|
124
|
|
|
124
|
0
|
215
|
my( $line ) = @_; |
86
|
124
|
|
|
|
|
804
|
$line =~ s/(.)([S-Z])/$1 x ( ord( $2 ) - ord( 'S' ) + 1 )/ge; |
|
89
|
|
|
|
|
485
|
|
87
|
124
|
|
|
|
|
203
|
$line =~ s/(.)s/$1 x 9/g; |
88
|
124
|
|
|
|
|
202
|
return decode_SQZ( $line ); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub decode |
92
|
|
|
|
|
|
|
{ |
93
|
122
|
|
|
122
|
0
|
185
|
&decode_DIFDUP; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
1; |