Esempio n. 1
0
int
init_grad_choices()
{
    int	iter, param_defined, result;
    char	gradient_buf[ NUM_GRADIENTS+1 ];

    init_interface_table();
    init_grad_labels();
    init_console_table();
    param_defined = 1;

    /*  Special note on P_getstring:

        The last argument tells P_getstring the total size of the buffer
        in the 3rd argument, including the terminating NULL character.
        So to get NUM_GRADIENTS non-null characters, you must tell it
        the buffer has space for one more character.			*/

    result = P_getstring(
                 SYSTEMGLOBAL, "gradtype", &gradient_buf[ 0 ], 1, NUM_GRADIENTS+1
             );
    if (result != 0)
        param_defined = 0;

    for (iter = 0; iter < NUM_GRADIENTS; iter++) {
        if (param_defined)
            gradient_choice[ iter ] = find_table_char(
                                          gradient_buf[ iter ],
                                          &gradient_value[ 0 ],
                                          sizeof( gradient_value )
                                      );
        else
            gradient_choice[ iter ] = NOT_PRESENT;
    }

    /* Generate Gradient coil choices, always allocate None */

    if ( (sysgcoil_choices[0]= (char *)malloc(strlen("none")+1)) !=NULL)
        strcpy(sysgcoil_choices[0],"None") ;
    result = P_getstring(SYSTEMGLOBAL, "sysgcoil", &sysgcoil[0], 1,
                         GCOILmaxnchar);
    ncoilchoices = getsysgcoil_choices();
    if ( (result == 0) && strlen(sysgcoil) )
    {
        gradient_choice[ GRAD_COIL ] = find_table_string(
                                           sysgcoil,
                                           &sysgcoil_choices[ 0 ],
                                           ncoilchoices);
    }
    else
    {
        gradient_choice[ GRAD_COIL ] = NOT_PRESENT;
    }

}
Esempio n. 2
0
string AspUtil::getString(string varname, string defaultVal)
{
    const char *cname = varname.c_str();
    char cval[2048];
    if (P_getstring(CURRENT, cname, cval, 1, sizeof(cval))) {
        if (P_getstring(GLOBAL, cname, cval, 1, sizeof(cval))) {
            // Doesnt exist; create it with default value
            //setString(varname, defaultVal, false);
            return defaultVal;
        }
    }
    string rtn(cval);
    return rtn;
}
Esempio n. 3
0
int
disp_current_seq()
/****************/
{ 
  char name[66];
#ifdef VNMRJ
  if (P_getstring(CURRENT,"pslabel",name,1,64)) ABORT;
  disp_seq(name);
#else
  if (P_getstring(CURRENT,"pslabel",name,1,15)) ABORT;
  disp_seq(name);
#endif
  RETURN;
}
Esempio n. 4
0
string AspUtil::getString(string varname)
{
    const char *cname = varname.c_str();
    char cval[2048];
    if (P_getstring(CURRENT, cname, cval, 1, sizeof(cval))) {
        if (P_getstring(GLOBAL, cname, cval, 1, sizeof(cval))) {
            // Doesn't exist; return empty string
            // (Don't create variable)
            return "";
        }
    }
    string rtn(cval);
    return rtn;
}
Esempio n. 5
0
int autora(int argc, char *argv[], int retc, char *retv[])
{
        char   tmpPath[MAXPATH];
        int    ival;

	DPRINT0("autora command invoked\n"); /* resume is implicit */
	ival = ok_to_acquire();
        if (ival != -2)
           release_console2();
	if ( (ival != 0) && (ival != -4))
        {
           /* Acquisition needs to be Idle or in automation mode */
	   report_acq_perm_error( argv[0], ival );
	   ABORT;
        }
        if (argc == 1)
        {
           strcpy(tmpPath,userdir);
           strcat(tmpPath,"/global");
           DPRINT1("copying Global parameters to '%s' file.\n",tmpPath);
           if (P_save(GLOBAL,tmpPath))
           {   Werrprintf("Problem saving global parameters in '%s'.",tmpPath);
           }
        }

	P_getstring(GLOBAL,"autodir",&tmpPath[ 0 ], 1, MAXPATH);
        setAutoDir(tmpPath);
        if (send2Acq(11, tmpPath) < 0)
                Werrprintf("autora message was not sent");
	RETURN;
}
Esempio n. 6
0
static int
get_ecc_filename(char *fname, int len)
{
    char *pc;
    char pfx[] = ".";
    int n;

    sprintf(fname,"%s/%s/%s", systemdir, DECCLIB, pfx);
    n = strlen(fname);
    pc = fname + n;
    len -= n;

    quoteToMainFlag=0;
    if (P_getstring(GLOBAL,"sysgcoil", pc, 1, len)
        || strlen(pc) == 0)
    {
        strcpy(pc, "main");
        quoteToMainFlag=1;
    }
    if (bugmask & ECCBUGBIT){
        printf("ECC: basename=%s, filepath=%s\n", pc, fname);
    }
    if ( strcmp(pc,"None")  == 0)
        return(FALSE);
    else
        return(TRUE);
}
Esempio n. 7
0
void AspInteg::getValue(spAspDataInfo_t dataInfo, string &lbl, int &cwd, int &cht) { 
   char str[MAXSTR],tmpStr[MAXSTR];
   sprintf(str,"%.2f",absValue);
   if (P_getstring(GLOBAL, "integProperty", tmpStr, 1, sizeof(tmpStr))) strcpy(tmpStr,"%norm%"); 
   string value = string(tmpStr);
   if(value.length() < 1 || value == "-" || value == "?") {
	lbl = string(str);
   } else {
      size_t p1=string::npos;
      size_t p2=string::npos;
      p1=value.find("%",0);
      if(p1 != string::npos) p2=value.find("%",p1+1);
      if(p2 != string::npos) {
         strcpy(tmpStr,value.substr(p1+1,p2-p1-1).c_str());
         bool norm = (strcasecmp(tmpStr,"norm") == 0);
         if(norm) {
                sprintf(str,"%.2f",normValue);
         }
	 lbl = value.substr(0,p1) + string(str) + value.substr(p2+1);
      } else lbl = string(value); 
   }

   int ascent, descent;
   GraphicsWin::getTextExtents(lbl.c_str(), 14, &ascent, &descent, &cwd);

   cht = ascent + descent;

   return;
}
Esempio n. 8
0
/*------------------------------------------------------------------
|
|	wait4spin()/0
|	send acode to wait for spinner to obtain spin-speed 
+-----------------------------------------------------------------*/
void wait4spin()
{
char spintype[MAXSTR];
int  codeStream[20],i;
    if ( ((setupflag == GO) || (setupflag == SPIN) || (setupflag == SAMPLE)) &&
          spinactive )
    {
       if ( P_getstring(GLOBAL,"spintype", spintype, 1, MAXSTR)  == 0)
          if ( strcmp(spintype,"mas") == 0 ) 
             return;
       i = 0;
       codeStream[i++] = HSrotor ? 100 : 1;
       if ( (interLock[1] != 'N') && (interLock[1] != 'n'))
          codeStream[i++] = ( (interLock[1] == 'y') || (interLock[1] == 'Y') ) ?
                        HARD_ERROR : WARNING_MSG;
       else
          codeStream[i++] = 0;
       if (ok2bumpflag)
          codeStream[i++] = 1;
       else
          codeStream[i++] = 0;
       broadcastCodes(CHECKSPIN, i, codeStream);
       delay(0.100);  /* delays added to prevent DDR from reboot when spin=value, GMB 1/18/05 */
    }
}
Esempio n. 9
0
int getparm(char *varname, char *vartype, int tree,
            void *varaddr, int size)
{
    int ret;
    char mess[MAXSTR];

    if ( (strcmp(vartype,"REAL") == 0) || (strcmp(vartype,"real") == 0) )
    {
        if ((ret = P_getreal(tree,varname,(double *)varaddr,1)) < 0)
        {
           if (dowarn)
           {
             sprintf(mess,"Cannot get parameter: %s\n",varname);
             text_error(mess);
	     if (bgflag)
	         P_err(ret,varname,": ");
           }
           else
           {
              dowarn = 1;
           }
	   return(1);
        }
    }
    else 
    {
	if ( (strcmp(vartype,"STRING") == 0) || 
	     (strcmp(vartype,"string") == 0) )
        {
            if ((ret = P_getstring(tree,varname,(char *)varaddr,1,size)) < 0)
            {
              if (dowarn)
              {
                sprintf(mess,"Cannot get parameter: %s\n",varname);
                text_error(mess);
		if (bgflag)
	     	    P_err(ret,varname,": ");
              }
              else
              {
                 dowarn=1;
              }
              return(1);
            }
	}
	else
	{   sprintf(mess,"Variable '%s' is neither a 'real' or 'string'.\n",
			vartype);
            text_error(mess);
	    return(1);
	}
      }
    return(0);
}
Esempio n. 10
0
static int check_int(int *number)
/********************/
{
  vInfo  info;
  char   intmod[9];
  int    res;
  
  *number = ((P_getVarInfo(CURRENT,"liamp",&info)) ? 0 : info.size);
  if ( (res=P_getstring(CURRENT,"intmod",intmod,1,8)) )
  { P_err(res,"intmod",":"); ABORT; }
  return(!(strcmp(intmod,INT_FULL))); 
}
Esempio n. 11
0
/*----------------------------------------------------------------
| 
|	spinnerStringToInt()/i
|	return the numerical value for the spinner parameter
+-----------------------------------------------------------------*/
int spinnerStringToInt()
{
char spintype[MAXSTR];
int  spinner;
   /* we now use 'spintype' ="liquids","tach","mas","nano" "none" */
   if ( P_getstring(GLOBAL,"spintype", spintype, 1, MAXSTR)  < 0)
      spinner=LIQUIDS_SPINNER;
   else if ( ! strcmp(spintype,"liquids") ) spinner = LIQUIDS_SPINNER;
   else if ( ! strcmp(spintype,"tach") )    spinner = SOLIDS_SPINNER;
   else if ( ! strcmp(spintype,"mas") )     spinner = MAS_SPINNER;
   else if ( ! strcmp(spintype,"nano") )    spinner = NANO_SPINNER;
   else    spinner = NO_SPINNER;
   return(spinner);
}
void settmpgradtype(char *tmpgradname)
{
   double pfgBoard;
   char tmpGradtype[MAXSTR];

   if (P_getstring(CURRENT, tmpgradname, tmpGradtype, 1, MAXSTR) == 0)
   {
      if (strlen(tmpGradtype) >= 3)
      {
         P_setstring(GLOBAL,"gradtype",tmpGradtype,1);

//       see checkGradtype() in psgmain.cpp
         specialGradtype = 0;
         if ( P_getreal(GLOBAL,"pfg1board",&pfgBoard,1) == 0)
         {
            if (pfgBoard > 0.5)
            {
               strcpy(tmpGradtype,"   ");
               P_getstring(GLOBAL,"gradtype",tmpGradtype,1,MAXSTR-1);
               if (tmpGradtype[2] == 'a')
               {
                  specialGradtype = 'a';
               }
               else if (tmpGradtype[2] == 'h')
               {
                  specialGradtype = 'h';
               }
               if (specialGradtype)
               {
                  tmpGradtype[2] = 'p';
                  P_setstring(GLOBAL,"gradtype",tmpGradtype,1);
               }
            }
         }
      }
   }
}
Esempio n. 13
0
void abort_message(const char *format, ...)
{
    va_list vargs;
    char  emessage[1024];

    if (dpsTimer || nomessageflag)
    {
        closeFiles();
        close_error(1);       /* 1 arg means fail/abort */
        exit(1);
    }
    va_start(vargs, format);
    vfprintf(stdout,format,vargs);
    va_end(vargs);
    if ( *(format+(strlen(format)-1)) != '\n')
        fprintf(stdout,"\n");
    if (!erroropen)
    {
        if (P_getstring(GLOBAL, "userdir", errorpath, 1, MAXPATHL) >= 0)
        {
            strcat(errorpath,"/psg.error");
            if ( (errorfile=fopen(errorpath,"w+")) )
                erroropen = 1;
        }
    }
    if (erroropen)
    {
        va_start(vargs, format);
        vfprintf(errorfile,format,vargs);
        va_end(vargs);
        fprintf(errorfile,"P.S.G. Aborted....\n");
        fprintf(stdout,"P.S.G. Aborted....\n");
    }
    va_start(vargs, format);
    vsprintf(emessage,format,vargs);
    va_end(vargs);
    closeFiles();
    if (newacq)
    {
        while (emessage[strlen(emessage)-1] == '\n')
            emessage[strlen(emessage)-1] = '\0';
        vnmremsg(emessage);
        if (!acqiflag && !dps_flag)
            release_console();
    }
    close_error(1);    /* 1 arg means fail/abort */
    exit(1);
}
Esempio n. 14
0
static int init_vars2()
/*************/
{
    char flag[16];

    /*spec1  = 0;
      spec2  = 1;
      next   = 2;*/
    spec_index = 3;
    scale = 0.0;
    /*init_display();*/
    dotflag = TRUE;
    if (P_getstring(CURRENT,"dotflag" ,flag, 1,16) == 0)
        dotflag = (flag[0] != 'n');
    return(COMPLETE);
}
Esempio n. 15
0
static int
deccWarnings()
{
    int rtn = FALSE;
    char buf[2];
    if (P_getstring(GLOBAL, "deccwarnings", buf, 1, sizeof(buf))
        || (buf[0] != 'n' && buf[0] != 'N'))
    {
        rtn = TRUE;
    }
#ifdef ECC_INCLUDE_MAIN
    return 1;
#else
    return rtn;
#endif
}
Esempio n. 16
0
int jcurwin_jexp(int expnum, int oldexpnum )
{
    int index, get1, get2, retval=1;
    double dval;
    vInfo info; /* int VnmrJViewId */
    char path[MAXSTR];
    struct stat     stat_blk;

    (void) oldexpnum;
    if (mode_of_vnmr==AUTOMATION) /* || (mode_of_vnmr==BACKGROUND) */ 
      return(retval);

    if (expnum > 0)
    {
      sprintf(path, "%s/lock_%d.primary", userdir, expnum);
      if (stat( path, &stat_blk ) != 0) return(retval);

      get1 = P_getVarInfo(GLOBAL, "jcurwin", &info);
      get2 = P_getreal(GLOBAL, "jviewports", &dval, 1);
/* read number of viewports from jviewports[1] */
      if (get1==0 && get2==0)
      {
	get2 = (int) (dval + 0.5);
	if ((get2 > 0) && (get2 <= info.size))
	{
	  for (index=0; index<get2; index++)
	  {
	    P_getreal(GLOBAL, "jcurwin", &dval, index+1);
	    if (expnum == (int)dval)
	    {
	      char mstr[MAXPATH];
/*	      sprintf(mstr, "viewport %d", index+1);
	      writelineToVnmrJ("vnmrjcmd",mstr);
	      sprintf(mstr, "vplayout use %d", index+1);
	      writelineToVnmrJ("vnmrjcmd",mstr);
*/
	      P_getstring(GLOBAL, "jviewportlabel", mstr, index+1, MAXPATH);
	      Winfoprintf("Cannot join workspace exp%d - in use by %s viewport.\n",expnum,mstr);
	      retval = 0;
	      break;
	    }
	  }
	}
      }
    }
    return(retval);
}
Esempio n. 17
0
static void saveViewPortAddr()
{
   char addr[MAXPATH];
   char path[MAXPATH];
   int pid, port;
   int fd;
   mode_t umaskVal;

   P_getstring(GLOBAL,"vnmraddr",addr,1,MAXPATH);
   sscanf(addr,"%s %d %d", path, &port, &pid);
   sprintf(path,"%s/persistence/.vp_%d_%d", userdir, jParent, jcurwin_cexpn());
   umaskVal = umask(0);
   fd = open(path, O_CREAT | O_RDWR | O_TRUNC, 0666);
   write(fd, &port, sizeof(port));
   write(fd, &pid, sizeof(pid));
   close(fd);
   (void) umask(umaskVal);
}
Esempio n. 18
0
File: cps.c Progetto: timburrow/ovj3
void getStringSetDefault(int tree, const char *name, char *buf, const char *def)
{
	int index;
	char *content;
	if (tree != CURRENT)
	{
		if (P_getstring(tree, name,buf,1,MAXSTR) < 0)
		strcpy(buf,def);
	}
	else
	{
	    index = find(name);   /* hash table find */
	    if (index != NOTFOUND)
	    {
		   content = ((char *) cvals[index]);
	       strncpy(buf,content,MAXSTR-1);
		   buf[MAXSTR-1] = 0;
	    }
	    else
		   strcpy(buf,def);
		}
}
Esempio n. 19
0
/* ---------------------------------------------------------------
|  var_active(varname,tree);
|
|  Purpose:
|	This module determines if the variable passed is active or not.
|	This is determined by looking at the variable information
|	 structure "_vInfo".
|	if a real variable the info.active is check.
|	if a string then it's value is checked for 'unused' value.
|       Returns 1 if active, 0 if not, and -1 if error.
|
|				Author Greg Brissey  5/13/86
+------------------------------------------------------------------*/
int var_active(char *varname, int tree)
{
    char	strval[20];
    int		ret;
    vInfo	varinfo;		/* variable information structure */

    if (bgflag)
	fprintf(stderr,"active(): Variable: %s, Tree: %d \n",varname,tree);
    if ( (ret = P_getVarInfo(tree,varname,&varinfo)) )
    {
	if (bgflag)
           fprintf(stderr,"Cannot find the variable: %s",varname);
	return(-1);
    }
    if (bgflag)
	fprintf(stderr,"active(): vInfo.basicType = %d \n",varinfo.basicType);
    if (varinfo.basicType != T_STRING)
    {
    	if (bgflag)
	    fprintf(stderr,"active(): vInfo.active = %d \n",varinfo.active);
    	if (varinfo.active == ACT_ON)
	    return(1);
    	else
	    return(0);
    }
    else  /* --- variable is string check is value for 'undef' --- */
    {
	P_getstring(tree,varname,strval,1,10);
	/*getparm(varname,"string",tree,&strval[0],10);*/
	if (bgflag)
	    fprintf(stderr,"active(): Value of String variable: '%s'\n",strval);
    	if ((strncmp(strval,"unused",6) == 0) || 
	    (strncmp(strval,"Unused",6) == 0) )
	    return(0);
    	else
	    return(1);
    }
}
Esempio n. 20
0
/*-----------------------------------------------------------
|
|   text_error()
|   Writes messages to a file named "psg.error" in the
|       vnmruser (env variable) directory.
|
+-----------------------------------------------------------*/
void text_error(const char *format, ...)
{
    va_list vargs;
    char  emessage[1024];

    if (nomessageflag)
        return;
    va_start(vargs, format);
    vfprintf(stdout,format,vargs);
    va_end(vargs);
    if ( *(format+(strlen(format)-1)) != '\n')
        fprintf(stdout,"\n");
    if (!erroropen)
    {
        if (P_getstring(GLOBAL, "userdir", errorpath, 1, MAXPATHL) >= 0)
        {
            strcat(errorpath,"/psg.error");
            if ( (errorfile=fopen(errorpath,"w+")) )
                erroropen = 1;
        }
    }
    if (erroropen)
    {
        va_start(vargs, format);
        vfprintf(errorfile,format,vargs);
        va_end(vargs);
    }
    if (newacq)
    {
        va_start(vargs, format);
        vsprintf(emessage,format,vargs);
        va_end(vargs);
        while (emessage[strlen(emessage)-1] == '\n')
            emessage[strlen(emessage)-1] = '\0';
        vnmremsg(emessage);
    }
}
Esempio n. 21
0
/*-----------------------------------------------------------
|
|   putCmd()
|   Writes commands to a file named "psgCmd" in the
|       curexp directory.
|
+-----------------------------------------------------------*/
void putCmd(const char *format, ...)
{
    va_list vargs;

    if (acqiflag || (setupflag > 0) || (dps_flag && !checkflag) )
        return;
    if (cmdOpen == 0)
    {
        if (P_getstring(GLOBAL, "curexp", cmdPath, 1, MAXPATHL) >= 0)
        {
            strcat(cmdPath,"/psgCmd");
            if ( (cmdFile=fopen(cmdPath,"w+")) )
                cmdOpen = 1;
        }
    }
    if (cmdOpen == 1)
    {
        va_start(vargs, format);
        vfprintf(cmdFile,format,vargs);
        va_end(vargs);
        if ( *(format+(strlen(format)-1)) != '\n')
            fprintf(cmdFile,"\n");
    }
}
Esempio n. 22
0
int autocmd(int argc, char *argv[], int retc, char *retv[])
{
	char	autodir[ MAXPATH+2 ], autoinfofil[ MAXPATH ],
		inputstr[ MAXPATH ];
	char    *pathptr;
	int	autodir_defined;
	int	l, r;
	FILE	*autoinfoptr;

/*  This process must be able to write to $vnmrsystem/conpar...  */

	disp_status( "AUTO    " );

/*  Establish current value of AUTODIR  */

	autodir[ 0 ] = '\0';		/*  Start with 0-length string */
	if (argc < 2) 			/*  No arguments, just command  */
	{
		r =  P_getstring(
		    GLOBAL, "autodir", &autodir[ 0 ], 1, MAXPATH
		);
		autodir_defined = (r == 0);
		if ( autodir_defined )
		  autodir_defined = !(strlen( &autodir[ 0 ] ) < 1);

		if ( !autodir_defined )
		  W_getInput( "Enter automation directory name: ",
			&inputstr[ 0 ], MAXPATH
		  );
		else
		{
                        /*
			 * Pass a separate string to W_getInput so as to avoid 
	    		 * overwriting AUTODIR if a <CR> gets typed.
                         */
			Winfoprintf(
			        "Automation directory is '%s'", &autodir[ 0 ] );
			W_getInput( "Enter new name, or <CR> to keep current: ",
				&inputstr[ 0 ], MAXPATH
			);
			if (inputstr[ 0 ] == '\0')
			   strcpy(&inputstr[ 0 ], &autodir[ 0 ]);
		}
	}
	else 				/*  Argument is value for AUTODIR  */
	{
		strcpy( &inputstr[ 0 ], argv[ 1 ] );
	}
	l = strlen( &inputstr[ 0 ] );
	if ( l <= MAXPATH-1)
        {
		if (inputstr[ 0 ] != '/')
		{
			pathptr = get_cwd();
			l += strlen( pathptr ) + 1;
			if (l < MAXPATH-1 )
			{  strcpy(&autodir[ 0 ], pathptr);
			   strcat(&autodir[ 0 ], "/");
			   strcat(&autodir[ 0 ], &inputstr[ 0 ]);
			}
		}
		else
		   strcpy( &autodir[ 0 ], &inputstr[ 0 ] );
        }
	if ( l > MAXPATH-1)
	{
		Werrprintf(
	    "Too many characters in full pathname of automation directory"
		);
		disp_status( "        " );
		ABORT;
	}
/*  Verify that 'autodir' is not the 0-length string; verify
    it is an absolute UNIX path name  */

	else if (l < 1)
	{
		Werrprintf("Error: value of automation directory not defined" );
		disp_status( "        " );
		ABORT;
	}

/*  Make the automation directory if not present.  All users get full
    access, barring umask.  Abort if a problem.  If using the SUN console,
    the PERROR output will go to the (hidden or closed) shelltool
    window - too bad!!	*/

	if (access( &autodir[ 0 ], 0 ) != 0)
	  if ( (r = mkdir( &autodir[ 0 ], 0777 )) )
	  {
		Werrprintf( "Error creating automation directory" );
		perror( "make automation directory" );
		disp_status( "        " );
		ABORT;
	  }

/*  Now this process must be able to read, write and execute (search)
    the automation directory.						*/

	if (access( &autodir[ 0 ], R_OK | W_OK | X_OK ))
	{
		Werrprintf( "Insufficent access to automation directory" );
		disp_status( "        " );
		ABORT;
	}

/*  Create special automation experiments, exp1 through exp4  */

	if (create_autoexps( &autodir[ 0 ] ) != 0) ABORT;

/*  Displayed status may be changed by creating experiments.  */

	disp_status( "AUTO    " );
	strcpy( &autoinfofil[ 0 ], &autodir[ 0 ] );
	strcat( &autoinfofil[ 0 ], "/autoinfo" );
	autoinfoptr = fopen( &autoinfofil[ 0 ], "w+" );
	if (autoinfoptr == NULL )
	{
		Werrprintf( "Error creating %s", &autoinfofil[ 0 ] );
		disp_status( "        " );
		ABORT;
	}
	fclose( autoinfoptr );			/* Someday this file will  */
						/* contain useful information */
/*  Ignore error from setstring, for now.  */

	r = P_setstring( GLOBAL, "autodir", &autodir[ 0 ], 1 );
	disp_status( "        " );
	RETURN;
}
Esempio n. 23
0
int autogo(int argc, char *argv[], int retc, char *retv[])
{
/*  The argument vector and return vector are used to call the
    "auto" and "autora" commands of VNMR.				*/

	char	enterfile[ MAXPATH ], newautodir[ MAXPATH ],
		macdir[MAXPATH], cp_autoq_cmd[ MAXPATH*2+4 ];
	char	*cmd_argvec[ 3 ];

	disp_status( "AUTOGO  " );

/*  Establish if path to automation queue is specified in the command (the
    first argument).  If not, ask for it.  Abort if none provided.	*/

	if (argc > 1) {
		if (strlen(argv[1]) > MAXPATH-1)
                {
			Werrprintf(
		    "%s: automation queue pathname too long", argv[ 0 ]
			);
			disp_status( "        " );
			ABORT;
		}
		else
		  strcpy( &enterfile[ 0 ], argv[ 1 ] );
	}
	else {
		enterfile[ 0 ] = '\0';	/* In case nothing is entered */
		W_getInput( "Location of automation queue: ",	
			&enterfile[ 0 ], MAXPATH
		);
	}
	if (strlen( &enterfile[ 0 ] ) < 1) {
		Werrprintf(
		    "%s:  automation queue pathname not specified", argv[ 0 ]
		);
		disp_status( "        " );
		ABORT;
	}

/*  This routine produces an error message if it detects an error.	*/

	if (check_autoqueue( argv[ 0 ], &enterfile[ 0 ], &macdir[0] ))
           ABORT;

/*  Now check if the command specifies the automation directory  */

	if (argc > 2) {
		cmd_argvec[ 0 ] = "auto";
		cmd_argvec[ 1 ] = argv[ 2 ];
		cmd_argvec[ 2 ] = NULL;
                /*
		 *  Command is:  auto('/usr2/auto')
    		 *  It will complain if it encounters a problem.
                 */
	}
	else {
		cmd_argvec[ 0 ] = "auto";
		cmd_argvec[ 1 ] = NULL;
	}

/*  The "auto" command clears the displayed status.  */

	if (autocmd( argc-1, &cmd_argvec[ 0 ], 0, NULL))
		ABORT;
	disp_status( "AUTOGO  " );

/*  Copy the enter queue file into the automation directory.  Borrow the string
    "newautodir" to store the value of this directory.  Its value should be
    explicitly retrieved now, since it may not have been defined earlier, or
    its value may have changed during the execution of the "autogo" command. */

	P_getstring(
		GLOBAL, "autodir", &newautodir[ 0 ], 1, MAXPATH
	);

/*  Borrow string "cp_autoq_cmd" to construct system enter queue.  Abort if
    the file exists and is of non-zero length.				*/

	sprintf( &cp_autoq_cmd[ 0 ], "%s/enterQ", &newautodir[ 0 ] );
	if (access( &cp_autoq_cmd[ 0 ], 0 ) == 0)
	{
		struct stat	buf;

		if (stat( &cp_autoq_cmd[ 0 ], &buf ) != 0)
		{
			Werrprintf(
	    "%s:  cannot access existing automation queue", argv[ 0 ]
			);
			disp_status( "        " );
			ABORT;
		};
		if (buf.st_size > 0)
		{
			Werrprintf(
	    "%s:  current automation queue is not empty", argv[ 0 ]
			);
			disp_status( "        " );
			ABORT;
		}
	}

	sprintf( &cp_autoq_cmd[ 0 ], "%s/gQ", &newautodir[ 0 ] );
	if (access( &cp_autoq_cmd[ 0 ], F_OK ) == 0)
	{
		if ( unlink( &cp_autoq_cmd[ 0 ] ) )
		{
			Werrprintf( "%s:  cannot remove %s", argv[ 0 ], &cp_autoq_cmd[ 0 ] );
			disp_status( "        " );
			ABORT;
		}
	}

	sprintf( &cp_autoq_cmd[ 0 ], "cp %s %s/enterQ",
		&enterfile[ 0 ], &newautodir[ 0 ]);
	system( &cp_autoq_cmd[ 0 ] );
        if (macdir[0] != '\0')
        {
	   sprintf( &cp_autoq_cmd[ 0 ], "cp -rf %s %s/enterQ.macdir",
		&macdir[ 0 ], &newautodir[ 0 ]);
	   system( &cp_autoq_cmd[ 0 ] );
        }

	cmd_argvec[ 0 ] = "autogo";
	cmd_argvec[ 1 ] = NULL;

	if (autora( 1, &cmd_argvec[ 0 ], 0, NULL )) ABORT;

	disp_status( "        " );
	RETURN;
}
Esempio n. 24
0
void find_dqdfrq(double *truefrq, double *dqdfrq)
{
  double dqd_overrange=0;
  int itmp, itmp2, itmp3, jtmp2, jtmp3, warnflag=0;
  char dqd_latch[MAXSTR];

  if ((dqd[0] == 'y') && !noiseacquire && !hwlooping &&
       ((dsp_params.il_oversamp > 1) || (dsp_params.rt_oversamp > 1)) )
  {
    if (*truefrq > 0.5) warnflag=1;
/*    *truefrq = sfrq; */
    *truefrq = sfrq + 10.5;
    *truefrq *= 1.0e6;
    *dqdfrq = ExpInfo.DspOslsfrq;
    P_getreal(GLOBAL, "overrange", &dqd_overrange, 1);
    P_getstring(GLOBAL, "latch", dqd_latch, 1, MAXSTR);
    if ((dqd_overrange > 0.1) && (dqd_latch[0] == 'y'))
    {
      if ((dqd_overrange > 9e4) && (fabs(*dqdfrq) > dqd_overrange) && (warnflag == 1)) /* overrange=1e5 */
      {
        text_error("WARNING: oslsfrq too large.\n");
        fprintf(stderr,"acquire(): oslsfrq overrange warning, cannot signal average\n  sfrq %12.1f  oslsfrq %12.1f  totfrq %12.1f\n", *truefrq - 10.5e6, *dqdfrq, *truefrq + *dqdfrq - 10.5e6);
      }
      else /* overrange = 1e4 */
      {
       if (fabs(*dqdfrq) > dqd_overrange)
       {
        itmp  = ((int)(*truefrq / 1e5)) % 10; /* could replace 1e4,1e4 with overrange */
        itmp2 = ((int)((*truefrq + *dqdfrq) / 1e5)) % 10;
        jtmp2 = ((int)((*truefrq + *dqdfrq) / 1e4)) % 10;
        if (itmp != itmp2)
        {
	  if ( ((*dqdfrq < 0) && (jtmp2 != 9)) || ((*dqdfrq > 0) && (jtmp2 != 0)) )
	  {
            itmp3 = ((int)((*truefrq - *dqdfrq) / 1e5)) % 10;
	    jtmp3 = ((int)((*truefrq - *dqdfrq) / 1e4)) % 10;
	    if (itmp != itmp3)
	    {
	      if ( ((*dqdfrq < 0) && (jtmp3 != 9)) || ((*dqdfrq > 0) && (jtmp3 != 0)) )
	      {
		if (warnflag == 1)
		{
	          text_error("WARNING: oslsfrq too large.\n");
	          fprintf(stderr,"acquire(): oslsfrq overrange warning, cannot signal average\n  sfrq %12.1f  oslsfrq %12.1f  totfrq %12.1f\n", *truefrq - 10.5e6, *dqdfrq, *truefrq + *dqdfrq - 10.5e6);
		}
	      }
	      else
	      {
                if (go_dqd == 0)
                {
	          *dqdfrq = -(*dqdfrq);
                  ExpInfo.DspOslsfrq = *dqdfrq;
                  go_dqd = 1;
                }
                else if (warnflag == 1)
                {
	          text_error("WARNING: oslsfrq too large.\n");
	          fprintf(stderr,"acquire(): oslsfrq overrange warning, cannot signal average\n  sfrq %12.1f  oslsfrq %12.1f  totfrq %12.1f\n", *truefrq - 10.5e6, *dqdfrq, *truefrq + *dqdfrq - 10.5e6);
                }
	      }
	    }
	    else
	    {
              if (go_dqd == 0)
              {
	        *dqdfrq = -(*dqdfrq);
                ExpInfo.DspOslsfrq = *dqdfrq;
                go_dqd = 1;
              }
              else if (warnflag == 1)
              {
	        text_error("WARNING: oslsfrq too large.\n");
	        fprintf(stderr,"acquire(): oslsfrq overrange warning, cannot signal average\n  sfrq %12.1f  oslsfrq %12.1f  totfrq %12.1f\n", *truefrq - 10.5e6, *dqdfrq, *truefrq + *dqdfrq - 10.5e6);
              }
	    }
	  }
        }
       }
      }
    }
    else
    {
/*
      itmp = ((int)(*truefrq / 1e4)) % 10;
      if (go_dqd == 0)
      {
        if (itmp < 5)
        {
          if (*dqdfrq < 0) *dqdfrq = -(*dqdfrq);
        }
        else
        {
          if (*dqdfrq > 0) *dqdfrq = -(*dqdfrq);
        }
        ExpInfo.DspOslsfrq = *dqdfrq;
        go_dqd = 1;
      }

      itmp  = ((int)(*truefrq / 1e5)) % 10;
      itmp2 = ((int)((*truefrq + *dqdfrq) / 1e5)) % 10;
      if ((itmp != itmp2) && (warnflag == 1))
      {
	text_error("WARNING: oslsfrq too large.\n");
	fprintf(stderr,"acquire(): oslsfrq overrange warning, cannot signal average\n  sfrq %12.1f  oslsfrq %12.1f  totfrq %12.1f\n", *truefrq - 10.5e6, *dqdfrq, *truefrq + *dqdfrq - 10.5e6);
      }
*/
      itmp  = ((int)(*truefrq / 1e5)) % 10;
      itmp2 = ((int)((*truefrq + *dqdfrq) / 1e5)) % 10;
      if (itmp != itmp2)
      {
        itmp3 = ((int)((*truefrq - *dqdfrq) / 1e5)) % 10;
	if (itmp != itmp3)
	{
	  if (warnflag == 1)
	  {
	    text_error("WARNING: oslsfrq too large.\n");
	    fprintf(stderr,"acquire(): oslsfrq overrange warning, cannot signal average\n  sfrq %12.1f  oslsfrq %12.1f  totfrq %12.1f\n", *truefrq - 10.5e6, *dqdfrq, *truefrq + *dqdfrq - 10.5e6);
	  }
	}
	else
	{
          if (go_dqd == 0)
          {
	    *dqdfrq = -(*dqdfrq);
            ExpInfo.DspOslsfrq = *dqdfrq;
            go_dqd = 1;
          }
          else if (warnflag == 1)
          {
	    text_error("WARNING: oslsfrq too large.\n");
	    fprintf(stderr,"acquire(): oslsfrq overrange warning, cannot signal average\n  sfrq %12.1f  oslsfrq %12.1f  totfrq %12.1f\n", *truefrq - 10.5e6, *dqdfrq, *truefrq + *dqdfrq - 10.5e6);
          }
	}
      }
    }

    *truefrq = tof; /* absolutely need this!!! */
  }
  else
  {
    *truefrq = 0.0;
    *dqdfrq  = 0.0;
  }
}
Esempio n. 25
0
int decc_compare(int argc, char *argv[], int retc, char *retv[])
{
int i, same;
char oe[MAXSTR],e[MAXSTR];
double otaus, taus, oampls, ampls, olimits, limits, oscales, scales;

   (void)argv;
   if (argc>1) debug=1;
   else        debug=0;
   if (debug)
      Winfoprintf("decc_compare started");

   same=1;
   for (i=1; i<53; i++)
   {
      if (P_getstring(GLOBAL, "enabled", e, i, MAXSTR) < 0)
      {
         Werrprintf("decc_compare: cannot find 'enabled'");
         same=0; break;
      }
      if (P_getstring(GLOBAL, "o_enabled", oe, i, MAXSTR) < 0)
      {
         Werrprintf("decc_compare: cannot find 'o_enabled'");
         same=0; break;
      }
      if (e[0] != oe[0])
      {
         same=0; break;
      }

      if (P_getreal(GLOBAL, "taus", &taus, i) < 0)
      {
         Werrprintf("decc_compare: cannot find 'taus'");
         same=0; break;
      }
      if (P_getreal(GLOBAL, "o_taus", &otaus, i) < 0)
      {
         Werrprintf("decc_compare: cannot find 'o_taus'");
         same=0; break;
      }
      if (fabs(taus-otaus) > 1e-6)
      {
         same=0; break;
      }
         
      if (P_getreal(GLOBAL, "ampls", &ampls, i) < 0)
      {
         Werrprintf("decc_compare: cannot find 'ampls'");
         same=0; break;
      }
      if (P_getreal(GLOBAL, "o_ampls", &oampls, i) < 0)
      {
         Werrprintf("decc_compare: cannot find 'o_ampls'");
         same=0; break;
      }
      if (fabs(ampls-oampls) > 1e-6)
      {
         same=0; break;
      }
   }

   if (same != 0) 
   {
      for (i=1; i<8; i++)
      {
         if (P_getreal(GLOBAL, "limits", &limits, i) < 0)
         {
            Werrprintf("decc_compare: cannot find 'limits'");
            same=0; break;
         }
         if (P_getreal(GLOBAL, "o_limits", &olimits, i) < 0)
         {
            Werrprintf("decc_compare: cannot find 'o_limits'");
            same=0; break;
         }
         if (fabs(limits-olimits) > 5e-9)
         {
            same=0; break;
         }
      }
   }
	
   if (same != 0) 
   {
      for (i=1; i<11; i++)
      {
         if (P_getreal(GLOBAL, "scales", &scales, i) < 0)
         {
            Werrprintf("decc_compare: cannot find 'scales'");
            same=0; break;
         }
         if (P_getreal(GLOBAL, "o_scales", &oscales, i) < 0)
         {
            Werrprintf("decc_compare: cannot find 'o_scales'");
            same=0; break;
         }
         if (fabs(scales-oscales) > 5e-9)
         {
            same=0; break;
         }
      }
   }

   if (same != 0)
   {
      if (P_getstring(GLOBAL, "decctool_fln", e, 1, MAXSTR) < 0)
      {
         Werrprintf("decc_compare: cannot find 'decctool_fln'");
         same=0;
      }
      if (P_getstring(GLOBAL, "deccorig_fln", oe, 1, MAXSTR) < 0)
      {
         Werrprintf("decc_compare: cannot find 'deccorig_fln'");
         same=0;
      }
      if ( strcmp(e,oe) )
      {
Winfoprintf("decc_compare: '%s' '%s'\n",e,oe);
         same=0;
      }
   }
	
       
   if (P_setreal(GLOBAL, "deccflag", (double)same, 7) < 0)
   {
      Werrprintf("decc_compare: cannot set deccflag[7]");
   }
   appendvarlist("deccflag");
   if (retc > 0) 
      retv[0] = realString((double) same);
   RETURN; 
}
Esempio n. 26
0
int decc_save(int argc, char *argv[], int retc, char *retv[])
{
char    sysgcoil[MAXSTR];
char    filename[MAXSTR];
char    decclibpath[MAXSTR];
char    fullpath[MAXSTR];
char    cmd[MAXSTR];
char   *tmpPtr, *tmpPtr2;
char    enabled[MAXSTR];
double  taus,ampls,scales,limits;
int     done, biggest;
int     i, j,k;
FILE   *fd,*fd2;

   (void) retc;
   (void) retv;
   if (argc>2) debug=1;
   else        debug=0;
   if (argc < 2)
   {
      Werrprintf("Usage -- decc_save(filename)");
      RETURN;
   }
   if (P_getstring(SYSTEMGLOBAL,"sysgcoil", sysgcoil, 1, MAXSTR) < 0)
   {
      Werrprintf("decc_save: cannot find 'sysgcoil'");
      RETURN;
   }

   strcpy(filename,argv[1]);
   if (debug) Winfoprintf("decc_save: inputfile='%s'\n",filename);
   if (filename[0] == '.')
   {  Werrprintf("decc_save: filename cannot start with a '.'");
      ABORT;
   }

   // strip version if any
   getVersion(filename);
   if (debug) Winfoprintf("decc_save: minus version='%s'\n",filename);

   // check decclib for highest version 
   strcpy(decclibpath,systemdir);
   strcat(decclibpath,"/imaging/decclib/");
   strcpy(fullpath,decclibpath);
   strcat(fullpath,filename);

   biggest = getBiggestVersion(fullpath);

   tmpPtr = tmpPtr2 = filename;
   sprintf(fullpath,"%s%s.%d",decclibpath,tmpPtr,biggest+1);

   done=0;
   while ( ! done)
   {
      Winfoprintf("decc_save: saving to '%s'",fullpath);
      // save to file
      fd = fopen(fullpath,"w");
      if (fd==0)
      {
         Werrprintf("decc_save: problem opening %s",fullpath);
         RETURN;
      }
      fprintf(fd,"filename\t%s.%d\n",tmpPtr2,biggest+1);
      fd2 = popen("date","r");
      fgets(cmd,MAXSTR,fd2);
      pclose(fd2);
      fprintf(fd,"date\t%s\n",cmd);
      
      i=1; j=0; k=0;
      while (j<13)
      {
         fprintf(fd,"%s",terms[j]);		// "xx" etc.
         k += nterms[j];
         while (i<=k)
         {
            fputc((int)'\t',fd);
            if (P_getstring(GLOBAL,"enabled",enabled,i,MAXSTR) < 0)
            {
               Werrprintf("decc_save: cannot find 'enabled'");
            }
            if (enabled[0]=='n') fputc((int)'*',fd);
            if (P_getreal(GLOBAL,"taus",&taus,i) < 0)
            {
               Werrprintf("decc_save: cannot find 'taus'");
            }
            if (P_getreal(GLOBAL,"ampls",&ampls,i) < 0)
            {
               Werrprintf("decc_save: cannot find 'ampls'");
            }
            fprintf(fd,"%g %g",taus/1000.0,ampls/100.0);
            i++;
         }
         fputc((int)'\n',fd);
         j++;
      }

      fprintf(fd,"eccscale");
      for (i=1; i<5; i++)
      {
         if (P_getreal(GLOBAL,"scales",&scales,i) < 0)
         {
            Werrprintf("decc_save: cannot find 'scales'");
         }
         fprintf(fd,"\t%g",scales);
      }
      fputc((int)'\n',fd);

      fprintf(fd,"shimscale");
      for (i=5; i<8; i++)
      {
         if (P_getreal(GLOBAL,"scales",&scales,i) < 0)
         {
            Werrprintf("decc_save: cannot find 'scales'");
         }
         fprintf(fd,"\t%g",scales);
      }
      fputc((int)'\n',fd);

      fprintf(fd,"totalscale");
      for (i=8; i<11; i++)
      {
         if (P_getreal(GLOBAL,"scales",&scales,i) < 0)
         {
            Werrprintf("decc_save: cannot find 'scales'");
         }
         fprintf(fd,"\t%g",scales);
      }
      fputc((int)'\n',fd);

      fprintf(fd,"slewlimit");
      for (i=1; i<5; i++)
      {
         if (P_getreal(GLOBAL,"limits",&limits,i) < 0)
         {
            Werrprintf("decc_save: cannot find 'limits'");
         }
         fprintf(fd,"\t%g",limits);
      }
      fputc((int)'\n',fd);

      fprintf(fd,"dutylimit");
      for (i=5; i<9; i++)
      {
         if (P_getreal(GLOBAL,"limits",&limits,i) < 0)
         {
            Werrprintf("decc_save: cannot find 'limits'");
         }
         fprintf(fd,"\t%g",limits);
      }
      fputc((int)'\n',fd);
      fclose(fd);

      // check if we need to save to .sysgcoil
      if (tmpPtr==sysgcoil) done=1;
      else
      {  
         tmpPtr=sysgcoil;
         sprintf(fullpath,"%s.%s",decclibpath,tmpPtr);
      }
   }
   // Now all is saved,
   // deccflag[8]=biggest+1 (version)
   // set o_enabled=enabled, o_taus=taus, o_ampls=ampls
   //     o_limits=limits,   o_scales=scales
   // and deccflag[7]=1 (Unmodified).
   if (P_setreal(GLOBAL,"deccflag", (double)(biggest+1),8) < 0)
   {
      Werrprintf("decc_save: cannot set 'deccflag[8]'i to version");
   }

   for (i=1; i< 53; i++)
   {   
      if (P_getstring(GLOBAL,"enabled",enabled,i,MAXSTR) < 0)
      {
         Werrprintf("decc_save: cannot find 'enabled'");
         break;
      }
      if (P_getreal(GLOBAL,"taus",&taus,i) < 0)
      {
         Werrprintf("decc_save: cannot find 'taus'");
         break;
      }
      if (P_getreal(GLOBAL,"ampls",&ampls,i) < 0)
      {
         Werrprintf("decc_save: cannot find 'ampls'");
         break;
      }

      if (P_setstring(GLOBAL,"o_enabled", enabled, i) < 0)
      {
         Werrprintf("decc_save: cannot find 'o_enabled'");
         break;
      }
      if (P_setreal(GLOBAL,"o_taus", taus, i) < 0)
      {
         Werrprintf("decc_save: cannot find 'o_taus'");
         break;
      }
      if (P_setreal(GLOBAL,"o_ampls", ampls, i) < 0)
      {
         Werrprintf("decc_save: cannot find 'o_ampls'");
         break;
      }
   }

   for (i=1; i<11; i++)
   {
      if (P_getreal(GLOBAL,"scales",&scales,i) < 0)
      {
         Werrprintf("decc_save: cannot find 'scales'");
         break;
      }
      if (P_setreal(GLOBAL,"o_scales", scales, i) < 0)
      {
         Werrprintf("decc_save: cannot find 'o_scales'");
         break;
      }
   }

   for (i=1; i<8; i++)
   {
      if (P_getreal(GLOBAL,"limits",&limits,i) < 0)
      {
         Werrprintf("decc_save: cannot find 'limits'");
         break;
      }
      if (P_setreal(GLOBAL,"o_limits", limits, i) < 0)
      {
         Werrprintf("decc_save: cannot find 'o_limits'");
         break;
      }
   } 

   if (P_setreal(GLOBAL, "deccflag", 1.0, 7) < 0) // Unmodified
   {
      Werrprintf("decc_save: cannot set deccflag[7]");
   }
   if (debug) Winfoprintf("decc_save: saved fln='%s',version=%d\n",
				filename,biggest+1);

   sprintf(fullpath,"%s.%d",filename,biggest+1);
   if (P_setstring(GLOBAL,"deccorig_fln", fullpath, 1) < 0)
   {
      Werrprintf("decc_load: cannot set 'deccorig_fln'");
   }
   if (P_setstring(GLOBAL,"decctool_fln", fullpath, 1) < 0)
   {
      Werrprintf("decc_load: cannot set 'decctool_fln'");
   }

   appendvarlist("deccflag deccorig_fln decctool_fln");
   RETURN;
}
Esempio n. 27
0
int decc_load(int argc, char *argv[], int retc, char *retv[])
{
char    decclibpath[MAXSTR];
char    filename[MAXSTR];
char    fullpath[MAXSTR];
char    oneline[MAXSTR];
char    delimiters[10], yesno[10];
char	cmd[MAXPATH];
char	sysgcoil[MAXSTR];
#ifdef LINUX
char   *ptr,*ptr2;
#else
char   *ptr,*ptr2, *strtok_r();
#endif
double  taus, ampls, scales, limits;
int     i,version;
int     param,first,last;
int	dotflag;
FILE *fd;
   (void) retc;
   (void) retv;
   if (argc>2) debug=1;
   else        debug=0;
   if (argc < 2)
   {
      Werrprintf("Usage -- decc_load(filename)");
      RETURN;
   }

   version = first = last = 0;
   param = SKIP;
   strcpy(filename,argv[1]);
   strcpy(decclibpath,systemdir);
   strcat(decclibpath,"/imaging/decclib/");
   strcpy(fullpath,decclibpath);

   if (filename[0] != '.') 
   {
      dotflag=0;
      if ((version = getVersion(filename)) < 0)
      { 
         // check decclib for highest version 
         strcat(fullpath,filename);
         version = getBiggestVersion(fullpath);
      }

      if (version == 0) 
         sprintf(fullpath,"%s%s",decclibpath,filename);
      else
         sprintf(fullpath,"%s%s.%d",decclibpath,filename,version);
   }
   else
   {
      dotflag=1;
      sprintf(fullpath,"%s%s", fullpath, filename);
   }
   Winfoprintf("decc_load: loading '%s'",fullpath);
   fd = fopen(fullpath, "r");
   if (fd == NULL)
   {  Werrprintf("decc_load: can not open %s",fullpath);
      RETURN;
   }

   strcpy(delimiters,"\n \t");
   ptr = fgets(oneline,MAXSTR,fd);
   if (debug) Winfoprintf("dec_load: oneline='%s'",oneline);
   while (ptr != NULL)
   {
      ptr2 = strtok_r(ptr,delimiters,&ptr);
      if (ptr2 == 0)
      {  ptr = fgets(oneline,MAXSTR,fd);
         continue;	// skip blank lines
      }
      if (debug) Winfoprintf("decc_load: linetype='%s'",ptr2);
      if ( (strcmp(ptr2,"filename") == 0) && (dotflag==1) )
      {  ptr2 = strtok_r(ptr,delimiters,&ptr);
          strcpy(filename,ptr2);
          if (debug) Winfoprintf("decc_load: filename='%s'",filename);
          if (P_setstring(GLOBAL,"deccorig_fln", filename, 1) < 0)
          {
             Werrprintf("decc_load: cannot set 'deccorig_fln'");
          }
          if (P_setstring(GLOBAL,"decctool_fln", filename, 1) < 0)
          {
             Werrprintf("decc_load: cannot set 'decctool_fln'");
          }
          version = getVersion(filename);
          param=SKIP;
      }
      else if (strncmp(ptr2,"da",2) == 0) { param=SKIP; }
      else if (strncmp(ptr2,"xx",2) == 0) { param=TAUS;   first=1;  last=6;  }
      else if (strncmp(ptr2,"yx",2) == 0) { param=TAUS;   first=7;  last=9;  }
      else if (strncmp(ptr2,"zx",2) == 0) { param=TAUS;   first=10; last=12; }
      else if (strncmp(ptr2,"xy",2) == 0) { param=TAUS;   first=13; last=15; }
      else if (strncmp(ptr2,"yy",2) == 0) { param=TAUS;   first=16; last=21; }
      else if (strncmp(ptr2,"zy",2) == 0) { param=TAUS;   first=22; last=24; }
      else if (strncmp(ptr2,"xz",2) == 0) { param=TAUS;   first=25; last=27; }
      else if (strncmp(ptr2,"yz",2) == 0) { param=TAUS;   first=28; last=30; }
      else if (strncmp(ptr2,"zz",2) == 0) { param=TAUS;   first=31; last=36; }
      else if (strncmp(ptr2,"xb",2) == 0) { param=TAUS;   first=37; last=40; }
      else if (strncmp(ptr2,"yb",2) == 0) { param=TAUS;   first=41; last=44; }
      else if (strncmp(ptr2,"zb",2) == 0) { param=TAUS;   first=45; last=48; }
      else if (strncmp(ptr2,"b0",2) == 0) { param=TAUS;   first=49; last=52; }
      else if (strncmp(ptr2,"ec",2) == 0) { param=SCALES; first=1;  last=4;  }
      else if (strncmp(ptr2,"sh",2) == 0) { param=SCALES; first=5;  last=7;  }
      else if (strncmp(ptr2,"to",2) == 0) { param=SCALES; first=8;  last=10; }
      else if (strncmp(ptr2,"sl",2) == 0) { param=LIMITS; first=1;  last=4;  }
      else if (strncmp(ptr2,"du",2) == 0) { param=LIMITS; first=5;  last=7;  }

      switch(param)
      {  case TAUS:
              for (i=first; i<=last; i++)
              {  ptr2 = strtok_r(ptr,delimiters,&ptr);
                 if (*ptr2 == '*')
                 {  strcpy(yesno,"n");
                    ptr2++;
                 }
                 else
                 {  strcpy(yesno,"y");
                 }
                 if (P_setstring(GLOBAL,"enabled", yesno, i) < 0)
                 {  Werrprintf("decc_load: cannot set 'enabled'");
                 }
                 if (P_setstring(GLOBAL,"o_enabled", yesno, i) < 0)
                 {  Werrprintf("decc_load: cannot set 'o_enabled'");
                 }
                 taus = atof(ptr2) * 1000.0;
                 if (P_setreal(GLOBAL,"taus",taus,i) < 0)
                 {  Werrprintf("decc_load: cannot set 'taus'");
                 }
                 if (P_setreal(GLOBAL,"o_taus",taus,i) < 0)
                 {  Werrprintf("decc_load: cannot set 'o_taus'");
                 }
                 ptr2 = strtok_r(ptr,delimiters,&ptr);
                 ampls = atof(ptr2) * 100.0;
                 if (P_setreal(GLOBAL,"ampls",ampls,i) < 0)
                 {  Werrprintf("decc_load: cannot set 'ampls'");
                 }
                 if (P_setreal(GLOBAL,"o_ampls",ampls,i) < 0)
                 {  Werrprintf("decc_load: cannot set 'o_ampls'");
                 }
                 if (debug)
                    Winfoprintf("decc_load: i=%d e=%s t=%f a=%f",
					i,yesno, taus, ampls);
              }
              break;
         case SCALES:
              for (i=first; i<=last; i++)
              {  ptr2 = strtok_r(ptr,delimiters,&ptr);
                 if (ptr2 == 0)
                    scales = 0.0;
                 else
                    scales = atof(ptr2);
                 if (P_setreal(GLOBAL,"scales",scales,i) < 0)
                 {  Werrprintf("decc_load: cannot set 'scales'");
                 }
                 if (P_setreal(GLOBAL,"o_scales",scales,i) < 0)
                 {  Werrprintf("decc_load: cannot set 'o_scales'");
                 }
              }
              break;
         case LIMITS:
              for (i=first; i<=last; i++)
              {  ptr2 = strtok_r(ptr,delimiters,&ptr);
                 if (ptr2 == 0)
                    limits = 0.0;
                 else
                    limits = atof(ptr2);
                 if (P_setreal(GLOBAL,"limits",limits,i) < 0)
                 {  Werrprintf("decc_load: cannot set 'limits'");
                 }
                 if (P_setreal(GLOBAL,"o_limits",limits,i) < 0)
                 {  Werrprintf("decc_load: cannot set 'o_limits'");
                 }
              }
              break;
      }
      ptr = fgets(oneline,MAXSTR,fd);
   }
   if (P_setreal(GLOBAL, "deccflag", 1.0, 7) < 0) // Unmodified
   {
      Werrprintf("decc_load cannot set deccflag[7]");
   }
   if (P_setreal(GLOBAL,"deccflag", (double)(version),8) < 0)
   {
      Werrprintf("decc_load: cannot set 'deccflag[8]' to version");
   }
 
   appendvarlist("enabled,taus,ampls,scales,limits,deccflag,deccorig_fln,decctool_fln");
   if (P_getstring(SYSTEMGLOBAL,"sysgcoil", sysgcoil, 1, MAXSTR) < 0)
   {
      Werrprintf("decc_load: cannot find 'sysgcoil'");
   }
   else
   {
      strcpy(cmd,"cp ");	// "cp "
      strcat(cmd,fullpath);     // "cp /vnmr/imaging/decclib/new.3"
      strcat(cmd," ");     	// "cp /vnmr/imaging/decclib/new.3"
      strcat(cmd,decclibpath);  // "cp .../new.3 /vnmr/imaging/decclib"
      strcat(cmd,"/.");		// "cp .../new.3 .../."
      strcat(cmd,sysgcoil);	// "cp .../new.3 .../.sysgcoil"
      system(cmd);
   }
   if (debug) Winfoprintf("decc_load: Done!");
   fclose(fd);
   RETURN;
}
Esempio n. 28
0
pulsesequence()
{
	/* Internal variable declarations *********************/
	char txphase[MAXSTR];
	char rxphase[MAXSTR];
    char blankmode[MAXSTR]={0};
	double  postDelay;
	double rfDuration;
	double acqt;
	int i,ret=-1;
	static int phs1[4] = {0,2,1,3}; /* from T1meas.c */

	/*************************************************/                                     
	/*  Initialize paramter **************************/
	i                = 0;
	postDelay        = 0.5;
	acqt             = 0.0;
	getstr("rxphase",rxphase);
	getstr("txphase",txphase);  

	ret = P_getstring(GLOBAL,"blankmode",blankmode,1,MAXSTR);
    //getparm("blankmode","string",GLOBAL,blankmode,MAXSTR);
	postDelay = tr - at;

   //printf("blankmode=%s\n",blankmode);
                        
	/*************************************************/
	/* check phase setting ***************************/
	if ( (txphase[0] =='n')   && (rxphase[0] =='n') )
	{
		abort_message("ERROR - Select at least one phase [Tx or Rx]\n");   
	}

	/**************************************************/
	/* check pulse width  *****************************/
	rfDuration = shapelistpw(p1pat, p1);     /* assign exitation pulse  duration */
	acqt = rfDuration + rof1 - alfa;
	if (FP_GT(acqt, at))
	{
		abort_message("Pulse duration too long. max [%.3f]    ms\n",(at-rof1+alfa)*1000.0);   
	}
    if(ret==0 && blankmode[0]=='u')
    	obsunblank();
	delay(postDelay);
    
	settable(t1,4,phs1); /*from T1meas.c */
	getelem(t1,ct,v11);  /*from T1meas.c */
	setreceiver(t1);                    
	/*==============================================*/
	/*  START LOOPBACK PULSE SEQUENCE               */
	/*==============================================*/
	status(A);
	obsoffset(resto);

	/* TTL trigger to scope sequence ****************************/       
	sp1on();             

	/* Relaxation delay ***********************************/       
    xgate(ticks);

	/* RF pulse *******************************************/ 
	obspower(tpwr);
	obspwrf(tpwrf);
	ShapedXmtNAcquire(p1pat, rfDuration, v11, rof1, OBSch);

	endacq();
	sp1off();
    if(ret==0 && blankmode[0]=='u')
 		obsunblank();
}
Esempio n. 29
0
/*-------------------------------------------------------------------
|
|	test4acquire() 
|	check too see if data has been acquired yet.
|	if it has not then do an implicit acuire.
|	else do not.
|				Author Greg Brissey  7/10/86
+------------------------------------------------------------------*/
void test4acquire()
{
    int	    i;
    int	    chan;
    int     MINch;
    double  acqdelay;	/* delay time between receiver On an data acquired*/
    codeint *tmpptr;	/* temp pointer into codes */
    extern void prg_dec_off();
    double truefrq=0.0, dqdfrq=0.0;
    char osskip[4];

    if (bgflag)
	fprintf(stderr,"test4acquire(): acqtriggers = %d \n",acqtriggers);
    if (acqtriggers == 0)	/* No data acquisition Yet? */
    {
	if (nf > 1.0)
	{
	    text_error("Number of FIDs (nf) Not Equal to One\n");
	    psg_abort(0);
	}
        if (ap_interface < 4)
	   HSgate(rcvr_hs_bit,FALSE);	/* turn receiver On */
	else
           SetRFChanAttr(RF_Channel[OBSch], SET_RCVRGATE, ON, 0);

	if (newacq)
        {
           /* execute osskip delay if osskip parameter set */
           if ((P_getstring(GLOBAL,"qcomp",osskip,1,2)) == 0)
           {
             if (osskip[0] == 'y')
             {
               /* fprintf(stderr,"hwlooping:test4acquire(): executing dsposskipdelay= %g\n", dsposskipdelay); */
               if (dsposskipdelay >= 0.0) G_Delay(DELAY_TIME, dsposskipdelay, 0);
             }
           }

           HSgate(INOVA_RCVRGATE,FALSE);        /* turn receiver On */
        }

	/* txphase(zero);	*/	/* set xmitter phase to zero */
	/* decphase(zero);	*/	/* set decoupler phase to zero */
	/* acqdelay = alfa + (1.0 / (beta * fb) ); */

	for (i = 1; i <= NUMch; i++)  /* zero HS phaseshifts */
	   SetRFChanAttr(RF_Channel[i], SET_RTPHASE90, zero, 0);

	if ((!noiseacquire) && (dsp_params.il_oversamp > 1))
	   find_dqdfrq(&truefrq, &dqdfrq);
	if (fabs(dqdfrq) > 0.1)
	   set_spare_freq(OBSch); 
/*	   obsoffset(truefrq+dqdfrq); */

	acqdelay = alfa + (1.0 / (beta * fb) );
	if (acqdelay > ACQUIRE_START_DELAY)
	   acqdelay = acqdelay - ACQUIRE_START_DELAY;
	if ((fabs(dqdfrq) > 0.1) && (acqdelay > 1.7e-6)) /* more like 40us?? */
	    acqdelay = acqdelay - 1.7e-6;

        if ((acqdelay < 0.0) && (ix == 1))
	   text_error("Acquisition filter delay (fb, alfa) is negative (%f).\n",
             acqdelay);
        else
	   G_Delay(DELAY_TIME,acqdelay,0);	/* alfa delay */
	acquire(np,1.0/sw);	/* acquire data */

	MINch = (ap_interface < 4) ? DODEV : TODEV;
	for (chan = MINch; chan <= NUMch; chan++)
	{
           if ( is_y(rfwg[chan-1]) )
           {
	      if ( (ModInfo[chan].MI_dm[0] == 'n') ||
                   ((ModInfo[chan].MI_dm[0] == 'y') &&
		    (ModInfo[chan].MI_dmm[0] != 'p')) )
              {
                 prg_dec_off(2, chan);
              }
           }
        }

	tmpptr = Aacode + multhwlp_ptr; /* get address into codes */
	*tmpptr = 1;		/* impliicit acquisition */
    }
    if (newacq)
    {
	if (explicitacq)
	{
              codeint *ptr;
	      /* update last acquire with disable overload */;
    	      ptr = Aacode + disovld_ptr;
	      *ptr++ = DISABLEOVRFLOW;
      	      *ptr = adccntrl;
	}
	/* Always set to FALSE for the next array element */
	explicitacq = FALSE;
    }

    if (grad_flag == TRUE) 
    {
      zero_all_gradients();
    }
    if (newacq)
    {
      gatedecoupler(A,15.0e-6);	/* init to status A conditions */
      statusindx = A;
    }
    putcode(STFIFO);	/* start fifo if it already hasn't */
    putcode(HKEEP);		/* do house keeping */
    if (newacq)
    {
      if ( getIlFlag() )
      {
	ifzero(ilflagrt);
    	   putcode(IFZFUNC);	/* brach to start of scan (NSC) if ct<nt */
	   putcode((codeint)ct);
	   putcode((codeint)ntrt);
    	   putcode(nsc_ptr);	/* pointer to nsc */
	elsenz(ilflagrt);
     	   add(strt,one,tmprt);	
   	   putcode(IFZFUNC);	/* brach to start of scan (NSC) if ct<strt+1 */
	   putcode((codeint)ct);
	   putcode((codeint)tmprt);
    	   putcode(nsc_ptr);	/* pointer to nsc */
	   modn(ct, bsval, tmprt);
    	   putcode(IFZFUNC);	/* brach to start of scan (NSC) if ct%bs */
	   putcode((codeint)zero);
	   putcode((codeint)tmprt);
    	   putcode(nsc_ptr);	/* pointer to nsc */
	endif(ilflagrt);
      }
      else
      {
    	   putcode(IFZFUNC);	/* brach to start of scan (NSC) if ct<nt */
	   putcode((codeint)ct);
	   putcode((codeint)ntrt);
    	   putcode(nsc_ptr);	/* pointer to nsc */
      }
    }
    else
    {
    	putcode(BRANCH);	/* brach back to start of scan (NSC) */
    	putcode(nsc_ptr);	/* pointer to nsc */
    }
}
Esempio n. 30
0
/*---------------------------------------
|                                       |
|             init_wt2()/7              |
|                                       |
+--------------------------------------*/
int init_wt2(struct wtparams *wtpar, register float  *wtfunc,
             register int n, int rftflag, int fdimname, double fpmult, int rdwtflag)
{
    char                  wtfname[MAXSTR],
                          wtfilename[MAXPATHL],
                          parfilename[MAXPATHL],
                          run_usrwt[MAXSTR];
    int                   maxpoint,
                          sinesquared,
                          wtfile,
                          wtfileflag,
                          sa_first, sa_last,
                          res;
    float                 sind,
                          cosd,
                          ph,
                          phi,
                          awc;
    register int          i;
    register float        lbconst,
             lbvar,
             gfconst,
             gfvar,
             f,
             max,
             sinc,
             cosc,
             *fpnt,
             lastwtval,
             sbfunc;
    FILE                  *fopen(),
                          *fileres;


    if (wtpar->sw == 0.0)
    {
        Werrprintf("Error:  sw is zero.");
        return(ERROR);
    }

    /**************************************************
    *  Section for user-defined weighting functions.  *
    **************************************************/

    strcpy(wtfname, "");
    if (fdimname & S_NI2)
    {
        res = P_getstring(CURRENT, "wtfile2", wtfname, 1, MAXPATHL-1);
    }
    else if (fdimname & (S_NF|S_NI))
    {
        res = P_getstring(CURRENT, "wtfile1", wtfname, 1, MAXPATHL-1);
    }
    else
    {
        res = P_getstring(CURRENT, "wtfile", wtfname, 1, MAXPATHL-1);
    }

    wtfileflag = ((res == 0) && (strcmp(wtfname, "") != 0));

    /***********************************************
    *  Initialize weighting function data.  It is  *
    *  necessary to do this even if no weighting   *
    *  is active because of WTI.                   *
    ***********************************************/

    fpnt = wtfunc;
    for (i = 0; i < n; i++)
        *fpnt++ = 1.0;

    /************************
    *  Set weighting flag.  *
    ************************/

    if ( !(wtpar->lb_active || wtpar->sb_active || wtpar->gf_active || wtpar->sa_active ||
            wtfileflag) )
    {
        wtpar->wtflag = FALSE;
        return(COMPLETE);
    }

    /***************************************************************
    *  Initiate user-defined weighting routines.  The executable   *
    *  "wtfile" is found in the user's "wtlib" directory and the   *
    *  corresponding parameter set, in the current experiment      *
    *  directory with the extension ".wtp".  The file containing   *
    *  the user-written, formatted weighting data is found in the  *
    *  current experiment directory.                               *
    ***************************************************************/

    fpnt = wtfunc;
    if (wtfileflag)
    {
        strcpy(parfilename, curexpdir);
#ifdef UNIX
        strcat(parfilename, "/");
#endif
        strcat(parfilename, wtfname);
        strcat(parfilename, ".wtp");

        strcpy(wtfilename, userdir);
#ifdef UNIX
        strcat(wtfilename, "/wtlib/");
#else
        vms_fname_cat(wtfilename, "[.wtlib]");
#endif
        strcat(wtfilename, wtfname);
#ifndef UNIX				/*  Presumably VMS  */
        strcat(wtfilename, ".exe" );
#endif

        fileres = fopen(wtfilename, "r");

        /*****************************************************************
        * If there is no user-weighting program in the user's wtlib,     *
        * look for a file containing the user-weighting function written *
        * out explicitly in the current experiment directory             *
        *****************************************************************/

        if (fileres == 0)
        {
            strcpy(wtfilename, curexpdir);
#ifdef UNIX
            strcat(wtfilename, "/");
#endif
            strcat(wtfilename, wtfname);

            fileres = fopen(wtfilename, "r");
            if (fileres == 0)
            {
                Werrprintf("Unable to find requested user-weighting files");
                return(ERROR);
            }

            /****************************************************
            *  Read in user-defined, formatted weighting data.  *
            ****************************************************/

            i = 0;
            while (fscanf(fileres, "%f", fpnt) != EOF)
            {
                fpnt++;
                if (++i == n)
                    break;
            }

            lastwtval = *(fpnt - 1);
            for ( ; i < n; i++)
                *fpnt++ = lastwtval;
            fclose(fileres);
        }
        else
        {
            fclose(fileres);

            if (!rdwtflag)
            {
#ifdef UNIX

                /*  The UNIX command includes the complete path.  */

                sprintf( &run_usrwt[ 0 ],
                         "%s %s %s %s %14d %7d %d",
                         wtfilename, curexpdir, wtfname, parfilename,
                         (int) (wtpar->sw*1000.0), n, rftflag);

#else

                /*
                 *  For VMS, necessary to define a DCL symbol
                 *  to reference the user's program.
                 */
                {
                    char    wt_sym_value[ MAXPATHL ];
                    int     symbol_descr[ 2 ], value_descr[ 2 ], one;

                    wt_sym_value[ 0 ] = '$';
                    wt_sym_value[ 1 ] = '\0';
                    strcat( &wt_sym_value[ 0 ], wtfilename );
                    symbol_descr[ 0 ] = strlen( wtfname );
                    symbol_descr[ 1 ] = (int) wtfname;
                    value_descr[ 0 ]  = strlen( &wt_sym_value[ 0 ] );
                    value_descr[ 1 ] =  (int) &wt_sym_value[ 0 ];
                    one = 1;        /* because LIB$GETSYMBOL wants a reference */

                    LIB$SET_SYMBOL( &symbol_descr[ 0 ], &value_descr[ 0 ], &one );

                    /*
                     *  The VMS command only has the command name and arguments,
                     *  and not the complete path.
                     */
                    sprintf( &run_usrwt[ 0 ],
                             "%s %s %s %s %14d %7d %d",
                             wtfname, curexpdir, wtfname, parfilename,
                             (int) (wtpar->sw*1000.0), n, rftflag);
                }
#endif

                /**********************************************************
                *  Now execute the user's program to produce the desired  *
                *  weighting function.  The weighting function will be    *
                *  written out to disk by the user's program.             *
                **********************************************************/

                system( &run_usrwt[ 0 ] );
            }

            /********************************************************
            *  Read user-calculated weighting data in from the ap-  *
            *  propriate file in the current experiment directory.  *
            ********************************************************/

            strcpy(wtfilename, curexpdir);
#ifdef UNIX
            strcat(wtfilename, "/");
#endif
            strcat(wtfilename, wtfname);
            strcat(wtfilename, ".wtf");

            wtfile = open(wtfilename, O_RDONLY, 0666);
            if (wtfile == 0)
            {
                Werrprintf("Error opening user-calculated weighting file");
                return(ERROR);
            }
            if ((res = read(wtfile, fpnt, sizeof(float)*n)) < 0)
            {
                Werrprintf("Error in reading user-calculated weighting data");
                close(wtfile);
                return(ERROR);
            }

            close(wtfile);
        }
    }

    /************************************************
    *  Section for exponential weighting functions  *
    ************************************************/

    lbconst = 0.0;
    if (wtpar->lb_active)
    {
        if (wtpar->lb < -1e6)
            wtpar->lb = -1e6;
        if (wtpar->lb > 1e6)
            wtpar->lb = 1e6;
        lbconst = wtpar->lb/(0.31831*wtpar->sw);
        if (rftflag)
            lbconst /= 2.0;
    }
    if (wtpar->sa_active)
    {
        sa_first = (wtpar->sas_active) ? wtpar->sas : 0;
        sa_last = wtpar->sa + sa_first;
    }
    else
    {
        sa_first = 0;
        sa_last = n;
    }

    /*****************************************
    *  Section for sine weighting functions  *
    *****************************************/

    sinesquared = 0;
    ph = phi = 0.0;
    cosc = sinc = cosd = sind = 0.0;
    if (wtpar->sb_active)
    {
        sinesquared = (wtpar->sb < 0.0);
        if (sinesquared)
            wtpar->sb *= (-1);

        if (wtpar->sb > 1000.0)
        {
            wtpar->sb = 1000.0;
        }
        else if (wtpar->sb < (1.0/wtpar->sw))
        {
            wtpar->sb = 1.0/wtpar->sw;
        }

        ph = M_PI_2/(wtpar->sw*wtpar->sb);
        if (rftflag)
            ph /= 2.0;

        phi = ph;
        sind = sin((double) (ph));
        cosd = cos((double) (ph));
        if (wtpar->sbs_active)
        {
            if (wtpar->sbs < -1000.0)
            {
                wtpar->sbs = -1000.0;
            }
            else if (wtpar->sbs > 1000.0)
            {
                wtpar->sbs = 1000.0;
            }

            ph = -M_PI_2*wtpar->sbs/wtpar->sb;
            if ((ph > 0.0) && (ph < M_PI))
            {
                sinc = sin((double) (ph));
                cosc = cos((double) (ph));
            }
            else
            {
                sinc = 0.0;
                cosc = 1.0;
            }
        }
        else
        {
            ph   = 0.0;
            sinc = 0.0;
            cosc = 1;
        }

        sbfunc = sinc;
        if (sinesquared)
            wtpar->sb *= (-1);
    }
    else
    {
        sbfunc = 1.0;
    }

    /*********************************************
    *  Section for gaussian weighting functions  *
    *********************************************/

    maxpoint = 0;
    gfconst = 0.0;
    if (wtpar->gf_active)
    {
        if (wtpar->gf < -1000.0)
        {
            wtpar->gf = -1000;
        }
        else if (wtpar->gf > 1000.0)
        {
            wtpar->gf = 1000.0;
        }
        if (wtpar->gf == 0.0)
        {
            wtpar->gf = 0.1;
        }

        gfconst = 1.0/( wtpar->sw*wtpar->gf);
        if (rftflag)
            gfconst /= 2.0;

        if (wtpar->gfs_active)
        {
            if (wtpar->gfs < -1000.0)
            {
                wtpar->gfs = -1000.0;
            }
            else if (wtpar->gfs > 1000.0)
            {
                wtpar->gfs = 1000.0;
            }

            maxpoint = wtpar->sw*wtpar->gfs;
            if (rftflag)
                maxpoint *= 2;

            if (maxpoint < 0)
            {
                maxpoint = 0;
            }
            else if (maxpoint >= n)
            {
                maxpoint = n-1;
            }
        }
    }

    /********************************************
    *  Section for additive weighting constant  *
    ********************************************/

    if (wtpar->awc_active)
    {
        awc = wtpar->awc;
    }
    else
    {
        awc = 0.0;
    }

    /************************************************
    *  Create weighting function in weight buffer.  *
    ************************************************/

    max = 0.0;
    fpnt = wtfunc;
    for (i = 0; i < n; i++)
    {
        f = (*fpnt) * sbfunc;
        if (wtpar->lb_active)
        {
            lbvar = i*lbconst;
            if (lbvar > MAX_WTVAL)
            {
                f *= MIN_WTFUNC;
            }
            else if (lbvar < MIN_WTVAL)
            {
                f *= MAX_WTFUNC;
            }
            else
            {
                f *= (float) (exp( -lbvar ));
            }
        }

        f += awc;
        if (wtpar->gf_active)
        {
            gfvar = (i - maxpoint)*gfconst;
            gfvar *= gfvar;
            if (gfvar > MAX_WTVAL)
            {
                f *= MIN_WTFUNC;
            }
            else
            {
                f *= (float) (exp( -gfvar ));
            }
        }
        if (wtpar->sa_active)
        {
            if (i < sa_first)
                f = 0.0;
            if (i > sa_last)
                f = 0.0;
        }

        if (f < 0.0)
        {
            f = 0.0;
        }
        else if (f > max)
        {
            max = f;
        }

        *fpnt++ = f;
        if (wtpar->sb_active)
        {
            if ((ph > 0.0) && (ph < M_PI))
            {
                /* cordic rotation */
                sbfunc = sinc*cosd + cosc*sind;
                cosc   = cosc*cosd - sinc*sind;
                sinc = sbfunc;
                if (sinesquared)
                    sbfunc *= sbfunc;
            }
            else
            {
                sbfunc = 0.0;
            }
            ph += phi;
        }
    }

    /*************************************************
    *  Scale weighting function so that the maximum  *
    *  value therein is 1.0, neglecting the effect   *
    *  "fpmult".                                     *
    *************************************************/

    fpnt = wtfunc;                  /* Reset "fpnt" pointer */
    if ((max > 0.0) && (max != 1.0))
    {
        f = 1/max;
        for (i = 0; i < n; i++)
        {
            *fpnt *= f;
            fpnt++;
        }
    }

    *wtfunc *= (float) fpmult;          /* Scales first point in weighting function */

    return(COMPLETE);
}