/* -------------------------------------------------------------
   file: Calendar.h
   ------------------------------------------------------------- */
/* -------------------------------------------------------------
   Battelle Memorial Institute
   Pacific Northwest Laboratory
   ------------------------------------------------------------- */
/* -------------------------------------------------------------
   Created September 12, 1996 by  William A Perkins
   Last Change: Wed Feb  3 10:28:10 1999 by Bart Nijssen <nijssen@u.washington.edu>
   ------------------------------------------------------------- */

/* $Id: Calendar.h,v 1.2 2001/03/31 00:10:20 waichler Exp $ */

#ifndef _Calendar_h_
#define _Calendar_h_

#include <stdio.h>
#include "typenames.h"

#define SECPMIN 60
#define SECPHOUR 3600
#define SECPDAY 86400
#define MINPHOUR 60
#define MINPDAY 1440
#define HOURPDAY 24
#define DAYPWEEK 7
#define DAYPYEAR 365
#define MONTHPYEAR 12

/* rint(x) is a sun specific function that rounds x to an integral
   value according to the current IEEE754 rounding direction.  This
   definition mimics the current behaivor as tested on doofus using cc */
#ifdef MS_C_PLUSPLUS
#define rint(x) floor((x)+0.5)
#endif


/* -------------------------------------------------------------
   module type definitions
   ------------------------------------------------------------- */
typedef struct {
  int Year;
  int Month;
  int Day;
  int Hour;
  int Min;
  int Sec;
  int JDay;			/* Day of year(jan 1 = 1) */
  double Julian;		/* Julian day */
} DATE;

typedef struct {
  int Dt;			/* Timestep (in sec) */
  DATE Start;			/* Starting date of run */
  DATE End;			/* Ending date of run */
  DATE Current;			/* Current date in run */
  DATE StartRadar;		/* Start radar file */
  DATE StartMM5;		/* Start of MM5 files */
  int Step;			/* Timestep since start */
  int DayStep;			/* Time step since midnight */
  int NDaySteps;		/* Number of timesteps per day */
  int NTotalSteps;		/* Total number of steps in run */
} TIMESTRUCT;

/* -------------------------------------------------------------
   available functions
   ------------------------------------------------------------- */
uchar After(DATE *Day1, DATE *Day2);
uchar Before(DATE *Day1, DATE *Day2);
void CopyDate(DATE *Copy, DATE *Original);
int DayOfYear(int Year, int Month, int Day);
/*void IncreaseTime(TIMESTRUCT *Time);
int InitTime(TIMESTRUCT *Time, DATE *Start, DATE *End, DATE *StartRadar, 
	     DATE *StartMM5, int Dt);*/
uchar IsEqualTime(DATE *Day1, DATE *Day2);
uchar IsLeapYear(int Year);
uchar IsNewDay(int DayStep);
uchar IsNewMonth(DATE *Now, int Interval);
DATE NextDate(DATE *Current, int Interval);
int NumberOfSteps(DATE *Start, DATE *End, int Interval);
void PrintDate(DATE *Day, FILE *OutFile);
void SPrintDate(DATE *Day, char *buffer);
int ScanDate(FILE *InFile, DATE *Day);
int SScanDate(char *Str, DATE *Day);
void JulianDayToGregorian(double jd, int *y, int *m, int *d, int *h, int *mi, 
			  double *sec);
double GregorianToJulianDay(int year, int mon, int day, int h, int mi, 
			    double se);
int DayOfWeek(double j);

#endif
