Пример #1
0
int hpa(int argc, char *argv[], int retc, char *retv[])
/*************/
{
  double plotchar = 0.6;

  (void) argc;
  (void) argv;
  (void) retc;
  (void) retv;
  if (setplotter()) return(ERROR);
  if (raster)
  {
    Werrprintf("hpa is not supported on raster plotters");
    return(COMPLETE);
  }
  charsize(plotchar);
  color(GREEN);
  if (debug1)
    Wscrprintf("ppmm= %g ymultiplier= %d plot= %d raster= %d, mnumxpnts= %d\n",
                ppmm,ymultiplier,plot,raster,mnumxpnts);

/*  Copy the display parameters from the current group to the
    processed group so the current values will be plotted.	*/

  P_copygroup( CURRENT, PROCESSED, G_DISPLAY );

  plotparam("tn",      COL1,   ROW1, 6,0);
  plotparam("sw",      COL1,   ROW2, 8,1);
  plotparam("at",      COL1,   ROW3, 8,3);
  plotparam("pw",      COL1,   ROW4, 8,1);
  plotparam("sfrq",    COL2,   ROW1, 8,4);
  plotparam("tof",     COL2,   ROW2, 8,1);
  plotparam("d1",      COL2,   ROW3, 8,3);
  plotparam("ct",      COL2+2, ROW4, 8,0);
  plotparam("dn",      COL3,   ROW1, 6,0);
  plotparam("dm",      COL3,   ROW2, 6,0);
  plotparam("dmm",     COL3+7, ROW3, 6,0);
  plotparam("pp",      COL3,   ROW4, 8,1);
  plotparam("dof",     COL4,   ROW1, 8,1);
  plotparam("dlp",     COL4,   ROW2, 8,0);
  plotparam("dmf",     COL4,   ROW3, 8,0);
  plotparam("dpwr",    COL4,   ROW4, 8,0);
  plotparam("fn",      COL5,   ROW1, 8,0);
  plotparam("lb",      COL5,   ROW2, 8,3);
  plotparam("wp",      COL5+2, ROW3, 8,1);
  plotparam("gf",      COL6,   ROW2, 8,3);
  plotparam("sp",      COL7-6, ROW3, 8,1);
  plotparam("seqfil",  COL8,   ROW1, 6,0);
  plotparam("temp",    COL8-2, ROW3, 8,1);
  plotparam("solvent", COL8,   ROW4, 8,0);
  plotparam("file",    COL9,   ROW2, 8,0);
  plotparam("date",    COL9,   ROW3, 8,0);
  plotparam("h1freq",  COL9,   ROW4, 6,0);
  plottext(295,ROW2);
  endgraphics();
  return(COMPLETE);
}
Пример #2
0
static int fiddisp(int local_color, int do_ww)
/****************/
{
    int erase;
    int vmin = 1;
    int vmax = mnumypnts - 3;
    getVLimit(&vmin, &vmax);

    if (debug1)
    {
        Wscrprintf("starting fid display\n");
        Wscrprintf("fpnt=%d, npnt=%d, mnumxpnts=%d, dispcalib=%g\n",
                   fpnt,npnt,mnumxpnts,dispcalib);
    }
    erase = 0;
    fid_ybars(spectrum+(fpnt * 2),(double) (vs * scale),dfpnt,dnpnt,npnt,
              dfpnt2 + (int)(dispcalib * (vp + wc2/2.0)),spec_index,dotflag);
    if (do_ww)
        whitewash(outindex(spec_index),dfpnt,dnpnt);
    displayspec(dfpnt,dnpnt,0,&spec_index,&spec_index,&erase,vmax,vmin,local_color);
    return(COMPLETE);
}
Пример #3
0
static int calc_fid(int trace)
/****************/
{   float datamax;

    if (debug1) Wscrprintf("function calc_fid\n");
    if ((spectrum = get_one_fid(trace,&fn,&c_block, FALSE)) == 0) return(ERROR);
    c_buffer = trace;
    c_first  = trace;
    c_last   = trace;
    if (normflag)
    {
        maxfloat(spectrum,pointsperspec / 2, &datamax);
        scale = (float) dispcalib / datamax;
        if (debug1)
            Wscrprintf("datamax=%g ", datamax);
    }
    else
        scale = (float) dispcalib / CALIB;
    if (debug1)
        Wscrprintf("normflag= %d scale=%g\n", normflag, scale);
    return(COMPLETE);
}
Пример #4
0
static void RshowTval(Tval *t)
{   Wscrprintf("   size      = %d\n",t->size);
    Wscrprintf("   basicType = ");
    switch (t->basicType)
    { case T_UNDEF:	Wscrprintf("UNDEFINED\n");
			break;
      case T_REAL:	Wscrprintf("REAL\n");
			break;
      case T_STRING:	Wscrprintf("STRING\n");
			break;
      default:		Wscrprintf("unknown (=%d)\n",t->basicType);
			break;
    }
}
Пример #5
0
static zerobuffs()
/****************/
/* zero the sorting buffers */
{ register int i;
  if (debug1) Wscrprintf("zerobuffs\n");
  if ((plbuff = (struct plotbuffentry *) allocateWithId(PLOTBUFFARRAY *
			      sizeof(struct plotbuffentry),"dpcon"))==0)
    { Werrprintf("cannot allocate plot sorting buffer");
      ABORT;
    }
  if ((indxbuff = (struct indxentry *) allocateWithId(INDXBUFFARRAY *
		              sizeof(struct indxentry),"dpcon")) == 0)
    { Werrprintf("cannot allocate plot sorting buffer");
      ABORT;
    }
  for (i=0; i<PLOTBUFFARRAY; i++)
    plbuff[i].next = 0;
  for (i=0; i<INDXBUFFARRAY; i++)
    indxbuff[i].otherendoflink = indxbuff[i].xsave =indxbuff[i].ysave = 0;
  numberfilled = indxnumber = lastpbindx = lastindx = 0;
  RETURN;
}
Пример #6
0
static void plotparam(char *paramname, int xpos, int ypos, int length, int digits)
/***************************************/
/* display parameter with paramname at specified x-y position */
{
   char t[MAXPATHL];
   int tree;

    xpos = (int) ( xpos * ppmm * wcmax / 400.0);
    tree = (strcmp(paramname,"h1freq")==0) ? SYSTEMGLOBAL : PROCESSED;
    getdstring(paramname,t,length,digits,tree,1);
    if ((strcmp(paramname,"file") == 0) &&
	(strrchr( &t[ 0 ], DIRTERMCHAR ) != NULL))
      fixfilename(t); 
    if (strcmp(t,"undefined")==0)
      strcpy(t,"---");
    if (xpos + ((int) strlen(t)+1) * xcharpixels > mnumxpnts)
      xpos = mnumxpnts - (strlen(t)+1) * xcharpixels;
    if (debug1)
	Wscrprintf("param %s is %s\n",paramname,t);
    amove(xpos,(int)(ypos*ppmm/ymultiplier));
    dstring(t);
}
Пример #7
0
static void RshowRvals(int b, Rval *r)
{   if (r)
    {	int   i;

	i = 1;
	while (r)
	{   Wscrprintf("[%d] = ",i);   
	    switch (b)
	    { case T_UNDEF:	Wscrprintf("undef\n");
				break;
	      case T_REAL:	Wscrprintf("%g\n",r->v.r);
				break;
	      case T_STRING:	Wscrprintf("\"%s\"\n",r->v.s);
				break;
	      default:		Wscrprintf("unknown (=%d)\n",b);
				break;
	    }
	    i += 1;
	    r  = r->next;
	}
    }
    else
	Wscrprintf("   ** no values **\n");
}
Пример #8
0
static int getlines(int noneg)
/*******************/
{
  vInfo  info;
  double freq;
  double amp;
  double tmpfrq;
  int    tmppos;
  int    r;
  int    index;
  int    count=0;

  if ( (r=P_getVarInfo(CURRENT,"llfrq",&info)) )
  { P_err(r,"llfrq",":");   return ERROR; }
  if (info.size >= 1)
  {
    if ((linefrq = (double *)
                   allocateWithId(sizeof(double)*(info.size + 1),"dpf"))==0)
    { Werrprintf("cannot allocate buffer space");
      return(0);
    }
    if ((lineamp = (double *)
                   allocateWithId(sizeof(double)*(info.size + 1),"dpf"))==0)
    { Werrprintf("cannot allocate buffer space");
      release(linefrq);
      return(0);
    }
    if ((linepos = (int *)
                   allocateWithId(sizeof(int)*(info.size + 1),"dpf"))==0)
    { Werrprintf("cannot allocate buffer space");
      release(linefrq);
      release(lineamp);
      return(0);
    }
    if (debug1)
      Wscrprintf("line      freq       amp       position\n");
    for (index = 1; index <= info.size; index++)
    {
      if ( (r=P_getreal(CURRENT,"llfrq",&freq,index)) )
      { P_err(r,"llfrq",":");   return ERROR; }
      tmpfrq = freq - rflrfp;
      tmppos = dfpnt  + dnpnt  * (wp  - tmpfrq  + sp ) / wp;
      if ( (r=P_getreal(CURRENT,"llamp",&amp,index)) )
      { P_err(r,"llamp",":");   return ERROR; }
      if (tmppos > dfpnt && tmppos < dfpnt+dnpnt && (amp >= 0 || !noneg))
      {
	count++;
        linefrq[count] = tmpfrq;
        linepos[count] = tmppos;
        if (amp < 0.0)
          amp = 0.0;
        lineamp[count] = amp * scale;
        if (debug1)
          Wscrprintf("%d   %g   %g   %d\n",
                  count,linefrq[count],lineamp[count],linepos[count]);
      }
    }
    return(count);
  }
  else
    return(0); 
}
Пример #9
0
int cmdHistory(int argc, char *argv[], int retc, char *retv[])
{
   char path[MAXPATH];

   if (argc == 1)
   {
      if (globalCmdHistory)
         sprintf(path,"%s/cmdHistory",userdir);
      if (retc)
      {
         retv[0] = (globalCmdHistory) ? newString("") : newString(path);
         if (retc > 1)
            retv[1] = (localCmdHistory) ? newString("") : newString(localCmdHistoryPath);
      }
      else
         Winfoprintf("Global history is %s. Local history is %s",
            (globalCmdHistory) ? path : "off",
            (localCmdHistory) ? localCmdHistoryPath : "off");
      doThisCmdHistory = 0;
      RETURN;
   }
   if (Bnmr)
      RETURN;
   if (argc == 2) /* This handles global cmdHistory and the 'skip' case */
   {
      if ( ! strcmp(argv[1],"on") ) /* write to global cmdHistory */
      {
         if (globalCmdHistory == NULL)
         {
            sprintf(path,"%s/cmdHistory",userdir);
            globalCmdHistory = fopen(path,"w");
         }
         doCmdHistory = 1;
         doThisCmdHistory = 0;
      }
      else if ( ! strcmp(argv[1],"append") ) /* append to global cmdHistory */
      {
         if (globalCmdHistory == NULL)
         {
            sprintf(path,"%s/cmdHistory",userdir);
            globalCmdHistory = fopen(path,"a");
         }
         doCmdHistory = 1;
         doThisCmdHistory = 0;
      }
      else if ( ! strcmp(argv[1],"off") )
      {
         if (globalCmdHistory)
         {
            fclose(globalCmdHistory);
            globalCmdHistory = NULL;
         }
         if ( ! localCmdHistory)
            doCmdHistory = 0;
         doThisCmdHistory = 0;
      }
      else if ( ! strcmp(argv[1],"skip") )  /* allow macros to avoid being added to the history */
      {
         doThisCmdHistory = 0;
      }
      else
      {
         Wscrprintf("%s usage error: %s unknown argument",argv[0], argv[1]);
      }
   }
   else if (argc == 3) /* This handles local cmdHistory */
   {
      if ( ! strcmp(argv[1],"on") )
      {
         if ( localCmdHistory )
            fclose(localCmdHistory);
         localCmdHistory = fopen(argv[2],"w");
         if ( localCmdHistory )
         {
            doCmdHistory = 1;
            doThisCmdHistory = 0;
            strcpy(localCmdHistoryPath,argv[2]);
         }
         else
         {
            Werrprintf("%s failed to open command history file %s",argv[0], argv[2]);
         }
      }
      else if ( ! strcmp(argv[1],"append") )
      {
         if ( localCmdHistory )
            fclose(localCmdHistory);
         localCmdHistory = fopen(argv[2],"a");
         if ( localCmdHistory )
         {
            doCmdHistory = 1;
            doThisCmdHistory = 0;
            strcpy(localCmdHistoryPath,argv[2]);
         }
         else
         {
            Werrprintf("%s failed to open command history file %s",argv[0], argv[2]);
         }
      }
      else if ( ! strcmp(argv[1],"off") )
      {
         if (localCmdHistory)
            fclose(localCmdHistory);
         localCmdHistory = NULL;
         if ( ! globalCmdHistory)
            doCmdHistory = 0;
         doThisCmdHistory = 0;
      }
      else
      {
         Wscrprintf("%s usage error: %s unknown argument",argv[0], argv[1]);
      }
   }
   else
   {
      Wscrprintf("%s usage error: too many arguments",argv[0]);
   }
   RETURN;
}
Пример #10
0
/*-----------------------------------------------
|						|
|		AP_bootup_msg()			|
|						|
|   This is merely a message line to be gen-	|
|   erated (conditionally) in bootup.c.  By	|
|   putting the message here (sky.c), sky.c is	|
|   now the only source code file which uses	|
|   the "AP" conditional compile flag, thus	|
|   simplifying maintenance.			|
|						|
+----------------------------------------------*/
void AP_bootup_msg()
{
#ifdef AP
   Wscrprintf( "              Version for Sky Array Processor\n");
#endif 
}
Пример #11
0
int splmodprepare(int argc, char *argv[], int retc, char *retv[])

