/*
**++
**  MODULE DESCRIPTION:
**
**      This is the wind chill calculating module and related functions.
**
**  AUTHORS:
**
**      Phil Baughn (BASIC version)
**	Rod Falanga (C version)
**
**  CREATION DATE:  18 October 1990
**
**  DESIGN ISSUES:
**
**      A. This module will also be dominated by a large do loop, which will
**	   remain in effect so long as the User responses to the question
**	   about wanting to do more wind chill calculations in the affirmative.
**	B. Within the do loop, the first thing done is the screen is cleared
**	   and this module's name is given with the system's current date
**	   and time.
**	C. The temperature is entered by the User.
**	D. The wind speed is entered by the User.
**	E. Calculations are then performed and the wind chill is displayed
**	   to the User.
**	F. The User is asked if they wish to perform another wind chill
**	   calculation.  Depending upon their response, they either will
**	   or they won't.
**
**  KEYWORDS:
**   
**      WIND CHILL
**   
**  MODIFICATION HISTORY:
**
**      {@tbs@}...
**--
*/


/*
**
**  INCLUDE FILES
**
*/

#ifdef VMS
#include math
#include stdio
#else
#include <math.h>
#include <stdio.h>
#endif

/*
**
**  MACRO DEFINITIONS
**
*/

#define DUMMY_LEN	50


/*
**++
**  FUNCTIONAL DESCRIPTION:
**
**      This is the main wind chill function.
**
**--
*/
#ifdef VMS
void wind_chill (void)
#else
void wind_chill ()
#endif
{
#ifdef VMS
    extern void position (int, int), 
                print (char *), 
                get_date_time (char *, char *), 
                get_string (char *), 
                display_wind_chill (double);
#else
    extern void position (), 
                print (), 
                get_date_time (), 
                get_string (), 
                display_wind_chill ();
#endif
    char date [DUMMY_LEN], 
         time [DUMMY_LEN], 
#ifdef VMS
         *uppercase (char *), 
#else
         *uppercase (), 
#endif
         again [DUMMY_LEN];
#ifdef VMS
    double get_double (void), 
#else
    double get_double (), 
#endif
	   temperature, 
	   wind_speed, 
	   t1, 
	   tc, 
	   h, 
	   x, 
	   x1, 
	   integer_part, 
	   factional_part;
    int zz;

    /*	 
    **  Enter the main do loop.
    */	 
    do
    {
        /*	 
        **  Clear the screen, mention the name of this function and display
	**  the system's current date and time.
        */	 
	Erase();
	position(2, 27);
	print("WIND CHILL CALCULATION");
        get_date_time (date, time);
	position(4, 34);
	print(date);
	position(5, 35);
	print(time);

        /*	 
        **  Get the temperature.
        */	 
	position(7, 12);
	print("ENTER TEMPERATURE IN FAHRENHEIT                    ");
	temperature = get_double();

        /*	 
        **  Get the wind's speed.
        */	 
	position(8, 12);
	print("ENTER WIND SPEED IN MILES PER HOUR                 ");
	wind_speed = get_double();

        /*	 
        **  Now start the lenghty algorithm to determine the wind chill.
        */	 
        if (wind_speed <= 4.)
            wind_speed = 4.;
	t1 = temperature;
	wind_speed = (wind_speed * 1609.35) / (3600.);
	tc = 33. - ((temperature - 32.) * (5. / 9.));
        h = (10.45 + (sqrt (wind_speed) * 10.) - wind_speed) * tc;
	x = h - 506.784;

        if (x < 0.)
            display_wind_chill (t1);
        else
        {
	    x1 = 50 - (x / 12.3);
            factional_part = modf ((((x1 * 10.) + 5.) / 10.), &integer_part);
	    x1 = integer_part;
	    position (11, 19);
	    print ("PLEASE WAIT - WIND CHILL BEING COMPUTED");
            for (zz = 0;  zz < 1600;  zz++)
                ;
	    position (13, 17);
	    print ("T1=T:V=(V*1069.35)/3600:TC=33-((T-32)*(5/9))");
	    position (14, 20);
	    print ("H=(10.45+(SQR(V)*10)-V)*TC:X=H-506.784");
	    position (15, 21);
	    print ("X1=50-(X/12.3):X1=INT(((X1*10)+5)/10)");
            display_wind_chill (x1);
        }

        /*	 
        **  Now, ask the User if they want to do it again.
        */	 
	position(24, 19);
	print("RUN ANOTHER WIND CHILL FACTOR (Y/N)");
	get_string(again);
    } while (again[0] == 'Y' || again[0] == 'y');
}   /* end of wind_chill() */

/*
**++
**  FUNCTIONAL DESCRIPTION:
**
**      This function will display to the User the current wind chill
**  factor.
**
**  FORMAL PARAMETERS:
**
**      wind_chill:
**          a double
**
**--
*/
#ifdef VMS
static void display_wind_chill (double wind_chill)
#else
static void display_wind_chill (wind_chill)
double wind_chill;
#endif
{
    char wind_chill_str [DUMMY_LEN*2];
#ifdef VMS
    extern void position (int, int), print (char *);
#else
    extern void position (), print ();
#endif

    sprintf (wind_chill_str, "WIND CHILL TEMPERATURE = %.1f DEGREES FAHRENHEIT", wind_chill);
    position(19, 15);
    print(wind_chill_str);
}   /* end of display_wind_chill() */
