Ejemplo n.º 1
0
void addemail4parent(char* mailid,pid_t childpid){
	char domainname[80];
	getdomain(mailid,domainname);
	domainData newdomain;
	strcpy(newdomain.domain,domainname);
	newdomain.pid=childpid;
	data[noDomains]=newdomain;
	noDomains++;
    sleep(2);
    kill(childpid,SIGUSR1);
    sleep(2);
}
Ejemplo n.º 2
0
int *NEWinserteffectlits(int *a,Seff *se,int *b) {
  int *vals;
  switch(se->t) {
  case SEpatom: *a = fePLIT(atomindex(se->a,b)); return a+1;
  case SEnatom: *a = feNLIT(atomindex(se->a,b)); return a+1;
  case SEconj: return NEWinserteffectlitsL(a,se->juncts,b);
  case SEwhen: return a;
  case SEforall:
    vals = getdomain(se->ss->t);
    while(*vals != -1) {
      b[-1-se->ss->v] = *vals;

      a = NEWinserteffectlits(a,se->effect,b);

      vals = vals + 1;
    }
    return a;

  default: return a;
  }
}
Ejemplo n.º 3
0
void NEWgroundoperators() {
  int i,j;
  int *domains[1000];
  int binding[1000];
  int staticrestriction[1000];
  atom *al;

  NEWpreprocessoperators();

  initactions(); /* initialize the ground action data structure */
  initatomtable(); /* initialize the tables for atoms */

  for(i=0;i<nOfSActions;i++) {
    typedvarlist *params = Sactions[i].params;
    typedvarlist *l = params;

    if(flagShowInput) {
      printf("Grounding schema %i:%s\n",i,symbol(Sactions[i].name));
      printSaction(&Sactions[i]);
    }

    /* Fetch domains of the parameters */
    nOfBindings = 0;
    while(l != NULL) {
      staticrestriction[nOfBindings] = occursinstatic(nOfBindings,Sactions[i].precon);
#ifdef DEBUG
      if(staticrestriction[nOfBindings]) {
	printf("Parameter %i is static.\n",nOfBindings);
	printSaction(&Sactions[i]);
      } else { printf("."); }
#endif
#ifdef ASSERTS
      assert(isvar(l->v));
#endif
      domains[nOfBindings] = getdomain(l->t);
      nOfBindings += 1;
      l = l->tl;
    }

#ifdef ASSERTS
    assert(nOfBindings < 100);
#endif

    /* Go through all parameter assignments and ground */

    NEWgothrough(0,i,domains,staticrestriction);

  }

  goal = NEWgroundfma(Sgoal,binding);

  /* Go through the initial state description to assign
     indices to initial state atoms. */

  al = Sinit;
  while(*al != NULL) {
    atomindex(*al,NULL);
    al = al + 1;
  }

  initialstate = (int *)malloc(sizeof(int) * nOfAtoms);
  for(i=0;i<nOfAtoms;i++) initialstate[i] = 0;

  al = Sinit;
  while(*al != NULL) {
    j = atomindex(*al,NULL);
    initialstate[j] = 1;

#ifdef ASSERTS
    assert(j>=0); assert(j<nOfAtoms);
#endif

    al = al + 1;
  }

}
Ejemplo n.º 4
0
fma *NEWgroundfma(Sfma *sf,int *b) {
  int *vals;
  fma *f = (fma *)malloc(sizeof(fma));

  switch(Sfmatypeof(sf)) {

  case STRUE: f->t = TRUE; break;
  case SFALSE: f->t = FALSE; break;

  case Sconj:
    f->t = conj;
    f->juncts = NEWgroundfmalist(sf->juncts,b);
    break;

  case Sdisj:
    f->t = disj;
    f->juncts = NEWgroundfmalist(sf->juncts,b);
    break;

  case Seq:
    if(bvalue(sf->p1,b) == bvalue(sf->p2,b)) {
      f->t = TRUE;
    } else {
      f->t = FALSE;
    }
    break;

  case Sneq:
    if(bvalue(sf->p1,b) == bvalue(sf->p2,b)) {
      f->t = FALSE;
    } else {
      f->t = TRUE;
    }
    break;

  case Spatom:
    f->t = patom;
    f->a = atomindex(sf->a,b);
    break;

  case Snatom:
    f->t = natom;
    f->a = atomindex(sf->a,b);
    break;

  case Sforall:  /* Iterate over all values of the variable. */

    f->t = conj;
    f->juncts = NULL;

    vals = getdomain(sf->ss->t);

    while(*vals != -1) {
      b[-1-sf->ss->v] = *vals;
      f->juncts = fmacons(NEWgroundfma(sf->f,b),f->juncts);
      vals = vals + 1;
    }
    break;

  case Sforsome: /* Iterate over all values of the variable. */

    f->t = disj;
    f->juncts = NULL;

    vals = getdomain(sf->ss->t);

    while(*vals != -1) {
      b[-1-sf->ss->v] = *vals;
      f->juncts = fmacons(NEWgroundfma(sf->f,b),f->juncts);
      vals = vals + 1;
    }
    break;
  }
  return f;
}
Ejemplo n.º 5
0
eff *NEWlocateconditionals(Seff *se,int *b,eff *ac,int whennesting) {
  int *vals,i,*ptr;
  eff *e,*ac0;
  Sefflist *ses;

  switch(se->t) {

  case SEconj:
    ses = se->juncts;
    while(ses != NULL) {
      ac = NEWlocateconditionals(ses->hd,b,ac,whennesting);
      ses = ses->tl;
    }
    return ac;

  case SEwhen:
    e = (eff *)malloc(sizeof(eff));

    whenstack[whennesting] = se->cond;
    ac0 = NEWlocateconditionals(se->effect,b,ac,whennesting+1);

    if(se->cond->t == SFALSE) return ac0;
    if(!someunconditional(se->effect)) return ac0;

    if(whennesting == 0) { /* Non-nested when */

      e->condition = NEWgroundfma(se->cond,b);
#ifdef CFMA
      e->ccondition = Cgroundfma(se->cond,b);
      //      printcfma(e->ccondition);
#endif

    } else{ /* Nesting of 2 or more whens */

      fmalist *fs = NULL;
      for(i=0;i<=whennesting;i++) {
	fs = fmacons(NEWgroundfma(whenstack[i],b),fs);
      }
      e->condition = (fma *)malloc(sizeof(fma));
      e->condition->t = conj;
      e->condition->juncts = fs;
    }

    e->effectlits = (int *)malloc((NEWnOfEffectLits(se->effect)+1) * sizeof(int));
    ptr = NEWinserteffectlits(e->effectlits,se->effect,b);
    *ptr = -1;
    e->tl = ac0;
    return e;

  case SEforall:

    vals = getdomain(se->ss->t);

    while(*vals != -1) {
      b[-1-se->ss->v] = *vals;

      ac = NEWlocateconditionals(se->effect,b,ac,whennesting);

      vals = vals + 1;
    }
    return ac;

  default: return ac;
  }
}
Ejemplo n.º 6
0
void run(){
	char domainname[80];
	char op[20],mailid[80],temp[80];
	char* add_email="add_email";
	struct sigaction usr_action;
	sigset_t block_mask;

	printf("Enter op: ");
	scanf("%s",op);
		if(comparestr(op,"add_email")){
			printf("Entered addition zone. Enter mailid\n");
			scanf("%s",mailid);
			strcpy(temp,mailid);
			getdomain(temp,domainname);
			int searchVal=searchDomain(domainname);
			if(searchVal == -1){	//create new domain
				printf("\n------------------------------------\nAdding a new process\n");


				//fork a new process here
				pid_t childpid; /* variable to store the child's pid */
				int retval;     /* child process: user-provided return code */
				int status;     /* parent process: child's exit status */
				
				/* only 1 int variable is needed because each process would have its
				   own instance of the variable
				   here, 2 int variables are used for clarity */
				    
				/* now create new process */
				
				childpid = fork();
				
				if (childpid >= 0) /* fork succeeded */
				{
					if (childpid == 0){ /* fork() returns 0 to the child process */
						noEmails=0;
						sigfillset (&block_mask);
						usr_action.sa_handler = child_handler;
						usr_action.sa_mask = block_mask;
						usr_action.sa_flags = 0;
						sigaction (SIGUSR1, &usr_action, NULL);
						
						struct sigaction act2;
						
						memset (&act2, '\0', sizeof(act2));
						
						/* Use the sa_sigaction field because the handles has two additional parameters */
						act2.sa_sigaction = &child_handler_kill;
						
						/* The SA_SIGINFO flag tells sigaction() to use the sa_sigaction field, not sa_handler. */
						act2.sa_flags = SA_SIGINFO;
						
						if (sigaction(SIGTERM, &act2, NULL) < 0) {
						    printf ("sigaction");
						}
						while(1){;}
				    	
				    }
					// connect to (and possibly create) the segment: //
			           if(childpid > 0){
			           		sigfillset (&block_mask);
			           		usr_action.sa_handler = parent_handler;
			           		usr_action.sa_mask = block_mask;
			           		usr_action.sa_flags = 0;
			           		sigaction (SIGUSR2, &usr_action, NULL);	
				         
			           		strcpy(p2cshared->email, mailid);
			           		strcpy(p2cshared->op, op);
				    		addemail4parent(mailid,childpid);
				       	}
				   
				}
				else /* fork returns -1 on failure */
				{
				    perror("fork"); /* display error message */
				    exit(0); 
				}
			}



			else{
	           	strcpy(p2cshared->email, mailid);
	           	strcpy(p2cshared->op, op);
	    		sleep(2);
	    		kill(data[searchVal].pid,SIGUSR1);
	    		sleep(2);      

			}
		}
		else if(comparestr(op,"delete_email")){
			printf("Entered deleting zone. Enter mailid\n");
			scanf("%s",mailid);
			operationp(mailid,op);
		}
		else if(comparestr(op,"search_email")){
			printf("Entered searching zone. Enter mailid\n");
			scanf("%s",mailid);
			operationp(mailid,op);
		}
		else if(comparestr(op,"delete_domain")){
			printf("Entered deleting zone. Enter mailid\n");
			scanf("%s",mailid);
			int id=searchDomain(mailid);
			if(id==-1){
				printf("Parent: Domain does not exist\n");
			}
			else{
				kill(data[id].pid,SIGTERM);
				waitpid(data[id].pid, 0, 0); //important for wait so that child doesnt become zombie
				                                    //A child that terminates, but has not been waited for becomes a "zombie". 
				printf("Parent process - Domain %s with PID - %d deleted\n", mailid, data[id].pid);
				data[id].pid = -1;
				data[id].domain[0]='\0';
			}
		}
		else if(comparestr(op,"Quit")){
			printf("Quit\n");
			int i=0;
			for(i=0;i<noDomains;i++){
			    if(data[i].pid != 0){
			         
			         kill(data[i].pid, SIGTERM); 
			         waitpid(data[i].pid, 0, 0); //important for wait so that child doesnt become zombie
			     }
			}
			printf("Parent : Killed all children, now suicide awaits\n");
			//raise(SIGKILL);
			
		}
		else{
			printf("Incorrect input: try again");
		}
	    
}
Ejemplo n.º 7
0
struct address *
verify(struct letter *let, struct domain *dom, char *p, int flags, int *reason)
{
    char *e = p + strlen(p);
    int bad = 0;
    struct address *ret;
    extern char *addr(char*,int*);
    struct iplist mxes;
    int i;

    while ( (e > p) && (isspace(e[-1]) || e[-1] == '\r' || e[-1] == '\n') )
	--e;
    if (*e)
	*e = 0;

    if ((e > p) && (ret = mkaddress(addr(p, &bad))) ) {
	if (ret->domain) {
	    ret->local = 0;
	    /* check that there is an mx (or A record) for the mail domain;
	     * if that fails we fail unless verify_from is off and it's
	     * a MAIL FROM:<> address
	     */
	    if ( (getMXes(ret->domain, 1, &mxes) > 0) ) {
		for (i=0; i < mxes.count; i++)
		    if ( localIP(let->env, &mxes.a[i] ) ) {
			/* we are a legitimate mx for this address.
			 */
			ret->local = 1;
			if ( (i == 0) || !(let->env->mxpool) ) {
			    /* If we're not mxpooling, we handle mail for
			     * this domain locally, but if we are mxpooling
			     * we only handle the mail locally if we're the
			     * best mx for the domain
			     */
			    ret->deliver_here = 1;
			    ret->dom = getdomain(ret->domain);
			}
			break;
		    }
		freeiplist(&mxes);
	    }
	    else if ( !okayanyhow(let->env,flags) ) {
		if (reason) *reason = V_NOMX;
		freeaddress(ret);
		return 0;
	    }

	}
	else {
	    ret->deliver_here = ret->local = 1;
	    ret->dom = dom;
	}

	if (ret->deliver_here && (!userok(let,ret)) && (flags & VF_USER) ) {
	    if (reason) *reason = V_WRONG;
	    freeaddress(ret);
	    return 0;
	}
	return ret;
    }
    if (reason) { *reason = bad ? V_BOGUS : V_ERROR; }
    return 0;
}
Ejemplo n.º 8
0
int main(int argc, char *argv[]) {

    int i,j/*,k,test*/;
    int ndomain,total,add;
    int gottrans;
    int T_FLAG;

    /*  char c; */
    char *env;
    char *deffile,*keyword,*value;

    FILE *PARMS,*TRANS,*PDB;

    struct parameters *parms;
    struct domain_loc *domain;

    if(argc<2) exit_error();

    /* get environment variable */
    if((env=getenv("STAMPDIR"))==NULL) {
        fprintf(stderr,"error: environment variable STAMPDIR must be set\n");
        exit(-1);
    }
    parms=(struct parameters*)malloc(sizeof(struct parameters));

    strcpy(parms[0].stampdir,env);

    /* read in default parameters from $STAMPDIR/stamp.defaults */
    deffile=(char*)malloc(1000*sizeof(char));
#if defined(_MSC_VER)
    sprintf(deffile,"%s\\stamp.defaults",env);
#else
    sprintf(deffile,"%s/stamp.defaults",env);
#endif
    if((PARMS=fopen(deffile,"r"))==NULL) {
        fprintf(stderr,"error: default parameter file %s does not exist\n",deffile);
        exit(-1);
    }
    if(getpars(PARMS,parms)==-1) exit(-1);
    fclose(PARMS);

    /* define DSSP directory file name */
    sprintf(&parms[0].dsspfile[0],"%s/dssp.directories",env);

    /* now search the command line for commands */
    keyword=(char*)malloc(1000*sizeof(char));
    value=(char*)malloc(1000*sizeof(char));
    for(i=1; i<argc; ++i) {
        if(argv[i][0]!='-') exit_error();
        strcpy(keyword,&argv[i][1]);
        if(i+1<argc) strcpy(value,argv[i+1]);
        else strcpy(value,"none");
        for(j=0; j<strlen(keyword); ++j)
            keyword[j]=ltou(keyword[j]); /* change to upper case */
        T_FLAG=(value[0]=='Y' || value[0]=='y' || value[0]=='1' ||
                value[0]=='T' || value[0]=='t' || value[0]=='o' ||
                value[0]=='O');
        /* enables one to write '1', 'YES', 'Yes', 'yes', 'T_FLAG', 'True' or 'true' to
         *  set any boolean parmsiable to one */
        if((strcmp(&argv[i][1],"l")==0) || (strcmp(&argv[i][1],"f")==0) || (strcmp(&argv[i][1],"p")==0)) {
            if(i+1>=argc) exit_error();
            /* listfile name */
            strcpy(parms[0].listfile,argv[i+1]);
            i++;
        } else if(strcmp(&argv[i][1],"P")==0) {
            /* want to read in parameter file */
            if(i+1>=argc) exit_error();
            if((PARMS=fopen(argv[i+1],"r"))==NULL) {
                fprintf(stderr,"error opening file %s\n",argv[i+1]);
                exit(-1);
            }
            if(getpars(PARMS,parms)==-1) exit(-1);
            fclose(PARMS);
            i++;
        } else if(strcmp(&argv[i][1],"o")==0) {
            /* output file */
            if(i+1>=argc) exit_error();
            strcpy(parms[0].logfile,argv[i+1]);
            i++;
        } else if(strcmp(&argv[i][1],"help")==0) {
            help_exit_error();
        } else if((strcmp(&argv[i][1],"V")==0) || (strcmp(&argv[i][1],"v")==0)) {
            parms[0].verbose=1;
            strcpy(parms[0].logfile,"stdout");
        } else if(strcmp(&argv[i][1],"s")==0) {
            parms[0].SCAN=1;
            parms[0].TREEWISE=parms[0].PAIRWISE=0;
        } else if(strcmp(&argv[i][1],"n")==0) {
            if(i+1>=argc) exit_error();
            sscanf(argv[i+1],"%d",&parms[0].NPASS);
            i++;
            if(parms[0].NPASS!=1 && parms[0].NPASS!=2) exit_error();
        } else if(strcmp(keyword,"PAIRPEN") == 0 || strcmp(keyword,"PEN")==0 || strcmp(keyword,"SECOND_PAIRPEN")==0) {
            sscanf(value,"%f",&parms[0].second_PAIRPEN);
            i++;
        } else if(strcmp(keyword,"FIRST_PAIRPEN")==0) {
            sscanf(value,"%f",&parms[0].first_PAIRPEN);
            i++;
        } else if(strcmp(keyword,"MAXPITER") == 0 || strcmp(keyword,"MAXSITER") == 0) {
            sscanf(value,"%d",&parms[0].MAXPITER);
            i++;
        } else if(strcmp(keyword,"MAXTITER") == 0) {
            sscanf(value,"%d",&parms[0].MAXTITER);
            i++;
        } else if(strcmp(keyword,"TREEPEN") == 0 || strcmp(keyword,"SECOND_TREEPEN")==0) {
            sscanf(value,"%f",&parms[0].second_TREEPEN);
            i++;
        } else if(strcmp(keyword,"FIRST_TREEPEN")==0) {
            sscanf(value,"%f",&parms[0].first_TREEPEN);
            i++;
        } else if(strcmp(keyword,"SCORETOL") == 0) {
            sscanf(value,"%f",&parms[0].SCORETOL);
            i++;
        } else if(strcmp(keyword,"CLUSTMETHOD") == 0) {
            sscanf(value,"%d",&parms[0].CLUSTMETHOD);
            i++;
        } else if(strcmp(keyword,"E1") == 0 || strcmp(keyword,"SECOND_E1")==0) {
            sscanf(value,"%f",&parms[0].second_E1);
            i++;
        } else if(strcmp(keyword,"E2") == 0 || strcmp(keyword,"SECOND_E2")==0) {
            sscanf(value,"%f",&parms[0].second_E2);
            i++;
        } else if(strcmp(keyword,"FIRST_E1")==0) {
            sscanf(value,"%f",&parms[0].first_E1);
            i++;
        } else if(strcmp(keyword,"FIRST_E2")==0) {
            sscanf(value,"%f",&parms[0].first_E2);
            i++;
        } else if(strcmp(keyword,"NPASS")==0) {
            sscanf(value,"%d",&parms[0].NPASS);
            i++;
            if(parms[0].NPASS!=1 && parms[0].NPASS!=2) {
                fprintf(stderr,"error: NPASS must be either 1 or 2\n");
                return -1;
            }
        } else if(strcmp(keyword,"CUTOFF") == 0 || strcmp(keyword,"SECOND_CUTOFF")==0) {
            sscanf(value,"%f",&parms[0].second_CUTOFF);
            i++;
        } else if(strcmp(keyword,"FIRST_CUTOFF")==0)  {
            sscanf(value,"%f",&parms[0].first_CUTOFF);
            i++;
        } else if(strcmp(keyword,"TREEPLOT") == 0) {
            parms[0].TREEPLOT=T_FLAG;
            i++;
        } else if(strcmp(keyword,"PAIRPLOT") == 0) {
            parms[0].PAIRPLOT=T_FLAG;
            i++;
        } else if(strcmp(keyword,"NALIGN") == 0) {
            sscanf(value,"%d",&parms[0].NALIGN);
            i++;
        } else if(strcmp(keyword,"DISPALL") == 0) {
            parms[0].DISPALL=T_FLAG;
            i++;
        } else if(strcmp(keyword,"HORIZ") ==0) {
            parms[0].HORIZ=T_FLAG;
            i++;
        } else if(strcmp(keyword,"ADD") ==0) {
            sscanf(value,"%f",&parms[0].ADD);
            i++;
        } else if(strcmp(keyword,"NMEAN") ==0) {
            sscanf(value,"%f",&parms[0].NMEAN);
            i++;
        } else if(strcmp(keyword,"NSD") ==0) {
            sscanf(value,"%f",&parms[0].NSD);
            i++;
        } else if(strcmp(keyword,"STATS") ==0) {
            parms[0].STATS=T_FLAG;
            i++;
        } else if(strcmp(keyword,"NA") == 0) {
            sscanf(value,"%f",&parms[0].NA);
            i++;
        } else if(strcmp(keyword,"NB") == 0) {
            sscanf(value,"%f",&parms[0].NB);
            i++;
        } else if(strcmp(keyword,"NASD") == 0) {
            sscanf(value,"%f",&parms[0].NASD);
            i++;
        } else if(strcmp(keyword,"NBSD") == 0) {
            sscanf(value,"%f",&parms[0].NBSD);
            i++;
        } else if(strcmp(keyword,"PAIRWISE") == 0)  {
            parms[0].PAIRWISE=T_FLAG;
            i++;
        } else if(strcmp(keyword,"TREEWISE") == 0) {
            parms[0].TREEWISE=T_FLAG;
            i++;
        } else if(strcmp(keyword,"ORDFILE") == 0) {
            strcpy(parms[0].ordfile,value);
            i++;
        } else if(strcmp(keyword,"TREEFILE") == 0) {
            strcpy(parms[0].treefile,value);
            i++;
        } else if(strcmp(keyword,"PLOTFILE") == 0) {
            strcpy(parms[0].plotfile,value);
            i++;
        } else if(strcmp(keyword,"PREFIX") == 0 || strcmp(keyword,"TRANSPREFIX")==0 || strcmp(keyword,"STAMPPREFIX")==0) {
            strcpy(parms[0].transprefix,value);
            i++;
        } else if(strcmp(keyword,"MATFILE") == 0) {
            strcpy(parms[0].matfile,value);
            i++;
        } else if(strcmp(keyword,"THRESH") ==0) {
            sscanf(value,"%f",&parms[0].THRESH);
            i++;
        } else if(strcmp(keyword,"TREEALIGN")==0) {
            parms[0].TREEALIGN=T_FLAG;
            i++;
        } else if(strcmp(keyword,"TREEALLALIGN")==0) {
            parms[0].TREEALLALIGN=T_FLAG;
            i++;
        } else if(strcmp(keyword,"PAIRALIGN")==0 || strcmp(keyword,"SCANALIGN")==0)  {
            parms[0].PAIRALIGN=T_FLAG;
            i++;
        } else if(strcmp(keyword,"PAIRALLALIGN")==0 || strcmp(keyword,"SCANALLALIGN")==0) {
            parms[0].PAIRALLALIGN=T_FLAG;
            i++;
        } else if(strcmp(keyword,"PRECISION")==0) {
            sscanf(value,"%d",&parms[0].PRECISION);
            i++;
        } else if(strcmp(keyword,"MAX_SEQ_LEN")==0) {
            sscanf(value,"%d",&parms[0].MAX_SEQ_LEN);
            i++;
        } else if(strcmp(keyword,"ROUGHFIT")==0) {
            parms[0].ROUGHFIT=T_FLAG;
            i++;
        } else if(strcmp(keyword,"ROUGH")==0) {
            parms[0].ROUGHFIT=1;
        } else if(strcmp(keyword,"ROUGHOUT")==0) {
            parms[0].roughout=1;
        } else if(strcmp(keyword,"ROUGHOUTFILE")==0) {
            if(i+1>=argc) exit_error();
            strcpy(&parms[0].roughoutfile[0],argv[i+1]);
            i++;
            parms[0].roughout=1;
        } else if(strcmp(keyword,"BOOLCUT")==0 || strcmp(keyword,"SECOND_BOOLCUT")==0) {
            sscanf(value,"%f",&parms[0].second_BOOLCUT);
            i++;
        } else if(strcmp(keyword,"FIRST_BOOLCUT")==0) {
            sscanf(value,"%f",&parms[0].first_BOOLCUT);
            i++;
        } else if(strcmp(keyword,"SCANSLIDE")==0) {
            sscanf(value,"%d",&parms[0].SCANSLIDE);
            i++;
        } else if(strcmp(keyword,"SCAN")==0) {
            parms[0].SCAN=T_FLAG;
            i++;
            if(T_FLAG)
                parms[0].PAIRWISE=parms[0].TREEWISE=0;
        } else if(strcmp(keyword,"SCANMODE")==0) {
            sscanf(value,"%d",&parms[0].SCANMODE);
            i++;
            if(parms[0].SCANMODE==1) parms[0].PAIRALIGN=1;
        } else if(strcmp(keyword,"SCANCUT")==0)  {
            sscanf(value,"%f",&parms[0].SCANCUT);
            i++;
        } else if(strcmp(keyword,"SECSCREEN")==0) {
            parms[0].SECSCREEN=T_FLAG;
            i++;
        } else if(strcmp(keyword,"SECSCREENMAX")==0) {
            sscanf(value,"%f",&parms[0].SECSCREENMAX);
            i++;
        } else if(strcmp(keyword,"SCANTRUNC")==0) {
            parms[0].SCANTRUNC=T_FLAG;
            i++;
        } else if(strcmp(keyword,"SCANTRUNCFACTOR")==0) {
            sscanf(value,"%f",&parms[0].SCANTRUNCFACTOR);
            i++;
        } else if(strcmp(keyword,"DATABASE")==0) {
            strcpy(&parms[0].database[0],value);
            i++;
        } else if(strcmp(keyword,"SCANFILE")==0) {
            strcpy(&parms[0].scanfile[0],value);
            i++;
        } else if(strcmp(keyword,"LOGFILE")==0) {
            strcpy(&parms[0].logfile[0],value);
            i++;
        } else if(strcmp(keyword,"SECTYPE")==0) {
            sscanf(value,"%d",&parms[0].SECTYPE);
            i++;
        } else if(strcmp(keyword,"SCANSEC")==0) {
            sscanf(value,"%d",&parms[0].SCANSEC);
            i++;
        } else if(strcmp(keyword,"SECFILE")==0) {
            strcpy(&parms[0].secfile[0],value);
            i++;
            parms[0].SECTYPE=2;
        } else if(strcmp(keyword,"BOOLEAN")==0) {
            parms[0].BOOLEAN=T_FLAG;
            i++;
        } else if(strcmp(keyword,"BOOLMETHOD")==0) {
            sscanf(value,"%d",&parms[0].BOOLMETHOD);
            i++;
        } else if(strcmp(keyword,"LISTFILE")==0) {
            strcpy(&parms[0].listfile[0],value);
            i++;
        } else if(strcmp(keyword,"STAMPDIR")==0) {
            strcpy(&parms[0].stampdir[0],value);
            i++;
        } else if(strcmp(keyword,"CLUST")==0) {
            parms[0].CLUST=T_FLAG;
            i++;
        } else if(strcmp(keyword,"COLUMNS")==0) {
            sscanf(value,"%d",&parms[0].COLUMNS);
            i++;
        } else if(strcmp(keyword,"SW")==0) {
            sscanf(value,"%d",&parms[0].SW);
            i++;
        } else if(strcmp(keyword,"CCFACTOR")==0) {
            sscanf(value,"%f",&parms[0].CCFACTOR);
            i++;
        } else if(strcmp(keyword,"CCADD")==0) {
            parms[0].CCADD=T_FLAG;
            i++;
        } else if(strcmp(keyword,"MINFIT")==0) {
            sscanf(value,"%d",&parms[0].MINFIT);
            i++;
        } else if(strcmp(keyword,"ROUGHALIGN")==0) {
            strcpy(parms[0].roughalign,value);
            i++;
        } else if(strcmp(keyword,"FIRST_THRESH")==0) {
            sscanf(value,"%f",&parms[0].first_THRESH);
            i++;
        } else if(strcmp(keyword,"MIN_FRAC")==0) {
            sscanf(value,"%f",&parms[0].MIN_FRAC);
            i++;
        } else if(strcmp(keyword,"SCORERISE")==0) {
            parms[0].SCORERISE=T_FLAG;
            i++;
        } else if(strcmp(keyword,"SKIPAHEAD")==0) {
            parms[0].SKIPAHEAD=T_FLAG;
            i++;
        } else if(strcmp(keyword,"SCANSCORE")==0) {
            sscanf(value,"%d",&parms[0].SCANSCORE);
            i++;
        } else if(strcmp(keyword,"PAIROUTPUT")==0) {
            parms[0].PAIROUTPUT=T_FLAG;
            i++;
        } else if(strcmp(keyword,"ALLPAIRS")==0) {
            parms[0].ALLPAIRS=T_FLAG;
            i++;
        } else if (strcmp(keyword,"ATOMTYPE")==0) {
            parms[0].ATOMTYPE=T_FLAG;
            i++;
        } else if(strcmp(keyword,"DSSP")==0) {
            parms[0].DSSP=T_FLAG;
            i++;
        } else if(strcmp(keyword,"SLOWSCAN")==0) {
            parms[0].SLOWSCAN=T_FLAG;
            i++;
        } else if(strcmp(keyword,"SLOW")==0) {
            parms[0].SLOWSCAN=1;
        } else if(strcmp(keyword,"CUT")==0) {
            parms[0].CO=1;
        } else if(strcmp(&argv[i][1],"slide")==0) {
            if(i+1>=argc) exit_error();
            sscanf(argv[i+1],"%d",&parms[0].SCANSLIDE);
            i++;
        } else if(strcmp(&argv[i][1],"d")==0) {
            /* database file */
            if(i+1>=argc) exit_error();
            strcpy(&parms[0].database[0],argv[i+1]);
            i++;
        } else if(strcmp(&argv[i][1],"pen1")==0) {
            if(i+1>=argc) exit_error();
            sscanf(argv[i+1],"%f",&parms[0].first_PAIRPEN);
            i++;
        } else if(strcmp(&argv[i][1],"pen2")==0) {
            if(i+1>=argc) exit_error();
            sscanf(argv[i+1],"%f",&parms[0].second_PAIRPEN);
            i++;
        } else if(strcmp(&argv[i][1],"prefix")==0) {
            if(i+1>=argc) exit_error();
            strcpy(&parms[0].transprefix[0],argv[i+1]);
            i++;
        } else if(strcmp(&argv[i][1],"scancut")==0) {
            if(i+1>=argc) exit_error();
            sscanf(argv[i+1],"%f",&parms[0].SCANCUT);
            i++;
        } else if(strcmp(&argv[i][1],"opd")==0) {
            parms[0].opd=1;
        } else  {
            exit_error();
        }
    }
    free(keyword);
    free(value);


    /* make the names of all the output files using the prefix */
    sprintf(&parms[0].ordfile[0],"%s.ord",parms[0].transprefix);
    sprintf(&parms[0].treefile[0],"%s.tree",parms[0].transprefix);
    sprintf(&parms[0].plotfile[0],"%s.plot",parms[0].transprefix);
    sprintf(&parms[0].matfile[0],"%s.mat",parms[0].transprefix);
    sprintf(&parms[0].roughalign[0],"%s_align.rough",parms[0].transprefix);
    sprintf(&parms[0].scanfile[0],"%s.scan",parms[0].transprefix);

    if(strcmp(parms[0].logfile,"stdout")==0 ||
            strcmp(parms[0].logfile,"STDOUT")==0) {
        parms[0].LOG=stdout;
    } else if(strcmp(parms[0].logfile,"silent")==0 ||
              strcmp(parms[0].logfile,"SILENT")==0) {
#if defined(_MSC_VER)
        parms[0].LOG=stdout;
#else
        parms[0].LOG=fopen("/dev/null","w");
#endif
    } else {
        if((parms[0].LOG=fopen(parms[0].logfile,"w"))==NULL) {
            fprintf(stderr,"error opening file %s\n",parms[0].logfile);
            exit(-1);
        }
    }

    if(strcmp(parms[0].logfile,"silent")==0) {
        printf("\nSTAMP Structural Alignment of Multiple Proteins\n");
        printf(" by Robert B. Russell & Geoffrey J. Barton \n");
        printf(" Please cite PROTEINS, v14, 309-323, 1992\n\n");
    }
    fprintf(parms[0].LOG,"-------------------------------------------------------------------------------\n");
    fprintf(parms[0].LOG,"                                   S t A M P\n");
    fprintf(parms[0].LOG,"                             Structural Alignment of\n");
    fprintf(parms[0].LOG,"                               Multiple Proteins\n");
    fprintf(parms[0].LOG,"                     By Robert B. Russell & Geoffrey J. Barton \n");
    fprintf(parms[0].LOG,"                       Last Modified: %s\n",lastmod);
    fprintf(parms[0].LOG,"         Please cite Ref: Russell and GJ Barton, PROTEINS, v14, 309-323, 1992\n");
    fprintf(parms[0].LOG,"-------------------------------------------------------------------------------\n\n");


    fprintf(parms[0].LOG,"STAMPDIR has been set to %s\n\n\n",parms[0].stampdir);
    /* read in coordinate locations and initial transformations */
    if((TRANS = fopen(parms[0].listfile,"r")) == NULL) {
        fprintf(stderr,"error: file %s does not exist\n",parms[0].listfile);
        exit(-1);
    }
    /* determine the number of domains specified */
    ndomain=count_domain(TRANS);
    domain=(struct domain_loc*)malloc(ndomain*sizeof(struct domain_loc));
    rewind(TRANS);
    if(getdomain(TRANS,domain,&ndomain,ndomain,&gottrans,parms[0].stampdir,parms[0].DSSP,parms[0].LOG)==-1) exit(-1);
    fclose(TRANS);

    fprintf(parms[0].LOG,"Details of this run:\n");
    if(parms[0].PAIRWISE) fprintf(parms[0].LOG,"PAIRWISE mode specified\n");
    if(parms[0].TREEWISE) fprintf(parms[0].LOG,"TREEWISE mode specified\n");
    if(parms[0].SCAN) fprintf(parms[0].LOG,"SCAN mode specified\n");

    if(!parms[0].SCAN) {
        /* if no MINFIT has been given, then take the smallest length and divide it by two */
        if(parms[0].MINFIT==-1) {
            parms[0].MINFIT=parms[0].MAXLEN;
            for(i=0; i<ndomain; ++i) if(domain[i].ncoords<parms[0].MINFIT) parms[0].MINFIT=domain[i].ncoords;
            parms[0].MINFIT/=2;
        }
        fprintf(parms[0].LOG,"  pairwise score file: %s\n",parms[0].matfile);
        if(parms[0].TREEWISE) {
            fprintf(parms[0].LOG,"  tree order file: %s\n",parms[0].ordfile);
            fprintf(parms[0].LOG,"  tree file: %s\n",parms[0].treefile);
            fprintf(parms[0].LOG,"  tree plot file: %s\n",parms[0].plotfile);
        }
    } else {
        fprintf(parms[0].LOG,"   SCANMODE set to %d\n",parms[0].SCANMODE);
        fprintf(parms[0].LOG,"   SCANSCORE set to %d\n",parms[0].SCANSCORE);
        fprintf(parms[0].LOG,"    (see documentation for an explanation)\n");
        if(parms[0].opd==1) fprintf(parms[0].LOG,"   Domains will be skipped after the first match is found\n");
        if(parms[0].SCANMODE==1) {
            fprintf(parms[0].LOG,"     Transformations for Sc values greater than %f are to be output\n",parms[0].SCANCUT);
            fprintf(parms[0].LOG,"     to the file %s\n",parms[0].transprefix);
        } else {
            fprintf(parms[0].LOG,"     Only the scores are to be output to the file %s\n",parms[0].scanfile);
        }
        fprintf(parms[0].LOG,"  secondary structures are ");
        switch(parms[0].SCANSEC) {
        case 0:
            fprintf(parms[0].LOG," not to be considered\n");
            break;
        case 1:
            fprintf(parms[0].LOG," to be from DSSP\n");
            break;
        case 2:
            fprintf(parms[0].LOG," to be read in from %s\n",parms[0].secfile);
            break;
        default:
            fprintf(parms[0].LOG," not to be considered\n");
        }
        if(parms[0].SECSCREEN) {
            fprintf(parms[0].LOG,"   An initial screen on secondary structure content is to performed when possible\n");
            fprintf(parms[0].LOG,"   Secondary structure summaries farther than %6.2f %% apart result in\n",parms[0].SECSCREENMAX);
            fprintf(parms[0].LOG,"     a comparison being ignored\n");
        }
        fprintf(parms[0].LOG,"   Initial fits are to be performed by aligning the N-terminus of the query\n    with every %d residue of the database sequence\n",parms[0].SCANSLIDE);
        fprintf(parms[0].LOG,"    of the query along the database structure.\n");
        if(parms[0].SCANTRUNC) {
            fprintf(parms[0].LOG,"   If sequences in the database are > %5.3f x the query sequence length\n",parms[0].SCANTRUNCFACTOR);
            fprintf(parms[0].LOG,"    then a fraction of the the database structure, corresponding to this\n");
            fprintf(parms[0].LOG,"    of length %5.3f x the query, will be considered\n",parms[0].SCANTRUNCFACTOR);
            fprintf(parms[0].LOG,"   comparisons are to be ignored if the database structure is less than\n    %6.4f x the length of the query structure\n",parms[0].MIN_FRAC);
        }
        fprintf(parms[0].LOG,"   Domain database file to be scanned %s\n",parms[0].database);
    }

    if(parms[0].TREEWISE)
        fprintf(parms[0].LOG,"  output files prefix: %s\n",parms[0].transprefix);

    fprintf(parms[0].LOG,"\n\nParameters:\n");
    fprintf(parms[0].LOG,"Rossmann and Argos parameters:\n");
    if(parms[0].NPASS==2) {
        fprintf(parms[0].LOG,"  Two fits are to be performed, the first fit with:\n");
        fprintf(parms[0].LOG,"   E1=%7.3f,",parms[0].first_E1);
        fprintf(parms[0].LOG," E2=%7.3f,",parms[0].first_E2);
        fprintf(parms[0].LOG," CUT=%7.3f,",parms[0].first_CUTOFF);
        fprintf(parms[0].LOG," PAIRPEN=%7.3f,",parms[0].first_PAIRPEN);
        fprintf(parms[0].LOG," TREEPEN=%7.3f\n",parms[0].first_TREEPEN);
        /*	   fprintf(parms[0].LOG,"   E1=%7.3f, E2=%7.3f, CUT=%7.3f, PAIRPEN=%7.3f, TREEPEN=%7.3f\n",
           parms[0].first_E1,parms[0].first_E2,parms[0].first_CUTOFF,parms[0].first_PAIRPEN,parms[0].first_TREEPEN); */
        fprintf(parms[0].LOG,"  The second fit with:\n");
    } else
        fprintf(parms[0].LOG,"  One fit is to performed with:\n");
    fprintf(parms[0].LOG,"   E1=%7.3f, E2=%7.3f, CUT=%7.3f, PAIRPEN=%7.3f, TREEPEN=%7.3f\n",
            parms[0].second_E1,parms[0].second_E2,parms[0].second_CUTOFF,parms[0].second_PAIRPEN,parms[0].second_TREEPEN);
    if(parms[0].BOOLEAN) {
        fprintf(parms[0].LOG,"  BOOLEAN mode specified\n");
        fprintf(parms[0].LOG,"  A boolean matrix will be calculated corresponding to whether\n");
        fprintf(parms[0].LOG,"   positions have Pij values greater than:\n");
        if(parms[0].NPASS==2)
            fprintf(parms[0].LOG,"    %7.3f, for the first fit and\n",parms[0].first_BOOLCUT);
        fprintf(parms[0].LOG,"    %7.3f",parms[0].second_BOOLCUT);
        if(parms[0].NPASS==2)
            fprintf(parms[0].LOG," for the second fit.\n");
        else
            fprintf(parms[0].LOG,".\n");
        fprintf(parms[0].LOG,"  In the multiple case, this criteria must be satisfied for *all*\n");
        fprintf(parms[0].LOG,"   possible pairwise comparisons\n");
    }
    if(parms[0].SW==1) {
        fprintf(parms[0].LOG,"  Corner cutting is to be performed\n");
        fprintf(parms[0].LOG,"    Corner cutting length: %6.2f\n",parms[0].CCFACTOR);
        if(parms[0].CCADD)
            fprintf(parms[0].LOG,"    The length difference is to be added to this value\n");
    } else {
        fprintf(parms[0].LOG,"  The entire SW matrix is to be calculated and used\n");
    }
    fprintf(parms[0].LOG,"  The minimum length of alignment to be evaluated further is %3d residues\n",parms[0].MINFIT);
    fprintf(parms[0].LOG,"\n");
    fprintf(parms[0].LOG,"  Convergence tolerance SCORETOL= %f %%\n", parms[0].SCORETOL);
    fprintf(parms[0].LOG,"  Other parameters:\n");
    fprintf(parms[0].LOG,"    MAX_SEQ_LEN=%d, MAXPITER=%d, MAXTITER=%d\n",
            parms[0].MAX_SEQ_LEN,parms[0].MAXPITER,parms[0].MAXTITER);
    fprintf(parms[0].LOG,"    PAIRPLOT (SCANPLOT) = %d, TREEPLOT = %d, PAIRALIGN (SCANALIGN) = %d, TREEALIGN = %d\n",
            parms[0].PAIRPLOT,parms[0].TREEPLOT,parms[0].PAIRALIGN,parms[0].TREEALIGN);
    fprintf(parms[0].LOG,"    PAIRALLALIGN (SCANALLALIGN) = %d, TREEALLALIGN = %d\n",parms[0].PAIRALLALIGN,parms[0].TREEALLALIGN);

    if(!parms[0].BOOLEAN) {
        fprintf(parms[0].LOG,"\n\nDetails of Confidence value calculations:\n");
        if(parms[0].STATS) fprintf(parms[0].LOG,"  actual mean and standard deviations are to be\n   used for determination of Pij' values.\n");
        else {
            fprintf(parms[0].LOG,"  pre-set mean and standard deviations are to be used\n   and multiple comparisons are to be corrected.\n");
            fprintf(parms[0].LOG,"  mean Xt = %f, standard deviation SDt = %f\n", parms[0].NMEAN,parms[0].NSD);
            fprintf(parms[0].LOG,"  for the multiple case:\n");
            fprintf(parms[0].LOG,"    pairwise means are to be calculated from:\n      Xp = exp(%6.4f * log(length) + %6.4f)\n",parms[0].NA,parms[0].NB);
            fprintf(parms[0].LOG,"     and pairwise standard deviations from:\n     SDp = exp(%6.4f * log(length) + %6.4f)\n",parms[0].NASD,parms[0].NBSD);
            fprintf(parms[0].LOG,"    the mean to be used is calculated from:  \n      Xc =  (Xm/Xp) * Xt).\n");
            fprintf(parms[0].LOG,"     and the standard deviation from: \n     SDc = (SDm/SDp)*SDt).\n");
        } /* End of if(parms[0].STATS) */
    } else {
        fprintf(parms[0].LOG,"  Positional values will consist of one's or zeros depending on whether\n");
        fprintf(parms[0].LOG,"   a position satisfies the BOOLEAN criterion above\n");
        fprintf(parms[0].LOG,"  The score (Sp) for each alignment will be a sum of these positions.\n");
    } /* end of if(parms[0].BOOLEAN */

    if(!parms[0].SCAN && parms[0].TREEWISE) {
        fprintf(parms[0].LOG,"\n\nTree is to be generated by ");
        if(parms[0].CLUSTMETHOD==0) fprintf(parms[0].LOG,"1/rms values.\n");
        if(parms[0].CLUSTMETHOD==1) {
            fprintf(parms[0].LOG,"scores from path tracings modified as follows:\n");
            fprintf(parms[0].LOG,"    Sc = (Sp/Lp) * ((Lp-ia)/La) * ((Lp-ib)/Lb),\n");
            fprintf(parms[0].LOG,"    where Sp is the actual score, Lp is the path length.\n");
            fprintf(parms[0].LOG,"    and La & Lb are the lengths of the structures considered.\n");
        } /* End of if(parms[0].METHOD==2) */
    }
    fprintf(parms[0].LOG,"\n\n");

    fprintf(parms[0].LOG,"Reading coordinates...\n");
    for(i=0; i<ndomain; ++i) {
        fprintf(parms[0].LOG,"Domain %3d %s %s\n   ",i+1,domain[i].filename,domain[i].id);
        if((PDB=openfile(domain[i].filename,"r"))==NULL) {
            fprintf(stderr,"error opening file %s\n",domain[i].filename);
            exit(-1);
        }
        domain[i].ncoords=0;
        domain[i].coords=(int**)malloc(parms[0].MAX_SEQ_LEN*sizeof(int*));
        domain[i].aa=(char*)malloc((parms[0].MAX_SEQ_LEN+1)*sizeof(char));
        domain[i].numb=(struct brookn*)malloc((parms[0].MAX_SEQ_LEN)*sizeof(struct brookn));
        total=0;
        fprintf(parms[0].LOG,"    ");
        for(j=0; j<domain[i].nobj; ++j) {
            if(!parms[0].DSSP) {
                if(igetca(PDB,&domain[i].coords[total],&domain[i].aa[total],&domain[i].numb[total],
                          &add,domain[i].start[j],domain[i].end[j],domain[i].type[j],(parms[0].MAX_SEQ_LEN-total),
                          domain[i].reverse[j],parms[0].PRECISION,parms[0].ATOMTYPE,parms[0].LOG)==-1) {
                    fprintf(stderr,"Error in domain %s object %d \n",domain[i].id,j+1);
                    exit(-1);
                }
            } else {
                if(igetcadssp(PDB,&domain[i].coords[total],&domain[i].aa[total],&domain[i].numb[total],
                              &add,domain[i].start[j],domain[i].end[j],domain[i].type[j],(parms[0].MAX_SEQ_LEN-total),
                              domain[i].reverse[j],parms[0].PRECISION,parms[0].LOG)==-1) exit(-1);
            }
            switch(domain[i].type[j]) {
            case 1:
                fprintf(parms[0].LOG," all residues");
                break;
            case 2:
                fprintf(parms[0].LOG," chain %c",domain[i].start[j].cid);
                break;
            case 3:
                fprintf(parms[0].LOG," from %c %4d %c to %c %4d %c",
                        domain[i].start[j].cid,domain[i].start[j].n,domain[i].start[j].in,
                        domain[i].end[j].cid,domain[i].end[j].n,domain[i].end[j].in);
                break;
            }
            fprintf(parms[0].LOG,"%4d CAs ",add);
            total+=add;
            closefile(PDB,domain[i].filename);
            PDB=openfile(domain[i].filename,"r");
        }
        domain[i].ncoords=total;
        fprintf(parms[0].LOG,"=> %4d CAs in total\n",domain[i].ncoords);
        fprintf(parms[0].LOG,"Applying the transformation... \n");
        printmat(domain[i].R,domain[i].V,3,parms[0].LOG);
        fprintf(parms[0].LOG,"      ...to these coordinates.\n");
        matmult(domain[i].R,domain[i].V,domain[i].coords,domain[i].ncoords,parms[0].PRECISION);
        closefile(PDB,domain[i].filename);
    }
    fprintf(parms[0].LOG,"\n\n");
    fprintf(parms[0].LOG,"Secondary structure...\n");
    for(i=0; i<ndomain; ++i)
        domain[i].sec=(char*)malloc(parms[0].MAX_SEQ_LEN*sizeof(char));

    switch(parms[0].SECTYPE) {
    case 0: {
        fprintf(parms[0].LOG,"No secondary structure assignment will be considered\n");
        for(i=0; i<ndomain; ++i) {
            for(j=0; j<domain[i].ncoords; ++j) domain[i].sec[j]='?';
            domain[i].sec[j]='\0';
        }
        parms[0].SECSCREEN=0;
    }
    break;
    case 1: {
        fprintf(parms[0].LOG,"Will try to find Kabsch and Sander DSSP assignments\n");

        if(getks(domain,ndomain,parms)!=0) parms[0].SECSCREEN=0;
    }
    break;
    case 2: {
        fprintf(parms[0].LOG,"Reading in secondary structure assignments from file: %s\n",parms[0].secfile);
        if(getsec(domain,ndomain,parms)!=0) parms[0].SECSCREEN=0;
    }
    break;
    default: {
        fprintf(stderr,"error: unrecognised secondary structure assignment option\n");
        exit(-1);
    }
    }

    fprintf(parms[0].LOG,"\n\n");
    if(parms[0].SCAN) {
        i=0;
        fprintf(parms[0].LOG,"Scanning with domain %s\n",&(domain[i].id[0]));
        if(strcmp(parms[0].logfile,"silent")==0) {

            printf("Results of scan will be written to file %s\n",parms[0].scanfile);
            printf("Fits  = no. of fits performed, Sc = STAMP score, RMS = RMS deviation\n");
            printf("Align = alignment length, Nfit = residues fitted, Eq. = equivalent residues\n");
            printf("Secs  = no. equiv. secondary structures, %%I = seq. identity, %%S = sec. str. identity\n");
            printf("P(m)  = P value (p=1/10) calculated after Murzin (1993), JMB, 230, 689-694\n");
            printf("\n");
            printf("     Domain1         Domain2          Fits  Sc      RMS   Len1 Len2 Align Fit   Eq. Secs    %%I    %%S     P(m)\n");
        }

        if(parms[0].SLOWSCAN==1) {
            if(slow_scan(domain[i],parms)==-1) exit(-1);
        } else {
            if(scan(domain[i],parms)==-1) exit(-1);
        }
        if(strcmp(parms[0].logfile,"silent")==0)
            printf("See the file %s.scan\n",parms[0].transprefix);
        fprintf(parms[0].LOG,"\n");
    } else {
        if(parms[0].ROUGHFIT) if(roughfit(domain,ndomain,parms)==-1) exit(-1);
        if(parms[0].PAIRWISE) if(pairwise(domain,ndomain,parms)==-1) exit(-1);
        if(parms[0].TREEWISE) if(treewise(domain,ndomain,parms)==-1) exit(-1);
    } /* end of if(parms[0].SCAN... */

    /* freeing memory to keep purify happy */
    /*
      for(i=0; i<ndomain; ++i) {
      free(domain[i].aa);
      free(domain[i].sec);
      free(domain[i].v); free(domain[i].V);
      for(j=0; j<3; ++j) {
      free(domain[i].R[j]);
      free(domain[i].r[j]);
      }
      free(domain[i].R);
      free(domain[i].r);
      for(j=0; j<domain[i].ncoords; ++j)
      free(domain[i].coords[j]);
      free(domain[i].coords);
      free(domain[i].type);
      free(domain[i].start);
      free(domain[i].end);
      free(domain[i].reverse);
      free(domain[i].numb);
      }
    */
    free(domain);

    exit(0);
}