wmail: use automake.
[dockapps.git] / wmspaceweather / wmSpaceWeather / GetKp
blob6e03dc340477d8e4630a30928b0ca5347b100543
1 #!/usr/bin/perl
4 # A really crappy code to grab last 8 Kp values....
8 require "ctime.pl";
11 ($Year, $Month, $Day) = &year_month_day();
13 if (-e "/tmp/DGD.txt"){
14 unlink("/tmp/DGD.txt");
17 if (-e "/tmp/curind.txt"){
18 unlink("/tmp/curind.txt");
22 $grabcmd = "cd /tmp; wget --passive-ftp --tries 2 -q ftp://www.sec.noaa.gov/pub/indices/DGD.txt";
23 system "$grabcmd";
27 # ensure that there are at least 8 values available...
29 %Kp = ();
30 $Kp{190001011} = 999;
31 $Kp{190001012} = 999;
32 $Kp{190001013} = 999;
33 $Kp{190001014} = 999;
34 $Kp{190001015} = 999;
35 $Kp{190001016} = 999;
36 $Kp{190001017} = 999;
37 $Kp{190001018} = 999;
40 open(TmpFile, "/tmp/DGD.txt");
41 while (<TmpFile>){
42 chop;
43 if ($_ =~ /^\d{4} \d{2} \d{2}\s*\d*/ ){
45 $Date = $_;
47 s/^(\d{4}) (\d{2}) (\d{2}).*\s{2,}(.*)/\4/;
48 s/([ -]{0,1}\d{1,2})([ -]{0,1}\d{1,2})([ -]{0,1}\d{1,2})([ -]{0,1}\d{1,2})([ -]{0,1}\d{1,2})([ -]{0,1}\d{1,2})([ -]{0,1}\d{1,2})([ -]{0,1}\d{1,2})/\1 \2 \3 \4 \5 \6 \7 \8/;
50 $Date =~ s/^(\d{4}) (\d{2}) (\d{2}).*\s{2,}(.*)/\1\2\3/;
51 ($a, $b, $c, $d, $e, $f, $g, $h) = split(/\s{1,}/, $_);
53 $TimeTag = $Date*10 + 1; $Kp{$TimeTag} = $a;
54 $TimeTag = $Date*10 + 2; $Kp{$TimeTag} = $b;
55 $TimeTag = $Date*10 + 3; $Kp{$TimeTag} = $c;
56 $TimeTag = $Date*10 + 4; $Kp{$TimeTag} = $d;
57 $TimeTag = $Date*10 + 5; $Kp{$TimeTag} = $e;
58 $TimeTag = $Date*10 + 6; $Kp{$TimeTag} = $f;
59 $TimeTag = $Date*10 + 7; $Kp{$TimeTag} = $g;
60 $TimeTag = $Date*10 + 8; $Kp{$TimeTag} = $h;
64 close(TmpFile);
69 # Add in very latest stuff
71 $grabcmd = "cd /tmp; wget --passive-ftp --tries 2 -q ftp://www.sec.noaa.gov/pub/latest/curind.txt";
72 system "$grabcmd";
73 %lmonstr = ( "Jan", 1, "Feb", 2, "Mar", 3, "Apr", 4, "May", 5, "Jun", 6, "Jul", 7, "Aug", 8, "Sep", 9, "Oct", 10, "Nov", 11, "Dec", 12);
75 @lval = ($lyear, $lmonstr{$lmon}, $ldom);
76 open(TmpFile, "/tmp/curind.txt");
77 while (<TmpFile>){
78 chop;
79 if ($_ =~ /^:Geomagnetic_Values: (\d{4}) (.*) (\d{1,2})/){
80 $y = $_;
81 $ms = $_;
82 $d = $_;
84 $y =~ s/^:Geomagnetic_Values: (\d{4}) (.*) (\d{1,2})/\1/;
85 $ms =~ s/^:Geomagnetic_Values: (\d{4}) (.*) (\d{1,2})/\2/;
86 $d =~ s/^:Geomagnetic_Values: (\d{4}) (.*) (\d{1,2})/\3/;
87 $tDate = $y*10000 + $lmonstr{$ms}*100 + $d;
89 if ($_ =~ /.*\d/) {
90 $Line = $_;
93 if ($_ =~ /^\s{1,}[0-9e\.\+\-]{2,}\s{1,}[0-9e\.\+\-]{2,}\s{1,}[0-9e\.\+\-]{2,}\s{1,}[0-9e\.\+\-]{2,}\s{1,}[0-9e\.\+\-]{2,}\s{1,}[BCMX]{1,}[0-9\.]{1,}\s{1,}[0-9-]{1,}/){
95 $FluxLine = $_;
103 $Line =~ s/.*\s{3,}(.*)/\1/;
104 ($a, $b, $c, $d, $e, $f, $g, $h) = split(/\s{1,}/, $Line);
105 if ($tDate > 0) {
106 $TimeTag = $tDate*10 + 1; $Kp{$TimeTag} = $a;
107 $TimeTag = $tDate*10 + 2; $Kp{$TimeTag} = $b;
108 $TimeTag = $tDate*10 + 3; $Kp{$TimeTag} = $c;
109 $TimeTag = $tDate*10 + 4; $Kp{$TimeTag} = $d;
110 $TimeTag = $tDate*10 + 5; $Kp{$TimeTag} = $e;
111 $TimeTag = $tDate*10 + 6; $Kp{$TimeTag} = $f;
112 $TimeTag = $tDate*10 + 7; $Kp{$TimeTag} = $g;
113 $TimeTag = $tDate*10 + 8; $Kp{$TimeTag} = $h;
114 } else {
115 $Kp{190001011} = 999;
116 $Kp{190001012} = 999;
117 $Kp{190001013} = 999;
118 $Kp{190001014} = 999;
119 $Kp{190001015} = 999;
120 $Kp{190001016} = 999;
121 $Kp{190001017} = 999;
122 $Kp{190001018} = 999;
127 $n = 0;
128 %Result = ();
129 foreach $key (reverse sort keys %Kp ) {
130 if (($Kp{$key} >= 0)&&($n < 8)){
131 $Result{$key} = $Kp{$key};
132 ++$n;
136 open(TmpFile, ">/tmp/LatestKp.txt");
137 foreach $key (sort keys %Result ) {
138 if ($Result{$key} > 10) { $Result{$key} = -1; }
139 printf TmpFile "$key $Result{$key}\n";
145 $FluxLine =~ s/^\s*//;
146 if ($FluxLine =~ /\d/){
147 ($E1, $E2, $P1, $P2, $P3, $Xray, $junk) = split(/\s{1,}/, $FluxLine);
149 } else {
150 $E1 = -999;
151 $E2 = -999;
152 $P1 = -999;
153 $P2 = -999;
154 $P3 = -999;
155 $Xray = "Z0.0";
159 printf TmpFile "$E1\n";
160 printf TmpFile "$E2\n";
161 printf TmpFile "$P1\n";
162 printf TmpFile "$P2\n";
163 printf TmpFile "$P3\n";
164 printf TmpFile "$Xray\n";
165 close(TmpFile);
175 # sort(List);
177 # $Gif = "$List[$#List]";
178 # $Latest = "http://swdcdb.kugi.kyoto-u.ac.jp/dstdir/dst1/q/$Gif";
181 # $grabcmd = "/u/mgh/wwwgrab/wwwgrab $Latest /n/tmp/polar/$Gif";
182 # system "$grabcmd";
185 # system "convert -crop 0x0 /n/tmp/polar/${Gif} /n/tmp/polar/Dst.rle";
186 # system "fant -s .5 .5 -o /n/tmp/polar/Dst2.rle /n/tmp/polar/Dst.rle";
187 # system "convert -frame 4x4 -gamma 3 -crop 0x0 -colors 256 /n/tmp/polar/Dst2.rle /n/leadbelly/belly3/PolarNRT/CEPPAD/IPS/LatestDst.gif";
193 # open(TmpFile, ">/n/leadbelly/belly3/PolarNRT/CEPPAD/IPS/LatestDst.txt");
194 # printf TmpFile "${Gif}\n";
195 # close(TmpFile);
197 # system "touch /n/leadbelly/belly3/PolarNRT/CEPPAD/IPS/LatestDst.txt";
200 sub year_month_day{
202 local($ldate_string, $ldow, $lmon, $ldom, $ltim, $lyear, %lmonstr, $tzone, @lval);
204 $ldate_string = &ctime(time);
205 ($ldow, $lmon, $ldom, $ltim, $lyear) = split(" ", $ldate_string);
207 %lmonstr = ( "Jan", 1, "Feb", 2, "Mar", 3, "Apr", 4, "May", 5, "Jun", 6, "Jul", 7, "Aug", 8, "Sep", 9, "Oct", 10, "Nov", 11, "Dec", 12);
209 @lval = ($lyear, $lmonstr{$lmon}, $ldom);