/****************************************************************************

Mediterranean met data reader                           18 July 95

****************************************************************************/

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

#define TRUE 1              /* set parameters       */
#define FALSE 0

void startup(void);
void comp_data(void);
void shutdown(void);


FILE *fptr, *fptw;

void main ( void )                                             /* main program calling */
{                                                  /* all functions        */
  startup();
  comp_data();
  shutdown();

}

/***************************************************************************/
/*                         FUNCTION DEFINITIONS                            */
/***************************************************************************/


void comp_data() /*************************  4. reads and calculates data  */
{
	double time, direction, force, pressure, temperature;
	int year, month, day, hour;
	char datestring[9];

	while ( fscanf ( fptr,"NICE, %8s, %lg, %lg, %lg, %lg \n", datestring,
			 &direction, &force, &pressure, &temperature) != EOF )
	{
	  datestring[9]='\0';
	  sscanf (datestring,"%2d%2d%2d%2d", &year, &month, &day, &hour);
	  time = 151.0 + (double)day + (double)hour / 24.0;

	  fprintf ( fptw,"%5.4lf %5.1lf %5.1lf %5.1lf %5.1lf\n", time, direction,
		    force, pressure, temperature);
	}
/* ........................................................................ */

	shutdown();

}

void shutdown (void)
{
	fclose(fptr);
	fclose(fptw);
}

void startup (void)
{
  char input[50];
  char fileread[50], filewrite[50], gtdname[50];
  int gtdnumber;

  strcpy (fileread,  "met2.raw");
  strcpy (filewrite, "met2.txt");

 if ( (fptr = fopen( fileread,"rt"  ) ) != NULL )
 {
   printf("ok....");
 } else printf( "error in reading file " );

 if ( (fptw = fopen( filewrite,"wt" ) ) != NULL )
 {
	printf("ok.\n");
 } else printf( "error in reading file " );

}

