/***************************************************************************/
/***************************************************************************/
/**                                                                       **/
/**                         RF Safety Calculator                          **/
/**                         ----============----                          **/
/**                                                                       **/
/**  Kenneth E. Harker WM5R                          22 September 2003    **/
/**                                                                       **/
/**  The following public domain C program was written using the cgic     **/
/**  library. This program has been derived directly from a public domain **/
/**  BASIC program written and published by Wayne Overbeck N6NB in the    **/
/**  January, 1997 issue of _CQ VHF_, p. 33.                              **/
/**                                                                       **/
/**  Updated on 1 Septemer 1997 to reflect changes made by the FCC in its **/
/**    August 27, 1997 Second Memorandum and Order.                       **/
/**                                                                       **/
/**  Updated on 29 January 1998 to fix minor presentation bugs.           **/ 
/**                                                                       **/
/**  Updated on 13 March 1998 to fix disclaimer.                          **/ 
/**                                                                       **/
/**  Updated on 25 September 1998 to handle move to n5xu.ae.utexas.edu.   **/ 
/**                                                                       **/
/**  Updated on 25 January 2000 to make 0 watts or 0 distance invalid     **/
/**    entries, added real-looking squared units using <SUP></SUP> tags,  **/
/**    and changed results display a little.                              **/
/**                                                                       **/
/**  Updated on 22 September 2003 to match new page style and design.     **/
/**                                                                       **/
/***************************************************************************/
/***************************************************************************/


#include <stdio.h>
#include <stdlib.h>
#include "cgic.h"
#include "math.h"


/***************************************************************************/
/***************************************************************************/
/**                                                                       **/
/**                          Function Prototypes                          **/
/**                                                                       **/
/***************************************************************************/
/***************************************************************************/


double  get_watts();
double  get_gain();
double  get_distance();
double  get_frequency();
int     get_ground();


/***************************************************************************/
/***************************************************************************/
/**                                                                       **/
/**                             Main Function                             **/
/**                                                                       **/
/***************************************************************************/
/***************************************************************************/


