📄 sudgast.c
字号:
char *value_temp; char s[40]; char ga[40]; char infile[100]; char templatefile[100]; char format[20]; char cmd[80]; int bitlength; int status; int genes; int repetition; int smooth; int ok; unsigned long values; unsigned long verify; float dt; double min, min0; double max, max0; initargs(argc,argv); requestdoc(0); if (!getparstring("workdir", &value)) { sprintf(msg, "Setup: Specify working directory!"); Error(msg); } sprintf(workdir,"%s",value); if (!getparstring("suffix", &value)) { value = "dga"; } sprintf(suff,"%s",value); printf("\n\n"); if (strlen(suff) == 0) { strcpy(suff,"dga"); sprintf(infile, "%s/in.dga", workdir); sprintf(templatefile, "%s/template.dga", workdir); } else { sprintf(infile, "%s/in.%s", workdir, suff); sprintf(templatefile, "%s/template.%s", workdir, suff); } if (!getparstring("verbose", &value)) { value = "1"; } if (!atoi(value)) *verbose = 0; else *verbose = 1; bitlength = 0; /* get string interpretation */ if (!getparstring("sources", &value)) { sprintf(msg, "Setup: Specify number of sources!"); Error(msg); } genes = atoi(value); if (!getparstring("receivers", &value)) { sprintf(msg, "Setup: Specify number of receivers!"); Error(msg); } genes += atoi(value); *ggenes = genes; if (!getparstring("datafile", &value)) { sprintf(msg, "Setup: Specify data file name!"); Error(msg); }/* opening input file*/ fpp = fopen(value,"r"); if (fpp == NULL) { sprintf(msg, "Can't open %s", value); Error(msg); } /* get info from first trace */ if (!fgettr(fpp,&tr)) Error("can't get first trace of input data"); dt = (float) tr.dt / 1000.0; close(fpp); fp = fopen(templatefile, "w"); fprintf(fp, "genes: %d\n\n", genes); for (i=0; i<genes; ) { if (!getpardouble("minstatic", &min)) { sprintf(msg,"Setup: Specify minimum static in ms!"); Error(msg); } min0 = min; min = (double) NINT(min / dt); /* to time samples */ if (!getpardouble("maxstatic", &max)) { sprintf(msg, "Setup: Specify maximum statics in ms!"); Error(msg); } max0 = max; max = (double) NINT(max / dt); /* to time samples */ ok = 0; if (!getparulong("numbits", &values)) { values = 64; } verify = 1L << ilog2(values); ok = verify == values; if (!ok) { sprintf(msg, "Bad choice for values !"); Error(msg); } value="%8.3f"; repetition=genes; for (j=0; j < repetition && i < genes; j++, i++) { fprintf(fp, "gene %d\n", i); fprintf(fp, "min: %g\n", min); fprintf(fp, "max: %g\n", max); fprintf(fp, "values: %lu\n", values); fprintf(fp, "format: %s\n", value); fprintf(fp, "\n"); bitlength += ilog2(values); } fclose(fp); } *mmin = min; *mmax = max; if ((fp = fopen(infile, "w")) == NULL) { printf("can't open %s\n", infile); printf("Setup aborted.\n"); exit(1); } if (!getparstring("verbose", &value)) { value = "1"; } if (!atoi(value)) *verbose = 0; else *verbose = 1; setpar(fp, "Verbose", "1", value, verbose); value = "1"; setpar(fp, "Experiments", "1", value, 0); if (*verbose) { printf("File suffix [dga]: %s\n", suff); printf("Minimum statics [?]: %6.2f\n", min0); printf("Maximum statics [?]: %6.2f\n", max0); printf("Number of bits (must be a power of 2) [64]: %lu\n", values); } /* get string interpretation */ if (!getparstring("sources", &value)) { sprintf(msg, "Setup: Specify number of sources!"); Error(msg); } genes = atoi(value); /* statics parameters */ setpar(fp, "Sources", "?", value, verbose); if (!getparstring("receivers", &value)) { sprintf(msg, "Setup: Specify number of receivers!"); Error(msg); } genes += atoi(value); /* statics parameters */ setpar(fp, "Receivers", "?", value, verbose); if (!getparstring("cmps", &value)) { sprintf(msg, "Setup: Specify number of cmps!"); Error(msg); } genes = atoi(value); /* statics parameters */ setpar(fp, "CMPs", "?", value, verbose); if (!getparstring("maxfold", &value)) { sprintf(msg, "Setup: Specify maximum fold of the data!"); Error(msg); } /* statics parameters */ setpar(fp, "Fold", "?", value, verbose); if (!getparstring("maxlag", &value)) { value = "160"; } /* statics parameters */ setpar(fp, "Maxlag", "160", value, verbose); if (!getparstring("dx", &value)) { sprintf(msg, "Setup: Specify receiver spacing!"); Error(msg); } /* statics parameters */ setpar(fp, "Dx", "?", value, verbose); if (!getparstring("smooth", &value)) { value = "1"; } /* statics parameters */ setpar(fp, "Smooth", "1", value, verbose); if (!getparstring("evolutions", &value)) { value = "20"; } setpar(fp, "Evolutions", "20", value, verbose); *numevol = atoi(value); if (!getparstring("iterations", &value)) { value = "500"; } setpar(fp, "Trials per Evolution", "500", value, verbose); if (!getparstring("popsize", &value)) { value = "50"; } setpar(fp, "Subpopulation Size", "50", value, verbose); *population = atoi(value); if (!getparstring("populations", &value)) { value = "2"; } setpar(fp, "Number of populations", "2", value, verbose); *ncities = atoi(value); fprintf(fp, "%18s = %d\n", "Structure Length", bitlength); if (!getparstring("crossprob", &value)) { value = ".6"; } setpar(fp, "Crossover probability", "0.6", value, verbose); if (!getparstring("mutprob", &value)) { value = ".001"; } setpar(fp, "Mutation probability", "0.001", value, verbose); value = "1."; setpar(fp, "Generation Gap", "1.0", value, 0); value = "5"; setpar(fp, "Scaling Window", "5", value, 0); value = "100"; setpar(fp, "Report Interval", "100", value, 0); value = "10"; setpar(fp, "Structures Saved", "10", value, 0); value = "2"; setpar(fp, "Max Gens w/o Eval", "2", value, 0); value = "0"; setpar(fp, "Dump Interval", "0", value, 0); value = "0"; setpar(fp, "Dumps Saved", "0", value, 0); value_temp = malloc(1); /* used due a possible bug with char* */ if (!getparstring("rand", &value)) { *seed = getpid(); sprintf(value_temp,"%d",*seed); /* INTEGER -> CHARACTER */ value = value_temp; setpar(fp, "Random Seed", "getpid()", value, verbose); } else { setpar(fp, "Random Seed", "getpid()", value, verbose); *seed = atoi(value); } *random_gnr = 1; value = ".5"; setpar(fp, "Rank Min", "0.5", value, 0); if (!getparstring("uphill", &value)) { value = "1"; } setpar(fp, "CG Active", "1", value, verbose); if (!getparstring("firstcg", &value)) { value = "10"; } setpar(fp, "Min Evol for CG", "10", value, verbose); if (!getparstring("maxiteratcg", &value)) { value = "20"; } setpar(fp, "Max number of iter in CG", "20", value, verbose); if (!getparint("maxevol", max_stat_evol)) { *max_stat_evol = 2; } if (*verbose) printf("Max number of low variance evolutions [2]: %d\n", *max_stat_evol); if (*verbose) printf("Working directory [?]: %s\n", workdir); if (!getparstring("datafile", &value)) { sprintf(msg, "Setup: Specify data file name!"); Error(msg); } setpar(fp, "Datafile", "?", value, verbose); if (!getparstring("xcorrfile", &value)) { sprintf(msg, "Setup: Specify crosscorrelation file name!"); Error(msg); } setpar(fp, "Xcorrfile", "?", value, verbose); fclose(fp); *offset = 1.; printf("\n"); /*sprintf(cmd, "cat %s", infile); system(cmd);*/}int ilog2(n) unsigned long n;{ int i; if (n <= 0) { printf("Help! values is %d, must be positive!\n", n); abort(); } i = 0; while ((int) (n & 1) == 0) { n >>= 1; i++; } return(i);}setpar(fp, prompt, defaultstring, s, show) FILE *fp; char *prompt; char *defaultstring; char s[80]; int *show;{ if (*show) printf("%s [%s]: %s\n", prompt, defaultstring,s); if (strlen(s) == 0) strcpy(s, defaultstring); fprintf(fp, "%18s = %s\n", prompt, s);}getstring(s)char s[];{ gets(s);}/* * GENESIS Copyright (c) 1986, 1990 by John J. Grefenstette * This program may be freely copied for educational * and research purposes. All other rights reserved. * * file: error.c * * purpose: print message in error log file and abort. * * modified: 7 feb 86 */double Rand(){ double random; random = (double) franuni(); return(random);}int Randint(low,high)int low, high;{ float random; int intrandom; random = franuni(); intrandom = (int) (random * (high - low + 1) + low); return (intrandom);}double Randdouble(dlow,dhigh)double dlow, dhigh;{ float random; double drandom; random = franuni(); drandom = (double) (random * (dhigh - dlow) + dlow); return (drandom);}Error(s)char *s;{ FILE *fopen(), *fp; long clock; long time(); char *ctime(); fp = fopen("log.error", "a"); fprintf(fp, "%s\n", s); time(&clock); fprintf(fp, "%s\n", ctime(&clock)); fclose(fp); fprintf(stderr, "%s\n", s); pvmLeave(); /* Leaving PVM */ exit(1);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -