Initializing help system before first use

Services related to parameters

Whenever a module defines control parameters, it needs to provide the service to retrieve a parameter number by a name. If the corresponding parameter is not found in the module, this function returns -1. Otherwise, if the parameter belongs to the module, its reference number (here: index in the list of parameters defined by the module) must be returned, together with information about its type (second argument of the function).

static int task_findparam(const char *name, int *type)
{
 int n;
 int notfound;

 n=0;
 do
 {
  if((notfound=strcmp(name, taskparams[n].name))==0) break;
  n++;
 } while(taskparams[n].name!=NULL);

 if(!notfound)
 {
  *type=taskparams[n].type;
  return n;
 }
 else
  return -1;
}

The findparam service function is only used during the compilation of a model to convert the name of a parameter to a module-internal identification number. This number is used by the subroutines setparam and getparam during the execution of the model (see Section Functions for handling parameters).

The second service that we are defining is optional: it provides a possibility of enumerating the parameters of the module (e.g. this is used when module information is displayed with the examine command).

static void *task_nextparam(void *ref, const char **name, const char **desc,
                            int *type)
{
 long cst;

 cst=(long)ref;
 if((cst<0)||(cst>=TASK_NUMPARAM))
  return NULL;
 else
 {
  *name=taskparams[cst].name;
  *type=taskparams[cst].type;
  *desc=taskparams[cst].desc;
  return (void *)(cst+1);
 }
}

Mosel calls this function repeatedly until it returns NULL. At the first call the value of the argument ref is NULL, while at any subsequent calls it corresponds to the return value of the immediately preceding execution of this function. The other arguments need to be filled with the information for a parameter (name and type are required, the descriptive text is optional). The constant TASK_NUMPARAM is the number of parameters that we have defined in this module.