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/trunk/lib/JCAMP/DX/ASDF.pm $ |
6
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
7
|
|
|
|
|
|
|
#* |
8
|
|
|
|
|
|
|
# Encoder/decoder for ASDF formats. |
9
|
|
|
|
|
|
|
#** |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
package JCAMP::DX::ASDF; |
12
|
|
|
|
|
|
|
|
13
|
2
|
|
|
2
|
|
479
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
56
|
|
14
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
2091
|
|
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
|
|
|
|
|
34
|
$line =~ s/^\s+//; |
28
|
1
|
|
|
|
|
7
|
$line =~ s/\s+$//; |
29
|
|
|
|
|
|
|
|
30
|
1
|
|
|
|
|
14
|
return split /\s+/, $line; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub decode_PAC |
34
|
|
|
|
|
|
|
{ |
35
|
2
|
|
|
2
|
0
|
6
|
my( $line ) = @_; |
36
|
2
|
|
|
|
|
7
|
$line =~ s/^\s+//; |
37
|
2
|
|
|
|
|
7
|
$line =~ s/\s+$//; |
38
|
|
|
|
|
|
|
|
39
|
2
|
|
|
|
|
20
|
my @elements = $line =~ /([ +-]?\d+)/g; |
40
|
2
|
|
|
|
|
5
|
return map { s/^[ +]//; $_ } @elements; |
|
20
|
|
|
|
|
32
|
|
|
20
|
|
|
|
|
46
|
|
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub decode_SQZ |
44
|
|
|
|
|
|
|
{ |
45
|
11
|
|
|
11
|
0
|
36
|
my( $line ) = @_; |
46
|
11
|
|
|
|
|
72
|
$line =~ s/\s+(\d)/+$1/g; |
47
|
11
|
|
|
|
|
26
|
$line =~ s/\s+-/-/g; |
48
|
|
|
|
|
|
|
|
49
|
11
|
|
|
|
|
25
|
$line =~ s/\@/+0/g; |
50
|
11
|
|
|
|
|
25
|
$line =~ s/([A-I])/'+' . (ord( $1 ) - ord( 'A' ) + 1)/ge; |
|
10
|
|
|
|
|
30
|
|
51
|
11
|
|
|
|
|
20
|
$line =~ s/([a-i])/-ord( $1 ) + ord( 'a' ) - 1/ge; |
|
6
|
|
|
|
|
16
|
|
52
|
11
|
|
|
|
|
23
|
return decode_DIF( $line ); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub decode_DIF |
56
|
|
|
|
|
|
|
{ |
57
|
12
|
|
|
12
|
0
|
34
|
my( $line ) = @_; |
58
|
12
|
|
|
|
|
22
|
my @elements; |
59
|
12
|
|
|
|
|
32
|
while( $line ) { |
60
|
211
|
100
|
|
|
|
766
|
if( $line =~ s/^\+// ) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
61
|
50
|
|
|
|
|
93
|
next; |
62
|
|
|
|
|
|
|
} elsif( $line =~ s/^(-?\d+)// ) { |
63
|
76
|
|
|
|
|
149
|
push @elements, int( $1 ); |
64
|
76
|
50
|
|
|
|
169
|
print STDERR "got $& -> $elements[-1]\n" if $debug; |
65
|
|
|
|
|
|
|
} elsif( $line =~ s/^%(\d*)// ) { |
66
|
13
|
50
|
|
|
|
32
|
push @elements, $elements[-1] + ($1 ne '' ? $1 : 0); |
67
|
13
|
50
|
|
|
|
46
|
print STDERR "got $& -> $elements[-1]\n" if $debug; |
68
|
|
|
|
|
|
|
} elsif( $line =~ s/^([J-R])(\d*)// ) { |
69
|
39
|
|
50
|
|
|
116
|
push @elements, $elements[-1] + |
70
|
|
|
|
|
|
|
((ord( $1 ) - ord( 'J' ) + 1) . ($2 // '')); |
71
|
39
|
50
|
|
|
|
87
|
print STDERR "got $& -> $elements[-1]\n" if $debug; |
72
|
|
|
|
|
|
|
} elsif( $line =~ s/^([j-r])(\d*)// ) { |
73
|
33
|
|
50
|
|
|
97
|
push @elements, $elements[-1] - |
74
|
|
|
|
|
|
|
((ord( $1 ) - ord( 'j' ) + 1) . ($2 // '')); |
75
|
33
|
50
|
|
|
|
69
|
print STDERR "got $& -> $elements[-1]\n" if $debug; |
76
|
|
|
|
|
|
|
} elsif( $line =~ s/^(.)// ) { |
77
|
0
|
|
|
|
|
0
|
warn "unrecognised symbol: $1"; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
12
|
|
|
|
|
82
|
return @elements; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub decode_DIFDUP |
84
|
|
|
|
|
|
|
{ |
85
|
10
|
|
|
10
|
0
|
20
|
my( $line ) = @_; |
86
|
10
|
|
|
|
|
81
|
$line =~ s/(.)([S-Z])/$1 x ( ord( $2 ) - ord( 'S' ) + 1 )/ge; |
|
9
|
|
|
|
|
44
|
|
87
|
10
|
|
|
|
|
22
|
$line =~ s/(.)s/$1 x 9/g; |
88
|
10
|
|
|
|
|
20
|
return decode_SQZ( $line ); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub decode |
92
|
|
|
|
|
|
|
{ |
93
|
8
|
|
|
8
|
0
|
17
|
&decode_DIFDUP; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
1; |