#!/usr/local/bin/perl # perl script for H.A.P. Calulations use CGI::Carp qw(fatalsToBrowser); #comment out this line when your done debugging this script $|++; #dont't buffer output #use strict; # file name:: hap.cgi # Created on Sunday, July 15, 2007 by Sim Ayers of SBE Builders # get latest version of this script at http://www.sbebuilders.com ################################################### # You are free to customize this script as you wish. # DISCLAIMER # The information and code provided is provided 'as is' without # warranty of any kind, either express or implied. In no event # shall the Company SBE Builders be liable for any damages whatsoever # including direct, indirect, incidental, consequential, loss of # business profits or special damages, even if the author has been # advised of the possibility of such damages. # DO NOT USE THIS SCRIPT UNLESS YOU CAN FULLY AGREE WITH THIS # DISCLAIMER. # copyright(C) 2007 ################################################### my ($content_type_printed,%data,$back_wall,$projection,$face_wall,$pitch,$show_feet_inches); # print out perl headers to browser print "Content-type: text/plain\n\n" unless $content_type_printed++; &read_input(); #read user input variables if ($data{'major_pitch'} eq ""){ # hand edit variables below for default values $major_pitch = 10; $major_rafter_seatcut = 5.5; $major_rafter_depth = 11.5; $show_feet_inches = 'no'; } else{ $major_pitch = $data{'major_pitch'}; $major_pitch_angle = $data{'major_pitch_angle'}; $major_rafter_depth = $data{'major_rafter_depth'}; $major_rafter_seatcut = $data{'major_rafter_seatcut'}; $show_feet_inches = $data{'show_feet_inches'}; } #Global symbols # http://perldoc.perl.org/Math/Complex.html use Math::Complex qw(:trig); use POSIX qw(ceil floor); $PIE = 3.14159265358979323846; $RAD_TO_DEGREE = (180/pi); $DEGREE_TO_RAD = ($PIE/180); $major_pitch_D4_test = "failed"; $major_pitch_D3_test = "failed"; #Plan Angle Calculation $Eave_Angle = $roof_eave_angle * $DEGREE_TO_RAD; if($major_pitch_angle > 0.0){ $tan_Major_Pitch_Angle = tan($major_pitch_angle * $DEGREE_TO_RAD); $major_pitch = (tan($major_pitch_angle * $DEGREE_TO_RAD) ) * 12; } else{ $tan_Major_Pitch_Angle = ($major_pitch /12); $major_pitch_angle = atan($tan_Major_Pitch_Angle) * $RAD_TO_DEGREE; } $cos_Major_Pitch_Angle = cos(atan($tan_Major_Pitch_Angle)); $sin_Major_Pitch_Angle = sin(atan($tan_Major_Pitch_Angle)); $major_pitch_plumb_height = $major_rafter_depth / $cos_Major_Pitch_Angle; $major_pitch_HBP = $major_rafter_seatcut * $tan_Major_Pitch_Angle; $major_pitch_HAP = $major_pitch_plumb_height - $major_pitch_HBP; $major_pitch_D4 = $major_pitch_plumb_height /4; $major_pitch_D3 = $major_pitch_plumb_height /3; $major_pitch_D3_test = "passed" if(($major_pitch_D3 * 2) <= $major_pitch_HAP); $major_pitch_D4_test = "passed" if(($major_pitch_D4 * 3) <= $major_pitch_HAP); print "\n\n\nH.A.P Rafter Calculations (Height Above Plate)"; print "\n\n"; print "\n\nMajor Pitch = " .roundAngle_5($major_pitch); print "\n\nMajor Pitch Angle = " .roundAngle_5($major_pitch_angle); print "\n\n"; print "\n\nMajor Pitch Rafter Seatcut = " .roundAngle_5($major_rafter_seatcut); print "\n\nMajor Pitch Rafter Material Depth = " .roundAngle_5($major_rafter_depth); print "\n\n"; print "\n\nMajor Pitch D/4 Calculation Test = " .$major_pitch_D4_test; print "\n\nMajor Pitch 1/3 Rule Calculation Test = " .$major_pitch_D3_test; print "\n\n"; print "\n\nMajor Pitch With a $major_rafter_seatcut seat cut length = " .roundAngle_5($major_pitch_HAP) ." H.A.P."; print "\n\nMajor Pitch With a $major_rafter_seatcut seat cut length = " .roundAngle_5($major_pitch_HBP) ." H.B.P."; print "\n\nMajor Pitch Plumb Height For $major_rafter_depth material = " .roundAngle_5($major_pitch_plumb_height); print "\n\n"; print "\n\nMajor Pitch D/4 Calculation For $major_rafter_depth material = " .roundAngle_5($major_pitch_D4); print "\n\nMajor Pitch D/4 Structural Code Bearing Height For $major_rafter_depth material = " .roundAngle_5($major_pitch_D4*3); print "\n\n"; print "\n\nMajor Pitch D/3 1/3 Rule Calculation For $major_rafter_depth material = " .roundAngle_5($major_pitch_D3); print "\n\nMajor Pitch D/3 1/3 Rule Structural Code Bearing Height For $major_rafter_depth material = " .roundAngle_5($major_pitch_D3*2); print "\n\n"; exit; ################################### # library sub routines follow ################################### #=============================================================================# sub hypot{ my ($x,$y) = @_; my $s = sqrt( $x* $x + $y * $y); return $s; } #=============================================================================# sub convertTOfeet{ my ($decimal) = @_; return $decimal unless $show_feet_inches eq 'yes'; #print "\n inches decimal = " .$decimal; my $wholefeet = floor($decimal/12); my $wholeinch = floor($decimal - ($wholefeet*12)); my $decimalfrac = ($decimal*1) - floor($decimal); my ($frac1,$frac2,$frac_str); $frac2 = 16; if ($decimalfrac >= 0.9774) # 15/16 = 0.9375 { $wholeinch++; $decimalfrac = 0.00; if($wholeinch == 12) { $wholefeet++; $wholeinch = 0; } } if ($decimalfrac > 0.0001) { $frac1 = $decimalfrac * $frac2; my $wholefrac = floor($decimalfrac * $frac2); $frac1 = ceil($decimalfrac * $frac2); $frac1 = 15 if($frac1 == 16); ($frac1,$frac2) = check_frac($frac1,$frac2); $frac_str = sprintf(" %d/%d",$frac1,$frac2); } my $str = sprintf("%d'-%d%s''", $wholefeet,$wholeinch,$frac_str); return $str; } #=============================================================================# sub check_frac{ my ($numerator ,$denominator) = @_; return (7,8) if $numerator eq 14; return (3,4) if $numerator eq 12; return (5,8) if $numerator eq 10; return (1,2) if $numerator eq 8; return (3,8) if $numerator eq 6; return (1,4) if $numerator eq 4; return (1,8) if $numerator eq 2; return ("","") if $numerator eq 0; return ("","") if $denominator eq 0; return ($numerator ,$denominator); } #=============================================================================# sub roundAngle{ my ($angle) = @_; my $str = sprintf("%.5f",$angle); return $str; } #=============================================================================# sub roundAngle_5{ my ($angle) = @_; my $str = sprintf("%.5f",$angle); return $str; } #=============================================================================# sub convertTOpitch{ my ($decimal) = @_; my $wholefeet = floor($decimal/12); my $wholeinch = floor($decimal - ($wholefeet*12)); my $decimalfrac = ($decimal*1) - floor($decimal); my ($frac1,$frac2,$frac_str); $frac2 = 16; if ($decimalfrac >= 0.9774) # 15/16 = 0.9375 { $wholeinch++; $decimalfrac = 0.00; if($wholeinch == 12) { $wholefeet++; $wholeinch = 0; } } if ($decimalfrac > 0.0001) { $frac1 = $decimalfrac * $frac2; my $wholefrac = floor($decimalfrac * $frac2); $frac1 = ceil($decimalfrac * $frac2); $frac1 = 15 if($frac1 == 16); ($frac1,$frac2) = check_frac($frac1,$frac2); $frac_str = sprintf(" %d/%d",$frac1,$frac2); } my $str = sprintf("%d%s", $wholeinch,$frac_str); return $str; } #===================================================================# sub read_input { my($buffer) = undef; my ($item); if ($ENV{'REQUEST_METHOD'} eq 'POST') { read(STDIN,$buffer,$ENV{'CONTENT_LENGTH'}); } else { $buffer=$ENV{'QUERY_STRING'}; } $buffer = $ARGV[0] if (not $buffer); my @pairs=split(/&/,$buffer); foreach $item(@pairs) { my ($key,$content)=split (/=/,$item,2); # Split into key and value. $content =~ tr/+/ /; # Convert plus's to spaces $content =~ s/%(..)/pack("c",hex($1))/ge; # Convert %XX from hex numbers to alphanumeric $content =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; # prevent hackers from exploiting the input name $key =~ tr/+/ /; # Convert plus's to spaces $key =~ s/%(..)/pack("c",hex($1))/ge; # Convert %XX from hex numbers to alphanumeric $key =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $key =~ s/ /_/g; # get rid of attempts to insert HTML tags $content =~ s///g; # server-side-includes $content =~ s/<([^>]|\n)*>//gs; $content =~ s//>/g; # get rid of attempts to insert illegal characters $content =~ s/\\//g; # remove black slashes $content =~ s/\0//g; # remove nulls $content =~ s/[\\\&\;\`\'\"\|\*\?\~\^\[\]\{\}\$]//gs; $content =~ s/\cM/\n/g; #convert CR to LF $content =~ s/^\s+|\s+$//gs; $content = substr($content,0,4096); $data{$key} = $content; } return 1; }