コード例 #1
0
ファイル: pars.c プロジェクト: queer1/rforensicbatwing
void read_parameters_data(parameters *p) {
    int i,integertmp=0;
    p->genetic_data=readcharintegermatrix(openinputfile(p->datafilename),
                                          &(p->samplesize),&(p->nloci));
    p->nSTR=p->nloci-p->ninf;
    if (p->samplesize<=1) {
      Rprintf("only one individual, unable to analyse this\n\n");
      error("error");
    }
    if (p->labelfilename!=NULL) {
      //    printf("reading from file %s\n",p->labelfilename);
      p->labels=readstrings(p->labelfilename,p->samplesize,20);
      for (i=1;i<=p->samplesize;i++) {
	Rprintf("%s ",p->labels[i]);
	Rprintf("\n");
      }
    } else {
      p->labels=NULL;
    }
    if (p->locationfilename!=NULL) {  /*  need to do this because of difficulties with fltk"*/
        if (strcmp(p->locationfilename,"")==0) {
            FREE(p->locationfilename);
            p->locationfilename=NULL;
        }
    }
    if (p->locationfilename==NULL) {
        p->location=NULL;
        p->npopulations=0;
        if (p->migmodel)
	  myerror("need locations for migration model");
    } else {
        p->location=readintegervector(openinputfile(p->locationfilename),&(integertmp));
        if (p->npopulations==0) {
            for (i=1;i<=integertmp;i++) {
                if (p->location[i]>p->npopulations)
                    p->npopulations=p->location[i];
            }
        }
        if (integertmp!=p->samplesize) {
	  Rprintf("locations %d not the same as # samples %d\n",integertmp,p->samplesize);
            error("error");
        }
    }
    if (p->migmodel)
        p->propprior.par[0]=(double)p->npopulations;

    if (p->npriors==p->locustypes[0]) {
        if (p->locustypes[0]==1&&p->locustypes[1]!=1) {
            if (p->locustypes[1]!=p->nSTR)
                myerror("incorrect locustype - need locustypes equal to number of STR loci");
        } else if (p->locustypes[0]!=1) {
            integertmp = 0;
            for (i=1;i<=p->locustypes[0];i++)
                integertmp+=p->locustypes[i];
            if (integertmp!=p->nSTR)
                myerror("incorrect locustype - sum does not equal number of STR loci");
        }
    } //else myerror("incorrect number of mutation rate priors");
}
コード例 #2
0
/**
 *  The example test program creates two pyramid graphs and produces
 *  the OR-product graph of them.  Then it prints the DOT
 *  representation of such graphs.
 *
 */
int main(int argc, char *argv[])
{

  int pebbling_bound=0;

  int pyramid_height=0;
  int tree_height=0;
  int chain_length=0;
  
  FILE *input_file=NULL;

  int input_directives = 0;
  char graph_name[100];
  
  int option_code=0;

  /* Parse option to set Pyramid height,
     pebbling upper bound. */
  while((option_code = getopt(argc,argv,"hb:p:2:c:f:i:g:"))!=-1) {
    switch (option_code) {
    case 'h':
      fprintf(stderr,USAGEMESSAGE,argv[0]);
      exit(EXIT_SUCCESS);
      break;
    case 'b':
      pebbling_bound=atoi(optarg);
      if (pebbling_bound>0) break;
      fprintf(stderr,USAGEMESSAGE,argv[0]);
      exit(EXIT_FAILURE);
      break;
    /* Input */
    case 'p':
      pyramid_height=atoi(optarg);
      if (pyramid_height>0) {input_directives++; break;}
      fprintf(stderr,USAGEMESSAGE,argv[0]);
      exit(EXIT_FAILURE);
      break;
    case '2':
      tree_height=atoi(optarg);
      if (tree_height>0) {input_directives++; break;}
      fprintf(stderr,USAGEMESSAGE,argv[0]);
      exit(EXIT_FAILURE);
      break;
    case 'c':
      chain_length=atoi(optarg);
      if (chain_length>0) {input_directives++; break;}
      fprintf(stderr,USAGEMESSAGE,argv[0]);
      exit(EXIT_FAILURE);
      break;
    case 'i':
      input_file=openinputfile(optarg);
      input_directives++;
      break;
    case '?':
    default:
      fprintf(stderr,USAGEMESSAGE,argv[0]);
      exit(EXIT_FAILURE);
    }
  }

  /* Test for valid command line */
  if (pebbling_bound==0) {
      fprintf(stderr,USAGEMESSAGE,argv[0]);
      exit(EXIT_FAILURE);
  }

  /* Only one input */
  if (input_directives > 1) {
    fprintf(stderr,USAGEMESSAGE,argv[0]);
    exit(EXIT_FAILURE);
  } 
  if (input_directives == 0) input_file = stdin;

  
  /* Produce or read input graph */
  DAG *C=NULL;
  if (pyramid_height>0) {
  
    C=pyramid(pyramid_height);
    snprintf(graph_name, 100, "Pyramid of height %d",pyramid_height);
  
  } else if (tree_height>0) {
    
    C=tree(tree_height);
    snprintf(graph_name, 100, "Tree of height %d",tree_height);
  
  } else if (chain_length>0) {
    
    C=path(chain_length);
    snprintf(graph_name, 100, "Chain of height %d",chain_length);

  } else {
    C=kthparser(input_file);
    fclose(input_file);
    snprintf(graph_name, 100, "Input graph");
  }

  /* Re-output the input graph */
  printf("c ===== input DAG ======\n");
  printf("c c %s\n", graph_name);
  fprint_DAG(stdout,C,"c ");
  printf("c ======================\n");
  printf("c Dymon-Tompa rounds: %d\n", pebbling_bound);
  printf("c ======================\n");
  
  /* Output the QBF */

  /* Clean up and exit */
  dispose_DAG(C);
  exit(EXIT_SUCCESS);
}