# Script written by: Govindakrishnan Kannan # Required: Parses the o/p files generated by the parse_RDF.pl and generates # metrics for each county in KY. # Status: Processes ONLY KYRDFXXX inputted at the command-lien for debug purposes. # Modified: 08/12/2003 package process_vars_html_test; require Exporter; @ISA = qw(Exporter); @EXPORT = qw(process_vars_html_test); ## /** # General information: # Table of variables for RDF, AFM, etc. # i) # RDF AFM PFM # --- --- --- # CDT/EDT CDT/EDT 3HRLY # MX/MN MAX/MIN # ii) # Some new notations(?) introduced in the "CLOUDS" ## **/ #Major change: Have an association as follows: # | 03 | - | # | 06 | a | # | 12 | b | # | 15 | c | # | 18 | d | # | 21 | e | # With number of columns as the number of hours => every-time look-up the {hr, var} #@EXPORT = qw(process_vars_html_test get_row_mm get_day_start_index print_array is_max_min_present); ## /** Package that takes care of printing all the variables **/ ## /** Goal 1: Write the output to a html file. **/ @seq = ("Today", "Tonight", "Tomorrow", "Tomorrow night", "Day-after-tomorrow", "Day-after-tomorrow"); $inp_file = "", $out_file = "";$fmt = "";$start_index = 0; $county_list_file = "/d2-agwx/ldmdata/scripts/county.list.ky"; %time_desc = ("9","AM", "15", "PM", "12", "AM", "3", "AM"); %dir_desc = ("N", "north", "NE", "northeast", "S", "south", "E", "east", "SE", "southeast", "SW", "southwest", "W", "west", "NW", "northwest"); ## /** To interpolate the WIND DIR, assign degrees from 0-360 as follows: # N(0, 360), NE(45, 315), E(90), SE(135), S(180), SW(225), W(270), # NW(315). **/ ## %interpol_wdir_desc = ("N", 1, "NE",2, "E", 3, "SE", 4, "S", 5, "SW", 6, "W",7, "NW", 8); @cloud_desc_hrs_arr = (2,7,10,15,3,6,11,14); ## /** Variables that represent the changes in RH% - by default 80, 50. **/ ## /** In general its should be the (HIGH, LOW) values. **/ ## /** RH values for tobacco bulking and handling are the third and fourth values **/ @rh_percent_numhrs_val = (80, 50, 74, 84); @temp_numhrs_val = (90, 32); #@rh_tobacco_bulking = (74, 84); ## /** Main subroutine - calls a subroutine for each of the corresponding vars. ## and uses the array returned by them to write to the file. ## **/ sub process_vars_html_test { # arguments are - inp_file, out_file, format. ($inp_file, $out_file, $fmt) = @_; my($desc_length, $day_index, @mm_desc, @qpf_pop_desc, %stress_hr_day_map, @winds_desc, @county_name, @dewpt_desc, @clouds_desc, $temp, @ls_stress_desc, @hrs_with_temp_desc, @hrs_with_rh_desc, @hrs_with_wind_desc, @tobacco_bulking_desc); local($county_desc, $update_time, $var); open(INP_H, "$inp_file") || die("Culdn't read a file"); open(OUT_H, ">$out_file") || die("Culdn't write a file"); print ("The input_file is $inp_file (FORMAT)=$fmt ...\n"); $start_index = &get_day_start_index(); ## /** Get the start day for the narrative **/ #print ("b4 get_day_start_index \n\n"); $day_index = &get_day_start_index(); #print ("after get_day_start_index \n\n"); ## /** Match the county number to look up in the county.list.ky **/ $inp_file =~ /(\d\d\d)/; $temp = "$&"; ## /** Get the coresponding line from the file. ## BUG: The first line doesn't necessarily match with the correct county ## as the same county number appears in other lines too. **/ $i = 0; open (CTYLIST_H, "$county_list_file") || die("Culdn't read a file county.list.ky"); @match = `grep -A 0 "$temp" "$county_list_file"`; while (1) { @temp = split(/\|/, $match[$i]); ++$i; if ($temp[0] == $temp) { last; } } ## /** Printing the county's name at the top of the file. **/ $temp[3] = ucfirst(lc($temp[3])); if ($temp[3] eq "Mccracken") { $temp[3] = "McCracken"; } ## /** Get the daywise descriptions for the different variables. **/ ## /** ## Include the model here to look for the appropriate variables within the subroutines; ## i-e:- MAX/MIN in AFM instead of MX/MN, etc. @mm_desc = &get_daywise_mmdesc($temp[3]); $desc_length = @mm_desc; ## /** Since POP is dependent on QPF, better to have as one routine. **/ @qpf_pop_desc = &get_daywise_qpf_pop_desc(); @dewpt_desc = &get_daywise_dewptdesc(); @rh_desc = &get_daywise_rhdesc(); @clouds_desc = &get_daywise_cloudsdesc(); @winds_desc = &get_daywise_windsdesc(); @ls_stress_desc = &get_daywise_ls_stress_desc(); %stress_hr_day_map = &get_ls_stress_hr_day_map(); @hrs_with_temp_desc = &get_numhrs_with_temp(); @hrs_with_rh_desc = &get_numhrs_with_rh(); ## /** The interpolated WIND DIR is calculated below **/ #&get_numhrs_with_wdir(); ## /** To compute tobacco bulking and handling levels **/ @tobacco_bulking_desc = &get_tobacco_bulking_desc(); #printf OUT_H ("%s County's Agricultural Weather Forecast Narrative\n", $match[3]); select(OUT_H); #$county_desc = sprintf("%s County's Agricultural Weather Forecast Narrative", $match[3]); #$~= "COUNTY_DESC"; #write; ## /** Print the update time after the county's name. **/ #printf OUT_H ("Last updated: %s\n", $update_time); $update_time = sprintf("Updated: %s\n", &get_header_time()); $~= "TIME_DESC"; write; for ($i = 0; $i < $desc_length; $i++) { #printf OUT_H ("%s:\n", uc($seq[$day_index++]) ); $var = uc($seq[$day_index]); $~= "DAY_DESC"; write; ## /** Print the QPF value here. **/ $var = sprintf(" %s", $qpf_pop_desc[$i]); $var = "$mm_desc[$i]"." $qpf_pop_desc[$i]"; #$var = "$mm_desc[$i]"; if ($dewpt_desc[$i] ne "UNDEF") { $var = "$var"." $dewpt_desc[$i]"; } if ($rh_desc[$i] ne "UNDEF") { $var = "$var"."$rh_desc[$i]"; } $var = "$var"." $clouds_desc[$i]"."$winds_desc[$i]"; $var = "$var"." $winds_desc[$i]"; if ( ($day_index == 0) || ($day_index == 2) || ($day_index == 4) ) { if ( $ls_stress_desc[$stress_hr_day_map{$day_index}] ne "UNDEF") { $var = "$var"." $ls_stress_desc[$stress_hr_day_map{$day_index}]"; } } if ( $hrs_with_temp_desc[$i] ne "UNDEF") { $var = "$var "."$hrs_with_temp_desc[$i]"; } if ( $hrs_with_rh_desc[$i] ne "UNDEF") { $var = "$var "."$hrs_with_rh_desc[$i]"; } #$var = "$var "."$tobacco_bulking_desc[$i]"; ## /** Getting the wind speed description **/ select(OUT_H); $~="VAR_DESC"; write; ++$day_index; } select(STDOUT); print ("The output_file is $out_file ...\n"); ## Testing the interpolation of data. ## Same function could be used for "TEMP", "DEWPT", "RH". #&get_vars_hourly("TEMP"); ## Testing the interpolation of DEWPT data. #&get_vars_hourly("DEWPT"); #&get_vars_hourly("RH"); #&get_numhrs_with_temp(); print ("****--****\n"); close(INP_H); close(OUT_H); } ## # /** Subroutine to calculate the actual offset at which the time-line begins (i-e:- 03 or 18) . # Not necesaary to calculate the offset, but just in case the format changes or is # obtained erroneously. **/ ## ## # /** Must handle 2 cases # 1) VAR is CDT 3HRLY, 2) VAR is MAX/MIN # # ## sub get_offset { my($offset, @row_time, $row_time); my(@header_time, $header_time, $compare); my($element, $i, $find_row, $stop_flag, $first_time_col); $row_time = &get_row_time(); #print ("get_offset: row-time = $row_time \n"); @row_time = split(/\s/, $row_time); #print ("get_offset: $row_time[0], $row_time[1] \n"); $offset = 0; $stop_flag = 0; foreach $element (@row_time) { #if ( ( ($element ne $row_time[0]) && ($element ne $row_time[1]) )&& ( ord($element) != 0) ) { # $stop_flag = 1; #} #if ($row_time[0] eq "MAX/MIN" || $row_time[0] eq "MIN/MAX") { # if ( ($element ne $row_time[0]) && ( ord($element) != 0) ) { # $stop_flag = 1; # } #} #if ($row_time[0] eq "CDT" || $row_time[0] eq "EDT") { if (ord($element) != 0) { if ($element ne $row_time[0]) { if ($fmt eq "RDF") { $stop_flag = 1; } elsif ($fmt eq "AFM") { if ($element ne $row_time[1]) { $stop_flag = 1; } } } } #print ("get_off: $element \n"); if ( $stop_flag != 1) { if ( ord($element) == 0) { #print("sp \n"); ++$offset; ++$first_time_col; } else { #For "CDT or "EDT" or "HRLY" #print("some ele - $element\n"); $offset += length($element); } } else { last; } } $corrected_offset = &get_corrected_offset($row_time, $offset); #print ("get_offset: offset = $offset; co-off = $corrected_offset \n\n"); #$start_time = $row_time[$corrected_offset - 3]; return ($corrected_offset); } #end-sub sub get_corrected_offset { my ($row_time, $offset) = ($_[0], $_[1]); my($element, $useful_row_time, $len, $ret_corrected_offset); ## /** Finding the beginning pos. of the sub-string for HOURS row. **/ $useful_row_time = substr($row_time, $offset, length($row_time)); #print ("useful_row_time =$useful_row_time \n"); ## /** Examine and adjust the offset to get the net-offset. **/ $len = 0; $ret_corrected_offset = $offset; while (1) { $element = substr($useful_row_time, $len, 1); #$len + 1); #print ("g_c_o:ele=$element \n"); if ( ord($element) == 32) { ++$ret_corrected_offset ; #= $offset + 1 $len++; } else { last; } } #print ("get_corr_offset: ret $ret_corrected_offset:$offset \n"); return($ret_corrected_offset); } #end-sub ## ***************************************************************************** # /****************************************************************************/ # Utilty subroutines that are shared by other subroutines that process each of the variables. # /****************************************************************************/ sub init_hash_time { my(@temp, $i, $element); @temp = &get_row_time_array(); $i = 0; foreach $element (@temp) { if ($element == 00) { $element = 12; } $hash_time{$i} = $element; $i++; } } sub get_row_mm { my(@row_mn_mx, @temp); if ($fmt eq "RDF") { @row_mn_mx = `grep -A 0 "MX/MN" $inp_file`; if ($row_mn_mx[0] eq undef) { @row_mn_mx = `grep -A 0 "MN/MX" $inp_file`; } } elsif ($fmt eq "AFM") { ## /* Finding the first occur. of "MAX" or "MIN" as "MAX/MIN' and "MIN/MAX" both ## occur int the same file eg:- fous53.krlx.gk @row_mn_mx = `grep -A 0 "MAX" $inp_file`; #if ($row_mn_mx[0] eq undef) { #@temp = `grep -A 0 "MIN" $inp_file`; #print("get_row_mm: ret $row_mn_mx[0] \n"); #print("get_row_mm: ret $row_mn_mx[1] \n"); #print("get_row_mm: ret $temp[0] \n"); #print("get_row_mm: ret $temp[1] \n"); # } } #if ($row_mn_mx[0] eq undef) { # if ($fmt eq "RDF") { # @row_mn_mx = `grep -A 0 "MN/MX" $inp_file`; # } # elsif ($fmt eq "AFM") { # @row_mn_mx = `grep -A 0 "MIN/MAX" $inp_file`; #} #} return ($row_mn_mx[0]); } sub get_day_start_index { my ($row_mm, $day_index, $mx_mn_present); $row_mm = &get_row_mm; $day_index = 1; $mx_mn_present = &is_max_min_present($row_mm); if ($mx_mn_present) { $day_index = 0; } return ($day_index); } sub is_max_min_present { ($row_mn_mx) = @_; my($ret_val, @row_mn_mx); $ret_val = 0; @row_mn_mx = split(/\s/, $row_mn_mx); if ( ($row_mn_mx[0] eq "MX/MN") || ($row_mn_mx[0] eq "MAX/MIN") ) { $ret_val = 1; } return ($ret_val); } sub get_row_time { my (@std_time, @ret_time, $row_time, $i); @std_time = ("EST", "CST"); if ($fmt eq "AFM") { $std_time[0] = "EST 3HRLY"; $std_time[1] = "CST 3HRLY"; } $i = -1; while(1) { if ($fmt eq "RDF") { @ret_time = `grep -A 0 "$std_time[++$i]"." " $inp_file`; } elsif ($fmt eq "AFM") { @ret_time = `grep -A 0 "$std_time[++$i]" $inp_file`; # grep -A 1.. } #print ("get_row_time:while: std_time = $std_time[$i];ret = $ret_time[0] \n"); if ($ret_time[0] ne undef) { last; } } #print("row_time=$ret_time[0] \n"); return ($ret_time[0]); } sub get_var_row { my($var_type) = @_; my(@ret_var); @ret_var = `grep -A 0 "$var_type"." " $inp_file`; return (@ret_var); } sub get_header_time { my (@header_time, @ret_time, $header_time, $i); @header_time = ("EST","CST"); $i = -1; while(1) { @ret_time = `grep -A 0 "M $header_time[++$i]" $inp_file`; if ($ret_time[0] ne undef) { last; } } return ($ret_time[0]); } sub get_row_time_array { my($row_time, @row_time, $correct_offset, $len, $cnt); $row_time = &get_row_time(); $correct_offset = &get_offset(); @row_time = split(/\s/, substr($row_time, $correct_offset, length($row_time)) ); $len = @row_time; $cnt = 0; while ($cnt < $len) { if ( $row_time[$cnt] =~ /(0\d)/) { if ( $row_time[$cnt] == 00) { $row_time[$cnt] = 12; } else { $row_time[$cnt] = substr($row_time[$cnt],1,1); } } $cnt++; } return (@row_time); } sub print_array { my(@temp) = @_; my($temp, $i); $temp = @temp; $i = 0; print ("^^^^Printing array\n"); while($i < $temp) {#foreach $ele (@temp) { print ("Element is $temp[$i++] \n"); } print ("^^^^^^\n"); } ## /** Subroutine computes the min-max over the given sub-array (dewpoints, rhf) **/ sub get_minmax_vals { my($beg_index, $end_index, @row) = @_; my(@ret_row, $i); #"max" dew pt is the first array element; and "min" dew pt is #the next array element. #print("if - $row[$i - 1] \n"); #Find a valid non-null value across the row, from the END within the specified range. while ($row[$end_index] eq undef ) { --$end_index; #print ("WHILE-undef..\n"); } #Find a valid non-null value across the row, from the BEGINNING within the specified range. while ($row[$beg_index] eq undef ) { ++$beg_index; print ("WHILE-undef..minmax_vals\n"); } $ret_row[0] = $row[$beg_index]; $ret_row[1] = $row[$beg_index]; for($i = $beg_index + 1; $i <= $end_index; $i++) { #if ($row[$i - 1] != 0) { if ( $row[$i] > $ret_row[0] ) { $ret_row[0] = $row[$i]; } elsif ( $row[$i] < $ret_row[1] ) { $ret_row[1] = $row[$i]; } #} } #for return (@ret_row); } #end sub sub get_suitable_value { my($val_index, @indices, @var) = @_; my($val); print ("get_suitable_value \n\n"); &print_array(@indices); &print_array(@var); while ( ($val = $row_mn_mx[$indices[$val_index]]) eq undef ) { $val = $row_mn_mx[$indices[$val_index--]] } return($val); } sub get_minmax_vals2 { #my($case, @row, @range) = @_; my($start_index, $stop_index, @var) = @_; my(@row, $i); #"max" dew pt is the first array element; and "min" dew pt is #the next array element. $row[0] = $var[$start_index]; $row[1] = $var[$start_index]; for($i=$start_index + 1; $i <= $stop_index; $i++) { if ( $var[$i] > $row[0] ) { $row[0] = $var[$i]; } elsif ( $var[$i] < $row[1] ) { $row[1] = $var[$i]; } } #for return (@row); } #end sub ## /** Companion sub-routine for get_daywise_desc() **/ sub get_var_array { my ($var_type) = @_; my(@var_arr, $ele, @new_var_arr, $i, $new_index, $correct_offset, $temp); $correct_offset = &get_offset(); @var_arr = `grep -A 0 "$var_type " $inp_file`; $temp = &get_row_time(); #printf ("substr=%s\n",substr($temp, $correct_offset, length($temp)) ); @var_arr = split(/\s/, substr($var_arr[0], $correct_offset, length($var_arr[0])) ); $i = @var_arr; $i = 0; foreach $ele (@var_arr) { ## /** We need only the 15 elements, till 3 AM for the day-after-tomm., in a DAY reading **/ if ($i > 15) { last; } elsif ( ord($ele) != 0) { $new_var_arr[$i] = $ele; ++$i; } } return (@new_var_arr); } #sub sub get_actual_var_array { my ($var_type) = @_; my(@var_arr, $ele, @new_var_arr, $i, $new_index, $correct_offset, $temp); $correct_offset = &get_offset(); @var_arr = `grep -A 0 "$var_type " $inp_file`; $temp = &get_row_time(); printf ("substr=%s\n",substr($temp, $correct_offset, length($temp)) ); @var_arr = split(/\s/, substr($var_arr[0], $correct_offset, length($var_arr[0])) ); $i = @var_arr; $i = 0; #foreach $ele (@var_arr) { ## /** We need only the 15 elements, till 3 AM for the day-after-tomm., in a DAY reading **/ #if ($i > 15) { #last; #} #elsif ( ord($ele) != 0) { #else { #$new_var_arr[$i] = $ele; #++$i; #} #} #return (@new_var_arr); return (@var_arr); } #sub #Returns the offset from the "starting-time" column. sub get_var_first_offset{ my(@var_arr) = @_; my($ele, $num_spaces); $num_spaces = 0; foreach $ele (@var_arr) { if ( ord($ele) == 0) { ++$num_spaces; } else { last; } } return($num_spaces/2 - 1); }#sub sub get_var_last_offset { my($first_off, @var_arr) = @_; my($len, $last_off); $len = &get_actual_arr_len(@var_arr); $last_off = $len + $first_off; return ($last_off); } sub get_actual_arr_len { my(@var_arr) = @_; my($num_non_null); $num_non_null = 0; foreach $ele (@var_arr) { ## /** We need only the 15 elements, till 3 AM for the day-after-tomm., in a DAY reading **/ if ( ord($ele) != 0) { ++$num_non_null; } } return ($num_non_null); } #sub sub get_non_null_arr { my(@var_arr) = @_; my(@new_var_arr, $i); $i = 0; foreach $ele (@var_arr) { ## /** We need only the 15 elements, till 3 AM for the day-after-tomm., in a DAY reading **/ if ( ord($ele) != 0) { $new_var_arr[$i] = $ele; ++$i; } } return (@new_var_arr); } #sub #Returns 8 elements - each pair havinb the start, stop for sub-range. sub get_range { my($foff, $loff, $actual_len) = @_; my(@row_time, @ret_range, $foff_hr, $loff_hr); @row_time = &get_row_time_array(); #get the frist-element of the row-time array, and compute the index . $foff_hr = $row_time[0] + $foff*3; $ret_range[0] = 0; $ret_range[1] = (18 - $foff_hr)/3 ; $ret_range[2] = $ret_range[1]; $ret_range[3] = $ret_range[2] + 4; $ret_range[4] = $ret_range[3]; $ret_range[5] = $ret_range[4] + 4; $ret_range[6] = $ret_range[5]; $ret_range[7] = $actual_len + $foff; return (@ret_range); } #GK: Added 10/16 sub get_reformatted_array { my(@arr) = @_; my( $num_spaces, $i, $j, $start , @reformat_arr, $ele, $temp); $num_spaces = 0, $start = 0; #Count the number fo spaces before the first-value foreach $ele (@arr) { #printf ("ord=%D", ord($ele)); if (ord($ele) == 0) { ++$num_spaces; } else { $num_spaces = int($num_spaces/3); #print ("j= $j \n"); for($i = $start; $i < $start + $num_spaces; $i++) { $reformat_arr[$i] = ""; } ## Logic for RH is handled here-itself; if (length($ele) <= 3) { $reformat_arr[$start + $num_spaces] = $ele; $start += $num_spaces + 1; } # if else { #Extract all patterns within this sub-string eq:100100..|971009889 $temp = $ele; while (length($temp) > 0) { $temp =~ /(100|\d\d)/; if ( ord($&) != 0) { $reformat_arr[$start++] = $&; } printf ("\nThe first-match=%s;len=%d", $&, length($&)); $temp = substr($temp, length($&)); #, length($temp)-length($&)); } #WHILE } #inner-else $num_spaces = 0; } #else } #FOR return (@reformat_arr); } sub get_var_index_wrt_hrs { my($offset, @hrs_blk) = @_; #print ("day-st = $day_start \n"); my(@hrs_array, $i,$j, @ret_indices, $day_start); $j = 0; $i = 0; $day_start = $start_index; @hrs_array = &get_row_time_array(); if ($offset == 2) { #Go thru' the array starting with the third element wherein array is #{09, 15, 12, 03,09,15...} #if day_start == 1=> consider from 09 onwards else 12 if ($day_start) { $day_start += 1; } } printf("get_var_index_wrt_hrs: Checking hrs_array..\n"); &print_array(@hrs_array); &print_array(@hrs_blk); foreach $ele (@hrs_array) { if ($ele == $hrs_blk[$day_start]) { $ret_indices[$j++] = $i; print ("assigned = ($i - 1) \n"); $day_start++; } ++$i; printf ("ele = %d;cmp = %d \n",$ele, $hrs_blk[$day_start]); } return(@ret_indices); } ## /** To get the 4 values of the QPF, POP variables **/ sub get_fourvals_array { my($var_type) = @_; my(@var_arr, @new_var_arr, $correct_offset, $new_index, $ele); @var_arr = `grep -A 0 "$var_type" $inp_file`; $correct_offset = &get_offset(); $new_index = 0; ## /** "new_row_pop" stores only 4 elements starting with index = 0 **/ @var_arr = split(/\s/, substr($var_arr[0], $correct_offset, length($var_arr[0]))); foreach $ele (@var_arr) { if ($new_index > 3 ) { last; } elsif ( ord($ele) != 0) { $new_var_arr[$new_index] = $ele; $new_index += 1; } } return (@new_var_arr); } sub round_off() { my($val) = @_; my($frac, $retval); ## /** Match the decimal part and compare it with 0.5 **/ $val =~ /(\.(\d*))$/; $frac = $&; ## /** For some reason, if the argument passed is an integer, the pattern doesn't match ## and assigns the value "5.00" to the fractional part. **/ if ($frac == 5.00) { $frac = 0.00; } $val =~ /\d*/; $retval = $&; if ( $frac > 0.5 && $frac != 0) { ++$retval; } return($retval); } sub get_num_hrs { ## /** $var = type of variable; $var_val, value to compare; ## $var_val_choice = choice that specifies the value to use. **/ my($var, $var_val_choice) = @_; my(@interpol_var, @ret_hrs, $begin, $end, $i, $j); @interpol_var = &get_vars_hourly("$var"); #&print_array(@interpol_temp); #&print_interpol_array(@interpol_var); $end = 11; $begin = 0; # $end = 12; for($i = 0;$i < 4; $i++) { $ret_hrs[$i] = 0; if ($i == 3) { $end = 45; } for($j = $begin; $j <= $end; $j++) { if ($var eq "TEMP") { ## /** Checking for all TEMPs. >= 90 OR <= 32 **/ if ($var_val_choice == 0) { #if ($var_val == 90) { if ( $interpol_var[$j] >= 90 ) { ++$ret_hrs[$i]; } } elsif ( $interpol_var[$j] <= 32 ) { ++$ret_hrs[$i]; } } elsif ($var eq "RH") { ## /** Checkng for all RHs < 50% OR > 80% **/ #if ($var_val == $rh_percent_numhrs_val[0]) { if ($var_val_choice == 0) { if ( $interpol_var[$j] > $rh_percent_numhrs_val[0] ) { ++$ret_hrs[$i]; } } elsif ($var_val_choice == 1) { if ($interpol_var[$j] < $rh_percent_numhrs_val[1] ) { ++$ret_hrs[$i]; } } elsif ($var_val_choice == 2) { if ($interpol_var[$j] < $rh_percent_numhrs_val[2] ) { ++$ret_hrs[$i]; } } elsif ($var_val_choice == 3) { if ($interpol_var[$j] < $rh_percent_numhrs_val[3] ) { ++$ret_hrs[$i]; } } } #elsif } #for-2 $begin = $end + 1; $end += 12; } #for-1 return (@ret_hrs); } ## /** Print hourly temp. data; follows similar logic to RH desc. as the temps .could be ## more than 100 degrees. **/ sub get_vars_hourly { my($var_type) = @_; my(@hrly_var, @temp_var, @row_var, $correct_offset, $i, $hrly_index, $str_var, $delta, $flag); $flag = 0; ## /** "hrly_var" augments the interpolated data with the data that already exists in the array. **/ for($i = 0; $i<= 45; $i++) { $hrly_var[$i] = 0.0; } if ($var_type eq "WIND DIR") { @temp_var = &get_var_array("WIND DIR"); &print_array(@temp_var); for($i = 0; $i<= 15; $i++) { $hrly_var[$i*3] = $interpol_wdir_desc{$temp_var[$i]}; } $flag = 1; } else { ## /** "new_row_var" stores only 4 elements starting with index = 0; refer the format **/ $i = 0; @row_var = &get_var_row($var_type); #;`grep -A 0 "$var_type " $inp_file`; $correct_offset = &get_offset(); if ($row_var[0] ne undef) { $flag = 1; $row_var = substr($row_var[0], $correct_offset, length($row_var[0])); while (1) { $str_var = $row_var; #$row_var =~ /(\s*)(\d*)(\s*)/; $row_var =~ /(\s*)(100|\d\d|\d\d\d)(\s*)/; if ($i > 15) { last; } else { ## /** The following line takes care-of considering the subsequent text that ## appears after a space from the previous value. **/ $row_var = substr($row_var, length($&), length($row_var[0])); $str_var =~ /(100|\d\d|\d\d\d)/; if ( ord($&) != 0) { $new_row_var[$i] = $&; $hrly_var[$i*3] = $new_row_var[$i]; ++$i; } } }#while } #if } #else #&print_array(@new_row_var); #print ("b4 interpoln. \n"); #&print_array(@hrly_var); if ($flag == 1) { ## /** Iterate 15 times(intervals) calculating the 2 interpolated values, each time(interval) **/ $hrly_index = 1; for($i = 1; $i <= 15; $i++) { $delta = ( $hrly_var[$i*3] - $hrly_var[($i - 1)*3]); ## /** Round-off the end result. **/ $hrly_var[$hrly_index] = $hrly_var[$hrly_index - 1] + ($delta/3); $hrly_var[$hrly_index] = &round_off($hrly_var[$hrly_index]); $hrly_var[$hrly_index+1] = $hrly_var[$hrly_index] + ($delta/3); $hrly_var[$hrly_index+1] = &round_off($hrly_var[$hrly_index+1]); #printf ("%d = %2.3f||",$hrly_index, $hrly_var[$hrly_index]); #printf ("%d = %2.3f\n",($hrly_index+1), $hrly_var[$hrly_index+1]); $hrly_index += 3; } #print ("After interpoln, for $var_type the hrly vars follows...\n"); #&print_interpol_array(@hrly_var); } #if return (@hrly_var); } ## Sub. sub print_interpol_array { my(@temp) = @_; my($temp, $i); $temp = @temp; $i = 0; print ("^^^^Printing interpol-array\n"); while($i < $temp) {#foreach $ele (@temp) { #print ("Element is $ele\n"); print ("Element is $temp[$i++]\n"); if ( ($i == 12) || ($i == 24) || ($i == 36) ) { print ("===\n"); } } print ("^^^^^^\n"); } sub get_hr_by_desc { my($ele) = @_; my($hrs); #$hrs = "UNDEF"; $hrs = "hour"; if ( $ele > 1) { $hrs = "hours"; } return ($hrs); } ## ***************************************************************************** # ## /** Subroutines that process each of the variables and return the description per day. **/ ## /*****************************************************************************************/ ## /** Subroutine to process MN/MX. **/ #/********************************* GK: 10/16 - Logic: Reformat the array read from RDF/AFM, # such that there is a value for the corresponding hour. sub get_daywise_mmdesc { my($county_name) = @_; my($correct_offset, $row_mn_mx, @daywise_desc, $val); my($i, $desc1, $desc2, $desc, $j, $k, @reformat_row, @row_mn_mx, @hrly_block); @hrly_block = (15,03,15,03,15); $row_mn_mx = &get_row_mm(); $correct_offset = &get_offset(); ## /** Actual processing of the array - MN/MX - making use of the periodicity of the forecast. # If its morning - first temp. is for f-15 and thereafter next-03, next-15, next-03, next-15 ## If its afternoon - first temp is for f-03 and thereafter next-15 , next-03, next-15, next-03 **/ $i = 0; $j = 0; $val = 0; ## /** "new_row_mn_mx" stores only 4 elements starting with index = 0; refer the format **/ #@row_mn_mx = split(/\s/, substr($row_mn_mx, $correct_offset, length($row_mn_mx))); @row_mn_mx = split(/\s/, substr($row_mn_mx, $correct_offset, length($row_mn_mx))); #GK:10.16 - Reformat the array as told above @row_mn_mx = &get_reformatted_array(@row_mn_mx); #&print_array(@reformat_row); #print ("row=$row_mn_mx\n"); ## /** Assumption: If the row is MN/MX, then periodically follow ("LOW", "HIGH"). **/ $desc1 = "low"; $desc2 = "high"; if (&is_max_min_present($row_mn_mx)) { $desc1 = "high"; $desc2 = "low"; } ## /** Get the starting_day index depending on whether its Today or Tonight. **/ #/*** Index into the global @hrly_block array get the indices of # the "row_arr" that correspond to, the specific time in the "hours" array. # A generic sub-routine that can be resued. # ******/ if ($fmt eq "RDF") { @hrly_block = (15,3,15,3,15); #print ("rdf"); } elsif ($fmt eq "AFM") { @hrly_block = (18,6,18,6,18); } @var_indices = &get_var_index_wrt_hrs(0, @hrly_block); print ("var-indices,,\n\n"); &print_array(@var_indices); $j = $start_index; for($i = 0; $i <= 3; $i++) { $desc = $desc2; $word = "around"; ## /** Alternating the descriptions for day and night. **/ if ( $i%2 == 0) { $desc = $desc1; $word = "near"; } # For AFM, the temperature may not be there in the given hourly-block, # so find a non-zero temp. closer to those hours. #$val = &get_suitable_value($i, @var_indices, @row_mn_mx); $k = $var_indices[$i]; if ($fmt eq "AFM") { while ( $row_mn_mx[$k] eq undef ) {--$k;} } $daywise_desc[$i] = sprintf("The %s %s in %s county, is expected to be %s %d degrees.", $desc, lc($seq[$j++]), $county_name, $word, $row_mn_mx[$k]); } #for return (@daywise_desc); } #end-sub ## /** Subroutine to process QPF. **/ sub get_daywise_qpfdesc { my($correct_offset, @daywise_desc); my($i, $new_index, @new_row_qpf, @row_qpf); @row_qpf = `grep -A 0 "QPF 12HR" $inp_file`; $correct_offset = &get_offset(); $new_index = 0; ## /** "$new_row_qpf" stores only 4 elements starting ## with index = 0; refer the format. **/ @row_qpf = split(/\s/, substr($row_qpf[0], $correct_offset, length($row_qpf[0]))); foreach $ele (@row_qpf) { if ($new_index > 3 ) { last; } elsif ( ord($ele) != 0) { $new_row_qpf[$new_index] = $ele; $new_index += 1; } } ## /** Get the starting_day index depending on whether its Today or Tonight **/ $start_index = &get_day_start_index(); for($i = 0; $i <= 3; $i += 1) { if ( $new_row_qpf[$i] == 0) { $daywise_desc[$i] = "No rainfalls"; } else { $daywise_desc[$i] = sprintf("Rainfall totals of %s inches", $new_row_qpf[$i]); } } #for return (@daywise_desc); } #end-sub ## /** Subroutine to process POP 12HR. **/ sub get_daywise_popdesc { my($correct_offset, @daywise_desc); my($i, $new_index, @new_row_pop, @row_pop); @row_pop = &get_var_row("POP 12HR"); @row_pop = &get_var_row("POP 12HR"); $correct_offset = &get_offset(); $new_index = 0; ## /** "new_row_pop" stores only 4 elements starting with index = 0 **/ @row_pop = split(/\s/, substr($row_pop[0], $correct_offset, length($row_pop[0]))); foreach $ele (@row_pop) { if ($new_index > 3 ) { last; } elsif ( ord($ele) != 0) { $new_row_pop[$new_index] = $ele; $new_index += 1; } } ## /** Get the starting_day index depending on whether its Today or Tonight **/ $start_index = &get_day_start_index(); for($i = 0; $i <= 3; $i += 1) { #$daywise_desc[$i] = sprintf("over %s", $new_row_pop[$i]); #$daywise_desc[$i] .= "%".sprintf(" of the county \nare expected %s.", # lc($seq[$start_index++])); if ( $new_row_pop[$i] == 0) { $daywise_desc[$i] = "are expected."; } else { $daywise_desc[$i] = sprintf("over %s", $new_row_pop[$i]); $daywise_desc[$i] .= "%".sprintf(" of the county \nare expected."); } } #for return (@daywise_desc); } #end-sub ## /** Subroutine to process QPF and POP. **/ #GK: New version sub get_daywise_qpf_pop_desc { my($i,$temp, $correct_offset, @daywise_desc, @temp, @reformat_row_pop, @row_qpf, @hrly_block); $correct_offset = &get_offset(); @temp = &get_var_row("POP 12HR"); #print ("row_pop = $temp[0] \n"); @temp= split(/\s/, substr($temp[0], $correct_offset, length($temp[0]))); @reformat_row_pop = &get_reformatted_array(@temp); #print ("row_pop \n"); #&print_array(@reformat_row_pop); @row_qpf = &get_fourvals_array("QPF 12HR"); ## /** Get the starting_day index depending on whether its Today or Tonight. **/ #/*** Index into the global @hrly_block array get the indices of # the "row_arr" that correspond to, the specific time in the "hours" array. # A generic sub-routine that can be resued. # ******/ if ($fmt eq "RDF") { @hrly_block = (15,3,15,3,15); #print ("rdf"); } elsif ($fmt eq "AFM") { @hrly_block = (18,6,18,6,18); } @temp = &get_var_index_wrt_hrs(0, @hrly_block); #print ("abcd var-indices,,\n\n"); &print_array(@temp); ## /** Get the starting_day index depending on whether its Today or Tonight **/ #$start_index = &get_day_start_index(); for($i = 0; $i <= 3; $i += 1) { #$daywise_desc[$i] = sprintf("over %s", $new_row_pop[$i]); #$daywise_desc[$i] .= "%".sprintf(" of the county \nare expected %s.", # lc($seq[$start_index++])); if ( $reformat_row_pop[$temp[$i]] != 0) { $temp = sprintf(" over %s", $reformat_row_pop[$temp[$i]]); $temp .= "%".sprintf(" of the county \nare expected."); $daywise_desc[$i] = sprintf("Rainfall totals of %s inches", $row_qpf[$i]); if ( $row_qpf[$i] == 0) { $daywise_desc[$i] = "Rainfall totals of .00 - .01 inches"; } $daywise_desc[$i] .= "$temp"; } else { $daywise_desc[$i] = "No rainfall is expected."; } } #for return (@daywise_desc); } #end-sub ## /** Subroutine to process DEW PT. ## Computes the dew point, day-wise as follows: ## the min-max within a range of 12hrs i-e:- 06-18 (for day) and 18-6 (for night), etc. **/ #GK: New version sub get_daywise_dewptdesc { my($correct_offset, @daywise_desc, @dewpts, @row_dewpt, @hrly_block, @var_indices, $start_offset, $end_offset); my($i, $offset); #@row_dewpt = `grep -A 0 "DEWPT " $inp_file`; @row_dewpt = &get_var_row("DEWPT"); $correct_offset = &get_offset(); #@row_dewpt = &get_var_array("DEWPT"); for($i = 0; $i<=15; $i++) { $new_row_dewpt[$i] = "UNDEF"; } ## /** "new_row_dewpt" stores only 4 elements starting with index = 0; refer the format **/ if ( $row_dewpt[0] ne undef) { @row_dewpt = split(/\s/, substr($row_dewpt[0], $correct_offset, length($row_dewpt[0]))); @reformat_row = &get_reformatted_array(@row_dewpt); #print ("reformat dew-pt arrays..\n"); #&print_array(@reformat_row); #@row_dewpt = split(/\s/, substr($row_dewpt[0], $correct_offset, length($row_dewpt[0]))); #foreach $ele (@row_dewpt) { #if ($new_index > 15) { # last; #} #elsif ( ord($ele) != 0) { #$new_row_dewpt[$new_index] = $ele; #++$new_index; #} #} #Assume this array for both RDF/AFM @hrly_block = (18,6,18,6,18); @var_indices = &get_var_index_wrt_hrs(0, @hrly_block); #print ("printing indices..\n"); #&print_array(@var_indices); ## Get the starting_day index depending on whether its Today or Tonight #$first_off = &get_var_first_offset(@row_dewpt); #$last_off = &get_var_last_offset($first_off, @row_dewpt); #$actual_len = &get_actual_arr_len(@row_dewpt); #@range_arr = &get_range($first_off, $last_off, $actual_len); #@row_dewpt = &get_var_array("DEWPT"); for($i = 0; $i <= 3; $i += 1) { ### #Get the maximum and minimum from every-set of {1-5}, {5-9}, {9-13}, {13-16} #and return it for the day. ### ### #Correction: off1 - offset from the beginning of the hr-row; # off2 - offset from the endof the which hr-row; # So get the first hour also #Get the maximum and minimum from every-set of {off1-5}, {5-9}, {9-13}, {13-off2} #and return it for the day. ### # ### #@dewpts = &get_minmax_vals($i, @reformat_row); #@new_row_dewpt $start_offset = 1; $end_offset = $var_indices[0]; if ($i > 0) { $start_offset = $var_indices[$i-1]; $end_offset = $var_indices[$i]; } #if ($i == 3) { #print ("last sub..\n"); #} @dewpts = &get_minmax_vals($start_offset,$end_offset, @reformat_row); #@new_row_dewpt if ($dewpts[0] == $dewpts[1]) { #$daywise_desc[$i] = sprintf("Dewpoint %s ", lc($seq[$start_index++])); #$daywise_desc[$i] .= sprintf("will be near %s degrees.", $dewpts[1]); $daywise_desc[$i] = sprintf("Dewpoints will be near %s degrees.", $dewpts[1]); } else { #$daywise_desc[$i] = sprintf("Dewpoints %s ", lc($seq[$start_index++])); #$daywise_desc[$i] .= sprintf("will range from %s to %s degrees.", # $dewpts[1], $dewpts[0]); $daywise_desc[$i] = sprintf("Dewpoints will range from %s to %s degrees.", $dewpts[1], $dewpts[0]); } #print ("The desc is $daywise_desc[$i] \n"); } #for } #if return (@daywise_desc); } #end-sub ## /** Subroutine to process RHF. **/ sub get_daywise_rhdesc { my($correct_offset, $row_rh, @daywise_desc, @rhs); my($i, $j, $desc, $new_index, @new_row_rh, @row_rh, @var_indices, @hrly_block, $end_offset, $start_offset, @hrly_block); ## # Process the RH carefully - a worst case would be a string of 100s # 100100100100..|10010010097..|9710010097..etc. # the worst case: 100..repeated till 16 times. ## @row_rh = &get_var_row("RH "); $correct_offset = &get_offset(); $new_index = 0; ##22 - max number of RH values in AFM for($i = 0; $i<=22; $i++) { $new_row_rh[$i] = "UNDEF"; } if ($fmt eq "AFM") { $j = 22; } elsif ($fmt eq "RDF") { $j = 15; } ## /** "new_row_rh" stores only 4 elements starting with index = 0; refer the format **/ if ($row_rh[0] ne undef) { $row_rh = substr($row_rh[0], $correct_offset, length($row_rh[0])); @row_rh = split(/\s/, substr($row_rh[0], $correct_offset, length($row_rh[0]))); @row_rh = &get_reformatted_array(@row_rh); print("formatted row rh \n"); &print_array(@row_rh); ## /** Get the starting_day index depending on whether its Today or Tonight **/ #print ("printing row_rh..\n"); #&print_array(@new_row_rh); #@reformat_row = &get_reformatted_array(@new_row_rh); #print ("reformat dew-pt arrays..\n"); #&print_array(@reformat_row); #@row_dewpt = split(/\s/, substr($row_dewpt[0], $correct_offset, length($row_dewpt[0]))); #foreach $ele (@row_dewpt) { #if ($new_index > 15) { # last; #} #elsif ( ord($ele) != 0) { #$new_row_dewpt[$new_index] = $ele; #++$new_index; #} #} #Assume this array for both RDF/AFM @hrly_block = (18,6,18,6,18); @var_indices = &get_var_index_wrt_hrs(0, @hrly_block); $j = $start_index; print ("RH.."); &print_array(@new_row_rh); for($i = 0; $i <= 3; $i += 1) { ## /** Get the maximum and minimum from every-set of {1-5}, {5-9}, {9-13}, {13-16} **/ #@rh = &get_minmax_vals($i, @new_row_rh); $start_offset = 1; $end_offset = $var_indices[0]; if ($i > 0) { $start_offset = $var_indices[$i-1]; $end_offset = $var_indices[$i]; } @rh = &get_minmax_vals($start_offset,$end_offset, @row_rh); #@new_row_dewpt #print ("printing min-max rh..") ; #&print_array(@rh); $daywise_desc[$i] = lc($seq[$j]); $daywise_desc[$i] = "\nThese dewpoints will \ncombine with $daywise_desc[$i]\'s temperatures" ." resulting in relative humidity"; $val = "0"; if ( ($j == 0) || ($j == 2 )|| ($j == 4) ) { $desc = "minimum"; } else { $desc = "maximum"; } if ($rh[0] == $rh[1]) { #if ($rh[0] ne undef ) { $val = $rh[0]; #} #$daywise_desc[$i] .= sprintf(" $desc of %s", $val); } else { #$daywise_desc[$i] .= sprintf(" between %s",$rh[1]); #$daywise_desc[$i] .= "%".sprintf(" to %s", $rh[0]); if ($desc eq "maximum") { $val = $rh[0]; } else { $val = $rh[1]; } } $daywise_desc[$i] .= sprintf(" $desc of %s", $val); $daywise_desc[$i] .= sprintf("%."); $j++; } #for } #&print_array(@dayise_desc); return (@daywise_desc); } #end-sub ## /** Subroutine to process SKY conditions. **/ sub get_daywise_cloudsdesc { my($correct_offset, @daywise_desc, $init_offset); my($i, $j, $k, $hr_index, $hr, @hr, $hr_adjust, @temp, @row_cloud); @row_cloud = &get_var_row("CLOUDS");#;`grep -A 0 "CLOUDS " $inp_file`; $correct_offset = &get_offset(); for($i = 0; $i<= 3; $i++) { $new_row_cloud[$i] = "UNDEF"; $daywise_desc[$i] = "UNDEF"; } ## /** Just get the entire array of cloud's description, and defer processing them until later. **/ @row_cloud = split(/\s/, substr($row_cloud[0], $correct_offset, length($row_cloud[0]))); @row_cloud = &get_reformatted_array(@row_cloud); printf ("Printing formatted row_cloud in daywise_clou desc \n"); &print_array(@row_cloud); @hrly_block = (9,15,12,3,9,15,12,3,9,15); @var_indices = &get_var_index_wrt_hrs(2, @hrly_block); #printf ("Printing var_indices in daywise_clou desc \n"); #&print_array(@var_indices); ## /** Get the starting_day index depending on whether its Today or Tonight **/ $init_offset = 0; if ($start_index == 1) { $init_offset = 4; } @time_array = &get_row_time_array(); #print ("The row_time from clodedesc follows..\n"); #&print_array(@temp); #Store (2,7,10,15) and (3,6,11,14) in an array #each of this is the first element of the pair that we need # the second element progresses as 4,8,12,16 #$hr_id = 4; $k = 0; for($i = 0; $i <= 3; $i += 1) { $daywise_desc[$i] = sprintf("Skies will be "); for($j = 0; $j <= 1; $j++) { $hr = $time_array[$var_indices[$k]]; $cloud_desc = &get_precise_cloud_desc($var_indices[$k], $hr, @row_cloud); printf ("The cloud_desc returned is $cloud_desc for hour $hr\n"); if ( $hr > 12) { $hr = $hr - 12; } #$desc = sprintf("%s at %s %s", $desc_array[$j], $hr, $time_desc{$temp[$times_arr[$init_offset]]} ); if ($cloud_desc ne "UNDEF") { $desc = sprintf("%s at %s %s", $cloud_desc, $hr, $time_desc{$time_array[$var_indices[$k]]} ); #Include the "and" part IFF the forecast for the first-part is NON-NULL and second-part is # NON-NULL too; the following "if" block considers both these cases. if ($j == 1) { if ( $daywise_desc[$i] ne "Skies will be " ) { $daywise_desc[$i] = "$daywise_desc[$i]"." and "."$desc"; } else { $daywise_desc[$i] = "$daywise_desc[$i]"."$desc"; } } elsif ($j == 0) { $daywise_desc[$i] = "$daywise_desc[$i]"."$desc"; } } $k++; } #inner for $daywise_desc[$i] = "$daywise_desc[$i]"."\."; #++$start_index; #$hr_id += 4; } #for print ("cloud_desc \n"); &print_array(@daywise_desc); return (@daywise_desc); } #end-sub sub get_precise_cloud_desc { my ($hr_index, $hr, @row_cloud) = @_; my (%cloud_desc, $ret_desc); #Added entries FW, BK (=B in RDF) for AFM-model. %cloud_desc = ("B","mostly cloudy", "OV", "cloudy", "SCD", "partly sunny", "SCN", "partly cloudy", "CLN", "clear", "CLD", "sunny", "FWD", "mostly sunny", "FWN", "mostly clear", "BK", "mostly cloudy"); #$ret_desc = $row_cloud[$hr_index + 3]; $ret_desc = $row_cloud[$hr_index]; if ( ($ret_desc eq "B1") || ($ret_desc eq "B2") || ($ret_desc eq "BK")) { $ret_desc = $cloud_desc{"B"}; } elsif ( $ret_desc eq "SC" ) { if ($hr == 9 || $hr == 15) { $ret_desc = $cloud_desc{"SCD"}; } else { $ret_desc = $cloud_desc{"SCN"}; } } elsif ( $ret_desc eq "CL") { if ($hr == 12 || $hr == 3) { $ret_desc = $cloud_desc{"CLN"}; #CLD } else { $ret_desc = $cloud_desc{"CLD"}; } } elsif ( $ret_desc eq "OV") { # ( $ret_desc eq "OV") { $ret_desc = $cloud_desc{"OV"}; } elsif ( $ret_desc eq "FW" ) { if ($hr == 9 || $hr == 15) { $ret_desc = $cloud_desc{"FWD"}; } else { $ret_desc = $cloud_desc{"FWN"}; } } elsif ( $ret_desc eq undef) { # ( $ret_desc eq "OV") { $ret_desc = "UNDEF"; } return ($ret_desc); } sub get_daywise_windsdesc { my(@daywise_desc, $start_offset, $end_offset, $temp, @row_wind_dir, @row_wind_spd, $hr_id, $hr, @var_indices, @hrly_block); ## /** Get the entire row for "WIND SPD" and "WIND DIR" and defer processing them until later. **/ ## /** Get the starting_day index depending on whether its Today or Tonight **/ $correct_offset = &get_offset(); @row_wind_dir = &get_var_row("WIND DIR"); @row_wind_dir = split(/\s/, substr($row_wind_dir[0], $correct_offset, length($row_wind_dir[0]))); @row_wind_dir = &get_reformatted_array(@row_wind_dir); print ("wdir"); &print_array(@row_wind_dir); @row_wind_spd = &get_var_row("WIND SPD"); print ("wspd - 1"); &print_array(@row_wind_spd); @row_wind_spd = split(/\s/, substr($row_wind_spd[0], $correct_offset, length($row_wind_spd[0]))); print ("wspd - 2"); &print_array(@row_wind_spd); @row_wind_spd = &get_reformatted_array(@row_wind_spd); print ("wspd"); &print_array(@row_wind_spd); #&print_array(@row_wind_spd); #$init_offset = 3; @temp = &get_row_time_array(); $hr_id = 4; @hrly_block = (18,6,18,6,18); @var_indices = &get_var_index_wrt_hrs(0, @hrly_block); @hrly_block = (15,3,15,3,15); @var_indices2 = &get_var_index_wrt_hrs(0, @hrly_block); &print_array(@var_indices); for($i = 0; $i <= 3; $i += 1) { #$desc = $row_wind_spd[$init_offset + $i*4]; #if ($row_wind_dir[$init_offset + $i*4] eq "--") { # if ($row_wind_spd[$init_offset + $i*4] == 0 ) { # $desc = "calm"; # $temp = $desc; #} #} $desc = $row_wind_spd[$var_indices[$i]]; if ($row_wind_dir[[$var_indices[$i]]] eq "--") { if ($row_wind_spd[$var_indices[$i]] == 0 ) { $desc = "calm"; $temp = $desc; } } $hr = $temp[$hr_id]; if ( $hr > 12) { $hr = $hr - 12; } #@minmax = &get_minmax_vals($i, @row_wind_spd); $start_offset = 1; $end_offset = $var_indices[0]; if ($i > 0) { $start_offset = $var_indices[$i-1]; $end_offset = $var_indices[$i]; } @minmax = &get_minmax_vals($start_offset,$end_offset, @row_wind_spd); #@new_row_dewpt $daywise_desc[$i] = sprintf("Wind speed will "); if ($minmax[0] == $minmax[1]) { #$daywise_desc[$i] = sprintf("Dewpoint %s ", lc($seq[$start_index++])); #$daywise_desc[$i] .= sprintf("will be near %s degrees.", $dewpts[1]); $daywise_desc[$i] = $daywise_desc[$i].sprintf("be near %s mph", $minmax[0]); } else { #$daywise_desc[$i] = sprintf("Dewpoints %s ", lc($seq[$start_index++])); #$daywise_desc[$i] .= sprintf("will range from %s to %s degrees.", # $dewpts[1], $dewpts[0]); $daywise_desc[$i] = "$daywise_desc[$i]".sprintf("range from %s to %s mph", $minmax[1], $minmax[0]); } $daywise_desc[$i] = "$daywise_desc[$i] during the period. ".sprintf("Winds at %d %s will be", $hr, $time_desc{$temp[$hr_id]} ); #if ($row_wind_spd[$init_offset + $i*4] <= 12) { if ($row_wind_spd[$var_indices2[$i]] <= 12) { $desc = "favorable"; } else { $desc = "unfavorable"; } if ($temp ne "calm") { #$temp = sprintf("out of the %s at %s mph", $dir_desc{$row_wind_dir[$init_offset + $i*4]}, $row_wind_spd[$init_offset + $i*4]); $temp = sprintf("out of the %s at %s mph", $dir_desc{$row_wind_dir[$var_indices2[$i]]}, $row_wind_spd[$var_indices2[$i]]); } $temp = "$temp". ", which is "."$desc"." spraying conditions in rain-free areas"; $daywise_desc[$i] = " $daywise_desc[$i]"." $temp"."."; #++$start_index; $hr_id += 4; } #for &print_array(@daywise_desc); return (@daywise_desc); } #sub ## /** Month starts from 0(Jan.) to 11(Dec.) **/ sub get_daywise_ls_stress_desc { my($curr_time, @time_list, @dewpt_arr, @temp_arr, $ls_stress_count, $init_offset, $i, @ls_stress_desc, @row_dewpt, @row_temp); $ls_stress_count = 2; $init_offset = 3; $curr_time = time(); @time_list = localtime($curr_time); for($i = 0; $i < 2; $i++) { $ls_stress_desc[$i] = "UNDEF"; } ## /** Checking for the month if its btw. May(>=5) and August(<=7) **/ if ( ($time_list[4] >= 5) && ($time_list[4] <= 9) ) { #7 if ($start_index == 1) { $init_offset = 7; } #@dewpt_arr = &get_var_array("DEWPT"); #@temp_arr = &get_var_array("TEMP"); @row_dewpt = &get_var_row("DEWPT"); @row_dewpt = split(/\s/, substr($row_dewpt[0], $correct_offset, length($row_dewpt[0]))); @row_dewpt = &get_reformatted_array(@row_dewpt); @row_temp = &get_var_row("DEWPT"); @row_temp = split(/\s/, substr($row_temp[0], $correct_offset, length($row_temp[0]))); @row_temp = &get_reformatted_array(@row_temp); @hrly_block = (15,15,15); @var_indices = &get_var_index_wrt_hrs(0, @hrly_block); $i = 0; while ($i < $ls_stress_count) { $ls_stress_desc[$i] = (0.55*$row_temp[$var_indices[$i]]) + (0.20*$row_dewpt[$var_indices[$i]]) + 17.5; if($ls_stress_desc[$i] > 83.5){ $ls_stress_desc[$i] = uc("emergency"); } elsif($ls_stress_desc[$i] > 78.5 && $ls_stress_desc[$i] < 83.6){ $ls_stress_desc[$i] = uc("danger"); } else{ $ls_stress_desc[$i] = uc("no-stress"); } $ls_stress_desc[$i] = sprintf("Livestock heat stress index will be in the\n%s category at 3 PM.", $ls_stress_desc[$i]); ++$i; } #while } #if #&print_array(@ls_stress_desc); return (@ls_stress_desc); } #sub ## /** Companion subroutine for ls_stress. **/ sub get_ls_stress_hr_day_map { my(%ret_arr, $k); $ret_arr{0} = 0; $ret_arr{2} = 1; if (&get_day_start_index()) { $ret_arr{2} = 0; $ret_arr{4} = 1; } #&print_array(%ret_arr); return (%ret_arr); } ## /** Subroutine to process the number of hours with a particular temperature range **/ sub get_numhrs_with_temp{ my($curr_time, @temp, @hrs_with_temp, $i, @daywise_desc, $temp); $curr_time = time(); @temp = localtime($curr_time); if ($temp[4] >= 6 && $temp[4] <= 9) { ## /** Get the number of hours that are greater than 90 deg. **/ $arg = 0; #90; } else { ## /** Get the number of hours that are greater than 32 deg. **/ $arg = 1; #32; } @hrs_with_temp = &get_num_hrs("TEMP", $arg); #&print_array(@hrs_with_temp); for($i = 0; $i <=3; $i++) { $daywise_desc[$i] = "UNDEF"; if ($hrs_with_temp[$i] != 0) { $daywise_desc[$i] = &get_hr_by_desc($hrs_with_temp[$i]); #&get_hr_by_desc($daywise_desc[$i]); $daywise_desc[$i] = sprintf("There will be %d %s where the temperature will be", $hrs_with_temp[$i], $daywise_desc[$i]); if ($arg == 0) { #90 $daywise_desc[$i] = "$daywise_desc[$i]".sprintf(" equal to or exceed"); } else { $daywise_desc[$i] = "$daywise_desc[$i]".sprintf(" lower than or equal to"); } $daywise_desc[$i] = "$daywise_desc[$i]". sprintf(" %d degrees.", $temp_numhrs_val[$arg], $hrs_with_temp[$i]); } } return (@daywise_desc); } ## sub. ## /** Subroutine to process the number of hours with a particular RH range **/ sub get_numhrs_with_rh { my(@hrs_with_rh_high, @hrs_with_rh_low, @daywise_desc, $i, $rh1, $rh2, $hrs); @hrs_with_rh_high = &get_num_hrs("RH", 0); @hrs_with_rh_low = &get_num_hrs("RH", 1); &print_array(@hrs_with_rh_high); &print_array(@hrs_with_rh_low); for($i = 0; $i <= 3; $i++) { $daywise_desc[$i] = "UNDEF"; $rh1 = sprintf("Relative humidity will be"); $rh2 = sprintf("greater than"); $hrs = &get_hr_by_desc($hrs_with_rh_low[$i]); #if ( $hrs_with_rh_50[$i] != 0) { $daywise_desc[$i] = "$rh1 ".sprintf("less than "); $daywise_desc[$i] = "$daywise_desc[$i]"."$rh_percent_numhrs_val[1]%". sprintf(" for %d %s",$hrs_with_rh_low[$i], $hrs); #} $hrs = &get_hr_by_desc($hrs_with_rh_high[$i]); #if ( $hrs_with_rh_80[$i] != 0) { $rh2 = "$rh2 "."$rh_percent_numhrs_val[0]%".sprintf(" for %d %s",$hrs_with_rh_high[$i], $hrs); if ( $daywise_desc[$i] eq "UNDEF") { $daywise_desc[$i] = "$rh1 ".sprintf("%s", $rh2); } else { $daywise_desc[$i] = "$daywise_desc[$i]".sprintf(" and %s", $rh2); } #} if ( $daywise_desc[$i] ne "UNDEF") { $daywise_desc[$i] = "$daywise_desc[$i]"."."; } } return (@daywise_desc); } sub get_numhrs_with_wdir { ## Pending. my(@interpol_wdir) = @_; @interpol_wdir = &get_vars_hourly("WIND DIR"); } sub get_tobacco_bulking_desc { ## Pending. my(@hrs_tobacco_bulking, @tobacco_bulking_desc, $desc, $hrs, @interpol_rh, $i); @interpol_rh = &get_vars_hourly("RH"); &print_interpol_array(@interpol_rh); ## /** Get the starting_day index depending on whether its Today or Tonight. **/ #$start_index = &get_day_start_index(); for( $i = 0; $i < 4; $i++) { @hrs_tobacco_bulking = &get_num_hrs_for_tobacco($i, @interpol_rh); $hrs = &get_hr_by_desc($hrs_tobacco_bulking[0]); print ("[$i] [F] $hrs_tobacco_bulking[0]:[M] $hrs_tobacco_bulking[1]:[U] $hrs_tobacco_bulking[2] \n"); #tobacco_bulkng_desc[$i] = tobacco_bulkng_desc[$i].sprintf() $desc = sprintf("Tobacco bulking and handling levels %s should have %d %s of favorable conditions", lc($seq[$start_index++]), $hrs_tobacco_bulking[0], $hrs); $hrs = &get_hr_by_desc($hrs_tobacco_bulking[1]); $desc = $desc.sprintf(" , %d %s of marginal conditions", $hrs_tobacco_bulking[1], $hrs); $hrs = &get_hr_by_desc($hrs_tobacco_bulking[2]); $desc = $desc.sprintf(" , %d %s of unfavorable conditions.", $hrs_tobacco_bulking[2], $hrs); $tobacco_bulking_desc[$i] = $desc; } return (@tobacco_bulking_desc); } sub get_num_hrs_for_tobacco { ## Pending. my($itrn, @interpol_var) = @_; my(@ret_hrs, $begin, $end, $i, $j); #&print_array(@interpol_temp); #&print_interpol_array(@interpol_var); $end = 11; $begin = $itrn*($end + 1); # $end = 12; if ( ($itrn == 1) || ($itrn == 2) ) { $end = $end + ($itrn *12); } elsif ($itrn == 3) { $end = 45; } for ($i = 0; $i < 3; $i++) { $ret_hrs[$i] = 0; for($j = $begin; $j <= $end; $j++) { ## /** Checkng for all RHs < 50% OR > 80% **/ if ($i == 0) { if ( $interpol_var[$j] > $rh_percent_numhrs_val[3] ) { ++$ret_hrs[$i]; } } elsif ($i == 1) { if ( ($interpol_var[$j] >= $rh_percent_numhrs_val[2]) && ($interpol_var[$j] < $rh_percent_numhrs_val[3]) ) { ++$ret_hrs[$i]; } } else { if ($interpol_var[$j] < $rh_percent_numhrs_val[2] ) { ++$ret_hrs[$i]; } } } #for-2 } #for-1 return (@ret_hrs); } #Sub ## List of print formats to print the narrative. format COUNTY_DESC =

^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $county_desc

. format TIME_DESC =

^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $update_time

. format DAY_DESC =

^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $var

. format VAR_DESC = ~~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $var
. 1;