Attachment 'dlt.pl'
Download 1 #!/usr/local/bin/perl
2 # dlt.pl
3 # produce tables and plots of average density, lapse rate, and temperature
4 # v0.1 Keith Lofstrom 2014 Oct 27
5
6 use strict;
7 use List::Util qw(sum min max);
8
9 my $s = 4 ; # half altitude span
10
11 my @densfile = ( "dens070", "dens120", "dens200" ) ; # density g/cm^3
12 my @tempfile = ( "temp070", "temp120", "temp200" ) ; # temperature K
13 my @f107 = ( 70, 120, 200 ) ; # e-22 W/Hz-m^2
14
15 my @alt ; # single dimensional altitude array
16 my @den ; # density array of arrays
17 my @lap ; # lapse rate array of arrays
18 my @tem ; # temperature array of arrays
19
20 foreach my $i ( 0..$#f107 ) {
21 my @alt1 = () ; # altitude km
22 my @den1 = () ; # density kg/m^3
23 my @tem1 = () ; # temperature K
24
25 # create temperature by averaging over a day
26 open( IN, $tempfile[$i] ) ;
27 while (<IN>) {
28 next if /^#/ ;
29 my @innum = split ;
30 shift @innum ; # first value is altitude
31 push @tem1 , sum( @innum ) / @innum ; # average of temperatures
32 }
33
34 # create density and altitude arrays by averaging over a day
35 open( IN, $densfile[$i] ) ;
36 while (<IN>) {
37 next if /^#/ ;
38 my @innum = split ;
39 push @alt1 , shift @innum ; # first value is altitude
40 push @den1 , sum( @innum ) / @innum ; # average of densities
41 }
42 close( IN );
43
44 if ( $#alt1 != $#den1 ) {
45 die( "density ", $f107[$i]," ", $#alt1," ",$#den1 )
46 }
47
48 if ( $#alt1 != $#tem1 ) {
49 die( "temperature ", $f107[$i]," ", $#alt1," ",$#tem1 )
50 }
51
52 # compute lapse rate array and copy altitude (redundant)
53 foreach my $j ( 0..$#alt1 ) {
54 my $n0 = max( 0, $j-$s );
55 my $n1 = min( $#alt1, $j+$s );
56 $lap[$i][$j] = ($alt1[$n1]-$alt1[$n0])/log($den1[$n0]/$den1[$n1]);
57 $alt[ $j] = $alt1[ $j] ; # probably can do this with a push
58 $tem[$i][$j] = $tem1[ $j] ;
59 $den[$i][$j] = $den1[ $j] * 1000.0 ; # convert from g/cm3 to kg/m3
60 }
61 }
62
63 print "#f107";
64 foreach my $i ( 0..$#f107 ) { printf "|%15.0f ", $f107[ $i ] ; }
65 print "\n# alt";
66 foreach my $i ( 0..$#f107 ) { printf "| density lapse temp "; }
67 print "\n" ;
68
69
70 foreach my $j ( 0..$#alt ) {
71 printf "%4.0f", $alt[$j] ;
72 foreach my $i( 0..$#f107 ) {
73 printf "%11.3e%7.2f%7.1f", $den[$i][$j], $lap[$i][$j], $tem[$i][$j] ;
74 }
75 print "\n" ;
76 }
77
78 exit ;
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.