feature.c File Reference

#include <stdlib.h>
#include "string.h"
#include "anamod.h"
#include "petsc.h"

Include dependency graph for feature.c:

Go to the source code of this file.

Data Structures

struct  FeatureSet_
struct  FeatureValues_

Defines

#define NALLOC   25
#define FSETCOOKIE   9876
#define CHECKVALIDFSET(i)   {ANAMODCHECKVALID(i,FSETCOOKIE,"feature set");}
#define FVALCOOKIE   9877
#define CHECKVALIDFVAL(i)   {ANAMODCHECKVALID(i,FVALCOOKIE,"feature values");}

Functions

PetscErrorCode NewFeatureSet (FeatureSet *set)
PetscErrorCode DeleteFeatureSet (FeatureSet set)
PetscErrorCode AddToFeatureSet (FeatureSet set, char *cat, char *cmp, int *idx)
PetscErrorCode NewFeatureValues (FeatureValues *values)
PetscErrorCode DeleteFeatureValues (FeatureValues values)
PetscErrorCode InstantiateFeatureSet (AnaModNumericalProblem prob, FeatureSet set, FeatureValues values)
PetscErrorCode GetFeatureValue (FeatureValues values, int index, AnalysisItem *val, PetscTruth *f)
PetscErrorCode AnaModSetRetrievalFunction (PetscErrorCode(*fun)(void *, char *, char *, AnalysisItem *, AnalysisDataType *, PetscTruth *))
PetscErrorCode AnaModGetRetrievalFunction (PetscErrorCode(**fun)(void *, char *, char *, AnalysisItem *, AnalysisDataType *, PetscTruth *), PetscTruth *flg)

Variables

static PetscErrorCode(* retriever )(void *, char *, char *, AnalysisItem *, AnalysisDataType *, PetscTruth *) = NULL


Define Documentation

#define CHECKVALIDFSET (  )     {ANAMODCHECKVALID(i,FSETCOOKIE,"feature set");}

Definition at line 59 of file feature.c.

Referenced by AddToFeatureSet(), DeleteFeatureSet(), and InstantiateFeatureSet().

#define CHECKVALIDFVAL (  )     {ANAMODCHECKVALID(i,FVALCOOKIE,"feature values");}

Definition at line 65 of file feature.c.

Referenced by DeleteFeatureValues(), GetFeatureValue(), and InstantiateFeatureSet().

#define FSETCOOKIE   9876

Definition at line 58 of file feature.c.

Referenced by NewFeatureSet().

#define FVALCOOKIE   9877

Definition at line 64 of file feature.c.

Referenced by NewFeatureValues().

#define NALLOC   25

Definition at line 57 of file feature.c.


Function Documentation

PetscErrorCode AddToFeatureSet ( FeatureSet  set,
char *  cat,
char *  cmp,
int *  idx 
)

Add a requested feature to a featureset object. See Feature sets

Arguments:

  • set : the featureset
  • cat,cmp : the category and component name. It is an error to supply unknown names
  • idx : the index under which the feature is known in this featureset. This index can be supplied to GetFeatureValue(). This parameter can be null.

Definition at line 114 of file feature.c.

References CHECKVALIDFSET, name, and StringArrayAdd().

00115 {
00116   PetscErrorCode ierr;
00117   char *name; int l1,l2;
00118   PetscFunctionBegin;
00119   CHECKVALIDFSET(set);
00120 
00121   l1 = strlen(cat); l2 = strlen(cmp);
00122   ierr = PetscMalloc((l1+l2+1)*sizeof(char),&name); CHKERRQ(ierr);
00123   sprintf(name,"%s/%s",cat,cmp);
00124   ierr = StringArrayAdd(set->features,name,idx); CHKERRQ(ierr);
00125   ierr = PetscFree(name); CHKERRQ(ierr);
00126   PetscFunctionReturn(0);
00127 }

Here is the call graph for this function:

