// aYearAgo_from_Dayfile.js
/* Search for all values for particular date and return observations and calculated values to calling HTML in correct positions
Uses JavaScript and jQuery to process dayfile.txt and select a single record */
function calculateBeaufort(speed,units){
var beaufort, unitChoice=['km/h','mph','kts','m/s'];
var speedArray= [
[1,1,1,0.3,'Calm'],
[6,3,3,1.5,'Light air'],
[12,8,7,3.3,'Light breeze'],
[20,13,11,5.5,'Gentle breeze'],
[29,18,16,8.0,'Moderate breeze'],
[39,25,21,11,'Fresh breeze'],
[50,31,27,14,'Strong breeze'],
[62,39,34,17,'High wind'],
[75,47,41,21,'Gale'],
[89,55,48,25,'Strong gale'],
[103,64,56,29,'Storm'],
[118,73,64,33,'Violent storm']
];
for (var i1=0;units=unitChoice[i1];i1++){
for(i2=0;i2<12;i2++){
if(speed12)revisedHours-=12;
return String(revisedHours)+":"+timeStamp.substr(3,2)+" "+am_pm;
}
// EXTRACTING INFORMATION FROM DAILY SUMMARY FILE
/*Parameters passed from calling HTML:
var metDate=['<#metdateyesterday format="dd">','<#metdateyesterday format="mm">','<#metdateyesterday format="yyyy">',(parseInt("0"+"<#rollovertime>",10)),"<#rollovertime>"];// day of month, month number (1 to 12), year, hour of rollover, rollover string
<#rollovertime> can report 'Midnight', '9am', or '10am', so prefixing it with a zero and using 'parseInt' converts that to 0, 9, or 10
*/
var dailyLogFile='dayfile.txt'; // specifies path from your html to the daily summary log
var field_delimiter = ","; // edit this to ';' if necessary to match the delimiter between fields in your dayfile.txt
var date_delimiter = "/"; // edit this to include your computer default short date format separator
// edit next two arrays for your language
var days=['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday']; // Sunday is always first day of week for JavaScript
var mname = ['January','February','March','April','May','June','July','August','September','October','November','December']; // For script months numbered 0 to 11
htmlIdArray=['','#gust','#gwb','','','#Tlow_temp','','#Thigh_temp','#low_press','#Tlow_press','#high_press','#Thigh_press','#rate','#Trate','#rain','#av_temp','#run','','#Twind','#low_hum','#Tlow_hum','#high_hum','#Thigh_hum','','','#high_hi','#Thigh_hi','#high_app','#Thigh_app','#low_app','#Tlow_app','#hourR','#ThourR','#low_wc','#Tlow_wc','','','','','','#hdd','#cdd']; // id of HTML elements where a single figure or time stamp is to be inserted, those where more complex operations required are set to null. Index aligned with field number in daily summary log
/*
Nothing below this should need editing, except the SWITCH (if you have solar data or use an old build version of Cumulus or use different HTML datacell ids)
*/
// start of jQuery calls
jQuery(document).ready(function(){
var parameter_array=[];
var textStatus = "'null'";
// using jQuery
$.get(dailyLogFile,function(fdata,textStatus,jqXHR){
var lines=fdata.split("\r\n"); // defines that carriage return then line feed (newline) used to split daily observations in dayfile
var wd_data=lines[lines.length-367].split(field_delimiter);
var t_range=0;
for(var i=wd_data.length-1; i>0; i--){
parameter_array[i]="--";
if ((wd_data[i])!=="")parameter_array[i]=wd_data[i]; // insert observations if exists
switch(i){ // edit these cases to match your build of Cumulus, order does not matter
case 1:
case 2:
case 8:
case 10:
case 12:
case 14:
case 15:
case 16:
case 19:
case 21:
case 25:
case 27:
case 29:
case 31:
case 33:
case 40:
case 41:
$(htmlIdArray[i]).prepend(parameter_array[i]);break;// values
case 5:
case 7:
case 9:
case 11:
case 13:
case 18:
case 20:
case 22:
case 26:
case 28:
case 30:
case 32:
case 34:
$(htmlIdArray[i]).append(calculateTime(parameter_array[i]));break;// time stamps
case 3:
$('#Tgust1').append(calculateTime(parameter_array[3]));
$('#Tgust2').append(calculateTime(parameter_array[3]));
break;
case 4:
$('#low_temp').prepend(parameter_array[4]);
t_range -=parseInt((100*parameter_array[4]),10);
break;
case 6:
$('#high_temp').prepend(parameter_array[i]);
t_range+=parseInt((parameter_array[6]*100),10);
break;
case 17:
$('#peakWind').prepend(parseFloat(parameter_array[i,1]));
$('#beauFort').html(calculateBeaufort(parseFloat(parameter_array[i,1])),windUnit);
break;
case 35:
$('#high_dp').prepend(parameter_array[i,1]);
$('#high_ah_ya').prepend(humConvert(parameter_array[i,1]));
$('#high_ah_yest').prepend(humConvert(dewPt[2]));
$('#high_ah_to').prepend(humConvert(dewPt[3]));
break;
case 36:
$('#Thigh_dp').append(calculateTime(parameter_array[i,1]));
$('#Thigh_dp2').append(calculateTime(parameter_array[i,1]));
break;
case 37:
$('#low_dp').prepend(parameter_array[i,1]);
$('#low_ah_ya').prepend(humConvert(parameter_array[i,1]));
$('#low_ah_yest').prepend(humConvert(dewPt[0]));
$('#low_ah_to').prepend(humConvert(dewPt[1]));
break;
case 38:
$('#Tlow_dp').append(calculateTime(parameter_array[i,1]));
$('#Tlow_dp2').append(calculateTime(parameter_array[i,1]));break;
case 39:
$('#dwb').prepend(parameter_array[i,1]);
$('#dwb').append(windDirLang(parameter_array[i,1]));
break;
default:
}
}; // end of loop through values in row
$('#temp_range').prepend((t_range/100).toFixed(1));
// Note: Firefox and similar browsers need to be told the file type is not HTML by the "text" as last (datatype) parameter of GET.
},"text");// end of get
}); // end of ready