<commit_before><?php
include("../../../../config/settings.inc.php");

$var = isset($_GET["var"]) ? $_GET["var"] : "gdd50";
$year = isset($_GET["year"]) ? $_GET["year"] : 2006;
$smonth = isset($_GET["smonth"]) ? $_GET["smonth"]:  5;
$emonth = isset($_GET["emonth"]) ? $_GET["emonth"]: 10;
$sday = isset($_GET["sday"]) ? $_GET["sday"]: 1;
$eday = isset($_GET["eday"]) ? $_GET["eday"]: 1;

$gs_start = mktime(0,0,0,$smonth,$sday,$year);
$gs_end = mktime(0,0,0,$emonth,$eday,$year);

$round = Array("prec" => 2, "gdd50" => 0, "gdd32" => 0, "et" => 2, "sgdd50" => 0, "sdd86" => 0, "srad" => 0);

$today = time();
if ($gs_end >= $today)  $gs_end = $today;

$emonth = strftime("%m", $gs_end);
$eday = strftime("%d", $gs_end);
$smonth = strftime("%m", $gs_start);
$sday = strftime("%d", $gs_start);

include("$rootpath/include/forms.php");

?>

<?php 
        $page = "isuag";
	$TITLE = "IEM | ISUAG Growing Season Data";
	$HEADEXTRA = '<script language="JavaScript" type="text/javascript">
<!--//BEGIN Script
function new_window(url) {
        link = 
       
window.open(url,"_new","toolbar=0,location=0,directories=0,status=0,menubar=no,scrollbars=yes,resizable=yes,width=450,height=400");
} 
//END Script-->
</script>';
        include("$rootpath/include/header.php"); 
?>


<h3 class="heading">Growing Season Charts</h3><p>

<form method="GET" action="gsplot.phtml">
<table> <tr>
   <th class="subtitle">Plot Parameter</th>
   <th class="subtitle">Year</th>
   <th class="subtitle">Month</th>
   <th class="subtitle">Day</th>
   <td></td>
  </tr>
 <tr>
  <td rowspan=2><select name="var">
     <option value="gdd50" <?php if($var == "gdd50") echo "SELECTED"; ?>>Growing Degree Days (base=50,cap=86)</option>
     <option value="gdd32" <?php if($var == "gdd32") echo "SELECTED"; ?>>Growing Degree Days (base=32,cap=86)</option>
     <option value="et" <?php if($var == "et") echo "SELECTED"; ?>>Potential Evapotranspiration</option>
     <option value="prec" <?php if($var == "prec") echo "SELECTED"; ?>>Precipitation</option>
     <option value="sgdd50" <?php if($var == "sgdd50") echo "SELECTED"; ?>>Soil Growing Degree Days (base=50)</option>
     <option value="srad" <?php if($var == "srad") echo "SELECTED"; ?>>Solar Radiation (langleys)</option>
     <option value="sdd86" <?php if($var == "sdd86") echo "SELECTED"; ?>>Stress Degree Days (base=86)</option>
    </select></td>
  <td rowspan=2><?php echo yearSelect(1988, $year, "year"); ?></td>
  <td><?php monthSelect2($smonth, 'smonth'); ?></td>
  <td><?php daySelect2($sday, 'sday'); ?></td>
  <td rowspan=2><input type="submit" value="Make Plot"></td>
  </tr>
 <tr>
  <td><?php monthSelect2($emonth, 'emonth'); ?></td>
  <td><?php daySelect2($eday, 'eday'); ?></td>
  </tr>
</table>
 

<?php
dl($mapscript);
include("$rootpath/include/agclimateLoc.php");

function mktitlelocal($map, $imgObj, $titlet) { 
 
  $layer = $map->getLayerByName("credits");
 
     // point feature with text for location
  $point = ms_newpointobj();
  $point->setXY( 0, 10);
  $point->draw($map, $layer, $imgObj, 0,
    $titlet ."                                                           ");
  $point->free();

     // point feature with text for location
  $point = ms_newpointobj();
  $point->setXY( 0, 330);
  $point->draw($map, $layer, $imgObj, 1,
    "  Iowa Environmental Mesonet | Iowa State Ag Climate Network ");
  $point->free();
}

