| 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 | ▶ | use strict; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 14 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||
| 16 | # ABSTRACT: encoder/decoder for ASDF formats | ||||||||||||||||||||||||||||||
| 17 | 5 | our $VERSION = '0.03'; # VERSION | |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||
| 19 | 5 | require Exporter; | |||||||||||||||||||||||||||||
| 20 | 5 | our @ISA = qw( Exporter ); | |||||||||||||||||||||||||||||
| 21 | 5 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||||
| 22 | decode | ||||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||
| 25 | 5 | our $debug = 0; | |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||
| 27 | sub decode_FIX | ||||||||||||||||||||||||||||||
| 28 | 1 | ▶ | { | ||||||||||||||||||||||||||||
|
Subroutine
decode_FIX: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 29 | 1 | my( $line ) = @_; | |||||||||||||||||||||||||||||
| 30 | 1 | $line =~ s/^\s+//; | |||||||||||||||||||||||||||||
| 31 | 1 | $line =~ s/\s+$//; | |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||
| 33 | 1 | return split /\s+/, $line; | |||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||
| 36 | sub decode_PAC | ||||||||||||||||||||||||||||||
| 37 | 2 | ▶ | { | ||||||||||||||||||||||||||||
|
Subroutine
decode_PAC: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 38 | 2 | my( $line ) = @_; | |||||||||||||||||||||||||||||
| 39 | 2 | $line =~ s/^\s+//; | |||||||||||||||||||||||||||||
| 40 | 2 | $line =~ s/\s+$//; | |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||
| 42 | 2 | my @elements = $line =~ /([ +-]?\d+)/g; | |||||||||||||||||||||||||||||
| 43 | 2 | return map { s/^[ +]//; $_ } @elements; | |||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||
| 46 | sub decode_SQZ | ||||||||||||||||||||||||||||||
| 47 | 125 | ▶ | { | ||||||||||||||||||||||||||||
|
Subroutine
decode_SQZ: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 48 | 125 | my( $line ) = @_; | |||||||||||||||||||||||||||||
| 49 | 125 | $line =~ s/\s+(\d)/+$1/g; | |||||||||||||||||||||||||||||
| 50 | 125 | $line =~ s/\s+-/-/g; | |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||
| 52 | 125 | $line =~ s/\@/+0/g; | |||||||||||||||||||||||||||||
| 53 | 125 | $line =~ s/([A-I])/'+' . (ord( $1 ) - ord( 'A' ) + 1)/ge; | |||||||||||||||||||||||||||||
| 54 | 125 | $line =~ s/([a-i])/-ord( $1 ) + ord( 'a' ) - 1/ge; | |||||||||||||||||||||||||||||
| 55 | 125 | return decode_DIF( $line ); | |||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||
| 58 | sub decode_DIF | ||||||||||||||||||||||||||||||
| 59 | 126 | ▶ | { | ||||||||||||||||||||||||||||
|
Subroutine
decode_DIF: called CC=15 SCAR=29.3
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 60 | 126 | my( $line ) = @_; | |||||||||||||||||||||||||||||
| 61 | 126 | my @elements; | |||||||||||||||||||||||||||||
| 62 | 126 | ▶ | while( $line ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 63 | 4039 | ▶ | if( $line =~ s/^\+// ) { | ||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||
| 64 | 180 | next; | |||||||||||||||||||||||||||||
| 65 | } elsif( $line =~ s/^(-?\d+)// ) { | ||||||||||||||||||||||||||||||
| 66 | 210 | push @elements, int( $1 ); | |||||||||||||||||||||||||||||
| 67 | 210 | ▶ | print STDERR "got $& -> $elements[-1]\n" if $debug; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 68 | } elsif( $line =~ s/^%(\d*)// ) { | ||||||||||||||||||||||||||||||
| 69 | 65 | ▶ | push @elements, $elements[-1] + ($1 ne '' ? $1 : 0); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 70 | 65 | ▶ | print STDERR "got $& -> $elements[-1]\n" if $debug; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 71 | } elsif( $line =~ s/^([J-R])(\d*)// ) { | ||||||||||||||||||||||||||||||
| 72 | 2211 | ▶ | push @elements, $elements[-1] + | ||||||||||||||||||||||||||||
|
Condition50%1/2
$2 // ""
MC/DC0%0/1
$2 // ""
$2
Truth table50%1/2
A
A= $2
| |||||||||||||||||||||||||||||||
| 73 | ((ord( $1 ) - ord( 'J' ) + 1) . ($2 // '')); | ||||||||||||||||||||||||||||||
| 74 | 2211 | ▶ | print STDERR "got $& -> $elements[-1]\n" if $debug; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 75 | } elsif( $line =~ s/^([j-r])(\d*)// ) { | ||||||||||||||||||||||||||||||
| 76 | 1373 | ▶ | push @elements, $elements[-1] - | ||||||||||||||||||||||||||||
|
Condition50%1/2
$2 // ""
MC/DC0%0/1
$2 // ""
$2
Truth table50%1/2
A
A= $2
| |||||||||||||||||||||||||||||||
| 77 | ((ord( $1 ) - ord( 'j' ) + 1) . ($2 // '')); | ||||||||||||||||||||||||||||||
| 78 | 1373 | ▶ | print STDERR "got $& -> $elements[-1]\n" if $debug; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 79 | } elsif( $line =~ s/^(.)// ) { | ||||||||||||||||||||||||||||||
| 80 | 0 | warn "unrecognised symbol: $1"; | |||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||
| 83 | 126 | return @elements; | |||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||
| 86 | sub decode_DIFDUP | ||||||||||||||||||||||||||||||
| 87 | 124 | ▶ | { | ||||||||||||||||||||||||||||
|
Subroutine
decode_DIFDUP: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 88 | 124 | my( $line ) = @_; | |||||||||||||||||||||||||||||
| 89 | 124 | $line =~ s/(.)([S-Z])/$1 x ( ord( $2 ) - ord( 'S' ) + 1 )/ge; | |||||||||||||||||||||||||||||
| 90 | 124 | $line =~ s/(.)s/$1 x 9/g; | |||||||||||||||||||||||||||||
| 91 | 124 | return decode_SQZ( $line ); | |||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||
| 94 | sub decode | ||||||||||||||||||||||||||||||
| 95 | 122 | ▶ | { | ||||||||||||||||||||||||||||
|
Subroutine
decode: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 96 | 122 | &decode_DIFDUP; | |||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||
| 99 | 5 | 1; | |||||||||||||||||||||||||||||