line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
2
|
|
|
|
|
|
|
#$Author: andrius $ |
3
|
|
|
|
|
|
|
#$Date: 2021-02-10 13:44:25 +0200 (Tr, 10 vas. 2021) $ |
4
|
|
|
|
|
|
|
#$Revision: 94 $ |
5
|
|
|
|
|
|
|
#$URL: svn+ssh://www.crystallography.net/home/coder/svn-repositories/JCAMP-DX/tags/v0.03/lib/JCAMP/DX/ASDF.pm $ |
6
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
7
|
|
|
|
|
|
|
#* |
8
|
|
|
|
|
|
|
# Encoder/decoder for ASDF formats. |
9
|
|
|
|
|
|
|
#** |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
package JCAMP::DX::ASDF; |
12
|
|
|
|
|
|
|
|
13
|
5
|
|
|
5
|
|
547
|
use strict; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
144
|
|
14
|
5
|
|
|
5
|
|
24
|
use warnings; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
5204
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# ABSTRACT: encoder/decoder for ASDF formats |
17
|
|
|
|
|
|
|
our $VERSION = '0.03'; # VERSION |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
require Exporter; |
20
|
|
|
|
|
|
|
our @ISA = qw( Exporter ); |
21
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
22
|
|
|
|
|
|
|
decode |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
our $debug = 0; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub decode_FIX |
28
|
|
|
|
|
|
|
{ |
29
|
1
|
|
|
1
|
0
|
85
|
my( $line ) = @_; |
30
|
1
|
|
|
|
|
4
|
$line =~ s/^\s+//; |
31
|
1
|
|
|
|
|
5
|
$line =~ s/\s+$//; |
32
|
|
|
|
|
|
|
|
33
|
1
|
|
|
|
|
12
|
return split /\s+/, $line; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub decode_PAC |
37
|
|
|
|
|
|
|
{ |
38
|
2
|
|
|
2
|
0
|
6
|
my( $line ) = @_; |
39
|
2
|
|
|
|
|
7
|
$line =~ s/^\s+//; |
40
|
2
|
|
|
|
|
7
|
$line =~ s/\s+$//; |
41
|
|
|
|
|
|
|
|
42
|
2
|
|
|
|
|
21
|
my @elements = $line =~ /([ +-]?\d+)/g; |
43
|
2
|
|
|
|
|
4
|
return map { s/^[ +]//; $_ } @elements; |
|
20
|
|
|
|
|
34
|
|
|
20
|
|
|
|
|
45
|
|
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub decode_SQZ |
47
|
|
|
|
|
|
|
{ |
48
|
125
|
|
|
125
|
0
|
226
|
my( $line ) = @_; |
49
|
125
|
|
|
|
|
290
|
$line =~ s/\s+(\d)/+$1/g; |
50
|
125
|
|
|
|
|
184
|
$line =~ s/\s+-/-/g; |
51
|
|
|
|
|
|
|
|
52
|
125
|
|
|
|
|
165
|
$line =~ s/\@/+0/g; |
53
|
125
|
|
|
|
|
324
|
$line =~ s/([A-I])/'+' . (ord( $1 ) - ord( 'A' ) + 1)/ge; |
|
120
|
|
|
|
|
455
|
|
54
|
125
|
|
|
|
|
244
|
$line =~ s/([a-i])/-ord( $1 ) + ord( 'a' ) - 1/ge; |
|
6
|
|
|
|
|
19
|
|
55
|
125
|
|
|
|
|
204
|
return decode_DIF( $line ); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub decode_DIF |
59
|
|
|
|
|
|
|
{ |
60
|
126
|
|
|
126
|
0
|
224
|
my( $line ) = @_; |
61
|
126
|
|
|
|
|
160
|
my @elements; |
62
|
126
|
|
|
|
|
241
|
while( $line ) { |
63
|
4039
|
100
|
|
|
|
17250
|
if( $line =~ s/^\+// ) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
64
|
180
|
|
|
|
|
365
|
next; |
65
|
|
|
|
|
|
|
} elsif( $line =~ s/^(-?\d+)// ) { |
66
|
210
|
|
|
|
|
473
|
push @elements, int( $1 ); |
67
|
210
|
50
|
|
|
|
498
|
print STDERR "got $& -> $elements[-1]\n" if $debug; |
68
|
|
|
|
|
|
|
} elsif( $line =~ s/^%(\d*)// ) { |
69
|
65
|
50
|
|
|
|
178
|
push @elements, $elements[-1] + ($1 ne '' ? $1 : 0); |
70
|
65
|
50
|
|
|
|
145
|
print STDERR "got $& -> $elements[-1]\n" if $debug; |
71
|
|
|
|
|
|
|
} elsif( $line =~ s/^([J-R])(\d*)// ) { |
72
|
2211
|
|
50
|
|
|
6565
|
push @elements, $elements[-1] + |
73
|
|
|
|
|
|
|
((ord( $1 ) - ord( 'J' ) + 1) . ($2 // '')); |
74
|
2211
|
50
|
|
|
|
4773
|
print STDERR "got $& -> $elements[-1]\n" if $debug; |
75
|
|
|
|
|
|
|
} elsif( $line =~ s/^([j-r])(\d*)// ) { |
76
|
1373
|
|
50
|
|
|
4214
|
push @elements, $elements[-1] - |
77
|
|
|
|
|
|
|
((ord( $1 ) - ord( 'j' ) + 1) . ($2 // '')); |
78
|
1373
|
50
|
|
|
|
2991
|
print STDERR "got $& -> $elements[-1]\n" if $debug; |
79
|
|
|
|
|
|
|
} elsif( $line =~ s/^(.)// ) { |
80
|
0
|
|
|
|
|
0
|
warn "unrecognised symbol: $1"; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
126
|
|
|
|
|
963
|
return @elements; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub decode_DIFDUP |
87
|
|
|
|
|
|
|
{ |
88
|
124
|
|
|
124
|
0
|
222
|
my( $line ) = @_; |
89
|
124
|
|
|
|
|
819
|
$line =~ s/(.)([S-Z])/$1 x ( ord( $2 ) - ord( 'S' ) + 1 )/ge; |
|
89
|
|
|
|
|
481
|
|
90
|
124
|
|
|
|
|
204
|
$line =~ s/(.)s/$1 x 9/g; |
91
|
124
|
|
|
|
|
202
|
return decode_SQZ( $line ); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub decode |
95
|
|
|
|
|
|
|
{ |
96
|
122
|
|
|
122
|
0
|
190
|
&decode_DIFDUP; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
1; |