Esempio n. 1
0
/*
 * search() looks for a character forward or backward from mark 
 */
extern char	*BX_search(register char *start, char **mark, char *chars, int how)
{
        if (!mark || !*mark)
                *mark = start;

        if (how > 0)   /* forward search */
        {
		*mark = sindex(*mark, chars);
		how--;
		for (;(how > 0) && *mark && **mark;how--)
			*mark = sindex(*mark+1, chars);
	}

	else if (how == 0)
		return (char *) 0;

	else  /* how < 0 */
	{
		*mark = rsindex(*mark, start, chars, -how);
#if 0
		how++;
		for (;(how < 0) && *mark && **mark;how++)
			*mark = rsindex(*mark-1, start, chars);
#endif
	}

	return *mark;
}
Esempio n. 2
0
File: words.c Progetto: jnbek/TekNap
/*
 * search() looks for a character forward or backward from mark 
 */
char	*search (char *start, char **mark, char *chars, int how)
{
        if (!mark || !*mark)
                *mark = start;

        if (how > 0)   /* forward search */
        {
		*mark = sindex(*mark, chars);
		how--;
		for (;(how > 0) && *mark && **mark;how--)
			*mark = sindex(*mark+1, chars);
	}

	else if (how == 0)
		return NULL;

	else  /* how < 0 */
		*mark = rsindex(*mark, start, chars, -how);

	return *mark;
}
Esempio n. 3
0
MagickExport int Tokenizer(TokenInfo *token_info,const unsigned flag,
  char *token,const size_t max_token_length,const char *line,const char *white,
  const char *break_set,const char *quote,const char escape,char *breaker,
  int *next,char *quoted)
{
  int
    c;

  register long
    i;

  *breaker='\0';
  *quoted='\0';
  if (line[*next] == '\0')
    return(1);
  token_info->state=IN_WHITE;
  token_info->quote=(char) MagickFalse;
  token_info->flag=flag;
  for (token_info->offset=0; (int) line[*next] != 0; (*next)++)
  {
    c=(int) line[*next];
    i=sindex(c,break_set);
    if (i >= 0)
      {
        switch (token_info->state)
        {
          case IN_WHITE:
          case IN_TOKEN:
          case IN_OZONE:
          {
            (*next)++;
            *breaker=break_set[i];
            token[token_info->offset]='\0';
            return(0);
          }
          case IN_QUOTE:
          {
            StoreToken(token_info,token,max_token_length,c);
            break;
          }
        }
        continue;
      }
    i=sindex(c,quote);
    if (i >= 0)
      {
        switch (token_info->state)
        {
          case IN_WHITE:
          {
            token_info->state=IN_QUOTE;
            token_info->quote=quote[i];
            *quoted=(char) MagickTrue;
            break;
          }
          case IN_QUOTE:
          {
            if (quote[i] != token_info->quote)
              StoreToken(token_info,token,max_token_length,c);
            else
              {
                token_info->state=IN_OZONE;
                token_info->quote='\0';
              }
            break;
          }
          case IN_TOKEN:
          case IN_OZONE:
          {
            *breaker=(char) c;
            token[token_info->offset]='\0';
            return(0);
          }
        }
        continue;
      }
    i=sindex(c,white);
    if (i >= 0)
      {
        switch (token_info->state)
        {
          case IN_WHITE:
          case IN_OZONE:
            break;
          case IN_TOKEN:
          {
            token_info->state=IN_OZONE;
            break;
          }
          case IN_QUOTE:
          {
            StoreToken(token_info,token,max_token_length,c);
            break;
          }
        }
        continue;
      }
    if (c == (int) escape)
      {
        if (line[(*next)+1] == '\0')
          {
            *breaker='\0';
            StoreToken(token_info,token,max_token_length,c);
            (*next)++;
            token[token_info->offset]='\0';
            return(0);
          }
        switch (token_info->state)
        {
          case IN_WHITE:
          {
            (*next)--;
            token_info->state=IN_TOKEN;
            break;
          }
          case IN_TOKEN:
          case IN_QUOTE:
          {
            (*next)++;
            c=(int) line[*next];
            StoreToken(token_info,token,max_token_length,c);
            break;
          }
          case IN_OZONE:
          {
            token[token_info->offset]='\0';
            return(0);
          }
        }
        continue;
      }
    switch (token_info->state)
    {
      case IN_WHITE:
        token_info->state=IN_TOKEN;
      case IN_TOKEN:
      case IN_QUOTE:
      {
        StoreToken(token_info,token,max_token_length,c);
        break;
      }
      case IN_OZONE:
      {
        token[token_info->offset]='\0';
        return(0);
      }
    }
  }
  token[token_info->offset]='\0';
  return(0);
}
Esempio n. 4
0
/*
 * display_link : Prints the contents of the given virtual link. If
 *	listflag is 0, then this uses last{host,path} to save state
 *	between calls for a less verbose output. If listflag is non-zero
 *	then all information is printed every time.
 */
