File Coverage

blib/lib/Rinchi/CIGIPP/AtmosphereControl.pm
Criterion Covered Total %
statement 60 92 65.2
branch 11 32 34.3
condition 4 12 33.3
subroutine 16 18 88.8
pod 14 14 100.0
total 105 168 62.5


line stmt bran cond sub pod time code
1             #
2             # Rinchi Common Image Generator Interface for Perl
3             # Class Identifier: f78acd92-200e-11de-bdaa-001c25551abc
4             # Author: Brian M. Ames
5             #
6              
7             package Rinchi::CIGIPP::AtmosphereControl;
8              
9 1     1   24 use 5.006;
  1         4  
  1         42  
10 1     1   7 use strict;
  1         2  
  1         82  
11 1     1   7 use warnings;
  1         2  
  1         1145  
12 1     1   7 use Carp;
  1         2  
  1         2952  
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.01';
36              
37             # Preloaded methods go here.
38              
39             =head1 NAME
40              
41             Rinchi::CIGIPP::AtmosphereControl - Perl extension for the Common Image
42             Generator Interface - Atmosphere Control data packet.
43             data packet.
44             =head1 SYNOPSIS
45              
46             use Rinchi::CIGIPP::AtmosphereControl;
47             my $atmos_ctl = Rinchi::CIGIPP::AtmosphereControl->new();
48              
49             $packet_type = $atmos_ctl->packet_type();
50             $packet_size = $atmos_ctl->packet_size();
51             $atmospheric_model_enable = $atmos_ctl->atmospheric_model_enable(Rinchi::CIGIPP->Disable);
52             $humidity = $atmos_ctl->humidity(35);
53             $air_temperature = $atmos_ctl->air_temperature(23.357);
54             $visibility_range = $atmos_ctl->visibility_range(47.803);
55             $horizontal_wind_speed = $atmos_ctl->horizontal_wind_speed(55.727);
56             $vertical_wind_speed = $atmos_ctl->vertical_wind_speed(40.386);
57             $wind_direction = $atmos_ctl->wind_direction(47.212);
58             $barometric_pressure = $atmos_ctl->barometric_pressure(17.871);
59              
60             =head1 DESCRIPTION
61              
62             The Atmosphere Control data packet allows the Host to control global
63             atmospheric properties within the simulation.
64              
65             Weather layers and weather entities always take precedence over the global
66             atmospheric conditions. Once the atmospheric properties of a layer or entity
67             are set, global atmospheric changes will not affect the weather inside the
68             layer or entity unless that layer or entity is disabled. The global atmospheric
69             changes will, however, affect the weather within a transition band or
70             transition perimeter.
71              
72             CIGI supports the use of FASCODE, MODTRAN, SEDRIS, or other atmospheric models
73             for determining radiance and transmittance within a heterogeneous atmosphere
74             for sensor simulations. The Atmospheric Model Enable attribute determines
75             whether an atmospheric model is used. The particular model is not specified and
76             is determined by the IG.
77              
78             =head2 EXPORT
79              
80             None by default.
81              
82             #==============================================================================
83              
84             =item new $atmos_ctl = Rinchi::CIGIPP::AtmosphereControl->new()
85              
86             Constructor for Rinchi::AtmosphereControl.
87              
88             =cut
89              
90             sub new {
91 1     1 1 283 my $class = shift;
92 1   33     9 $class = ref($class) || $class;
93              
94 1         17 my $self = {
95             '_Buffer' => '',
96             '_ClassIdent' => 'f78acd92-200e-11de-bdaa-001c25551abc',
97             '_Pack' => 'CCCCffffffI',
98             '_Swap1' => 'CCCCVVVVVVV',
99             '_Swap2' => 'CCCCNNNNNNN',
100             'packetType' => 10,
101             'packetSize' => 32,
102             '_bitfields1' => 0, # Includes bitfields unused15, and atmosphericModelEnable.
103             'atmosphericModelEnable' => 0,
104             'humidity' => 0,
105             'airTemperature' => 0,
106             'visibilityRange' => 0,
107             'horizontalWindSpeed' => 0,
108             'verticalWindSpeed' => 0,
109             'windDirection' => 0,
110             'barometricPressure' => 0,
111             '_unused16' => 0,
112             };
113              
114 1 50       5 if (@_) {
115 0 0       0 if (ref($_[0]) eq 'ARRAY') {
    0          
116 0         0 $self->{'_Buffer'} = $_[0][0];
117             } elsif (ref($_[0]) eq 'HASH') {
118 0         0 foreach my $attr (keys %{$_[0]}) {
  0         0  
119 0 0       0 $self->{"_$attr"} = $_[0]->{$attr} unless ($attr =~ /^_/);
120             }
121             }
122             }
123              
124 1         4 bless($self,$class);
125 1         3 return $self;
126             }
127              
128             #==============================================================================
129              
130             =item sub packet_type()
131              
132             $value = $atmos_ctl->packet_type();
133              
134             Data Packet Identifier.
135              
136             This attribute identifies this data packet as the Atmosphere Control packet.
137             The value of this attribute must be 10.
138              
139             =cut
140              
141             sub packet_type() {
142 1     1 1 6 my ($self) = @_;
143 1         9 return $self->{'packetType'};
144             }
145              
146             #==============================================================================
147              
148             =item sub packet_size()
149              
150             $value = $atmos_ctl->packet_size();
151              
152             Data Packet Size.
153              
154             This attribute indicates the number of bytes in this data packet. The value of
155             this attribute must be 32.
156              
157             =cut
158              
159             sub packet_size() {
160 1     1 1 7 my ($self) = @_;
161 1         4 return $self->{'packetSize'};
162             }
163              
164             #==============================================================================
165              
166             =item sub atmospheric_model_enable([$newValue])
167              
168             $value = $atmos_ctl->atmospheric_model_enable($newValue);
169              
170             Atmospheric Model Enable.
171              
172             This attribute specifies whether the IG should use an atmospheric model to
173             determine spectral radiances for sensor applications. If this attribute is set
174             to Disable (0), source radiances will be calculated. If this attribute is set
175             to Enable (1), apparent radiances will be calculated using the appropriate models.
176              
177             Disable 0
178             Enable 1
179              
180             =cut
181              
182             sub atmospheric_model_enable() {
183 1     1 1 4 my ($self,$nv) = @_;
184 1 50       12 if (defined($nv)) {
185 1 50 33     6 if (($nv==0) or ($nv==1)) {
186 1         3 $self->{'atmosphericModelEnable'} = $nv;
187 1         2 $self->{'_bitfields1'} |= $nv &0x01;
188             } else {
189 0         0 carp "atmospheric_model_enable must be 0 (Disable), or 1 (Enable).";
190             }
191             }
192 1         4 return ($self->{'_bitfields1'} & 0x01);
193             }
194              
195             #==============================================================================
196              
197             =item sub humidity([$newValue])
198              
199             $value = $atmos_ctl->humidity($newValue);
200              
201             Global Humidity.
202              
203             This attribute specifies the global humidity of the environment.
204              
205             =cut
206              
207             sub humidity() {
208 1     1 1 5 my ($self,$nv) = @_;
209 1 50       3 if (defined($nv)) {
210 1 50 33     13 if ($nv>=0 and $nv<=100 and int($nv)==$nv) {
      33        
211 1         2 $self->{'humidity'} = $nv;
212             } else {
213 0         0 carp "humidity must be an integer 0-100 (percent).";
214             }
215             }
216 1         5 return $self->{'humidity'};
217             }
218              
219             #==============================================================================
220              
221             =item sub air_temperature([$newValue])
222              
223             $value = $atmos_ctl->air_temperature($newValue);
224              
225             Global Air Temperature.
226              
227             This attribute specifies the global air temperature of the environment.
228              
229             =cut
230              
231             sub air_temperature() {
232 1     1 1 19 my ($self,$nv) = @_;
233 1 50       4 if (defined($nv)) {
234 1         3 $self->{'airTemperature'} = $nv;
235             }
236 1         3 return $self->{'airTemperature'};
237             }
238              
239             #==============================================================================
240              
241             =item sub visibility_range([$newValue])
242              
243             $value = $atmos_ctl->visibility_range($newValue);
244              
245             Global Visibility Range.
246              
247             This attribute specifies the global visibility range through the atmosphere
248             measured in meters.
249              
250             =cut
251              
252             sub visibility_range() {
253 1     1 1 6 my ($self,$nv) = @_;
254 1 50       6 if (defined($nv)) {
255 1         2 $self->{'visibilityRange'} = $nv;
256             }
257 1         3 return $self->{'visibilityRange'};
258             }
259              
260             #==============================================================================
261              
262             =item sub horizontal_wind_speed([$newValue])
263              
264             $value = $atmos_ctl->horizontal_wind_speed($newValue);
265              
266             Global Horizontal Wind Speed.
267              
268             This attribute specifies the global wind speed, measured in meters/second,
269             parallel to the ellipsoid-tangential reference plane.
270              
271             =cut
272              
273             sub horizontal_wind_speed() {
274 1     1 1 6 my ($self,$nv) = @_;
275 1 50       5 if (defined($nv)) {
276 1         4 $self->{'horizontalWindSpeed'} = $nv;
277             }
278 1         2 return $self->{'horizontalWindSpeed'};
279             }
280              
281             #==============================================================================
282              
283             =item sub vertical_wind_speed([$newValue])
284              
285             $value = $atmos_ctl->vertical_wind_speed($newValue);
286              
287             Global Vertical Wind Speed.
288              
289             This attribute specifies the global vertical wind speed measured in
290             meters/second. A positive value produces an updraft, while a negative value
291             produces a downdraft.
292              
293             =cut
294              
295             sub vertical_wind_speed() {
296 1     1 1 5 my ($self,$nv) = @_;
297 1 50       4 if (defined($nv)) {
298 1         2 $self->{'verticalWindSpeed'} = $nv;
299             }
300 1         2 return $self->{'verticalWindSpeed'};
301             }
302              
303             #==============================================================================
304              
305             =item sub wind_direction([$newValue])
306              
307             $value = $atmos_ctl->wind_direction($newValue);
308              
309             Global Wind Direction.
310              
311             This attribute specifies the global wind direction.
312              
313             Note: This is the direction from which the wind is blowing.
314              
315             =cut
316              
317             sub wind_direction() {
318 1     1 1 5 my ($self,$nv) = @_;
319 1 50       4 if (defined($nv)) {
320 1         2 $self->{'windDirection'} = $nv;
321             }
322 1         3 return $self->{'windDirection'};
323             }
324              
325             #==============================================================================
326              
327             =item sub barometric_pressure([$newValue])
328              
329             $value = $atmos_ctl->barometric_pressure($newValue);
330              
331             Global Barometric Pressure.
332              
333             This attribute specifies the global atmospheric pressure measured in millibars
334             (mb) or hectopascals (hPa). The units are interchangeable.
335              
336             =cut
337              
338             sub barometric_pressure() {
339 1     1 1 6 my ($self,$nv) = @_;
340 1 50       13 if (defined($nv)) {
341 1         2 $self->{'barometricPressure'} = $nv;
342             }
343 1         2 return $self->{'barometricPressure'};
344             }
345              
346             #==========================================================================
347              
348             =item sub pack()
349              
350             $value = $atmos_ctl->pack();
351              
352             Returns the packed data packet.
353              
354             =cut
355              
356             sub pack($) {
357 1     1 1 6 my $self = shift ;
358            
359 1         9 $self->{'_Buffer'} = CORE::pack($self->{'_Pack'},
360             $self->{'packetType'},
361             $self->{'packetSize'},
362             $self->{'_bitfields1'}, # Includes bitfields unused15, and atmosphericModelEnable.
363             $self->{'humidity'},
364             $self->{'airTemperature'},
365             $self->{'visibilityRange'},
366             $self->{'horizontalWindSpeed'},
367             $self->{'verticalWindSpeed'},
368             $self->{'windDirection'},
369             $self->{'barometricPressure'},
370             $self->{'_unused16'},
371             );
372              
373 1         3 return $self->{'_Buffer'};
374             }
375              
376             #==========================================================================
377              
378             =item sub unpack([$buffer])
379              
380             $value = $atmos_ctl->unpack($buffer);
381              
382             Unpacks the packed data packet.
383              
384             =cut
385              
386             sub unpack($) {
387 0     0 1   my $self = shift @_;
388            
389 0 0         if (@_) {
390 0           $self->{'_Buffer'} = shift @_;
391             }
392 0           my ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k) = CORE::unpack($self->{'_Pack'},$self->{'_Buffer'});
393 0           $self->{'packetType'} = $a;
394 0           $self->{'packetSize'} = $b;
395 0           $self->{'_bitfields1'} = $c; # Includes bitfields unused15, and atmosphericModelEnable.
396 0           $self->{'humidity'} = $d;
397 0           $self->{'airTemperature'} = $e;
398 0           $self->{'visibilityRange'} = $f;
399 0           $self->{'horizontalWindSpeed'} = $g;
400 0           $self->{'verticalWindSpeed'} = $h;
401 0           $self->{'windDirection'} = $i;
402 0           $self->{'barometricPressure'} = $j;
403 0           $self->{'_unused16'} = $k;
404 0           $self->{'atmosphericModelEnable'} = $self->atmospheric_model_enable();
405              
406 0           return $self->{'_Buffer'};
407             }
408              
409             #==========================================================================
410              
411             =item sub byte_swap()
412              
413             $value = $atmos_ctl->byte_swap();
414              
415             Byte swaps the packed data packet.
416              
417             =cut
418              
419             sub byte_swap($) {
420 0     0 1   my $self = shift @_;
421            
422 0 0         if (@_) {
423 0           $self->{'_Buffer'} = shift @_;
424             } else {
425 0           $self->pack();
426             }
427 0           my ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k) = CORE::unpack($self->{'_Swap1'},$self->{'_Buffer'});
428              
429 0           $self->{'_Buffer'} = CORE::pack($self->{'_Swap2'},$a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k);
430 0           $self->unpack();
431              
432 0           return $self->{'_Buffer'};
433             }
434              
435             #==========================================================================
436              
437             1;
438             __END__