/*
 * SUMMARY:      ReadRadTable.c - Read IPW radiation lookup table
 * USAGE:        Part of DHSVM
 *
 * AUTHOR:       Bart Nijssen
 * ORG:          University of Washington, Department of Civil Engineering
 * E-MAIL:       nijssen@u.washington.edu
 * ORIG-DATE:    Apr-96
 * Last Change: Wed Feb  3 23:11:34 1999 by Bart Nijssen <nijssen@u.washington.edu>
 * DESCRIPTION:  Read lookup table with radiatin values for each radiation
 *                class calulated with the aid of IPW
 * DESCRIP-END.
 * FUNCTIONS:    ReadRadTable()
 * COMMENTS:     
 */

#ifndef lint
static char vcid[] = "$Id: ReadRadTable.c,v 1.2 2001/03/31 00:10:33 waichler Exp $";
#endif /* lint */

#include <stdio.h>
#include <stdlib.h>
#include "settings.h"
#include "data.h"
#include "DHSVMerror.h"
#include "functions.h"
#include "constants.h"

/*****************************************************************************
  Function name: ReadRadTable()

  Purpose      : Read the radiation values for the different IPW-generated 
                 radiation classes for the current time period

  Required     : 
    FILES InFile       - information about input file
    int NDaySteps      - number of timesteps in a day (24 hr period)
    RADTABLE *RadClass - pointer to table with radiation values

  Returns      : void

  Modifies     :
    Values at locations pointed to by RadClass

  Comments     :
*****************************************************************************/
void ReadRadTable(FILES *InFile, int NDaySteps, RADTABLE *RadClass)
{
  int i;			/* counter */
  int j;			/* counter */
  int NSolarSteps;		/* Number of solar timesteps during a day */

  if (DEBUG)
    printf("Reading radiation table from file: %s\n", InFile->FileName);

  SkipLines(InFile, 3);
  if (ScanInts(InFile->FilePtr, &(RadClass->Start), 1) != 1)  
    ReportError(InFile->FileName, 5);
  if (ScanInts(InFile->FilePtr, &NSolarSteps, 1) != 1)  
    ReportError(InFile->FileName, 5);
  RadClass->End = RadClass->Start + NSolarSteps - 1;

  SkipLines(InFile, 2);

  for (i = 0; i < RadClass->Start - 1; i++) {
    for (j = 0; j < RadClass->NClasses; j++) {
      RadClass->Beam[i][j] = 0;
      RadClass->Diffuse[i][j] = 0;
    }
  }

  for (i = RadClass->Start - 1; i < RadClass->End; i++) {
    for (j = 0; j < RadClass->NClasses; j++) {
      if (ScanFloats(InFile->FilePtr, &(RadClass->Beam[i][j]), 1) != 1)
	ReportError(InFile->FileName, 5);
      if (ScanFloats(InFile->FilePtr, &(RadClass->Diffuse[i][j]), 1) != 1)
	ReportError(InFile->FileName, 5);
    }
  }

  for (i = RadClass->End; i < NDaySteps; i++) {
    for (j = 0; j < RadClass->NClasses; j++) {
      RadClass->Beam[i][j] = 0;
      RadClass->Diffuse[i][j] = 0;
    }
  }
}
