Example #1
0
int assignReal(double d, varInfo *v, int i)
{   Rval *q;

    DPRINT3(3,"assignReal: 0x%08x[%d] <== %lf",v,i,d);
    if (v)
    {   if (v->T.basicType == T_STRING)
	{   WerrprintfWithPos("Can't assign REAL value to STRING variable");
#ifdef VNMRJ
	    jExpressionError();
#endif 
	    return(0);
	}
	else
	{   if (v->T.basicType == T_UNDEF)
	    {
		DPRINT0(3,", newly defined as REAL");
		v->T.basicType = T_REAL;
	    }
	    if (i)
	    {
		DPRINT1(3,", just to element %d\n",i);
		if (i <= v->T.size+1)
		{   if ((q=selectRval(v,i)) == NULL)
		       q = addNewRval(v);
		    q->v.r = d;
		    /* v->active = ACT_ON; */
		    return(1);
		}
		else
		{   WerrprintfWithPos("Assignment to non-existent element (=%d)",i);
#ifdef VNMRJ
		    jExpressionError();
#endif 
		    return(0);
		}
	    }
	    else
	    {
		DPRINT0(3,", to whole thing\n");
		disposeRealRvals(v->R);
		v->T.size = 0;
		v->R      = NULL;
		q         = addNewRval(v);
		q->v.r    = d;
		/* v->active = ACT_ON; */
	    }
	    return(1);
	}
    }
    else
    {
	DPRINT0(3,", NULL var ptr\n");
	return(0);
    }
}
Example #2
0
void tossVar(register symbol *p)
{  register varInfo *v;

   if (p)
   {
      DPRINT1(3,"tossVar: symbol 0x%06x",p);
      if (p->name)
      {
	 DPRINT2(3,", name is \"%s\" (at 0x%06x)",p->name,p->name);
	 release(p->name);
      }
      if ( (v=(varInfo *)(p->val)) )
      {
	 DPRINT1(3,", varInfo 0x%06x",v);
	 if (v->T.basicType == T_STRING)
	 {
	    DPRINT0(3,", STRING\n");
	    disposeStringRvals(v->R);
	    disposeStringRvals(v->E);
	 }
	 else
	 {
	    DPRINT0(3,", REAL\n");
	    disposeRealRvals(v->R);
	    disposeRealRvals(v->E);
	 }
#ifndef VNMRJ
#ifdef VNMRTCL
         /* This function is used by the TCL interface
          * The function is in socket.c in the acqcomm library
          */
         unsetMagicVar(v);
#endif 
#endif 
	 release(v);
      }
      release(p);
   }
}
Example #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);
}