/*************************************************************************
  Program:     	readawc.c 
 	 Read Available Water Capacity data.
***************************************************************************
  Written by:   J. Liu
  Modified for application to China  by:  Gang Mo
  Last update:	Nov., 1998
*****************************************************************************/
#include"beps.h"

void readawc(line,awc,rcode)
  int long line; 
  double *awc;
  int long *rcode;
  {
  FILE *infile;	
  long int pix;		
  long int ptr;
  long int size, nitems;
  unsigned char* awcimg;
  awcimg=(unsigned char *)malloc(npixels*sizeof(unsigned char)); 

	/* 	Open Available Water Capacity file */
  	if ((infile=fopen(awcf, "rb")) == NULL)
    	{
          printf("\n Unable to open file <%s>,  exitting program ...\n\n",
						awcf);
	  *rcode = ERROR;
	  return;
    	}
 
	/*	Calculate starting point of data */
	ptr=line*npixels;

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

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

	/*	Get awc  */
  	for (pix=0;pix<npixels;pix++)
			awc[pix]=0.01*awcimg[pix];

    free(awcimg);
  	fclose(infile);
 }
