SALSA Analysis Modules
Data Structures | Defines | Functions | Variables
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, const char *cat, const 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, PetscBool *f)
PetscErrorCode AnaModSetRetrievalFunction (PetscErrorCode(*fun)(void *, char *, char *, AnalysisItem *, AnalysisDataType *, PetscBool *))
PetscErrorCode AnaModGetRetrievalFunction (PetscErrorCode(**fun)(void *, char *, char *, AnalysisItem *, AnalysisDataType *, PetscBool *), PetscBool *flg)
PetscErrorCode AnaModCheckValidFeatureSet (void *f)

Variables

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

Define Documentation

#define CHECKVALIDFSET (   i)    {ANAMODCHECKVALID(i,FSETCOOKIE,"feature set");}
#define CHECKVALIDFVAL (   i)    {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,
const char *  cat,
const 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 115 of file feature.c.

References CHECKVALIDFSET, name, and StringArrayAdd().

{
  PetscErrorCode ierr;
  char *name; int l1,l2;
  PetscFunctionBegin;
  CHECKVALIDFSET(set);

  l1 = strlen(cat); l2 = strlen(cmp);
  ierr = PetscMalloc((l1+l2+1)*sizeof(char),&name); CHKERRQ(ierr);
  sprintf(name,"%s/%s",cat,cmp);
  ierr = StringArrayAdd(set->features,name,idx); CHKERRQ(ierr);
  ierr = PetscFree(name); CHKERRQ(ierr);
  PetscFunctionReturn(0);
}

Here is the call graph for this function:

PetscErrorCode AnaModCheckValidFeatureSet ( void *  f)

Definition at line 242 of file feature.c.

References CHECKVALIDFSET.

{
  PetscFunctionBegin;
  CHECKVALIDFSET((FeatureSet)f);
  PetscFunctionReturn(0);
}
PetscErrorCode AnaModGetRetrievalFunction ( PetscErrorCode(**)(void *, char *, char *, AnalysisItem *, AnalysisDataType *, PetscBool *)  fun,
PetscBool *  flg 
)

Definition at line 230 of file feature.c.

References retriever.

Referenced by InstantiateFeatureSet().

{
  PetscBool has;
  PetscFunctionBegin;
  has = (PetscBool)(retriever!=NULL);
  if (flg) *flg = has;
  if (has &&fun) *fun = retriever;
  PetscFunctionReturn(0);
}
PetscErrorCode AnaModSetRetrievalFunction ( PetscErrorCode(*)(void *, char *, char *, AnalysisItem *, AnalysisDataType *, PetscBool *)  fun)

Definition at line 220 of file feature.c.

References retriever.

{
  PetscFunctionBegin;
  retriever = fun;
  PetscFunctionReturn(0);
}
PetscErrorCode DeleteFeatureSet ( FeatureSet  set)

Delete a featureset object. See Feature sets

Definition at line 90 of file feature.c.

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

{
  PetscErrorCode ierr;
  PetscFunctionBegin;
  CHECKVALIDFSET(set);
  ierr = DeleteIntArray(set->IDs); CHKERRQ(ierr);
  ierr = DeleteStringArray(set->features); CHKERRQ(ierr);
  ierr = PetscFree(set); CHKERRQ(ierr);
  PetscFunctionReturn(0);
}

Here is the call graph for this function:

PetscErrorCode DeleteFeatureValues ( FeatureValues  values)

Free a featurevalues object. See Feature sets

Definition at line 149 of file feature.c.

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

{
  PetscErrorCode ierr;
  PetscFunctionBegin;
  CHECKVALIDFVAL(values);
  ierr = DeleteAnalysisItemArray(values->values); CHKERRQ(ierr);
  ierr = DeleteAnalysisDataTypeArray(values->types); CHKERRQ(ierr);
  ierr = PetscFree(values); CHKERRQ(ierr);
  PetscFunctionReturn(0);
}

Here is the call graph for this function:

PetscErrorCode GetFeatureValue ( FeatureValues  values,
int  index,
AnalysisItem val,
PetscBool *  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 207 of file feature.c.

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

{
  PetscErrorCode ierr;
  PetscFunctionBegin;
  CHECKVALIDFVAL(values);
  ierr = AnalysisItemArrayTryGetAt(values->values,index,val,f); CHKERRQ(ierr);
  PetscFunctionReturn(0);
}

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 164 of file feature.c.

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

{
  PetscErrorCode (*retriever)
    (void*,char*,char*,AnalysisItem*,AnalysisDataType*,PetscBool*);
  int nval,ival; PetscBool flg; PetscErrorCode ierr;
  PetscFunctionBegin;
  CHECKVALIDFSET(set);
  CHECKVALIDFVAL(values);
  ierr = AnaModGetRetrievalFunction(&retriever,&flg); CHKERRQ(ierr);
  if (!flg) PetscFunctionReturn(0);
  ierr = StringArrayGetFill(set->features,&nval); CHKERRQ(ierr);
  for (ival=0; ival<nval; ival++) {
    char *feature,*cat,*cmp; int l;
    AnalysisItem res; AnalysisDataType t;
    ierr = StringArrayGetAt(set->features,ival,&feature); CHKERRQ(ierr);
    for (l=0; l<strlen(feature); l++) {
      if (feature[l]=='/') {
        feature[l] = 0; cat = feature; cmp = feature+l+1;
        ierr = (*retriever)(prob,cat,cmp,&res,&t,&flg); CHKERRQ(ierr);
        if (flg) {
          ierr = AnalysisItemArraySetAt(values->values,ival,res); CHKERRQ(ierr);
          ierr = AnalysisDataTypeArraySetAt(values->types,ival,t); CHKERRQ(ierr);
        }
        feature[l] = '/'; break;
      }
    }
  }
  PetscFunctionReturn(0);
}

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.

{
  FeatureSet fnew; PetscErrorCode ierr;
  PetscFunctionBegin;
  ierr = PetscMalloc(sizeof(struct FeatureSet_),&fnew); CHKERRQ(ierr);
  ierr = PetscMemzero(fnew,sizeof(struct FeatureSet_)); CHKERRQ(ierr);
  fnew->cookie = FSETCOOKIE;
  ierr = CreateIntArray("IDs",50,&(fnew->IDs)); CHKERRQ(ierr);
  ierr = CreateStringArray("features",50,&(fnew->features)); CHKERRQ(ierr);
  *set = fnew;
  PetscFunctionReturn(0);
}

Here is the call graph for this function:

PetscErrorCode NewFeatureValues ( FeatureValues values)

Allocate a featurevalues object. See Feature sets

Definition at line 133 of file feature.c.

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

{
  FeatureValues fnew; PetscErrorCode ierr;
  PetscFunctionBegin;
  ierr = PetscMalloc(sizeof(struct FeatureValues_),&fnew); CHKERRQ(ierr);
  ierr = PetscMemzero(fnew,sizeof(struct FeatureValues_)); CHKERRQ(ierr);
  fnew->cookie = FVALCOOKIE;
  ierr = CreateAnalysisItemArray("values",50,&fnew->values); CHKERRQ(ierr);
  ierr = CreateAnalysisDataTypeArray("values",50,&fnew->types); CHKERRQ(ierr);
  *values = fnew;
  PetscFunctionReturn(0);
}

Here is the call graph for this function:


Variable Documentation

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