/*
 * SUMMARY:      rad.h header file for radiation functions for DHSVM
 * USAGE:        Part of DHSVM
 *
 * AUTHOR:       Bart Nijssen
 * ORG:          University of Washington, Department of Civil Engineering
 * E-MAIL:       nijssen@u.washington.edu
 * ORIG-DATE:    Apr-1996
 * LAST-MOD: Wed Dec  3 13:59:00 1997 by Bart Nijssen <nijssen@u.washington.edu>
 * DESCRIPTION:  header file for radiation functions for DHSVM
 * DESCRIP-END.
 * FUNCTIONS:    
 * COMMENTS:     
 */

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

#ifndef CALCSOLAR_H
#define CALCSOLAR_H

 /*#define ALBEDO  0.15            WORK IN PROGRESS, See InitNewStep() */

/* set some constants */
#ifndef TRUE
#define TRUE 1
#endif

#ifndef FALSE
#define FALSE 0
#endif

#ifndef MINPHOUR
#define MINPHOUR 60
#endif

#ifndef DAYPYEAR
#define DAYPYEAR 365
#endif

#ifndef DEGPRAD
#define DEGPRAD 57.29578               /* degree per radian */
#endif

#ifndef MINPDEG
#define MINPDEG 4.                     /* minutes per degree longitude */
#endif

#ifndef PI
#define  PI 3.14159265358979323846
#endif

#ifndef RADPHOUR
#define  RADPHOUR 0.2617994            /* radians per hour: Earth's Rotation 
                                            (2 PI rad/day) * (1 day/24 h) */
#endif

#ifndef SOLARCON
#define SOLARCON 1360.                 /* Solar constant (W/m^2) */
#endif

#ifndef RADPDEG
#define RADPDEG  (PI/180.0)            /* radians per degree */
#endif


typedef struct {
  float SolarAzimuth;		/* solar azimuth */
  float Latitude;               /* Latitude of center of study area */
  float Longitude;              /* Longitude of center of study area */
  float StandardMeridian;       /* Standard meridian for current time zone */
  float NoonHour;               /* Time at which solar noon occurs for
                                   current location */
  float Declination;            /* Solar declination */
  float HalfDayLength;          /* Length of half day in hours */
  float Sunrise;                /* Hour of sunrise */
  float Sunset;                 /* Hour of sunset */
  float TimeAdjustment;         /* Time adjustment to be made between center
                                   of study area and standard meridian */
  float SunEarthDistance;       /* Distance from Sun to Earth */
  float SineSolarAltitude;      /* Sine of sun's SolarAltitude  */
  int DayLight;                 /* FALSE: measured solar radiation and the
                                   sun is below the horizon.  
                                   TRUE: sun is above the horizon */
  float SolarTimeStep;          /* Fraction of the timestep the sun is above
                                   the horizon  */
  float SunMax;                 /* Calculated solar radiation at the top of
                                   the atmosphere (W/m^2) */
} SOLARGEOMETRY;



void SolarAngle(float Latitude, float Albedo, float Declination, 
                float CellAspect, float CellSlope, float SunMax, 
                float SineSolarAltitude, float SolarTimeStep, int DayLight,
                float SolarAzimuth, float Dt, float *Direct, float *Diffuse);

void SolarConst(float lat_deg, float lat_min, float lng_deg, 
                float lng_min, float *StandardMeridian, float *Latitude, 
                float *Longitude);

void SolarDay(int DayOfYear, float Longitude, float Latitude, 
              float StandardMeridian, float *NoonHour, float *Declination, 
              float *HalfDayLength, float *Sunrise, float *Sunset, 
              float *TimeAdjustment, float *SunEarthDist);

void SolarHour(float Latitude, float LocalHour, float Dt, float NoonHour, 
               float Declination, float Sunrise, float Sunset, 
               float TimeAdjustment, float SunEarthDist, 
               float *SineSolarAltitude, int *DayLight, float *SolarTimeStep,
               float *SunMax, float *SolarAzimuth);

void CalcSolarDay(int DayOfYear, SOLARGEOMETRY *SolarGeo);

void CalcSolarHour(float StartHour, float Dt, SOLARGEOMETRY *SolarGeo);

#endif
