示例#1
0
int
A_getreal(int tree, const char *name, double **valaddr, int index)
{
   symbol        **root;

   if ( (root = getTreeRoot(getRoot(tree))) )
   {
      varInfo        *v;

      if ( (v = rfindVar(name, root)) )	/* if variable exists */
      {
	 if (0 < index && index <= v->T.size)	/* within bounds ? */
	 {
	    int             i;
	    Rval           *r;

	    i = 1;
	    r = v->R;
	    while (r && i < index)	/* travel down Rvals  */
	    {
	       r = r->next;
	       i += 1;
	    }
	    if (r)
	    {
	       *valaddr = &r->v.r;	/* pass address back */
	       if (bgflag > 1)
	       {
		  fprintf(stderr,
		     "A_getstring: Address to put address of value: %p , ",
			  (void *) valaddr);
		  fprintf(stderr, "Address of value: %p \n",
			  (void *) *valaddr);
	       }
	       return (0);
	    }
	    else
	    {
	       return (-99);	/* unknown error */
	    }
	 }
	 else
	    return (-9);	/* index out of bounds */
      }
      else
	 return (-2);		/* variable doesn't exist */
   }
   else
      return (-1);		/* tree doesn't exist */
}
示例#2
0
varInfo *findVar(char *n)
{  symbol **pp;
   varInfo *v;

   if ( (pp=selectVarTree(n)) )
   {  if (pp == &current)	/* if select tree is current, check it first */
      {  if ( (v = rfindVar(n,pp)) )
	    return(v);
	 else
	    if ( (v = rfindVar(n,&global)) )		/*  then check global */
	       return(v);
	    else
	       if ( (v = rfindVar(n,&systemglobal)) )  /*then check systemglobal */
	          return(v);
	       else
	          return(NULL);
      }
      else
	 return(rfindVar(n,pp));
   }
   else
      return(NULL);
}
示例#3
0
int P_loadVar(int tree, char *name,  vInfo *v, int *fd) 	
{   char            buf[4097];
    double          dvalue;
    int             i; 
    int             length;
    int             nread;
    symbol        **root;
    varInfo        *newv;
    
/* If the variable was passed as a system global, store it
   in the global variable tree.					*/

/* if lockfreq is passed from the system global and global annouce the fact and
   abort  */
    if (tree==SYSTEMGLOBAL)	/* break if in two for speed,avoid strcmp if possible */
    {
      if (strcmp(name,"lockfreq") == 0) 
      {
         if (!havelockfreq)
	    havelockfreq=1;
         else
         {
	   text_error(
	    "lockfreq in both conpar and global, remove occurrence in global.\n");
           havelockfreq = -1;
         }
      }
    }
    if (tree==GLOBAL)	/* break if in two for speed,avoid strcmp if possible */
    {
      if (strcmp(name,"lockfreq") == 0) 
      {
         if (!havelockfreq)
	    havelockfreq=1;
         else
         {
	   text_error(
	    "lockfreq in both conpar and global, remove occurrence in global.\n");
           havelockfreq = -1;
         }
      }
    }
    if (tree==SYSTEMGLOBAL) tree = GLOBAL;
    if ( (root = getTreeRoot(getRoot(tree))) )
    {	if ( (newv=rfindVar(name,root)) ) /* if variable exists, get rid of it*/
	{   if (newv->T.basicType == T_STRING)  
	    {   disposeStringRvals(newv->R);
		disposeStringRvals(newv->E);
	    }
	    else
	    {   disposeRealRvals(newv->R);
		disposeRealRvals(newv->E);
	    }
	    newv->R = NULL;
	    newv->E = NULL;
	    newv->T.size = newv->ET.size = 0;
	    newv->T.basicType  = v->basicType;
	    newv->ET.basicType = v->basicType;
	}
	else
	    newv = RcreateVar(name,root,v->basicType); /* create the variable */
	newv->active = v->active;
	newv->subtype= v->subtype;
	newv->Dgroup = v->Dgroup;
	newv->Ggroup = v->group;
	newv->prot   = v->prot;
	newv->minVal = v->minVal;
	newv->maxVal = v->maxVal;
	newv->step   = v->step;
	if (v->basicType == T_STRING)
	{    for (i=0 ; i<v->size ; i++)
	    {	nread = read(fd[0],&length,sizeof(int)); 
		nread = read(fd[0],buf,length);
		buf[length] = '\0';
		if (bgflag > 2)
		    fprintf(stderr,"bg: STRING[%d] = \"%s\"\n",i,buf);
		assignString(buf,newv,i+1);
	    }
	    /* copy over enumerals */
/* ---------------------- deleted
	    for (i=0 ; i<v->Esize ; i++)
	    {	nread = read(fd[0],&length,sizeof(int)); 
		nread = read(fd[0],buf,length);
		buf[length] = NULL;
		if (bgflag > 2)
		    fprintf(stderr,"bg: Enum STRING[%d] = \"%s\"\n",i,buf);
		assignEString(buf,newv,i+1); 
	    }
+------------------------- */
	}
	else /* assume T_REAL */
	{   for (i=0 ; i<v->size ; i++)
	    {	nread = read(fd[0],&dvalue,sizeof(double));
		/* convert usec pulse values in to seconds */
                if (v->subtype == ST_PULSE) /* pulse in usec */ 
                { 
                     dvalue *= 1.0e-6; 	/* now in sec. */
                }
		if (bgflag > 2)
		    fprintf(stderr,"bg: REAL[%d] = \"%g\"\n",i,dvalue);
		assignReal(dvalue,newv,i+1);
	    }
	    /*  copy over enumeral values */
/* ---------------------- deleted
	    for (i=0 ; i<v->Esize ; i++)
	    {	nread = read(fd[0],&dvalue,sizeof(double));
		if (bgflag > 2)
		    fprintf(stderr,"bg: Enum REAL[%d] = \"%g\"\n",i,dvalue);
		assignEReal(dvalue,newv,i+1);  
	    }
+------------------------- */
	}
    }
    else
    {
	fprintf(stderr,"P_loadVar: fatal error, cannot find tree %d\n",tree);
        havelockfreq = -1;  /* make PSG abort */
    }
    return(0);
}