This commit is contained in:
2007-06-01 15:07:24 +00:00
parent 079d097fb2
commit 736a5b384f

View File

@ -5,7 +5,11 @@
static ecotx_t *readnext_ecotaxon(FILE *f,ecotx_t *taxon);
/**
* Open the taxonomy database
* @param pointer to the database (.tdx file)
* @return a ecotxidx_t structure
*/
ecotxidx_t *read_taxonomyidx(const char *filename)
{
int32_t count;
@ -22,10 +26,12 @@ ecotxidx_t *read_taxonomyidx(const char *filename)
for (i=0; i < count; i++)
readnext_ecotaxon(f,&(index->taxon[i]));
index->taxon[i].parent=index->taxon + (int32_t)index->taxon[i].parent;
return index;
}
int32_t delete_taxonomy(ecotxidx_t *index)
{
int32_t i;
@ -61,6 +67,15 @@ int32_t delete_taxon(ecotx_t *taxon)
return 1;
}
/**
* Read the database for a given taxon a save the data
* into the taxon structure(if any found)
* @param *f pointer to FILE type returned by fopen
* @param *taxon pointer to the structure
*
* @return a ecotx_t structure if any taxon found else NULL
*/
ecotx_t *readnext_ecotaxon(FILE *f,ecotx_t *taxon)
{
@ -80,7 +95,7 @@ ecotx_t *readnext_ecotaxon(FILE *f,ecotx_t *taxon)
raw->taxid = swap_int32_t(raw->taxid);
}
taxon->parent = raw->parent;
taxon->parent = (ecotx_t*)raw->parent;
taxon->taxid = raw->taxid;
taxon->rank = raw->rank;
@ -119,6 +134,8 @@ ecotaxonomy_t *read_taxonomy(const char *prefix)
}
int32_t delete_ecotaxonomy(ecotaxonomy_t *taxonomy)
{
if (taxonomy)
@ -138,20 +155,19 @@ int32_t delete_ecotaxonomy(ecotaxonomy_t *taxonomy)
}
ecotx_t *eco_findtaxonatrank(ecotx_t *taxon,
int32_t rankidx,
ecotaxonomy_t *taxonomy)
int32_t rankidx)
{
ecotx_t *current_taxon;
ecotx_t *next_taxon;
current_taxon = taxon;
next_taxon = &(taxonomy->taxons->taxon[current_taxon->parent]);
next_taxon = current_taxon->parent;
while ((current_taxon!=next_taxon) &&
while ((current_taxon!=next_taxon) && // I' am the root node
(current_taxon->rank!=rankidx))
{
current_taxon = next_taxon;
next_taxon = &(taxonomy->taxons->taxon[current_taxon->parent]);
next_taxon = current_taxon->parent;
}
if (current_taxon->rank==rankidx)
@ -175,7 +191,7 @@ ecotx_t *eco_getspecies(ecotx_t *taxon,
if (!tax || rankindex < 0)
ECOERROR(ECO_ASSERT_ERROR,"No taxonomy defined");
return eco_findtaxonatrank(taxon,rankindex,tax);
return eco_findtaxonatrank(taxon,rankindex);
}
ecotx_t *eco_getgenus(ecotx_t *taxon,
@ -193,7 +209,7 @@ ecotx_t *eco_getgenus(ecotx_t *taxon,
if (!tax || rankindex < 0)
ECOERROR(ECO_ASSERT_ERROR,"No taxonomy defined");
return eco_findtaxonatrank(taxon,rankindex,tax);
return eco_findtaxonatrank(taxon,rankindex);
}
@ -212,7 +228,7 @@ ecotx_t *eco_getfamily(ecotx_t *taxon,
if (!tax || rankindex < 0)
ECOERROR(ECO_ASSERT_ERROR,"No taxonomy defined");
return eco_findtaxonatrank(taxon,rankindex,tax);
return eco_findtaxonatrank(taxon,rankindex);
}
ecotx_t *eco_getkingdom(ecotx_t *taxon,
@ -230,7 +246,7 @@ ecotx_t *eco_getkingdom(ecotx_t *taxon,
if (!tax || rankindex < 0)
ECOERROR(ECO_ASSERT_ERROR,"No taxonomy defined");
return eco_findtaxonatrank(taxon,rankindex,tax);
return eco_findtaxonatrank(taxon,rankindex);
}
ecotx_t *eco_getsuperkingdom(ecotx_t *taxon,
@ -248,5 +264,5 @@ ecotx_t *eco_getsuperkingdom(ecotx_t *taxon,
if (!tax || rankindex < 0)
ECOERROR(ECO_ASSERT_ERROR,"No taxonomy defined");
return eco_findtaxonatrank(taxon,rankindex,tax);
return eco_findtaxonatrank(taxon,rankindex);
}