/*************************************************************************
  Program:     	readsnow.c 
  -------
  Description:
  -----------
 	 Read snow pack data in a text file.
***************************************************************************
  CCRS (EMS/Applications Division)
  Written by:   J. Liu
  Last update:	Nov. 1999
*****************************************************************************/
#include"beps.h"
#include<string.h>

void readsnow(line,xx,rcode)
	int long line; 
	struct xvalue xx[]; 
	int short *rcode;
{		
	FILE *infile;
    long int pix;		
  	long int ptr;
  	long int size, nitems;  
    unsigned char* snowimg;
	snowimg=(unsigned char *)malloc(npixels*sizeof(unsigned char));

/*	Open snow pack binary file */
	if ((infile= fopen(snowpackf,"rb")) ==NULL) {
          printf("\n Unable to open file<%s>,  exitting program ...\n\n",
							snowpackf);
          *rcode = ERROR;
	  return;
     }

/*	Calculate starting point of data */
	ptr=line*npixels;

/*	Seek to start of data */
	fseek(infile,ptr,0);

/*	Read data */
  	fread(&snowimg[0],size=1,nitems=npixels,infile);

/*	Convert snow pack to meter */
	for (pix=0;pix<npixels;pix++){
		xx[pix].x1= snowimg[pix]*5.0/1000.0;	// in meter
	}

/*	Close snowpack file */
	fclose(infile);

	free(snowimg);
  	
	return;
  
 }