PetscErrorCode AnaModGetRetrievalFunction ( PetscErrorCode(**)(void *, char *, char *, AnalysisItem *, AnalysisDataType *, PetscTruth *)  fun,
PetscTruth *  flg 
)

Definition at line 229 of file feature.c.

References retriever.

Referenced by InstantiateFeatureSet().

00230 {
00231   PetscTruth has;
00232   PetscFunctionBegin;
00233   has = (PetscTruth)(retriever!=NULL);
00234   if (flg) *flg = has;
00235   if (has &&fun) *fun = retriever;
00236   PetscFunctionReturn(0);
00237 }

PetscErrorCode AnaModSetRetrievalFunction ( PetscErrorCode(*)(void *, char *, char *, AnalysisItem *, AnalysisDataType *, PetscTruth *)  fun  ) 

Definition at line 219 of file feature.c.

References retriever.

00220 {
00221   PetscFunctionBegin;
00222   retriever = fun;
00223   PetscFunctionReturn(0);
00224 }

PetscErrorCode DeleteFeatureSet ( FeatureSet  set  ) 

Delete a featureset object. See Feature sets

Definition at line 90 of file feature.c.

References CHECKVALIDFSET, DeleteIntArray(), and DeleteStringArray().

00091 {
00092   PetscErrorCode ierr;
00093   PetscFunctionBegin;
00094   CHECKVALIDFSET(set);
00095   ierr = DeleteIntArray(set->IDs); CHKERRQ(ierr);
00096   ierr = DeleteStringArray(set->features); CHKERRQ(ierr);
00097   ierr = PetscFree(set); CHKERRQ(ierr);
00098   PetscFunctionReturn(0);
00099 }

Here is the call graph for this function:

PetscErrorCode DeleteFeatureValues ( FeatureValues  values  ) 

Free a featurevalues object. See Feature sets

Definition at line 148 of file feature.c.

References CHECKVALIDFVAL, DeleteAnalysisDataTypeArray(), DeleteAnalysisItemArray(), FeatureValues_::types, and FeatureValues_::values.

00149 {
00150   PetscErrorCode ierr;
00151   PetscFunctionBegin;
00152   CHECKVALIDFVAL(values);
00153   ierr = DeleteAnalysisItemArray(values->values); CHKERRQ(ierr);
00154   ierr = DeleteAnalysisDataTypeArray(values->types); CHKERRQ(ierr);
00155   ierr = PetscFree(values); CHKERRQ(ierr);
00156   PetscFunctionReturn(0);
00157 }

Here is the call graph for this function:

PetscErrorCode GetFeatureValue ( FeatureValues  values,
int  index,
AnalysisItem val,
PetscTruth *  f 
)

Extract a value from a featurevalues object. See Feature sets.

Arguments:

  • values : the FeatureValues object.
  • index : the index, as returned by AddToFeatureSet().
  • val (output) : the value; this argument can be null.
  • f (output) : indicates whether the return value was indeed preset in the featurevalues object; this argument can be null.

Definition at line 206 of file feature.c.

References AnalysisItemArrayTryGetAt(), CHECKVALIDFVAL, and FeatureValues_::values.

00207 {
00208   PetscErrorCode ierr;
00209   PetscFunctionBegin;
00210   CHECKVALIDFVAL(values);
00211   ierr = AnalysisItemArrayTryGetAt(values->values,index,val,f); CHKERRQ(ierr);
00212   PetscFunctionReturn(0);
00213 }

Here is the call graph for this function:

PetscErrorCode InstantiateFeatureSet ( AnaModNumericalProblem  prob,
FeatureSet  set,
FeatureValues  values 
)

Fill in a featurevalues object. See Feature sets

Definition at line 163 of file feature.c.

References AnalysisDataTypeArraySetAt(), AnalysisItemArraySetAt(), AnaModGetRetrievalFunction(), CHECKVALIDFSET, CHECKVALIDFVAL, retriever, StringArrayGetAt(), StringArrayGetFill(), FeatureValues_::types, and FeatureValues_::values.

