/*
This assignment represents my own work
								0249371	devenyga@mcmaster.ca

The following people assisted me with this assignment:

I assisted the following people on this assignment:
Brad Statham 0257756

Title: C-Code Assignment 4
Sub-Title: Contaminant Movement Modeling
Course Code: ENG1D04
Tutorial: T25
Submitted By: Gabriel Devenyi
Student ID: 0249371
Date: March 14, 2003
Description: This program models the movement of dust particles and surface currents and analyzes the surface conditions.

<Asymptions>
1. The user will input the correct types, real for real, integer for integer.
2. A constant will define the maximum number of data points, MAXN
3. First acceleration 0m/s^2 becasue no values before inital time.
*/

#include <stdio.h>
#include <math.h>

#define MAXN 10
#define DEG_TO_RAD 3.1415/180
#define PHI 52
#define KCONSTANT 0.0127

typedef struct
{
	float time;
	float velocity;
} wind_data;

void input_data(float *t_zero, float *d_time, wind_data *list);
void calculate(wind_data list[], float *accel_list, float *current);
void output_data(wind_data list[], float accel_list[], float current[]);

int main(void)
{
	wind_data data[MAXN];
	float inital_time, delta_time;

	float accel[MAXN];
	float surface_current[MAXN];
	
	input_data(&inital_time, &delta_time, data);
	calculate(data, accel, surface_current);
	output_data(data, accel, surface_current);
	
	printf("\n");
	return 0;
}

void input_data(float *t_zero, float *d_time, wind_data *list)
{
	int i;
	printf("Please enter the inital time: ");
	scanf ("%f", t_zero);
	printf("Please enter the measurement interval: ");
	scanf ("%f", d_time);
	
	for (i = 0; i < MAXN; i++)
	{
		printf("Please enter velocity %d: ", i+1);
		scanf("%f", &list[i].velocity);
		list[i].time = *t_zero + (i * *d_time);
	}
}

void calculate(wind_data list[], float *accel_list, float *current)
{
	int i;
	accel_list[0] = 0;
	for (i = 0; i < MAXN; i++)
	{
		if (list[i].velocity > 2.0)
		{
			current[i] = (KCONSTANT / (sqrt(sin(PHI)))) * list[i].velocity;
		} else
		{
			current[i] = 0;
		}
		
		if (i != 0)
		{
			accel_list[i] = (list[i].velocity - list[i-1].velocity) / (list[i].time - list[i-1].time);
		}
	}
}

void output_data(wind_data list[], float accel_list[], float current[])
{
	int i;
	printf("\nTime\tWind Velocity\tAcceleration of a\tSurface Drift\tSurface\n");
	printf("(s)\t(m/s)\t\tdust particle (m/s^2)\tCurrents (cm/s)\tConditions");
	for (i = 0; i < MAXN; i++)
	{
		printf("\n%.2f\t%.2f\t\t%.2f\t\t\t%.2f\t\t", list[i].time, list[i].velocity, accel_list[i], current[i]);
		if ((list[i].velocity) > 7.0)
		{
			printf("storm");
		} else if ((list[i].velocity >= 5.0) && (list[i].velocity <= 7.0))
		{
			printf("near storm phase");
		} else if ((list[i].velocity > 2.0) && (list[i].velocity < 5.0))
		{
			printf("transition phase");
		} else if (list[i].velocity <= 2.0)
		{
			printf("calm");
		}
	}
}