function plotNoData($map, $img){
  $layer = $map->getLayerByName("credits");

  $point = ms_newpointobj();
  $point->setXY( 100, 200);
  $point->draw($map, $layer, $img, 1,
    "  No data found for this date! ");
  $point->free();

}

$varDef = Array("gdd50" => "Growing Degree Days (base=50)",
  "gdd32" => "Growing Degree Days (base=32)",
  "et" => "Potential Evapotranspiration",
  "prec" => "Precipitation",
  "srad" => "Solar Radiation (langleys)",
  "sgdd50" => "Soil Growing Degree Days (base=50)",
  "sdd86" => "Stress Degree Days (base=86)"
);



$rnd = Array("gdd50" => 0,
  "gdd32" => 0,
  "et" => 2, "c11" => 2,
  "prec" => 2,
  "srad" => 0,
  "sgdd50" => 0,
  "sdd86" => 0);


$myStations = $ISUAGcities;
$height = 350;
$width = 450;

$proj = "proj=tmerc,lat_0=41.5,lon_0=-93.65,x_0=0,y_0=0,k=0.9999";

$map = ms_newMapObj("base.map");
$map->setProjection($proj);

$map->setextent(-252561, -133255, 300625, 277631);


$counties = $map->getlayerbyname("counties");
$counties->set("status", MS_ON);

$snet = $map->getlayerbyname("snet");
$snet->set("status", MS_ON);
$sclass = $snet->getClass(0);

$iards = $map->getlayerbyname("iards");
$iards->set("status", 1);


$ponly = $map->getlayerbyname("pointonly");
$ponly->set("status", MS_ON);

$img = $map->prepareImage();
$counties->draw($img);
$iards->draw($img);

include("$rootpath/include/database.inc.php");
$c = iemdb("isuag");

$sstr = strftime("%Y-%m-%d", $gs_start);
$estr = strftime("%Y-%m-%d", $gs_end);
$sstr_txt = strftime("%b %d", $gs_start);
$estr_txt = strftime("%b %d", $gs_end);