void display_link(VLINK l,int listflag)
{
    PATTRIB 	ap;
    char	linkpath[MAX_VPATH];
    int		dirflag = 0;
#ifdef MSDOS
    unsigned long size = 0L;
#else
    int		size = 0;
#endif
    char	*modes = "";
    char	archie_date[20];
    char	*gt_date = "";
    int		gt_year = 0;
    int		gt_mon = 0;
    int		gt_day = 0;
    int		gt_hour = 0;
    int		gt_min = 0;
    
    /* Initialize local buffers */
    *archie_date = '\0';

    /* Remember if we're looking at a directory */
    if (sindex(l->type,"DIRECTORY"))
	dirflag = 1;
    else
	dirflag = 0;
    
    /* Extract the linkpath from the filename */
    strcpy(linkpath,l->filename);
    *(linkpath + (strlen(linkpath) - strlen(l->name) - 1)) = '\0';
    
    /* Is this a new host? */
    if (strcmp(l->host,lasthost) != 0) {
	if (!listflag)
	    printf("\nHost %s\n\n",l->host);
	strcpy(lasthost,l->host);
	*lastpath = '\001';
    }
    
    /* Is this a new linkpath (location)? */
    if(strcmp(linkpath,lastpath) != 0) {
	if (!listflag)
	    printf("    Location: %s\n",(*linkpath ? linkpath : "/"));
	strcpy(lastpath,linkpath);
    }
    
    /* Parse the attibutes of this link */
    for (ap = l->lattrib; ap; ap = ap->next) {
	if (strcmp(ap->aname,"SIZE") == 0) {
#ifdef MSDOS
	    sscanf(ap->value.ascii,"%lu",&size);
#else
	    sscanf(ap->value.ascii,"%d",&size);
#endif
	} else if(strcmp(ap->aname,"UNIX-MODES") == 0) {
	    modes = ap->value.ascii;
	} else if(strcmp(ap->aname,"LAST-MODIFIED") == 0) {
	    gt_date = ap->value.ascii;
	    sscanf(gt_date,"%4d%2d%2d%2d%2d",&gt_year,
		   &gt_mon, &gt_day, &gt_hour, &gt_min);
	    if ((12 * (presenttime->tm_year + 1900 - gt_year) + 
					presenttime->tm_mon - gt_mon) > 6) 
		sprintf(archie_date,"%s %2d %4d",month_sname(gt_mon),
			gt_day, gt_year);
	    else
		sprintf(archie_date,"%s %2d %02d:%02d",month_sname(gt_mon),
			 gt_day, gt_hour, gt_min);
	}
    }
    
    /* Print this link's information */
    if (listflag)
#if defined(MSDOS)
	printf("%s %6lu %s %s%s\n",gt_date,size,l->host,l->filename,
	       (dirflag ? "/" : ""));
#else
	printf("%s %6d %s %s%s\n",gt_date,size,l->host,l->filename,
	       (dirflag ? "/" : ""));
#endif
    else
Esempio n. 5
0
/* here it is! */
int parser(unsigned inflag,char* token,int tokmax,char* line,char* white,char* brkchar,char* quote,
		   char eschar,char* brkused,int* next,char* quoted){
  int qp;
  char c,nc;
          
  *brkused=0;           /* initialize to null */	  
  *quoted=0;		/* assume not quoted  */

  if(!line[*next])      /* if we're at end of line, indicate such */
    return 1;

  _p_state=IN_WHITE;       /* initialize state */
  _p_curquote=0;           /* initialize previous quote char */
  _p_flag=inflag;          /* set option flag */

  for(_p_tokpos=0;c=line[*next];++(*next))      /* main loop */
  {
    if((qp=sindex(c,brkchar))>=0)  /* break */
    {
      switch(_p_state)
      {
        case IN_WHITE:          /* these are the same here ...	*/
        case IN_TOKEN:          /* ... just get out		*/
	case IN_OZONE:		/* ditto			*/
          ++(*next);
          *brkused=brkchar[qp];
          goto byebye;
        
        case IN_QUOTE:           /* just keep going */
          chstore(token,tokmax,c);
          break;
      }
    }
    else if((qp=sindex(c,quote))>=0)  /* quote */
    {
      switch(_p_state)
      {
        case IN_WHITE:   /* these are identical, */
          _p_state=IN_QUOTE;        /* change states   */
          _p_curquote=quote[qp];         /* save quote char */
          *quoted=1;	/* set to true as long as something is in quotes */
          break;
  
        case IN_QUOTE:
          if(quote[qp]==_p_curquote)	/* same as the beginning quote? */
	  {
            _p_state=IN_OZONE;
	    _p_curquote=0;
	  }
          else
            chstore(token,tokmax,c);	/* treat as regular char */
          break;

	case IN_TOKEN:
	case IN_OZONE:
	  *brkused=c;			/* uses quote as break char */
	  goto byebye;
      }
    }
    else if((qp=sindex(c,white))>=0)       /* white */
    {
      switch(_p_state)
      {
        case IN_WHITE:
	case IN_OZONE:
          break;		/* keep going */
          
        case IN_TOKEN:
          _p_state=IN_OZONE;
          break;
          
        case IN_QUOTE:
          chstore(token,tokmax,c);     /* it's valid here */
          break;
      }
    }
    else if(c==eschar)			/* escape */
    {
      nc=line[(*next)+1];
      if(nc==0)			/* end of line */
      {
	*brkused=0;
	chstore(token,tokmax,c);
	++(*next);
	goto byebye;
      }
      switch(_p_state)
      {
	case IN_WHITE:
	  --(*next);
	  _p_state=IN_TOKEN;
	  break;

	case IN_TOKEN:
	case IN_QUOTE:
	  ++(*next);
	  chstore(token,tokmax,nc);
	  break;

	case IN_OZONE:
	  goto byebye;
      }
    }
    else        /* anything else is just a real character */
    {
      switch(_p_state)
      {
        case IN_WHITE:
          _p_state=IN_TOKEN;        /* switch states */
          
        case IN_TOKEN:           /* these 2 are     */
        case IN_QUOTE:           /*  identical here */
          chstore(token,tokmax,c);
          break;

	case IN_OZONE:
	  goto byebye;
      }
    }
  }             /* end of main loop */

byebye:
  token[_p_tokpos]=0;   /* make sure token ends with EOS */
  
  return 0;
  
}
Esempio n. 6
0
int Parse(char *token, int tokmax, char *line, 
	  int *next, int *brkpos, int *quotepos) {
  int qp;
  int i, c, nc;

  *brkpos = -1;
  *quotepos = -1;
  for (i = 0; i < NN; i++) quote_open[i] = 0;
  
  if (!line[*next]) return 1;

  state = IN_WHITE;
  
  for (tokpos = 0; (c = line[*next]); (*next)++) {
    if ((qp = sindex(c, delim)) >= 0) {
      switch(state) {
      case IN_WHITE:
      case IN_TOKEN:
      case IN_OZONE:
	(*next)++;
	*brkpos = qp;
	goto OUT;

      case IN_QUOTE:
	chstore(token, tokmax, c);
	break;
      }
    } else if ((qp = sindex(c, quote_begin)) >= 0) {
      switch (state) {
      case IN_WHITE:
	state = IN_QUOTE;
	*quotepos = qp;
	quote_open[qp]++;
	break;

      case IN_QUOTE:
	if (qp == *quotepos) {
	  if (c == quote_end[*quotepos]) {
	    state = IN_OZONE;
	    quote_open[qp]--;
	  } else {
	    quote_open[qp]++;
	    chstore(token, tokmax, c);
	  }
	} else {
	  chstore(token, tokmax, c);
	}
	break;
      case IN_TOKEN:
      case IN_OZONE:
	goto OUT;
      }
    } else if ((qp = sindex(c, quote_end)) >= 0) {
      switch (state) {
      case IN_QUOTE:
	if (quote_open[qp] > 1) {
	  chstore(token, tokmax, c);
	  quote_open[qp]--;
	} else if (quote_open[qp] < 1) {
	  chstore(token, tokmax, c);
	} else {
	  state = IN_OZONE;
	  quote_open[qp]--;
	}
	break;
      default:
	*quotepos = qp;
	return -1;
      }
    } else if ((qp = sindex(c, white)) >= 0) {
      switch (state) {
      case IN_WHITE:
      case IN_OZONE:
	break;
      case IN_TOKEN:
	state = IN_OZONE;
	break;
      case IN_QUOTE:
	chstore(token, tokmax, c);
	break;
      }
    } else if (c == escape) {
      nc = line[(*next)+1];
      if (nc == '\0') {
	chstore(token, tokmax, c);
	(*next)++;
	goto OUT;
      }
      switch(state) {
      case IN_WHITE:
	(*next)--;
	state = IN_TOKEN;
	break;
      case IN_TOKEN:
      case IN_QUOTE:
	(*next)++;
	chstore(token, tokmax, nc);
	break;
      case IN_OZONE:
	goto OUT;
      }
    } else {
      switch (state) {
      case IN_WHITE:
	state = IN_TOKEN;
      case IN_TOKEN:
      case IN_QUOTE:
	chstore(token, tokmax, c);
	break;
      case IN_OZONE:
	goto OUT;
      }
    }
  }

 OUT:
  token[tokpos] = '\0';
  
  return 0;
}
int main(int argc,char **argv)
{
  char command[MAXLN];  
  char demfile[MAXLN], pointfile[MAXLN], newfile[MAXLN]; //flood function
  char angfile[MAXLN], slopefile[MAXLN]; //setdir function
  char areafile[MAXLN]; //area function
  int  row=0,col=0,ccheck=0; //area function
  char sindexfile[MAXLN],tergridfile[MAXLN],terparfile[MAXLN],satfile[MAXLN]; //sindex function
    
  int err;
  char *ext;
  int isCmd;
  //printf("num of arg: %d\n" , argc);
  
  sprintf(command,"%s",argv[1]);
  isCmd = 0;
  
  time_t start,end;

time (&start);


if (strcmp( command, "flood" )== 0)
   {
     isCmd = 1;
    printf("MESSAGE: Executing %s command...\n" , command);
    sprintf(demfile,"%s",argv[2]);
    sprintf(pointfile,"%s",argv[3]);
    sprintf(newfile,"%s",argv[4]);
    
    
    if(err=flood(demfile, pointfile, newfile) != 0)
        printf("ERROR: Flood error %d\n",err);
    } 

if (strcmp( command, "setdir" )== 0)
   {
   isCmd = 1;
   printf("MESSAGE: Executing %s command...\n" , command);
   sprintf(demfile,"%s",argv[2]);
   sprintf(angfile,"%s",argv[3]);
   sprintf(slopefile,"%s",argv[4]);    
   if(err=setdir(demfile, angfile, slopefile) != 0)
        printf("ERROR: Setdir error %d\n",err);        
   }

if (strcmp( command, "area" )== 0)
   {
   isCmd = 1;
   printf("MESSAGE: Executing %s command...\n" , command);
   sprintf(angfile,"%s",argv[2]);
   sprintf(areafile,"%s",argv[3]);
   sscanf(argv[4],"%d",&col);
   sscanf(argv[5],"%d",&row);
   sscanf(argv[6],"%d",&ccheck);
      
   if(err=area(angfile, areafile, row, col, ccheck) != 0)
        printf("ERROR: Area error %d\n",err);        
   }      

if (strcmp( command, "sindex" )== 0)
   {
   isCmd = 1;
   printf("MESSAGE: Executing %s command...\n" , command);
   sprintf(slopefile,"%s",argv[2]);
   sprintf(areafile,"%s",argv[3]);
   sprintf(sindexfile,"%s",argv[4]);
   sprintf(tergridfile,"%s",argv[5]);
   sprintf(terparfile,"%s",argv[6]);
   sprintf(satfile,"%s",argv[7]);
      
   if(err=sindex(slopefile,areafile,sindexfile,tergridfile,terparfile,satfile) != 0)
        printf("ERROR: Area error %d\n",err);        
   }  

if (isCmd != 1)
   {
     printf("\n\n************************************\n\n");
     printf("SINMAP - Stability INdex MAPping\n");
     printf("original package version 1.0  3/30/98\n\n");
     printf("Program to compute stability index and factor of safety for landslide Hazard mapping.\n\n");
     printf("Main Author: David G Tarboton - Utah State University\n\n");
     printf("This version is provided by Enrico A. Chiaradia - University of Milan\n");
     printf("e-mail: [email protected]\n\n");
     printf("AVAILABLE COMMANDS ARE:\n");
     printf("flood demname=STRING pointname=STRING filldemname=STRING\n");
     printf("setdir filldemname=STRING anglename=STRING slopename=STRING\n");
     printf("area angname=STRING areaname=STRING ccell=INT rcell=INT ccheck=BOOLEAN\n");
     printf("sindex slopename=STRING areaname=STRING sindexname=STRING tergridname=STRING terparname=STRING satname=STRING\n");
     printf("\nUSAGE EXAMPLE:\n");
     printf("sinmap.exe flood dem.asc null.asc filleddem.asc\n");
     
     err = 0;
          }
time (&end);
double dif = difftime (end,start);
printf("Time elapsed: %.2lf seconds\n",dif );

if (err == 0)
   printf("Done.\n");
else
{
   printf("Finished with error!\n");
      
system("PAUSE");
}


return err;
}    
Esempio n. 8
0
void runGenTest(RunParameters &r) {

    // Define variables
    
    Vector J, expJ;
    std::vector<int> cons;
    std::vector<double> weight;
    
    if (r.useGI) {
    
        epsilonP2_ptr=&epsilonP2_GI;
        epsilonC_ptr=&epsilonC_GI;
        getMaxError_ptr=&getMaxError_GI;
        
    }
    else {
    
        epsilonP2_ptr=&epsilonP2;
        epsilonC_ptr=&epsilonC;
        getMaxError_ptr=&getMaxError;
        
    }
    
    // Get reference sequence from file
    
    FILE *consIn = fopen(r.getConsensusInfile().c_str(),"r");
         
    if (consIn!=NULL) getConsensus(consIn,cons);
    else { printf("Error reading input from file %s\n\n",r.getConsensusInfile().c_str()); exit(1); }
    fclose(consIn);
    
    if (r.useVerbose) {
      
        printf("Reference sequence: ");
        for (int i=0;i<cons.size();i++) printf(" %d",cons[i]);
        printf("\n\n");
	
    }

    // Retrieve couplings from file
    
    FILE *dataIn=fopen(r.getInfile().c_str(),"r");
        
    if (dataIn!=NULL) getCouplings(dataIn,J);
    else { printf("Error reading input from file %s",r.getInfile().c_str()); exit(1); }
    fclose(dataIn);

    // Resize expJ
    
    for (int i=0;i<J.size();i++) expJ.push_back(std::vector<double>(J[i].size(),0));
    for (int i=0;i<J.size();i++) { for (int j=0;j<J[i].size();j++) expJ[i][j] = exp(J[i][j]); }
    
    // Declare 2-point correlations, 3-point correlations, P(k) and magnetisations
    
    bool ThreePoints = (r.p3red || r.p3);
    int N = sizetolength(J.size()); // System size
    double alpha = 0.01;            // Field regularization multiplier
    double gamma = 0;               // Regularization strength (L2, set below)
    
    if (r.useGamma) {
    
        if (r.gamma==0) gamma=1/(r.sampleB);
        else            gamma=r.gamma;
        
    }
    
    Vector p(J.size(),std::vector<double>());           // MC magnetisations and 2-point correlations
    Vector cc(J.size(),std::vector<double>());          // MC connected 2-point correlations
    Vector q(J.size(),std::vector<double>());           // MSA magnetisations and 2-point correlations
    Vector qcc(J.size(),std::vector<double>());         // MSA connected 2-point correlations
    std::vector<std::vector<std::vector<std::vector<double> > > > p3(N);  // MC 3-point correlations
    std::vector<std::vector<std::vector<std::vector<double> > > > c3(N);  // MC connected 3-point correlations
    std::vector<std::vector<std::vector<std::vector<double> > > > q3(N);  // MSA 3-point correlations
    std::vector<std::vector<std::vector<std::vector<double> > > > qc3(N); // MSA connected 3-point correlations
    std::vector<double> pk(N+1,0);                      // MC mutation probability
    std::vector<double> qk(N+1,0);                      // MSA mutation probability    
    std::vector<double> absErr(2,0);                    // Absolute errors on magnetisation and 2-point correlations
    
    for (int i=0;i<J.size();i++) {
    
       cc[i].resize(J[i].size(),0); 
       p[i].resize(J[i].size(),0);
       qcc[i].resize(J[i].size(),0); 
       q[i].resize(J[i].size(),0);
       
    }
	if (ThreePoints) { for (int i=0;i<N;i++) {
    
	    p3[i].resize(N);
	    c3[i].resize(N);
	    q3[i].resize(N);
	    qc3[i].resize(N);
        
	    for (int j=0;j<N;j++) {
        
            p3[i][j].resize(N);
            c3[i][j].resize(N);
            q3[i][j].resize(N);
            qc3[i][j].resize(N);
            
            for (int k=0;k<N;k++) {
            
                p3[i][j][k].resize(p[i].size()*p[j].size()*p[k].size(),0);
                c3[i][j][k].resize(p[i].size()*p[j].size()*p[k].size(),0);
                q3[i][j][k].resize(p[i].size()*p[j].size()*p[k].size(),0);
                qc3[i][j][k].resize(p[i].size()*p[j].size()*p[k].size(),0);
                
            }
            
	    }
        
	} }

    // Get sequences from MSA file and compute correlations
    
    FILE *alIn=fopen(r.getInfileAl().c_str(),"r");
    FILE *weightIn=fopen(r.getWeights().c_str(),"r");

    if (alIn!=NULL){
        if (ThreePoints) getAlignment(alIn,weightIn,J,q,q3,qk,cons);
        else getAlignment(alIn,weightIn,J,q,qk,cons);
    }
    else { printf("Error reading input from file %s\n\n",r.getInfileAl().c_str()); exit(1); }
    fclose(alIn);    
    if (weightIn!=NULL) fclose(weightIn);
        
    if (r.useVerbose) printf("Got N=%d, len(h[0])=%d\n",N,(int)J[0].size());
        
    // Get default starting configuration, if nontrivial
    
    std::vector<int> lattice(N);
    
    if (r.useStart) {
    
        FILE *startIn=fopen(r.getStartInfile().c_str(),"r");
        for (int i=0;i<N;i++) fscanf(startIn,"%d",&lattice[i]);
    
    }
    
    else { for (int i=0;i<N;i++) lattice[i]=(int) p[i].size(); } 
    
    // Prepare to simulate
    
    srand((unsigned)time(0));

    // Run MC and get correlations
   
    if (ThreePoints) getErrorGenTest(J, expJ, r.sampleB, r.b, r.runs, p, lattice, pk, p3, cons); // compute errors on P P2 and MAX
    else             getErrorGenTest(J, expJ, r.sampleB, r.b, r.runs, p, lattice, pk, cons);     // compute errors on P P2 and MAX

    //Compute connected correlations
    
    double Neff  = 0;
    double NJeff = 0;
    // estimate the threshold for correlations to print out
    double meanq = 0;
    
    for (int i=0;i<lattice.size();i++) { for (int a=0;a<p[i].size();a++) {

        Neff++;
        meanq+=q[i][a];

        absErr[0] += (p[i][a] - q[i][a]) * (p[i][a] - q[i][a]);
    
        for (int j=i+1;j<lattice.size();j++) { for (int b=0;b<p[j].size();b++) {

            NJeff++;
	    
            int idx = index(i,j,lattice.size());
            int sab = sindex(a,b,J[i].size(),J[j].size());
            
            absErr[1] += (p[idx][sab] - q[idx][sab]) * (p[idx][sab] - q[idx][sab]);

            cc[idx][sab]  = p[idx][sab] - (p[i][a] * p[j][b]);
            qcc[idx][sab] = q[idx][sab] - (q[i][a] * q[j][b]);
		    
            if (ThreePoints) { for (int k=j+1;k<lattice.size();k++) { for (int c=0;c<p[k].size();c++) {
		
                int ijx  = idx;
                int ikx  = index(i,k,lattice.size());
                int jkx  = index(j,k,lattice.size());
                int sac  = sindex(a,c,J[i].size(),J[k].size());
                int sbc  = sindex(b,c,J[j].size(),J[k].size());
                int sabc = sindex3(a,b,c,J[i].size(),J[j].size(),J[k].size());
                
                c3[i][j][k][sabc]  = p3[i][j][k][sabc] - (p[i][a]*p[jkx][sbc]) - (p[j][b]*p[ikx][sac]) - (p[k][c]*p[ijx][sab]) + (2*(p[i][a]*p[j][b]*p[k][c]));
                qc3[i][j][k][sabc] = q3[i][j][k][sabc] - (q[i][a]*q[jkx][sbc]) - (q[j][b]*q[ikx][sac]) - (q[k][c]*q[ijx][sab]) + (2*(q[i][a]*q[j][b]*q[k][c]));
		    
            } } }
            
        } }
        
    } }
	
    absErr[0] = sqrt(absErr[0]/Neff);
    absErr[1] = sqrt(absErr[1]/NJeff);
    meanq=meanq/Neff;
    
    // Print out errors

    double maxPrecision=1/(r.sampleB);

    double ep1 = epsilonP(q, p, N, maxPrecision, J, gamma, alpha);
    double ep2 = (*epsilonP2_ptr)(q, p, N, maxPrecision, J, gamma);
    double em  = (*getMaxError_ptr)( q, p, maxPrecision, J, gamma, alpha);
    
    printf("\nRelative errors: P %f, P2 %f MAX %f gamma %f\n",ep1,ep2,em,gamma);
    printf("Absolute errors: P %f, P2 %f \n\n",absErr[0],absErr[1]);

    //Print results for comparison
    
    FILE *mOut  = fopen(r.getMOutfile().c_str(),"w");
    FILE *pOut  = fopen(r.getP2Outfile().c_str(),"w");
    FILE *ccOut = fopen(r.getCCOutfile().c_str(),"w");
    FILE *pkOut = fopen(r.getPKOutfile().c_str(),"w");
    
    printMagnetisations(mOut, q, p);
    double num=0;
    printCorrelations(ccOut, qcc, cc,pOut, q, p);
    
    if (ThreePoints){
      
        FILE *p3Out = fopen(r.getP3Outfile().c_str(),"w");
        FILE *c3Out = fopen(r.getC3Outfile().c_str(),"w");
        if (r.p3red) num=meanq*meanq*meanq;
        if (r.p3) num=0;
        print3points(c3Out, qc3, c3,p3Out, q3, p3, num);
	
    }
    for (int sit=0;sit<N;sit++) fprintf(pkOut,"%d %le %le\n",sit,qk[sit],pk[sit]);
    fflush(pkOut);

}
Esempio n. 9
0
/*
 * Evaluate a function.
 *
 * @fname: name of function to evaluate.
 */
char *gtfun(char *fname)
{
	int fnum;	/* index to function to eval */
	int status;	/* return status */
	char *tsp;	/* temporary string pointer */
	char arg1[NSTRING];	/* value of first argument */
	char arg2[NSTRING];	/* value of second argument */
	char arg3[NSTRING];	/* value of third argument */
	static char result[2 * NSTRING];	/* string result */

	/* look the function up in the function table */
	fname[3] = 0;		/* only first 3 chars significant */
	mklower(fname);		/* and let it be upper or lower case */
	for (fnum = 0; fnum < ARRAY_SIZE(funcs); fnum++)
		if (strcmp(fname, funcs[fnum].f_name) == 0)
			break;

	/* return errorm on a bad reference */
	if (fnum == ARRAY_SIZE(funcs))
		return errorm;

	/* if needed, retrieve the first argument */
	if (funcs[fnum].f_type >= MONAMIC) {
		if ((status = macarg(arg1)) != TRUE)
			return errorm;

		/* if needed, retrieve the second argument */
		if (funcs[fnum].f_type >= DYNAMIC) {
			if ((status = macarg(arg2)) != TRUE)
				return errorm;

			/* if needed, retrieve the third argument */
			if (funcs[fnum].f_type >= TRINAMIC)
				if ((status = macarg(arg3)) != TRUE)
					return errorm;
		}
	}


	/* and now evaluate it! */
	switch (fnum) {
	case UFADD:
		return itoa(atoi(arg1) + atoi(arg2));
	case UFSUB:
		return itoa(atoi(arg1) - atoi(arg2));
	case UFTIMES:
		return itoa(atoi(arg1) * atoi(arg2));
	case UFDIV:
		return itoa(atoi(arg1) / atoi(arg2));
	case UFMOD:
		return itoa(atoi(arg1) % atoi(arg2));
	case UFNEG:
		return itoa(-atoi(arg1));
	case UFCAT:
		strcpy(result, arg1);
		return strcat(result, arg2);
	case UFLEFT:
		return strncpy(result, arg1, atoi(arg2));
	case UFRIGHT:
		return (strcpy(result,
			       &arg1[(strlen(arg1) - atoi(arg2))]));
	case UFMID:
		return (strncpy(result, &arg1[atoi(arg2) - 1],
				atoi(arg3)));
	case UFNOT:
		return ltos(stol(arg1) == FALSE);
	case UFEQUAL:
		return ltos(atoi(arg1) == atoi(arg2));
	case UFLESS:
		return ltos(atoi(arg1) < atoi(arg2));
	case UFGREATER:
		return ltos(atoi(arg1) > atoi(arg2));
	case UFSEQUAL:
		return ltos(strcmp(arg1, arg2) == 0);
	case UFSLESS:
		return ltos(strcmp(arg1, arg2) < 0);
	case UFSGREAT:
		return ltos(strcmp(arg1, arg2) > 0);
	case UFIND:
		return strcpy(result, getval(arg1));
	case UFAND:
		return ltos(stol(arg1) && stol(arg2));
	case UFOR:
		return ltos(stol(arg1) || stol(arg2));
	case UFLENGTH:
		return itoa(strlen(arg1));
	case UFUPPER:
		return mkupper(arg1);
	case UFLOWER:
		return mklower(arg1);
	case UFTRUTH:
		return ltos(atoi(arg1) == 42);
	case UFASCII:
		return itoa((int) arg1[0]);
	case UFCHR:
		result[0] = atoi(arg1);
		result[1] = 0;
		return result;
	case UFGTKEY:
		result[0] = tgetc();
		result[1] = 0;
		return result;
	case UFRND:
		return itoa((ernd() % abs(atoi(arg1))) + 1);
	case UFABS:
		return itoa(abs(atoi(arg1)));
	case UFSINDEX:
		return itoa(sindex(arg1, arg2));
	case UFENV:
#if	ENVFUNC
		tsp = getenv(arg1);
		return tsp == NULL ? "" : tsp;
#else
		return "";
#endif
	case UFBIND:
		return transbind(arg1);
	case UFEXIST:
		return ltos(fexist(arg1));
	case UFFIND:
		tsp = flook(arg1, TRUE);
		return tsp == NULL ? "" : tsp;
	case UFBAND:
		return itoa(atoi(arg1) & atoi(arg2));
	case UFBOR:
		return itoa(atoi(arg1) | atoi(arg2));
	case UFBXOR:
		return itoa(atoi(arg1) ^ atoi(arg2));
	case UFBNOT:
		return itoa(~atoi(arg1));
	case UFXLATE:
		return xlat(arg1, arg2, arg3);
	}

	exit(-11);		/* never should get here */
}