int cgiMain() {

  double  watts;      /**  User-supplied average power level        **/
  double  gain;       /**  User-supplied antenna gain in dBi        **/
  double  distance;   /**  User-supplied distance to affected area  **/
  double  frequency;  /**  User-supplied frequency of operation     **/
  double  ground;     /**  Should ground reflections be included?   **/
  double  power;      /**  Power in kilowatts                       **/
  double  eirp;       /**  Effective radiated power                 **/
  double  dx;         /**  Distance in centimeters                  **/
  double  std1;       /**  Internal calculation                     **/
  double  std2;       /**  Internal calculation                     **/
  double  dx1;        /**  Internal calculation                     **/
  double  dx2;        /**  Internal calculation                     **/
  double  gf;         /**  Ground factor                            **/
  double  pwrdens;    /**  Power density                            **/
  int     toohigh;    /**  Frequency chosen is too high             **/


  toohigh = 0;
  cgiHeaderContentType("text/html");
  fprintf(cgiOut, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\n");
  fprintf(cgiOut, "<!-- ===================================================================== -->\n");
  fprintf(cgiOut, "<!--                                                                       -->\n");
  fprintf(cgiOut, "<!--  Copyright (c) 1996-2003 University of Texas Amateur Radio Club       -->\n");
  fprintf(cgiOut, "<!--                                                                       -->\n");
  fprintf(cgiOut, "<!--  Permission to make digital/hard copy of part or all of this work     -->\n");
  fprintf(cgiOut, "<!--  for personal or classroom use is granted without fee provided that   -->\n");
  fprintf(cgiOut, "<!--  copies are not made or distributed for profit or commercial          -->\n");
  fprintf(cgiOut, "<!--  advantage, the copyright notice and its date appear, and notice is   -->\n");
  fprintf(cgiOut, "<!--  given that copying is by permission of the University of Texas       -->\n");
  fprintf(cgiOut, "<!--  Amateur Radio Club.  To copy otherwise, to republish, to post on     -->\n");
  fprintf(cgiOut, "<!--  servers, or to redistribute to lists requires prior specific         -->\n");
  fprintf(cgiOut, "<!--  permission and/or a fee.                                             -->\n");
  fprintf(cgiOut, "<!--                                                                       -->\n");
  fprintf(cgiOut, "<!--  Please contact wm5r@wm5r.org for information concerning the          -->\n");
  fprintf(cgiOut, "<!--  intellectual property in this document.                              -->\n");
  fprintf(cgiOut, "<!--                                                                       -->\n");
  fprintf(cgiOut, "<!-- ===================================================================== -->\n");
  fprintf(cgiOut, "<HTML><HEAD>\n");
  fprintf(cgiOut, "  <META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=iso-8859-1\">\n");
  fprintf(cgiOut, "  <META NAME=\"keywords\" CONTENT=\"UTARC, N5XU, W5EHM, W5NLH, W5JGC, 5XU, \n");
  fprintf(cgiOut, "    University of Texas Amateur Radio Club, Amateur Radio, ham radio, \n");
  fprintf(cgiOut, "    contesting, DXing, university club, registered student organization, \n");
  fprintf(cgiOut, "    Texas radio, Texas, ARRL, Austin, WRW, station, Sweepstakes, N2000XU, \n");
  fprintf(cgiOut, "    K5T, HF, VHF, Meteor Scatter, EME, MSCW, Satellites, newsletter, manual,\n");
  fprintf(cgiOut, "    meetings, history, photos, awards, Amateur Radio RF Safety Calculator, \n");
  fprintf(cgiOut, "    RF Safety, RF Calculator, RF Safety Calculator, frequency, bands, license,\n");
  fprintf(cgiOut, "    ticket, radio frequency, RF\">\n");
  fprintf(cgiOut, "  <META NAME=\"description\" CONTENT=\"University of Texas Amateur Radio Club\">\n");
  fprintf(cgiOut, "  <META NAME=\"MSSmartTagsPreventParsing\" CONTENT=\"TRUE\">\n");
  fprintf(cgiOut, "  <LINK REL=\"SHORTCUT ICON\" HREF=\"http://n5xu.ae.utexas.edu/favicon.ico\">\n");
  fprintf(cgiOut, "\n");
  fprintf(cgiOut, "<TITLE>Amateur Radio RF Safety Calculator</TITLE>\n");
  fprintf(cgiOut, "</HEAD><BODY BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\">\n");
  fprintf(cgiOut, "<CENTER>\n");
  fprintf(cgiOut, "<TABLE WIDTH=800><TR><TD WIDTH=800>\n");
  fprintf(cgiOut, "<CENTER>\n");
  fprintf(cgiOut, "<TABLE>\n");
  fprintf(cgiOut, "  <TR>\n");
  fprintf(cgiOut, "   <TD><H1>Amateur Radio RF Safety Calculator</H1></TD>\n");
  fprintf(cgiOut, "  </TR>\n");
  fprintf(cgiOut, "</TABLE>\n");
  fprintf(cgiOut, "</CENTER>\n");
  fprintf(cgiOut, "\n");
  fprintf(cgiOut, "<CENTER>\n");
  fprintf(cgiOut, "<IMG ALT=\"\" SRC=\"http://n5xu.ae.utexas.edu/icons/utbanner.gif\" WIDTH=800 HEIGHT=3><BR>\n");
  fprintf(cgiOut, "</CENTER>\n");
  fprintf(cgiOut, "\n");

  watts     = get_watts();      
  gain      = get_gain();       
  distance  = get_distance();   
  frequency = get_frequency();  
  ground    = get_ground();     

  if ((watts <= 0) || (gain < 0) || (distance < 0) || (frequency <= 0)) {
    fprintf(cgiOut, "<CENTER>\n");
    fprintf(cgiOut, "<H2>Calculation Results</H2>\n");
    fprintf(cgiOut, "</CENTER>\n");
    fprintf(cgiOut, "<P>There are no results because you either did not ");
    fprintf(cgiOut, "enter required information or you did not enter ");
    fprintf(cgiOut, "valid information.  If you are still interested in ");
    fprintf(cgiOut, "calculating your station's compliance with the FCC RF ");
    fprintf(cgiOut, "safety regulations, please ");
    fprintf(cgiOut, "<A HREF=\"http://n5xu.ae.utexas.edu/rfsafety/\">try ");
    fprintf(cgiOut, "again</A> and enter only number values.</P>\n");
  } else {  /**  Success!!  **/

    power = 1000.0 * watts;
    eirp  = power * pow(10,(gain/10.0));
    dx    = distance * 30.48;
 
    if (frequency < 1.34) {
      std1 = 100.0; std2 = 100.0;
    }  /**  Below 1.34 MHz  **/
    else if (frequency < 3.0) {
      std1 = 100.0; std2 = 180.0 / (pow(frequency,2));
    }  /**  Below 3.0 MHz  **/
    else if (frequency < 30.0) {
      std1 = 900.0 / pow(frequency,2); std2 = 180.0 / (pow(frequency,2));
    }  /**  Below 30 MHz  **/
    else if (frequency < 300.0) {
      std1 = 1.0; std2 = 0.2;
    }  /**  Below 300 MHz  **/
    else if (frequency < 1500.0) {
      std1 = frequency / 300.0; std2 = frequency / 1500.0;
    }  /**  Below 1500 MHz  **/
    else if (frequency < 100000.0) {
      std1 = 5.0; std2 = 1.0;
    }  /**  Below 100 GHz  **/
    else {  /**  Frequency too high  **/
      fprintf(cgiOut, "<CENTER>\n");
      fprintf(cgiOut, "<H2>Calculation Results</H2>\n");
      fprintf(cgiOut, "</CENTER>\n");
      fprintf(cgiOut, "<P>The FCC does not have exposure limits above 100 ");
      fprintf(cgiOut, "GHz. If you are still interested in calculating ");
      fprintf(cgiOut, "your station's compliance with the FCC RF safety ");
      fprintf(cgiOut, "regulations, please ");
      fprintf(cgiOut, "<A HREF=\"http://n5xu.ae.utexas.edu/rfsafety/\">try ");
      fprintf(cgiOut, "again</A> and enter only number values.</P>\n");  
      toohigh = 1;
    }  /**  Frequency too high  **/
    if (toohigh == 0) {  /**  In normal range  **/

      if (ground == 0)
        gf = 0.64;
      else
        gf = 0.25;
      pwrdens = (gf * eirp) / (3.14159 * pow(dx,2));
      pwrdens = ((pwrdens*10000) + 0.5) / 10000;
      dx1 = sqrt((gf * eirp)/(std1 * 3.14159));
      dx1 = dx1/30.48;
      dx1 = ((dx1 * 10) + 0.5) / 10;
      dx2 = sqrt((gf * eirp)/(std2 * 3.14159));
      dx2 = dx2/30.48;
      dx2 = ((dx2 * 10) + 0.5) / 10;
      std1 = (((std1 * 100) + 0.5) / 100);
      std2 = (((std2 * 100) + 0.5) / 100);
      
      fprintf(cgiOut, "<CENTER>\n");
      fprintf(cgiOut, "<TABLE BORDER=0 WIDTH=750><TR><TD>\n");
      fprintf(cgiOut, "<TABLE BORDER=0 ALIGN=LEFT CELLSPACING=10><TR><TD ALIGN=CENTER>\n");
      fprintf(cgiOut, "<FONT SIZE=5><STRONG>Calculation ");
      fprintf(cgiOut, "Results</STRONG></FONT>\n");
      fprintf(cgiOut, "<P></P>\n");
      fprintf(cgiOut, "<TABLE BORDER=1 WIDTH=380>\n");
      fprintf(cgiOut, "  <TR>\n");
      fprintf(cgiOut, "    <TD ALIGN=CENTER><B><FONT SIZE=2>Average Power at the ");
      fprintf(cgiOut, "Antenna</FONT></B></TD>\n");
      fprintf(cgiOut, "    <TD ALIGN=CENTER>%.3f watts</TD>\n",watts);
      fprintf(cgiOut, "  </TR>\n");
      fprintf(cgiOut, "  <TR>\n");
      fprintf(cgiOut, "    <TD ALIGN=CENTER><B><FONT SIZE=2>Antenna Gain in ");
      fprintf(cgiOut, "dBi</FONT></B></TD>\n");
      fprintf(cgiOut, "    <TD ALIGN=CENTER>%.2f dBi</TD>\n",gain);
      fprintf(cgiOut, "  </TR>\n");
      fprintf(cgiOut, "  <TR>\n");
      fprintf(cgiOut, "    <TD ALIGN=CENTER><B><FONT SIZE=2>Distance to the ");
      fprintf(cgiOut, "Area of Interest</FONT></B></TD>\n");
      fprintf(cgiOut, "    <TD ALIGN=CENTER>%.2f feet</TD>\n",distance);
      fprintf(cgiOut, "  </TR>\n");
      fprintf(cgiOut, "  <TR>\n");
      fprintf(cgiOut, "    <TD ALIGN=CENTER><B><FONT SIZE=2>Frequency of ");
      fprintf(cgiOut, "Operation</FONT></B></TD>\n");
      fprintf(cgiOut, "    <TD ALIGN=CENTER>%.3f MHz</TD>\n",frequency);
      fprintf(cgiOut, "  </TR>\n");
      fprintf(cgiOut, "  <TR>\n");
      fprintf(cgiOut, "    <TD ALIGN=CENTER><B><FONT SIZE=2>Are Ground ");
      fprintf(cgiOut, "Reflections Calculated?</FONT></B></TD>\n");
      if (ground == 0)
        fprintf(cgiOut, "    <TD ALIGN=CENTER>Yes</TD>\n");
      else
        fprintf(cgiOut, "    <TD ALIGN=CENTER>No</TD>\n");
      fprintf(cgiOut, "  </TR>\n");
      fprintf(cgiOut, "  <TR>\n");
      fprintf(cgiOut, "    <TD ALIGN=CENTER><B><FONT SIZE=2>Estimated RF Power ");
      fprintf(cgiOut, "Density</FONT></B></TD>\n");
      fprintf(cgiOut, "    <TD ALIGN=CENTER>%.4f mw/cm<SUP><FONT SIZE=1>2</FONT></SUP></TD>\n",pwrdens);
      fprintf(cgiOut, "  </TR>\n");
      fprintf(cgiOut, "</TABLE>\n");
      fprintf(cgiOut, "</CENTER>\n");
      fprintf(cgiOut, "</TD></TR><TR><TD>\n");


      fprintf(cgiOut, "<CENTER>\n");
      fprintf(cgiOut, "<TABLE BORDER=1 WIDTH=380>\n");
      fprintf(cgiOut, "  <TR>\n");
      fprintf(cgiOut, "    <TH>&nbsp;</TH>\n");
      fprintf(cgiOut, "    <TH>Controlled<BR>Environment</TH>\n");
      fprintf(cgiOut, "    <TH>Uncontrolled<BR>Environment</TH>\n");
      fprintf(cgiOut, "  </TR>\n");
      fprintf(cgiOut, "  <TR>\n");
      fprintf(cgiOut, "    <TD><CENTER><FONT SIZE=2><B>Maximum ");
      fprintf(cgiOut, "Permissible Exposure ");
      fprintf(cgiOut, "      (MPE)</B></FONT></CENTER></TD>\n");
      fprintf(cgiOut, "    <TD><CENTER>%.2f mw/cm<SUP><FONT SIZE=1>2</FONT></SUP></CENTER></TD>\n",std1);
      fprintf(cgiOut, "    <TD><CENTER>%.2f mw/cm<SUP><FONT SIZE=1>2</FONT></SUP></CENTER></TD>\n",std2);
      fprintf(cgiOut, "  </TR>\n");
      fprintf(cgiOut, "  <TR>\n");
      fprintf(cgiOut, "    <TD><CENTER><B><FONT SIZE=2>Distance to ");
      fprintf(cgiOut, "Compliance");
      fprintf(cgiOut, " From Center of Antenna</B></FONT></CENTER></TD>\n");
      fprintf(cgiOut, "    <TD><CENTER>%.2f feet</CENTER></TD>\n",dx1);
      fprintf(cgiOut, "    <TD><CENTER>%.2f feet</CENTER></TD>\n",dx2);
      fprintf(cgiOut, "  </TR>\n");
      fprintf(cgiOut, "  <TR>\n");
      fprintf(cgiOut, "    <TD><CENTER><B><FONT SIZE=2>Does the Area of ");
      fprintf(cgiOut, "Interest Appear to be in Compliance?");
      fprintf(cgiOut, "</B></FONT></CENTER></TD>\n");
      /*
      if (distance > dx1)
        fprintf(cgiOut, "    <TD><CENTER>yes</CENTER></TD>\n");
      else
        fprintf(cgiOut, "    <TD><CENTER>no</CENTER></TD>\n");
      if (distance > dx2)
        fprintf(cgiOut, "    <TD><CENTER>yes</CENTER></TD>\n");
      else
        fprintf(cgiOut, "    <TD><CENTER>no</CENTER></TD>\n");
      */
      if (pwrdens < std1)
        fprintf(cgiOut, "    <TD><CENTER>yes</CENTER></TD>\n");
      else
        fprintf(cgiOut, "    <TD><CENTER>no</CENTER></TD>\n");
      if (pwrdens < std2)
        fprintf(cgiOut, "    <TD><CENTER>yes</CENTER></TD>\n");
      else
        fprintf(cgiOut, "    <TD><CENTER>no</CENTER></TD>\n");
      fprintf(cgiOut, "  </TR>\n");
      fprintf(cgiOut, "</TABLE>\n");
      fprintf(cgiOut, "</TD></TR></TABLE>\n");
      fprintf(cgiOut, "</CENTER>\n");

      fprintf(cgiOut, "<CENTER>\n");
      fprintf(cgiOut, "<P></P>\n");
      fprintf(cgiOut, "&nbsp;<BR><FONT SIZE=5><STRONG>Interpretation of Results");
      fprintf(cgiOut, "</STRONG></FONT></CENTER>\n");
      fprintf(cgiOut, "<OL>");
      fprintf(cgiOut, "  <LI><P><FONT SIZE=2>Remember that the power value ");
      fprintf(cgiOut, "      entered into ");
      fprintf(cgiOut, "      these calculations should be the <A ");
      fprintf(cgiOut, "      HREF=\"http://n5xu.ae.utexas.edu/rfsafety/power.shtml\">average power</A> ");
      fprintf(cgiOut, "      seen at the antenna, and not Peak Envelope ");
      fprintf(cgiOut, "      Power (PEP).  You may also consider feedline ");
      fprintf(cgiOut, "      loss in calculating your average power at");
      fprintf(cgiOut, "      the antenna.");
      fprintf(cgiOut, "   </FONT></P></LI>");

      fprintf(cgiOut, "   <LI><P><FONT SIZE=2>If you wish to estimate the ");
      fprintf(cgiOut, "      power density ");
      fprintf(cgiOut, "      at a point below the main lobe of a directional");
      fprintf(cgiOut, "      antenna, and if the antenna's vertical pattern ");
      fprintf(cgiOut, "      is known, recalculate using the antenna's gain ");
      fprintf(cgiOut, "      in the relevant direction.");
      fprintf(cgiOut, "   </FONT></P></LI>");

      fprintf(cgiOut, "  <LI><P><FONT SIZE=2>Please also consult <A HREF=\"http://www.fcc.gov/Bureaus/Engineering_Technology/Documents/bulletins/oet65/oet65b.pdf\">FCC OET Bulletin 65 Supplement B</A>, ");
      fprintf(cgiOut, "      the Amateur Radio supplement to FCC OET ");
      fprintf(cgiOut, "      Bulletin 65.  It contains a thorough ");
      fprintf(cgiOut, "      discussion of the RF Safety regulations as ");
      fprintf(cgiOut, "      they apply to amateur stations and contains ");
      fprintf(cgiOut, "      numerous charts, tables, worksheets, and other ");
      fprintf(cgiOut, "      data to help determine station compliance. ");
      fprintf(cgiOut, "   </FONT></P></LI>");

      fprintf(cgiOut, "</OL>");
      fprintf(cgiOut, "<P></P>\n");
      fprintf(cgiOut, "<CENTER>\n");
      fprintf(cgiOut, "<FONT SIZE=5><STRONG><A HREF=\"http://n5xu.ae.utexas.edu/rfsafety/\">Perform another computation</A></STRONG></FONT>");
      fprintf(cgiOut, "</TD></TR><TR><TD>&nbsp;</TD></TR></TABLE>\n");
      fprintf(cgiOut, "</CENTER>\n");
      
    }  /**  In normal range  **/
  }  /**  Success!!  **/
  
  fprintf(cgiOut, "<CENTER>\n");
  fprintf(cgiOut, "<IMG ALT=\"\" SRC=\"http://n5xu.ae.utexas.edu/icons/utbanner.gif\" WIDTH=800 HEIGHT=3><BR>\n");
  fprintf(cgiOut, "</CENTER>\n");
  
  fprintf(cgiOut, "<P><FONT SIZE=2>\n");
  fprintf(cgiOut, "<B>No Warranties:</B>  This information is provided\n");
  fprintf(cgiOut, "\"as is\" without any warranty, condition, or\n");
  fprintf(cgiOut, "representation of any kind, either express or implied,\n");
  fprintf(cgiOut, "including but not limited to, any warranty respecting\n");
  fprintf(cgiOut, "non-infringement, and the implied warranties of\n");
  fprintf(cgiOut, "conditions of merchantability and fitness for a\n");
  fprintf(cgiOut, "particular purpose. In no event shall Kenneth E.\n");
  fprintf(cgiOut, "Harker, the University of Texas Amateur Radio Club,\n");
  fprintf(cgiOut, "the University of Texas at Austin, or any directors,\n");
  fprintf(cgiOut, "trustees, or members thereof be liable for any direct,\n");
  fprintf(cgiOut, "indirect, special, incidental, consequential or other\n");
  fprintf(cgiOut, "damages howsoever caused whether arising in contract,\n");
  fprintf(cgiOut, "tort, or otherwise, arising out of or in connection\n");
  fprintf(cgiOut, "with the use or performance of the information\n");
  fprintf(cgiOut, "contained on this web site.\n");
  fprintf(cgiOut, "</FONT></P>\n");
  
  fprintf(cgiOut, "<CENTER>\n");
  fprintf(cgiOut, "<IMG ALT=\"\" SRC=\"http://n5xu.ae.utexas.edu/icons/utbanner.gif\" WIDTH=800 HEIGHT=3><BR>\n");
  fprintf(cgiOut, "</CENTER>\n");
  fprintf(cgiOut, "<P></P>\n");
  
  fprintf(cgiOut, "<ADDRESS>\n");
  fprintf(cgiOut, "University of Texas Amateur Radio Club N5XU<BR>\n");
  fprintf(cgiOut, "Send comments to: <STRONG>");
  fprintf(cgiOut, "<A HREF=\"mailto:kharker@cs.utexas.edu\">");
  fprintf(cgiOut, "kharker@cs.utexas.edu</A></STRONG><BR>");
  fprintf(cgiOut, "CGI script last modified: 22 September 2003<BR>\n");
  fprintf(cgiOut, "</ADDRESS><BR>\n");
  
  fprintf(cgiOut, "</TD></TR></TABLE>\n");
  fprintf(cgiOut, "</CENTER>\n");
  
  fprintf(cgiOut, "</BODY></HTML>\n");
  
  return 0;
  
}  /**  End of main  **/


/***************************************************************************/
/***************************************************************************/
/**                                                                       **/
/**                            Function Get_Watts                         **/
/**                                                                       **/
/**  Returns:                                                             **/
/**    The value of watts that the user supplies                          **/
/**    -1 on improper or no entry                                         **/
/**                                                                       **/
/***************************************************************************/
/***************************************************************************/


double get_watts() {

  double             watts_input;  /**  Watts input  **/
  cgiFormResultType  result;       /**  Form result  **/

  result = cgiFormDoubleBounded("watts", &watts_input, 0.0,150000.0, -1.0);
  if (result != cgiFormEmpty)
    if (result < 0)
      return(-1);
    else
      return(watts_input);
  else
    return(-1);

}  /**  End of get_watts  **/
	

/***************************************************************************/
/***************************************************************************/
/**                                                                       **/
/**                            Function Get_Gain                          **/
/**                                                                       **/
/**  Returns:                                                             **/
/**    The value of gain over dBi that the user supplies                  **/
/**    -1 on improper or no entry                                         **/
/**                                                                       **/
/***************************************************************************/
/***************************************************************************/


double get_gain() {

  double             gain_input;  /**  Gain input   **/
  cgiFormResultType  result;      /**  Form result  **/

  result = cgiFormDoubleBounded("gain", &gain_input, 0.0,1000.0,-1.0);
  if (result != cgiFormEmpty)
    if (result < 0)
      return(-1);
    else
      return(gain_input);
  else
    return(-1);

}  /**  End of get_gain  **/
	

/***************************************************************************/
/***************************************************************************/
/**                                                                       **/
/**                          Function Get_Distance                        **/
/**                                                                       **/
/**  Returns:                                                             **/
/**    The value of distance that the user supplies                       **/
/**    -1 on improper or no entry                                         **/
/**                                                                       **/
/***************************************************************************/
/***************************************************************************/


double get_distance() {

  double             distance_input;  /**  Distance input  **/
  cgiFormResultType  result;          /**  Form result     **/

  result = cgiFormDoubleBounded("feet", &distance_input, 0.0,100000.0,-1.0);
  if (result != cgiFormEmpty)
    if (result < 0)
      return(-1);
    else
      return(distance_input);
  else
    return(-1);

}  /**  End of get_distance  **/
	

/***************************************************************************/
/***************************************************************************/
/**                                                                       **/
/**                            Function Get_Frequency                     **/
/**                                                                       **/
/**  Returns:                                                             **/
/**    The value of frequency that the user supplies                      **/
/**    -1 on improper or no entry                                         **/
/**                                                                       **/
/***************************************************************************/
/***************************************************************************/


double get_frequency() {

  double             frequency_input;  /**  Frequency input  **/
  cgiFormResultType  result;           /**  Form result      **/

  result = cgiFormDoubleBounded("freq", &frequency_input, 0.0, 500000.0, -1.0);
  if (result != cgiFormEmpty)
    if (result < 0)
      return(-1);
    else
      return(frequency_input);
  else
    return(-1);

}  /**  End of get_frequency  **/
	

/***************************************************************************/
/***************************************************************************/
/**                                                                       **/
/**                            Function Get_Ground                        **/
/**                                                                       **/
/**  Returns:                                                             **/
/**    1  if YES                                                          **/
/**    0  if NO                                                           **/
/**                                                                       **/
/***************************************************************************/
/***************************************************************************/


int get_ground() {

  char *ground_choices[] = {  /**  Ground Choices  **/
    "1",
    "2"
  };  /**  Ground Choices  **/
  int  ground_input;  /**  0 or 1  **/

  cgiFormRadio("ground", ground_choices, 2, &ground_input, 0);
  return (ground_input);

}  /**  End of get_ground  **/
	

/***************************************************************************/
/***************************************************************************/
/**                                                                       **/
/**                           End of rfsafety.c                           **/
/**                                                                       **/
/***************************************************************************/
/***************************************************************************/
