/* ------------------------------------------------------- */
if ($var == 'gdd32') {
  $q = "SELECT station, c11, c12
     from t${year}_daily WHERE valid >= '". $sstr ."'
     and valid < '". $estr ."'";

  $gdds = Array();
  $rs =  pg_exec($c, $q);
  for ($i=0; $row = @pg_fetch_array($rs,$i); $i++) {
    $stid = $row['station'];
    $high = (float)$row['c11'];
    $low  = (float)$row['c12'];

    if ($low < 32)  $low = 32.00;
    if ($high > 86) $high = 86.00;
    if ($high < 32) $tgdd = 0.00;
    else $tgdd = (($high+$low)/2.00) - 32.00;

    if (! isset($gdds[$stid]) ) $gdds[$stid] = 0;
    $gdds[$stid] = $gdds[$stid] + $tgdd;
  }
  $vals = $gdds;
} 
/* ------------------------------------------------------- */
if ($var == 'gdd50') {
  $q = "SELECT station, c11, c12
     from t${year}_daily WHERE valid >= '". $sstr ."'
     and valid < '". $estr ."'";

  $gdds = Array();
  $rs =  pg_exec($c, $q);
  for ($i=0; $row = @pg_fetch_array($rs,$i); $i++) {
    $stid = $row['station'];
    $high = (float)$row['c11'];
    $low  = (float)$row['c12'];

    if ($low < 50)  $low = 50.00;
    if ($high > 86) $high = 86.00;
    if ($high < 50) $tgdd = 0.00;
    else $tgdd = (($high+$low)/2.00) - 50.00;
    if (! isset($gdds[$stid]) ) $gdds[$stid] = 0;
    $gdds[$stid] = $gdds[$stid] + $tgdd;
  }
  $vals = $gdds;
}  
/* ------------------------------------------------------- */
if ($var == 'sdd86') {
  $q = "SELECT station, c11, c12
     from t${year}_daily WHERE valid >= '". $sstr ."'
     and valid < '". $estr ."'";

  $gdds = Array();
  $rs =  pg_exec($c, $q);
  for ($i=0; $row = @pg_fetch_array($rs,$i); $i++) {
    $stid = $row['station'];
    $high = (float)$row['c11'];
    $low  = (float)$row['c12'];

    if ($low < 86)  $low = 86.00;
    if ($high < 86) $tgdd = 0.00;
    else $tgdd = (($high+$low)/2.00) - 86.00;

    if (! isset($gdds[$stid]) ) $gdds[$stid] = 0;
    $gdds[$stid] = $gdds[$stid] + $tgdd;
  }
  $vals = $gdds;
}  
/* ------------------------------------------------------- */
else if ($var == 'sgdd50') {
  $q = "SELECT station, date(valid) as dvalid, 
     max(c300) as high, min(c300) as low
     from t${year}_hourly WHERE valid >= '". $sstr ."'
     and valid < '". $estr ."' GROUP by station, dvalid";

  $gdds = Array();
  $rs =  pg_exec($c, $q);
  for ($i=0; $row = @pg_fetch_array($rs,$i); $i++) {
    $stid = $row['station'];
    $high = (float)$row['high'];
    $low  = (float)$row['low'];

    if ($low < 50)  $low = 50.00;
    if ($high > 86) $high = 86.00;
    if ($high < 50) $tgdd = 0.00;
    else $tgdd = (($high+$low)/2.00) - 50.00;

    if (! isset($gdds[$stid]) ) $gdds[$stid] = 0;
    $gdds[$stid] = $gdds[$stid] + $tgdd;
  }
  $vals = $gdds;
}  
/* ------------------------------------------------------- */
else if ($var == 'et') {
  $q = "SELECT station, sum(c70) as et
     from t${year}_daily WHERE valid >= '". $sstr ."'
     and valid < '". $estr ."' GROUP by station";

  $vals = Array();
  $rs =  pg_exec($c, $q);
  for ($i=0; $row = @pg_fetch_array($rs,$i); $i++) {
    $stid = $row['station'];
    $vals[$stid] = $row['et'];
  }
}
/* ------------------------------------------------------- */
else if ($var == 'srad') {
  $q = "SELECT station, sum(c80) as srad
     from t${year}_daily WHERE valid >= '". $sstr ."'
     and valid < '". $estr ."' GROUP by station";

  $vals = Array();
  $rs =  pg_exec($c, $q);
  for ($i=0; $row = @pg_fetch_array($rs,$i); $i++) {
    $stid = $row['station'];
    $vals[$stid] = $row['srad'];
  }
}
/* ------------------------------------------------------- */
else if ($var == 'prec') {
  $q = "SELECT station, sum(c90) as prec
     from t${year}_daily WHERE valid >= '". $sstr ."'
     and valid < '". $estr ."' GROUP by station";

  $vals = Array();
  $rs =  pg_exec($c, $q);
  for ($i=0; $row = @pg_fetch_array($rs,$i); $i++) {
    $stid = $row['station'];
    $vals[$stid] = $row['prec'];
  }
}  
/* ------------------------------------------------------- */


$tr = "# ".$year." ". $varDef[$var] ." (". $sstr_txt ." - ". $estr_txt .")\n";
$tr .= "#-----------------------snip------------------\n";
$tr .= sprintf("%20s,%10s,%10s,%10s\n", 'StationName', 'Latitude', 'Longitude', $var);
foreach($vals as $key => $value){
  if ($key == "A133259" || $key == "A130219") continue;

  $tr .= sprintf("%20s,%10s,%10s,%10s\n", $ISUAGcities[$key]['city'],
  $ISUAGcities[$key]['lat'], $ISUAGcities[$key]['lon'], round($value, $round[$var]) );

  // Red Dot... 
  $pt = ms_newPointObj();
  $pt->setXY($ISUAGcities[$key]['lon'], $ISUAGcities[$key]['lat'], 0);
  $pt->draw($map, $ponly, $img, 0, ' ' );
  $pt->free();

  // Value UL
  $pt = ms_newPointObj();
  $pt->setXY($ISUAGcities[$key]['lon'], $ISUAGcities[$key]['lat'], 0);
  $pt->draw($map, $snet, $img, 0, 
     round($value, $rnd[$var]) );
  $pt->free();

  if (isset($_GET["var2"])) {
    // Value LL
    $pt = ms_newPointObj();
    $pt->setXY($ISUAGcities[$key]['lon'], $ISUAGcities[$key]['lat'], 0);
    if ($var2 == 'c530'){
      $pt->draw($map, $snet, $img, 2, 
        $row[$var2] ." ". $row[$var2 .'_f'] );
    } else {
      $pt->draw($map, $snet, $img, 2, 
        round($row[$var2], $rnd[$var2]) ." ". $row[$var2 .'_f'] );
    }
    $pt->free();
  }

  // City Name
  $pt = ms_newPointObj();
  $pt->setXY($ISUAGcities[$key]['lon'], $ISUAGcities[$key]['lat'], 0);
  $pt->draw($map, $snet, $img, 1, $ISUAGcities[$key]['city'] );
  $pt->free();
}
if ($i == 0)
   plotNoData($map, $img);