{
	/*Declarations*/
/*{{{*/
	int		i,j,l,lr,					/*standard iterators*/	
			bd[MAXPOINTS],				/*array for amplitude levels deleted from analysis (prune)*/
			badinc,						/*number of pruned levels*/
			nPeaks,						/*number of peaks*/
			ncomp,					/*max number of components for the fit*/
			dosyversion,					/*version number*/
			mfit,						/*obsolete - for HR-DOSY fitting in dosyfit*/
			calibflag,					/*obsolete - here for historical reasons*/
			nugflag,					/*whether to use pure exponentials or corrected*/
			badflag,					/*for removing data from pruned amplitudes*/
			mtry,						/*number of starting values for each D*/
			nugsize,					/*length of array nugcal_*/
			nPoints;					/*number of points per peak (amplitude levels)*/

	char	rubbish[MAXLENGTH], 		/* string for various purposes*/
			jstr[MAXLENGTH]; 			/* string for various purposes*/

	double	dosyconstant,				/*calculated from the pulse sequence */
			gcal_,			/*conversion factor from DAC points to Gauss - from nugcal_*/
			gcal__conv,			/*conversion factor from DAC points to Gauss - to convert gradAmp using nugcal_*/
			gradAmp[MAXPOINTS],					/*gradient amplitudes */
			frq[MAXPEAKS],						/*frequencies for each peak */
			ampl[MAXPOINTS],						/*amplitudes for each peak */
			nnl_splmod,					/*SPLMOD parameter - number of analyses for each data set*/
			tmp,					/*for temporary usage*/
			ngam_splmod,				/*SPLMOD parameter - value of background (baseline)*/
			iwt_splmod,					/*SPLMOD parameter - statistical weighting*/
			nerfit_splmod,				/*SPLMOD parameter - for statistical weighting*/
			plmnmx_1_splmod,			/*SPLMOD parameter - minimum peak amplitude*/
			plmnmx_2_splmod,			/*SPLMOD parameter - maximum peak amplitude*/
			pnmnmx_1_splmod,			/*SPLMOD parameter - controls minimum D */
			pnmnmx_2_splmod,			/*SPLMOD parameter - controls maximum D */
			nug[MAXFITCOEFFS+1];			/*coefficients for NUG correction*/

	FILE 	*in,						/*for dosy_in file*/
		*splmodin;				/*for splmod.in format*/	

#ifdef DEBUG_SPLMOD
	FILE 	*debug;
#endif


/*}}}*/

/* Setting some flags to default values */
	/*{{{*/
/*}}}*/
	

#ifdef DEBUG_SPLMOD
	//strcpy(rubbish,userdir);
	strcpy(rubbish,curexpdir);
	strcat(rubbish,"/dosy/debug_splmodprepare");
	debug =fopen(rubbish,"w");		/* file for debugging information */
	fprintf(debug,"Start of splmodprepare\n");
	fprintf(debug,"Before reading in of data\n");
#endif



	
	/*Read data from dosy_in*/
/*{{{*/
	//strcpy(rubbish,userdir);
	strcpy(rubbish,curexpdir);
	strcat(rubbish,"/dosy/dosy_in");
	in = fopen(rubbish,"r");		/* input file for 2D DOSY */
	if (!in) { 
		Werrprintf("splmodprepare: could not open file %s",rubbish);
		return(ERROR);
	}

	//strcpy(rubbish,userdir);
	strcpy(rubbish,curexpdir);
	strcat(rubbish,"/dosy/dosy_splmod.in");
	splmodin = fopen(rubbish,"w");	/*  output - input for splmod */
	if (!splmodin) {
		Werrprintf("splmodprepare: could not open file %s",rubbish);
		fclose(in);
		return(ERROR);
	}


	strcpy(jstr,curexpdir);
	strcat(jstr,"/dosy/dosy_in");
	if (fscanf(in,"DOSY version %d\n",&dosyversion) == EOF)
	{
		Werrprintf("splmodprepare: reached end of file %s", jstr);
		fclose(in);
		fclose(splmodin);
		return(ERROR);
	}
	if (fscanf(in,"%d spectra will be deleted from the analysis :\n",&badinc) == EOF) {
		Werrprintf("splmodprepare: reached end of file %s", jstr);
		fclose(in);
		fclose(splmodin);
		return(ERROR);
	}
	for (i=0;i<badinc;i++) {
		if (fscanf(in,"%d\n",&bd[i]) == EOF) {
			Werrprintf("splmodprepare: reached end of file %s", jstr);
		fclose(in);
		fclose(splmodin);
			return(ERROR);
		}
	}

	if ((fscanf(in,"Analysis on %d peaks\n",&nPeaks) == EOF) /* read in calibration parameters */
		|| (fscanf(in,"%d points per peaks\n",&nPoints) == EOF)
		|| (fscanf(in,"%d parameters fit\n",&mfit) == EOF)
		|| (fscanf(in,"dosyconstant = %lf\n",&dosyconstant) == EOF)
		|| (fscanf(in,"gradient calibration flag :  %d\n",&calibflag) == EOF))
	{
		Werrprintf("splmodprepare: reached end of file %s", jstr);
		fclose(in);
		fclose(splmodin);
		return(ERROR);
	}
	calibflag=0; /*obsolete*/

	
/*}}}*/
#ifdef DEBUG_SPLMOD
	fprintf(debug,"Before reading in of parameters from Vnmr\n");
#endif

	/*Read in parameters from Vnmr */
/*{{{*/

 /* MN2Mar Reading in ncomp - number of components to be fixed (i.e ncomp=2 is a biexponential fit */
ncomp=1;
  if (!P_getreal (CURRENT, "ncomp", &tmp, 1))
    {
	 ncomp = (int) (tmp + 0.5);
      if (ncomp < 1) 
	ncomp = 1;
    }
/* fetching nugflag as a parameter */
			for(i=0;i<=MAXFITCOEFFS;i++)
                                        nug[i]=0.0;
                        nugflag=0;
                        if (!P_getstring(CURRENT, "nugflag",rubbish,1,2)) {
                                if (!strcmp("y",rubbish)) {
                                        nugflag=1;
                                }
                                else {
                                        nugflag=0;
                                }
                        }
                        if(nugflag){
                                P_getsize(CURRENT,"nugcal_",&nugsize);
                                if (nugsize>5) nugsize=5;
                                if (nugsize<2){
                                        Wscrprintf("splmodread: nugcal_ must contain at least 2 values");
                                        Werrprintf("splmodread: nugcal_ must contain at least 2 values");
			 		fclose(in);
			 		fclose(splmodin);
                                        return(ERROR);
                                        }
                                if (P_getreal(CURRENT, "nugcal_", &gcal_, 1))
                                        {
                                        Werrprintf("splmodread: cannot read gcal_ from nugcal_");
                                        Wscrprintf("splmodread: cannot read gcal_ from nugcal_");
			 		fclose(in);
			 		fclose(splmodin);
                                        return(ERROR);
                                        }
                         for (i=1;i<nugsize;i++){
                                        if (P_getreal(CURRENT, "nugcal_", &nug[i], i+1))
                                                {
                                                Werrprintf("splmodread: cannot read coefficients from nugcal_");
                                                Wscrprintf("splmodread: cannot read coefficients from nugcal_");
			 			fclose(in);
			 			fclose(splmodin);
                                                return(ERROR);
                                                }
                                        }
#ifdef DEBUG_SPLMOD
                                        fprintf(debug,"nugsize:  %d\n",nugsize);
                                        fprintf(debug,"gcal_ %e :\n",gcal_);
                                        for (i=0;i<MAXFITCOEFFS;i++)
                                        fprintf(debug,"nug %e :\n",nug[i+1]);
                                        fprintf(debug,"ncomp:  %d\n",ncomp);
#endif
                        }















	
/*}}}*/


/* Check for sensible values of n and np */
/*{{{*/
	if (nPeaks > MAXPEAKS)
	{
		fprintf(splmodin,"Too many peaks for the analysis !\n");
		Werrprintf("splmodprepare: Too many peaks for the analysis !\n");
		fclose(in);
		fclose(splmodin);
		return(ERROR);
	}
	if (nPoints > MAXPOINTS)
	{
		Werrprintf("splmodprepare: Too many increments for analysis, max. nunmber of gzlvl1 is %d\n", MAXPOINTS);
		fclose(in);
		fclose(splmodin);
		return(ERROR);
	}/*}}}*/

	

	/*Read in gradient amplitudes values from file*/

	for (i=0,j=0;i<(nPoints+badinc);i++){         /*scan through all the input values, discarding the unwanted ones */ 
		badflag = 0;
		for (l=0;l<badinc;l++)  if (i == bd[l]-1) badflag = TRUE;
		strcpy(jstr,curexpdir);
		strcat(jstr,"/dosy/dosy_in"); /* read in gradient array */
		if (badflag) {
			if (fscanf(in,"%s",rubbish) == EOF) {
				Werrprintf("splmodprepare: reached end of file %s on increment %d", jstr, i);
		fclose(in);
		fclose(splmodin);
				return(ERROR);
			}
		}
		else     {
			if (fscanf(in,"%lf",&gradAmp[j]) == EOF) {
				Werrprintf("splmodprepare: reached end of file %s on increment %d", jstr, i);
		fclose(in);
		fclose(splmodin);
				return(ERROR);
			}
			j++; 
		}
	}
/* MN11Feb08 if NUG is used, we need to correct the gradAmp values for the (potentially) different gcal_
if (P_getreal (CURRENT, "gcal_", &gcal__orig, 1))
    {
      Werrprintf ("Error accessing parameter gcal_\n");
      fclosetest (in);
      fclose(splmodin);
      return (ERROR);
    }
if (nugflag){
  gcal__conv = gcal_/gcal__orig;
}
else{
  gcal__conv = 1.0;
}
	for (i=0;i<nPoints;i++){       
	gradAmp[i]=gradAmp[i]*gcal__conv;
}

*/

  gcal__conv = 1.0;

	/*Read in frequencies from dosy_in*/
/*{{{*/
		strcpy(jstr,curexpdir);
		strcat(jstr,"/dosy/dosy_in"); 
		if (fscanf(in,"%s",rubbish) == EOF) {
			Werrprintf("splmodprepare: reached end of file %s", jstr);
		fclose(in);
		fclose(splmodin);
			return(ERROR);
		}
		while (strcmp(rubbish,"(Hz)") != 0)
			if (fscanf(in,"%s",rubbish) == EOF) {
				Werrprintf("splmodprepare: reached end of file %s", jstr);
		fclose(in);
		fclose(splmodin);
				return(ERROR);
			}
		for (i=0;i<nPeaks;i++)
			if ((fscanf(in,"%s",rubbish) == EOF) || (fscanf(in,"%lf",&frq[i]) == EOF)) {
				Werrprintf("splmodprepare: reached end of file %s", jstr);
		fclose(in);
		fclose(splmodin);
				return(ERROR);
			}
/*}}}*/


	/* Loop over resonances begins */
		
	for (lr=0;lr<nPeaks;lr++){					

 			/* read in amplitudes from dosy_in */
/*{{{*/
			if (lr == 0)       {
				if (fscanf(in,"%s",rubbish) == EOF) {
					Werrprintf("splmodprepare: reached end of file %s", jstr);
		fclose(in);
		fclose(splmodin);
					return(ERROR);
				}
				while(strcmp(rubbish,"(mm)") != 0) {
					if (fscanf(in,"%s",rubbish) == EOF) {
						Werrprintf("splmodprepare: reached end of file %s", jstr);
		fclose(in);
		fclose(splmodin);
						return(ERROR);
					}
				}
			}        

		
			for (i=0,j=0;i<(nPoints+badinc);i++) {
				badflag = 0;
				for (l=0;l<badinc;l++)         if (i == bd[l]-1) badflag = 1;
				fscanf(in,"%s",rubbish);
				fscanf(in,"%s",rubbish);
				if (badflag)	fscanf(in,"%s",rubbish);
				else		fscanf(in,"%lf",&ampl[j++]);
			}


/*}}}*/	
			/*Testing some parameters*/
		nnl_splmod=(double) ncomp;							/*max number of components per decay*/	
		ngam_splmod=0.0;							/*assume base line corrected*/
		iwt_splmod=1.0;								/*all points have the same statistical weight*/	
		nerfit_splmod=0.0;							/*must be 0 if iwt is 1*/	
		plmnmx_1_splmod=0.0;						/*minimum amplitude - non negativity*/	
		plmnmx_2_splmod=5.0;						/*maximum amplitude value - 5 times the max y value*/	
		pnmnmx_1_splmod=2.0e-2;						/*default value*/	
		pnmnmx_2_splmod=2.08;						/*default value*/	
		pnmnmx_1_splmod=0.002;                                          /* conservative value */
		pnmnmx_2_splmod=3.0;                                            /* conservative value */
		mtry=20;									/*number of starting values for each D*/	
		
		fprintf(splmodin," ***DOSY EXPERIMENT*** peak number %d   at %lf Hz\n",(lr+1),frq[lr]);
		fprintf(splmodin," NNL       %d    %1.1f\n",0,nnl_splmod);
		fprintf(splmodin," NGAM      %d    %1.1f\n",0,ngam_splmod);
		fprintf(splmodin," IWT       %d    %1.1f\n",0,iwt_splmod);
		fprintf(splmodin," NERFIT    %d    %1.1f\n",0,nerfit_splmod);
		fprintf(splmodin," CONVRG    %d    %1.1E\n",1,5e-7);
		fprintf(splmodin," DOSPL\nFFFFFFFFFFFFFFFFFFFF\n");				/*use exact model - no bsplines */
		fprintf(splmodin," MTRY\n");									/*number of starting values for each D*/	
		for (i=1;i<=20;i++){
			fprintf(splmodin," %3d",mtry);
		}
		fprintf(splmodin," \n");	
		fprintf(splmodin," PLMNMX    %d    %1.1E\n",1,plmnmx_1_splmod);
		fprintf(splmodin," PLMNMX    %d    %1.1E\n",2,plmnmx_2_splmod);
		fprintf(splmodin," PNMNMX    %d    %1.1E\n",1,pnmnmx_1_splmod);
		fprintf(splmodin," PNMNMX    %d    %1.1E\n",2,pnmnmx_2_splmod);
		fprintf(splmodin," MXITER    %d    %3.1f\n",1,2000.0);
		fprintf(splmodin," MXITER    %d    %3.1f\n",2,4000.0);
		fprintf(splmodin," IFORMY\n (1E11.5)\n");
		fprintf(splmodin," IFORMT\n (1E11.5)\n");
		if (nugflag){
			fprintf(splmodin," RUSER     %d    %1.4E\n",1,nug[1]);	
			fprintf(splmodin," RUSER     %d    %1.4E\n",2,nug[2]);
			fprintf(splmodin," RUSER     %d    %1.4E\n",3,nug[3]);
			fprintf(splmodin," RUSER     %d    %1.4E\n",4,nug[4]);
		}
		fprintf(splmodin," IUSER     %d    %1.1f\n",1,1.0);	
		fprintf(splmodin," IPRITR    %d    %1.1f\n",1,0.0);	
		fprintf(splmodin," IPRITR    %d    %1.1f\n",2,0.0);	
		fprintf(splmodin," IPLFIT    %d    %1.1f\n",1,0.0);	
		fprintf(splmodin," IPLFIT    %d    %1.1f\n",2,0.0);	
		fprintf(splmodin," IPLRES    %d    %1.1f\n",1,1.0);	
		fprintf(splmodin," IPLRES    %d    %1.1f\n",2,1.0);	
		if (lr==(nPeaks-1)){
			fprintf(splmodin," LAST      %d    %1.1f\n",0,1.0);			
		}else{
			fprintf(splmodin," LAST      %d    %1.1f\n",0,-1.0);		
		}
		fprintf(splmodin," END\n");	
		if (nPoints<10){				/*for right justify*/
			fprintf(splmodin," NY        %d\n",nPoints);		
		}else if (nPoints<100){
			fprintf(splmodin," NY       %d\n",nPoints);		
		}else{
			fprintf(splmodin," NY      %d\n",nPoints);		
		}
		for (i=0;i<nPoints;i++){
			fprintf(splmodin," %10.4E\n",(gradAmp[i]*gradAmp[i]));	
		}


		for (i=0;i<nPoints;i++){
			fprintf(splmodin," %10.4E\n",ampl[i]);	
		}


	}
			
#ifdef DEBUG_SPLMOD
	fprintf(debug,"End of splmodprepare\n");
	fclose(debug);
#endif

	fclose(in);
	fclose(splmodin);

		RETURN;
}
Пример #12
0
static int getregions(int resets)
/*******************/
{
  double freq;
  double amp;
  int    r;
  int    index,groups;

  double vs1;
  double start;
  double edge;
  double norm;
  
  if ((lineamp = (double *)
              allocateWithId(sizeof(double)*(((resets + 1) / 2)+1),"dpir"))==0)
  { Werrprintf("cannot allocate buffer space");
    return(0);
  }
  if ((gb = (struct int_entry *)
          allocateWithId(sizeof(struct int_entry)*(((resets + 1) / 2)+1),"dpir"))==0)
  { Werrprintf("cannot allocate buffer space");
    release(lineamp);
    return(0);
  }

  start = sp + wp;
  edge = start;
  if (normInt)
  {
    norm = 0.0;
    if (debug1)
      Wscrprintf("integral normalization\n");
    for (index = 1; index <= resets; index++)
    {
      if ( (r=P_getreal(CURRENT,"lifrq",&freq,index)) )
      { P_err(r,"lifrq",":");   return ERROR; }
      if (freq - rflrfp < edge )
        if (index % 2 == 0)
        {
          if ( (r=P_getreal(CURRENT,"liamp",&amp,index)) )
          { P_err(r,"liamp",":");   return ERROR; }
          norm += amp;
        }
    }
    vs1 = (norm == 0.0) ? 1.0 : insval  / norm;
  }
  else
    vs1 =  insval;
  if (vs1 == 0.0)
    vs1 = 1.0;
  if (debug1)
    Wscrprintf("scale factor= %g, liamp size= %d\n",
                vs1,resets);
  groups = 0;
  gb[1].lowlimit = dfpnt;
  for (index = 1; index <= resets; index++)
  {
    if ( (r=P_getreal(CURRENT,"lifrq",&freq,index)) )
    { P_err(r,"lifrq",":");   return ERROR; }
    freq -= rflrfp;
    if (freq < edge )
    {
      if (freq < sp)
        freq = sp;
      if ( (r=P_getreal(CURRENT,"liamp",&amp,index)) )
      { P_err(r,"liamp",":");   return ERROR; }
      if (index % 2)
        gb[groups + 1].lowlimit = dfpnt  + dnpnt  * (wp - freq + sp ) / wp;
      else
      {
        groups++;
        gb[groups].highlimit = dfpnt  + dnpnt  * (wp - freq + sp ) / wp;
        lineamp[groups] = vs1 * amp;
      }
    }
  }
  return(groups);
}
Пример #13
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);
}
Пример #14
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;
}
Пример #15
0
/*---------------------------------------
|					|
|		init_makeslice()		|
|					|
+--------------------------------------*/
static int init_makeslice(int argc, char *argv[])
{
char	path1[MAXPATHL],diffname[MAXPATHL];
short	status_mask;
int	i;
FILE	*diffusion_file;
double	integ_step;
extern	int	read_peak_file(/*peak_table,filename*/);


#ifdef DEBUG_MAKESLICE
  strcpy (rubbish, curexpdir);
  strcat (rubbish, "/dosy/debug_makeslice");
  debug = fopen (rubbish, "a"); /* file for debugging information */
  fprintf (debug, "At start of init_makeslice\n");
  fclose(debug);
#endif
if (
   P_getreal(PROCESSED,"fn",&fn,1)	||
   P_getreal(CURRENT,"sw",&sw,1)	||
   P_getreal(PROCESSED,"fn1",&fn1,1)	||
   P_getreal(CURRENT,"sw1",&sw1,1)
   )
		{
                Werrprintf("makeslice: Error accessing parameters\n");
                return(ERROR);
                }
/* PB: The following lines have been added to check the number of arguments to makeslice */
#ifdef DEBUG_MAKESLICE
  strcpy (rubbish, curexpdir);
  strcat (rubbish, "/dosy/debug_makeslice");
  debug = fopen (rubbish, "a"); /* file for debugging information */
  fprintf (debug, "fn = %f\n",fn);
  fprintf (debug, "sw = %f\n",sw);
  fprintf (debug, "fn1 = %f\n",fn);
  fprintf (debug, "sw1 = %f\n",sw1);
  fprintf (debug, "After reading parameters in init_makeslice\n");
  fclose(debug);
#endif

if((argc<3)||(argc>4)){
		Werrprintf("makeslice: incorrect number of arguments \n");
		Werrprintf("makeslice('<mode>(optional)',start,finish)\n");
                return(ERROR);
		}
if(argc==3) {
		display_mode='i'; 
		start_diff = atof(argv[1]);
		finish_diff = atof(argv[2]);
	}	

else {
	if((argv[1][0]!='i')&&(argv[1][0]!='s')){
		Werrprintf("makeslice: if 'mode' is specified, it must be supplied as first argument!");
		return(ERROR);
		}
		display_mode = argv[1][0];
		start_diff = atof(argv[2]);
		finish_diff = atof(argv[3]);
	}

if(start_diff>finish_diff) swap(&start_diff,&finish_diff);
mean_diff = 0.5*(start_diff+finish_diff);
diff_window = finish_diff-start_diff;


/* initialise the data files in the present experiment ... */
if ( (r = D_gethead(D_DATAFILE, &fidhead)) )
	{
      	if (r == D_NOTOPEN)
      		{
/*		Wscrprintf("spectrum had to be re-opened?\n"); */
         	strcpy(path1, curexpdir);
         	strcat(path1, "/datdir/data");
         	r = D_open(D_DATAFILE, path1, &fidhead); /* open the file */
      		}
      	if (r)
      		{
         	D_error(r);
 	        return(ERROR);
      		}
  	}

#ifdef DEBUG_MAKESLICE
  strcpy (rubbish, curexpdir);
  strcat (rubbish, "/dosy/debug_makeslice");
  debug = fopen (rubbish, "a"); /* file for debugging information */
  fprintf (debug, "After reading header in init_makeslice\n");
  fclose(debug);
#endif
f1pts=1;
status_mask = (S_COMPLEX);
if ((fidhead.status & status_mask) == status_mask ) f1pts=2;
status_mask = (S_HYPERCOMPLEX);
if ((fidhead.status & status_mask) == status_mask ) f1pts=4;
status_mask = (S_DATA|S_SPEC|S_FLOAT|S_SECND);
if ( (fidhead.status & status_mask) != status_mask )
	{
#ifdef DEBUG_MAKESLICE
  strcpy (rubbish, curexpdir);
  strcat (rubbish, "/dosy/debug_makeslice");
  debug = fopen (rubbish, "a"); /* file for debugging information */
  fprintf (debug, "Status is %d in init_makeslice\n",fidhead.status);
  fclose(debug);
#endif
     	Werrprintf("No 2D spectrum available, please use undosy3D or do 2D transform before using makeslice\n");
     	return(ERROR);
  	}
#ifdef DEBUG_MAKESLICE
  strcpy (rubbish, curexpdir);
  strcat (rubbish, "/dosy/debug_makeslice");
  debug = fopen (rubbish, "a"); /* file for debugging information */
  fprintf (debug, "Before initialising peak table in init_makeslice\n");
  fclose(debug);
#endif
fn_int = (int) fn;
fn1_int = (int) fn1;
/* Initialise the peak table */
strcpy(path1,curexpdir);
strcat(path1,"/ll2d/peaks.bin");
if (read_peak_file(&peak_table,path1))
	{
	Wscrprintf("makeslice: Could not read ll2d peak file !\n");
	delete_peak_table(&peak_table);
	return(ERROR);
	}

#ifdef DEBUG_MAKESLICE
  strcpy (rubbish, curexpdir);
  strcat (rubbish, "/dosy/debug_makeslice");
  debug = fopen (rubbish, "a"); /* file for debugging information */
  fprintf (debug, "Opening diffusion_display_3d.inp file in init_makeslice\n");
  fclose(debug);
#endif
peak = peak_table->head;
strcpy(diffname,curexpdir);
strcat(diffname,"/dosy/diffusion_display_3D.inp");
if ((diffusion_file=fopen(diffname,"r"))==NULL)
	{
	Werrprintf("Error opening %s file\n",diffname);
	return(ERROR);
	}
#ifdef DEBUG_MAKESLICE
  strcpy (rubbish, curexpdir);
  strcat (rubbish, "/dosy/debug_makeslice");
  debug = fopen (rubbish, "a"); /* file for debugging information */
  fprintf (debug, "Reading diffusion_display_3d.inp file in init_makeslice\n");
  fclose(debug);
#endif

/* Read in the diffusion information, and check whether peaks are in the diffusion band */
i=0;
integ_step = diff_window/(2.0*(double)NINTSTEPS);	/* the calculation is divided in NINTSTEPS steps */
/*Wscrprintf("\n\tDiffusion range visible: %.2lf +/- %.2lf\n\n",mean_diff,0.5*diff_window);*/
Wscrprintf("\n\tDiffusion range visible: from %.2lf to %.2lf (*10e-10m2s-1)\n\n",start_diff,finish_diff);
while(fscanf(diffusion_file,"%d %lf %lf\n",&pk[i].num,&pk[i].diff_coef,&pk[i].std_dev)!=EOF && i<MAXNUMPEAKS)
	{
#ifdef DEBUG_MAKESLICE
  strcpy (rubbish, curexpdir);
  strcat (rubbish, "/dosy/debug_makeslice");
  debug = fopen (rubbish, "a"); /* file for debugging information */
  fprintf (debug, "Reading peak %d in init_makeslice\n",i);
  fclose(debug);
#endif
	if (display_mode == 's')
		{
		if (within_diffusion_boundaries(i))
			{
			if (compute_integral(i,integ_step) == TRUE)	i++;
			}
		}
	else if (display_mode == 'i')
		{
		r = compute_integral(i,integ_step);
		/* If less than 1 % of intensity, then assume 0 */
        	if (pk[i].intensity >= 0.01)
               		{
		/* If at least 95 % of the intensity within, then assume 100 % */
                	if (pk[i].intensity >= 0.95) pk[i].intensity = 1.0;
                	i++;
                	}
		}
	}
if (display_mode == 's')
	{
	/* Check that the last peak IS within the slice because it does not get eliminated by the above loop */
	if (!within_diffusion_boundaries(i))
		{
		pk[i].num = 0;
		pk[i].diff_coef = 0.0;
		pk[i].std_dev = 0.0;
		}
	else if (compute_integral(i,integ_step) != TRUE)
		{
		pk[i].num = 0;
		pk[i].diff_coef = 0.0;
		pk[i].std_dev = 0.0;
		}
	}
if (display_mode == 'i')
	{
	/* Check the final peak */
	if (pk[i-1].intensity < 0.01)
		{
		pk[i-1].num = 0.0;
		pk[i-1].diff_coef = 0.0;
		pk[i-1].std_dev = 0.0;
		pk[i-1].intensity = 0.0;
		}
	}
#ifdef DEBUG_MAKESLICE
  strcpy (rubbish, curexpdir);
  strcat (rubbish, "/dosy/debug_makeslice");
  debug = fopen (rubbish, "a"); /* file for debugging information */
  fprintf (debug, "Before closing diffusion_display_3d.inp file in init_makeslice\n");
  fclose(debug);
#endif
fclose(diffusion_file);
if (i == MAXNUMPEAKS)
	{
	Wscrprintf("number of peaks reduced to %d\n",MAXNUMPEAKS);
	}
#ifdef DEBUG_MAKESLICE
  strcpy (rubbish, curexpdir);
  strcat (rubbish, "/dosy/debug_makeslice");
  debug = fopen (rubbish, "a"); /* file for debugging information */
  fprintf (debug, "After reading peak file in init_makeslice\n");
  fclose(debug);
#endif

/*   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(path1,curexpdir);
		strcat(path1,"/datdir/phasefile");
		r = D_open(D_PHASFILE,path1,&phasehead);
		}
	if (r)
		{
		D_error(r);
		return(ERROR);
		}
	}
phasehead.status = 0;
if ( (r = D_updatehead(D_PHASFILE, &phasehead)) )
	{
	D_error(r);
	Wscrprintf("PHASE updatehead\n");
	return(ERROR);
	}

return(COMPLETE);
}
Пример #16
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;
}
Пример #17
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;
}
Пример #18
0
void RshowVar(FILE *f, varInfo *v)
{   
    double maxv, minv, stepv;
    int i,pindex;
    unsigned int p;

    (void) f;
    if (v)
    {	
	RshowRvals(v->T.basicType,v->R);
	RshowTval(&(v->T));
	if(v->ET.size) /* if there are enums */
	{   Wscrprintf("Enumerals\n");
	    RshowRvals(v->T.basicType,v->E);
	}
	Wscrprintf("subtype = %s   ",whatType(v->subtype));
	Wscrprintf("active = %s  ",whatActive(v->active));
	Wscrprintf("group = %s   ",whatGroup(v->Ggroup));
	Wscrprintf("Dgroup = %d\n",v->Dgroup);
	Wscrprintf("protection = ");
	p = v->prot;
	for (i=15; i >= 0; i--)
	  Wscrprintf("%1d%c",(p >> i) & 1,(i != 0) ? ' ' : '\n');

/*  If P_MMS bit set, use maxVal, minVal, etc. fields as indicies
    into system global paramters "parmax", "parmin", etc. extracting
    the desired value from the appropriate array.                       */

        if (v->prot & P_MMS)
        {
           pindex = (int) (v->minVal+0.1);
           if (P_getreal( SYSTEMGLOBAL, "parmin", &minv, pindex ))
            minv = -1.0e+30;
           pindex = (int) (v->maxVal+0.1);
           if (P_getreal( SYSTEMGLOBAL, "parmax", &maxv, pindex ))
            maxv = 1.0e+30;
           pindex = (int) (v->step+0.1);
           if (P_getreal( SYSTEMGLOBAL, "parstep", &stepv, pindex ))
            stepv = 0.0;
	   Wscrprintf("maxVal[%d] = %1.12g   ",(int)(v->maxVal+0.1),maxv);
	   Wscrprintf("minVal[%d] = %1.12g   ",(int)(v->minVal+0.1),minv);
	   Wscrprintf("step[%d] = %1.12g\n\n",
		(int)(v->step+0.1),stepv);
	}
	else
	{
	   Wscrprintf("maxVal = %1.12g   ",v->maxVal);
	   Wscrprintf("minVal = %1.12g   ",v->minVal);
	   Wscrprintf("step = %1.12g\n\n",v->step);
	}
    }
    else
