示例#1
0
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
文件: menu.c 项目: ombt/ombt
// edit string tables
void
edstring(char *input)
{
	// read in string tables
	readstrings(input);

	// review or update
	editstrings(input);
	return;
}
示例#3
0
void readsysdefaults(void)
{
    int i,j;
    FILE *f;
    char buf[200];
    char *s;

    /* Setup defaults. */
    setarray ( &sysdefplanets, 0 );
    startplanets[0]=startplanets[10]=startplanets[20]=startplanets[30]=1;
    setarray ( &sysdefships, 1 );
    setarray ( &sysdefweapons, 1 );

    testtime= -1;
    topgun=0; /* added 12/9/90 TC */
    newturn=0; /* added 1/20/91 TC */
    hiddenenemy=1;
    binconfirm=0;
    plkills=2;
    ddrank=0;
    garank=0;
    sbrank=3;
    chaosmode=0;
    tournplayers=5;
    udpAllowed=1;		/* UDP */
    top_armies = 30;            /* added 11/27/93 ATH */
    planet_move = 0;		/* added 9/28/92 NBT */
    wrap_galaxy = 0;		/* added 6/28/95 JRP */
    pingpong_plasma = 0;	/* added 7/6/95 JRP */
#ifdef MINES
    mines = 0;			/* added 8/3/95 JRP */
#endif
    twarpMode = 0;
    twarpSpeed = 60;
    distortion = 10;
    fps = 50;
    maxups = fps;
    minups = 1;
    defups = maxups;
    manager_type = NO_ROBOT;
    strcpy(Motd,N_MOTD);
    strcpy(script_tourn_start, "");
    strcpy(script_tourn_end, "");

    getshipdefaults();

    f=fopen(SysDef_File, "r");
    if (f==NULL) {
	ERROR(1,("No system defaults file!  Using coded defaults.\n"));
        return;
    }
    stat(SysDef_File, &oldstat);

    while (fgets(buf, 200, f)!=NULL) {
	if (buf[0] == '#') continue; /* a comment */
	s=strchr(buf, '='); /* index marked as LEGACY in POSIX.1-2001 */
	if (s==NULL) continue;
	*s='\0';
	s++;

	/* check each keyword from file with our list of keywords */
	for (j=0; sysdef_keywords[j].type != SYSDEF_END; j++) {

	    /* check current keyword for a match */
	    if (strcmp(buf,sysdef_keywords[j].key)==0) {
		switch (sysdef_keywords[j].type) {
		case SYSDEF_INT:
		    {
			int *p = (int *) sysdef_keywords[j].p;
			*p = atoi(s);
		    }
		    break;
		case SYSDEF_FLOAT:
		    {
			float *p = (float *) sysdef_keywords[j].p;
			sscanf (s, "%f", p);
		    }
		    break;
		case SYSDEF_CHAR:
		    sscanf(s,"%s", (char *) sysdef_keywords[j].p);
		    break;
		case SYSDEF_ARRAY:
		    {
			struct sysdef_array *a = sysdef_keywords[j].p;
			setarray(a, 0);
			readstrings(a->name, s, a->keys, a->p, a->max);
		    }
		    break;
		case SYSDEF_ROBOT:
		    /* cast from pointer to integer of different size [ok] */
		    if (atoi(s)) manager_type = (int) sysdef_keywords[j].p;
		    break;
		case SYSDEF_SHIP:
		    shipdefs (atoi(s),f);
		    break;
		}
		break;
	    }
	}	
    }

    /* Make sure every team can start at some planet! */
    for (i=0; i<4; i++) { 
	int k = 0;
	for (j=0; j<10; j++) {
	    if (startplanets[i*10+j]) {
		k++;
		break;
	    }
	}
	if (k == 0) {
	    ERROR(1,("No starting planets specified for team %d\n", i));
	    startplanets[i*10]=1;
	}
    }

    /* apply minimum and maximum values here */
    if (tournplayers == 0) tournplayers=5;
    if (ping_freq <= 0) ping_freq = 1;
    if (ping_iloss_interval <= 0) ping_iloss_interval = 1;
    if (ping_ghostbust_interval <= 0) ping_ghostbust_interval = 1;
    if (ghostbust_timer <= 0) ghostbust_timer = 1;

#ifdef BASEPRACTICE
    if (manager_type == BASEP_ROBOT) {
      binconfirm=0;	/* allow robots to join	*/
#ifdef ALLOW_PRACTICE_ROBOT_SB
      sbrank=0;		/* no SB restriction	*/
#endif
      check_scum=0;
    }
#endif

    if (manager_type == INL_ROBOT) {
      tournplayers=1;
      ddrank=0;		/* no DD restriction		*/
      garank=0;		/* no GA restriction		*/
      sbrank=0;		/* no SB restriction		*/
      killer=0;		/* disable iggy for game	*/
      surrenderStart=0;
    }

    fclose(f);
}