mktitlelocal($map, $img, " ".$year." ". $varDef[$var] ." (". $sstr_txt ." - ". $estr_txt .") ");
$map->drawLabelCache($img);

$url = $img->saveWebImage();

?>
<center><font class="bluet">Plot</font></center>
<table>
<tr><td valign="top">
<h3 class="heading">Dynamic Historical Data:</h3>
<a href="dayplot.phtml">Daily Data Plots</a>
<br /><b>Growing Season Plots</b>

<p>Open this plot in a <a href="javascript:new_window('image.phtml?f=<?php echo $url; ?>');">new window</a> for comparison with other plots. Once the
image is loaded up in another window, you can modify this plots 
parameters.

<p><b>*Note:</b> Precipitation recorded from this network is not reliable.
 You should precipitation obs from the <a href="<?php echo $rooturl; ?>/COOP/">COOP</a> network.
</td>
  <td>
  <img src="<?php echo $url; ?>" border=1>
</td></tr>
</table>

<p>
<center><img src="/images/gisready.png"><h3 class="subtitle"> Data Listing</h3></center>
<pre><?php echo $tr; ?></pre>

<p>You should be able to 'copy & paste' this raw data listing into a simple
text editor and save the data file on your machine.  Most GIS systems can 
then import this dataset as a layer.  You may have to omit the commented lines
(#) if your GIS has trouble importing the data.

<?php 
  include("$rootpath/include/footer.php");
?>
<commit_msg>1986<commit_after><?php
include("../../../../config/settings.inc.php");

$var = isset($_GET["var"]) ? $_GET["var"] : "gdd50";
$year = isset($_GET["year"]) ? $_GET["year"] : 2006;
$smonth = isset($_GET["smonth"]) ? $_GET["smonth"]:  5;
$emonth = isset($_GET["emonth"]) ? $_GET["emonth"]: 10;
$sday = isset($_GET["sday"]) ? $_GET["sday"]: 1;
$eday = isset($_GET["eday"]) ? $_GET["eday"]: 1;

$gs_start = mktime(0,0,0,$smonth,$sday,$year);
$gs_end = mktime(0,0,0,$emonth,$eday,$year);

$round = Array("prec" => 2, "gdd50" => 0, "gdd32" => 0, "et" => 2, "sgdd50" => 0, "sdd86" => 0, "srad" => 0);

$today = time();
if ($gs_end >= $today)  $gs_end = $today;

$emonth = strftime("%m", $gs_end);
$eday = strftime("%d", $gs_end);
$smonth = strftime("%m", $gs_start);
$sday = strftime("%d", $gs_start);

include("$rootpath/include/forms.php");

?>

<?php 
        $page = "isuag";
	$TITLE = "IEM | ISUAG Growing Season Data";
	$HEADEXTRA = '<script language="JavaScript" type="text/javascript">
<!--//BEGIN Script
function new_window(url) {
        link = 
       
window.open(url,"_new","toolbar=0,location=0,directories=0,status=0,menubar=no,scrollbars=yes,resizable=yes,width=450,height=400");
} 
//END Script-->
</script>';
        include("$rootpath/include/header.php"); 
?>


<h3 class="heading">Growing Season Charts</h3><p>

<form method="GET" action="gsplot.phtml">
<table> <tr>
   <th class="subtitle">Plot Parameter</th>
   <th class="subtitle">Year</th>
   <th class="subtitle">Month</th>
   <th class="subtitle">Day</th>
   <td></td>
  </tr>
 <tr>
  <td rowspan=2><select name="var">
     <option value="gdd50" <?php if($var == "gdd50") echo "SELECTED"; ?>>Growing Degree Days (base=50,cap=86)</option>
     <option value="gdd32" <?php if($var == "gdd32") echo "SELECTED"; ?>>Growing Degree Days (base=32,cap=86)</option>
     <option value="et" <?php if($var == "et") echo "SELECTED"; ?>>Potential Evapotranspiration</option>
     <option value="prec" <?php if($var == "prec") echo "SELECTED"; ?>>Precipitation</option>
     <option value="sgdd50" <?php if($var == "sgdd50") echo "SELECTED"; ?>>Soil Growing Degree Days (base=50)</option>
     <option value="srad" <?php if($var == "srad") echo "SELECTED"; ?>>Solar Radiation (langleys)</option>
     <option value="sdd86" <?php if($var == "sdd86") echo "SELECTED"; ?>>Stress Degree Days (base=86)</option>
    </select></td>
  <td rowspan=2><?php echo yearSelect(1986, $year, "year"); ?></td>
  <td><?php monthSelect2($smonth, 'smonth'); ?></td>
  <td><?php daySelect2($sday, 'sday'); ?></td>
  <td rowspan=2><input type="submit" value="Make Plot"></td>
  </tr>
 <tr>
  <td><?php monthSelect2($emonth, 'emonth'); ?></td>
  <td><?php daySelect2($eday, 'eday'); ?></td>
  </tr>
</table>
 

<?php
dl($mapscript);
include("$rootpath/include/agclimateLoc.php");

function mktitlelocal($map, $imgObj, $titlet) { 
 
  $layer = $map->getLayerByName("credits");
 
     // point feature with text for location
  $point = ms_newpointobj();
  $point->setXY( 0, 10);
  $point->draw($map, $layer, $imgObj, 0,
    $titlet ."                                                           ");
  $point->free();

     // point feature with text for location
  $point = ms_newpointobj();
  $point->setXY( 0, 330);
  $point->draw($map, $layer, $imgObj, 1,
    "  Iowa Environmental Mesonet | Iowa State Ag Climate Network ");
  $point->free();
}

function plotNoData($map, $img){
  $layer = $map->getLayerByName("credits");

  $point = ms_newpointobj();
  $point->setXY( 100, 200);
  $point->draw($map, $layer, $img, 1,
    "  No data found for this date! ");
  $point->free();

}

$varDef = Array("gdd50" => "Growing Degree Days (base=50)",
  "gdd32" => "Growing Degree Days (base=32)",
  "et" => "Potential Evapotranspiration",
  "prec" => "Precipitation",
  "srad" => "Solar Radiation (langleys)",
  "sgdd50" => "Soil Growing Degree Days (base=50)",
  "sdd86" => "Stress Degree Days (base=86)"
);



$rnd = Array("gdd50" => 0,
  "gdd32" => 0,
  "et" => 2, "c11" => 2,
  "prec" => 2,
  "srad" => 0,
  "sgdd50" => 0,
  "sdd86" => 0);


$myStations = $ISUAGcities;
$height = 350;
$width = 450;

$proj = "proj=tmerc,lat_0=41.5,lon_0=-93.65,x_0=0,y_0=0,k=0.9999";

$map = ms_newMapObj("base.map");
$map->setProjection($proj);

$map->setextent(-252561, -133255, 300625, 277631);


$counties = $map->getlayerbyname("counties");
$counties->set("status", MS_ON);

$snet = $map->getlayerbyname("snet");
$snet->set("status", MS_ON);
$sclass = $snet->getClass(0);

$iards = $map->getlayerbyname("iards");
$iards->set("status", 1);


$ponly = $map->getlayerbyname("pointonly");
$ponly->set("status", MS_ON);

$img = $map->prepareImage();
$counties->draw($img);
$iards->draw($img);

include("$rootpath/include/database.inc.php");
$c = iemdb("isuag");

$sstr = strftime("%Y-%m-%d", $gs_start);
$estr = strftime("%Y-%m-%d", $gs_end);
$sstr_txt = strftime("%b %d", $gs_start);
$estr_txt = strftime("%b %d", $gs_end);

/* ------------------------------------------------------- */
if ($var == 'gdd32') {
  $q = "SELECT station, c11, c12
     from t${year}_daily WHERE valid >= '". $sstr ."'
     and valid < '". $estr ."'";

  $gdds = Array();
  $rs =  pg_exec($c, $q);
  for ($i=0; $row = @pg_fetch_array($rs,$i); $i++) {
    $stid = $row['station'];
    $high = (float)$row['c11'];
    $low  = (float)$row['c12'];

    if ($low < 32)  $low = 32.00;
    if ($high > 86) $high = 86.00;
    if ($high < 32) $tgdd = 0.00;
    else $tgdd = (($high+$low)/2.00) - 32.00;

    if (! isset($gdds[$stid]) ) $gdds[$stid] = 0;
    $gdds[$stid] = $gdds[$stid] + $tgdd;
  }
  $vals = $gdds;
} 
/* ------------------------------------------------------- */
if ($var == 'gdd50') {
  $q = "SELECT station, c11, c12
     from t${year}_daily WHERE valid >= '". $sstr ."'
     and valid < '". $estr ."'";

  $gdds = Array();
  $rs =  pg_exec($c, $q);
  for ($i=0; $row = @pg_fetch_array($rs,$i); $i++) {
    $stid = $row['station'];
    $high = (float)$row['c11'];
    $low  = (float)$row['c12'];

    if ($low < 50)  $low = 50.00;
    if ($high > 86) $high = 86.00;
    if ($high < 50) $tgdd = 0.00;
    else $tgdd = (($high+$low)/2.00) - 50.00;
    if (! isset($gdds[$stid]) ) $gdds[$stid] = 0;
    $gdds[$stid] = $gdds[$stid] + $tgdd;
  }
  $vals = $gdds;
}  
/* ------------------------------------------------------- */
if ($var == 'sdd86') {
  $q = "SELECT station, c11, c12
     from t${year}_daily WHERE valid >= '". $sstr ."'
     and valid < '". $estr ."'";

  $gdds = Array();
  $rs =  pg_exec($c, $q);
  for ($i=0; $row = @pg_fetch_array($rs,$i); $i++) {
    $stid = $row['station'];
    $high = (float)$row['c11'];
    $low  = (float)$row['c12'];

    if ($low < 86)  $low = 86.00;
    if ($high < 86) $tgdd = 0.00;
    else $tgdd = (($high+$low)/2.00) - 86.00;

    if (! isset($gdds[$stid]) ) $gdds[$stid] = 0;
    $gdds[$stid] = $gdds[$stid] + $tgdd;
  }
  $vals = $gdds;
}  
/* ------------------------------------------------------- */
else if ($var == 'sgdd50') {
  $q = "SELECT station, date(valid) as dvalid, 
     max(c300) as high, min(c300) as low
     from t${year}_hourly WHERE valid >= '". $sstr ."'
     and valid < '". $estr ."' GROUP by station, dvalid";

  $gdds = Array();
  $rs =  pg_exec($c, $q);
  for ($i=0; $row = @pg_fetch_array($rs,$i); $i++) {
    $stid = $row['station'];
    $high = (float)$row['high'];
    $low  = (float)$row['low'];

    if ($low < 50)  $low = 50.00;
    if ($high > 86) $high = 86.00;
    if ($high < 50) $tgdd = 0.00;
    else $tgdd = (($high+$low)/2.00) - 50.00;

    if (! isset($gdds[$stid]) ) $gdds[$stid] = 0;
    $gdds[$stid] = $gdds[$stid] + $tgdd;
  }
  $vals = $gdds;
}  
/* ------------------------------------------------------- */
else if ($var == 'et') {
  $q = "SELECT station, sum(c70) as et
     from t${year}_daily WHERE valid >= '". $sstr ."'
     and valid < '". $estr ."' GROUP by station";

  $vals = Array();
  $rs =  pg_exec($c, $q);
  for ($i=0; $row = @pg_fetch_array($rs,$i); $i++) {
    $stid = $row['station'];
    $vals[$stid] = $row['et'];
  }
}
/* ------------------------------------------------------- */
else if ($var == 'srad') {
  $q = "SELECT station, sum(c80) as srad
     from t${year}_daily WHERE valid >= '". $sstr ."'
     and valid < '". $estr ."' GROUP by station";

  $vals = Array();
  $rs =  pg_exec($c, $q);
  for ($i=0; $row = @pg_fetch_array($rs,$i); $i++) {
    $stid = $row['station'];
    $vals[$stid] = $row['srad'];
  }
}
/* ------------------------------------------------------- */
else if ($var == 'prec') {
  $q = "SELECT station, sum(c90) as prec
     from t${year}_daily WHERE valid >= '". $sstr ."'
     and valid < '". $estr ."' GROUP by station";

  $vals = Array();
  $rs =  pg_exec($c, $q);
  for ($i=0; $row = @pg_fetch_array($rs,$i); $i++) {
    $stid = $row['station'];
    $vals[$stid] = $row['prec'];
  }
}  
/* ------------------------------------------------------- */


$tr = "# ".$year." ". $varDef[$var] ." (". $sstr_txt ." - ". $estr_txt .")\n";
$tr .= "#-----------------------snip------------------\n";
$tr .= sprintf("%20s,%10s,%10s,%10s\n", 'StationName', 'Latitude', 'Longitude', $var);
foreach($vals as $key => $value){
  if ($key == "A133259" || $key == "A130219") continue;

  $tr .= sprintf("%20s,%10s,%10s,%10s\n", $ISUAGcities[$key]['city'],
  $ISUAGcities[$key]['lat'], $ISUAGcities[$key]['lon'], round($value, $round[$var]) );

  // Red Dot... 
  $pt = ms_newPointObj();
  $pt->setXY($ISUAGcities[$key]['lon'], $ISUAGcities[$key]['lat'], 0);
  $pt->draw($map, $ponly, $img, 0, ' ' );
  $pt->free();

  // Value UL
  $pt = ms_newPointObj();
  $pt->setXY($ISUAGcities[$key]['lon'], $ISUAGcities[$key]['lat'], 0);
  $pt->draw($map, $snet, $img, 0, 
     round($value, $rnd[$var]) );
  $pt->free();

  if (isset($_GET["var2"])) {
    // Value LL
    $pt = ms_newPointObj();
    $pt->setXY($ISUAGcities[$key]['lon'], $ISUAGcities[$key]['lat'], 0);
    if ($var2 == 'c530'){
      $pt->draw($map, $snet, $img, 2, 
        $row[$var2] ." ". $row[$var2 .'_f'] );
    } else {
      $pt->draw($map, $snet, $img, 2, 
        round($row[$var2], $rnd[$var2]) ." ". $row[$var2 .'_f'] );
    }
    $pt->free();
  }

  // City Name
  $pt = ms_newPointObj();
  $pt->setXY($ISUAGcities[$key]['lon'], $ISUAGcities[$key]['lat'], 0);
  $pt->draw($map, $snet, $img, 1, $ISUAGcities[$key]['city'] );
  $pt->free();
}
if ($i == 0)
   plotNoData($map, $img);

mktitlelocal($map, $img, " ".$year." ". $varDef[$var] ." (". $sstr_txt ." - ". $estr_txt .") ");
$map->drawLabelCache($img);

$url = $img->saveWebImage();

?>
<center><font class="bluet">Plot</font></center>
<table>
<tr><td valign="top">
<h3 class="heading">Dynamic Historical Data:</h3>
<a href="dayplot.phtml">Daily Data Plots</a>
<br /><b>Growing Season Plots</b>

<p>Open this plot in a <a href="javascript:new_window('image.phtml?f=<?php echo $url; ?>');">new window</a> for comparison with other plots. Once the
image is loaded up in another window, you can modify this plots 
parameters.

<p><b>*Note:</b> Precipitation recorded from this network is not reliable.
 You should precipitation obs from the <a href="<?php echo $rooturl; ?>/COOP/">COOP</a> network.
</td>
  <td>
  <img src="<?php echo $url; ?>" border=1>
</td></tr>
</table>

<p>
<center><img src="/images/gisready.png"><h3 class="subtitle"> Data Listing</h3></center>
<pre><?php echo $tr; ?></pre>

<p>You should be able to 'copy & paste' this raw data listing into a simple
text editor and save the data file on your machine.  Most GIS systems can 
then import this dataset as a layer.  You may have to omit the commented lines
(#) if your GIS has trouble importing the data.

<?php 
  include("$rootpath/include/footer.php");
?>

{'fraction_non_alphanumeric': 0.2842118763627036, 'fraction_numerical': 0.03274763798041982, 'mean_word_length': 3.053370299774736, 'pattern_counts': {'":': 0, '<': 259, '<?xml version=': 0, '>': 377, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1870397', 'n_tokens_mistral': 9814, 'n_tokens_neox': 9126, 'n_words': 1992}