/*
 * SUMMARY:      DecodeIPW.c - Decode the IPW-generated radiation classes 
 * 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-MOD: Wed Feb 12 15:50:28 1997 by Bart Nijssen <nijssen@meter.ce.washington.edu>
 * DESCRIPTION:  Decode the IPW-generated radiation classes   
 * DESCRIP-END.
 * FUNCTIONS:    DecodeIPW()
 * COMMENTS:     
 */

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

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "settings.h"
#include "rad.h"

/*******************************************************************************
  DecodeIPW()
*******************************************************************************/
void DecodeIPW(int EndStep, int NDaySteps, unsigned int Code, char *Value)
{
  char Str[MAXSTRING+1];
  int i;                        /* counter */
  int j;
  int Length;

  /* if the length of the string is smaller than the number of timesteps with
     daylight, than the radiation code must have leading zeros which need to
     be added back in */

  sprintf(Str, "%u", Code);
  Length = strlen(Str);

  for (i = 0; i < (EndStep - Length); i++)
    Value[i] = 0;

  for (j = 0; i < EndStep; i++, j++)
    Value[i] = Str[j] - '0';
  
  for ( ; i < NDaySteps; i++)
    Value[i] = 0;
  
  return;
}

