/*
**++
**  MODULE DESCRIPTION:
**
**      This module and the accompanying functions are for the dew point
**  calculation.
**
**  AUTHORS:
**
**      Phil Baughn (BASIC version)
**	Rod Falanga (C version)
**
**  CREATION DATE:  24 October 1990
**
**  MODIFICATION HISTORY:
**
**      {@tbs@}...
**--
*/


/*
**
**  INCLUDE FILES
**
*/

#ifdef VMS
#include stdio
#include math
#else
#include <stdio.h>
#include <math.h>
#endif


/*
**
**  MACRO DEFINITIONS
**
*/

#define DUMMY_LEN	50

/*
**++
**  FUNCTIONAL DESCRIPTION:
**
**      This is the main function for the dew point calculation.
**
**--
*/
#ifdef VMS
void dew_point (void)
#else
void dew_point ()
#endif
{
#ifdef VMS
    extern void position (int , int), 
                print (char *), 
                get_date_time (char *, char *), 
                get_string (char *);
#else
    extern void position (), 
                print (), 
                get_date_time (), 
                get_string ();
#endif
    char date [DUMMY_LEN], 
         time [DUMMY_LEN], 
         again [DUMMY_LEN], 
         temperature_str [DUMMY_LEN];
#ifdef VMS
    extern double get_double (void);
#else
    extern double get_double ();
#endif
    double temperature, 
	   relative_humidity, 
	   td, 
	   x;

    /*	 
    **  Like many of the other calculations, this one has a large do() loop
    **	which the User stays in until he/she indicates that they want
    **	to leave.
    */	 
    do
    {
        Erase();

        /*	 
        **  Display the system's date and time.
        */	 
	get_date_time(date, time);
	position (2, 28);
	print ("DEW POINT CALCULATION");
	position (4, 34);
	print (date);
	position (5, 35);
	print (time);

        /*	 
        **  Have the User enter the temperature and relative humidity.
        */	 
	position(7, 12);
	print("ENTER TEMPERATURE IN FAHRENHEIT                    ");
	temperature = get_double();
	position(8, 12);
	print("ENTER THE RELATIVE HUMIDITY (`50' = 50%)           ");
	relative_humidity = get_double();

        /*	 
        **  Now perform the dew point calculation.
        */	 
	temperature = (temperature - 32.) * 5. / 9.;
	x = 1 - (.01 * relative_humidity);
	td = temperature - (14.55 + .114 * temperature) * x - 
	    pow((2.5 + .007 * temperature) * x, 3.0) - 
	    (15.9 + .117 * temperature) * pow(x, 14.0);
	td = (td * 9. / 5.) + 32.;
	position (13, 23);
	print ("TF=(T-32)*5/9:X=1-(.01*DPRH)");
	position (14, 9);
	print ("TD=T-(14.55+.114*T)*X-((2.5+.007*T)*X)^3-(15.9+.117*T)*X^14");
	position (15, 30);
	print ("TD=(TD*9/5)+32");
	position (19, 21);
	print ("DEW POINT CALCULATION = "); 
        sprintf (temperature_str, "%.1f", td);
	print(temperature_str);

        /*	 
        **  Ask the User if they want to do another dew point calculation.
        */	 
	position(24, 20);
	print("CALCULATE ANOTHER DEW POINT (Y/N)");
	get_string(again);
    } while (again[0]=='Y' || again[0]=='y');
}   /* end of dew_point() */
