next up previous
Next: Librnpl Up: Parameters Previous: FORTRAN Interface

C Interface

The C interface consists of a single routine whose prototype is in librnpl.h.

BBH_V get_param(const BBH_C *p_file, BBH_C *name, BBH_I def,
               BBH_C *type, BBH_I size, BBH_V *p);

This routine takes the file name, parameter name, default flag, parameter type, parameter size (in elements), and a pointer to the parameter. The following code fragment reads several parameters from a file called myparams.

  long len,ar1[3];
  double p,ar2[5];
  char *s,**ar3;
	
  ar3=(char **)malloc(4*sizeof(char *));
  len=10;
  get_param("myparams","len",1,"long",1,&len);
  get_param("myparams","array1",0,"long",3,ar1);
  get_param("myparams","p",0,"double",1,&p);
  ar2[0]=ar2[1]=ar2[2]=ar2[3]=ar2[4]=1.0;
  get_param("myparams","array2",1,"double",5,ar2);
  get_param("myparams","string1",0,"string",1,&s);
  get_param("myparams","stringar",0,"string",4,ar3);

Notice that the addresses of size 1 parameters must be passed. The parameter type is one of the three strings used above. The default flag is set to 1 if the parameter has a default and 0 if not. Storage for each string is allocated by the routine if the default flag is 0. Otherwise existing storage is freed and reallocated. Thus string parameters must be malloced and not taken from the stack.



Robert Marsa
Fri Jul 14 13:58:46 CDT 1995