📄 firelib.c
字号:
{12, FIRE_TYPE_DEAD, 0.6440, 109.},
{12, FIRE_TYPE_DEAD, 0.7590, 30.},
{13, FIRE_TYPE_DEAD, 0.3220, 1500.},
{13, FIRE_TYPE_DEAD, 1.0580, 109.},
{13, FIRE_TYPE_DEAD, 1.2880, 30.},
};
/* First, create the catalog. */
if ( maxModels < 13 )
maxModels = 13;
if ( (catalog = Fire_FuelCatalogCreate(name, maxModels)) == NULL )
return (NULL);
/* Second, create all 14 models. */
adjust = 1.0;
for ( m=0; m<14; m++ )
{
if ( Fire_FuelModelCreate(catalog, m, M[m].name, M[m].desc, M[m].depth,
M[m].mext, adjust, M[m].maxParticles) != FIRE_STATUS_OK )
{
fprintf(stderr, "%s\n", FuelCat_Error(catalog));
Fire_FuelCatalogDestroy(catalog);
return (NULL);
}
}
/* Finally, add all the fuel particles. */
stot = 0.0555;
seff = 0.0100;
heat = 8000.0;
dens = 32.0;
for ( p=0; p<39; p++ )
{
if ( Fire_FuelParticleAdd(catalog, P[p].model, P[p].type, P[p].load,
P[p].savr, dens, heat, stot, seff) != FIRE_STATUS_OK )
{
fprintf(stderr, "%s\n", FuelCat_Error(catalog));
Fire_FuelCatalogDestroy(catalog);
return (NULL);
}
}
return (catalog);
}
/*
*******************************************************************************
*
* Fire_FuelCatalogDestroy()
*
* Description
* Destroys the fuel catalog and all its associated models and particles.
*
* Side Effects
* Destroys all FuelData instances belonging to the catalog.
* Frees the array of pointers to FuelData structures.
* Frees the catalog name.
* Frees the catalog error text buffer.
* Frees the FuelCatalog instance.
*
* Function Returns
* FIRE_STATUS_OK or FIRE_STATUS_ERROR.
* Return status and error text are stored in the Fire Catalog's buffers.
*
*******************************************************************************
*/
int
Fire_FuelCatalogDestroy ( FuelCatalogPtr catalog )
// FuelCatalogPtr catalog; /* FuelCatalogData instance to destroy. */
{
size_t model;
/* Validate the catalog. */
assert(catalog!=NULL && FuelCat_MagicCookie(catalog)==FIRE_CATALOG_MAGIC);
/* First destroy all the fuel models in this catalog. */
/* The free the catalog's array of FuelData pointers. */
if ( FuelCat_ModelArray(catalog) )
{
for ( model=0; model <= FuelCat_MaxModels(catalog); model++ )
{
if ( FuelCat_ModelPtr(catalog,model) )
Fire_FuelModelDestroy(catalog, model);
}
free(FuelCat_ModelArray(catalog));
FuelCat_ModelArray(catalog) = NULL;
}
/* Next destroy the flame length table. */
if ( FuelCat_FlameArray(catalog) )
{
free(FuelCat_FlameArray(catalog));
FuelCat_FlameArray(catalog) = NULL;
FuelCat_FlameClasses(catalog) = 0;
FuelCat_FlameStep(catalog) = 0.0;
}
/* Then free the name and error buffer for this FuelCatalogData instance. */
if ( FuelCat_Error(catalog) )
{
free(FuelCat_Error(catalog));
FuelCat_Error(catalog) = NULL;
}
if ( FuelCat_Name(catalog) )
{
free(FuelCat_Name(catalog));
FuelCat_Name(catalog) = NULL;
}
/* Finally,free the FuelCatalogData instance and return. */
free(catalog);
return (FuelCat_Status(catalog) = FIRE_STATUS_OK);
}
/*
*******************************************************************************
*
* Fire_FuelModelCreate()
*
* Description
* Creates a new fuel model able to hold maxParticles fuel particles.
* Fuel particles are subsequently added by Fire_FuelParticleAdd().
*
* Side Effects
* Any existing fuel model with modelId in the Fuel Catalog is destroyed.
* Allocates the fuel model's FuelData block.
* Allocates the fuel model's name string.
* Allocates the fuel model's description string.
* Allocates the fuel model's fuel particle pointer array of maxParticles
* (the FuelParticleData blocks are actually allocated within
* Fire_FuelparticleAdd() and thier pointers stored in this array).
* The fuel model's address is stored in the fuel catalog's pointer array.
*
* Function Returns
* FIRE_STATUS_OK or FIRE_STATUS_ERROR.
* Return status and error text are stored in the Fire Catalog's buffers.
*
*******************************************************************************
*/
int
Fire_FuelModelCreate (FuelCatalogPtr catalog, size_t model, char *name, char *desc, double depth, double mext, double adjust, size_t maxParticles)
// FuelCatalogPtr catalog; /* FuelCatalogData instance */
// size_t model; /* fuel model number [0-maxModels] */
// char *name; /* short name */
// char *desc; /* longer description */
// double depth; /* bed depth (ft) */
// double mext; /* moisture of extinction (dl) */
// double adjust; /* spread adjustment factor (dl) */
// size_t maxParticles; /* maximum number of fuel model particles */
{
static char *blank = {""};
size_t particle;
/* Validate the catalog. */
assert(catalog!= NULL && FuelCat_MagicCookie(catalog)==FIRE_CATALOG_MAGIC);
/* Make sure model id is within range. */
if ( model > FuelCat_MaxModels(catalog) )
{
sprintf(FuelCat_Error(catalog),
"Fire_FuelModelCreate(): fuel model \"%s\" number %d exceeds fuel catalog \"%s\" range [0..%d].",
name, model, FuelCat_Name(catalog), FuelCat_MaxModels(catalog));
return (FuelCat_Status(catalog) = FIRE_STATUS_ERROR);
}
/* Validate depth and mext. */
if ( depth < Smidgen )
{
sprintf(FuelCat_Error(catalog),
"Fire_FuelModelCreate(): el modelo de combustible \"%s\" n鷐ero %d de ancho %5.4f es demasiado peque駉.",
name, model, depth);
return (FuelCat_Status(catalog) = FIRE_STATUS_ERROR);
}
if ( mext < Smidgen )
{
sprintf(FuelCat_Error(catalog),
"Fire_FuelModelCreate(): el modelo de combustible \"%s\" n鷐ero %d de humedad de extinci髇 %5.4f es demasiado peque駉.",
name, model, mext);
return (FuelCat_Status(catalog) = FIRE_STATUS_ERROR);
}
/* If this model already exists, delete it. */
if ( FuelCat_ModelPtr(catalog,model) )
Fire_FuelModelDestroy(catalog, model);
/* Allocate the model's FuelData structure. */
if ( maxParticles < 1 )
maxParticles = 1;
if ( (FuelCat_ModelPtr(catalog,model) =
(FuelModelPtr) calloc(1, sizeof(FuelModelData))) == NULL
|| (Fuel_ParticleArray(catalog,model) =
(PartPtr *) calloc(maxParticles, sizeof(PartPtr))) == NULL )
{
Fire_FuelModelDestroy(catalog, model);
sprintf(FuelCat_Error(catalog),
"Fire_FuelModelCreate(): imposible asignar el modelos de combustible \"%s\" n鷐ero %d para el cat醠ogo de combustibles \"%s\".",
name, model, FuelCat_Name(catalog));
return (FuelCat_Status(catalog) = FIRE_STATUS_ERROR);
}
/* Catch NULL names and descriptions. */
if ( name == NULL )
name = blank;
if ( desc == NULL )
desc = blank;
/* Store remaining attributes. */
Fuel_Model(catalog,model) = model;
Fuel_Depth(catalog,model) = depth;
Fuel_Mext(catalog,model) = mext;
Fuel_SpreadAdjustment(catalog,model) = adjust;
Fuel_Name(catalog,model) = strdup(name);
Fuel_Desc(catalog,model) = strdup(desc);
Fuel_CombustionFlag(catalog,model) = 0;
Fuel_MaxParticles(catalog,model) = maxParticles;
Fuel_Particles(catalog,model) = 0;
for ( particle=0; particle<Fuel_MaxParticles(catalog,model); particle++ )
Fuel_ParticlePtr(catalog,model,particle) = NULL;
return (FuelCat_Status(catalog) = FIRE_STATUS_OK);
}
/*
*******************************************************************************
*
* Fire_FuelModelDestroy()
*
* Description
* Deletes the specified fuel model.
* Note: this is one of only 3 functions that use the modelId instead
* of a FuelData pointer to identify the model.
*
* Side Effects
* Free's all fuel particles added to the fuel model.
* Free's the fuel particle pointer array.
* Free's the fuel model's name.
* Free's the fuel model's description.
* Free's the fuel model's FuelData block.
* Sets the Fuel Catalog's pointer for this fuel model to NULL.
*
* Function Returns
* FIRE_STATUS_OK or FIRE_STATUS_ERROR.
* Return status and error text are stored in the Fire Catalog's buffers.
*
*******************************************************************************
*/
int
Fire_FuelModelDestroy ( FuelCatalogPtr catalog, size_t model )
// FuelCatalogPtr catalog; /* FuelCatalogData instance pointer */
// size_t model; /* fuel model id number [0-maxModels] */
{
size_t particle;
/* Validate the catalog. */
assert(catalog!= NULL && FuelCat_MagicCookie(catalog)==FIRE_CATALOG_MAGIC);
/* Make sure model id is within range and exists. */
if ( ! Fire_FuelModelExists(catalog,model) )
{
sprintf(FuelCat_Error(catalog),
"Fire_FuelModelDestroy(): el modelo de combustible %d no existe en el cat醠ogo de combustibles \"%s\".",
model, FuelCat_Name(catalog));
return (FuelCat_Status(catalog) = FIRE_STATUS_ERROR);
}
/* Free all the fuel model particles and their pointer array. */
if ( Fuel_ParticleArray(catalog,model) )
{
for (particle=0; particle<Fuel_MaxParticles(catalog,model); particle++)
{
if ( Fuel_ParticlePtr(catalog,model,particle) )
{
free(Fuel_ParticlePtr(catalog,model,particle));
Fuel_ParticlePtr(catalog,model,particle) = NULL;
}
}
free(Fuel_ParticleArray(catalog,model));
Fuel_ParticleArray(catalog,model) = NULL;
}
/* Free the fuel model name and description. */
if ( Fuel_Name(catalog,model) )
{
free(Fuel_Name(catalog,model));
Fuel_Name(catalog,model) = NULL;
}
if ( Fuel_Desc(catalog,model) )
{
free(Fuel_Desc(catalog,model));
Fuel_Desc(catalog,model) = NULL;
}
/* Now free the FuelData instance and reset its catalog entry. */
free(FuelCat_ModelPtr(catalog,model));
FuelCat_ModelPtr(catalog,model) = NULL;
return (FuelCat_Status(catalog) = FIRE_STATUS_OK);
}
/*
*******************************************************************************
*
* Fire_FuelModelExists()
*
* Description
* Performs a sanity check to make sure the catalog pointer is valid
* and the fuel model number is within range and exists.
*
* Side Effects
* None.
*
* Function Returns
* 1 if "model" exists, 0 if it is undefined.
*
*******************************************************************************
*/
int
Fire_FuelModelExists ( FuelCatalogPtr catalog, size_t model )
// FuelCatalogPtr catalog; /* FuelCatalogData instance pointer */
// size_t model; /* fuel model id number [0-maxModels] */
{
/* Validate the model number. */
if ( model > FuelCat_MaxModels(catalog)
|| ! FuelCat_ModelPtr(catalog,model) )
return (int) 0;
return (int) 1;
}
/*
****************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -