Ejemplo n.º 1
0
void fn_site(char **args)
{
    char *line;
    
    if (args == NULL) {
	line = read_string("site ", 1);
	if (line == NULL || line[0] == '\0') {
	    free(line);
	    disp_status(DISP_STATUS, "");
	    return;
	}
    }
    else
	line = args_to_string(args);

    ftp_site(line);

    free(line);
}
Ejemplo n.º 2
0
void fn_shell(char **args)
{
	char *cmd;

	if (args)
	    cmd = args[0];
	else
	    cmd = read_string("! ", 1);

	escape_disp(0);
	if (cmd[0] != '\0') {
		system(cmd);
		printf("[Press return] ");
		fflush(stdout);
		disp_prompt_char();
	}
	else
		system("$SHELL -i");
	disp_status(DISP_STATUS, "");
	reenter_disp();
}
Ejemplo n.º 3
0
void
fn_rmdir(char **args)
{
    char *name;
    
    if (args == NULL) {
	name = read_string("Directory: ", 1);
	if (name == NULL || name[0] == '\0') {
	    disp_status(DISP_STATUS, "");
	    free(name);
	    return;
	}
    }
    else
	name = args[0];

    ftp_rmdir(name);

    if (args == NULL)
	free(name);

    return;
}
Ejemplo n.º 4
0
int vnmr_unlock(int argc, char *argv[], int retc, char *retv[] )
{
	char		host_of_lock[ MAXPATHL ], jexpcmd[ 16 ],
			lock_file_name[ MAXPATHL ];
	int		expn, ival, mode_of_lock, pid_of_lock, force;

	expn = check_unlock_args( argc, argv, &force );
        if (expn == expdir_to_expnum(curexpdir))
           RETURN;
	if (expn < 1) ABORT;

	if (get_secondary_lock( expn, SEC_LOCK_COUNT ) != 0) {
		Werrprintf( "%s: cannot obtain secondary lock", argv[ 0 ] );
		ABORT;
	}
	get_primary_lockfile( expn, userdir, &lock_file_name[ 0 ] );
	ival = verify_primary_lock(
		&lock_file_name[ 0 ], &mode_of_lock, &host_of_lock[ 0 ], &pid_of_lock
	);
	remove_secondary_lock( expn );

	if (ival != 0) {
                if (access( &lock_file_name[ 0 ], F_OK ) == 0)
		  unlink( &lock_file_name[ 0 ] );
                sprintf( &jexpcmd[ 0 ], "jexp(%d)\n", expn );
                execString( &jexpcmd[ 0 ] );
                RETURN;
        }

	if (!force && (mode_of_lock == ACQUISITION)) {
		Werrprintf( "%s:  cannot remove acquisition lock", argv[ 0 ] );
		ABORT;
	}

	disp_status( "UNLOCK  " );
	if (!force && (strcmp( &host_of_lock[ 0 ], &HostName[ 0 ] ) != 0)) {
                Werrprintf( "%s:  experiment locked by remote host %s",
                        argv[ 0 ], &host_of_lock[ 0 ]
                );
                disp_status( "        " );
                ABORT;
        }
 
	ival = find_pid( pid_of_lock, argv[ 0 ] );
	if ( ival < 0) {
		disp_status( "        " );
		ABORT;
	}
	else if (!force && (ival > 0)) {
                Werrprintf(
                    "%s:  experiment locked by active process", argv[ 0 ]
                );
                disp_status( "        " );
                ABORT;
        }

	ival = unlink( &lock_file_name[ 0 ] );
	if (ival != 0) {
                Werrprintf( "%s:  unable to remove lock file", argv[ 0 ] );
                disp_status( "        " );
                ABORT;
        }

	Winfoprintf( "experiment %d unlocked", expn );
	disp_status( "        " );
	sprintf( &jexpcmd[ 0 ], "jexp(%d)\n", expn );
	execString( &jexpcmd[ 0 ] );
	RETURN;
}
Ejemplo n.º 5
0
void
show_prefix(void)
{

	disp_status(DISP_STATUS, ": %d", prefix_arg);
}
Ejemplo n.º 6
0
/*-----------------------------------------------
|						|
|		    lpcmd()			|
|						|
|  This function performs 1D LP on a single	|
|  or arrayed FID data set. A new fid file      |
|  is write to argv[1] or curexpdir/lp.fid      |
|  if not specified.                            |
|						|
+----------------------------------------------*/
int lpcmd(int argc, char *argv[], int retc, char *retv[])
{
  char		filepath[MAXPATHL];
  int		status,
		res,
		cblock,
		lastcblock,
		blocksdone,
		lsfidx,
		fidnum = 0,
		arg_no,
		npx,
		npadj,
		ftflag,
		noreal,
		element_no,
		lastfid,
		first,
		last,
		step,
		i,
		ctcount,
		realt2data;
  float		*outp;
  dpointers	inblock;
  dpointers	outblock;
  dfilehead	fidhead,
		datahead,
		phasehead;
  lpstruct	parLPinfo;
  ftparInfo	ftpar;
  char		newfidpath[MAXPATHL];

  Wturnoff_buttons();
  ftpar.procstatus = (CMPLX_t2|LP_F2PROC);

/************************************
*  Initialize all parameterizeable  *
*  variables                        *
************************************/

  arg_no = first = step = element_no = 1;
  ftpar.nblocks = MAXINT;
  last = MAXINT;

  noreal = ftflag = TRUE;
  ftpar.t2dc = -1;
  ftpar.zeroflag = FALSE;
  ftpar.sspar.lfsflag = ftpar.sspar.zfsflag = FALSE;
  ftpar.dspar.dsflag = FALSE;
  ftpar.dspar.fileflag = FALSE;
  ftpar.dspar.newpath[0] = '\0';
  ftpar.ftarg.useFtargs = 0;
 
  // default newfidpath
  sprintf(newfidpath,"%s/lp.fid",curexpdir);

/*********************************
*  Parse STRING arguments first  *
*********************************/

  while ( (argc > arg_no) && (noreal = !isReal(argv[arg_no])) )
  {
     if(strcmp(argv[arg_no],"rlp") == 0) { // e.g., lp('/tmp/lp.fid')
       ftpar.procstatus = (REAL_t2|LP_F2PROC);
     } else if(argv[arg_no][0] == '/') { // e.g., lp('/tmp/lp.fid')
        strcpy(newfidpath,argv[arg_no]);
     } else {
        sprintf(newfidpath,"%s/%s",curexpdir,argv[arg_no]);
     }
     arg_no++;
  }
  if(strcmp(newfidpath+strlen(newfidpath)-4,".fid") != 0 &&
     strcmp(newfidpath+strlen(newfidpath)-5,".fid/") != 0) strcat(newfidpath,".fid");
  
/******************************
*  Initialize data files and  *
*  FT parameters.             *
******************************/

  if ( i_ft(argc, argv, (S_DATA | S_FLOAT),
            0, 0, &ftpar, &fidhead, &datahead, &phasehead) )
  {
      disp_status("        ");
      ABORT;
  }
  
  if ( (res = D_getbuf(D_USERFILE, fidhead.nblocks,  0, &inblock)) ) { 
    ctcount=1;
  } else ctcount = inblock.head->ctcount; 

  if(ctcount<1) ctcount=1;

  if (ftpar.t2dc == -1)
  {
      ftpar.t2dc = (fidhead.status & S_DDR) ? FALSE : TRUE;
  }
  disp_current_seq();

  ftpar.cf = first;

     specIndex = first;		/* tells interactive programs
				   that new data exist */
/***************************************************
*  np0  =  total number of points in the fid       *
*  npx  =  used number of points in the fid        *
*                                                  *
*  Adjust "npx" and "lsfidx".                      *
***************************************************/

  lsfidx = ftpar.lsfid0;

    npx = ftpar.np0;
    npadj = npx - lsfidx;     /* adjusted number of FID data points */

  if (lsfidx < 0)
  {
     if (npx < 2)
     {
        Werrprintf("lsfid is too large in magnitude");
        ABORT;
     }
  }
  else
  {
     if (lsfidx >= npx)
     {
        Werrprintf("lsfid is too large in magnitude");
        ABORT;
     }
  }

  realt2data = (ftpar.procstatus & REAL_t2);
  fpointmult = getfpmult(S_NP, fidhead.status & S_DDR);

  // note, limit for forward LP is npadj (5th arg)
  if ( setlppar(&parLPinfo, S_NP, ftpar.procstatus, npadj/2, MAXINT,
		  LPALLOC, "ft2d") )
  {
     disp_status("        ");
     releaseAllWithId("ft2d");
     Wsetgraphicsdisplay("");		/* TRY THIS!  SF */
     ABORT;
  }

  if (parLPinfo.sizeLP)
  {
     int	maxlpnp,
		nptmp;

     if (realt2data)
     {
        Werrprintf("LP analysis is not supported for real t2 data");
        releaseAllWithId("ft2d");
        disp_status("        ");
        ABORT;
     }

     maxlpnp = npadj;

     for (i = 0; i < parLPinfo.sizeLP; i++)
     {
        lpparams = *(parLPinfo.parLP + i);

        if (lpparams.status & FORWARD)
        {
           nptmp = 2*(lpparams.startextpt + lpparams.ncextpt - 1);
           if (nptmp > maxlpnp)
              maxlpnp = nptmp;
        }
     }

     npadj = maxlpnp;
  }

/**************************
*  Start loop over FIDs.  *
**************************/

  lastfid = ftpar.ni0 * ftpar.ni1 * ftpar.arraydim;
     if (lastfid > ftpar.nblocks)
        lastfid = ftpar.nblocks;
     if (first > lastfid)
     {
        last = lastfid;
     }

  D_trash(D_DATAFILE);
  if(access(newfidpath,F_OK) != 0) {
   if(mkdir(newfidpath,0777)) {
     Winfoprintf("cannot create %s",newfidpath);
     ABORT;
   }
  }

  status = (S_DATA | S_FLOAT | S_COMPLEX | ftpar.D_cmplx);

  // now write out fid to newfidpath
  strcpy(filepath,newfidpath); 
  strcat(filepath,"/fid");
  
  datahead.status = fidhead.status;
  datahead.vers_id = fidhead.vers_id;
  datahead.nbheaders = fidhead.nbheaders;
  datahead.nblocks = fidhead.nblocks;
  datahead.ntraces = 1;
  datahead.np = npadj; 
  datahead.ebytes = fidhead.ebytes;
  datahead.tbytes = npadj*fidhead.ebytes;
  datahead.bbytes = datahead.tbytes + sizeof(dblockhead);;
   
  if (D_newhead(D_DATAFILE, filepath, &datahead) )
  {
     Werrprintf("cannot open file %s", filepath);
     ABORT;
  }

/***********************************************
*  Necessary until I can devise a function to  *
*  read only the FID block header in order to  *
*  determine if FID data exists in that block. *
***********************************************/

  blocksdone = FALSE;
  lastcblock = ftpar.nblocks;

  cblock = 0;

  while ((cblock < lastcblock) && (!blocksdone))
  {
     DPRINT1("block %d\n", cblock);
     if ( (res = D_allocbuf(D_DATAFILE, cblock, &outblock)) )
     {
        D_error(res);
        releaseAllWithId("ft2d");
        disp_status("        ");
        ABORT;
     }
     
     outblock.head->ctcount = ctcount;  /* default setting */
     outblock.head->scale = 0;    /* default setting */

       outp = (float *)outblock.data;

/**********************************************************
*  Start filling at the start of the output data buffer.  *
*  This facilitates the automatic array-like processing   *
*  of 'cf' and 'nf' in 1D.                                *
**********************************************************/

        fidnum = cblock;
     
     if (interuption)
     {
        releaseAllWithId("ft2d");
        D_trash(D_PHASFILE);
        D_trash(D_DATAFILE);
        disp_status("        ");
        ABORT;
     }

     if ((cblock + 1) == first)
     {
        if ( ! ((cblock+1) & 15) )
           disp_index(cblock + 1);
        if ( getfid(fidnum, outp, &ftpar, &fidhead, &lastfid) )
	{

	   Werrprintf("Unable to get FID data");
           releaseAllWithId("ft2d");
	   disp_index(0);
           disp_status("        ");
           ABORT;
        }

	if (lastfid == 0)
	{
           releaseAllWithId("ft2d");
	   disp_index(0);
	   disp_status("        ");
           ABORT;
        }
        else if (cblock == lastfid)
	{
           status = 0;
           blocksdone = TRUE;
           if (last == MAXINT)
           {
              last = cblock;
           }
	}
        else
        {
           if (parLPinfo.sizeLP)
           {
              for (i = 0; i < parLPinfo.sizeLP; i++)
              {
                 lpparams = *(parLPinfo.parLP + i);
                 disp_status(lpparams.label);

                 if (lpz(fidnum, outp, (npx - lsfidx)/2, lpparams))
                 {
                    Werrprintf("LP analysis failed");
                    releaseAllWithId("ft2d");
                    disp_index(0);
                    disp_status("       ");
                    ABORT;
                 }
              }
           }

           if (fpointmult != 1.0)
           {
              *outp *= fpointmult;
              *(outp + 1) *= fpointmult;
           }

           //zerofill(outp + npadj, ftpar.fn0 - npadj);

           last = cblock + 1;
        }

        // multiply outp by ctcount
        outp = (float *)outblock.data;
        outp += npadj;
        for(i = 0; i < npadj; i++)
	  *(--outp) *= ctcount;
       
        setheader(&outblock, status, 0, cblock+1,
			ftpar.hypercomplex);
        first += step;
     }
     else
     {
        setheader(&outblock, 0, 0, cblock, ftpar.hypercomplex);
     }

     if ( (res = D_markupdated(D_DATAFILE, cblock)) )
     {
        D_error(res);
        releaseAllWithId("ft2d");
        disp_index(0);
        disp_status("        ");
        ABORT;
     }

     if ( (res = D_release(D_DATAFILE, cblock)) )
     {
        D_error(res);
        releaseAllWithId("ft2d");
        disp_index(0);
        disp_status("        ");
        ABORT;
     }

     cblock++;
     if (!blocksdone)
        blocksdone = (first > lastcblock);
  }

  if ( (last != ftpar.nblocks) && (last != MAXINT) )
  {
     if ( (res = D_gethead(D_DATAFILE, &datahead)) )
     {
        D_error(res);
        disp_index(0);
        disp_status("        ");
        ABORT;
     }

     datahead.nblocks = last;
     if ( (res = D_updatehead(D_DATAFILE, &datahead)) )
     {
        D_error(res);
        disp_index(0);
        disp_status("        ");
        ABORT;
     }
  }

  releasevarlist();
  releaseAllWithId("ft2d");
  disp_index(0);
  disp_status("    ");
  D_close(D_USERFILE);
  D_flush(D_DATAFILE);
  D_trash(D_DATAFILE);
  D_trash(D_PHASFILE);

  // save procpar
  strcpy(filepath,newfidpath); 
  strcat(filepath,"/procpar");
  if(npx == npadj) {
     saveProcpar(filepath);
  } else {
     
     double sw,at, oldat;
     P_getreal(PROCESSED,"at", &oldat, 1);
     P_setreal(PROCESSED,"np",(double)npadj,1);
     if(!P_getreal(PROCESSED,"sw",&sw,1) && sw > 0) {
        at = npadj/(2*sw);
        P_setreal(PROCESSED,"at",at,1);	
     }  
     saveProcpar(filepath);
     P_setreal(PROCESSED,"np",(double)npx,1);
     P_setreal(PROCESSED,"at",oldat,1);
  }

  RETURN;
}
Ejemplo n.º 7
0
int flashc (int argc, char *argv[], int retc, char *retv[] )
/* 
Purpose:
-------
     Routine flashc is the main routine for the "flash convert" function.  It
edits the fid file in the current experiment, as well as process parameters nf,
ni, arraydim, arrayelemts, and cf to do the flash data format to standard 
format conversion.

Arguments:
---------
argc  :  (   )  Argument count.
argv  :  (   )  Command line arguments.
retc  :  (   )  Return argument count.  Not used here.
retv  :  (   )  Return arguments.  Not used here.
*/

/*  9-4-92
A single argument is allowed at this time to specify the number
of compressed traces to be left as a compressed nf block.  The use
for this is to allow compressed multislice or multiecho simultaneous
with compressed phase encoding.

    9-10-92
Argument list expanded to allow both compressed multi-slice, and
compressed multi-image formats.  The difference in format is:
(numerical values indicate acquisition order of traces)

  pe    1  2  3  4  5    ns ==>
  ||    6  7  8  9  10
  ||    11 12 13 14 15
  \/    ...
	..........  XX  where XX = phase encode * slices


  pe    1   pe+1  2pe+1  compressed images ==>
  ||    2   pe+2  2pe+2
  ||    3   pe+3  2pe+3
  \/    ...
	pe  pe*2 ... XX  where XX = phase encode * images


"rare" type data acquisition.

  pe    1   ne+1  2ne+1  ns ==>
  ||    2   ne+2  2ne+2
  ||    3   ne+3  2ne+3
  ||    ...
  ||	ne  ne*2 ... XX  where XX = num echoes (ne) * slices (ns)
  ||	
  ||	ne*ns+1  ne*ns+ne+1  ne*ns+2ne+1
  ||	ne*ns+2  ne*ns+ne+2  ne*ns+2ne+2
  ||	...
  ||	ne*ns+ne ne*ns+ne*2  ne*ns+ne*ns
  ||	.
  \/	2(ne*ns)+ne 2(ne*ns)+ne*2  2(ne*ns)+ne*ns
	.	
	... 		XX where XX = nv/ne*(ne * ns)

	


Examples of use from vnmr:
    flashc              simple compressed phase-encode
    flashc('ms',ns)     compressed phase-encode and compressed multi-slice
    flashc('mi',ns)     compressed multi-image and compressed phase-encode
    flashc('rare',ns,ne) compressed echo-train, multi-slice, and phase-encode

 'nf' argument added to reformat the data into the following:
    slice1 image, slice2 image, slice3 image,..., slicen image.

    flashc('nf')         simple compressed phase-encode
    flashc('nf','ms',ns) compressed phase-encode and compressed multi-slice
    flashc('nf','mi',ns) compressed multi-image and compressed phase-encode
    flashc('nf','rare',ns,ne) compressed echo-train, multi-slice, and 
								phase-encode
*/
{ /* Begin function flashc */
   /*
   Local Variables:
   ---------------
   default_fid  :  Complete file path to the fid file in the current experiment.
   temp_fid     :  Complete file path to a temporary version of the fid file in
		   the current experiment.
   nf		:  The Vnmr process parameter of the same name.
   ni		:  Ditto.
   ncomp	:  Number of traces to keep in compressed nf form.
   arraydim     :  Value of Vnmr process parameter arraydim.
   arrayelemts  :  Value of Vnmr process parameter arrayelemts.
   r            :  Return value of a function.
   format       :  image compression format; 0 = multi-slice, 1 = multi-image.
   */
   char   default_fid[MAXPATHL], temp_fid[MAXPATHL];
   int    format, r, nfarg;
   double ncomp, necho, nf, ni, arraydim, arrayelemts;

/* A convenience macro */
#define P_SETPAR(name,value)			\
   if (( r=P_setreal(PROCESSED,name,value,1)))	\
   {  P_err(r,name,":");			\
      ABORT;					\
   }						\
   if ( ( r=P_setreal(CURRENT,name,value,1)) )	\
   {  P_err(r,name,":");			\
      ABORT;					\
   }
   /*
   Begin Executable Code:
   --------------------
   */
   /* Verify that the user has passed correct number of arguments */
   if ( argc > 5 )
   {  Werrprintf ( "Flashc: wrong number of arguments." );
      ABORT;
   }

   nfarg = 0;
   /* Look for 'nf' argument */
   if (argc > 1)
   {
      if ( !strcmp(argv[1],"nf") )
      {
	nfarg = 1;
      }
   }
   /* Look for any arguments */
   if ( argc == 4+nfarg) {
      if ( !strcmp(argv[1+nfarg],"rare") )
      {
	  format = 2;
	  ncomp = atof(argv[2+nfarg]);
	  necho = atof(argv[3+nfarg]); /* necho= echo train of phase encode steps */
      }
      else
      {  Werrprintf ( "Flashc: unrecognized conversion type." );
         ABORT;
      }
   }
   else if ( argc == 3+nfarg ) {
      ncomp = atof(argv[2+nfarg]);
      necho = 1.0;
      if ( !strcmp(argv[1+nfarg],"ms") )
	  if (nfarg)
		format = 1;
	  else
		format = 0;
      else if ( !strcmp(argv[1+nfarg],"mi") )
	  if (nfarg)
		format = 0;
	  else
	  	format = 1;
      else
      {  Werrprintf ( "Flashc: unrecognized conversion type." );
         ABORT;
      }
   }
   else {
      ncomp = 1.0;
      necho = 1.0;
      format = 0;
   }


   /* Do an "interlock" to insure that flashc is called only once */
   if ( flash_interlock() != 0 )
      RETURN;


   /* Generate paths to the fid file and a parallel, temporary file. */
   (void)strcpy ( default_fid, curexpdir );
   (void)strcpy ( temp_fid, curexpdir );
#ifdef UNIX
   (void)strcat ( default_fid, "/acqfil/fid" );
   (void)strcat ( temp_fid, "/acqfil/flashc.temp" );
#else 
   vms_fname_cat ( default_fid, "[.acqfil]fid" );
   vms_fname_cat ( temp_fid, "[.acqfil]flashc.temp" );
#endif 

   /* Obtain the values of the process parameters */
   if ( get_flashc_parms ( &arraydim, &nf, &ni ) != 0 )
   {
      P_deleteVar ( PROCESSED, "flash_converted" );
      P_deleteVar ( CURRENT,   "flash_converted" );
      ABORT;
   }

   if (nfarg && (ncomp == 1.0)) ncomp = nf;

   /* Check nf to make sure it is divisible by ncomp */
   if ( (int)floor(nf+0.5) % (int)floor(ncomp+0.5) > 0 )
   {  Werrprintf ( "Flashc: ncomp is not a factor of nf." );
      P_deleteVar ( PROCESSED, "flash_converted" );
      P_deleteVar ( CURRENT,   "flash_converted" );
      ABORT;
   }
   /* Display status on screen */
   disp_status ( "FLASHC" );

   if (nfarg)
   {
   	/* Edit the fid file, may also revise parameters nf and ni. */
   	if ( nf_flash_convert ( default_fid, temp_fid, arraydim,
     	         format, ncomp, necho, nf, &ni ) != 0 )
        {
           P_deleteVar ( PROCESSED, "flash_converted" );
           P_deleteVar ( CURRENT,   "flash_converted" );
           disp_status ( "      " );
   	   ABORT;
        }
   }
   else
   {
   	/* Edit the fid file, may also revise parameter ni. */
   	if ( flash_convert ( default_fid, temp_fid, arraydim,
   	         format, ncomp, necho, nf, &ni ) != 0 )
        {
           P_deleteVar ( PROCESSED, "flash_converted" );
           P_deleteVar ( CURRENT,   "flash_converted" );
           disp_status ( "      " );
   	   ABORT;
        }
   }

   disp_status ( "      " );
   /* Write out the new parameter values */
   if (nfarg)
   {
   	P_SETPAR ( "nf", floor (ni*(nf / ncomp)+0.5) );
   	P_SETPAR ( "ni", 1.0 );
   }
   else
   {
   	P_SETPAR ( "nf", ncomp );
   	P_SETPAR ( "ni", floor ((nf / ncomp)+0.5) );
   }

   if ( arraydim > 1 )
      arrayelemts = 2;
   else
      arrayelemts = 1;
   P_SETPAR ( "arrayelemts", arrayelemts );

   if (nfarg)
      arraydim = floor(((arraydim/ni)*ncomp)+0.5);
   else
      arraydim *= floor ((nf / ncomp)+0.5);
   P_SETPAR ( "arraydim", arraydim );
   if ( ( r = P_setreal ( CURRENT, "cf", (float)1, 1 ) ) )
   {  P_err ( r, "cf", ":" );
      ABORT;
   }

   /* Display new parameters, and clear status on screen */
   appendvarlist("nf,ni,arrayelemts,arraydim,cf");

   Winfoprintf("Flash Convert reformatting completed.");
   /* Normal, successful return */
   RETURN;

/* Since this item was defined within this routine, get rid of it now */
#undef P_SETPAR

} /* End function flashc */
Ejemplo n.º 8
0
int dpf(int argc, char *argv[], int retc, char *retv[])
/*************/
{ int groups;
  int noisemult_p = 0;
  int numlines,maxlines;
  int i;
  int donll = TRUE;
  int noneg = FALSE;
  int top = FALSE;
  char command[128];
  char name[64];

  (void) retc;
  (void) retv;
  Wturnoff_buttons();
  leader_len = 20.0;
  axish = FALSE;
  axisp = FALSE;
  axisp_freq = 1.0;
  if (argc > 1)
  {
    for (i=1; i<argc; i++)
    {
      if (strcmp(argv[i],"off") == 0) {
	set_dpf_flag(0,"");
        redo_dpf_dpir();
	RETURN;
      } else if (strcmp(argv[i],"turnoff") == 0) {
        set_dpf_flag(0,"");
        RETURN;
      } else if (strcmp(argv[i],"noll") == 0) donll = FALSE;
      else if (strcmp(argv[i],"pos") == 0) noneg = TRUE;
      else if (strcmp(argv[i],"top") == 0) top = TRUE;
      else if (strcmp(argv[i],"axish") == 0) axish = TRUE;
      else if (strcmp(argv[i],"axisp") == 0)
      {
         axisp = TRUE;
         P_getreal(PROCESSED,"sfrq",&axisp_freq,1);
      }
      else if (strcmp(argv[i],"leader") == 0)
      {
         if (((i+1) < argc) && isReal(argv[i+1]) )
         {
            i++;
            leader_len = stringReal(argv[i]);
         }
      }
      else if (isReal(argv[i])) noisemult_p = i;
    }
  }
  if (donll) /* if not donll, dpf uses last previous line listing */
  {
    if (noisemult_p != 0)
    {
      if (noneg)
	strcpy(command,"nll('dpf','pos',");
      else
	strcpy(command,"nll('dpf',");
      strcat(command,argv[noisemult_p]);
      strcat(command,")\n");
    }
    else
    {
      if (noneg)
	strcpy(command,"nll('dpf','pos')\n");
      else
	strcpy(command,"nll('dpf')\n");
    }
    execString(command);
  }

  if(P_getreal(CURRENT, "dpf_sc2",&dpf_sc2,1)) dpf_sc2=sc2;
  if(P_getreal(CURRENT, "dpf_wc2",&dpf_wc2,1)) dpf_wc2=wc2;
  if(dpf_wc2>wc2) dpf_wc2=wc2;
  if(dpf_sc2<sc2) dpf_sc2=sc2;

  /* if (init2d(1,1)) return(ERROR); */
  scale = vs;
  if (normflag)
    scale *= normalize;
  /*   Wscrprintf("normflag=%d normalize=%g\n",normflag,normalize); */
  plot = (argv[0][0] == 'p');

/*select_init(get_rev, dis_setup, fdimname, doheaders, docheck2d, dospecpars,
            	doblockpars, dophasefile)*/
/*if (init2d(0,plot + 1)) return(ERROR); */
  if (select_init(
	0,
	plot+1,
	NO_FREQ_DIM,
	NO_HEADERS,
	DO_CHECK2D,
	DO_SPECPARS,
	NO_BLOCKPARS,
	NO_PHASEFILE
     ))
      return(ERROR);
  if ((numlines = getlines(noneg)) == 0) RETURN;
  if (!plot)
  {
    setwindows();
    dispcalib = (float) (mnumypnts-ymin) / (float) wc2max;

    getOptName(PEAK_MARK,name);
    set_line_thickness(name);
    getOptName(PEAK_NUM,name);
    set_graphics_font(name);
    
  }
  else
  { 
    double size = G_getCharSize("PeakNum");
    charsize(size);
    //charsize((double)0.7);
    dispcalib = ppmm / ymultiplier;
  }
  CharSize = ycharpixels + ycharpixels / 5;
  maxlines = dnpnt / CharSize;

  if (maxlines < numlines)
    remove_lines(maxlines,&numlines);
  if (numlines > 0)
  {
    //color(PARAM_COLOR);
    color(PEAK_MARK_COLOR);
    groups = groupcheck(numlines);
    if (debug1)
    {
      Wscrprintf("index high low newhigh newlow highlimit lowlimit\n");
      for (i = 1; i <= groups; i++)
        Wscrprintf("%d %d %d %d %d %d %d\n",i,ga[i].high,ga[i].low,
                   ga[i].newhigh,ga[i].newlow,ga[i].highlimit,ga[i].lowlimit);
    }
    label_proc = (top) ? (PFV) label_top : (PFV) label_bot;
    for (i = 1; i <= groups; i++)
      label_group(i);

    if (!plot) { // construct the command, and set the flag and command
      char cmd[64];
      if(argc > 1) {
        if (isReal(argv[1]) ) sprintf(cmd,"%s(%s",argv[0],argv[1]);
	else sprintf(cmd,"%s('%s'",argv[0],argv[1]);
	for(i=2;i<argc;i++)
        {
           if (isReal(argv[i]) )
           {
	      strcat(cmd,",");
              strcat(cmd,argv[i]);
           }
	   else
           {
	      strcat(cmd,",'");
              strcat(cmd,argv[i]);
	      strcat(cmd,"'");
           }
	}
	strcat(cmd,")\n");
      } else sprintf(cmd,"%s\n",argv[0]);
      Wsetgraphicsdisplay("ds");
      set_dpf_flag(1, cmd);
    }
  }
  releaseAllWithId("dpf");
  endgraphics();
  disp_status("        ");
  set_graphics_font("Default");
  RETURN;
}
Ejemplo n.º 9
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;
}
Ejemplo n.º 10
0
/*************************************

   fiddle()

**************************************/
int fiddle(int argc, char *argv[], int retc, char *retv[])
{
	int    pwr,cblock,res,dc_correct=TRUE;
	register int i,ntval;
	dpointers  inblock;
	float   a,b,c,d,denom;
	int    ocount;

	/* initialization bits */
	if (i_fiddle(argc,argv))
		ABORT;

	dc_correct=dccorr;
	pwr = fnpower(fn0);
	max=0.0;
	cfcount=0;
	count=0;
	firstrefint=0.0;
	phasetweek=0.0;
	degtorad=3.141592654/180.0;
	ocount=0;
	ntval = 1;
	if (!P_getreal(PROCESSED, "nt", &tmp, 1))
	{
		ntval = (int) (tmp + 0.5);
		if (ntval < 1)
			ntval = 1;
	}
	disp_status("IN3 ");

	/* check range of transforms */
	if (startno>=fidhead.nblocks) startno=fidhead.nblocks-1;
	if (startno<0) {
		startno=0; 
		finishno=fidhead.nblocks; 
		stepno=1;
	}
	if (finishno>fidhead.nblocks) finishno=fidhead.nblocks;
	if (stepno==0) stepno=1;

	/* setup destination fidfile and/or correction function file if requested 
*/
	if (writefg) setupwritefile();
	if (writecfflg) setupwritecf();

	/* start of main loop */
	incno=0;
	t1=0;
	rp0=rp;
	for (cblock = startno; cblock < finishno; cblock+=stepno)
	{
		if ( (res = D_getbuf(D_DATAFILE, fidhead.nblocks, cblock, &inblock)) )
		{
			D_error(res);
			freall(TRUE);
		}
		if ( (inblock.head->status & (S_DATA|S_SPEC|S_FLOAT|S_COMPLEX)) ==
		    (S_DATA|S_SPEC|S_FLOAT|S_COMPLEX) )
		{
			disp_index(cblock+1);
			incno+=1;
			if (verbose) Wscrprintf("Increment no. %d \n",incno);

			if (!aphflg) incrementrp();

			inp = (float *)inblock.data;
			/* DEBUGGING ONLY
			  if (verbose) Wscrprintf("Real part of 1st point of original fid 
%f \n",
			      inp[0]);
			  if (verbose) Wscrprintf("Imag part of 1st point of original fid 
%f \n",
			      inp[1]);
			*/
			/* dc (not normally used!) 
			if (dc_correct)
			  {
			  disp_status("DC ");
			  cmplx_dc(inp, &lvl_re, &lvl_im, &tlt_re, &tlt_im, np0/2, 
CMPLX_DC);
			  vvrramp(inp, 2, inp, 2, lvl_re, tlt_re, np0/2);
			  vvrramp(inp+1, 2, inp+1, 2, lvl_im, tlt_im, np0/2);
			  } */

			/* phase correct spectrum */
			finalph=0.0;
			rotate2(inp,np0/2,lp,rp);
			if (aphflg)
			{
				faph(inp,leftpos,rightpos,&finalph);
				rotate2(inp,np0/2,0.0,finalph);
			}

			/* if baseline then zero imag. */
			if (baseline||hilbert) fiddle_zeroimag();

			/* move first to data1, ready for ift, n.b. fn0==np0 */
			transpmove(inp,data1);

			/* do zeroing for reference region */
			if (solvent) solventextract();
			else
			{
				for (i=0;i<leftpos;i++)
				{
					inp[i]=0.0;
				}
				for (i=rightpos+2;i<np0;i++)
				{
					inp[i]=0.0;
				}

				if (ldcflag) baseline_correct(inp,leftpos,rightpos);
				if (extrap) extrapolate();
			} /* !solvent */
			transpmove(inp,data2);

			/* now do the ift's */
			if (!noift)
			{
				disp_status("IFT1 ");
			
	fft(data1,fn0/2,pwr,0,COMPLEX,COMPLEX,1.0,FTNORM/ntval,np0/2);
				disp_status("IFT2 ");
			
	fft(data2,fn0/2,pwr,0,COMPLEX,COMPLEX,1.0,FTNORM/ntval,np0/2);
			}

			if (makereffg) makeideal();

			/* need to weight data3 to create ideal fid */
			if (makereffg&&!noift)
			{
				disp_status("WT ");
				weightfid(wtfunc,data3,np0w/2,FALSE,COMPLEX);
			}

			if (stopflag<1||stopflag>3)
			{
				/* DEBUGGING ONLY
				  if (verbose) Wscrprintf("Real part of 1st point of 
original fid %f \n",
				      data1[0]);
				  if (verbose) Wscrprintf("Imag part of 1st point of 
original fid %f \n",
				      data1[1]);
				*/
				/* divide (3) by (2) */
				disp_status("DIV ");
				for (i=0;i<npi;i+=2)
				{
					a=data3[i];
					b=data3[i+1];
					c=data2[i];
					d=data2[i+1];
					denom=c*c+d*d;
					data2[i]=(a*c+b*d)/denom;
					data2[i+1]=(b*c-a*d)/denom;
				}

				if (writecfflg) writeoutcf();
				if (readcfflg) readincf();

				/* and multiply by (1) */

				/* DEBUGGING ONLY	
				  if (verbose) Wscrprintf("Real part of 1st point of 
correction function %f \n",
				      data2[0]);
				  if (verbose) Wscrprintf("Imag part of 1st point of 
correction function %f \n",
				      data2[1]);
				*/
				disp_status("MUL ");
				if (!corfunc)
				{
					for (i=0;i<npi;i+=2)
					{
						a=data2[i];
						b=data2[i+1];
						c=data1[i];
						d=data1[i+1];
						inp[i]=(a*c-b*d);
						inp[i+1]=(b*c+a*d);
					}
				}
				/* DEBUGGING ONLY
				  if (verbose) Wscrprintf("Real part of 1st point of 
corrected fid %f \n",
				      inp[0]);
				  if (verbose) Wscrprintf("Imag part of 1st point of 
corrected fid %f \n",
				      inp[1]);
				*/
				/* Halve first point of corrected fid */
				/* hang about, does this do anything??? */
				if (halffg) /* default true */
				{
					data1[0]=0.5*(data1[0]);
					data1[1]=0.5*(data1[1]);
				}

				if (npi<np0)
					for (i=npi;i<np0;i++)
						inp[i]=0.0;
			} /* stopflag not 1 - 3 */

			if (firstfg&&!nosub)
				movmem((char *)inp,(char *)data4,sizeof(float)*np0,1,4);
			if (secondfg&&!nosub)
			{
				disp_status("SUB ");
				submem(inp,data4,np0);
				if (invert) invertmem(inp,np0);
			}

			/* inp contains result fid - write out and/or FT! */
			if (writefg&&!firstfg) writeoutresult();
			if (!noftflag)
			{
				disp_status("FT ");
				fft(inp,fn0/2,pwr,0,COMPLEX,COMPLEX,-1.0,FTNORM/ct,np0/2);
			}

			/* move intermediate result for display if requested */
			if (stopflag||corfunc)
			{
				disp_status("MOVE ");
				switch (stopflag)
				{
				case 1: 
					p=data1; 
					break;
				case 2: 
					p=data2; 
					break;
				case 4: 
					p=data4; 
					break;
				default:
					p=data3; 
					break;
				}
				if (corfunc) p=data2;
				if (difffg&&(stopflag<4))
				{
					if (firstfg) movmem((char *)p,(char
					*)data4,sizeof(float)*np0,1,4);
					if (!firstfg)
					{
						submem(p,data4,np0);
						if (invert) invertmem(p,np0);
					}
				}
				if (noift)
					transpmove(p,inp);
					else
					movmem((char *)p,(char *)inp,sizeof(float)*np0,1,4);
			}

			/* re-phase back to rp,lp */
			disp_status("PHASE ");
			if (!(writefg&&!firstfg)) /* if not both writing and subsequent 
fid */
			{
				rotate2(inp,np0/2,-lp,-rp);
			}
			else rotate2(inp,np0/2,-lp,0.0);

			if (difffg)
			{
				secondfg=!secondfg;
				firstfg=!firstfg;
			}
			if (udifffg)
			{
				secondfg=TRUE;
				firstfg=FALSE;
			}
			if (secondfg||oflag)
				makereffg=FALSE;
			else makereffg=TRUE;

			/* oflag increment */
			if (oflag)
			{
				rp+=odat[ocount];
				ocount++;
				if (ocount>3) ocount=0;
			}
			/* release result */
			if ( (res=D_markupdated(D_DATAFILE,cblock)) )
			{
				D_error(res);
				disp_status("  ");
				freall(TRUE);
			}
			if ( (res = D_release(D_DATAFILE, cblock)) )
			{
				D_error(res);
				disp_status("  ");
				freall(TRUE);
			}
			if (interuption) /* ? not fully working ? */
			{
				Werrprintf("Fiddle processing halted");
				freall(TRUE);
				ABORT;
			}

			if (flag2d)
			{
				if (altfg)
				{
					if ((incno % 2)==0) t1=t1+1/sw1;
				}
				else
				{
					t1=t1+1/sw1;
				}
			}
		}  /* end of if ( (inblock.head->status &c at start of main loop */
	}	/* end of main loop */
	start_from_ft=TRUE;
	releasevarlist();
	appendvarlist("cr");
	Wsetgraphicsdisplay("ds");
	/* free memory */
	freall(FALSE);

	disp_status("  ");
	disp_index(0);
	RETURN;
}
Ejemplo n.º 11
0
void fn_help(char **args)
{
    static char spaces[] = "                ";

    struct binding *b;
    FILE *f;
    int what, c, i, j, l;
    char *s, *t;

    what = read_char("Help on <f>unction, <k>ey, or <o>ption "
		     "(shift for list)? ");

    switch (what) {
    case 'f':
	s = read_string("Function: ", 1);
	if (s == NULL || s[0] == '\0') {
	    free(s);
	    disp_status(DISP_STATUS, "");
	    return;
	}
	    
	if ((i=find_function(s)) == -1)
	    disp_status(DISP_STATUS, "no such function: %s", s);
	else
	    disp_status(DISP_STATUS, "%s: %s",
			functions[i].name, functions[i].help);

	free(s);
	break;

    case 'F':
	if ((f=disp_open(opt_pager, 1)) == NULL)
	    return;

	for (i=0; functions[i].name; i++) {
	    fprintf(f, "%-16.16s %s\n", functions[i].name, functions[i].help);
	}

	disp_close(f, 1);
	disp_status(DISP_STATUS, "");
	break;

    case 'k':
	c = read_char("Key: ");

	b = get_function(c, bs_none);
	if ((i=b->fn) == -1)
	    disp_status(DISP_STATUS, "[%s%s] key is unbound",
			(binding_state != bs_none ?
			 binding_statename[binding_state] : ""),
			print_key(c, 0));
	else {
	    char *buf;
	    int cols;

	    cols = tty_cols;
	    
	    if ((buf=(char *)malloc(cols+5)) == NULL)
		break;

	    sprintf(buf, "[%s%s] %s",
			(b->state != bs_none ?
			 binding_statename[b->state] : ""),
			print_key(c, 0),
			functions[i].name);
	    if (b->args) {
		int i, l;

		l = strlen(buf);
		for (i=0; b->args[i]; i++)
		    if (strlen(b->args[i])+l+2 > cols) {
			strcpy(buf+l, " ...");
			break;
		    }
		    else {
			sprintf(buf+l, " %s", b->args[i]);
			l += strlen(b->args[i])+1;
		    }
	    }

	    disp_status(DISP_STATUS, "%s", buf);
	    free(buf);
	}
	break;

    case 'K':
	if ((f=disp_open(opt_pager, 1)) == NULL)
	    return;

	for (i=0; i<max_fnkey+256; i++) {
	    for (b=&binding[i]; b; b=b->next) {
		if (b->fn != -1) {
		    s = (b->state != bs_none ?
			 binding_statename[b->state] : "");
		    t = print_key(i, 0);
		    l = strlen(s)+strlen(t);
		    fprintf(f, "%s%s%s%s",
			    s, t, spaces+((l>16) ? 16 : l),
			    functions[b->fn].name);
		    if (b->args) {
			for (j=0; b->args[j]; j++)
			    fprintf(f, " %s", b->args[j]);
		    }
		    fputc('\n', f);
		}
	    }
	}

	disp_close(f, 1);
	disp_status(DISP_STATUS, "");
	break;

    case 'o':
	s = read_string("Option: ", 1);
	if (s == NULL || s[0] == '\0') {
	    free(s);
	    disp_status(DISP_STATUS, "");
	    return;
	}
	    
	for (i=0; option[i].name; i++)
	    if (strcasecmp(option[i].name, s) == 0
		|| strcasecmp(option[i].shrt, s) == 0)
		break;
	
	if (option[i].name == NULL)
	    disp_status(DISP_STATUS, "no such option: %s", s);
	else {
	    char *buf;
	    
	    switch(option[i].type) {
	    case OPT_INT:
		if ((buf=(char *)malloc(30)) == NULL)
		    break;
		sprintf(buf, "(int) %d", *(option[i].var.i));
		break;
		
	    case OPT_CHR:
		if ((buf=(char *)malloc(30)) == NULL)
		    break;
		sprintf(buf, "(char) `%c'", *(option[i].var.i));
		break;

	    case OPT_STR:
		if ((buf=(char *)malloc(strlen(*(option[i].var.s))+10))
		    == NULL)
		    break;
		sprintf(buf, "(str) ``%s''", *(option[i].var.s));
		break;

	    case OPT_BOOL:
		if ((buf=(char *)malloc(30)) == NULL)
		    break;
		sprintf(buf, "(bool) %s",
			(*(option[i].var.i) ? "on" : "off"));
		break;

	    case OPT_ENUM:
		if ((buf=(char *)malloc(strlen(option[i].values[*(option[i].var.i)])+10))
		    == NULL)
		    break;
		sprintf(buf, "(enum) %s",
			option[i].values[*(option[i].var.i)]);
		break;
	    default:
		buf = NULL;
	    }

	    if (buf == NULL)
		break;

	    disp_status(DISP_STATUS, "%s (%s) [%s]: %s", 
			option[i].name, option[i].shrt,
			buf, option[i].help);
	}
	free(s);
	break;
	
    case 'O':
	if ((f=disp_open(opt_pager, 1)) == NULL)
	    return;
	
	for (i=0; option[i].name; i++) {
	    if (i > 0)
		fputc('\n', f);
	    
	    fprintf(f, "%s %-15.15s",
		     option[i].shrt, option[i].name);

	    switch(option[i].type) {
	    case OPT_INT:
		fprintf(f, "(int) %d\n", *(option[i].var.i));
		break;
		
	    case OPT_CHR:
		fprintf(f, "(char) `%c'\n", *(option[i].var.i));
		break;

	    case OPT_STR:
		fprintf(f, "(str) ``%s''\n", *(option[i].var.s));
		break;
		
	    case OPT_BOOL:
		fprintf(f, "(bool) %s\n",
			(*(option[i].var.i) ? "on" : "off"));
		break;
		
	    case OPT_ENUM:
		fprintf(f, "(enum) %s\n",
			option[i].values[*(option[i].var.i)]);
		break;
	    }
	    fprintf(f, "        %s\n", option[i].help);
	}

	disp_close(f, 1);
	disp_status(DISP_STATUS, "");
	
    default:
	disp_status(DISP_STATUS, "");
    }
}
Ejemplo n.º 12
0
void bootup(char *modeptr, int enumber)
/*****************************/
{
    char	 autodir[MAXPATH];
    char         parampath[MAXPATH];
    char         plotname[STR64];
    char         mstr[MAXPATH];
    char         rtautocmd[2 * MAXPATH + 20];
    char	 estring[5];
    extern char  PlotterName[];
    extern char  PrinterName[];
    int do_rt = 0;
    int lval;
    endian_tester et;

    (void) modeptr;
    et.my_int = 0x0a0b0c0d;
    BigEndian = (et.my_bytes[0] == 0x0a) ? 1:0;
    psg_pid = 0;		/* set pids to zero */

    if ( !Bnmr )
       disp_status("BOOTUP  ");

/*  May 18, 1987.  Addition to read the system global parameters.
    If a problem occurs, the program exits immediately, for this
    should not happen.  The CONPAR file is on the distribution tape.	*/

    strcpy(parampath,systemdir);
#ifdef UNIX
    strcat(parampath,"/conpar");
#else 
    strcat(parampath,"conpar");
#endif 
    if (P_read(SYSTEMGLOBAL,parampath)) 
    {
	fprintf(stderr,"problem loading system global parameters from %s\n",
		parampath);
	exit(1);
    }
    openVnmrInfo(systemdir);

/*  If automation mode, use value of autodir to establish path to experiment  */

    if (mode_of_vnmr == AUTOMATION)
    {
      getAutoDir(autodir, MAXPATH);
      if (strlen(autodir) == 0)
      {
	  fprintf( stderr, "unable to access 'autodir' parameter\n" );
	  exit(1);
      }
    }

    /* setup signal handlers to catch these signals */
    if (Wissun())		/* Only do this if using SUN console */
    {
        set_acqi_signal();
    }
    else if (mode_of_vnmr == FOREGROUND) /* Only creat a Vnmr socket if foreground */
    {

	setupVnmrAsync(AcqSocketIsRead);
    }

#ifndef VNMRJ
    if (Wishds())
	last_line = 19;
    else
#endif
	last_line = 20;

    /* load parameters in global file */
    /* moved 9 lines to read GLOBAL before EXP, this way we can use
       curexpdir to restart Vnmr in the last exp used. May 17, 1997 */

    strcpy(parampath,userdir);
    strcat(parampath,"/global");
    if (P_read(GLOBAL,parampath)) 
	Werrprintf("problem loading global parameters");
#ifdef VNMRJ
   // set curexpdir based on jcurwin of viewport 1
   jcurwin_init(curexpdir);
#endif

     // load unshared globalX for viewport X if foreground
     if (!Bnmr)
     {
        sprintf(parampath,"%s/global%d",userdir,VnmrJViewId);
        /* Don't complain if unshared globals are missing */
        P_read(GLOBAL,parampath);
     }

    // set OperatorName 
    if ( (P_getstring(GLOBAL,"operator",OperatorName,1,MAXSTR) != 0) ||
         ( ! strcmp(OperatorName, "") ) )
	strcpy(OperatorName, UserName);

/*  If lock fails, and program is running in foreground mode, set
    current experiment to be EXP0, which doesn't exist.  The user
    can then join another experiment or use other techniques to
    unlock the desired experiment.

    If running in any other mode, exit immediately with an error
    message.							*/

/* May 19, 1997. Use curexpdir to set the enumber, check if directory
   still exists, if not make it exp1. Only done if FOREGROUND Vnmr.
   Acqproc, autoproc, and other procs determine enumber themselves.
   Note that curexpdir is overwritten below, when we read exp parameters */

#ifdef VNMRJ
   jviewport_init();
   P_setstring(GLOBAL,"curexp",curexpdir,1);
#else 
   P_getstring(GLOBAL,"curexp",curexpdir,1,MAXPATH);
#endif 
   if (mode_of_vnmr == FOREGROUND)
   {
      enumber = expdir_to_expnum(curexpdir);
      if (enumber == 0)
         lval = -1;
      else if ( ! access(curexpdir,F_OK))
        lval = lockExperiment( enumber, FOREGROUND);
      else
        lval = -1;
   }
#ifdef SUN
   else if (mode_of_vnmr == ACQUISITION)
      lval = (enumber == 0) ? -2 :checkAcqLock( enumber );
   else if ( Bnmr && (enumber == 0) )
      lval = -2;
   else
#endif
      lval = lockExperiment( enumber, mode_of_vnmr );

    if (lval != 0)
    {
        if ((mode_of_vnmr != FOREGROUND) && (lval != -2) )
        {
	    fprintf( stderr, "unable to lock experiment %d\n", enumber);
	    exit(1);
	}
        if (enumber == 0)
        {
#ifdef VNMRJ
           if (VnmrJViewId != 1)
           {
	      P_getstring(GLOBAL, "jviewportlabel", mstr, VnmrJViewId, MAXPATH);
	      Werrprintf( "No experiment selected for the %s viewport.",mstr);
           }
           jcurwin_setexp( "0" , -1 );
#else 
           if (lval != -2)
	      Werrprintf( "No experiment selected.");
#endif 
        }
        else
        {
#ifdef VNMRJ
           if (VnmrJViewId == 1)
	      Werrprintf( "Unable to lock experiment %d", enumber );
           else
           {
	      P_getstring(GLOBAL, "jviewportlabel", mstr, VnmrJViewId, MAXPATH);
	      Werrprintf( "Unable to lock experiment %d for the %s viewport.",enumber, mstr);
           }
           jcurwin_setexp( "0", -1 );
#else 
	   Werrprintf( "Unable to lock experiment %d", enumber );
#endif 
        }
        strcpy( curexpdir, userdir );
#ifdef UNIX
        strcat( curexpdir, "/exp0" );
#else 
	vms_fname_cat( curexpdir, "[.exp0]" );
#endif 
#ifdef VNMRJ
        if (mode_of_vnmr != AUTOMATION)
        { 
           sprintf(mstr,"exp0 %s",curexpdir);
           writelineToVnmrJ("expn",mstr);
        }
#endif
    }

/*  Only read in parameters if the target experiment was locked.  */

    else
    {
	if (mode_of_vnmr == AUTOMATION)
	  strcpy( curexpdir, &autodir[ 0 ] );
	else
          strcpy( curexpdir, userdir );

	sprintf(estring, "%d", enumber);
#ifdef UNIX
        strcat(curexpdir, "/exp");
	strcat(curexpdir, estring);
#else 
        vms_fname_cat(curexpdir, "[.exp");
        vms_fname_cat(curexpdir, estring);
        vms_fname_cat(curexpdir, "]");
#endif 

        if (mode_of_vnmr == AUTOMATION)
        {
	    lval = strlen( &datadir[ 0 ] );
	    if (lval > MAXPATH-8)
	    {
	        fprintf(stderr, "data pathname too long in automation mode");
	        exit(1);
	    }
            else if (lval > 1)
            {
                int ex;

                sprintf(rtautocmd, "cp %s.fid/sampleinfo %s/sampleinfo",
                        datadir,curexpdir);
                system(rtautocmd);
                ex = 0;
                /* Wait up to 0.5 secs for fid to appear */
                while ( access(rtautocmd,R_OK) && (ex < 50) )
                {
                   struct timespec timer;

                   timer.tv_sec=0;
                   timer.tv_nsec = 10000000;   /* 10 msec */
#ifdef __INTERIX
				   usleep(timer.tv_nsec/1000);
#else
                   nanosleep( &timer, NULL);
#endif
                   ex++;
                }
	        sprintf( &rtautocmd[ 0 ], "%s('%s','nodg')\n",
                         (acqStartUseRtp) ? "RTP" : "RT", &datadir[ 0 ] );
                do_rt = 1; /* do the rt command after reading global tree */
            }
            else  /* read curpar parameters only from the automation exp */
            {
                D_getparfilepath(CURRENT, parampath, curexpdir);
                if (P_read(CURRENT,parampath))
                {  /* if no parameters in current experiment */
                   strcpy(parampath,systemdir);
#ifdef UNIX
                   strcat(parampath,"/stdpar/H1.par/procpar");
#else 
                   vms_fname_cat(parampath,"[.stdpar.H1_par]procpar");
#endif 
                   if (P_read(CURRENT,parampath))
	              Werrprintf("problem loading current parameters");
                }
                P_copy(CURRENT,PROCESSED);
            }
        }
	else       /* if (mode_of_vnmr != AUTOMATION) */
        {
           /* load parameters in curexp/curpar file */
           D_getparfilepath(CURRENT, parampath, curexpdir);
           if (P_read(CURRENT,parampath))
	       Werrprintf("problem loading current parameters from \"%s\"",
                           parampath);
           /* load parameters in curexp/procpar file */
           D_getparfilepath(PROCESSED, parampath, curexpdir);
           if (P_read(PROCESSED,parampath))
	       Werrprintf("problem loading processed parameters from \"%s\"",
                           parampath);
#ifdef VNMRJ
	   sprintf(mstr,"exp%s %s",estring,curexpdir);
	   writelineToVnmrJ("expn",mstr);
#endif 
        }
    }


    /* May 17, 1997. We read GLOBAL parameters earlier */
    setGlobalPars();
#ifdef VNMRJ
    if (!Bnmr)
       saveViewPortAddr();
#endif 
    bufferscale = getbufscale();	/* obtain the value for bufferscale */
    finddatainfo();
    DEBUGPRINT1("bufferscale set to %d\n", bufferscale);
    D_init();				/* initialize the data file handler;
					   bufferscale must be known before
					   D_init() is called.		    */

    /* setAppdirs needs to happen after operator is set in setGlobalPars but before
     * any macros are called
     */
#ifdef VNMRJ
    if (VnmrJViewId == 1)
#endif 
    {
       setAppdirs();
    }

    specIndex = 1;
    if (mode_of_vnmr == AUTOMATION)
    {
      if (do_rt)
      {
        turnOffFixpar();
        execString( &rtautocmd[ 0 ] );
      }
      else
      {
        Werrprintf( "Spectrometer in automation mode" );
      }
    }
    else if (enumber || (mode_of_vnmr != BACKGROUND) )
    {
       disp_expno();
    }
    init_proc2d();
    strcpy(dconi_runstring,"dcon\n");

    /* Assign some function pointers for the */
    /* graphics module                       */
    set_bootup_gfcn_ptrs();
    if (Bnmr)
       init_colors();  /* set default colors for graphics and plotters */

    set_automount_dir();

    /*  Set up plotting parameters */
    /*  If there is trouble setting plottin parameters (ie plotting device
        doesn't exist or devicetable/devicenames is bad, set to "none" device */
    if (P_getstring(GLOBAL,"plotter" ,plotname, 1,32))
    {  P_setstring(GLOBAL,"plotter","none",0);
       strcpy(PlotterName,"none");
    }
    if (!setPlotterName(plotname))
    {  P_setstring(GLOBAL,"plotter","none",0);
       strcpy(PlotterName,"none");
    }

    /*  Set up printing parameters */
    /*  If there is trouble setting printing parameters (ie printing device
        doesn't exist or devicetable/devicenames is bad, set to "none" device */
    if (P_getstring(GLOBAL,"printer" ,plotname, 1,32))
    {  P_setstring(GLOBAL,"printer","none",0);
       strcpy(PrinterName,"none");
    }
    if (!setPrinterName(plotname))
    {  P_setstring(GLOBAL,"Printer","none",0);
       strcpy(PrinterName,"none");
    }

#ifdef SUN
/*
 *  Set up signal handler to exit VNMR
 *  The function nmr_quit will be called when Vnmr exits
 */
    set_nmr_quit_signal();
#endif 
    check_datastation();

#ifdef VNMRJ
    writelineToVnmrJ("bootup","");
    /* create a frame for graphics display */
    frame_update("init", "");
#endif 

/*  The extra space in the first Wscrprintf is essential for
    the scrollable text subwindow to work correctly.			*/

/* ---  print revision ID and Date, Compiled within revdate.c --- */
    P_setstring( SYSTEMGLOBAL, "rev", &RevID[ 0 ], 1);
    P_setstring( SYSTEMGLOBAL, "revdate", &RevDate[ 0 ], 1);
    if (!Bnmr) /* only execute the bootup macro if we are in forground */
    {
	Wscrprintf("\n              %s\n",RevID);
        Wscrprintf("              %s\n",RevDate);

        Wscrprintf("              %s\n\n",Copyright);
        if (strlen(PlotterName) > 0)
           Wscrprintf( "              Plotting Device is set to %s\n",PlotterName);
        else
           Wscrprintf( "              Plotting Device is set to ''\n");
        if (strlen(PrinterName) > 0)
           Wscrprintf( "              Printing Device is set to %s\n\n",PrinterName);
        else
           Wscrprintf( "              Printing Device is set to ''\n\n");

        disp_current_seq();
        if (Wissun())
           sendTripleEscToMaster( 'C',"bootup(0)");
        else
	   execString("bootup(0)\n");
        disp_status("        ");
    }
    else if (enumber)
    {
	execString("bootup(1)\n");
    }

    p11_init();
}
Ejemplo n.º 13
0
int flush( int argc, char *argv[], int retc, char *retv[] )
{ char parampath[MAXPATH];
  int  curexpnumber;
  int  diskIsFull;
  int  ival;
  extern int start_from_ft;
  static int flushed = -1;

  (void) argc;
  (void) argv;
  (void) retc;
  (void) retv;

  // flush global if VnmrJViewId == 1 or argc != 99 (almost always the case).
  // Note, flush(99,NULL,0,NULL) is called in nmr_exit to avoid repeatly
  // flush global by multiple viewports.
  int flushGlobal=(VnmrJViewId == 1 || argc != 99);

  if ((mode_of_vnmr == AUTOMATION) && (datadir[0] != '\0') && (flushed == -1))
  {
     /* In automation, datadir[0] != '\0' means conditional processing is occurring.
      * The first time flush is called is during the bootup process when data is
      * being rt'ed from the .fid file into the automation experiment.
      * Therefore, no need to flush data.
      * Note that rt() always calls flush if in automation mode.
      */
     flushed = 0;
     RETURN;
  }
  if (skipFlush && (mode_of_vnmr == AUTOMATION))
  {
    skipFlush = 0;
    RETURN;
  }
  skipFlush = 0;
  curexpnumber = expdir_to_expnum(curexpdir);
  if (curexpnumber < 1) {
     if (!Bnmr)
        Werrprintf( "no current experiment, aborting save" );
     RETURN;
  }

  Wturnoff_buttons();
  if (showFlushDisp)
     disp_status("SVPAR   ");

  /* save parameters in curexp/curpar file */

  D_getparfilepath(CURRENT, parampath, curexpdir);
  if (P_save(CURRENT,parampath))
  {
     ival = isDiskFullFile( curexpdir, parampath, &diskIsFull );
     if (ival == 0 && diskIsFull)
     {
        Werrprintf("problem saving current parameters: disk is full");
     }
     else
       Werrprintf("problem saving current parameters");
     ABORT;
  }

  /* save parameters in curexp/procpar file */

  if ((mode_of_vnmr == AUTOMATION) && (datadir[0] != '\0') && (flushed == 0))
  {
    setfilepaths(0);  /* reset file paths to main data files for automation */
    P_copygroup(CURRENT,PROCESSED,G_DISPLAY);
    sprintf(parampath,"%s.fid",datadir);
    if (access(parampath,W_OK))  /* If .fid file is missing, assume it was deleted on purpose. */
    {
       strcpy(parampath,curexpdir);
    }
  }
  else
    strcpy(parampath,curexpdir);

  D_getparfilepath(PROCESSED, parampath, parampath);
  if (P_save(PROCESSED,parampath))
  {
     ival = isDiskFullFile( curexpdir, parampath, &diskIsFull );
     if (ival == 0 && diskIsFull)
     {
        Werrprintf("problem saving processed parameters: disk is full");
     }
     else
     {
       Werrprintf("problem saving processed parameters");
     }
     ABORT;
  }

  if ((mode_of_vnmr == AUTOMATION) && (datadir[0] != '\0') && (flushed == 0))
    flushed = 1;
  /* save parameters in global file except when doing automation or running in background */
  if ( (mode_of_vnmr != AUTOMATION) && ! Bnmr)
  {
#ifdef VNMRJ
    if (flushGlobal) // write shared and unshared
#endif 
    {
     strcpy(parampath,userdir);
     strcat(parampath,"/global");
     if (P_save(GLOBAL,parampath)) 
     {
	ival = isDiskFullFile( userdir, parampath, &diskIsFull );
	if (ival == 0 && diskIsFull)
	   Werrprintf("problem saving global parameters: disk is full");
	else
	   Werrprintf("problem saving global parameters");
        ABORT;
     }
    }

     // always write un-shared globals 
     sprintf(parampath,"%s/global%d",userdir,VnmrJViewId);
     if (P_saveUnsharedGlobal(parampath)) 
     {
	ival = isDiskFullFile( userdir, parampath, &diskIsFull );
	if (ival == 0 && diskIsFull)
	   Werrprintf("problem saving unshared global parameters: disk is full");
	else
	   Werrprintf("problem saving unshared global parameters");
        ABORT;
     }
  }

  p11_flush();

  if (showFlushDisp)
     disp_status("SAVEDATA");
  D_close(D_DATAFILE);
  D_close(D_PHASFILE);
  D_close(D_USERFILE);
  start_from_ft = 1;
  closexposebuf();
  if (showFlushDisp)
     disp_status("        ");
  RETURN;
}
Ejemplo n.º 14
0
void
fn_bind(char **args)
{
    enum state state, s2;
    int key, fn, i;
    char *line = NULL;
    char *staten, *kname, *cmd, **list, *p;
    struct binding *b;

    state = bs_none;

    if (args) {
	if ((s2=parse_state(args[0])) != bs_nostate) {
	    staten = args[0];
	    state = s2;
	    args++;
	}
	kname = args[0];
	cmd = args[1];
	args += 2;
    }
    else {
	if (rc_inrc) {
	    rc_error("bind: no arguments given");
	    return;
	}
	line = p = read_string("bind ", 1);

	if ((kname=rc_token(&p)) == NULL) {
	    disp_status(DISP_STATUS, "no key");
	    free(line);
	    return;
	}
	if ((s2=parse_state(kname)) != bs_nostate) {
	    staten = kname;
	    state = s2;

	    if ((kname=rc_token(&p)) == NULL) {
		disp_status(DISP_STATUS, "no key");
		free(line);
		return;
	    }
	}
	cmd = rc_token(&p);
    }

    if (state == bs_unknown) {
	if (rc_inrc)
	    rc_error("unknown state: %s", staten);
	else
	    disp_status(DISP_STATUS, "unknown state: %s", staten);
	if (line)
	    free(line);
	return;
    }

    if ((key=parse_key(kname)) < 0) {
	if (rc_inrc)
	    rc_error("unknown key: %s", kname);
	else
	    disp_status(DISP_STATUS, "unknown key: %s", kname);
	if (line)
	    free(line);
	return;
    }
	
    if (cmd) {
	if ((fn=find_function(cmd)) < 0) {
	    if (rc_inrc)
		rc_error("unknown function: %s", cmd);
	    else
		disp_status(DISP_STATUS, "unknown function: %s", cmd);
	    if (line)
		free(line);
	    return;
	}
    }

    if (!rc_inrc)
	disp_status(DISP_STATUS, "");
	
    b = get_function(key, state);

    if (b->state == state) {
	b->fn = -1;
	if (b->args) {
	    if (b->args < binding_argpool
		|| (b->args >= binding_argpool+binding_nargpool)) {
		for (i=0; b->args[i]; i++)
		    free(b->args[i]);
		free(b->args);
		b->args = NULL;
	    }
	}
    }
    else {
	if ((b=(struct binding *)malloc(sizeof(struct binding))) == NULL)
	    return;
	b->fn = -1;
	b->args = NULL;
	b->state = state;

	b->next = binding[key].next;
	binding[key].next = b;
    }

    if (cmd) {
	if (line)
	    list = rc_list(p);
	else {
	    for (i=0; args[i]; i++)
		;
	    if (i > 0) {
		list = (char **)malloc(sizeof(char *)*(i+1));
		memcpy(list, args, sizeof(char *)*(i+1));
	    }
	    else
		list = NULL;
	}

	b->fn = fn;
	b->args = list;
    }

    return;
}
Ejemplo n.º 15
0
int dpir(int argc, char *argv[], int retc, char *retv[])
/*************/
{ int groups;
  int resets;
  int i, min, ysize;
  char name[64];
  char tmpstr[MAXSTR];

  (void) retc;
  (void) retv;

  if (argc > 1 && strcmp(argv[1],"off") == 0) {
	set_dpir_flag(0,"");
        redo_dpf_dpir();
	RETURN;
  } else if (argc > 1 && strcmp(argv[1],"turnoff") == 0) {
        set_dpir_flag(0,"");
        RETURN;
  }

  vertflag=0;
  if ( ! P_getstring(GLOBAL, "integralOrient", tmpstr, 1, MAXSTR) )
  {
     vertflag = (strcmp(tmpstr,"vert") == 0);
  }
  if (argc > 1 && strcmp(argv[1],"vert") == 0) {
      vertflag=1;
  }

  if(argc == 1 || strcmp(argv[1],"noli") != 0) {
     execString("nli\n");
  }
  if (check_int(&resets))
  {
    Werrprintf("intmod must not be set to 'full'");
    ABORT;
  }
  if (resets <= 1)
  {
    Werrprintf("no integral resets are defined");
    ABORT;
  }
  plot = (argv[0][0] == 'p');
  if (select_init(
	0,
	plot+1,
	NO_FREQ_DIM,
	NO_HEADERS,
	DO_CHECK2D,
	DO_SPECPARS,
	NO_BLOCKPARS,
	NO_PHASEFILE
     )) {
      ABORT;
  }

  if(strlen(argv[0]) > 4 && argv[0][4] == 'N') {
     normInt = 1;
  } else if(strlen(argv[0]) > 3 && argv[0][3] == 'N') {
     normInt = 1;
  }

  if ((groups = getregions(resets)) == 0) {
	ABORT;
  }

  min=mnumxpnts; 
  for (i = 1; i <= groups; i++) {
    if(gb[i].lowlimit <= 0 || gb[i].highlimit <= 0
	|| gb[i].lowlimit >= (mnumxpnts-xcharpixels)
	|| gb[i].highlimit >= (mnumxpnts-xcharpixels)) continue;
    if((gb[i].highlimit-gb[i].lowlimit) < min) 
	min = gb[i].highlimit-gb[i].lowlimit;
  }
  if(min != 0 && min < 3*xcharpixels) ysize = 3; else ysize=2;
    
  if (!plot)
  {
    setwindows();
    dispcalib = (float) (mnumypnts-ymin) / (float) wc2max;
    CharSize = ycharpixels + ycharpixels / 5;

    getOptName(INTEG_MARK,name);
    set_line_thickness(name);
    getOptName(INTEG_NUM,name);
    set_graphics_font(name);
  }
  else
  { 
    double size = G_getCharSize("IntegralNum");
    charsize(size);
    //charsize((double)0.7);
    dispcalib = ppmm / ymultiplier;
    CharSize = ycharpixels;
  }

  if (showPlotBox()) dpir_off=0.0;
  else dpir_off=9.0;

  if(dispcalib>0) {
    int size= 12;
    G_getSize("IntegralNum", &size);
    i = (int)(vp*dispcalib); 
    if (vertflag && i < 4*size)
    {
      char cmd[64];
      i = (int)(4*size/dispcalib)+1;
      if(vertflag) sprintf(cmd,"vp=%d ds %s('vert')\n",i,argv[0]);
      else sprintf(cmd,"vp=%d ds %s\n",i,argv[0]);
      if(!plot) execString(cmd); 
      //Werrprintf("pir requires minimum vp of %d",i);
      RETURN;
    } else if (i < 3*size)
    {
      char cmd[64];
      i = (int)(3*size/dispcalib)+1;
      if(vertflag) sprintf(cmd,"vp=%d ds %s('vert')\n",i,argv[0]);
      else sprintf(cmd,"vp=%d ds %s\n",i,argv[0]);
      if(!plot) execString(cmd); 
      //Werrprintf("pir requires minimum vp of %d",i);
      RETURN;
    }
  } else {
    if (vp < 30)
    {
      char cmd[64];
      i=30;
      if(vertflag) sprintf(cmd,"vp=%d ds %s('vert')\n",i,argv[0]);
      else sprintf(cmd,"vp=%d ds %s\n",i,argv[0]);
      if(!plot) execString(cmd); 
      //Werrprintf("pir requires minimum vp of 30");
      RETURN;
    }
  }

  //color(PARAM_COLOR);
  color(INTEG_MARK_COLOR);
  if (debug1)
  {
    Wscrprintf("dispcalib= %g, dfpnt2= %d, CharSize= %d, bottom= %d\n",
        dispcalib,dfpnt2,CharSize,
        dfpnt2 - CharSize + (int) (dispcalib * (vp - dpir_off - 5.0)));
    Wscrprintf("index highlimit lowlimit below\n");
    for (i = 1; i <= groups; i++)
      Wscrprintf("%d %d %d %s\n",i,gb[i].highlimit,gb[i].lowlimit,
                  (gb[i].below) ? "true" : "false");
  }
  if(vertflag) {
    for (i = 1; i <= groups; i++) label_pirv(i);
  } else {
    for (i = 1; i <= groups; i++) label_pir(i, ysize);
  }
  if (!plot) {
      char cmd[64];
      if(argc > 1) {
        if (isReal(argv[1]) ) sprintf(cmd,"%s(%s",argv[0],argv[1]);
	else sprintf(cmd,"%s('%s'",argv[0],argv[1]);
	for(i=2;i<argc;i++)
        {
           if (isReal(argv[i]) )
           {
	      strcat(cmd,",");
              strcat(cmd,argv[i]);
           }
	   else
           {
	      strcat(cmd,",'");
              strcat(cmd,argv[i]);
	      strcat(cmd,"'");
           }
	}
	strcat(cmd,")\n");
      } else sprintf(cmd,"%s\n",argv[0]);
      Wsetgraphicsdisplay("ds");
      set_dpir_flag(1,cmd);
  }
  releaseAllWithId("dpir");
  endgraphics();
  disp_status("        ");
  set_graphics_font("Default");
  RETURN;
}
Ejemplo n.º 16
0
/*-----------------------------------------------
|						|
|	 	  getdata()/0			|
|						|
|   This function reads the 1D or 2D data in 	|
|   form disk, manipulates it appropriately,	|
|   and moves the ReRe component to the memory	|
|   allocated for the phasefile data.		|
|						|
+----------------------------------------------*/
static int getdata()
{
   char		dsplymes[20],	/* display mode label		*/
		dmg1[5];
   int		npf1=0,		/* number of points along F1	*/
		npf2=0,		/* number of points along F2	*/
		i,
		r,
		found,
		f1phase,
		f2phase,
		quad2,
		quad4,
		complex_1D=0,
                norm_av,
                norm_dir,
                norm_phase,
                norm_phaseangle,
                norm_dbm,
                rev_av=0,
                rev_dir=0,
                rev_phase=0,
                rev_phaseangle=0,
		nplinear,
		npblock;
   float	*f1phasevec=NULL,	/* F1 phasing vector		*/
		*f2phasevec=NULL;	/* F2 phasing vector		*/
   double	rp_norm,
		lp_norm;
   double	rp_rev,
		lp_rev;
   dpointers	datablock;
   hycmplxhead	*tmpblkhead;


/********************************************
*  Get pointer to data in specified block.  *
********************************************/

   if ( (r = D_getbuf(D_DATAFILE, nblocks, c_buffer, &datablock)) )
   {
      D_error(r);
      return(ERROR);
   }
   else if (checkdata(datablock.head))
   {
      return(ERROR);
   }

/**********************
*  Setup for 2D data  *
**********************/

   quad2 = quad4 = FALSE;
   f1phase = f2phase = FALSE;

   if (d2flag)
   {
/************************************
*  Set the flags for the number of  *
*  quadrants.                       *
************************************/

     quad4 = (datahead.status & S_HYPERCOMPLEX);
     if (!quad4)
        quad2 = (datahead.status & S_COMPLEX);

/********************************************
*  Precalculate phasing vectors for the F1  *
*  and F2 dimensions if necessary.          *
********************************************/

      nplinear = pointsperspec;
      npblock = specperblock * nblocks;
      if (quad4)
      {
         npblock *= 2;
         nplinear /= 2;
      }

      if (revflag)
      {
         npf1 = nplinear;
         npf2 = npblock;
      }
      else
      {
         npf2 = nplinear;
         npf1 = npblock;
      }

      f1phasevec = NULL;	/* initialize pointer */
      f2phasevec = NULL;	/* initialize pointer */

/**********************************************
*  If a phase-sensitive display is requested  *
*  along F1, precalculate the F1 phasing      *
*  vector.                                    *
**********************************************/

      rev_dir = get_direction(REVDIR);
      get_phase_pars(rev_dir,&rp_rev,&lp_rev);
      rev_phase = get_phase_mode(rev_dir);
      rev_phaseangle = get_phaseangle_mode(rev_dir);
      rev_av = get_av_mode(rev_dir);
      f1phase = ( ((rev_phase && nonzerophase(rp_rev, lp_rev)) || rev_phaseangle) &&
                  (quad2 || quad4) &&
		  get_axis_freq(rev_dir) );

      if (f1phase)
      {
         f1phasevec = (float *) (allocateWithId( (unsigned) (sizeof(float)
	 			    * npf1), "getdata" ));
         if (f1phasevec == NULL)
         {
            Werrprintf("Unable to allocate memory for F1 phase buffer");
            return(ERROR);
         }
         else
         {
            phasefunc(f1phasevec, npf1/2, lp_rev, rp_rev);
         }
      }

/**********************************************
*  If a phase-sensitive display is requested  *
*  along F2, precalculate the F2 phasing      *
*  vector.                                    *
**********************************************/

      norm_dir = get_direction(NORMDIR);
      get_phase_pars(norm_dir,&rp_norm,&lp_norm);
      norm_phase = get_phase_mode(norm_dir);
      norm_phaseangle = get_phaseangle_mode(norm_dir);
      norm_av = get_av_mode(norm_dir);
      norm_dbm = get_dbm_mode(norm_dir); /* may not be active?? */
      f2phase = ( (norm_phase || norm_phaseangle) && quad4 && nonzerophase(rp_norm, lp_norm) );
		/* (quad4 || quad2)??  (quad4) only?? */

      if (f2phase)
      {
         f2phasevec = (float *) (allocateWithId( (unsigned) (sizeof(float)
	 			    * npf2), "getdata" ));
         if (f2phasevec == NULL)
         {
            Werrprintf("Unable to allocate memory for F2 phase buffer");
            if (f1phase)
               releaseAllWithId("getdata");
            return(ERROR);
         }
         else
         {
            phasefunc(f2phasevec, npf2/2, lp_norm, rp_norm);
         }
      }
   }
   else
   {
      complex_1D = (datablock.head->status & NP_CMPLX);
      norm_dir = HORIZ;
      norm_phase = get_phase_mode(norm_dir);
      norm_phaseangle = get_phaseangle_mode(norm_dir);
      norm_av = get_av_mode(norm_dir);
      norm_dbm = get_dbm_mode(norm_dir); /* may not be active 2 */
   }

/*************************************
*  Readjust "npf1" and "npf2" to be  *
*  per block.                        *
*************************************/

   if (d2flag)
   {
      if (revflag)
      {
         npf2 /= nblocks;
      }
      else
      {
         npf1 /= nblocks;
      }
   }

/**********************************
*  Construct display mode label.  *
**********************************/

   strcpy(dsplymes, ""); 	/* initialization of string */

   if ( d2flag && (quad2 || quad4) )
   {
      char charval;
      char tmp[10];

      get_display_label(rev_dir,&charval);
      if (rev_phase)
      {
         sprintf(tmp, "PH%c ",charval);
      }
      else if (rev_av)
      {
         sprintf(tmp, "AV%c ",charval);
      }
      else if (rev_phaseangle)
      {
         sprintf(tmp, "PA%c ",charval);
      }
      else
      {
         sprintf(tmp, "PW%c ",charval);
      }

      strcpy(dsplymes, tmp);
   }

   if ( (d2flag && quad4) || ((!d2flag) && complex_1D) )
   {
      char charval;
      char tmp[10];

      get_display_label(norm_dir,&charval);
      if (charval == '\0')
         charval = ' ';
      if (norm_phase)
      {
         sprintf(tmp, "PH%c",charval);
      }
      else if (norm_av)
      {
         sprintf(tmp, "AV%c",charval);
      }
      else if (norm_phaseangle)
      {
         sprintf(tmp, "PA%c",charval);
      }
      else
      {
         sprintf(tmp, "PW%c",charval);
      }

      strcat(dsplymes, tmp);
   }

   disp_status(dsplymes);

/*************************************************
*  Manipulate data depending upon the number of  *
*  2D data quadrants and the desired mode of     *
*  display.					 *
*************************************************/

   if (d2flag)
   {
      if (quad4)
      {

/***********************************
*  HYPERCOMPLEX 2D spectral data:  *
*  F2 phase-sensitive display      *
***********************************/

         if (norm_phase)
         {
            if (rev_phase)
            {

	/*****************************
	*  phase for ReRe component  *
	*****************************/
               if (f1phase && f2phase)
               {
                  blockphase4(datablock.data, c_block.data, f1phasevec,
	  		f2phasevec, nblocks, c_buffer, npf1/2, npf2/2);
               }
               else if (f1phase)
               {
                  blockphase2(datablock.data, c_block.data, f1phasevec,
			nblocks, c_buffer, npf1/2, npf2/2, HYPERCOMPLEX,
			COMPLEX, TRUE, FALSE);
               }
               else if (f2phase)
               {
                  blockphase2(datablock.data, c_block.data, f2phasevec,
			nblocks, c_buffer, npf1/2, npf2/2, HYPERCOMPLEX,
			REAL, FALSE, FALSE);
               }
               else
               {
                  movmem((char *)datablock.data, (char *)c_block.data,
			(npf1*npf2*sizeof(float))/4, HYPERCOMPLEX,
			4);
               }
            }
            else
            {
               if (f2phase)
               {

	/***************************
	*  rotate ReRe <---> ReIm  *
	*  rotate ImRe <---> ImIm  *
	***************************/
                  if (rev_av)
                  {

	/********************************
	*  S = sqrt(ReRe**2 + ImRe**2)  *
	********************************/
                     blockphsabs4(datablock.data, c_block.data, f2phasevec,
			   nblocks, c_buffer, npf1/2, npf2/2, REAL, FALSE);
                  }
                  else if (rev_phaseangle)
                  {
                     blockphaseangle2(datablock.data, c_block.data, f1phasevec,
                           nblocks, c_buffer, npf1/2, npf2/2, HYPERCOMPLEX,
                           COMPLEX, TRUE, FALSE);
                  }
                  else
                  {

	/**************************
	*  S = ReRe**2 + ImRe**2  *
	**************************/
                     blockphspwr4(datablock.data, c_block.data, f2phasevec,
			   nblocks, c_buffer, npf1/2, npf2/2, REAL, FALSE);
                  }
               }
               else if (rev_av)	/* no F2 phasing required */
               {

	/********************************
	*  S = sqrt(ReRe**2 + ImRe**2)  *
	********************************/
                  absval2(datablock.data, c_block.data, (npf1*npf2)/4,
                        HYPERCOMPLEX, COMPLEX, REAL, FALSE);
               }
/* else if (rev_phaseangle) {} */
               else			/* no F2 phasing required */
               {

	/**************************
	*  S = ReRe**2 + ImRe**2  *
	**************************/
                  pwrval2(datablock.data, c_block.data, (npf1*npf2)/4,
                        HYPERCOMPLEX, COMPLEX, REAL, FALSE);
               }
            }
         }

/***********************************
*  HYPERCOMPLEX 2D spectral data:  *
*  F2 absolute-value display       *
***********************************/

         else if (norm_av)
         {
            if (rev_phase)
            {
               if (f1phase)
               {

	/********************************
	*  rotate ReRe <---> ImRe       *
	*  rotate ReIm <---> ImIm       *
	*  S = sqrt(ReRe**2 + ReIm**2)  *
	********************************/
                  blockphsabs4(datablock.data, c_block.data, f1phasevec,
			   nblocks, c_buffer, npf1/2, npf2/2, COMPLEX, TRUE);
               }
               else
               {

	/********************************
	*  S = sqrt(ReRe**2 + ReIm**2)  *
	********************************/
                  absval2(datablock.data, c_block.data, (npf1*npf2)/4,
			HYPERCOMPLEX, REAL, REAL, FALSE);
               }
            }
            else if (rev_av)
            {

	/****************************************************
	*  S = sqrt(ReRe**2 + ReIm**2 + ImRe**2 + ImIm**2)  *
	****************************************************/
               absval4(datablock.data, c_block.data, npf1*npf2/4);
            }
/* else if (rev_phaseangle) {} */
            else
            {

	/****************************
	*  S1 = ReRe**2 + ImRe**2   *
	*  S2 = ReIm**2 + ImIm**2   *
        *  S = sqrt(S1**2 + S2**2)  *
	****************************/
               blockpwrabs(datablock.data, c_block.data, (npf1*npf2)/4,
				COMPLEX);
            }
         }

/***********************************
*  HYPERCOMPLEX 2D spectral data:  *
*  F2 phaseangle display           *
***********************************/

         else if (norm_phaseangle)
         {
            Werrprintf("Cannot perform hypercomplex phaseangle");
            return(ERROR);
         }

/***********************************
*  HYPERCOMPLEX 2D spectral data:  *
*  F2 power display                *
***********************************/

         else
         {
            if (rev_phase)
            {
               if (f1phase)
               {

	/***************************
	*  rotate ReRe <---> ImRe  *
	*  rotate ReIm <---> ImIm  *
	*  S = ReRe**2 + ReIm**2   *
	***************************/
                  blockphspwr4(datablock.data, c_block.data, f1phasevec,
			   nblocks, c_buffer, npf1/2, npf2/2, COMPLEX, TRUE);
               }
               else
               {

	/**************************
	*  S = ReRe**2 + ReIm**2  *
	**************************/
                  pwrval2(datablock.data, c_block.data, (npf1*npf2)/4,
			   HYPERCOMPLEX, REAL, REAL, FALSE);
               }
            }
            else if (rev_av)
            {

	/****************************
	*  S1 = ReRe**2 + ReIm**2   *
	*  S2 = ImRe**2 + ImIm**2   *
        *  S = sqrt(S1**2 + S2**2)  *
	****************************/
               blockpwrabs(datablock.data, c_block.data, (npf1*npf2)/4,
				REAL);
            }
/* else if (rev_phaseangle) {} */
            else
            {

	/**********************************************
	*  S = ReRe**2 + ReIm**2 + ImRe**2 + ImIm**2  *
	*  THIS IS NOT QUITE RIGHT!                   *
	**********************************************/
               pwrval4(datablock.data, c_block.data, npf1*npf2/4);
            }
         }

/**********************************************
*  Set the F1 phase constants into the block  *
*  header of the phasefile data.              *
**********************************************/

         if (rev_phase || rev_phaseangle)
         {
            c_block.head->lpval = lp_rev;
            c_block.head->rpval = rp_rev;
         }
         else
         {
            c_block.head->lpval = 0.0;
            c_block.head->rpval = 0.0;
         }

/***************************************************
*  Locate the block header for the "hypercomplex"  *
*  information.  Then set the F2 phase constants   *
*  into the block header of the phasefile data.    *
***************************************************/

         i = 0;
         found = FALSE;

         while (!found)
         {
            if ( (~(datablock.head + i)->status) & MORE_BLOCKS )
            {
               Werrprintf("Block headers inconsistent with hypercomplex data");
               if (f1phase || f2phase)
                  releaseAllWithId("getdata");
               return(ERROR);
            }

            i += 1;
            found = ( (datablock.head + i)->status & U_HYPERCOMPLEX );
         }

         tmpblkhead = (hycmplxhead *) (c_block.head + i);
         if (norm_phase)
         {
            tmpblkhead->lpval1 = lp_norm;
            tmpblkhead->rpval1 = rp_norm;
         }
         else
         {
            tmpblkhead->lpval1 = 0.0;
            tmpblkhead->rpval1 = 0.0;
         }
      }
      else if (quad2)
      {

/*******************************
*  COMPLEX 2D spectral data:   *
*  F1 display selection        *
*******************************/

         if (rev_phase)
         {

       /***************************
       *  rotate ReRe <---> ImRe  *
       ***************************/
            if (f1phase)
            {
               blockphase2(datablock.data, c_block.data, f1phasevec,
			nblocks, c_buffer, npf1/2, npf2, COMPLEX, 1,
			TRUE, FALSE);
            }
            else
            {
               movmem((char *)datablock.data, (char *)c_block.data,
			(npf1*npf2*sizeof(float))/2, COMPLEX, 4);
            }
         }
         else if (rev_phaseangle)
         {
            if (f1phase)
            {
               blockphaseangle2(datablock.data, c_block.data, f1phasevec,
			nblocks, c_buffer, npf1/2, npf2, COMPLEX, 1,
			TRUE, FALSE);
            }
            else
            {
               movmem((char *)datablock.data, (char *)c_block.data,
                        (npf1*npf2*sizeof(float))/2, COMPLEX, 4);
            }
         }
         else if (rev_av)
         {

       /********************************
       *  S = sqrt(ReRe**2 + ImRe**2)  *
       ********************************/
            absval2(datablock.data, c_block.data, (npf1*npf2)/2,
			COMPLEX, 1, 1, FALSE);
         }
         else
         {

       /**************************
       *  S = ReRe**2 + ImRe**2  *
       **************************/
            pwrval2(datablock.data, c_block.data, (npf1*npf2)/2,
			COMPLEX, 1, 1, FALSE);
         }

         if (rev_phase || rev_phaseangle)
         {
            c_block.head->lpval = lp_rev;
            c_block.head->rpval = rp_rev;
         }
         else
         {
            c_block.head->lpval = 0.0;
            c_block.head->rpval = 0.0;
         }
      }
      else
      {

/***************************
*  REAL 2D spectral data   *
***************************/

         movmem((char *)datablock.data, (char *)c_block.data,
			npf1*npf2*sizeof(float), REAL, 4);
         c_block.head->lpval = 0.0;
         c_block.head->rpval = 0.0;
      }
   }

/**********************
*  Setup for 1D data  *
**********************/

   else
   {
    if(bph()>0 && complex_1D && (norm_phase || norm_phaseangle)) {
      // don't use lp, rp, because block is individually phased. 
      c_block.head->lpval=getBph1(c_buffer); 
      c_block.head->rpval=getBph0(c_buffer);
      if (norm_phase)
      {
        phase2(datablock.data, c_block.data, fn/2, c_block.head->lpval, c_block.head->rpval);
      }
      else if (norm_phaseangle)
      {
        phaseangle2(datablock.data, c_block.data, fn/2, COMPLEX,
			1, 1, FALSE, c_block.head->lpval, c_block.head->rpval);
      }
      P_setreal(CURRENT,"bph1",c_block.head->lpval,0);
      P_setreal(CURRENT,"bph0",c_block.head->rpval,0);
    } else { 
      c_block.head->lpval = 0.0;
      c_block.head->rpval = 0.0;

      if (complex_1D)
      {
         if (norm_phase)
         {
            phase2(datablock.data, c_block.data, fn/2, lp, rp);
            c_block.head->lpval = lp;
            c_block.head->rpval = rp;
         }
         else if (norm_phaseangle)
         {
            phaseangle2(datablock.data, c_block.data, fn/2, COMPLEX,
			1, 1, FALSE, lp, rp);
            c_block.head->lpval = lp;
            c_block.head->rpval = rp;
         }
         else if (norm_av)
         {
            absval2(datablock.data, c_block.data, fn/2, COMPLEX,
			1, 1, FALSE);
         }
         else if (norm_dbm)
         {
            dbmval2(datablock.data, c_block.data, fn/2, COMPLEX,
			1, 1, FALSE);
         } 
         else
         {
            pwrval2(datablock.data, c_block.data, fn/2, COMPLEX,
			1, 1, FALSE);
         }
      }
      else
      {
         if (datablock.head->status & S_COMPLEX)
         {
            movmem((char *)datablock.data, (char *)c_block.data,
			(fn/2)*sizeof(float), COMPLEX, 4);
         }
         else
         {
            movmem((char *)datablock.data, (char *)c_block.data,
			(fn/2)*sizeof(float), REAL, 4);
         }
      }
    }
   }

/*************************************
*  Set status word for block header  *
*  of phasefile.                     *
*************************************/

   c_block.head->status = (S_DATA|S_SPEC|S_FLOAT);

/*********************************** 
*  Set mode word for block header  * 
*  of phasefile.                   * 
***********************************/

   c_block.head->mode = get_mode(HORIZ);
   if (d2flag)
      c_block.head->mode |= get_mode(VERT);

/***************************************
*  Set additional words in main block  *
*  header of phasefile.                *
***************************************/

   c_block.head->scale = 0;
   c_block.head->ctcount = 0;
   c_block.head->index = (short)c_buffer;
   c_block.head->lvl = 0.0;
   c_block.head->tlt = 0.0;

/************************************************
*  Set status word in previous block header of  *
*  phasefile to indicate the presence of a      *
*  following block header.                      *
************************************************/

   if (d2flag)
   {
      i = 0;
      while ((datablock.head + i)->status & MORE_BLOCKS)
      {
         (c_block.head + i)->status |= MORE_BLOCKS;
         i += 1;
         if ((datablock.head + i)->status & U_HYPERCOMPLEX)
            (c_block.head + i)->status |= U_HYPERCOMPLEX;
      }
   }


/******************************************
*  Release this DATAFILE buffer with the  *
*  data handler routines.                 *
******************************************/

   if ( (r = D_release(D_DATAFILE, c_buffer)) )
   {
      D_error(r);
      if (f1phase || f2phase)
         releaseAllWithId("getdata");
      return(ERROR);
   }

   if (P_copyvar(CURRENT, PROCESSED, "dmg", "dmg"))
   {
      Werrprintf("dmg:  cannot copy from 'current' to 'processed' tree\n");
      if (f1phase || f2phase)
         releaseAllWithId("getdata");
      return(ERROR);
   }

   if (d2flag)
   {
      if (!P_getstring(CURRENT, "dmg1", dmg1, 1, 5))
      {
         if (P_copyvar(CURRENT, PROCESSED, "dmg1", "dmg1"))
         {
            Werrprintf("dmg1: cannot copy from 'current' to 'processed' tree");
            if (f1phase || f2phase) 
               releaseAllWithId("getdata");
            return(ERROR);
         }
      }
   }

   if (f1phase || f2phase)
      releaseAllWithId("getdata");
   if (!Bnmr)
      disp_status("                 ");
   return(COMPLETE);
}
Ejemplo n.º 17
0
/* frqdimname;	frequency dimension  */
static int getspecparms(int dis_setup, int frqdimname)
{
  char		aig[5],
		dmg[5],
		dmg1[5];
  int		dim0,dim1;
  int		r;
  double	x0;

// min, max sw values
  double minval, maxval;
  if(P_getmin(PROCESSED, "sw", &minval) ) minval = 200.0;
  if(P_getmax(PROCESSED, "sw", &maxval) ) maxval = 200.0;

  dim0 = FN0_DIM;
  dim1 = FN1_DIM;
  if (d2flag)
  {
     if (frqdimname == S_NP)
     {
        if (datahead.status & S_SPEC)
        {
           Werrprintf("Data file must first be re-initialized with FID data\n");
           return(ERROR);
        }

        d2flag = FALSE;
        dim0 = FN0_DIM;
        dim1 = FN0_DIM;
     }
     else
     {
        if (ndflag == FOUR_D)
        {
           if (frqdimname & S_NP)
           {
              dim0 = FN0_DIM;
              if (frqdimname & S_NI)
                 dim1 = FN1_DIM;
              else if (frqdimname & S_NI2)
                 dim1 = FN2_DIM;
              else
                 dim1 = FN3_DIM;
           }
           else if (frqdimname & S_NI)
           {
              dim0 = FN1_DIM;
              if (frqdimname & S_NI2)
                 dim1 = FN2_DIM;
              else
                 dim1 = FN3_DIM;
           }
           else
           {
              dim0 = FN2_DIM;
              dim1 = FN3_DIM;
           }
        }
        else if (frqdimname & S_NP)
        {
           dim0 = FN0_DIM;
           dim1 = ( (frqdimname & S_NI2) ? FN2_DIM : FN1_DIM );
        }
        else if ( (~frqdimname) & S_NF )
        {
           dim0 = FN2_DIM;
           dim1 = FN1_DIM;
        }
        else
        {   
           Werrprintf("Invalid name for 2nd dimension\n");
           return(ERROR);
        }
     }
  }

/************************************************
*  Set the normalization, processing mode, and  *
*  display flags for either 1D or 2D data.      *
************************************************/

  if ( (r = P_getstring(CURRENT, "aig", aig, 1, 4)) )
  {
     if ( expdir_to_expnum(curexpdir) > 0 )
        P_err(r, "aig", ":");
     return(ERROR);
  }

  if ( (r = P_getstring(CURRENT, "dmg", dmg, 1, 4)) )
  {
     P_err(r, "dmg", ":");
     return(ERROR);
  }

  normflag = (aig[0] == 'n');
  dophase = doabsval = dopower = dophaseangle = dodbm = FALSE;
  dof1phase = dof1absval = dof1power = dof1phaseangle = FALSE;

  dophase = ((dmg[0] == 'p') && (dmg[1] == 'h'));
  if (!dophase)
  {
     doabsval = ((dmg[0] == 'a') && (dmg[1] == 'v'));
     if (!doabsval)
     {
        dopower = ((dmg[0] == 'p') && (dmg[1] == 'w'));
        if (!dopower)
        {
           dophaseangle = ((dmg[0] == 'p') && (dmg[1] == 'a'));
           if (!dophaseangle)
           {
        	   dodbm = ((dmg[0] == 'd') && (dmg[1] == 'b'));
        	   if (!dodbm)
        	   {
        	      Werrprintf("Invalid display mode for 1D spectral data");
        	      return(ERROR);
        	   }
           }
        } 
     } 
  }

  if (d2flag)
  {
     r = P_getstring(CURRENT, "dmg1", dmg1, 1, 5);
     if (!r)
     {
        r = ( (strcmp(dmg1, "ph1") != 0) && (strcmp(dmg1, "av1") != 0) &&
		  (strcmp(dmg1, "pwr1") != 0) );
     }

     if (r)
     { /* default to "dmg" */
        if ( (r = P_getstring(CURRENT, "dmg", dmg1, 1, 4)) )
        {
           P_err(r, "dmg", ":");
           disp_status("        ");
           return(ERROR);
        }
     }

     dof1phase = ((dmg1[0] == 'p') && (dmg1[1] == 'h'));
     if (!dof1phase) 
     {
        dof1absval = ((dmg1[0] == 'a') && (dmg1[1] == 'v')); 
        if (!dof1absval)
        { 
           dof1power = ((dmg1[0] == 'p') && (dmg1[1] == 'w')); 
           if (!dof1power)
           {
              dof1phaseangle = ((dmg1[0] == 'p') && (dmg1[1] == 'a')); 
              if (!dof1phaseangle)
              {
                 Werrprintf("Invalid F1 display mode for 2D spectral data");
                 return(ERROR); 
              }
           } 
        } 
     }
  }

  if (dis_setup)
  {
/************************************
*  Get current display parameters.  *
************************************/
     P_getreal(CURRENT,"vs",&vs,1);
     P_getreal(CURRENT,"vsproj",&vsproj,1);
     P_getreal(CURRENT,"vs2d",&vs2d,1);
     C_GETPAR("is", &is);
     C_GETPAR("io", &io);
     C_GETPAR("th", &th);
     C_GETPAR("vp", &vp);
     C_GETPAR("vo", &vo);
     C_GETPAR("ho", &ho);
     C_GETPAR("lvl", &lvl);
     C_GETPAR("tlt", &tlt);
  }

  if (d2flag)
  {

/*******************************************************
*  Check whether the datafile contains FID's, half-    *
*  transformed spectra, or fully transformed spectra.  *
*******************************************************/

     if ( (~datahead.status) & S_SECND)
     { /* not fully transformed 2D spectrum */
        dim1 = ( (datahead.status & S_NI2) ? SW2_DIM : SW1_DIM );
        if ( (~datahead.status) & S_SPEC)
           dim0 = SW0_DIM;
     }
  }
  else
  {
     dim0 = FN0_DIM;
     dim1 = FN1_DIM;
  }

  if (d2flag && revflag)
  {
     set_spec_display(HORIZ,dim1,VERT,dim0);
     set_display_label(HORIZ,revchar,VERT,normchar);
     set_spec_proc(HORIZ,dim1,REVDIR, VERT,dim0,NORMDIR);
  }
  else
  {
     set_spec_display(HORIZ,dim0,VERT,dim1);
     set_display_label(HORIZ,normchar,VERT,revchar);
     set_spec_proc(HORIZ,dim0,NORMDIR, VERT,dim1,REVDIR);
  }
  get_sfrq(HORIZ,&sfrq);
  get_sfrq(VERT,&sfrq1);
  get_cursor_pars(HORIZ,&cr,&delta);
  get_phase_pars(HORIZ,&rp,&lp);
  get_ref_pars(HORIZ,&sw,&rflrfp,&fn);
  if(sw<=0 || sw>maxval) {
	Winfoprintf("Error sw out of bounds %f: 0 to %f",sw,maxval);
	return(ERROR);
  }
  get_scale_axis(HORIZ,&axisHoriz);
  get_scale_axis(VERT,&axisVert);
  {
     double axis_scl;
     int    reversed;

     get_scale_pars(HORIZ,&sp,&wp,&axis_scl,&reversed);
     if (get_axis_freq(HORIZ))
       set_sp_wp(&sp, &wp, sw, fn/2, rflrfp);
     else
       set_sf_wf(&sp, &wp, sw, fn/2);
     UpdateVal(HORIZ,WP_NAME,wp,NOSHOW);
     UpdateVal(HORIZ,SP_NAME,sp,NOSHOW);
  }

  if (d2flag)
  {
     get_phase_pars(VERT,&rp1,&lp1);
     get_ref_pars(VERT,&sw1,&rflrfp1,&fn1);
     if(dim1==FN1_DIM && (sw1<=0 || sw1>maxval)) {
	Winfoprintf("Error sw1 out of bounds %f: 0 to %f",sw1,maxval);
	return(ERROR);
  }
     {
        double axis_scl;
        int    reversed;

        get_scale_pars(VERT,&sp1,&wp1,&axis_scl,&reversed);
        if (get_axis_freq(VERT))
           set_sp_wp(&sp1, &wp1, sw1, fn1/2, rflrfp1);
        else
           set_sf_wf(&sp1, &wp1, sw1, fn1/2);
        UpdateVal(VERT,WP_NAME,wp1,NOSHOW);
        UpdateVal(VERT,SP_NAME,sp1,NOSHOW);
     }
     x0 = 1.0;
     if ( get_axis_freq(HORIZ) && get_axis_freq(VERT) )
     {
        if (((axisHoriz == 'c') || (axisHoriz == 'm') || (axisHoriz == 'u'))
         && ((axisVert == 'c') || (axisVert == 'm') || (axisVert == 'u')))
        {
	   if (axisHoriz == 'c') x0 =  1.0;
	   if (axisHoriz == 'm') x0 = 10.0;
	   if (axisHoriz == 'u') x0 = 1e4;
	   if (axisVert == 'c') x0 /= 1.0;
	   if (axisVert == 'm') x0 /= 10.0;
	   if (axisVert == 'u') x0 /= 1e4;
        }
     }
     aspect_ratio = (wp*sfrq1)/(x0*wp1*sfrq);
  }
  else
  {
     fn1 = fn;
     sw1 = 0.0;
     rflrfp1 = 0.0;
     aspect_ratio = 100.0;
  }
  normInt = 0;
  insval = 1.0;
  if (!P_getreal(CURRENT, "ins", &insval, 1))
  {
     vInfo  info;
     double tmp;

     if (!P_getreal(CURRENT, "insref", &tmp, 1))
     {
        P_getVarInfo(CURRENT,"insref",&info);
        if (!info.active)
           normInt = 1;
        else if (tmp > 0.0)
           insval /= tmp;
     }
  }
  if (insval <= 0.0)
     insval = 1.0;
  if (!normInt)
     insval /= (double) fn;

  normInt2 = 0;
  ins2val = 1.0;
  if (!P_getreal(CURRENT, "ins2", &ins2val, 1))
  {
     vInfo  info;
     double tmp;

     if (!P_getreal(CURRENT, "ins2ref", &tmp, 1))
     {
        P_getVarInfo(CURRENT,"ins2ref",&info);
        if (!info.active)
           normInt2 = 1;
        else if (tmp > 0.0)
           ins2val /= tmp;
     }
  }
  if (ins2val <= 0.0)
     ins2val = 1.0;
  if (!normInt2)
     ins2val /= ((double)fn * (double)fn1);

  return(COMPLETE);
}
Ejemplo n.º 18
0
void fn_set(char **args)
{
    char *opt, *value;
    char *line = NULL, *p;
    char prompt[128];
    int ival, i;

    if (args) {
	opt = args[0];
	if (args[1])
	    value = args[1];
	else {
	    if (rc_inrc) {
		rc_error("no option value given");
		return;
	    }
	    sprintf(prompt, "set %s to: ", opt);
	    p = line = read_string(prompt, 1);
	    value = rc_token(&p);
	}
    }
    else {
	if (rc_inrc) {
	    rc_error("no option value given");
	    return;
	}
	p = line = read_string("set ", 1);
	opt = rc_token(&p);
	if (opt == NULL) {
	    disp_status(DISP_STATUS, "");
	    return;
	}
	value = rc_token(&p);
    }

    if (opt == NULL || opt[0] == '\0') {
	disp_status(DISP_STATUS, "no option.");
	return;
    }

    for (i=0; option[i].name; i++)
	if (strcasecmp(option[i].name, opt) == 0
	    || strcasecmp(option[i].shrt, opt) == 0)
	    break;

    if (option[i].name == NULL) {
	if (rc_inrc)
	    rc_error("unknown option: %s", opt);
	else
	    disp_status(DISP_STATUS, "unknown option: %s", opt);
	return;
    }

    switch (option[i].type) {
    case OPT_INT:
	if (value) {
	    ival = atoi(value);
	    if (option[i].func)
		option[i].func(ival, option[i].var.i);
	    else
		*(option[i].var.i) = ival;
	}
	
	if (!rc_inrc)
	    disp_status(DISP_STATUS, "%s set to %d", option[i].name,
			*(option[i].var.i));
	break;

    case OPT_CHR:
	if (value) {
	    ival = value[0];
	    if (option[i].func)
		option[i].func(ival, option[i].var.i);
	    else
		*(option[i].var.i) = ival;
	}
	
	if (!rc_inrc)
	    disp_status(DISP_STATUS, "%s set to `%c'", option[i].name,
			*(option[i].var.i));
	break;

    case OPT_STR:
	if (value) {
	    if (option[i].func)
		option[i].func(strdup(value), option[i].var.s);
	    else
		*(option[i].var.s) = strdup(value);
	}
	
	if (!rc_inrc)
	    disp_status(DISP_STATUS, "%s set to `%s'", option[i].name,
			*(option[i].var.s));
	break;
	
    case OPT_BOOL:
	if (value) {
	    if (value[0] == 't')
		ival = !*(option[i].var.i);
	    else if (value[0] == '0' || value[0] == 'n'
		|| strcasecmp(value, "off") == 0)
		ival = 0;
	    else
		ival = 1;
	    if (option[i].func)
		option[i].func(ival, option[i].var.i);
	    else
		*(option[i].var.i) = ival;
	}

	if (!rc_inrc)
	    disp_status(DISP_STATUS, "%s set to %s", option[i].name,
			(*(option[i].var.i) ? "on" : "off"));
	break;

    case OPT_ENUM:
	if (value) {
	    for (ival=0; option[i].values[ival]; ival++) {
		if (strcasecmp(value, option[i].values[ival]) == 0)
		    break;
	    }
	    if (option[i].values[ival] == NULL && !rc_inrc) {
		disp_status(DISP_STATUS, "unknown value %s for option %s",
			    value, option[i].name);
		break;
	    }

	    if (option[i].func)
		option[i].func(ival, option[i].var.i);
	    else
		*(option[i].var.i) = ival;
	}

	if (!rc_inrc)
	    disp_status(DISP_STATUS, "%s set to %s", option[i].name,
			option[i].values[(*(option[i].var.i))]);
	break;
    }
    
    if (line)
	free(line);

    return;
}
Ejemplo n.º 19
0
/*---------------------------------------
|    				        |
|    i_fiddle()    			|
|          				|
+--------------------------------------*/
static int i_fiddle(int argc, char *argv[])
{
	short status_mask;
	int  i,j;
	double v,np;
	vInfo info;
	int  flag;
	FILE *satfile;

	int	intcount;

	char	nohilbert[] 		= "nohilbert";		/* These are to */
	char	noextrap[] 		= "noextrap";		/* define the */
	char	verbos[] 		= "verbose";		/* strings used */
	char	fittedbaseline[] 	= "fittedbaseline";	/* for the 	*/
	char	stop1[] 		= "stop1";		/* fiddle 	*/
	char	stop2[] 		= "stop2";		/* command line	*/
	char	stop3[] 		= "stop3";
	char	stop4[] 		= "stop4";
	char	displaycf[] 		= "displaycf";
	char	nodc[] 			= "nodc";
	char	inver[] 		= "invert";
	char	satellites[] 		= "satellites";
	char	writefid[]		= "writefid";
	char	normalise[]		= "normalise";
	char	alternate[]		= "alternate";
	char	noaph[]			= "noaph";
	char	readcf[]		= "readcf";
	char	writecf[]		= "writecf";


	readcfflg=writecfflg=corfunc=noift=noftflag=invert=solvent=FALSE;
	dccorr=baseline=verbose=numsats=FALSE;
	apod=udifffg=difffg=firstfg=secondfg=nosub=FALSE;
	stopflag=0;
	halffg=hilbert=makereffg=ldcflag=extrap=aphflg=TRUE;
	altfg=flag2d=writefg=oflag=quantflag=FALSE;

	intcount=0;
	print=0;
	startno= -1;
	finishno=startno+1;
	stepno=1;
	sw1=0.0;
	rfl1=0.0;

	disp_status("IN");
	if ((P_getreal(PROCESSED, "ni", &v, 1) == 0&&(v>1.0))||
	    (P_getreal(PROCESSED, "ni2", &v, 1) == 0&&(v>1.0)) )
	{
		if (verbose) Wscrprintf("2D data\n");
		if 
(P_getreal(CURRENT,"sw1",&sw1,1)||P_getreal(CURRENT,"rfl1",&rfl1,1))
		{
			Werrprintf("Error accessing parameters\n");
			return(ERROR);
		}
	}


	if ((int)strlen(argv[0])>(int)6)
	{
		if (argv[0][6] == 'd')
		{
			Wscrprintf("Calculating FIDDLE'd difference between spectra n and n-1.\nds(1) for corrected 1st spectrum, ds(n) for difference.\n");
			difffg=TRUE;
			firstfg=TRUE;
		}
		if (argv[0][6] == 'u')
		{
			Wscrprintf("Calculating FIDDLE'd difference between spectra n and 1.\nds(1) for corrected 1st spectrum, ds(n) for difference \n");
			udifffg=TRUE;
			difffg=TRUE;
			firstfg=TRUE;
		}
		if (argv[0][6] == '2')
		{
			Wscrprintf("2D FIDDLE processing\n");
			flag2d=TRUE;
			quantflag=TRUE;
			extrap=FALSE;
			if (argv[0][8] == 'd')
			{
				Wscrprintf("... taking the difference between alternate fids\n");
				firstfg=TRUE;
				difffg=TRUE;
			}
		}
	}


	if (argc>1)		/* This is to check for the options used */
	{
		for (i=1;i<argc;i++)
		{
			if (atoi(argv[i])>0)
			{
				intcount++;
				if (intcount==1)
				{
					startno=atoi(argv[i])-1; 
					finishno=startno+1; 
					stepno=1;
				}
				if (intcount==2)
				{
					finishno=atoi(argv[i]); 
					stepno=1;
				}
				if (intcount==3)
				{
					stepno=atoi(argv[i]);
				}
			}
			else	if (equal(argv[i],nohilbert))
			{
				if (verbose) Wscrprintf("Not using Hilbert algorithm \n");
				hilbert=FALSE; 
				extrap=TRUE;
			}
			else if (equal(argv[i],noextrap))
			{
				if (verbose) Wscrprintf("Not using extrapolation of dispersion mode reference signal \n");
				extrap=FALSE;
			}
			else if (equal(argv[i],verbos))
			{
				verbose=TRUE;
				Wscrprintf("Verbose: displaying information during FIDDLE.\n");
			}
			else if (equal(argv[i],fittedbaseline))
			{
				if (verbose) Wscrprintf("Fitted baseline used.\n");
				baseline=TRUE;
			}
			else if (equal(argv[i],stop1))
			{
				if (verbose) Wscrprintf("Display experimental reference fid.\n");
				stopflag=1; 
				noftflag=TRUE;
			}
			else if (equal(argv[i],stop2))
			{
				if (verbose) Wscrprintf("Display correction function.\n");
				stopflag=2; 
				noftflag=TRUE;
			}
			else if (equal(argv[i],stop3))
			{
				if (verbose) Wscrprintf("Display ideal reference fid.\n");
				stopflag=3; 
				noftflag=TRUE;
			}
			else if (equal(argv[i],stop4))
			{
				if (verbose) Wscrprintf("Display first corrected fid.\n");
				stopflag=4;
			}
			else if (equal(argv[i],alternate))
			{
				if (verbose) Wscrprintf("Alternating phases of increments for hypercomplex 2D\n");
				altfg=TRUE;
			}
			else if (equal(argv[i],displaycf))
			{
				if (verbose) Wscrprintf("Display correction function in place of corrected spectrum\n");
				corfunc=TRUE; 
				noftflag=TRUE;
			}
			else if (equal(argv[i],nodc))
			{
				if (verbose) Wscrprintf("No dc correction of reference region \n");
				ldcflag=FALSE;
			}
			else if (equal(argv[i],inver))
			{
				if (verbose) Wscrprintf("Corrected difference spectrum will be inverted \n");
				invert=TRUE;
			}
			else if (equal(argv[i],satellites))
			{
				if (verbose) Wscrprintf("Satellites will be included in the ideal reference \n");
				numsats=TRUE;
				i++;
				if ((argc-1)<i)
				{
					Werrprintf("Satellite filename not specified");
					return(ERROR);
				}
				sprintf(satname,"/vnmr/satellites/%s",argv[i]);
				if (verbose) Wscrprintf("Satellite file name is %s \n",argv[i]);
			}
			else if (equal(argv[i],writefid))
			{
				if (verbose) Wscrprintf("Corrected fid will be written to disk \n");
				writefg=TRUE;
				i++;
				if ((argc-1)<i)
				{
					Werrprintf("Destination filename not specified\n");
					return(ERROR);
				}
				strcpy(writename,argv[i]);
				if (argv[i][0]!='/')
				{
					pathptr = get_cwd();
					strcpy(writename,pathptr);
					strcat(writename,"/");
					strcat(writename,argv[i]);
				}
				if
				(((int) 										
	(strlen(writename))<5)||(strcmp(&writename[strlen(writename)-4],".fid")))
				    strcat(writename,".fid");
				sprintf(sysstr,"mkdir %s",writename);
				if(system(sysstr))
				{
					sprintf(sysstr,"cd %s",writename);
					if(system(sysstr))
					{
						Werrprintf("System error: %s",sysstr);
						return(ERROR);
					}
				}
				Wscrprintf("Writing corrected fid out; destination file: %s\n",writename);
			}
			else if (equal(argv[i],writecf))
			{
				if (verbose) Wscrprintf("Correction function will be written to disk \n");
				writecfflg=TRUE;
				i++;
				if ((argc-1)<i)
				{
					Werrprintf("Destination filename not specified\n");
					return(ERROR);
				}
				strcpy(writecfname,argv[i]);
				if (argv[i][0]!='/')
				{
					pathptr = get_cwd();
					strcpy(writecfname,pathptr);
					strcat(writecfname,"/");
					strcat(writecfname,argv[i]);
				}
				if
				(((int) 										
	(strlen(writecfname))<5)||(strcmp(&writecfname[strlen(writecfname)-4],
				    ".fid")))
				    strcat(writecfname,".fid");
				sprintf(sysstr,"mkdir %s",writecfname);
				if(system(sysstr))
				{
					sprintf(sysstr,"cd %s",writecfname);
					if(system(sysstr))
					{
						Werrprintf("System error: %s",sysstr);
						return(ERROR);
					}
				}
				Wscrprintf("Writing correction function out; destination file: %s\n",writecfname);
			}
			else if (equal(argv[i],readcf))
			{
				if (verbose) Wscrprintf("Correction function will be read from disk \n");
				readcfflg=TRUE;
				i++;
				if ((argc-1)<i)
				{
					Werrprintf("Source filename not specified\n");
					return(ERROR);
				}
				strcpy(readcfname,argv[i]);
				if (argv[i][0]!='/')
				{
					pathptr = get_cwd();
					strcpy(readcfname,pathptr);
					strcat(readcfname,"/");
					strcat(readcfname,argv[i]);
				}
				if
				(((int) 										
	(strlen(readcfname))<5)||(strcmp(&readcfname[strlen(readcfname)-4],
				    ".fid")))
				   strcat(readcfname,".fid");
				sprintf(sysstr,"cd %s",readcfname);
				if(system(sysstr))
				{
					Werrprintf("System error: %s",sysstr);
					return(ERROR);
				}

				Wscrprintf("Reading correction function in; source file: %s\n",readcfname);
			}
			else if (equal(argv[i],noaph))
			{
				if (verbose) Wscrprintf("Reference region(s) will not be automatically phased\n");

				aphflg=FALSE;
			}
			else if (equal(argv[i],normalise))
			{
				if (verbose) Wscrprintf("Corrected spectra will be normalised to 1st spectrum\n");

				quantflag=TRUE;
			}

			else {
				Werrprintf("Option %s was not recognised ",argv[i]);
			}
		}
	}

	if (verbose&&numsats) printf("%s\n",satname);
	if (noift&&!stopflag) stopflag=2;
	if (stopflag==4&&!difffg) stopflag=3;
	if (difffg) finishno++;

	D_allrelease();


	/* get parameters */
	if  (
	    P_getreal(PROCESSED,"fn",&fn,1)||
	    P_getreal(CURRENT,"ct",&ct,1)||
	    P_getreal(CURRENT,"sw",&sw,1)||
	    P_getreal(CURRENT,"cr",&cr,1)||
	    P_getreal(CURRENT,"delta",&delta,1)||
	    P_getreal(CURRENT,"rfl",&rfl,1)||
	    P_getreal(CURRENT,"rfp",&rfp,1)||
	    P_getreal(CURRENT,"rp",&rp,1)||
	    P_getreal(CURRENT,"lp",&lp,1)||
	    P_getreal(PROCESSED,"sfrq",&sfrq,1)||
	    P_getreal(PROCESSED,"np",&np,1)
	    )
	{
		Werrprintf("Error accessing parameters\n");
		return(ERROR);
	}

	if (ct==0)
	{
		ct=1;
		Werrprintf("ct was zero; assumed to be 1\n");
	}
	if (verbose)
		Wscrprintf("sw %lf, cr %lf, delta %lf, rfl %lf, rfp %lf, rp %lf, lp %lf\n",
		    sw,cr,delta,rfl,rfp,rp,lp);
	if ((cr<rfp)||(cr-delta>rfp))
	{
		Werrprintf("Please place cursors either side of reference and try again\n");
		return(ERROR);
	}
	if (!aphflg)
	{
		if (flag2d)
		{
			if (P_getreal(CURRENT,"phinc",&rpinc,1))
			{
				/*  parameter phinc not created, so set phase increment to zero	*/
				rpinc=0.0;
			}
			if (P_getreal(CURRENT,"rp2nd",&rp2nd,1))
			{
				rp2nd=rp;
			}
		}
	}

	npi= (int)np;

	np0 = (int)fn;
	fn0 = np0;    /* ! */
	if (hilbert&&((int)np>fn0/2))
	{
		if (verbose) Wscrprintf("np = %f ",np);
		if (verbose) Wscrprintf("fn = %f\n",fn);
		Werrprintf("Data should be zerofilled so that fn>=2*np for hilbert transform");
		npi=(int) fn0/2;
	}
	if (hilbert) np0w=np0/2; 
	else np0w=np0;

	/* calculate rest of params */
	hzpp=sw/np0*2;
	refpos=2*(int)((sw-rfl)/hzpp);
	refposfr=((sw-rfl)/hzpp)-0.5*(double)refpos;
	leftpos=refpos-2*(int)((cr-rfp)/hzpp);
	rightpos=leftpos+2*(int)(delta/hzpp);
	if (verbose) Wscrprintf(" refposfr %g, hzpp %g, left %d, ref %d, right %d\n",
	    refposfr,hzpp,leftpos,refpos,rightpos);

	/* read satellite file if used */
	if (numsats)
	{
		if ((satfile=fopen(satname,"r"))==NULL)
		{
			Werrprintf("Error opening satellite file\n");
			return(ERROR);
		}
		numsats=0;
		while(fscanf(satfile,"%f %f %f\n",&satpos[numsats],
		    &satint[numsats],&satish[numsats])!=EOF)
		{
			if (verbose) printf("%f %f %f\n",
			    satpos[numsats],satint[numsats],satish[numsats]);
			numsats++;
		}
		fclose(satfile);
	}

	/* access & check the file containing the original spectrum */
	if ( (r = D_gethead(D_DATAFILE, &fidhead)) )
	{
		if (r == D_NOTOPEN)
		{
			if (verbose) Wscrprintf("Original Spectrum had to be re-opened \n");
			strcpy(path, curexpdir);
			strcat(path, "/datdir/data");
			r = D_open(D_DATAFILE, path, &fidhead); /* open the file */
		}

		if (r)
		{
			D_error(r);
			return(ERROR);
		}
	}
	status_mask = (S_DATA|S_SPEC|S_FLOAT|S_COMPLEX);
	if ( (fidhead.status & status_mask) != status_mask )
	{
		Werrprintf("No spectrum in file: use ft before fiddle. fidhead.status = %d", fidhead.status);
		return(ERROR);
	}
	if (np0 != fidhead.np)
	{
		Werrprintf("Size of data inconsistent, np0 = %d, head.np = %d",
		    np0, fidhead.np);
		return(ERROR);
	}

	if(writefg) getfidblockheadforwrite();
	if(writecfflg) getfidblockheadforcf();

	/* Set PHASFILE status to !S_DATA - this is required to
	 force a recalculation of the display from the new data
	 in DATAFILE (in the ds routine, see proc2d.c)   */
	if ( (r=D_gethead(D_PHASFILE,&phasehead)) )
	{
		if (r==D_NOTOPEN)
		{
			Wscrprintf("phas NOTOPEN\n");
			strcpy(path,curexpdir);
			strcat(path,"/datdir/phasefile");
			r=D_open(D_PHASFILE,path,&phasehead);
		}
		if (r)
		{
			D_error(r);
			return(ERROR);
		}
	}
	phasehead.status=0;
	if ( (r=D_updatehead(D_PHASFILE,&phasehead)) )
	{
		D_error(r);
		Wscrprintf("PHAS updatehead\n");
		return(ERROR);
	}

	/* allocate memory for the temp buffers & weight func. */
	if ( (data1=(float *)malloc(sizeof(float)*fn0))==0
	    ||(data2=(float *)malloc(sizeof(float)*fn0))==0
	    ||(data3=(float *)malloc(sizeof(float)*fn0))==0
	    ||(wtfunc=(float *)malloc(sizeof(float)*np0/2))==0)
	{
		Werrprintf("could not allocate memory\n");
		difffg=FALSE;
		freall(TRUE);
	}
	if (difffg)
	{
		if ((data4=(float *)malloc(sizeof(float)*fn0))==0)
		{
			Werrprintf("could not allocate memory\n");
			freall(TRUE);
		}
	}
	if (writefg||writecfflg||readcfflg)
	{
		if ((intbuf=(int *)malloc(sizeof(float)*fn0))==0)
		{
			Werrprintf("could not allocate memory\n");
			freall(TRUE);
		}
	}
	if(readcfflg) setupreadcf();

	/* setup weighting function for ideal fid */
	if (init_wt1(&wtp,S_NP))
	{
		Wscrprintf("ERROR: init_wt1(S_NP)\n");
		freall(TRUE);
	}
	if (init_wt2(&wtp,wtfunc,np0/2,FALSE,S_NP,1.0,FALSE))
	{
		Wscrprintf("ERROR: init_wt2()\n");
		freall(TRUE);
	}

	/* setup for solvent rd */
	if (solvent)
	{
		if (P_getVarInfo(CURRENT,"lifrq",&info))
		{
			Werrprintf("Error accessing resets");
			freall(TRUE);
		}
		numresets=(int)info.size;
		if (numresets<=1)
		{
			Werrprintf("Please provide some integral resets");
			freall(TRUE);
		}
		if ((resets=(double *)malloc(sizeof(double)*(numresets+4)))==0
		    ||(spy=(double *)malloc(sizeof(double)*(numresets+4)))==0
		    ||(spx=(int *)malloc(sizeof(int)*(numresets+4)))==0
		    ||(spg=(double *)malloc(sizeof(double)*(numresets+4)))==0 )
		{
			Werrprintf("error allocating memory");
			freall(TRUE);
		}
		i=1;
		flag=0;
		for (j=1;j<numresets;j++)
		{
			if (P_getreal(CURRENT,"lifrq",&resets[i],j))
			{
				Werrprintf("Error accessing lifrq(%d)\n",i);
				freall(TRUE);
			}
			if (resets[i]<(rfl-rfp+cr)&&flag==0)
			{
				resets[i+1]=resets[i];
				resets[i]=rfl-rfp+cr;
				flag=1;
				i++;
			}
			if (resets[i]<rfl&&flag==1)
			{
				resets[i+1]=resets[i];
				resets[i]=rfl;
				flag=2;
				i++;
			}
			if (resets[i]<(rfl-rfp+cr-delta)&&flag==2)
			{
				resets[i+1]=resets[i];
				resets[i]=rfl-rfp+cr-delta;
				flag=3;
				i++;
			}
			/*
				if (resets[i]>(rfl-rfp+cr-delta)&&flag==TRUE)
					i--;
			*/
			if (resets[i]==resets[i-1])
				i--;
			i++;
		}
		resets[0]=sw;
		numresets=i;
		resets[numresets]=hzpp;
	}

	disp_status(" ");
	return(COMPLETE);
}
Ejemplo n.º 20
0
void fn_version(char **args)
{
	disp_status(DISP_STATUS, "%s", version);
}
Ejemplo n.º 21
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;
}
Ejemplo n.º 22
0
void
fn_isearch(char **args)
{

    char b[1024], *p;
    int n, c, start, current, research, state, wrap;

    state = 0;

    if (args && strcmp(args[0], "-r") == 0) {
	state = FN_IS_BACK;
    }
    
    b[0] = '\0';
    p = b;
    n = 0;

    start = current = list->cur;

    while ((c=aux_isread(state, b)) != '\n' && c != 7 /* ^G */) {
	research = 1;
	if (c == tty_verase) {
	    if (p > b) {
		*(--p) = '\0';
		current = start;
		state &= ~FN_IS_WRAP;
	    }
	    else
		research = 0;
	}
	else if (c == tty_vwerase) {
	    while (p>b && *(--p) == ' ')
		;
	    while (p>b && *(p-1) != ' ')
		--p;

	    *p = '\0';

	    current = start;
	    state &= ~FN_IS_WRAP;
	}
	else if (c == tty_vkill) {
	    p = b;
	    *p = '\0';
	    
	    current = start;
	    state &= ~FN_IS_WRAP;
	}
	else if (c == 19 /* ^S */) {
	    if ((state & FN_IS_FAIL) && !(state & FN_IS_BACK))
		state |= FN_IS_WRAP;
	    state &= ~FN_IS_BACK;
	    research = 2;
	}
	else if (c == 18 /* ^R */) {
	    if ((state & FN_IS_FAIL) && (state & FN_IS_BACK))
		state |= FN_IS_WRAP;
	    state |= FN_IS_BACK;
	    research = 2;
	}
	else if (c == 12 /* ^L */) {
	    disp_redraw();
	    research = 0;
	}
	else if (c >= 32 && c < 127) {
	    *(p++) = c;
	    *p = '\0';
	}
	else {
	    loop_putkey(c);
	    return;
	}

	if (research) {
	    n = current;
	    state &= ~FN_IS_FAIL;
	    
	    if (!(state & FN_IS_BACK)) {
		if (research == 2)
		    n++;

		wrap = 0;
		while (!(state & FN_IS_FAIL)) {
		    if (wrap && n == current+1) {
			state |= FN_IS_FAIL;
			break;
		    }
		    if (n >= list->len) {
			if (state & FN_IS_WRAP) {
			    wrap = 1;
			    n = 0;
			}
			else {
			    state |= FN_IS_FAIL;
			    break;
			}
		    }
		    if (strstr(LIST_LINE(list, n)->name, b) != NULL)
			break;
		    n++;
		}
	    }
	    else {
		if (research == 2)
		    --n;

		wrap = 0;
		while (!(state & FN_IS_FAIL)) {
		    if (wrap && n == current-1) {
			state |= FN_IS_FAIL;
			break;
		    }
		    if (n < 0) {
			if (state & FN_IS_WRAP) {
			    n = list->len-1;
			    wrap = 1;
			}
			else {
			    state |= FN_IS_FAIL;
			    break;
			}
		    }
		    if (strstr(LIST_LINE(list, n)->name, b) != NULL)
			break;
		    --n;
		}
	    }
	}
	if (!(state & FN_IS_FAIL)) {
	    current = n;
	    if (current >= list->top && current < list->top+win_lines)
		aux_scroll(list->top, current, 0);
	    else
		aux_scroll(current-(win_lines/2), current, 0);
	}
    }
    if (c == 7 /* ^G */) {
	if (start >= list->top && start < list->top+win_lines)
	    aux_scroll(list->top, start, 0);
	else
	    aux_scroll(start-(win_lines/2), start, 0);
    }

    disp_status(DISP_STATUS, "");
    
    return;
}