do_calc_data() { int b, p, prelim, tampaw, tampax; register int i, j, w, x; if (lastb != eb || lastp != ep) { j = tampaw = w = 0; tampax = x = lmarg; domainflgs[6] = TRUE; for (i = 0; i < stasys; i++) { if (clefs[i]) { ptr_to_bp( clefs[i], &b, &p ); currscreen[j++] = x + 4; currscreen[j++] = convert_y( i, ((short*)clefs[i])[4] ); currscreen[j++] = b; currscreen[j++] = p; domain_x( currscreen[j-2], currscreen[j-1], &tampax, &tampaw ); tampax = currscreen[j-4]; } } w = tampaw; x = tampax; for (i = 0; i < stasys; i++) { if (keys[i] && ((char*)(keys[i]))[6]) { /* keysig not natural? */ ptr_to_bp( keys[i], &b, &p ); currscreen[j++] = x + w + 4; currscreen[j++] = (-1); currscreen[j++] = b; currscreen[j++] = p; domain_x( currscreen[j-2], currscreen[j-1], &tampax, &tampaw ); tampax = currscreen[j-4]; } } w = tampaw; x = tampax; for (i = 0; i < stasys; i++) { if (times[i]) { ptr_to_bp( times[i], &b, &p ); currscreen[j++] = x + w + 4; currscreen[j++] = (-1); currscreen[j++] = b; currscreen[j++] = p; domain_x( currscreen[j-2], currscreen[j-1], &tampax, &tampaw ); tampax = currscreen[j-4]; } } w = tampaw; x = tampax; if (bartypes[1] == S_START || bartypes[1] == S_STARTEND) { ptr_to_bp( bars[1], &b, &p ); currscreen[j++] = (x > lmarg)? x + w + 4: x + w; currscreen[j++] = (-1); currscreen[j++] = b; currscreen[j++] = p; domain_x( currscreen[j-2], currscreen[j-1], &tampax, &tampaw ); w = tampaw; x = currscreen[j-4]; } ts_startpt = (x > lmarg)? x + w + 2: x; prelim = j >> 2; currscreen = (int*)((long)currscreen + (j << 1)); maxnsymb -= prelim; nsymbonscr = calc_data( lastb, lastp, eb, ep, x + w, rmarg ); maxnsymb += prelim; currscreen = (int*)((long)currscreen - (j << 1)); if (nsymbonscr) nsymbonscr += prelim; } else
int main(int argc, char **argv) { char infile[200], edata[200], fdata[200], pi_gdata[200], dxidata[200], dsidata[200], punjdata[200], punidata[200]; double *d/*, val*/; FILE *fp1, *fp2, *fp3, *fp4, *fp5, *fp6, *fp7, *fp8; char str[100], title[100]; FILE * gp = popen ("gnuplot -persistent", "w"); // open gnuplot in persistent mode int j; int ni, bi, ci, bti, ali, /*dli,*/ xi, gi, ki, ei, oi; int ns, bs, bts, cs, als, /*dls,*/ xs, gs, ks, es, os; ns = sizeof(N)/sizeof(int); bs = sizeof(B)/sizeof(double); cs = sizeof(C)/sizeof(double); bts = sizeof(Beta)/sizeof(double); als = sizeof(Alpha)/sizeof(double); //dls = sizeof(Delta)/sizeof(double); xs = sizeof(X0)/sizeof(double); ks = sizeof(K)/sizeof(int); es = sizeof(Eta)/sizeof(double); gs = sizeof(Gamma)/sizeof(double); os = sizeof(Omega)/sizeof(double); for(ni = 0; ni < ns; ni++){ d = malloc(N[ni]*sizeof(double)); // to hold data after each read of columns in data files for(ci = 0; ci < cs; ci++){ for(bti = 0; bti < bts; bti++){ for(ali = 0; ali < als; ali++){ for(xi = 0; xi < xs; xi++){ for(gi = 0; gi < gs; gi++){ for(ei = 0; ei < es; ei++){ for(ki = 0; ki < ks; ki++){ for(oi = 0; oi < os; oi++){ sprintf(edata, "n%dc%.2fa%.2fb%.2fg%.2fe%.3fk%dx0%.2fw%.2fehist.dat",N[ni], C[ci], Alpha[ali], Beta[bti], Gamma[gi], Eta[ei], K[ki], X0[xi], Omega[oi]); // data for histogram of efforts sprintf(fdata, "n%dc%.2fa%.2fb%.2fg%.2fe%.3fk%dx0%.2fw%.2ffhist.dat", N[ni], C[ci], Alpha[ali], Beta[bti], Gamma[gi], Eta[ei], K[ki], X0[xi], Omega[oi]); // data for histogram of payoff sprintf(pi_gdata, "n%dc%.2fa%.2fb%.2fg%.2fe%.3fk%dx0%.2fw%.2fpi_ghist.dat", N[ni], C[ci], Alpha[ali], Beta[bti], Gamma[gi], Eta[ei], K[ki], X0[xi], Omega[oi]); // data for histogram of payoff sprintf(dxidata, "n%dc%.2fa%.2fb%.2fg%.2fe%.3fk%dx0%.2fw%.2fdxihist.dat",N[ni], C[ci], Alpha[ali], Beta[bti], Gamma[gi], Eta[ei], K[ki], X0[xi], Omega[oi]); // data for threshold sprintf(dsidata, "n%dc%.2fa%.2fb%.2fg%.2fe%.3fk%dx0%.2fw%.2fdsihist.dat", N[ni], C[ci], Alpha[ali], Beta[bti], Gamma[gi], Eta[ei], K[ki], X0[xi], Omega[oi]); // data for aggressiveness sprintf(punidata, "n%dc%.2fa%.2fb%.2fg%.2fe%.3fk%dx0%.2fw%.2fpunihist.dat", N[ni], C[ci], Alpha[ali], Beta[bti], Gamma[gi], Eta[ei], K[ki], X0[xi], Omega[oi]); sprintf(punjdata, "n%dc%.2fa%.2fb%.2fg%.2fe%.3fk%dx0%.2fw%.2fpunjhist.dat", N[ni], C[ci], Alpha[ali], Beta[bti], Gamma[gi], Eta[ei], K[ki], X0[xi], Omega[oi]); fp2 = fopen(edata, "w"); fp3 = fopen(fdata, "w"); fp4 = fopen(pi_gdata, "w"); fp5 = fopen(dxidata, "w"); fp6 = fopen(dsidata, "w"); fp7 = fopen(punidata, "w"); fp8 = fopen(punjdata, "w"); fprintf(fp2, "b's "); fprintf(fp3, "b's "); fprintf(fp4, "b's "); fprintf(fp5, "b's "); fprintf(fp6, "b's "); fprintf(fp7, "b's "); fprintf(fp8, "b's "); for(j = 0; j < N[ni]; j++){ fprintf(fp2, "%d ", j+1); fprintf(fp3, "%d ", j+1); fprintf(fp5, "%d ", j+1); fprintf(fp6, "%d ", j+1); fprintf(fp7, "%d ", j+1); fprintf(fp8, "%d ", j+1); // adding headers } fprintf(fp2, "X \n"); fprintf(fp3, "X \n"); fprintf(fp4, "pi_g \n"); fprintf(fp5, "X \n"); fprintf(fp6, "X \n"); fprintf(fp7, "X\n"); fprintf(fp8, "X\n"); for(bi = 0; bi < bs; bi++){ // files to be read for efforts for set of paramters sprintf(infile, "n%db%.2fc%.2fa%.2fb%.2fd%.2fg%.2fe%.3fk%dx0%.2fw%.2fesum.dat", N[ni], B[bi], C[ci], Alpha[ali], Beta[bti], Delta[0], Gamma[gi], Eta[ei], K[ki], X0[xi], Omega[oi]); if(!(fp1 = fopen(infile, "r"))){ printf("Could not open file '%s'",infile); exit(1); } if(calc_data(fp1, d, N[ni], 0)){ // calculate data and not normalize fclose(fp1); write_delta_ef(fp2, d, bi, N[ni], Gamma[gi]); // write data to histogram data file for efforts // j is passed as delta for linear spacing } else{ fclose(fp1); printf("error in data read '%s': column count does not match!!\n", infile); exit(1); } // for fertilities // files to be read for fertilities for set of paramters sprintf(infile, "n%db%.2fc%.2fa%.2fb%.2fd%.2fg%.2fe%.3fk%dx0%.2fw%.2ffsum.dat", N[ni], B[bi], C[ci], Alpha[ali], Beta[bti], Delta[0],Gamma[gi], Eta[ei], K[ki], X0[xi], Omega[oi]); if(!(fp1 = fopen(infile, "r"))){ printf("Could not open file '%s'",infile); exit(1); } if(calc_data(fp1, d, N[ni], 1)){ // calculate data and normalize fertitilties fclose(fp1); write_delta_ef(fp3, d, bi, N[ni], Gamma[gi]); // write data to histogram data file for fertilities // j is passed as delta for linear spacing } else{ fclose(fp1); printf("error in data read '%s': column count does not match!!\n", infile); exit(1); } // for group payoff /*sprintf(infile, "n%db%.2fc%.2fa%.2fb%.2fd%.2fg%.2fe%.3fk%dx0%.2fpi_gsum.dat", N[ni], B[bi], C[ci], Alpha[ali], Beta[bti], Delta[0],Gamma[gi], Eta[ei], K[ki], X0[xi]); if(!(fp1 = fopen(infile, "r"))){ printf("Could not open file '%s'",infile); exit(1); } if(fscanf(fp1, "%lf", &val) == 1){ fprintf(fp4, "b=%.2f %.4lf\n", B[bi], val); }*/ // files to be read for threshold for set of paramters sprintf(infile, "n%db%.2fc%.2fa%.2fb%.2fd%.2fg%.2fe%.3fk%dx0%.2fw%.2fdxisum.dat", N[ni], B[bi], C[ci], Alpha[ali], Beta[bti], Delta[0], Gamma[gi], Eta[ei], K[ki], X0[xi], Omega[oi]); if(!(fp1 = fopen(infile, "r"))){ printf("Could not open file '%s'",infile); exit(1); } if(calc_data(fp1, d, N[ni], 0)){ // calculate data and not normalize fclose(fp1); write_delta_ef(fp5, d, bi, N[ni], Gamma[gi]); // write data to histogram data file for efforts // j is passed as delta for linear spacing } else{ fclose(fp1); printf("error in data read '%s': column count does not match!!\n", infile); exit(1); } // files to be read for aggressiveness for set of paramters sprintf(infile, "n%db%.2fc%.2fa%.2fb%.2fd%.2fg%.2fe%.3fk%dx0%.2fw%.2fdsisum.dat", N[ni], B[bi], C[ci], Alpha[ali], Beta[bti], Delta[0], Gamma[gi], Eta[ei], K[ki], X0[xi], Omega[oi]); if(!(fp1 = fopen(infile, "r"))){ printf("Could not open file '%s'",infile); exit(1); } if(calc_data(fp1, d, N[ni], 0)){ // calculate data and not normalize fclose(fp1); write_delta_ef(fp6, d, bi, N[ni], Gamma[gi]); // write data to histogram data file for efforts // j is passed as delta for linear spacing } else{ fclose(fp1); printf("error in data read '%s': column count does not match!!\n", infile); exit(1); } // for group effort /*sprintf(infile, "n%db%.2fc%.2fa%.2fb%.2fd%.2fg%.2fe%.3fk%dx0%.2fx_gsum.dat", N[ni], B[bi], C[ci], Alpha[ali], Beta[bti], Delta[0],Gamma[gi], Eta[ei], K[ki], X0[xi]); if(!(fp1 = fopen(infile, "r"))){ printf("Could not open file '%s'",infile); exit(1); } if(fscanf(fp1, "%lf", &val) == 1){ fprintf(fp7, "b=%.2f %.4lf\n", B[bi], val); }*/ // for punishment sprintf(infile, "n%db%.2fc%.2fa%.2fb%.2fd%.2fg%.2fe%.3fk%dx0%.2fw%.2fpunisum.dat", N[ni], B[bi], C[ci], Alpha[ali], Beta[bti], Delta[0],Gamma[gi], Eta[ei], K[ki], X0[xi], Omega[oi]); if(!(fp1 = fopen(infile, "r"))){ printf("Could not open file '%s'",infile); exit(1); } if(calc_data(fp1, d, N[ni], 0)){ // calculate data and not normalize fclose(fp1); write_delta_ef(fp7, d, bi, N[ni], Gamma[gi]); // write data to histogram data file for efforts // j is passed as delta for linear spacing } else{ fclose(fp1); printf("error in data read '%s': column count does not match!!\n", infile); exit(1); } // for punishment sprintf(infile, "n%db%.2fc%.2fa%.2fb%.2fd%.2fg%.2fe%.3fk%dx0%.2fw%.2fpunjsum.dat", N[ni], B[bi], C[ci], Alpha[ali], Beta[bti], Delta[0],Gamma[gi], Eta[ei], K[ki], X0[xi], Omega[oi]); if(!(fp1 = fopen(infile, "r"))){ printf("Could not open file '%s'",infile); exit(1); } if(calc_data(fp1, d, N[ni], 0)){ // calculate data and not normalize fclose(fp1); write_delta_ef(fp8, d, bi, N[ni], Gamma[gi]); // write data to histogram data file for efforts // j is passed as delta for linear spacing } else{ fclose(fp1); printf("error in data read '%s': column count does not match!!\n", infile); exit(1); } } fclose(fp2); fclose(fp3); fclose(fp4); fclose(fp5); fclose(fp6); fclose(fp7); fclose(fp8); } } } } } } } } free(d); } // reading data and prepare histogram data file for multiple values of b and delta but same other parameters completed // plotting summary histograms all at a time // the one with cluster base is removed from for loop (like for B in original case) for(ni = 0; ni < ns; ni++){ for(ci = 0; ci < cs; ci++){ for(bti = 0; bti < bts; bti++){ for(ali = 0; ali < als; ali++){ for(xi = 0; xi < xs; xi++){ for(gi = 0; gi < gs; gi++){ for(ei = 0; ei < es; ei++){ for(ki = 0; ki < ks; ki++){ for(oi = 0; oi < os; oi++){ sprintf(edata, "n%dc%.2fa%.2fb%.2fg%.2fe%.3fk%dx0%.2fw%.2fehist.dat", N[ni], C[ci], Alpha[ali], Beta[bti], Gamma[gi], Eta[ei], K[ki], X0[xi], Omega[oi]); // data for histogram of efforts sprintf(fdata, "n%dc%.2fa%.2fb%.2fg%.2fe%.3fk%dx0%.2fw%.2ffhist.dat", N[ni], C[ci], Alpha[ali], Beta[bti], Gamma[gi], Eta[ei], K[ki], X0[xi], Omega[oi]); // data for histogram of payoff sprintf(pi_gdata, "n%dc%.2fa%.2fb%.2fg%.2fe%.3fk%dx0%.2fw%.2fpi_ghist.dat", N[ni], C[ci], Alpha[ali], Beta[bti], Gamma[gi], Eta[ei], K[ki], X0[xi], Omega[oi]); // data for histogram of payoff sprintf(dxidata, "n%dc%.2fa%.2fb%.2fg%.2fe%.3fk%dx0%.2fw%.2fdxihist.dat", N[ni], C[ci], Alpha[ali], Beta[bti], Gamma[gi], Eta[ei], K[ki], X0[xi], Omega[oi]); // data for histogram of efforts sprintf(dsidata, "n%dc%.2fa%.2fb%.2fg%.2fe%.3fk%dx0%.2fw%.2fdsihist.dat", N[ni], C[ci], Alpha[ali], Beta[bti], Gamma[gi], Eta[ei], K[ki], X0[xi], Omega[oi]); // data for histogram of payoff sprintf(punidata, "n%dc%.2fa%.2fb%.2fg%.2fe%.3fk%dx0%.2fw%.2fpunihist.dat", N[ni], C[ci], Alpha[ali], Beta[bti], Gamma[gi], Eta[ei], K[ki], X0[xi], Omega[oi]); sprintf(punjdata, "n%dc%.2fa%.2fb%.2fg%.2fe%.3fk%dx0%.2fw%.2fpunjhist.dat", N[ni], C[ci], Alpha[ali], Beta[bti], Gamma[gi], Eta[ei], K[ki], X0[xi], Omega[oi]); // plot histograms sprintf(title, "n= %d, c= %.2f, al= %.2f, be= %.2f, ga= %.2f, eta= %.3f, k= %d, X0= %.2f, w=%.2f", N[ni], C[ci], Alpha[ali], Beta[bti], Gamma[gi], Eta[ei], K[ki], X0[xi], Omega[oi]); if(EPS) sprintf(str, "sum_n%02dc%.2fa%.2fb%.2fg%.2fe%.3fk%02dx0%.2lfw%.2f.eps",N[ni], C[ci], Alpha[ali], Beta[bti], Gamma[gi], Eta[ei], K[ki], X0[xi], Omega[oi]); else sprintf(str, "sum_n%02dc%.2fa%.2fb%.2fg%.2fe%.3fk%02dx0%.2lfw%.2f.png",N[ni], C[ci], Alpha[ali], Beta[bti], Gamma[gi], Eta[ei], K[ki], X0[xi], Omega[oi]); hist_sum(gp, edata, fdata, dxidata, dsidata, punidata, punjdata, N[ni], Gamma[gi], title, str); sprintf(str, "sumg_n%02dc%.2fa%.2fb%.2fg%.2fe%.3fk%02dx0%.2lfw%.2f.png",N[ni], C[ci], Alpha[ali], Beta[bti], Gamma[gi], Eta[ei], K[ki], X0[xi], Omega[oi]); //hist_pi_g(gp, pi_gdata, x_gdata, pun_gdata, title, str); // histograms for efforts and payoffs for one set of n, c and X0 compeleted } } } } } } } } } fflush(gp); pclose(gp); return 0; }