Example #1
0
/*{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}
* Name: SD_Init
* Desc: Most of the init values come from the sr_SE table, selected
*        based on the Soil Type name.
*       Other inputs come from user in the s_SI struct
* Note-1: We'll be running Duff Sim because we had some duff but the fire
*         didn't consume any of it so we fake a small amount to create a
*         little bit of heat
* Note-2: It was decided that any remaining/post duff depth that we get from
*         our fuel calculations would act as an insulator allowing only
*         some much heat to pass thru, so these lines of code deal with that.
*   In: a_SI......soil input structure
{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{**/
int  SD_Init (d_SD *a_SD,  d_SI *a_SI,  char cr_ErrMes[])
{
int i;
REAL  r, r_Post, r_Pre, r_Con;

   gf_Heatpc = 0;                                /* Heat percent            */

/* Use Soil Type, get Duff Sim param record from table                       */
   for ( i = 0;  i < 100; i++ ) {                /* find match in table     */
     if ( !strcmp (sr_SD[i].cr_Name,"")) {       /* Hit end and didn't find */
       sprintf (cr_ErrMes,"SD_Init() - Invalid Soil Type: %s ", a_SI->cr_SoilType);
       return 0; }
     if ( !strcmp (sr_SD[i].cr_Name,a_SI->cr_SoilType)){ /* Copy out                */
       memcpy (a_SD,&sr_SD[i],sizeof(d_SD));
       break; } }

/* Set burntimes based on Moisture Condtion                                  */
   if (!xstrcmpi (a_SI->cr_MoistCond,e_Wet)){
     a_SD->i_burntime = 240;
     a_SD->i_midburn  = 300;}

   else if (!xstrcmpi (a_SI->cr_MoistCond,e_Moderate)) {
     a_SD->i_burntime = 120;
     a_SD->i_midburn  = 200;}

   else if ( !xstrcmpi (a_SI->cr_MoistCond,e_VeryDry) ||
             !xstrcmpi (a_SI->cr_MoistCond,e_Dry)) {
     a_SD->i_burntime = 80;
     a_SD->i_midburn  = 150;}
   else {
      sprintf (cr_ErrMes,"Invalid Moisture Condition: %s", a_SI->cr_MoistCond);
      return 0; }

/* Check Soil Moisture and set starting water content                        */
   if ( a_SI->f_SoilMoist > e_SMV_Max || a_SI->f_SoilMoist < e_SMV_Min ){
      sprintf (cr_ErrMes,"Soil Moisture %6.2f is out of range (%3.0f to %3.0f)", a_SI->f_SoilMoist, e_SMV_Min, e_SMV_Max);
      return 0; }
   a_SD->r_startwc = a_SI->f_SoilMoist / 100;    /* get it in decimal       */

   r_Post = a_SI->f_DufDepPos;               /* Post Duf Dep from Fuel Calc  */
   r_Pre = a_SI->f_DufDepPre;                /* Pre-Fire Duff Depth          */
   r_Con = r_Pre - r_Post;                   /* Consumed Duff Depth          */

/* Set the Duff Consumed amount                                              */
   if ( r_Con == 0 )                         /* see Note-1 above             */
     r_Con = e_MinDufCon;
   a_SD->r_ConDufDep = InchtoMeter (r_Con);  /* Need it in Meter fraction    */

/* Set Duff Heat Content                                                     */
   r = SD_HeatAdj (r_Post);                  /* based on remaining duf dep   */
   gf_Heatpc = r;                            /* save this                    */
   a_SD->r_duffheat = a_SD->r_duffheat * r;  /* use % of heat to use, Note-2 */

/* Init the Layer and Display arrays....                                     */
   SH_Init_LayDis (a_SD->rr_z, a_SD->rr_node);

   return 1;
}
Example #2
0
/*{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}
* Name: SH_Mngr
* Desc: Run Soil simulation. Will run the Duff or the Exp simulation
*        code, based on presence of Duff.
* Note Duff Sim:
*        The Fuel has to be run before coming here, because the Fuel
*        calculates the Post Duff Depth which DUff Sim needs to run.
* Note Exp Heat:
*        The Fuel has to be run before coming here, which should
*        have detected the no Duff Depth/Load and run burnup which calculates
*        the heat and time need by Exp Heat.
* Note-1: There use to be some Error_Window() type logic errors in the
*          soil code, it would have been hard and not worth it to do them
*          thru the functions so I did a global string.
*   In: a_SI......
*
*  Ret: 1 Ok,   0 Error
{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{**/
int WINAPI  SH_Mngr (d_SI *a_SI, d_SO *a_SO, char cr_TmpFN[], char cr_ErrMes[])
{
d_SD s_SD;
d_SE s_SE;
char cr[40];

  strcpy (gcr_SoiErr,"");
  SO_Init (a_SO);                            /* Init the output struct       */

  if ( !xstrcmpi(a_SI->cr_BrnIg,"NO")) {      /* Burnup ran & didn't ignite   */
    SHA_Init_0 ();                           /* so 0 out this arrary so that */
    return 1; }                              /* 0s come out in the report    */

  SHA_Init ();                               /* Init the Soil Heat Temp Array*/

  if ( a_SI->f_DufDepPre > 0 )               /* Prefire Duff depth determines*/
     goto DuffSim;                           /* if we run Duff or Exp simulat*/

/*.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.*/
/* Do the Exp Heat, because there is no duff depth                           */
  strcpy (a_SO->cr_Model,e_SM_ZDuff);           /* tells what soil model     */

  if ( !SE_Init (a_SI, &s_SE, cr_ErrMes))       /* Ready the SE input struct */
     return 0;

  if ( !SE_Mngr (&s_SE,cr_TmpFN,cr_ErrMes))     /* Run it, makes Pt arrar& File */
     return 0;

  goto Load;

/*.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.*/
/* Do the Duff Simulation Modes                                              */
DuffSim:
  strcpy (a_SO->cr_Model,e_SM_Duff);

  if ( !SD_ChkSoiDuf(a_SI->f_DufDepPre, a_SI->f_DufDepPos, cr_ErrMes) )
    return 0;

  if ( !SD_Init (&s_SD, a_SI, cr_ErrMes))
     return 0;

/* Duff Sim is done when there is a Duff Depth to use....................... */
  if ( !SD_Mngr(&s_SD,cr_TmpFN,cr_ErrMes))   /* Run Soil Duff Simulation     */
    return 0;

Load:
  SO_Load (a_SI, a_SO);                      /* Get Soil Outputs             */
  if ( strcmp (gcr_SoiErr,"") ) {            /* See Note-1 above             */
     strcpy (cr_ErrMes,gcr_SoiErr);
     return 0; }
  return 1;
}
Example #3
0
int make_condition (char *argv, CONDITION **head)
{
  const char *delim="<>=!";
  
  int i,j;
  int op_id;
  CONDITION *new_condition;
  char *var;
  char *op;
  char *val;
  
  *head=NULL;
  
  j=0;
  while (argv[j])
  {
    for (i=j;argv[j] && isspace(argv[j]);j++);
    for (i=j;argv[j] && !isspace(argv[j]) && !strchr(delim,argv[j]);j++);
    if (i==j)
    {
      printf ("Error: undefined argument\n");
      return -1;
    }
    var=mem2str(argv+i, j-i);
    if ((xstrcmpi(var,"AND"))==0)
    {
      free (var);
      continue;
    }
    
    for (i=j;argv[j] && isspace(argv[j]);j++);
    for (i=j;argv[j] && strchr(delim,argv[j]) ;j++);
    if (i==j)
    {
      printf ("error: undefined operator for the argument ā€˜%sā€™\n",var);    
      free (var);
      return -1;
    }
    op=mem2str(argv+i, j-i);
    if ((op_id=check_op (op,var))<0)
    {
      free (var);
      free (op);
      return -1;
    }
    
    for (i=j;argv[j] && isspace(argv[j]);j++);
    if (argv[j]=='\'')
    {
      for (i=++j;argv[j] && argv[j]!='\'';j++);
      if (!argv[j])
      {
        printf ("Error: unclosed single quote\n");
        free (var);
        free (op);
        return -1;
      }
    }
    else 
      for (i=j;argv[j] && !isspace(argv[j]);j++);
      
    if (i==j)
    {
      printf ("error: undefined value for the argument ā€˜%s %sā€™\n",var,op);    
      free (var);
      free (op);
      return -1;
    }
    val=mem2str(argv+i, j-i);
    if (argv[j]=='\'') 
      j++;
    
    for (i=j;argv[j] && isspace(argv[j]);j++);
    
    if ((new_condition=xmalloc (sizeof(CONDITION)))==NULL)
      return -1;
    
    new_condition->var=var;
    new_condition->var_id=0;
    new_condition->op=op;
    new_condition->op_id=op_id;
    new_condition->val=val;
    new_condition->next=*head;
    
    *head=new_condition;
   
  }
  return 0;
}
Example #4
0
int dbf_show_records (DBF *dbf)
{
  int i,err=0;
  double cmp;
  int len;
  ui32 position;
  CONDITION *p;
  
  char cmd[256];
  char tmpname [L_tmpnam]="/tmp/dbf2txt-XXXXXX";
  FILE *fp;
  
  /* Set var_id */
  for (p=dbf->condition;p;p=p->next)
  {
    for (i=0;i<dbf->NumberOfFields;i++)
    {
      if ((xstrcmpi (dbf->sub_header[i]->FieldName,p->var))==0)
      {
        p->var_id=i;
        break;
      }
    }
    if (i==dbf->NumberOfFields)
    {
      printf ("field \'%s\' not found in archive dbf\n",p->var);
      err=-1;
    }
  }
  if (err)
    return err;


  if ((mkstemp(tmpname))<0)
  {
    perror ("mkstemp");
    return -1;
  }
  if ((fp=fopen (tmpname,"w"))==NULL)
  {
    printf ("Cannot open `%s`\n",tmpname);
    perror ("");
    return -1;
  }
    
  /* Applying conditions */
  dbf->NumberOfRecords=0;
  for (i=1;i<=dbf->header->NumberOfRecords;i++)
  {
    _dbf_load_record (dbf->fp_in, dbf->header, dbf->record, i, dbf->header->LengthOfOneDataRecord);
    if (_dbf_isdelete(dbf->record)>0)
      continue;
    
    p=dbf->condition;
    
    while (p)
    {
      position=char2ui32(dbf->sub_header[p->var_id]->DisplacementOfFieldInRecord);
      len=LengthOfField(dbf->sub_header[p->var_id]);
      if (_dbf_isnumeric(dbf->sub_header[p->var_id]))
        cmp=(strtod(dbf->record+position,NULL) - strtod(p->val,NULL));
      else
        cmp=(double)strncmp (dbf->record+position,p->val,strlen(p->val));
    
      if ( (p->op_id==EQ && cmp==0) || (p->op_id==LT && cmp<0) || 
           (p->op_id==LE && cmp<=0) || (p->op_id==GT && cmp>0) || 
           (p->op_id==GE && cmp>=0) || (p->op_id==NE && cmp!=0) )
        p=p->next;     
      else
        break;
      
    }
    if (p==NULL)
    {
      dbf->NumberOfRecords++;
      dbf_push_record (dbf, i, fp);
    }
  }
  fclose (fp);
  
  if (dbf->NumberOfRecords==0)
  {
    printf ("Record not found!\n");
    return 0;
  }

  sprintf (cmd,"LC_COLLATE=C sort %s -k2",tmpname);
  fp=popen (cmd, "r");
 
  err=dbf_dump (dbf,fp,tmpname);

  return err;
        
}