void SW_VES_read(void) {
    /* =================================================== */

    FILE *f;
    IntU i;

    MyFileName = SW_F_name(eVegEstab);
    f = OpenFile(MyFileName, "r");
    SW_VegEstab.use = TRUE;

    /* if data file empty or useflag=0, assume no
    * establishment checks and just continue the model run. */
    if (!GetALine(f, inbuf) || *inbuf == '0' ) {
        SW_VegEstab.use = FALSE;
        if (EchoInits)
            LogError(logfp, LOGNOTE, "Establishment not used.\n");
        return;
    }
    while(GetALine(f, inbuf) ) {
        _read_spp(inbuf);
    }
    CloseFile(&f);

    for (i=0; i < SW_VegEstab.count; i++)
        _spp_init(i);

    if ( SW_VegEstab.count > 0)
        SW_VegEstab.yrsum.days = (TimeInt *)
                                 Mem_Calloc(SW_VegEstab.count,
                                            sizeof(TimeInt),
                                            "SW_VES_read()");
    if (EchoInits) _echo_inits();
}
void SW_VES_read(void) {
	/* =================================================== */
	FILE *f;

	MyFileName = SW_F_name(eVegEstab);
	f = OpenFile(MyFileName, "r");
	SW_VegEstab.use = swTRUE;

	/* if data file empty or useflag=0, assume no
	 * establishment checks and just continue the model run. */
	if (!GetALine(f, inbuf) || *inbuf == '0') {
		SW_VegEstab.use = swFALSE;
		if (EchoInits)
			LogError(logfp, LOGNOTE, "Establishment not used.\n");
		CloseFile(&f);
		return;
	}

	while (GetALine(f, inbuf)) {
		_read_spp(inbuf);
	}

	CloseFile(&f);

	Init_SW_VegEstab();

	if (EchoInits)
		_echo_VegEstab();
}
static void _read_bvt(void) {
/*======================================================*/
/* read two numbers, biomass (g/m2) and
 * transpiration (cm/m2) for that biomass to construct a
 * simple linear relationship that gives g biomass / cm transp
 * per m2.
 */

  FILE *fp;
  RealF bmass, transp;

  MyFileName = SXW.f_bvt;
  fp = OpenFile(MyFileName,"r");

  GetALine(fp, inbuf);
  bmass = atof(inbuf);

  GetALine(fp, inbuf);
  transp = atof(inbuf);


  CloseFile(&fp);

  _bvt = bmass / transp;

}
static void _read_test_data( void) {
/*======================================================*/
/* Read a set of arbitrary (non-baseline) group sizes and
 * transpiration values and populates the RGroup[g].relsizes
 * and the SXW.transp array. This simulates retrieval from
 * soilwat.
 */
  LyrIndex lyr, cnt;
  TimeInt pd;
  char *p;
  FILE *fp;
  char *fname = "sxw_testdata.in";

  fp = OpenFile(fname,"r");

  /* read the relative sizes */
  GetALine(fp, inbuf);
  p = strtok(inbuf," \t");
  cnt = 1;
  do {
    RGroup[cnt++]->relsize = atof(p);
  } while (p=strtok(NULL, " \t"));

  /* read the transpiration values */
  cnt=0;
  while( GetALine(fp, inbuf) ) {
    p = strtok(inbuf,", \t"); /* g'teed to work via GetALine() */
    if (++cnt > SXW.NPds) break;

    pd = atoi(p) -1;
    lyr = 0;
    while ((p=strtok(NULL," \t")) ) {
      if (lyr > SW_Site.n_transp_lyrs_tree) {
        LogError(logfp, LOGFATAL, "Too many layers of transpiration found in %s\n"
                        "Compare with soil layer definitions for SOILWAT.",
                        fname);
      }
      SXW.transp[Ilp(lyr,pd)] = atof(p);
      lyr++;
    }

  }

  if (cnt > SXW.NPds) {
    LogError(logfp, LOGFATAL, "Too many time periods found in %s.  Expected %d.",
            fname, SXW.NPds);
  }

  if (cnt < SXW.NPds) {
    LogError(logfp, LOGFATAL, "Not enough time periods found in %s.  Expected %d.",
            fname, SXW.NPds);
  }

  CloseFile(&fp);
}
// Process Begin Rwr token
void DoBegRwr()
{
	short lSearchSymbol,lLockSymbol;
	short len,i;
	long  lSearchTone,lLockTone;
	char  *tptr;

	where   = _RWR_DATA_;
	Rwrhead = new Header;
	RwrHeadKeep[currwridx] = (char *)Rwrhead;
	Rwrptr  = new RWR_Data;
	RwrPtrKeep[currwridx]  = (char *)Rwrptr;

	Rwrhead->type = tokmap[toktype];
	trdata = nextdata;
	trdata = GetALine( trdata,backn );	// RWRNAME
	len    = strlen( trdata );
	tptr   = (char *)&Rwrptr->Name[0];
	for ( i=0;i < len-1;i++ ) {
		*tptr = trdata[i];
		tptr++;
	}
	*tptr     = '\0';
	ttlentity += 32;	// fix length
	ttlrwr    += 32;

	trdata = nextdata;
	trdata = GetALine( trdata,backn );	// SearchSymbol
	lSearchSymbol       = Text2Short( trdata );
	Rwrptr->SearchState = lSearchSymbol;
	ttlentity += (sizeof(short));
	ttlrwr    += (sizeof(short));

	trdata = nextdata;
	trdata = GetALine( trdata,backn );	// SearchTone
	lSearchTone        = Text2Long( trdata );
	Rwrptr->SearchTone = lSearchTone;
	ttlentity += (sizeof(long));
	ttlrwr    += (sizeof(long));

	trdata = nextdata;
	trdata = GetALine( trdata,backn );	// LockSymbol
	lLockSymbol       = Text2Short( trdata );
	Rwrptr->LockState = lLockSymbol;
	ttlentity += (sizeof(short));
	ttlrwr    += (sizeof(short));

	trdata = nextdata;
	trdata = GetALine( trdata,backn );	// LockTone
	lLockTone        = Text2Long( trdata );
	Rwrptr->LockTone = lLockTone;
	ttlentity += (sizeof(long));
	ttlrwr    += (sizeof(long));
}
static void _read_watin(void) {
/*======================================================*/
/* get the name of the soilwat output definition file.  */
/* assume that there is no path prepended to the file
 * specification in the SOILWAT input files.  It might be
 * nice to allow relative paths, but there's really no need
 * for it as far as the STEPWAT program is concerned because
 * all the SOILWAT input files should be in one directory
 * and that is defined in sxw.in.  Thus, we'll treat the
 * outsetup.in filename as though it has no dirname and
 * append it to the soilwat input dirname.
 */
   FILE *f;
   int lineno = 0;
   Bool found = FALSE;

   MyFileName = SXW.f_watin;
   f = OpenFile(MyFileName, "r");

   while( GetALine(f, inbuf) ) {
     if (++lineno == (eOutput + 2)) {
       strcpy(_swOutDefName, DirName(SXW.f_watin));
       strcat(_swOutDefName, inbuf);
       found = TRUE;
       break;
     }
   }
   CloseFile(&f);

   if (!found) {
     LogError(logfp, LOGFATAL,
              "%s: Too few files (%d)", MyFileName, lineno);
   }

}
static void _read_prod(void) {
/*======================================================*/
  int x;
  FILE *fp;
  Months mon=Jan;

  MyFileName = SXW.f_prod;
  fp = OpenFile(MyFileName,"r");

  while(GetALine(fp, inbuf) ) {
      x=sscanf( inbuf, "%f %f",
                      &_prod_conv[mon][PC_Bmass],
                      &_prod_conv[mon][PC_Litter]);
      if (x<2) {
         LogError(logfp, LOGFATAL, "%s: invalid record %d.",
                 MyFileName, mon +1);
      }

      if (++mon > Dec)
        break;
   }
   CloseFile(&fp);

   if (mon <= Dec ) {
     LogError(logfp, LOGWARN,
              "%s: No Veg Production values found after month %d",
              MyFileName, mon +1);
   }

}
static void _model_init( void) {
/*======================================================*/

   FILE *f;
   int seed;
   char tmp[80];

   MyFileName = Parm_name(F_Model);
   f = OpenFile(MyFileName, "r");

   /* ----------------------------------------------------*/
   /* scan for the first line*/
   if (!GetALine(f, inbuf)) {
     LogError(logfp, LOGFATAL, "%s: No data found!\n", MyFileName);
   } else {
     sscanf( inbuf, "%s %hu %d",
             tmp,
             &Globals.runModelYears,
             &seed);

     Globals.Max_Age = Globals.runModelYears;
     Globals.runModelIterations = atoi(tmp);
     if (Globals.runModelIterations < 1 ||
         Globals.runModelYears < 1 ) {
       LogError(logfp, LOGFATAL,"Invalid parameters for RunModelIterations "
               "or RunModelYears (%s)",
               MyFileName);
     }
     Globals.bmass.suffixwidth = Globals.mort.suffixwidth = strlen(tmp);
     Globals.randseed = (IntL) ((seed) ? -abs(seed) : 0);
   }

   CloseFile(&f);
}
static void  _read_roots_max(void) {
/*======================================================*/
  GrpIndex g;
  int cnt=0, lyr;
  char *p;
  FILE *fp;

  MyFileName = SXW.f_roots;
  fp = OpenFile(MyFileName,"r");

  while( GetALine(fp, inbuf) ) {
    p = strtok(inbuf," \t"); /* g'teed to work via GetALine() */

    if ( (g=RGroup_Name2Index(p)) <0 ) {
      LogError(logfp, LOGFATAL, "%s: Invalid group name (%s) found.",
              MyFileName, p);
    }
    cnt++;
    lyr = 0;
    while ( (p=strtok(NULL," \t")) ) {
      _roots_max[Ilg(lyr,g)] = atof(p);
      lyr++;
    }

  }

  if (cnt < Globals.grpCount) {
    LogError(logfp, LOGFATAL,
             "%s: Not enough valid groups found.", MyFileName);
  }

  CloseFile(&fp);
}
static void  _read_times(void) {
/*======================================================*/
/* transpiration and phenology periods are the same.    */

  FILE *fp;

  MyFileName = SXW.f_times;
  fp = OpenFile(MyFileName,"r");

  if (!GetALine(fp, inbuf)) {
    LogError( logfp, LOGFATAL, "%s: No data found!", MyFileName);
  }

  if (strcmp(inbuf, "week") == 0)
    SXW.NPds = MAX_WEEKS;
  else if (strcmp(inbuf,"month") == 0)
    SXW.NPds = MAX_MONTHS;
  else if (strcmp(inbuf,"day") == 0)
    SXW.NPds = MAX_DAYS;
  else {
    LogError(logfp, LOGFATAL, "%s: Invalid period", MyFileName);
  }

  CloseFile(&fp);

}
// Process Begin Cat token
void DoBegCat()
{
	short len,i;
	char  *tptr;

	where   = _CATEGORY_;
	Cathead = new Header;
	CatHeadKeep[curcatidx] = (char *)Cathead;
	Catptr  = new Category;
	CatPtrKeep[curcatidx]  = (char *)Catptr;
	ttlentity += (2*sizeof(short));	// for the header
	ttlstat   += (2*sizeof(short));	// for the header
	Cathead->type = tokmap[toktype];

	trdata = nextdata;
	trdata = GetALine( trdata,backn );	// CatText
	len    = strlen( trdata );
	tptr   = (char *)&Catptr->Name[0];
	for ( i=0;i < len-1;i++ ) {
		*tptr = trdata[i];
		tptr++;
	}
	*tptr = '\0';
	ttlentity += 40;	// fix length
	ttlstat += 40;
	ttlcat += 40;
}
// Process Begin Entity token
void DoBegEntity()
{
	long  lGroupID,lSubGroupID,lEntityID;
	short lModelID,len,i;
	char  *tptr;

	where = _ENTITY_;
	if ( !Enthead )   Enthead   = new Header;
	if ( !Entityptr ) Entityptr = new Entity;
	Enthead->type = tokmap[toktype];
	trdata   = nextdata;
	trdata   = GetALine( trdata,backn );	// GroupID
	lGroupID = Text2Long( trdata );
	Entityptr->GroupID = lGroupID;

	trdata      = nextdata;
	trdata      = GetALine( trdata,backn );	// SubGroupID
	lSubGroupID = Text2Long( trdata );
	Entityptr->SubGroupID = lSubGroupID;

	trdata    = nextdata;
	trdata    = GetALine( trdata,backn );	// EntityID
	lEntityID = Text2Long( trdata );
	Entityptr->EntityID = lEntityID;

	ttlentity += ( 3*sizeof(long) );

	trdata   = nextdata;
	trdata   = GetALine( trdata,backn );	// ModelID
	lModelID = Text2Short( trdata );
	Entityptr->ModelID = lModelID;

	ttlentity += ( sizeof(short) );

	trdata = nextdata;
	trdata = GetALine( trdata,backn );	// EntityName
	len    = strlen( trdata );
	tptr   = (char *)&Entityptr->Name[0];
	for ( i=0;i < len-1;i++ ) {
		*tptr = trdata[i];
		tptr++;
	}
	*tptr = '\0';
	ttlentity += 32;	// fix length
}
Beispiel #13
0
void readGameFile(const char *s) {
	FILE *f;
	int lineno=0, i=0;
	char * pch;
	Game *game;
	char buf[1024];

	int gameSize = 0;

	if(s==NULL)
		exit(1);

	f = fopen(s, "r");
	if(f == NULL) {
		printf("Could not open file");
		exit(1);
	}

	while(GetALine(f, inbuf)) {
		game = malloc(sizeof(Game));

		strcpy(buf,inbuf);

		pch = strtok(inbuf, " ");
		while (pch != NULL)
		{
			gameSize++;
			pch = strtok (NULL, " ");
		}
		game->size = gameSize;
		game->flips = 0;
		game->pancakes = malloc(sizeof(int) * gameSize);
		//game->moves[0] = '\0';
		gameSize = 0;

		i=0;
		pch = strtok(buf, " ");
		while (pch != NULL) {
			game->pancakes[i] = atoi(pch);
			i++;
			pch = strtok(NULL, " ");
		}

		games[nGames] = game;
		nGames++;

		lineno++;
	}
}
Beispiel #14
0
/*
the first square should be hit only one time by the line.
so it's important to set p1 as the center of the first square.
*/
void SquareLine::GetALine(vector2d p1, vector2d p2, Square startings,Board	*w, std::list<Square> & l_squares)
{
	if(!NotOutOfBoard(startings) || w->GetContentAt(startings) ==  e_obstacle)
		return;


	sg=Segment(p1, p2);
	s_cur=startings;
	p_lastipoint=vector2d::Invalid;
	pl_squares = &l_squares;
	board = w;

	GetALine();

}
// Parse the tacref database file
void DoParse()
{
	char Prsdone;

	Prsdone = 0;
	while ( !Prsdone ) {
		trdata  = GetALine( trdata,backn );
		toktype = CheckToken( trdata );
		if ( toktype != -1 ) {
			(tokfunc[toktype])();
		}
		trdata = nextdata;
		if ( trdata >= endingdata ) {
			Prsdone = 1;
		}
	}
}
void SW_SWC_read(void) {
/* =================================================== */
/* Like all of the other "objects", read() reads in the
* setup parameters.  See _read_hist() for reading
* historical files.
*
*  1/25/02 - cwb - removed unused records of logfile and
*          start and end days.  also removed the SWTIMES dy
*          structure element.
*/

SW_SOILWAT *v = &SW_Soilwat;
FILE *f;
int lineno=0, nitems=4;

// gets the soil temperatures from where they are read in the SW_Site struct for use later
// SW_Site.c must call it's read function before this, or it won't work
LyrIndex i;
ForEachSoilLayer(i)
	v->sTemp[i] = SW_Site.lyr[i]->sTemp;

MyFileName = SW_F_name(eSoilwat);
f = OpenFile(MyFileName, "r");

while( GetALine(f, inbuf) ) {
switch(lineno) {
case 0:  v->hist_use = (atoi(inbuf)) ? TRUE : FALSE; break;
case 1:  v->hist.file_prefix = (char *)Str_Dup(inbuf);                break;
case 2:  v->hist.yr.first = yearto4digit(atoi(inbuf));  break;
case 3:  v->hist.method = atoi(inbuf);               break;
}
if (!v->hist_use)  return;
lineno++;
}
if (lineno < nitems) {
LogError(logfp, LOGFATAL,
"%s : Insufficient parameters specified.",MyFileName);
}
if (v->hist.method < 1 || v->hist.method > 2) {
LogError(logfp, LOGFATAL,
"%s : Invalid swc adjustment method.", MyFileName);
}
v->hist.yr.last = SW_Model.endyr;
v->hist.yr.total = v->hist.yr.last - v->hist.yr.first +1;
}
static void _read_phen(void) {
/*======================================================*/

  GrpIndex g;
  IntUS cnt=0;
  Months m;
  char *p;
  FILE *fp;

  MyFileName = SXW.f_phen;
  fp = OpenFile(MyFileName,"r");


  while( GetALine(fp, inbuf) ) {
    p = strtok(inbuf," \t"); /* g'teed to work via GetALine() */

    if ( (g=RGroup_Name2Index(p)) <0 ) {
      LogError(logfp, LOGFATAL,
               "%s: Invalid group name (%s) found.", MyFileName, p);
    }
    cnt++;
    m = Jan;
    while ((p=strtok(NULL," \t")) ) {
      if (m > Dec) {
        LogError(logfp, LOGFATAL,
                 "%s: More than 12 months of data found.", MyFileName);
      }
      _phen[Igp(g,m)] = atof(p);
      m++;
    }

  }

  if (cnt < Globals.grpCount) {
    LogError(logfp, LOGFATAL,
             "%s: Not enough valid groups found.", MyFileName);
  }

  CloseFile(&fp);

}
static void _files_init( void ) {
/*======================================================*/
  /* 7-May-02 (cwb) added code to interface with SOILWAT */

  FILE *f;
  ST_FileIndex i;

#ifndef STEPWAT
  ST_FileIndex last = F_MortAvg;
#else
  ST_FileIndex last = F_SXW;
#endif


  MyFileName = Parm_name(F_First);

  f = OpenFile(MyFileName, "r");

  for(i=F_Log; i <= last; i++) {
    if ( ! GetALine(f, inbuf)) break;
    _files[i] = Str_Dup(Str_TrimLeftQ(inbuf));
    //printf("FILES: %d : %s\n", i, _files[i]);
  }

  if ( i < last) {
    LogError(logfp, LOGFATAL, "%s: Too few input files specified",
                              MyFileName);
  }

  CloseFile(&f);

  if(!UseGrid) {	//if the gridded option has been specified, then the logfile has already been opened
  	if ( !strcmp("stdout", _files[F_Log]) )
    	logfp = stdout;
  	else
    	logfp = OpenFile(_files[F_Log], "w");
   }

}
static void  _read_files( void ) {
/*======================================================*/
  /* read list of input files.   */
  FILE *fin;
  int i, nfiles = SXW_NFILES;

  SXW.f_files = Parm_name(F_SXW);  /* aliased */
  MyFileName = SXW.f_files;
  fin = OpenFile(MyFileName,"r");

  for(i=0; i < nfiles; i++) {
    if (!GetALine(fin, inbuf)) break;
    *_files[i] = Str_Dup(Str_TrimLeftQ(inbuf));
  }
 
  if (i < nfiles) {
    LogError(logfp, LOGFATAL, "STEPWAT: %s: Insufficient files found",
            MyFileName);
  }

  CloseFile(&fin);


}
static void _plot_init( void) {
/*======================================================*/

   FILE *f;
   int x, nitems=1;

   MyFileName = Parm_name(F_Plot);
   f = OpenFile(MyFileName, "r");

   /* ----------------------------------------------------*/
   /* scan for the first line*/
   if (!GetALine(f, inbuf)) {
     LogError(logfp, LOGFATAL, "%s: No data found!\n", MyFileName);
   }

   x = sscanf( inbuf, " %f", &Globals.plotsize);
   if (x < nitems) {
     LogError(logfp, LOGFATAL, "%s: Incorrect number of fields",
                     MyFileName);
   }


   CloseFile(&f);
}
static void _read_hist( TimeInt year) {
/* =================================================== */
/* read a file containing historical swc measurements.
* Enter with year a four digit year number.  This is
* appended to the swc prefix to make the input file
* name.
*
*
* 1/25/02 - cwb - removed year field from input records.
*         This code uses GetALine() which discards comments
*         and only one year's data per file is allowed, so
*         and the date is part of the file name, but if you
*         must, you can add the date as well as other data
*         inside comments, preferably at the top of the file.
*
* Format of the input file is
* "doy layer swc stderr"
*
* for example,
*  90 1 1.11658 .1
*  90 2 1.11500 .1
*    ...
* 185 1 2.0330  .23
* 185 2 3.1432  .25
*    ...
* note that missing days or layers will not cause
* an error in the input, but missing layers could
* cause problems in the flow model.
*/
SW_SOILWAT *v = &SW_Soilwat;
FILE *f;
TimeInt doy;
int x, lyr, recno=0;
RealF swc, st_err;
char fname[MAX_FILENAMESIZE];



sprintf(fname, "%s.%4d", v->hist.file_prefix, year);

if (!FileExists(fname)) {
LogError(logfp, LOGWARN, "Historical SWC file %s not found.", fname);
return;
}

f = OpenFile(fname, "r");

_clear_hist();

while( GetALine(f, inbuf) ) {
recno++;
x=sscanf( inbuf, "%d %d %f %f",
&doy,
&lyr,
&swc,
&st_err);
if (x<4) {
LogError(logfp, LOGFATAL, "%s : Incomplete layer data at record %d\n"
"  Should be DOY LYR SWC STDERR.",
fname, recno);
}
if (x>4) {
LogError(logfp, LOGFATAL, "%s : Too many input fields at record %d\n"
"  Should be DOY LYR SWC STDERR.",
fname, recno);
}
if (doy < 1 || doy > MAX_DAYS) {
LogError(logfp, LOGFATAL, "%s : Day of year out of range at record %d",
fname, recno);
}
if (lyr < 1 || lyr > MAX_LAYERS) {
LogError(logfp, LOGFATAL, "%s : Layer number out of range (%d > %d), record %d\n",
fname, lyr, MAX_LAYERS, recno);
}

v->hist.swc[doy-1][lyr-1]  = swc;
v->hist.std_err[doy-1][lyr-1] = st_err;

}

}
Beispiel #22
0
void SW_F_read(const char *s) {
	/* =================================================== */
	/* enter with the name of the first file to read for
	 * the filenames, or NULL.  If null, then read files.in
	 * or whichever filename was set previously. see init().
	 *
	 * 1/24/02 - replaced [re]alloc with StrDup()
	 *         - added facility for log-to-file. logfp depends
	 *             on having executed SW_F_read().
	 */

	FILE *f;
	int lineno = 0, fileno = 0;
	char buf[FILENAME_MAX];

	if (!isnull(s))
		init(s); /* init should be run by SW_F_Construct() */

	MyFileName = SW_F_name(eFirst);
	f = OpenFile(MyFileName, "r");

	while (GetALine(f, inbuf)) {

		switch (lineno) {
		case 5:
			strcpy(weather_prefix, inbuf);
			break;
		case 12:
			strcpy(output_prefix, inbuf);
			break;

		default:
			if (++fileno == SW_NFILES)
				break;

			if (!isnull(InFiles[fileno]))
				Mem_Free(InFiles[fileno]);
			strcpy(buf, _ProjDir);
			strcat(buf, inbuf);
			InFiles[fileno] = Str_Dup(buf);
		}

		lineno++;
	}

	if (fileno < eEndFile - 1) {
		CloseFile(&f);
		LogError(stdout, LOGFATAL, "Too few files (%d) in %s", fileno, MyFileName);
	}

	CloseFile(&f);

#if !defined(STEPWAT) && !defined(RSOILWAT)
	if (0 == strcmp(InFiles[eLog], "stdout")) {
		logfp = stdout;
	} else if (0 == strcmp(InFiles[eLog], "stderr")) {
		logfp = stderr;
	} else {
		logfp = OpenFile(SW_F_name(eLog), "w");
	}
#endif

}
Beispiel #23
0
void SW_WTH_read(void) {
/* =================================================== */
SW_WEATHER *w = &SW_Weather;
const int nitems=18;
FILE *f;
int lineno=0, month, x;
RealF sppt,stmax,stmin;

MyFileName = SW_F_name(eWeather);
f = OpenFile(MyFileName, "r");

while( GetALine(f,inbuf) ) {

	switch(lineno) {
		case 0:  w->use_snow = itob(atoi(inbuf));         	break;
		case 1:  w->pct_snowdrift = atoi(inbuf);		  	break;
		case 2:  w->pct_runoff = atoi(inbuf);				break;
		case 3:  w->use_markov = itob(atoi(inbuf));       	break;
		case 4:  w->yr.first = YearTo4Digit(atoi(inbuf));	break;
		case 5:  w->days_in_runavg = atoi(inbuf);
					runavg_list = (RealD *) Mem_Calloc(w->days_in_runavg, sizeof(RealD), "SW_WTH_read()");
															break;
		default:
			if (lineno == 6 + MAX_MONTHS) break;

			x = sscanf(inbuf, "%d %f %f %f", &month, &sppt, &stmax, &stmin);
			if (x < 4) {
				LogError(logfp, LOGFATAL, "%s : Bad record %d.", MyFileName, lineno);
			}

			w->scale_precip[month-1] = sppt;
			w->scale_temp_max[month-1] = stmax;
			w->scale_temp_min[month-1] = stmin;
	}
	
	lineno++;
}

SW_WeatherPrefix(w->name_prefix);

CloseFile(&f);

if (lineno < nitems-1) {
	LogError(logfp, LOGFATAL, "%s : Too few input lines.",MyFileName);
}

w->yr.last = SW_Model.endyr;
w->yr.total = w->yr.last - w->yr.first +1;



if (w->use_markov) {
	SW_MKV_construct();

	if (!SW_MKV_read_prob()) {
		LogError(logfp, LOGFATAL, "%s: Markov weather requested but could not open %s",
		MyFileName, SW_F_name(eMarkovProb));
	}

	if (!SW_MKV_read_cov()) {
		LogError(logfp, LOGFATAL, "%s: Markov weather requested but could not open %s",
		MyFileName, SW_F_name(eMarkovCov));
	}

	} else if (SW_Model.startyr < w->yr.first) {
		LogError(logfp, LOGFATAL,
		"%s : Model year (%d) starts before weather files (%d)"
		" and use_Markov=FALSE.\nPlease synchronize the years"
		" or set up the Markov weather files",
		MyFileName, SW_Model.startyr, w->yr.first);
	}
/* else we assume weather files match model run years */

/* required for PET */
SW_SKY_read();
SW_SKY_init();

}
// Process description text
void DoDescript()
{
	short lZoomAdjust,lVertical,lHoriz,lMissile;
	short len,i;
	char  *newlnptr;
	char  *token,*tptr;
	short ttldesctxt;

	Deschead       = new Header;
	Deschead->type = _DESCRIPTION_;
	DescHeadKeep   = (char *)Deschead;
	ttlentity      += ( 2*sizeof(short) );
	ttldesctxt     = 0;

	token = trdata;
	token = strtok( NULL, backn );
	/* While there are tokens in "string" */
	while ( token ) {
		if (strncmp( token,"END_TEXT",8 )) {
			/* Not End Text yet, Copy token & Get next token */
			DescTxtptr = new TextString;
			DescPtrKeep[curdesidx] = (char *)DescTxtptr;
			ttlentity  += ( sizeof(short) );

			len = strlen( token );
			if ( len == 1 ) len++;
			DescTxtptr->length = len;
			DescChildTxt       = new char[len];
			DescChildKeep[curdesidx] = DescChildTxt;
			tptr = DescChildTxt;
			for ( i=0;i < len-1;i++ ) {
				*tptr = token[i];
				tptr++;
			}
			*tptr      = '\0';
			ttlentity  += len;
			ttldesctxt += len+sizeof(short);
			curdesidx++;

			token = strtok( NULL, backn );
			if ( token ) newlnptr = token;
		}
		else { // End of Text block found
			// Get some values here
			trdata      = token+strlen(token)+1;
			trdata      = GetALine( trdata,backn );	// ZoomAdjust
			lZoomAdjust = Text2Short( trdata );
			Entityptr->ZoomAdjust = lZoomAdjust;

			trdata    = nextdata;
			trdata    = GetALine( trdata,backn );	// Vert Offset
			lVertical = Text2Short( trdata );
			Entityptr->VerticalOffset = lVertical;

			trdata = nextdata;
			trdata = GetALine( trdata,backn );	// Horiz Offset
			lHoriz = Text2Short( trdata );
			Entityptr->HorizontalOffset = lHoriz;

			trdata   = nextdata;
			trdata   = GetALine( trdata,backn );	// MissileFlag
			lMissile = Text2Short( trdata );
			Entityptr->MissileFlag = lMissile;

			ttlentity += ( 4*sizeof(short) );
			trdata    = nextdata;
			trdata    = GetALine( trdata,backn );	// Photo fname
			len       = strlen( trdata );
			tptr      = (char *)&Entityptr->PhotoFile[0];
			for ( i=0;i < len-1;i++ ) {
				*tptr = trdata[i];
				tptr++;
			}
			*tptr          = '\0';
			ttlentity      += 32;	// fix length
			Deschead->size = ttldesctxt;
			break;
		}
	}
}
static void _read_spp(const char *infile) {
    /* =================================================== */
    SW_VEGESTAB_INFO *v;
    const int nitems=15;
    FILE *f;
    int lineno=0 ;
    char name[80];  /* only allow 4 char sppnames */

    f = OpenFile(infile, "r");

    v = SW_VegEstab.parms[ _new_species() ];

    while( GetALine(f, inbuf) ) {
        switch(lineno) {
        case 0:
            strcpy(name, inbuf);
            break;
        case 1:
            v->estab_lyrs            = atoi(inbuf);
            break;
        case 2:
            v->bars[SW_GERM_BARS]    = fabs(atof(inbuf));
            break;
        case 3:
            v->bars[SW_ESTAB_BARS]   = fabs(atof(inbuf));
            break;
        case 4:
            v->min_pregerm_days      = atoi(inbuf);
            break;
        case 5:
            v->max_pregerm_days      = atoi(inbuf);
            break;
        case 6:
            v->min_wetdays_for_germ  = atoi(inbuf);
            break;
        case 7:
            v->max_drydays_postgerm  = atoi(inbuf);
            break;
        case 8:
            v->min_wetdays_for_estab = atoi(inbuf);
            break;
        case 9:
            v->min_days_germ2estab   = atoi(inbuf);
            break;
        case 10:
            v->max_days_germ2estab   = atoi(inbuf);
            break;
        case 11:
            v->min_temp_germ         = atof(inbuf);
            break;
        case 12:
            v->max_temp_germ         = atof(inbuf);
            break;
        case 13:
            v->min_temp_estab        = atof(inbuf);
            break;
        case 14:
            v->max_temp_estab        = atof(inbuf);
            break;
        }
        /* check for valid name first */
        if (0==lineno ) {
            if (strlen(name) > MAX_SPECIESNAMELEN) {
                LogError( logfp, LOGFATAL, "%s: Species name <%s> too long (> %d chars).\n"
                          "Try again.\n",
                          infile, name, MAX_SPECIESNAMELEN);
            } else {
                strcpy(v->sppname, name);
            }
        }

        lineno++;  /*only increments when there's a value */
    }

    if (lineno < nitems) {
        LogError(logfp, LOGFATAL, "%s : Too few input parameters.\n",infile);
    }

    CloseFile(&f);
}
Beispiel #26
0
static Bool _read_hist( TimeInt year) {
/* =================================================== */
/* Read the historical (measured) weather files.
* Format is
* day-of-month, month number, year, doy, mintemp, maxtemp, ppt
*
* I dislike the inclusion of the first three columns
* but this is the old format.  If a new format emerges
* these columns will likely be removed.
*
* temps are in degrees C, ppt is in cm,
*
* 26-Jan-02 - changed format of the input weather files.
*
*/

	SW_WEATHER_HIST *wh = &SW_Weather.hist;
	FILE *f;
	int x, lineno=0, k = 0, i, j;
	RealF tmpmax, tmpmin, ppt, acc = 0.0;
	TimeInt doy;
	
	char fname[MAX_FILENAMESIZE];
	
	
	sprintf(fname, "%s.%4d", SW_Weather.name_prefix, year);

	if ( NULL == (f = fopen(fname, "r")) )
		return FALSE;
	
	_clear_hist_weather();
	
	
	while( GetALine(f, inbuf) ) {
		lineno++;
		x=sscanf( inbuf, "%d %f %f %f", &doy, &tmpmax, &tmpmin, &ppt);
		if (x < 4) {
			LogError(logfp, LOGFATAL, "%s : Incomplete record %d (doy=%d).", fname, lineno, doy);
		}
		if (x > 4) {
			LogError(logfp, LOGFATAL, "%s : Too many values in record %d (doy=%d).", fname, lineno, doy);
		}
		if (doy < 1 || doy > MAX_DAYS) {
			LogError(logfp, LOGFATAL, "%s : Day of year out of range, line %d.", fname, lineno);
		}
	
	
		/* --- Make the assignments ---- */
		doy--;
		wh->temp_max[doy] = tmpmax;
		wh->temp_min[doy] = tmpmin;
		wh->temp_avg[doy] = (tmpmax + tmpmin) / 2.0;
		wh->ppt[doy]      = ppt;
		
		/* Reassign if invalid values are found.  The values are
		* either valid or WTH_MISSING.  If they were not
		* present in the file, we wouldn't get this far because
		* sscanf() would return too few items.
		*/
		if ( missing(tmpmax) ) {
			wh->temp_max[doy] = WTH_MISSING;
			LogError(logfp, LOGWARN, "%s : Missing max temp on doy=%d.", fname, doy+1);
		}
		if ( missing(tmpmin) ) {
			wh->temp_min[doy] = WTH_MISSING;
			LogError(logfp, LOGWARN, "%s : Missing min temp on doy=%d.", fname, doy+1);
		}
		if ( missing(ppt) ) {
			wh->ppt[doy] = 0.;
			LogError(logfp, LOGWARN, "%s : Missing PPT on doy=%d.", fname, doy+1);
		}
		
		if(!missing(tmpmax) && !missing(tmpmin)) {
			k++;
			acc += wh->temp_avg[doy];
		}
	}  /* end of input lines */
	
	wh->temp_year_avg = acc / (k + 0.0);
	
	x = 0;
	for( i=0; i < MAX_MONTHS; i++) {
		k = 31;
		if(i == 8 || i == 3 || i == 5 || i == 10)
			k = 30; // september, april, june, & november all have 30 days...
		else if(i == 1) {
			k = 28; // february has 28 days, except if it's a leap year, in which case it has 29 days...
			if(isleapyear(year))
				k = 29; 
		}
		
		acc = 0.0;
		for( j=0; j < k; j++)
			acc += wh->temp_avg[j + x];
		wh->temp_month_avg[i] = acc / (k + 0.0);
		x += k;
	}
	
	fclose(f);
	
	return TRUE;
}
void SW_MDL_read(void) {
/* =================================================== */
/*
 * 1/24/02 - added code for partial start and end years
 *
 * 28-Aug-03 (cwb) - N-S hemisphere flag logic changed.
 *    Can now specify first day of first year, last
 *    day of last year or hemisphere.  Code checks
 *    whether the first value is [NnSs] or number to
 *    make the decision.  If the value is numeric,
 *    the hemisphere is assumed to be N.  This method
 *    allows some degree of flexibility on the
 *    starting year
 */
   SW_MODEL *m = &SW_Model;
   FILE *f;
   int y, cnt;
   TimeInt d;
   char *p, enddyval[6];
   Bool fstartdy=FALSE, fenddy=FALSE, fhemi=FALSE;

   MyFileName = SW_F_name(eModel);
   f = OpenFile(MyFileName, "r");

   /* ----- beginning year */
   if (!GetALine(f, inbuf)) {
     LogError(logfp, LOGFATAL, "%s: No input.", MyFileName);
   }
   y = atoi(inbuf);
   if (y < 0) {
     LogError(logfp, LOGFATAL,
              "%s: Negative start year (%d)", MyFileName, y);
   }
   m->startyr = yearto4digit((TimeInt) y);

   /* ----- ending year */
   if (!GetALine(f, inbuf)) {
     LogError(logfp, LOGFATAL, "%s: Ending year not found.", MyFileName);
   }
   y = atoi(inbuf); assert( y > 0);
   if (y < 0) {
     LogError(logfp, LOGFATAL,
              "%s: Negative ending year (%d)", MyFileName, y);
   }
   m->endyr  = yearto4digit((TimeInt) y);
   if (m->endyr < m->startyr) {
     LogError(logfp, LOGFATAL, "%s: Start Year > End Year", MyFileName);
   }

   /* ----- Start checking for model time parameters */
   /*   input should be in order of startdy, enddy, hemisphere,
   		but if hemisphere occurs first, skip checking for the rest
   		and assume they're not there.
    */
   cnt=0;
   while (GetALine(f, inbuf) ) {
     cnt++;
     if (isalpha(*inbuf) && strcmp(inbuf, "end")) { /* get hemisphere */
       m->isnorth = (toupper((int)*inbuf) == 'N' );
       fhemi = TRUE;
       break;
     }
     switch (cnt) {
       case 1:
          m->startstart = atoi(inbuf);
          fstartdy = TRUE;
          break;
       case 2:
          p=inbuf; cnt=0;
          while( *p && cnt < 6) { enddyval[cnt++] = tolower((int)*(p++));}
          enddyval[cnt] = enddyval[5] = '\0';
          fenddy = TRUE;
          break;
       case 3:
          m->isnorth = (toupper((int)*inbuf) == 'N' );
          fhemi = TRUE;
          break;
       default: break;                     /* skip any extra lines */
     }
   }

   if (!(fstartdy && fenddy && fhemi) ) {
     sprintf(errstr, "\nNot found in %s:\n", MyFileName);
     if (!fstartdy) {
       strcat(errstr, "\tStart Day  - using 1\n");
       m->startstart = 1;
     }
     if (!fenddy) {
       strcat(errstr, "\tEnd Day    - using \"end\"\n");
       strcpy(enddyval, "end");
     }
     if (!fhemi) {
       strcat(errstr, "\tHemisphere - using \"N\"\n");
       m->isnorth = TRUE;
     }
     strcat(errstr, "Continuing.\n");
     LogError(logfp, LOGWARN, errstr);
   }

   m->startstart += ((m->isnorth) ? DAYFIRST_NORTH : DAYFIRST_SOUTH) -1;
	if ( strcmp(enddyval, "end")==0 ){
		m->endend = (m->isnorth) ? Time_get_lastdoy_y(m->endyr)  : DAYLAST_SOUTH;
	} else {
		d = atoi(enddyval);
		m->endend = (d < 365) ? d : Time_get_lastdoy_y(m->endyr); 
	}
     
   m->daymid     = (m->isnorth) ? DAYMID_NORTH   : DAYMID_SOUTH;
   CloseFile(&f);

}
static void _env_init( void) {
/*======================================================*/
/* Read environmental parameters that drive
   the abiotic conditions.  These values go
   into the Globals structure
*/
   FILE *f;
   int x,
       index=0,
       nitems,
       use[3];

   MyFileName = Parm_name(F_Env);
   f = OpenFile(MyFileName, "r");

   while( GetALine(f, inbuf)) {

      switch(++index) {
        case 1:
            x=sscanf( inbuf, "%f %f %hu %hu %hu %hu %f",
                      &Globals.ppt.avg, &Globals.ppt.std,
                      &Globals.ppt.min, &Globals.ppt.max,
                      &Globals.ppt.dry, &Globals.ppt.wet,
                      &Globals.gsppt_prop);
            nitems = 7;
            break;
        case 2:
            x=sscanf( inbuf, "%f %f %f %f",
                      &Globals.temp.avg, &Globals.temp.std,
                      &Globals.temp.min, &Globals.temp.max);
            nitems = 4;
            break;
        case 3:
            x=sscanf( inbuf, "%d %f %f %f %f ", &use[0],
                      &Globals.pat.occur, &Globals.pat.removal,
                      &Globals.pat.recol[Slope],
                      &Globals.pat.recol[Intcpt]);
            nitems = 4;
            break;
        case 4:
            x=sscanf( inbuf, "%d %f %hu %hu", &use[1],
                      &Globals.mound.occur,
                      &Globals.mound.minyr,
                      &Globals.mound.maxyr);
            nitems = 3;
            break;
        case 5:
            x=sscanf( inbuf, "%d %f %hu", &use[2],
                      &Globals.burrow.occur,
                      &Globals.burrow.minyr);
            nitems = 2;
            break;
        case 6:
            x=sscanf( inbuf, "%f %f %f %f %f %f",
                      &Globals.tempparm[CoolSeason][0],
                      &Globals.tempparm[CoolSeason][1],
                      &Globals.tempparm[CoolSeason][2],
                      &Globals.tempparm[WarmSeason][0],
                      &Globals.tempparm[WarmSeason][1],
                      &Globals.tempparm[WarmSeason][2]);
            nitems = 6;
            break;
      }
      if (x<nitems) {
         LogError(logfp, LOGFATAL, "%s: Invalid record %d",
                 MyFileName, index);
      }

   } /* end while*/

   Globals.pat.use    = itob(use[0]);
   Globals.mound.use  = itob(use[1]);
   Globals.burrow.use = itob(use[2]);

   CloseFile(&f);
}
Beispiel #29
0
/*GetALine follow squares intersecting the segment sg, until it reaches : 
-the border of the board, 
-an obstacle or 
-a square that insects the segment only one time (the segment can't go beyond it to neigbooring squares) 
*/
void SquareLine::GetALine()
{
	vector2d l_cornerspos[4]; //corners of a square
	board->GetSquareCornersInLogPx(s_cur,l_cornerspos);
	Segment sg2;
	int i,intersection_value ;
	vector2d ipoint;

	//foreach segment in the square, see intersection;
	for(i=0; i<4; i++)
	{
		if(i+1 == 4)
			sg2=Segment(l_cornerspos[i],l_cornerspos[0]);
		else
			sg2=Segment(l_cornerspos[i],l_cornerspos[i+1]);
		
		intersection_value = lines_intersect(sg,sg2, ipoint);

		ipoint.setint();

		if(intersection_value == 1 && ! (ipoint== p_lastipoint) )
		{
			if( ipoint == l_cornerspos[i] || ipoint == l_cornerspos[i+1])
			{
				vector2d g = sg.p1-ipoint;
				Square s;

				if(g.x>0)
				{
					if(g.y>0)
					{
						s=s_cur+vector2d(1,0);
						if(board->GetContentAt(s) ==  e_obstacle)
						{
							s=s_cur+vector2d(0,1);
							if(board->GetContentAt(s) ==  e_obstacle)
							{
								return;
							}
							else
							{
								pl_squares->push_back(s);
							}
						}
						else
						{
							pl_squares->push_back(s);
						}

						s_cur=s_cur+vector2d(1,1);
					}
					else if(g.y<0)
					{
						s=s_cur+vector2d(1,0);
						if(board->GetContentAt(s) ==  e_obstacle)
						{
							s=s_cur+vector2d(0,-1);
							if(board->GetContentAt(s) ==  e_obstacle)
							{
								return;
							}
							else
							{
								pl_squares->push_back(s);
							}
						}
						else
						{
							pl_squares->push_back(s);
						}

						s_cur=s_cur+vector2d(1,-1);
					}
					else
						assert(0); //this means that the line coincides with the x-axis. and this is not possible since the destination point is a square center.
				}
				else if(g.x<0)
				{
					if(g.y>0)
					{
						s=s_cur+vector2d(-1,0);
						if(board->GetContentAt(s) ==  e_obstacle)
						{
							s=s_cur+vector2d(0,1);
							if(board->GetContentAt(s) ==  e_obstacle)
							{
								return;
							}
							else
							{
								pl_squares->push_back(s);
							}
						}
						else
						{
							pl_squares->push_back(s);
						}
						s_cur=s_cur+vector2d(-1,1);
					}
					else if(g.y<0)
					{
						s=s_cur+vector2d(-1,0);
						if(board->GetContentAt(s) ==  e_obstacle)
						{
							s=s_cur+vector2d(0,-1);
							if(board->GetContentAt(s) ==  e_obstacle)
							{
								return;
							}
							else
							{
								pl_squares->push_back(s);
							}
						}
						else
						{
							pl_squares->push_back(s);
						}
						s_cur=s_cur+vector2d(-1,-1);
					}
					else
						assert(0); //this means that the line coincides with the x-axis. and this is not possible since the destination point is a square center.
				}
				else
					assert(0); //this means that the line coincides with the y-axis. and this is not possible since the destination point is a square center.
			}
			else if(i==0)
			{
				s_cur=s_cur+vector2d(0,-1);
			}
			else if(i==1)
			{
				s_cur=s_cur+vector2d(1,0);
			}
			else if(i==2)
			{
				s_cur=s_cur+vector2d(0,1);
			}
			else
			{
				s_cur=s_cur+vector2d(-1,0);
			}

			p_lastipoint=ipoint;

			break;
		}
	}

	if(!NotOutOfBoard(s_cur) || board->GetContentAt(s_cur) ==  e_obstacle)
	{
		return;
	}

	if(i==4) 
	{//when i == 4, it's the last square touched by the segment sg.
		return;
	}

	pl_squares->push_back(s_cur);
	
	GetALine();

}
// Process Begin Text token
void DoBegText()
{
	short len,lcount;
	short i;
	char  *tptr;
	char  *endmark = "END_TEXT";
	char  *newlnptr;
	char  *token;
	long  lXrefGroup,lXrefSubGroup,lEntityID;

	curtxtidx  = 0;	// currently Not Used
	if ( where == _CATEGORY_ ) {	//
		Stringhead = new Header;
		CatStrKeep[curcatidx] = (char *)Stringhead;
		Stringhead->type      = tokmap[toktype];
		ttlentity  += (2*sizeof(short));
		ttlstat    += (2*sizeof(short));
		ttlcat     += (2*sizeof(short));

	trdata = nextdata;
	token  = strtok( trdata, backn );	// get 1st token
	lcount = 0;
	/* While there are tokens in "string" */
	while ( token ) {
		if (strncmp( token,endmark,strlen(endmark) )) {
			/* Not Endmark, Get next token: */
			//if ( !strncmp(token,"Propulsion: 2 Gas",17)) { // just checking
			//	len = 0;
			//}
			lcount++;	// count how many text strings are inside this block of TEXT
			CatInTxtptr = new Text4CatString;
			CatInTxtKeep[curcatidx][curintxtidx] = (char *)CatInTxtptr;

			len  = strlen( token );
			if ( len == 1 ) len++;
			CatInTxtptr->length = len;
			CatInChildTxt       = new char[len];
			CatInChildKeep[curcatidx][curintxtidx] = CatInChildTxt;
			tptr = CatInChildTxt;
			for ( i=0;i < len-1;i++ ) {
				*tptr = token[i];
				tptr++;
			}
			*tptr         = '\0';
			ttlentity     += len;
			ttlstat       += len;
			ttlcat        += len;
			ttlcatstrhead += len;
			//
			token = strtok( NULL, backn );
			if ( token ) newlnptr = token;
			if ( (strncmp(token,"END_TEXT",8)) ) {
				// more text string in this block
				curintxtidx++;
			}
		}
		else {	// End mark found, look ahead
			// get the 3 xrefs
			trdata     = token+strlen(token)+1;
			trdata     = GetALine( trdata,backn );	// XrefGroup
			lXrefGroup = Text2Long( trdata );
			CatInTxtptr->GroupID = lXrefGroup;

			trdata        = nextdata;
			trdata        = GetALine( trdata,backn );	// XrefSubGroup
			lXrefSubGroup = Text2Long( trdata );
			CatInTxtptr->SubGroupID = lXrefSubGroup;

			trdata    = nextdata;
			trdata    = GetALine( trdata,backn );	// XrefVehicle or EntityID
			lEntityID = Text2Long( trdata );
			CatInTxtptr->EntityID = lEntityID;

			ttlentity     += (lcount* (sizeof(short)+(3*sizeof(long))) );	// 11/23/98
			ttlstat       += (lcount* (sizeof(short)+(3*sizeof(long))) );
			ttlcat        += (lcount* (sizeof(short)+(3*sizeof(long))) );
			ttlcatstrhead += (lcount* (sizeof(short)+(3*sizeof(long))) );
			lcount        = 0;	// reset

			tptr = nextdata;
			if ( !(strncmp(tptr,"END_CAT",7)) ) { // no more text block, the end of a Cat
				trdata = tptr;
				curintxtidx++;
				break;
			}
			else {
				token = tptr;
				token = strtok( token, backn );
				token = strtok( NULL, backn );	// points 2 text
				curintxtidx++;
			}
		}
	}
	// Look ahead if there is more Cat
	token = trdata;
	token = strtok( token, backn );
	token = strtok( NULL, backn );
	if ( !(strncmp(token,"BEGIN_CAT",9)) ) {
		trdata           = token;	// more Cat
		nextdata         = token;
		Cathead->size    = ttlcat;	// save previous Cat chunk size
		ttlcat           = 0;	// reset 4 next cat
		Stringhead->size = ttlcatstrhead;
		ttlcatstrhead    = 0;
		catintxtidxkeep[curcatidx] = curintxtidx;
		curintxtidx      = 0;	// NEED 2 save this first
		curcatidx++;
		return;
	}

	// Advance to Description text
	/* While there are tokens in "string" */
	catintxtidxkeep[curcatidx] = curintxtidx;	// 4 the last Cat
	Cathead->size    = ttlcat;	// save previous Cat chunk size
	ttlcat           = 0;
	Stringhead->size = ttlcatstrhead;
	ttlcatstrhead    = 0;
	curcatidx++;	// 4 loop sake
	while ( token ) {
		if (strncmp( token,"BEGIN_TEXT",10 )) {
			/* Not Description Text yet, Get next token */
			token = strtok( NULL, backn );
			if ( token ) newlnptr = token;
		}
		else { // Beginning of Description text found
			Stathead->size = ttlstat;
			trdata         = token;
			nextdata       = token;
			where          = _ENDSTAT_;
			// Do the description here
			DoDescript();
			break;
		}
	}


	// put back linefeed since it's replaced
	len = strlen( token );	// does nothing, just 4 debugging
	//token[len] = 0x0A;

	} // ENDIF Category
}