File Coverage

blib/lib/Rinchi/CIGIPP/WaveControl.pm
Criterion Covered Total %
statement 79 115 68.7
branch 16 42 38.1
condition 6 18 33.3
subroutine 20 22 90.9
pod 18 18 100.0
total 139 215 64.6


line stmt bran cond sub pod time code
1             #
2             # Rinchi Common Image Generator Interface for Perl
3             # Class Identifier: f78ad832-200e-11de-bdae-001c25551abc
4             # Author: Brian M. Ames
5             #
6              
7             package Rinchi::CIGIPP::WaveControl;
8              
9 1     1   30 use 5.006;
  1         4  
  1         51  
10 1     1   6 use strict;
  1         1  
  1         49  
11 1     1   6 use warnings;
  1         3  
  1         37  
12 1     1   5 use Carp;
  1         2  
  1         5817  
13              
14             require Exporter;
15              
16             our @ISA = qw(Exporter);
17              
18             # Items to export into callers namespace by default. Note: do not export
19             # names by default without a very good reason. Use EXPORT_OK instead.
20             # Do not simply export all your public functions/methods/constants.
21              
22             # This allows declaration use Rinchi::CIGI::AtmosphereControl ':all';
23             # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
24             # will save memory.
25             our %EXPORT_TAGS = ( 'all' => [ qw(
26            
27             ) ] );
28              
29             our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
30              
31             our @EXPORT = qw(
32            
33             );
34              
35             our $VERSION = '0.02';
36              
37             # Preloaded methods go here.
38              
39             =head1 NAME
40              
41             Rinchi::CIGIPP::WaveControl - Perl extension for the Common Image Generator
42             Interface - Wave Control data packet.
43             data packet.
44             =head1 SYNOPSIS
45              
46             use Rinchi::CIGIPP::WaveControl;
47             my $wave_ctl = Rinchi::CIGIPP::WaveControl->new();
48              
49             $packet_type = $wave_ctl->packet_type();
50             $packet_size = $wave_ctl->packet_size();
51             $region_ident = $wave_ctl->region_ident(57556);
52             $entity_ident = $wave_ctl->entity_ident(19952);
53             $wave_ident = $wave_ctl->wave_ident(240);
54             $breaker_type = $wave_ctl->breaker_type(Rinchi::CIGIPP->Plunging);
55             $scope = $wave_ctl->scope(Rinchi::CIGIPP->GlobalScope);
56             $wave_enable = $wave_ctl->wave_enable(Rinchi::CIGIPP->Enable);
57             $wave_height = $wave_ctl->wave_height(83.07);
58             $wave_length = $wave_ctl->wave_length(12.084);
59             $period = $wave_ctl->period(54.785);
60             $direction = $wave_ctl->direction(24.212);
61             $phase_offset = $wave_ctl->phase_offset(69.289);
62             $leading = $wave_ctl->leading(26.815);
63              
64             =head1 DESCRIPTION
65              
66             The Wave Control packet is used to specify the behavior of waves propagating
67             across the surface of a body of water. Examples include simulated swells and
68             wind chop.
69              
70             The basic waveform is defined by a wave height, wavelength, period, and
71             direction of propagation. Wave height refers to the vertical distance between
72             the wave's crest and trough. The wavelength is the distance from one crest to
73             the next or from one trough to the next.
74              
75             The Phase Offset attribute specifies a phase angle to be added to the IG's
76             reference phase. This is useful for modeling the interference patterns produced
77             within a multiple-wave system. The Leading attribute determines the
78             cross-sectional shape of the wave. This value is the phase angle at which the
79             crest of the wave occurs. For a sinusoidal wave, this angle is zero (0)
80             degrees. As the value increases, the trough flattens and the crest moves toward
81             the front of the wave.
82              
83             =head2 EXPORT
84              
85             None by default.
86              
87             #==============================================================================
88              
89             =item new $wave_ctl = Rinchi::CIGIPP::WaveControl->new()
90              
91             Constructor for Rinchi::WaveControl.
92              
93             =cut
94              
95             sub new {
96 1     1 1 224 my $class = shift;
97 1   33     8 $class = ref($class) || $class;
98              
99 1         17 my $self = {
100             '_Buffer' => '',
101             '_ClassIdent' => 'f78ad832-200e-11de-bdae-001c25551abc',
102             '_Pack' => 'CCSCCSffffff',
103             '_Swap1' => 'CCvCCvVVVVVV',
104             '_Swap2' => 'CCnCCnNNNNNN',
105             'packetType' => 14,
106             'packetSize' => 32,
107             'region_entityIdent' => 0,
108             'waveIdent' => 0,
109             '_bitfields1' => 0, # Includes bitfields unused26, breakerType, scope, and waveEnable.
110             'breakerType' => 0,
111             'scope' => 0,
112             'waveEnable' => 0,
113             '_unused27' => 0,
114             'waveHeight' => 0,
115             'waveLength' => 0,
116             'period' => 0,
117             'direction' => 0,
118             'phaseOffset' => 0,
119             'leading' => 0,
120             };
121              
122 1 50       6 if (@_) {
123 0 0       0 if (ref($_[0]) eq 'ARRAY') {
    0          
124 0         0 $self->{'_Buffer'} = $_[0][0];
125             } elsif (ref($_[0]) eq 'HASH') {
126 0         0 foreach my $attr (keys %{$_[0]}) {
  0         0  
127 0 0       0 $self->{"_$attr"} = $_[0]->{$attr} unless ($attr =~ /^_/);
128             }
129             }
130             }
131              
132 1         3 bless($self,$class);
133 1         3 return $self;
134             }
135              
136             #==============================================================================
137              
138             =item sub packet_type()
139              
140             $value = $wave_ctl->packet_type();
141              
142             Data Packet Identifier.
143              
144             This attribute identifies this data packet as the Wave Control packet. The
145             value of this attribute must be 14.
146              
147             =cut
148              
149             sub packet_type() {
150 1     1 1 6 my ($self) = @_;
151 1         8 return $self->{'packetType'};
152             }
153              
154             #==============================================================================
155              
156             =item sub packet_size()
157              
158             $value = $wave_ctl->packet_size();
159              
160             Data Packet Size. This attribute indicates the number of bytes in this data
161             packet. The value of this attribute must be 32.
162              
163             =cut
164              
165             sub packet_size() {
166 1     1 1 5 my ($self) = @_;
167 1         3 return $self->{'packetSize'};
168             }
169              
170             #==============================================================================
171              
172             =item sub region_ident([$newValue])
173              
174             $value = $wave_ctl->region_ident($newValue);
175              
176             Entity ID. (Entity-based Surface Conditions)
177              
178             This attribute specifies the entity to which the surface attributes in this
179             packet are applied.
180              
181              
182              
183             =cut
184              
185             sub region_ident() {
186 1     1 1 6 my ($self,$nv) = @_;
187 1 50       4 if (defined($nv)) {
188 1         2 $self->{'region_entityIdent'} = $nv;
189             }
190 1         3 return $self->{'region_entityIdent'};
191             }
192              
193             #==============================================================================
194              
195             =item sub entity_ident([$newValue])
196              
197             $value = $wave_ctl->entity_ident($newValue);
198              
199             Region ID. (Regional Surface Conditions)
200              
201             This attribute specifies the region to which the surface attributes are
202             confined.
203             Note: Entity ID/Region ID is ignored if Scope is set to Global (0).
204              
205             =cut
206              
207             sub entity_ident() {
208 1     1 1 5 my ($self,$nv) = @_;
209 1 50       4 if (defined($nv)) {
210 1         2 $self->{'region_entityIdent'} = $nv;
211             }
212 1         4 return $self->{'region_entityIdent'};
213             }
214              
215             #==============================================================================
216              
217             =item sub wave_ident([$newValue])
218              
219             $value = $wave_ctl->wave_ident($newValue);
220              
221             Wave ID.
222              
223             This attribute specifies the wave to which the attributes in this packet are applied.
224              
225             =cut
226              
227             sub wave_ident() {
228 1     1 1 5 my ($self,$nv) = @_;
229 1 50       4 if (defined($nv)) {
230 1         2 $self->{'waveIdent'} = $nv;
231             }
232 1         4 return $self->{'waveIdent'};
233             }
234              
235             #==============================================================================
236              
237             =item sub breaker_type([$newValue])
238              
239             $value = $wave_ctl->breaker_type($newValue);
240              
241             Breaker Type.
242              
243             This attribute specifies the type of breaker within the surf zone. This may be
244             one of the following values:
245              
246             Plunging - Plunging waves peak until the wave forms a vertical wall, at which
247             point the crest moves faster than the base of the breaker. The wave will then
248             break violently into the wave trough.
249              
250             Spilling - Spilling breakers break gradually over a great distance. White water
251             forms over the crest, which spills down the face of the breaker.
252              
253             Surging - Surging breakers advance toward the beach as vertical walls of water.
254             Unlike with plunging and spilling breakers, the crest does not fall over the
255             front of the wave.
256              
257             Plunging 0
258             Spilling 1
259             Surging 2
260              
261             =cut
262              
263             sub breaker_type() {
264 1     1 1 2 my ($self,$nv) = @_;
265 1 50       4 if (defined($nv)) {
266 1 50 33     14 if (($nv==0) or ($nv==1) or ($nv==2)) {
      33        
267 1         2 $self->{'breakerType'} = $nv;
268 1         3 $self->{'_bitfields1'} |= ($nv << 3) &0x18;
269             } else {
270 0         0 carp "breaker_type must be 0 (Plunging), 1 (Spilling), or 2 (Surging).";
271             }
272             }
273 1         3 return (($self->{'_bitfields1'} & 0x18) >> 3);
274             }
275              
276             #==============================================================================
277              
278             =item sub scope([$newValue])
279              
280             $value = $wave_ctl->scope($newValue);
281              
282             Scope.
283              
284             This attribute specifies whether the wave is defined for global, regional, or
285             entity-controlled maritime surface conditions. If this value is set to Regional
286             (1), the wave properties are applied only within the region specified by Region
287             ID. If this value is set to Entity (2), the properties are applied to the area
288             defined by the moving model specified by Entity ID.
289              
290             GlobalScope 0
291             RegionalScope 1
292             EntityScope 2
293              
294             =cut
295              
296             sub scope() {
297 1     1 1 3 my ($self,$nv) = @_;
298 1 50       3 if (defined($nv)) {
299 1 50 33     6 if (($nv==0) or ($nv==1) or ($nv==2)) {
      33        
300 1         9 $self->{'scope'} = $nv;
301 1         2 $self->{'_bitfields1'} |= ($nv << 1) &0x06;
302             } else {
303 0         0 carp "scope must be 0 (GlobalScope), 1 (RegionalScope), or 2 (EntityScope).";
304             }
305             }
306 1         4 return (($self->{'_bitfields1'} & 0x06) >> 1);
307             }
308              
309             #==============================================================================
310              
311             =item sub wave_enable([$newValue])
312              
313             $value = $wave_ctl->wave_enable($newValue);
314              
315             Wave Enable.
316              
317             This attribute determines whether the wave is enabled or disabled. A disabled
318             wave does not contribute to the shape of the water's surface.
319              
320             Disable 0
321             Enable 1
322              
323             =cut
324              
325             sub wave_enable() {
326 1     1 1 3 my ($self,$nv) = @_;
327 1 50       4 if (defined($nv)) {
328 1 50 33     8 if (($nv==0) or ($nv==1)) {
329 1         2 $self->{'waveEnable'} = $nv;
330 1         2 $self->{'_bitfields1'} |= $nv &0x01;
331             } else {
332 0         0 carp "wave_enable must be 0 (Disable), or 1 (Enable).";
333             }
334             }
335 1         3 return ($self->{'_bitfields1'} & 0x01);
336             }
337              
338             #==============================================================================
339              
340             =item sub wave_height([$newValue])
341              
342             $value = $wave_ctl->wave_height($newValue);
343              
344             Wave Height.
345              
346             This attribute specifies the average vertical distance measured in meters from
347             trough to crest produced by the wave. Wave Height is centered on Sea Surface Height.
348              
349             =cut
350              
351             sub wave_height() {
352 1     1 1 4 my ($self,$nv) = @_;
353 1 50       4 if (defined($nv)) {
354 1         2 $self->{'waveHeight'} = $nv;
355             }
356 1         4 return $self->{'waveHeight'};
357             }
358              
359             #==============================================================================
360              
361             =item sub wave_length([$newValue])
362              
363             $value = $wave_ctl->wave_length($newValue);
364              
365             Wavelength.
366              
367             This attribute specifies the distance from a particular phase on a wave to the
368             same phase on an adjacent wave.
369              
370             =cut
371              
372             sub wave_length() {
373 1     1 1 4 my ($self,$nv) = @_;
374 1 50       4 if (defined($nv)) {
375 1         2 $self->{'waveLength'} = $nv;
376             }
377 1         11 return $self->{'waveLength'};
378             }
379              
380             #==============================================================================
381              
382             =item sub period([$newValue])
383              
384             $value = $wave_ctl->period($newValue);
385              
386             Period.
387              
388             This attribute specifies the time required for one complete oscillation of the wave.
389              
390             =cut
391              
392             sub period() {
393 1     1 1 4 my ($self,$nv) = @_;
394 1 50       3 if (defined($nv)) {
395 1         3 $self->{'period'} = $nv;
396             }
397 1         3 return $self->{'period'};
398             }
399              
400             #==============================================================================
401              
402             =item sub direction([$newValue])
403              
404             $value = $wave_ctl->direction($newValue);
405              
406             Direction.
407              
408             This attribute specifies the direction in which the wave propagates measured in
409             degrees from true north.
410              
411             =cut
412              
413             sub direction() {
414 1     1 1 4 my ($self,$nv) = @_;
415 1 50       3 if (defined($nv)) {
416 1         2 $self->{'direction'} = $nv;
417             }
418 1         3 return $self->{'direction'};
419             }
420              
421             #==============================================================================
422              
423             =item sub phase_offset([$newValue])
424              
425             $value = $wave_ctl->phase_offset($newValue);
426              
427             Phase Offset.
428              
429             This attribute specifies a phase offset for the wave.
430              
431             =cut
432              
433             sub phase_offset() {
434 1     1 1 4 my ($self,$nv) = @_;
435 1 50       3 if (defined($nv)) {
436 1         2 $self->{'phaseOffset'} = $nv;
437             }
438 1         3 return $self->{'phaseOffset'};
439             }
440              
441             #==============================================================================
442              
443             =item sub leading([$newValue])
444              
445             $value = $wave_ctl->leading($newValue);
446              
447             Leading.This attribute specifies the phase angle at which the crest occurs.
448              
449             =cut
450              
451             sub leading() {
452 1     1 1 10 my ($self,$nv) = @_;
453 1 50       4 if (defined($nv)) {
454 1         3 $self->{'leading'} = $nv;
455             }
456 1         2 return $self->{'leading'};
457             }
458              
459             #==========================================================================
460              
461             =item sub pack()
462              
463             $value = $wave_ctl->pack();
464              
465             Returns the packed data packet.
466              
467             =cut
468              
469             sub pack($) {
470 1     1 1 6 my $self = shift ;
471            
472 1         11 $self->{'_Buffer'} = CORE::pack($self->{'_Pack'},
473             $self->{'packetType'},
474             $self->{'packetSize'},
475             $self->{'region_entityIdent'},
476             $self->{'waveIdent'},
477             $self->{'_bitfields1'}, # Includes bitfields unused26, breakerType, scope, and waveEnable.
478             $self->{'_unused27'},
479             $self->{'waveHeight'},
480             $self->{'waveLength'},
481             $self->{'period'},
482             $self->{'direction'},
483             $self->{'phaseOffset'},
484             $self->{'leading'},
485             );
486              
487 1         4 return $self->{'_Buffer'};
488             }
489              
490             #==========================================================================
491              
492             =item sub unpack()
493              
494             $value = $wave_ctl->unpack();
495              
496             Unpacks the packed data packet.
497              
498             =cut
499              
500             sub unpack($) {
501 0     0 1   my $self = shift @_;
502            
503 0 0         if (@_) {
504 0           $self->{'_Buffer'} = shift @_;
505             }
506 0           my ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l) = CORE::unpack($self->{'_Pack'},$self->{'_Buffer'});
507 0           $self->{'packetType'} = $a;
508 0           $self->{'packetSize'} = $b;
509 0           $self->{'region_entityIdent'} = $c;
510 0           $self->{'waveIdent'} = $d;
511 0           $self->{'_bitfields1'} = $e; # Includes bitfields unused26, breakerType, scope, and waveEnable.
512 0           $self->{'_unused27'} = $f;
513 0           $self->{'waveHeight'} = $g;
514 0           $self->{'waveLength'} = $h;
515 0           $self->{'period'} = $i;
516 0           $self->{'direction'} = $j;
517 0           $self->{'phaseOffset'} = $k;
518 0           $self->{'leading'} = $l;
519              
520 0           $self->{'breakerType'} = $self->breaker_type();
521 0           $self->{'scope'} = $self->scope();
522 0           $self->{'waveEnable'} = $self->wave_enable();
523              
524 0           return $self->{'_Buffer'};
525             }
526              
527             #==========================================================================
528              
529             =item sub byte_swap()
530              
531             $obj_name->byte_swap();
532              
533             Byte swaps the packed data packet.
534              
535             =cut
536              
537             sub byte_swap($) {
538 0     0 1   my $self = shift @_;
539            
540 0 0         if (@_) {
541 0           $self->{'_Buffer'} = shift @_;
542             } else {
543 0           $self->pack();
544             }
545 0           my ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l) = CORE::unpack($self->{'_Swap1'},$self->{'_Buffer'});
546              
547 0           $self->{'_Buffer'} = CORE::pack($self->{'_Swap2'},$a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l);
548 0           $self->unpack();
549              
550 0           return $self->{'_Buffer'};
551             }
552              
553             1;
554             __END__