Пример #19
0
/*---------------------------------------
|                                       |
|              getfid()/5               |
|                                       |
+--------------------------------------*/
int getfid(int curfid, float *outp, ftparInfo *ftpar, dfilehead *fidhead, int *lastfid)
{
   short                *data,
                        *inp16;
   int                 *inp32;
   register int         i,
                        npx;
   int                  shift,
                        res;
   register float       *inpfloat,
                        rmult;
   register float       *tmp;
   dpointers            inblock;
   static float		xoff,
			yoff;
   int                  showMsg = 1;


/*  i_ft sets the correct values for cf and nf fields in ftpar  */

   if (curfid >= (*lastfid) || ftpar->cf > ftpar->nf)
   {
      zerofill(outp, ftpar->fn0);
   }
   else
   {
      if ( (res = D_getbuf(D_USERFILE, fidhead->nblocks,  curfid, &inblock)) )
      {
         *lastfid = curfid;
         if (ftpar->arraydim > 0)
         {
            if ( ftpar->np1 > 2*(curfid/ftpar->arraydim) )
               ftpar->np1 = 2*(curfid/ftpar->arraydim);
                                /* adjusts number of t1 points */
         }
 
         zerofill(outp, ftpar->fn0);
         D_close(D_USERFILE);

         if (*lastfid == 0)   
         {
            Werrprintf("No data in FID file");
         }
         else
         {               
            if (!acqflag)
               Winfoprintf("number of FID's used = %d", *lastfid);
         }
 
         return(COMPLETE);
      }

/************************************************************
*  Convert the data of each FID.  Check to see if FID data  *
*  are double precision or single precision and convert     *
*  appropriately.  Correct FID size for CT and scaling.     *
************************************************************/
      if (inblock.head->lpval != 0)
        ftpar->lpval = inblock.head->lpval;
/* Save this so other programs like addsub and wti can get it */
      oversamp_lp = inblock.head->lpval;
      ftpar->dspar.lvl = inblock.head->lvl;
      ftpar->dspar.tlt = inblock.head->tlt;
      ftpar->dspar.scale = inblock.head->scale;
      ftpar->dspar.ctcount = inblock.head->ctcount;

      data = (short *) (inblock.data);                        
      if (ftpar->cf > 1)
      {
         data += (ftpar->cf - 1)*ftpar->np0;
         if (ftpar->dpflag)
            data += (ftpar->cf - 1)*ftpar->np0;
      }

      if ( (ftpar->np0 - ftpar->lsfid0) > ftpar->fn0 )
         ftpar->np0 = ftpar->fn0 + ftpar->lsfid0;


      if (inblock.head->status == (S_DATA|S_FLOAT|S_COMPLEX))
      {
         inpfloat = (float *) (data);

         if (ftpar->lsfid0 < 0)
         {
            inpfloat += ftpar->np0;
            tmp = outp + ftpar->np0 - ftpar->lsfid0;
            npx = ftpar->np0;
            if ((inblock.head->ctcount > 1) || (inblock.head->scale) )
            {
               shift = 1 << abs(inblock.head->scale);
               if (inblock.head->scale < 0)
                  rmult = 1.0/(float)(shift);
               else
                  rmult = (float) shift;
               rmult /= (float)(inblock.head->ctcount);
               for (i = 0; i < npx; i++)
                  *(--tmp) = *(--inpfloat) * rmult;
            }
            else
            {
               for (i = 0; i < npx; i++)
                  *(--tmp) = *(--inpfloat);
            }

            npx = (-1)*ftpar->lsfid0;
            for (i = 0; i < npx; i++)
               *(--tmp) = 0.0;
         }
         else
         {
            inpfloat += ftpar->lsfid0;
            tmp = outp;
            npx = ftpar->np0 - ftpar->lsfid0;
            if ((inblock.head->ctcount > 1) || (inblock.head->scale) )
            {
               shift = 1 << abs(inblock.head->scale);
               if (inblock.head->scale < 0)
                  rmult = 1.0/(float)(shift);
               else
                  rmult = (float) shift;
               rmult /= (float)(inblock.head->ctcount);
               for (i = 0; i < npx; i++)
                  *tmp++ = *inpfloat++ * rmult;
            }
            else
            {
               for (i = 0; i < npx; i++)
                  *tmp++ = *inpfloat++;
            }
         }
      }
      else
      {
         if (inblock.head->ctcount == 0)
         {
            inblock.head->ctcount = 1;
            inblock.head->status = 0;
            *lastfid = curfid;
            if (ftpar->arraydim > 0)
            {
               if ( ftpar->np1 > 2*(curfid/ftpar->arraydim) )
                  ftpar->np1 = 2*(curfid/ftpar->arraydim);
            }
 
            if (!acqflag)
            {
               if ( *lastfid )
                  Winfoprintf("number of FID's used = %d", *lastfid);
               else
                  Winfoprintf("No data in FID file");
               showMsg = 0;
            }
         }

         inp16 = (short *) (inp32 = (int *) (data));
         shift = 1 << abs(inblock.head->scale);
         if (inblock.head->scale < 0)
            rmult = 1.0/(float)(shift);
         else
            rmult = (float) shift;
         rmult /= (float)(inblock.head->ctcount);
         if (inblock.head->status == (S_DATA|S_32|S_COMPLEX))
         {
            cnvrts32(rmult, inp32, outp, ftpar->np0, ftpar->lsfid0);
         }
         else if (inblock.head->status == (S_DATA|S_COMPLEX))
         {
            cnvrts16(rmult, inp16, outp, ftpar->np0, ftpar->lsfid0);
         }
         else
         {
            if (inblock.head->status != 0)
            {
               Wscrprintf("status of FID %d incorrect, status = %d\n",
                     curfid + 1, inblock.head->status);
            }
 
            zerofill(outp, ftpar->fn0);
            if (ftpar->arraydim > 0)
            {
               if ( ftpar->np1 > 2*(curfid/ftpar->arraydim) )
                  ftpar->np1 = 2*(curfid/ftpar->arraydim);
            }
 
            *lastfid = curfid;
            if ( !acqflag && showMsg )
            {
               if ( *lastfid )
                  Winfoprintf("number of FID's used = %d", *lastfid);
               else
                  Winfoprintf("No data in FID file");
            }
         }
      }

/*---------------------------------------------
|     if requested remove the baseline        |
|     supplied by noise check                 |
---------------------------------------------*/
 
     if ( ftpar->offset_flag && (inblock.head->ctcount == 1) )
     {
        if (curfid == 0)
        {
           xoff = inblock.head->lvl;
           yoff = inblock.head->tlt;
        }
 
        if (ftpar->lsfid0 < 0)
        {
           tmp = outp - ftpar->lsfid0;
           npx = ftpar->np0;
        }
        else
        {
           tmp = outp;
           npx = ftpar->np0 - ftpar->lsfid0;
        }

        i = 0;
        while (i < npx)
        {  
           *tmp++ -= xoff;
           *tmp++ -= yoff;
           i += 2;
        }
      }
/*    end of prototype baseline removal */

#ifdef XXX
      if ( !P_getreal(CURRENT, "rlmult", &rlmult, 1) )
      {
         if ( !P_getreal(CURRENT, "immult", &immult, 1) )
         {
            if (ftpar->lsfid0 < 0)
            {
               tmp = outp - ftpar->lsfid0;
               npx = ftpar->np0;
            }
            else
            {   
               tmp = outp;
               npx = ftpar->np0 - ftpar->lsfid0;
            }

            i = 0;
            while (i < npx)
            {
               *tmp++ *= rlmult;
               *tmp++ *= immult;
               i += 2;
            }
         }
      }
#endif
/* end of prototype differential channel scaling */

      if (ftpar->t2dc)
      {
        driftcorrect_fid(outp, ftpar->np0/2, ftpar->lsfid0/2, COMPLEX);
      }
 
      if ( (fabs(ftpar->phfid0) > MINDEGREE) ||
	   (fabs(ftpar->lsfrq0) > 1e-20) )
      {
         rotate_fid(outp, ftpar->phfid0, ftpar->lsfrq0,
			ftpar->np0 - ftpar->lsfid0, COMPLEX);
      }

      if (ftpar->zeroflag)
      {
         if (ftpar->zeroflag > 0)
            zeroimag(outp, ftpar->np0 - ftpar->lsfid0, TRUE);
         else
            negateimaginary(outp, (ftpar->np0 - ftpar->lsfid0) / 2, COMPLEX);
      }

      if ( (res = D_release(D_USERFILE, curfid)) )
      {
         D_error(res);
         D_close(D_USERFILE);
         return(ERROR);
      }
   }

   long_event();
   return(COMPLETE);
}
Пример #20
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();
}
Пример #21
0
int splmodread (int argc, char *argv[], int retc, char *retv[])
{
  /*Declarations */
  int i, j, k, l,		/*standard iterators */
    nPeaks,			/*number of peaks */
    dosyversion,		/*version number */
    badinc,			/*number of pruned levels */
    nugflag,			/*whether to use pure exponentials or corrected */
    badflag,			/*for removing data from pruned amplitudes */
    bd[MAXPOINTS],		/*array for amplitude levels deleted from analysis (prune) */
    bestsol,			/*best solution chosen by splmod */
    currsol,			/*solution chosen by us */
    currflag, /**/ inttmp,	/*temporary variable */
    nugsize,			/*length of array nugcal_ */
    checkpeakno,		/*check of peak number */
    solno,			/*solution number */
    nofit,			/*flag for failure to report a fit */
    nPoints;			/*number of points per peak (amplitude levels) */

  char rubbish[MAXLENGTH],	/* string for various purposes */
   *pptemp,			/* temprary pointer to pointer */
    js1[MAXLENGTH],		/* strings for various purposes */
   
    js2[MAXLENGTH],
    js3[MAXLENGTH],
    js4[MAXLENGTH],
    js5[MAXLENGTH],
    js6[MAXLENGTH],
    js7[MAXLENGTH],
    js8[MAXLENGTH],
    js9[MAXLENGTH], js10[MAXLENGTH], js11[MAXLENGTH], jstr[MAXLENGTH];

  double dosyconstant,		/*calculated from the pulse sequence */
    gcal_,			/*conversion factor from DAC points to Gauss */
    gwidth,			/*correction factor for Gaussian linewidth */
    doubletmp,			/*temporary variable */
    gradAmp[MAXPOINTS],		/*gradient amplitudes */
    alphaTmp[10],		/*for amplitudes */
    lamdaTmp[10],		/*for D-values */
    frq[MAXPEAKS],		/*frequencies for each peak */
    ampl[MAXPOINTS],		/*amplitudes for each peak */
    nug[MAXFITCOEFFS + 1];	/*coefficients for NUG correction */

  FILE *infile,			/*for dosy_splmod.out file */
   *dosyfile,			/*for dosy_in file */
   *fit_residuals,		/*for general_dosy_stats */
   *ddiffile,			/*for diffusion_display.inp */
   *D_spectrum;			/*for diffusion_spectrum */

  typedef struct FitValues_struct
  {
    double alpha[10], std_alpha[10], lamda[10], std_lamda[10];
  } FitValues_struct;
  FitValues_struct FitValues[10];


#ifdef DEBUG_SPLMOD
  FILE *debug;
#endif


#ifdef DEBUG_SPLMOD
  //strcpy (rubbish, userdir);
  strcpy (rubbish, curexpdir);
  strcat (rubbish, "/dosy/debug_splmodread");
  debug = fopen (rubbish, "w");	/* file for debugging information */
  fprintf (debug, "Start of splmodread\n");
#endif
#ifdef DEBUG_SPLMOD
  fprintf (debug, "Before reading in of data\n");
#endif

/* GM 4iii09 define scaling factor for width of Gaussian line in diffusion_spectrum */
  gwidth = 2.0 * sqrt (2.0 * (log (2.0)));

  /*Read data from dosy_in */



  //strcpy (rubbish, userdir);
  strcpy (rubbish, curexpdir);
  strcat (rubbish, "/dosy/dosy_in");
  dosyfile = fopen (rubbish, "r");
  if (!dosyfile)
    {
      Werrprintf ("splmodread: could not open file %s", rubbish);
      return (ERROR);
    }
  strcpy (jstr, curexpdir);
  strcat (jstr, "/dosy/dosy_in");

  if (fscanf (dosyfile, "DOSY version %d\n", &dosyversion) == EOF)
    {
      Werrprintf ("splmodprepare: reached end of file %s", jstr);
      fclose (dosyfile);
      return (ERROR);
    }
  if (fscanf
      (dosyfile, "%d spectra will be deleted from the analysis :\n",
       &badinc) == EOF)
    {
      Werrprintf ("splmodprepare: reached end of file %s", jstr);
      fclose (dosyfile);
      return (ERROR);
    }
  for (i = 0; i < badinc; i++)
    {
      if (fscanf (dosyfile, "%d\n", &bd[i]) == EOF)
	{
	  Werrprintf ("splmodread: reached end of file %s", jstr);
	  fclose (dosyfile);
	  return (ERROR);
	}
    }

  if ((fscanf (dosyfile, "Analysis on %d peaks\n", &nPeaks) == EOF)	/* read in calibration parameters */
      || (fscanf (dosyfile, "%d points per peaks\n", &nPoints) == EOF)
      || (fscanf (dosyfile, "%d parameters fit\n", &inttmp) == EOF)
      || (fscanf (dosyfile, "dosyconstant = %lf\n", &dosyconstant) == EOF)
      || (fscanf (dosyfile, "gradient calibration flag :  %d\n", &inttmp) ==
	  EOF)
      || (fscanf (dosyfile, "non-linear gradient flag :  %d\n", &nugflag) ==
	  EOF))
    {
      Werrprintf ("splmodread: reached end of file %s", jstr);
      fclose (dosyfile);
      return (ERROR);
    }

  for (i = 0, j = 0; i < (nPoints + badinc); i++)
    {				/*scan through all the input values, discarding the unwanted ones */
      badflag = 0;
      for (l = 0; l < badinc; l++)
	if (i == bd[l] - 1)
	  badflag = TRUE;
      strcpy (jstr, curexpdir);
      strcat (jstr, "/dosy/dosy_in");	/* read in gradient array */
      if (badflag)
	{
	  if (fscanf (dosyfile, "%s", rubbish) == EOF)
	    {
	      Werrprintf
		("splmodread: reached end of file %s on increment %d", jstr,
		 i);
	      fclose (dosyfile);
	      return (ERROR);
	    }
	}
      else
	{
	  if (fscanf (dosyfile, "%lf", &gradAmp[j]) == EOF)
	    {
	      Werrprintf
		("splmodread: reached end of file %s on increment %d", jstr,
		 i);
	      fclose (dosyfile);
	      return (ERROR);
	    }
	  j++;
	}
    }

  if (fscanf (dosyfile, "%s", rubbish) == EOF)
    {
      Werrprintf ("splmodread: reached end of file %s", jstr);
      fclose (dosyfile);
      return (ERROR);
    }
  while (strcmp (rubbish, "(mm)") != 0)
    {
      if (fscanf (dosyfile, "%s", rubbish) == EOF)
	{
	  Werrprintf ("splmodread: reached end of file %s", jstr);
	  fclose (dosyfile);
	  return (ERROR);
	}
    }


/*read in NUG if nugflag*/

  for (i = 0; i <= MAXFITCOEFFS; i++)
    nug[i] = 0.0;
  nugflag = 0;
  if (!P_getstring (CURRENT, "nugflag", rubbish, 1, 2))
    {
      if (!strcmp ("y", rubbish))
	{
	  nugflag = 1;
	}
      else
	{
	  nugflag = 0;
	}
    }
  if (nugflag)
    {
      P_getsize(CURRENT, "nugcal_", &nugsize);
      if (nugsize > 5)
	nugsize = 5;
      if (nugsize < 2)
	{
	  Wscrprintf ("splmodread: nugcal_ must contain at least 2 values");
	  Werrprintf ("splmodread: nugcal_ must contain at least 2 values");
	  fclose (dosyfile);
	  return (ERROR);
	}
      if (P_getreal (CURRENT, "nugcal_", &gcal_, 1))
	{
	  Werrprintf ("splmodread: cannot read gcal_ from nugcal_");
	  Wscrprintf ("splmodread: cannot read gcal_ from nugcal_");
	  fclose (dosyfile);
	  return (ERROR);
	}
      for (i = 1; i < nugsize; i++)
	{
	  if (P_getreal (CURRENT, "nugcal_", &nug[i], i + 1))
	    {
	      Werrprintf
		("splmodread: cannot read coefficients from nugcal_");
	      Wscrprintf
		("splmodread: cannot read coefficients from nugcal_");
	      fclose (dosyfile);
	      return (ERROR);
	    }
	}
#ifdef DEBUG_SPLMOD
      fprintf (debug, "nugsize:  %d\n", nugsize);
      fprintf (debug, "gcal_ %e :\n", gcal_);
      for (i = 0; i < MAXFITCOEFFS; i++)
	fprintf (debug, "nug %e :\n", nug[i + 1]);
#endif
    }



  /*open the fit_residuals */
  //strcpy (rubbish, userdir);
  strcpy (rubbish, curexpdir);
  strcat (rubbish, "/dosy/general_dosy_stats");
  fit_residuals = fopen (rubbish, "w");
  if (!fit_residuals)
    {
      Werrprintf ("splmodread: could not open file %s", rubbish);
      fclose (dosyfile);
      return (ERROR);
    }

  fprintf (fit_residuals, "\t\t2D data set\n");
  fprintf (fit_residuals,
	   "\t\tsee dosy_splmod.out for more statistical information.\n");
  if (nugflag)
    {
      fprintf (fit_residuals,
	       "Fitted for NUG corrected decays using Splmod\n\n\n\n");
    }
  else
    {
      fprintf (fit_residuals,
	       "Fitted for pure exponentials using Splmod\n\n\n\n");
    }

  /*Read data from dosy_splmod.out */
/*{{{*/
  //strcpy (rubbish, userdir);
  strcpy (rubbish, curexpdir);
  strcat (rubbish, "/dosy/dosy_splmod.out");
  infile = fopen (rubbish, "r");
  if (!infile)
    {
      Werrprintf ("splmodread: could not open file %s", rubbish);
      fclose (dosyfile);
      fclose (fit_residuals);
      return (ERROR);
    }

  //strcpy (rubbish, userdir);
  strcpy (rubbish, curexpdir);
  strcat (rubbish, "/dosy/diffusion_display.inp");
  ddiffile = fopen (rubbish, "w");
  if (!ddiffile)
    {
      Werrprintf ("splmodread: could not open file %s", rubbish);
      fclose (dosyfile);
      fclose (fit_residuals);
      fclose (infile);
      return (ERROR);
    }
  strcpy (rubbish, curexpdir);
  strcat (rubbish, "/dosy/diffusion_spectrum");
  D_spectrum = fopen (rubbish, "w");
  if (!D_spectrum)
    {
      Werrprintf ("splmodread: could not open file %s", rubbish);
      fclose (dosyfile);
      fclose (fit_residuals);
      fclose (infile);
      fclose (ddiffile);
      return (ERROR);
    }

  strcpy (jstr, curexpdir);
  strcat (jstr, "/dosy/dosy_splmod.out");

#ifdef DEBUG_SPLMOD
  fclose (debug);
#endif

  k = 0;
  solno = 0;
  nofit = 0;

  while (fgets (jstr, 512, infile) != NULL)	/* read each line of dosy_splmod.out in turn, parsing those lines which carry useful information */
    {
      if (strstr (jstr, "1SPLMOD") != NULL)	/* read in peak frequency */
	{
	  k++;
	  sscanf (jstr, "%s%s%s%s%s%s%s%s%s%s %d %s %lf", js1, js2, js3,
		  js4, js5, js6, js7, js8, js9, js10, &checkpeakno, js11,
		  &frq[k]);
	  solno = 0;
	  j = 0;
	  nofit = 1;
	  for (i = 0; i < 10; i++)
	    {
	      for (j = 0; j < 10; j++)
		{
		  FitValues[i].alpha[j] = 0.0;
		  FitValues[i].std_alpha[j] = 0.0;
		  FitValues[i].lamda[j] = 0.0;
		  FitValues[i].std_lamda[j] = 0.0;
		}
	    }

	  for (i = 0, j = 0; i < (nPoints + badinc); i++)
	    {
	      badflag = 0;
	      for (l = 0; l < badinc; l++)
		if (i == bd[l] - 1)
		  badflag = 1;
	      fscanf (dosyfile, "%s", rubbish);
	      fscanf (dosyfile, "%s", rubbish);
	      if (badflag)
		fscanf (dosyfile, "%s", rubbish);
	      else
		fscanf (dosyfile, "%lf", &ampl[j++]);
	    }
#ifdef DEBUG_SPLMOD
	  strcpy (rubbish, curexpdir);
	  strcat (rubbish, "/dosy/debug_splmodread");
	  debug = fopen (rubbish, "a");	/* file for debugging information */
	  fprintf (debug,
		   "For peak %d , check peak no is %d and freq is %lf \n",
		   k, checkpeakno, frq[k]);
	  fclose (debug);
#endif

	}
      else if (strstr (jstr, " +- ") != NULL)
	{
	  if (strstr (jstr, "ALPHA") != NULL)	/* a fit has succeeded, get ready to record results */
	    {
	      solno++;
	      j = 0;
	    }
	  else
	    {
	      if (strstr (jstr, "***") != NULL)	/* the percentage error is too high to print, so fit must be dud */
		{
		  solno--;
		  j = 0;
#ifdef DEBUG_SPLMOD
		  strcpy (rubbish, curexpdir);
		  strcat (rubbish, "/dosy/debug_splmodread");
		  debug = fopen (rubbish, "a");	/* file for debugging information */
		  fprintf (debug,
			   "For peak %d , fit is too poor to read in\n", k);
		  fclose (debug);
#endif
		}
	      else
		{
		  j++;
		  sscanf (jstr, "%s%s%s%s%s%s%s", js1, js2, js3, js4, js5,
			  js6, js7);
		  FitValues[solno].alpha[j] = strtod (js1, &pptemp);
		  FitValues[solno].std_alpha[j] = strtod (js3, &pptemp);
		  FitValues[solno].lamda[j] = strtod (js5, &pptemp);
		  FitValues[solno].std_lamda[j] = strtod (js7, &pptemp);
		  if (fabs (FitValues[solno].std_alpha[j]) > 100.0)
		    {
		      solno--;
#ifdef DEBUG_SPLMOD
		      strcpy (rubbish, curexpdir);
		      strcat (rubbish, "/dosy/debug_splmodread");
		      debug = fopen (rubbish, "a");	/* file for debugging information */
		      fprintf (debug,
			       "For peak %d , std dev of alpha is too high\n",
			       k);
		      fclose (debug);
#endif
		    }
		  else
		    {
		      nofit = 0;
		    }
#ifdef DEBUG_SPLMOD
		  strcpy (rubbish, curexpdir);
		  strcat (rubbish, "/dosy/debug_splmodread");
		  debug = fopen (rubbish, "a");	/* file for debugging information */
		  fprintf (debug,
			   "For peak %d , results are %e\t\%e\t\%e\t\%e \n",
			   k, FitValues[solno].alpha[j],
			   FitValues[solno].std_alpha[j],
			   FitValues[solno].lamda[j],
			   FitValues[solno].std_lamda[j]);
		  fprintf (debug, "%s", jstr);
		  fclose (debug);
#endif
		}
	    }
	}
      else if ((strstr (jstr, "FOUND") != NULL) && (nofit == FALSE))	/* a fit has been found and the best solution is being reported */
	{
	  sscanf (jstr, "%s%s%s%s%s%s %d", js1, js2, js3, js4, js5,
		  js6, &bestsol);
	  /* now process the results for this peak */
#ifdef DEBUG_SPLMOD
	  strcpy (rubbish, curexpdir);
	  strcat (rubbish, "/dosy/debug_splmodread");
	  debug = fopen (rubbish, "a");	/* file for debugging information */
	  fprintf (debug, "For peak %d , best sol is %d  \n", k, bestsol);
	  fclose (debug);
#endif
	  fprintf (fit_residuals, "\nFrequency %lf\n", frq[k]);


	  fprintf (fit_residuals, "y = Sum (Alpha[i]*Exp[-Lamda*x])\n");
	  fprintf (fit_residuals,
		   "Splmod solutions (best solution is %d components):\n",
		   bestsol);

	  for (i = bestsol; i >= 1; i--)
	    {
	      fprintf (fit_residuals, "Splmod solution: [%d]\n", i);
	      for (j = 1; j <= i; j++)
		{
		  fprintf (fit_residuals,
			   "Alpha[%d]= %10.4lf (+/- %5.4lf)	Lamda[%d]= %10.4lf (+/- %5.4lf)(* 10-10 m2s-1)\n",
			   j, FitValues[i].alpha[j],
			   FitValues[i].std_alpha[j], j,
			   1e14 * FitValues[i].lamda[j] / dosyconstant,
			   1e14 * FitValues[i].std_lamda[j] / dosyconstant);
		}
	    }

	  /* Check the fitted values for the best solution */
	  currsol = bestsol;
	  currflag = 0;
	  for (i = bestsol; i >= 1; i--)
	    {
	      if (currflag)
		{
		  currsol = currsol - 1;
		  currflag = 0;
		}
	      for (j = 1; j <= i; j++)
		{
		  fprintf (fit_residuals, "i is %d j is %d .\n", i, j);
		  fprintf (fit_residuals, "currsol is %d\n", currsol);

		  if (((100.0 * FitValues[i].std_alpha[j] /
			FitValues[i].alpha[j]) > MAX_ERROR)
		      || (FitValues[i].alpha[j] == 0.0))
		    {
		      currflag = 1;
		      fprintf (fit_residuals,
			       "STDEV of Alpha %d from SPLMOD solution %d was too high; choosing one less component.\n",
			       j, currsol);
		      fprintf (fit_residuals,
			       "FitVal %d Alpha %d is %lf .\n", i, j,
			       FitValues[i].alpha[j]);
		    }
		  if (((100.0 * FitValues[i].std_lamda[j] /
			FitValues[i].lamda[j]) > MAX_ERROR)
		      || (FitValues[i].lamda[j] == 0.0))
		    {
		      currflag = 1;
		      fprintf (fit_residuals,
			       "STDEV of Lamda %d from SPLMOD solution %d was too high; choosing one less component.\n",
			       j, currsol);
		      fprintf (fit_residuals,
			       "FitVal %d Lamda %d is %lf .\n", i, j,
			       FitValues[i].lamda[j]);
		    }
		  /* Reject solution if calculated signal attenuates more than tenfold between 1st and 2nd gradient value */
		  if (FitValues[i].lamda[j] >
		      2.30259 / (gradAmp[2] * gradAmp[2] -
				 gradAmp[1] * gradAmp[1]))
		    {
		      currflag = 1;
		      fprintf (fit_residuals,
			       "Lamda %d from SPLMOD solution %d was too high to be statistically significant; choosing one less component.\n",
			       j, currsol);
		      fprintf (fit_residuals,
			       "FitVal %d Lamda %d is %lf .\n", i, j,
			       FitValues[i].lamda[j]);
		    }
		}
	    }

	  fprintf (fit_residuals,
		   "SPLMOD solution %d was deemed the most appropriate\n",
		   currsol);

	  /*print values for best solution to diffusion_display.inp */
#ifdef DEBUG_SPLMOD
	  strcpy (rubbish, curexpdir);
	  strcat (rubbish, "/dosy/debug_splmodread");
	  debug = fopen (rubbish, "a");	/* file for debugging information */
	  fprintf (debug,
		   "Printing out results for peak %d to diffusion_display.inp \n",
		   k);
	  fclose (debug);
#endif
	  for (i = 1; i <= currsol; i++)
	    {
	      fprintf (ddiffile,
		       "%10.3lf\t%10.4lf\t%10.4lf\t%10.6lf\t%10.4lf\t%10.4lf\t%10.6lf\n",
		       frq[k], FitValues[currsol].alpha[i],
		       1e14 * FitValues[currsol].lamda[i] / dosyconstant,
		       1e14 * FitValues[currsol].std_lamda[i] /
		       dosyconstant, 0.0, 0.0, 0.0);
#ifdef DEBUG_SPLMOD
	      strcpy (rubbish, curexpdir);
	      strcat (rubbish, "/dosy/debug_splmodread");
	      debug = fopen (rubbish, "a");	/* file for debugging information */
	      fprintf (debug,
		       "Peak %d :   %10.3lf\t%10.4lf\t%10.4lf\t%10.6lf\t%10.4lf\t%10.4lf\t%10.6lf\n",
		       k, frq[k], FitValues[currsol].alpha[i],
		       1e14 * FitValues[currsol].lamda[i] / dosyconstant,
		       1e14 * FitValues[currsol].std_lamda[i] /
		       dosyconstant, 0.0, 0.0, 0.0);
	      fclose (debug);
#endif
	    }
	  /*print values for best solution to diffusion_spectrum */
	  for (i = 1; i <= currsol; i++)
	    {
	      fprintf (D_spectrum,
		       "%10.3lf,\t%10.4lf,\t%10.4lf,\t%10.6lf\n",
		       1e14 * FitValues[currsol].lamda[i] / dosyconstant,
		       FitValues[currsol].alpha[i],
		       gwidth * 1e14 * FitValues[currsol].std_lamda[i] /
		       dosyconstant, 1.0);
	    }
	  /*Print to general_dosy_stats */

	  fprintf (fit_residuals,
		   "Gradient area         exp. height    calc. height          Diff\n");

	  for (i = 1; i < 10; i++)
	    {
	      alphaTmp[i] = FitValues[currsol].alpha[i];
	      lamdaTmp[i] = FitValues[currsol].lamda[i];
	    }
	  for (i = 0; i < nPoints; i++)
	    {
	      doubletmp =
		residfunc (gradAmp[i], lamdaTmp, alphaTmp, currsol,
			   nugflag, dosyconstant, nug);
	      fprintf (fit_residuals, "%10.6lf %15.6lf %15.6lf %15.6lf\n",
		       dosyconstant * 0.0001 * (1.0e-9) * gradAmp[i] *
		       gradAmp[i], ampl[i], doubletmp, (ampl[i] - doubletmp));
	    }
	}
      else
	{
	}			/* no keyword found, line can be ignored */
    }				/* End of while loop over input file lines, and hence over peaks */

#ifdef DEBUG_SPLMOD
  strcpy (rubbish, curexpdir);
  strcat (rubbish, "/dosy/debug_splmodread");
  debug = fopen (rubbish, "a");	/* file for debugging information */
  fprintf (debug, "End of splmodread\n");
  fclose (debug);
#endif

  fclose (dosyfile);
  fclose (fit_residuals);
  fclose (infile);
  fclose (ddiffile);
  fclose (D_spectrum);
  RETURN;
}