00164 {
00165   PetscErrorCode (*retriever)
00166     (void*,char*,char*,AnalysisItem*,AnalysisDataType*,PetscTruth*);
00167   int nval,ival; PetscTruth flg; PetscErrorCode ierr;
00168   PetscFunctionBegin;
00169   CHECKVALIDFSET(set);
00170   CHECKVALIDFVAL(values);
00171   ierr = AnaModGetRetrievalFunction(&retriever,&flg); CHKERRQ(ierr);
00172   if (!flg) PetscFunctionReturn(0);
00173   ierr = StringArrayGetFill(set->features,&nval); CHKERRQ(ierr);
00174   for (ival=0; ival<nval; ival++) {
00175     char *feature,*cat,*cmp; int l;
00176     AnalysisItem res; AnalysisDataType t;
00177     ierr = StringArrayGetAt(set->features,ival,&feature); CHKERRQ(ierr);
00178     for (l=0; l<strlen(feature); l++) {
00179       if (feature[l]=='/') {
00180         feature[l] = 0; cat = feature; cmp = feature+l+1;
00181         ierr = (*retriever)(prob,cat,cmp,&res,&t,&flg); CHKERRQ(ierr);
00182         if (flg) {
00183           ierr = AnalysisItemArraySetAt(values->values,ival,res); CHKERRQ(ierr);
00184           ierr = AnalysisDataTypeArraySetAt(values->types,ival,t); CHKERRQ(ierr);
00185         }
00186         feature[l] = '/'; break;
00187       }
00188     }
00189   }
00190   PetscFunctionReturn(0);
00191 }

Here is the call graph for this function:

PetscErrorCode NewFeatureSet ( FeatureSet set  ) 

Allocate a featureset object. See Feature sets

Definition at line 74 of file feature.c.

References FeatureSet_::cookie, CreateIntArray(), CreateStringArray(), FeatureSet_::features, FSETCOOKIE, and FeatureSet_::IDs.

00075 {
00076   FeatureSet fnew; PetscErrorCode ierr;
00077   PetscFunctionBegin;
00078   ierr = PetscMalloc(sizeof(struct FeatureSet_),&fnew); CHKERRQ(ierr);
00079   ierr = PetscMemzero(fnew,sizeof(struct FeatureSet_)); CHKERRQ(ierr);
00080   fnew->cookie = FSETCOOKIE;
00081   ierr = CreateIntArray("IDs",50,&(fnew->IDs)); CHKERRQ(ierr);
00082   ierr = CreateStringArray("features",50,&(fnew->features)); CHKERRQ(ierr);
00083   *set = fnew;
00084   PetscFunctionReturn(0);
00085 }

Here is the call graph for this function:

PetscErrorCode NewFeatureValues ( FeatureValues values  ) 

Allocate a featurevalues object. See Feature sets

Definition at line 132 of file feature.c.

References FeatureValues_::cookie, CreateAnalysisDataTypeArray(), CreateAnalysisItemArray(), FVALCOOKIE, FeatureValues_::types, and FeatureValues_::values.

00133 {
00134   FeatureValues fnew; PetscErrorCode ierr;
00135   PetscFunctionBegin;
00136   ierr = PetscMalloc(sizeof(struct FeatureValues_),&fnew); CHKERRQ(ierr);
00137   ierr = PetscMemzero(fnew,sizeof(struct FeatureValues_)); CHKERRQ(ierr);
00138   fnew->cookie = FVALCOOKIE;
00139   ierr = CreateAnalysisItemArray("values",50,&fnew->values); CHKERRQ(ierr);
00140   ierr = CreateAnalysisDataTypeArray("values",50,&fnew->types); CHKERRQ(ierr);
00141   *values = fnew;
00142   PetscFunctionReturn(0);
00143 }

Here is the call graph for this function:


Variable Documentation

PetscErrorCode(* retriever)(void *, char *, char *, AnalysisItem *, AnalysisDataType *, PetscTruth *) = NULL [static]


Generated on Sun Oct 4 04:01:09 2009 for SALSA Analysis Modules by  doxygen 1.5.9