void worker(int len, int output_options, char* filename) { FILE* table=file_check(filename); // file is open to read if (table==NULL) exit(1); // if the file is not good we exit int i; gem* gems=malloc(len*sizeof(gem)); // if not malloc-ed 230k is the limit gem* pool[len]; int pool_length[len]; pool[0]=malloc(sizeof(gem)); gem_init(gems,1,1,1); gem_init(pool[0],1,1,1); pool_length[0]=1; int prevmax=pool_from_table(pool, pool_length, len, table); // pool filling fclose(table); // close if (prevmax<len-1) { for (i=0;i<=prevmax;++i) free(pool[i]); // free free(gems); // free if (prevmax>0) printf("Table stops at %d, not %d\n",prevmax+1,len); exit(1); } if (!(output_options & mask_quiet)) gem_print(gems); for (i=1;i<len;++i) { int j; gems[i]=pool[i][0]; for (j=1;j<pool_length[i];++j) if (gem_more_powerful(pool[i][j],gems[i])) { gems[i]=pool[i][j]; } if (!(output_options & mask_quiet)) { printf("Value:\t%d\n",i+1); if (output_options & mask_info) printf("Growth:\t%f\n", log(gem_power(gems[i]))/log(i+1)); if (output_options & mask_debug) printf("Pool:\t%d\n",pool_length[i]); gem_print(gems+i); } } if (output_options & mask_quiet) { // outputs last if we never seen any printf("Value:\t%d\n",len); printf("Growth:\t%f\n", log(gem_power(gems[len-1]))/log(len)); if (output_options & mask_debug) printf("Pool:\t%d\n",pool_length[len-1]); gem_print(gems+len-1); } gem* gemf=gems+len-1; // gem that will be displayed if (output_options & mask_upto) { double best_growth=-INFINITY; int best_index=0; for (i=0; i<len; ++i) { if (log(gem_power(gems[i]))/log(i+1) > best_growth) { best_index=i; best_growth=log(gem_power(gems[i]))/log(i+1); } } printf("Best gem up to %d:\n\n", len); printf("Value:\t%d\n",best_index+1); printf("Growth:\t%f\n", best_growth); gem_print(gems+best_index); gemf = gems+best_index; } gem* gem_array; gem red; if (output_options & mask_red) { if (len < 2) printf("I could not add red!\n\n"); else { int value=gem_getvalue(gemf); gemf = gem_putred(pool[value-1], pool_length[value-1], value, &red, &gem_array); printf("Gem with red added:\n\n"); printf("Value:\t%d\n", value); // made to work well with -u printf("Growth:\t%f\n", log(gem_power(*gemf))/log(value)); gem_print(gemf); } } if (output_options & mask_parens) { printf("Compressed combining scheme:\n"); print_parens_compressed(gemf); printf("\n\n"); } if (output_options & mask_tree) { printf("Gem tree:\n"); print_tree(gemf, ""); printf("\n"); } if (output_options & mask_table) print_table(gems, len); if (output_options & mask_equations) { // it ruins gems, must be last printf("Equations:\n"); print_equations(gemf); printf("\n"); } for (i=0;i<len;++i) free(pool[i]); // free free(gems); // free if (output_options & mask_red && len > 1) { free(gem_array); } }
void test_wsac3() { float x[1024], y[1024]; int err, max, leven; x[0] = 0; y[0] = 0; leven = TRUE; max = 1; /* File with one data point */ newhdr(); setnhv("npts", &max, &err, -1); setlhv("leven", &leven, &err, -1); setfhv("b", &(x[0]), &err, -1); setfhv("e", &(x[0]), &err, -1); setihv("iftype", "itime", &err, -1, -1); /* Filename Length Special < 0 */ wsac3(FILE_WRITE, &(x[0]), &(y[0]), &err, -1); ok(err == SAC_OK, "wsac3 writing sac file with 1 point"); file_check(FILE_WRITE, SAC_HEADER_SIZE + 1 * sizeof(float), "1 data point"); unlink(FILE_WRITE); /* Filename Correct Length */ wsac3(FILE_WRITE, &(x[0]), &(y[0]), &err, strlen(FILE_WRITE)); ok(err == SAC_OK, "wsac3 writing sac file with 1 point"); file_check(FILE_WRITE, SAC_HEADER_SIZE + 1 * sizeof(float), "1 data point"); unlink(FILE_WRITE); /* Filename Length too long */ wsac3(FILE_WRITE, &(x[0]), &(y[0]), &err, strlen(FILE_WRITE) * 3); ok(err == SAC_OK, "wsac3 writing sac file with 1 point"); file_check(FILE_WRITE, SAC_HEADER_SIZE + 1 * sizeof(float), "1 data point"); unlink(FILE_WRITE); /* Filename Length too short*/ wsac3(FILE_WRITE, &(x[0]), &(y[0]), &err, strlen(FILE_WRITE) - 4); ok(err == SAC_OK, "wsac3 writing sac file with 1 point"); file_check("test_write", SAC_HEADER_SIZE + 1 * sizeof(float), "1 data point"); unlink("test_write"); /* Filename Length = 0 */ wsac3(FILE_WRITE, &(x[0]), &(y[0]), &err, 0); ok(err == 101, "wsac3 writing sac file with 1 point value %d expected %d", err, 101); /* Increase the number of data points to 1024 */ { int i; for(i = 0; i < 1024; i++) { x[i] = y[i] = i; } } /* But do not tell the sacio library about the increased size*/ wsac3(FILE_WRITE, &(x[0]), &(y[0]), &err, -1); ok(err == SAC_OK, "wsac3 writing sac file with 1 / 1024 data points " "value %d expected %d", err, SAC_OK); file_check(FILE_WRITE, SAC_HEADER_SIZE + (1 * sizeof(float)), "1 data point"); unlink(FILE_WRITE); /* Inform sacio that the file is now longer */ max = 1024; setnhv("npts", &max, &err, -1); wsac3(FILE_WRITE, &(x[0]), &(y[0]), &err, -1); ok(err == SAC_OK, "wsac3 writing sac file with 1024 data points " "value %d expected %d", err, SAC_OK); file_check(FILE_WRITE, SAC_HEADER_SIZE + (1024 * sizeof(float)), "1024 data points"); unlink(FILE_WRITE); /* Write a file with < 0 points */ max = -1; setnhv("npts", &max, &err, -1); wsac3(FILE_WRITE, &(x[0]), &(y[0]), &err, -1); ok(err == 115, "wsac3 writing sac file with -1 data points " "value %d expected %d", err, 115); ok(!file_exists(FILE_WRITE), "-1 data points"); unlink(FILE_WRITE); /* Write the other types of sac files */ max = 2; setnhv("npts", &max, &err, -1); /* Spectral Real / Imaginary */ setihv("iftype", "irlim", &err, -1, -1); wsac3(FILE_WRITE, &(x[0]), &(y[0]), &err, -1); ok(err == SAC_OK, "wsac3 writing sac file (real/imag) with 2 data points " "value %d expected %d", err, SAC_OK); file_check_not_ok(FILE_WRITE, SAC_HEADER_SIZE + max * 2 * sizeof(float), "real/imag"); unlink(FILE_WRITE); /* Spectral Amplitude / Phase */ setihv("iftype", "iamph", &err, -1, -1); wsac3(FILE_WRITE, &(x[0]), &(y[0]), &err, -1); ok(err == SAC_OK, "wsac3 writing sac file (amp/phase)with 2 data points " "value %d expected %d", err, SAC_OK); file_check_not_ok(FILE_WRITE, SAC_HEADER_SIZE + max * 2 * sizeof(float), "amp/phase"); unlink(FILE_WRITE); /* IXY spaced file */ setihv("iftype", "ixy", &err, -1, -1); wsac3(FILE_WRITE, &(x[0]), &(y[0]), &err, -1); ok(err == SAC_OK, "wsac3 writing sac file (ixy) with 2 data points " "value %d expected %d", err, SAC_OK); file_check_not_ok(FILE_WRITE, SAC_HEADER_SIZE + (max * 2 * sizeof(float)), "ixy"); unlink(FILE_WRITE); /* unevenly spaced file */ leven = 0; setlhv("leven", &leven, &err, -1); setihv("iftype", "itime", &err, -1, -1); wsac3(FILE_WRITE, &(x[0]), &(y[0]), &err, -1); ok(err == SAC_OK, "wsac3 writing sac file (uneven/time) with 2 data points " "value %d expected %d", err, SAC_OK); file_check(FILE_WRITE, SAC_HEADER_SIZE + max * 2 * sizeof(float), "uneven/time"); unlink(FILE_WRITE); }
void worker(int len, int output_options, double growth_comb, char* filename, char* filenameA, int TC, int As, int Namps) { FILE* table=file_check(filename); // file is open to read if (table==NULL) exit(1); // if the file is not good we exit int i; gem* pool[len]; int pool_length[len]; pool[0]=malloc(2*sizeof(gem)); pool_length[0]=2; gem_init(pool[0] ,1,1,0); gem_init(pool[0]+1,1,0,1); int prevmax=pool_from_table(pool, pool_length, len, table); // managem pool filling fclose(table); if (prevmax<len-1) { // if the managems are not enough for (i=0;i<=prevmax;++i) free(pool[i]); // free if (prevmax>0) printf("Gem table stops at %d, not %d\n",prevmax+1,len); exit(1); } gem* poolf[len]; int poolf_length[len]; MGSPEC_COMPRESSION if (!(output_options & mask_quiet)) printf("Gem speccing pool compression done!\n"); FILE* tableA=file_check(filenameA); // fileA is open to read if (tableA==NULL) exit(1); // if the file is not good we exit int lena=len; gemO* poolO[lena]; int poolO_length[lena]; poolO[0]=malloc(sizeof(gemO)); poolO_length[0]=1; gem_init_O(poolO[0],1,1); int prevmaxA=pool_from_table_O(poolO, poolO_length, lena, tableA); // amps pool filling fclose(tableA); if (prevmaxA<lena-1) { for (i=0;i<=prevmaxA;++i) free(poolO[i]); // free if (prevmaxA>0) printf("Amp table stops at %d, not %d\n",prevmaxA+1,lena); exit(1); } gemO* bestO=malloc(lena*sizeof(gemO)); // if not malloc-ed 140k is the limit AMPS_COMPRESSION if (!(output_options & mask_quiet)) printf("Amp pool compression done!\n\n"); int j,k; // let's choose the right gem-amp combo gem gems[len]; gemO amps[len]; double spec_coeffs[len]; gem_init(gems,1,1,0); amps[0]=(gemO){0}; spec_coeffs[0]=0; double leech_ratio=Namps*(0.15+As/3*0.004)*2*(1+0.03*TC)/(1+TC/3*0.1); int skip_computations = (output_options & mask_quiet) && !((output_options & mask_table) || (output_options & mask_upto)); int first = skip_computations ? len-1 : 0; for (i=first; i<len; ++i) { // for every gem value gems[i]=(gem){0}; // we init the gems amps[i]=(gemO){0}; // to extremely weak ones for (k=0;k<poolf_length[i];++k) { // first we compare the gem alone if (gem_power(poolf[i][k]) > gem_power(gems[i])) { gems[i]=poolf[i][k]; } } int NS=i+1; double comb_coeff=pow(NS, -growth_comb); spec_coeffs[i]=comb_coeff*gem_power(gems[i]); // now with amps for (j=0, NS+=Namps; j<i+1; ++j, NS+=Namps) { // for every amp value from 1 to to gem_value double comb_coeff=pow(NS, -growth_comb); // we compute comb_coeff double Pa= leech_ratio * bestO[j].leech; // <- this is ok only for mg for (k=0; k<poolf_length[i]; ++k) { // then we search in the reduced gem pool double Palone = gem_power(poolf[i][k]); double power = Palone + poolf[i][k].bbound * Pa; double spec_coeff=power*comb_coeff; if (spec_coeff>spec_coeffs[i]) { spec_coeffs[i]=spec_coeff; gems[i]=poolf[i][k]; amps[i]=bestO[j]; } } } if (!(output_options & mask_quiet)) { printf("Total value:\t%d\n\n", i+1+Namps*gem_getvalue_O(amps+i)); printf("Managem\n"); printf("Value:\t%d\n",i+1); if (output_options & mask_debug) printf("Pool:\t%d\n",poolf_length[i]); gem_print(gems+i); printf("Amplifier (x%d)\n", Namps); printf("Value:\t%d\n",gem_getvalue_O(amps+i)); gem_print_O(amps+i); printf("Spec base power: \t%#.7g\n", gem_amp_power(gems[i], amps[i], leech_ratio)); printf("Spec coefficient:\t%f\n\n", spec_coeffs[i]); } } if (output_options & mask_quiet) { // outputs last if we never seen any printf("Total value:\t%d\n\n", len+Namps*gem_getvalue_O(amps+len-1)); printf("Managem\n"); printf("Value:\t%d\n", len); gem_print(gems+len-1); printf("Amplifier (x%d)\n", Namps); printf("Value:\t%d\n", gem_getvalue_O(amps+len-1)); gem_print_O(amps+len-1); printf("Spec base power: \t%#.7g\n", gem_amp_power(gems[len-1], amps[len-1], leech_ratio)); printf("Spec coefficient:\t%f\n\n", spec_coeffs[len-1]); } gem* gemf=gems+len-1; // gem that will be displayed gemO* ampf=amps+len-1; // amp that will be displayed if (output_options & mask_upto) { double best_sc=0; int best_index=0; for (i=0; i<len; ++i) { if (spec_coeffs[i] > best_sc) { best_index=i; best_sc=spec_coeffs[i]; } } printf("Best setup up to %d:\n\n", len); printf("Total value:\t%d\n\n", gem_getvalue(gems+best_index)+Namps*gem_getvalue_O(amps+best_index)); printf("Managem\n"); printf("Value:\t%d\n", gem_getvalue(gems+best_index)); gem_print(gems+best_index); printf("Amplifier (x%d)\n", Namps); printf("Value:\t%d\n", gem_getvalue_O(amps+best_index)); gem_print_O(amps+best_index); printf("Spec base power: \t%#.7g\n", gem_amp_power(gems[best_index], amps[best_index], leech_ratio)); printf("Spec coefficient:\t%f\n\n", best_sc); gemf = gems+best_index; ampf = amps+best_index; } gem* gem_array = NULL; gem red; if (output_options & mask_red) { if (len < 3) printf("I could not add red!\n\n"); else { int value = gem_getvalue(gemf); int valueA= gem_getvalue_O(ampf); double NS = value + Namps*valueA; double amp_leech_scaled = leech_ratio * ampf->leech; gemf = gem_putred(poolf[value-1], poolf_length[value-1], value, &red, &gem_array, amp_leech_scaled); printf("Setup with red added:\n\n"); printf("Total value:\t%d\n\n", value+Namps*gem_getvalue_O(ampf)); printf("Managem\n"); printf("Value:\t%d\n", value); gem_print(gemf); printf("Amplifier (x%d)\n", Namps); printf("Value:\t%d\n", gem_getvalue_O(ampf)); gem_print_O(ampf); printf("Spec base power w. red:\t%#.7g\n", gem_amp_power(*gemf, *ampf, leech_ratio)); double CgP = pow(NS, -growth_comb); printf("Spec coefficient:\t%f\n\n", CgP*gem_cfr_power(*gemf, amp_leech_scaled)); } } if (output_options & mask_parens) { printf("Managem speccing scheme:\n"); print_parens_compressed(gemf); printf("\n\n"); printf("Amplifier speccing scheme:\n"); print_parens_compressed_O(ampf); printf("\n\n"); } if (output_options & mask_tree) { printf("Managem tree:\n"); print_tree(gemf, ""); printf("\n"); printf("Amplifier tree:\n"); print_tree_O(ampf, ""); printf("\n"); } if (output_options & mask_table) print_amps_table(gems, amps, spec_coeffs, leech_ratio, len); if (output_options & mask_equations) { // it ruins gems, must be last printf("Managem equations:\n"); print_equations(gemf); printf("\n"); printf("Amplifier equations:\n"); print_equations_O(ampf); printf("\n"); } for (i=0;i<len;++i) free(pool[i]); // free gems for (i=0;i<len;++i) free(poolf[i]); // free gems compressed for (i=0;i<lena;++i) free(poolO[i]); // free amps free(bestO); // free amps compressed if (output_options & mask_red && len > 2) { free(gem_array); } }
void worker(int len, int lenc, int output_options, char* filename, char* filenamec, char* filenameA, int TC, int As, int GT, int Namps) { FILE* table=file_check(filename); // file is open to read if (table==NULL) exit(1); // if the file is not good we exit int i; gem* pool[len]; int pool_length[len]; pool[0]=malloc(2*sizeof(gem)); pool_length[0]=2; gem_init(pool[0] ,1,1,0); gem_init(pool[0]+1,1,0,1); int prevmax=pool_from_table(pool, pool_length, len, table); // managem spec pool filling fclose(table); if (prevmax<len-1) { // if the managems are not enough for (i=0;i<=prevmax;++i) free(pool[i]); // free if (prevmax>0) printf("Gem table stops at %d, not %d\n",prevmax+1,len); exit(1); } gem* poolf[len]; int poolf_length[len]; MGSPEC_COMPRESSION printf("Gem speccing pool compression done!\n"); FILE* tableA=file_check(filenameA); // fileA is open to read if (tableA==NULL) exit(1); // if the file is not good we exit int lena=len; // as long as the spec length gemO* poolO[lena]; int poolO_length[lena]; poolO[0]=malloc(sizeof(gemO)); poolO_length[0]=1; gem_init_O(poolO[0],1,1); int prevmaxA=pool_from_table_O(poolO, poolO_length, lena, tableA); // amps pool filling fclose(tableA); if (prevmaxA<lena-1) { for (i=0;i<=prevmaxA;++i) free(poolO[i]); // free if (prevmaxA>0) printf("Amp table stops at %d, not %d\n",prevmaxA+1,lena); exit(1); } gemO* bestO=malloc(lena*sizeof(gem)); // if not malloc-ed 140k is the limit AMPS_COMPRESSION printf("Amp pool compression done!\n"); FILE* tablec=file_check(filenamec); // file is open to read if (tablec==NULL) exit(1); // if the file is not good we exit gem** poolc=malloc(lenc*sizeof(gem*)); int* poolc_length=malloc(lenc*sizeof(int)); poolc[0]=malloc(sizeof(gem)); poolc_length[0]=1; gem_init(poolc[0],1,1,1); int prevmaxc=pool_from_table(poolc, poolc_length, lenc, tablec); // managem comb pool filling fclose(tablec); if (prevmaxc<lenc-1) { // if the managems are not enough for (i=0;i<=prevmaxc;++i) free(poolc[i]); // free if (prevmaxc>0) printf("Gem table stops at %d, not %d\n",prevmaxc+1,lenc); exit(1); } gem bestc=(gem){0}; // choosing best combine for (i=0;i<poolc_length[lenc-1];++i) { if (gem_more_powerful(poolc[lenc-1][i], bestc)) { bestc=poolc[lenc-1][i]; } } double bestc_growth=log(gem_power(bestc))/log(lenc); printf("Combining pool compression done!\n\n"); int j,k; // let's choose the right gem-amp combo gem gems[len]; // for every speccing value gemO amps[len]; // we'll choose the best amps double powers[len]; gem_init(gems,1,1,0); gem_init_O(amps,0,0); powers[0]=0; double leech_ratio=Namps*(0.15+As/3*0.004)*2*(1+0.03*TC)/(1+TC/3*0.1); double NT=pow(2, GT-1); if (!(output_options & mask_quiet)) { printf("Managem spec\n"); gem_print(gems); printf("Amplifier spec (x%d)\n", Namps); gem_print_O(amps); printf("Spec base power: \t0\n\n\n"); } for (i=1;i<len;++i) { // for every gem value gems[i]=(gem){0}; // we init the gems amps[i]=(gemO){0}; // to extremely weak ones for (k=0;k<poolf_length[i];++k) { // first we compare the gem alone if (gem_power(poolf[i][k]) > gem_power(gems[i])) { gems[i]=poolf[i][k]; } } int NS=i+1; double C0 = pow(NT/(i+1), bestc_growth); // last we compute the combination number powers[i] = C0 * gem_power(gems[i]); // now we compare the whole setup for (j=0, NS+=Namps; j<i+1; ++j, NS+=Namps) { // for every amp value from 1 up to gem_value double Cg = pow(NT/NS, bestc_growth); // we compute the combination number double Pa = leech_ratio * bestO[j].leech; // we already know the best amps for (k=0; k<poolf_length[i]; ++k) { // we look in the reduced gem pool double Palone = gem_power(poolf[i][k]); double Pbase = Palone + Pa * poolf[i][k].bbound; double power = Cg * Pbase; if (power>powers[i]) { powers[i]=power; gems[i]=poolf[i][k]; amps[i]=bestO[j]; } } } if (!(output_options & mask_quiet)) { printf("Managem spec\n"); printf("Value:\t%d\n",i+1); if (output_options & mask_debug) printf("Pool:\t%d\n",poolf_length[i]); gem_print(gems+i); printf("Amplifier spec (x%d)\n", Namps); printf("Value:\t%d\n",gem_getvalue_O(amps+i)); gem_print_O(amps+i); printf("Setup combine\n"); printf("Comb:\t%d\n",lenc); gem_print(&bestc); printf("Spec base power: \t%#.7g\n", gem_amp_power(gems[i], amps[i], leech_ratio)); printf("Global power at g%d:\t%#.7g\n\n\n", GT, powers[i]); } } if (output_options & mask_quiet) { // outputs last if we never seen any printf("Managem spec\n"); printf("Value:\t%d\n",len); gem_print(gems+len-1); printf("Amplifier spec (x%d)\n", Namps); printf("Value:\t%d\n",gem_getvalue_O(amps+len-1)); gem_print_O(amps+len-1); printf("Setup combine\n"); printf("Comb:\t%d\n",lenc); printf("Growth:\t%f\n", bestc_growth); gem_print(&bestc); printf("Spec base power: \t%#.7g\n", gem_amp_power(gems[len-1], amps[len-1], leech_ratio)); printf("Global power at g%d:\t%#.7g\n\n\n", GT, powers[len-1]); } gem* gemf = gems+len-1; // gem that will be displayed gemO* ampf = amps+len-1; // amp that will be displayed gem* gemfc= &bestc; // gemc that will be displayed if (output_options & mask_upto) { double best_pow=0; int best_index=0; for (i=0; i<len; ++i) { if (powers[i] > best_pow) { best_index=i; best_pow=powers[i]; } } printf("Best setup up to %d:\n\n", len); printf("Managem spec\n"); printf("Value:\t%d\n", gem_getvalue(gems+best_index)); gem_print(gems+best_index); printf("Amplifier spec (x%d)\n", Namps); printf("Value:\t%d\n", gem_getvalue_O(amps+best_index)); gem_print_O(amps+best_index); printf("Setup combine\n"); printf("Comb:\t%d\n",lenc); gem_print(gemfc); printf("Spec base power: \t%#.7g\n", gem_amp_power(gems[best_index], amps[best_index], leech_ratio)); printf("Global power at g%d:\t%#.7g\n\n\n", GT, powers[best_index]); gemf = gems+best_index; ampf = amps+best_index; } gem* gem_array; gem red; if (output_options & mask_red) { if (len < 3) printf("I could not add red!\n\n"); else { int value = gem_getvalue(gemf); int valueA= gem_getvalue_O(ampf); double NS = value + Namps*valueA; double amp_leech_scaled = leech_ratio * ampf->leech; gemf = gem_putred(poolf[value-1], poolf_length[value-1], value, &red, &gem_array, amp_leech_scaled); printf("Setup with red added:\n\n"); printf("Managem spec\n"); printf("Value:\t%d\n", value); // made to work well with -u gem_print(gemf); printf("Amplifier spec (x%d)\n", Namps); printf("Value:\t%d\n",gem_getvalue_O(ampf)); gem_print_O(ampf); printf("Setup combine\n"); printf("Comb:\t%d\n",lenc); gem_print(gemfc); printf("Spec base power with red:\t%#.7g\n", gem_amp_power(*gemf, *ampf, leech_ratio)); double CgP = pow(NT/NS, bestc_growth); printf("Global power w. red at g%d:\t%#.7g\n\n\n", GT, CgP*gem_cfr_power(*gemf, amp_leech_scaled)); } } if (output_options & mask_parens) { printf("Managem speccing scheme:\n"); print_parens_compressed(gemf); printf("\n\n"); printf("Amplifier speccing scheme:\n"); print_parens_compressed_O(ampf); printf("\n\n"); printf("Setup combining scheme:\n"); print_parens_compressed(gemfc); printf("\n\n"); } if (output_options & mask_tree) { printf("Managem speccing tree:\n"); print_tree(gemf, ""); printf("\n"); printf("Amplifier speccing tree:\n"); print_tree_O(ampf, ""); printf("\n"); printf("Setup combining tree:\n"); print_tree(gemfc, ""); printf("\n"); } if (output_options & mask_table) print_omnia_table(gems, amps, powers, len); if (output_options & mask_equations) { // it ruins gems, must be last printf("Managem speccing equations:\n"); print_equations(gemf); printf("\n"); printf("Amplifier speccing equations:\n"); print_equations_O(ampf); printf("\n"); printf("Setup combining equations:\n"); print_equations(gemfc); printf("\n"); } for (i=0;i<len;++i) free(pool[i]); // free gems for (i=0;i<len;++i) free(poolf[i]); // free gems compressed for (i=0;i<lenc;++i) free(poolc[i]); // free gems free(poolc); free(poolc_length); for (i=0;i<lena;++i) free(poolO[i]); // free amps free(bestO); // free amps compressed if (output_options & mask_red && len > 2) { free(gem_array); } }
void worker(int len, int output_options, int gem_limit, char* filename, char* filenameA, int TC, int As, int Namps) { FILE* table=file_check(filename); // file is open to read if (table==NULL) exit(1); // if the file is not good we exit int i; gem* pool[len]; int pool_length[len]; pool[0]=malloc(2*sizeof(gem)); pool_length[0]=2; gem_init(pool[0] ,1,1.000000,1,0); // grade damage crit bbound gem_init(pool[0]+1,1,1.186168,0,1); // BB has more dmg int prevmax=pool_from_table(pool, pool_length, gem_limit, table); // killgem pool filling fclose(table); if (prevmax<len-1) { // if the killgems are not enough for (i=prevmax+1; i<len; ++i) { pool_length[i]=0; pool[i]=NULL; } } gem* poolf[len]; int poolf_length[len]; KGSPEC_COMPRESSION printf("Gem speccing pool compression done!\n"); FILE* tableA=file_check(filenameA); // fileA is open to read if (tableA==NULL) exit(1); // if the file is not good we exit int lena = Namps ? len/Namps : 1; // if Namps==0 let lena=1 gemY* poolY[lena]; int poolY_length[lena]; poolY[0]=malloc(sizeof(gemY)); poolY_length[0]=1; gem_init_Y(poolY[0],1,1,1); int prevmaxA=pool_from_table_Y(poolY, poolY_length, lena, tableA); // amps pool filling fclose(tableA); if (prevmaxA<lena-1) { for (i=0;i<=prevmaxA;++i) free(poolY[i]); // free if (prevmaxA>0) printf("Amp table stops at %d, not %d\n",prevmaxA+1,lena); exit(1); } gemY* poolYf[lena]; int poolYf_length[lena]; AMPS_COMPRESSION printf("Amp pool compression done!\n\n"); int j,k,h; // let's choose the right gem-amp combo gem gems[len]; gemY amps[len]; gem_init(gems,1,1,1,0); amps[0]=(gemY){0}; double crit_ratio =Namps*(0.15+As/3*0.004)*2*(1+0.03*TC)/(1.0+TC/3*0.1); double damage_ratio=Namps*(0.20+As/3*0.004) * (1+0.03*TC)/(1.2+TC/3*0.1); if (!(output_options & mask_quiet)) { printf("Total value:\t1\n\n"); printf("Killgem\n"); gem_print(gems); printf("Amplifier (x%d)\n", Namps); gem_print_Y(amps); } for (i=1;i<len;++i) { // for every total value gems[i]=(gem){0}; // we init the gems amps[i]=(gemY){0}; // to extremely weak ones for (k=0;k<poolf_length[i];++k) { // first we compare the gem alone if (gem_power(poolf[i][k]) > gem_power(gems[i])) { gems[i]=poolf[i][k]; } } double power = gem_power(gems[i]); if (Namps!=0) for (j=1;j<=i/Namps;++j) { // for every amount of amps we can fit in int value = i-Namps*j; // this is the amount of gems we have left for (k=0;k<poolf_length[value];++k) { // we search in that pool for (h=0;h<poolYf_length[j-1];++h) { // and we look in the amp pool if (gem_amp_power(poolf[value][k], poolYf[j-1][h], damage_ratio, crit_ratio) > power) { power = gem_amp_power(poolf[value][k], poolYf[j-1][h], damage_ratio, crit_ratio); gems[i]=poolf[value][k]; amps[i]=poolYf[j-1][h]; } } } } if (!(output_options & mask_quiet)) { printf("Total value:\t%d\n\n", i+1); if (prevmax<len-1) printf("Killgem limit:\t%d\n", prevmax+1); printf("Killgem\n"); printf("Value:\t%d\n",gem_getvalue(gems+i)); if (output_options & mask_debug) printf("Pool:\t%d\n",poolf_length[gem_getvalue(gems+i)-1]); gem_print(gems+i); printf("Amplifier (x%d)\n", Namps); printf("Value:\t%d\n",gem_getvalue_Y(amps+i)); if (output_options & mask_debug) printf("Pool:\t%d\n",poolYf_length[gem_getvalue_Y(amps+i)-1]); gem_print_Y(amps+i); printf("Spec base power: \t%#.7g\n\n", gem_amp_power(gems[i], amps[i], damage_ratio, crit_ratio)); } } if (output_options & mask_quiet) { // outputs last if we never seen any printf("Total value:\t%d\n\n", len); if (prevmax<len-1) printf("Killgem limit:\t%d\n", prevmax+1); printf("Killgem\n"); printf("Value:\t%d\n", gem_getvalue(gems+len-1)); gem_print(gems+len-1); printf("Amplifier (x%d)\n", Namps); printf("Value:\t%d\n", gem_getvalue_Y(amps+len-1)); gem_print_Y(amps+len-1); printf("Spec base power: \t%#.7g\n\n", gem_amp_power(gems[len-1], amps[len-1], damage_ratio, crit_ratio)); } gem* gemf=gems+len-1; // gem that will be displayed gemY* ampf=amps+len-1; // amp that will be displayed gem* gem_array; gem red; if (output_options & mask_red) { if (len < 3) printf("I could not add red!\n\n"); else { int value=gem_getvalue(gemf); gemf = gem_putred(poolf[value-1], poolf_length[value-1], value, &red, &gem_array, damage_ratio*ampf->damage, crit_ratio*ampf->crit); printf("Setup with red added:\n\n"); printf("Total value:\t%d\n\n", value+Namps*gem_getvalue_Y(ampf)); printf("Killgem\n"); printf("Value:\t%d\n", value); gem_print(gemf); printf("Amplifier (x%d)\n", Namps); printf("Value:\t%d\n", gem_getvalue_Y(ampf)); gem_print_Y(ampf); printf("Spec base power with red:\t%#.7g\n\n", gem_amp_power(*gemf, *ampf, damage_ratio, crit_ratio)); } } if (output_options & mask_parens) { printf("Killgem speccing scheme:\n"); print_parens_compressed(gemf); printf("\n\n"); printf("Amplifier speccing scheme:\n"); print_parens_compressed_Y(ampf); printf("\n\n"); } if (output_options & mask_tree) { printf("Killgem tree:\n"); print_tree(gemf, ""); printf("\n"); printf("Amplifier tree:\n"); print_tree_Y(ampf, ""); printf("\n"); } if (output_options & mask_table) print_ngems_table(gems, amps, damage_ratio, crit_ratio, len); if (output_options & mask_equations) { // it ruins gems, must be last printf("Killgem equations:\n"); print_equations(gemf); printf("\n"); printf("Amplifier equations:\n"); print_equations_Y(ampf); printf("\n"); } for (i=0;i<len;++i) free(pool[i]); // free gems for (i=0;i<len;++i) free(poolf[i]); // free gems compressed for (i=0;i<lena;++i) free(poolY[i]); // free amps for (i=0;i<lena;++i) free(poolYf[i]); // free amps compressed if (output_options & mask_red && len > 2) { free(gem_array); } }
void worker(int len, int output_options, int pool_zero, char* filename) { FILE* table=file_check(filename); // file is open to read if (table==NULL) exit(1); // if the file is not good we exit int i; gem* gems=malloc(len*sizeof(gem)); // if not malloc-ed 230k is the limit gem** pool=malloc(len*sizeof(gem*)); int* pool_length=malloc(len*sizeof(int)); pool[0]=malloc(pool_zero*sizeof(gem)); pool_length[0]=pool_zero; if (pool_zero==1) { // combine gem_init(pool[0],1,1,1,1); // start gem does not matter gem_init(gems ,1,1,1,1); // grade damage crit bbound } else { // spec gem_init(pool[0] ,1,DAMAGE_CRIT ,1,0); gem_init(pool[0]+1,1,DAMAGE_BBOUND,0,1); // BB has more dmg gem_init(gems ,1,DAMAGE_CRIT ,1,0); // grade damage crit bbound } int prevmax=pool_from_table(pool, pool_length, len, table); // pool filling fclose(table); // close if (prevmax<len-1) { for (i=0;i<=prevmax;++i) free(pool[i]); // free free(pool); // free free(pool_length); // free free(gems); // free if (prevmax>0) printf("Table stops at %d, not %d\n",prevmax+1,len); exit(1); } int skip_computations = (output_options & mask_quiet) && !((output_options & mask_table) || (output_options & mask_upto)); int first = skip_computations ? len-1 : 0; for (i=first; i<len; ++i) { gems[i]=pool[i][0]; for (int j=1; j<pool_length[i]; ++j) { if (gem_more_powerful(pool[i][j],gems[i])) { gems[i]=pool[i][j]; } } if (!(output_options & mask_quiet)) { printf("Value:\t%d\n",i+1); if (output_options & mask_info) printf("Growth:\t%f\n", log(gem_power(gems[i]))/log(i+1)); if (output_options & mask_debug) printf("Pool:\t%d\n",pool_length[i]); gem_print(gems+i); } } if (output_options & mask_quiet) { // outputs last if we never seen any printf("Value:\t%d\n",len); printf("Growth:\t%f\n", log(gem_power(gems[len-1]))/log(len)); if (output_options & mask_debug) printf("Pool:\t%d\n",pool_length[len-1]); gem_print(gems+len-1); } gem* gemf=gems+len-1; // gem that will be displayed if (output_options & mask_upto) { double best_growth=-INFINITY; int best_index=0; for (i=0; i<len; ++i) { if (log(gem_power(gems[i]))/log(i+1) > best_growth) { best_index=i; best_growth=log(gem_power(gems[i]))/log(i+1); } } printf("Best gem up to %d:\n\n", len); printf("Value:\t%d\n",best_index+1); printf("Growth:\t%f\n", best_growth); gem_print(gems+best_index); gemf = gems+best_index; } gem* gem_array = NULL; gem red; if (output_options & mask_red) { if (len < 3 || pool_zero!=2) printf("I could not add red!\n\n"); else { int value=gem_getvalue(gemf); gemf = gem_putred(pool[value-1], pool_length[value-1], value, &red, &gem_array, 0, 0); printf("Gem with red added:\n\n"); printf("Value:\t%d\n", value); // made to work well with -u printf("Growth:\t%f\n", log(gem_power(*gemf))/log(value)); gem_print(gemf); } } if (output_options & mask_parens) { printf("Compressed combining scheme:\n"); print_parens_compressed(gemf); printf("\n\n"); } if (output_options & mask_tree) { printf("Gem tree:\n"); print_tree(gemf, ""); printf("\n"); } if (output_options & mask_table) print_table(gems, len); if (output_options & mask_equations) { // it ruins gems, must be last printf("Equations:\n"); print_equations(gemf); printf("\n"); } for (i=0;i<len;++i) free(pool[i]); // free free(pool); free(pool_length); free(gems); if (output_options & mask_red && len > 2 && pool_zero==2) { free(gem_array); } }
int main(int argc, char *argv[]) { int result = ACTION_NONE; int leave = 0; char *editor_file = 0; char path[512]; SDL_Surface *loading; #ifdef __unix__ gid_t realgid; hi_dir_chart_file = fopen(HI_DIR "/" CHART_FILE_NAME, "r+"); /* This is where we drop our setuid/setgid privileges. */ realgid = getgid(); if (setresgid(-1, realgid, realgid) != 0) { perror("Could not drop setgid privileges. Aborting."); exit(1); } #endif /* i18n */ #ifdef ENABLE_NLS setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); #endif #ifdef _WIN32 /* Get Windows to open files in binary mode instead of default text mode */ _fmode = _O_BINARY; #endif /* lbreakout info */ printf( "LBreakout2 %s\nCopyright 2001-2010 Michael Speck\nPublished under GNU GPL\n---\n", VERSION ); printf( "Looking up data in: %s\n", SRC_DIR ); printf( "Looking up highscores in: %s\n", HI_DIR ); printf( "Looking up custom levels in: %s/%s/lbreakout2-levels\n", (getenv( "HOME" )?getenv( "HOME" ):"."), CONFIG_DIR_NAME ); #ifndef AUDIO_ENABLED printf( "Compiled without sound and music\n" ); #endif set_random_seed(); /* set random seed */ config_load(); stk_init( SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK ); if ( config.fullscreen ) stk_display_open( SDL_SWSURFACE | SDL_FULLSCREEN, 640, 480, 16 ); else stk_display_open( SDL_SWSURFACE, 640, 480, 16 ); stk_audio_open( 0,0,0,config.audio_buffer_size ); SDL_WM_SetCaption( "LBreakout2", 0 ); SDL_SetEventFilter( event_filter ); stk_audio_enable_sound( config.sound ); stk_audio_set_sound_volume( config.volume * 16 ); /* load a little loading pic */ stk_surface_set_path( SRC_DIR "/gfx" ); loading = stk_surface_load( SDL_SWSURFACE, "loading.png" ); stk_surface_blit( loading, 0,0,-1,-1, stk_display, (stk_display->w-loading->w)/2, (stk_display->h-loading->h)/2 ); stk_display_update( STK_UPDATE_ALL ); /* load the GUI graphics from SRC_DIR/gui_theme */ stk_surface_set_path( SRC_DIR ); stk_audio_set_path( SRC_DIR ); gui_init( "gui_theme" ); stk_surface_set_path( SRC_DIR "/gfx" ); stk_audio_set_path( SRC_DIR "/sounds" ); /* load resources */ /* for simplicity all functions are kept but anything * that is now themeable is loaded in * theme_load instead of the original function * (deleting resources works analouge) */ theme_get_list(); if ( config.theme_count != theme_count ) { if ( config.theme_id >= theme_count ) config.theme_id = 0; config.theme_count = theme_count; } theme_load( theme_names[config.theme_id] ); /* old functions still with initialzations of * lists or variables */ client_game_create(); hint_load_res(); chart_load(); manager_create(); client_create(); exp_load(); editor_create(); help_create(); /* run game */ manager_fade( STK_FADE_IN ); while( !leave && !stk_quit_request ) { result = manager_run(); switch( result ) { case ACTION_QUIT: leave = 1; break; case ACTION_RESUME_0: manager_fade( STK_FADE_OUT ); if ( client_game_resume_local( 0 ) ) client_game_run(); client_game_finalize(); manager_fade( STK_FADE_IN ); break; case ACTION_PLAY_LBR: manager_fade( STK_FADE_OUT ); gameSeed = rand(); /* set random seed for next FREAKOUT/BonusLevels */ if ( client_game_init_local( "LBreakout2" ) ) client_game_run(); client_game_finalize(); manager_fade( STK_FADE_IN ); break; case ACTION_PLAY_CUSTOM: manager_fade( STK_FADE_OUT ); gameSeed = rand(); /* set random seed for next FREAKOUT/BonusLevels */ if (gameSeed==0) gameSeed=1; /* not allowed because.... A HACK!!! 0 means to have no bonus levels to save a parameter */ if ( client_game_init_local( levelset_names_local[config.levelset_id_local] ) ) client_game_run(); client_game_finalize(); manager_fade( STK_FADE_IN ); break; case ACTION_EDIT: /* new set? */ if ( strequal( NEW_SET, edit_set ) ) { editor_file = calloc( 16, sizeof( char ) ); snprintf( path, sizeof(path)-1, "%s/%s/lbreakout2-levels", getenv( "HOME" )? getenv("HOME"):".", CONFIG_DIR_NAME ); if ( !enter_string( font, _("Set Name:"), editor_file, 12 ) || !file_check( path, editor_file, "w" ) ) { free( editor_file ); break; } else manager_update_set_list(); } else editor_file = strdup( edit_set ); if ( editor_init( editor_file ) ) { manager_fade( STK_FADE_OUT ); editor_run(); editor_clear(); manager_fade( STK_FADE_IN ); } free( editor_file ); editor_file = 0; break; case ACTION_QUICK_HELP: help_run(); break; case ACTION_CLIENT: manager_fade( STK_FADE_OUT ); client_run(); manager_fade( STK_FADE_IN ); break; default: break; } } manager_fade( STK_FADE_OUT ); /* delete stuff */ help_delete(); manager_delete(); chart_save(); chart_delete(); editor_delete(); exp_delete(); client_game_delete(); hint_delete_res(); theme_delete(); theme_delete_list(); stk_surface_free( &loading ); config_save(); if (hi_dir_chart_file) fclose(hi_dir_chart_file); return EXIT_SUCCESS; }
static int file_read(lua_State *L) { lua_apr_file *file = file_check(L, 1, 1); return read_buffer(L, &file->input); }
static int file_write(lua_State *L) { lua_apr_file *file = file_check(L, 1, 1); return write_buffer(L, &file->output); }
static void dir_check(struct dir_info *dir) { struct dir_entry_info **entry_array, **p; size_t sz, n; struct dir_entry_info *entry; DIR *d; struct dirent *ent; unsigned checked = 0; char *path; int link_count = 2; /* Parent and dot */ struct stat st; /* Create an array of entries */ sz = sizeof(struct dir_entry_info *); n = dir->number_of_entries; entry_array = (struct dir_entry_info **) malloc(sz * n); CHECK(entry_array != NULL); entry = dir->first; p = entry_array; while (entry) { *p++ = entry; entry->checked = 0; entry = entry->next; } /* Sort it by name */ qsort(entry_array, n, sz, sort_comp); /* Go through directory on file system checking entries match */ path = dir_path(dir->parent, dir->name); d = opendir(path); CHECK(d != NULL); for (;;) { errno = 0; ent = readdir(d); if (ent) { if (strcmp(".",ent->d_name) != 0 && strcmp("..",ent->d_name) != 0) { dir_entry_check(entry_array, n, ent); checked += 1; } } else { CHECK(errno == 0); break; } } CHECK(closedir(d) != -1); CHECK(checked == dir->number_of_entries); /* Now check each entry */ entry = dir->first; while (entry) { if (entry->type == 'd') { dir_check(entry->entry.dir); link_count += 1; /* <subdir>/.. */ } else if (entry->type == 'f') file_check(entry->entry.file, -1); else if (entry->type == 's') symlink_check(entry->entry.symlink); else CHECK(0); entry = entry->next; } CHECK(stat(path, &st) != -1); CHECK(link_count == st.st_nlink); free(entry_array); free(path); }
static int file_lines(lua_State *L) { lua_apr_file *file = file_check(L, 1, 1); return read_lines(L, &file->input); }
int cmd_more(char file[]) { kol_struct70 k70; kol_struct_BDVK bdvk; unsigned result, filesize, pos, i; char buf[81]; //буфер char temp[256]; unsigned flags; if (strlen(file)<1) { #if LANG_ENG printf (" more <filename>\n\r"); #elif LANG_RUS printf (" more <имя файла>\n\r"); #endif return TRUE; } if ( '/' == file[0]) { strcpy(temp, file); if ( !file_check(temp) ) { file_not_found(file); return FALSE; } } else { strcpy(temp, cur_dir); if (temp[strlen(temp)-1] != '/') strcat(temp, "/"); // add slash strcat(temp, file); if ( !file_check(temp) ) { file_not_found(file); return FALSE; } } k70.p00 = 5; k70.p04 = k70.p08 = k70.p12 = 0; k70.p16 = (unsigned) &bdvk; k70.p20 = 0; k70.p21 = temp; result = kol_file_70(&k70); // получаем информацию о файле if ( 0 != result ) return FALSE; filesize = bdvk.p32[0]; // получаем размер файла buf[80]=0; flags = con_get_flags(); for (pos=0;pos<filesize;pos+=80) { memset(buf, 0, 80); k70.p00 = 0; k70.p04 = pos; k70.p08 = 0; k70.p12 = 80; k70.p16 = (unsigned) buf; k70.p20 = 0; k70.p21 = temp; result = kol_file_70(&k70); // чтение 80 символов for (i=0; i<80; i++) { if (27 == buf[i]) con_set_flags(flags|0x100); else con_set_flags(flags); printf ("%c", buf[i]); } if ( 0 != result ) { con_set_flags(flags); printf ("\n\r"); return TRUE; } } con_set_flags(flags); printf ("\n\r"); return TRUE; }
void Buyer::Buyticket() { Time time; int tag,selln; string line,type,dep_station,arr_station,temp,schedule; if(!time.Time_check()) { cout<<"Today's train schedules are not updated!"<<endl; return; } chdir(time.Show_file_curdir()); ifstream file_index("index.txt"); cout<<"which station start:";cin>>dep_station; cout<<"which station arrive:";cin>>arr_station; cout<<endl; while(getline(file_index,line)) { if(line.find("[dep_station] " + dep_station) != -1) { getline(file_index,line); if(line.find("[arr_station] " + arr_station) != -1) { getline(file_index,line); schedule = line; line = line + ".txt"; ifstream file_train(line); while(getline(file_train,line)) cout<<line<<endl; file_train.close(); cout<<endl; cout<<"Noseat => 1"<<endl; cout<<"Hardseat => 2"<<endl; cout<<"Hardbed => 3"<<endl; cout<<"Softbed => 4"<<endl; cout<<endl; cout<<"Buy what kind of ticket:"<<endl; cout<<"Please enter the number behind the type:";cin>>tag; chdir("..\\.."); ifstream file_check(File_user()); while(getline(file_check,line)) { if(line.find("[dep_station] " + dep_station) != -1) { getline(file_check,line); if(line.find("[arr_station] " + arr_station) != -1) { cout<<"repeat!"<<endl; return; } } } switch(tag) { case 1 : type = "noseat"; break; case 2 : type = "hardseat"; break; case 3 : type = "hardbed"; break; case 4 : type = "softbed"; break; default: cout<<"No such select !"<<endl; return; } ofstream file_user(File_user(), ios::out | ios::app); file_user<<endl; file_user<<"[schedule] "<<schedule<<endl; file_user<<"[date] "<<time.Show_cur()<<endl; file_user<<"[dep_station] "<<dep_station<<endl; file_user<<"[arr_station] "<<arr_station<<endl; file_user<<"[ticket_tag] "<<type<<endl; file_user.close(); chdir(time.Show_file_curdir()); ifstream infile(schedule + ".txt"); ofstream outfile("temp.txt"); while(getline(infile,line)) { if(line.find(type + "_selln") != -1) { stringstream str(line); while(str >> temp) selln = atoi(temp.c_str()); ++selln; outfile<<"["<<type<<"_selln] "<<selln<<endl; } else outfile<<line<<endl; }
struct network * file_to_linkedlist(char *path) { #ifdef DEBUG printf(" Entering file_to_linkedlist\n"); #endif struct ap_scan_info *node_info; struct network * node; int bytes_read; int listsize; // SIZE OF THE LIST (BYTES) node = NULL; network mainlist = NULL; //STEP 1_ CHECK IF THE GIVEN FILE ALREADY EXISTS //1.1 THE FILE DOES NOT EXIST -> RECALL THE FUNCTION if (file_check(path)==0) { printf(" File %s does not exist.\n",path); printf(" Perharps you wrote a wrong path.\n"); } //1.2 THE FILE DOES EXIST -> THE PROCCESS PROCEEDS else if (file_check(path)==1) { file = fopen(path, "r"); #ifdef DEBUG printf(" Opening the file %s\n",path); #endif //STEP 2_ LOOK HOW MANY NODES THE LIST HAS bytes_read = fread(&listsize,sizeof(int),1,file); //STEP 3_ CREATE AND INSERT (list_size) number of NODES for(i = 0; i < listsize ; i++) { node_info = (struct ap_scan_info*)malloc(sizeof(struct ap_scan_info)); //3.1 READ THE FIELD "mac" for (j =0 ; j < MAC_SIZE ; j++) { bytes_read = fread(&(node_info->mac[j]),sizeof(char),1,file); } //3.2 READ THE FIELD "essid" bytes_read = fread(&size,sizeof(int),1,file); node_info -> essid = (char*)calloc((sizeof(char)*size + 1),size); bytes_read = fread(node_info -> essid,sizeof(char),size,file); //3.3 READ THE FIELD enum network_mode mode; size=sizeof(enum network_mode); fread(&node_info->mode,size,1,file); //3.4 READ THE FIELD channel; //bytes_read = fread(&size,sizeof(int),1,file); bytes_read = fread(&(node_info -> channel),sizeof(int),1,file); //3.5 READ THE FIELD encrypted bytes_read = fread(&(node_info -> encrypted),sizeof(unsigned short),1,file); //ONLY READS 1 BYTE //3.6 READ THE FIELD quality for(k = 0 ; k < 2 ; k++) { bytes_read = fread(&(node_info -> quality[k]),sizeof(unsigned int),1,file); } //3.7 CREATE NODE node = create_node(node_info, count_nodes(mainlist) + 1); free(node_info); //3.8 INSERT NODE mainlist = insert_node(node , mainlist); //3.9 SORT THE NEW LIST mainlist = sort(mainlist); } if (fclose(file)!=0) { #ifdef DEBUG printf(" Closing the file\n"); #endif printf("[ERROR]: It's impossible to close the file\n"); } } //1.3 UNNEXPECTED ERROR -> END else printf(" Unexpected Error.\n"); #ifdef DEBUG printf(" Exiting file_to_linkedlist\n"); #endif return mainlist; }
/* ----------------------------------------- Main -----------------------------------------------------------------------*/ void main() { int places[25] = {5,0,0,0,-3,0,-5,0,0,0,0,2,-2,0,0,0,0,5,0,3,0,0,0,-5,0}; int n1,n2,off=0,off2=0,turn,win; char player1[20],player2[20]; /* ----------------------------------------- Init number generator and display initial board -----------------------------------------------------------------------*/ srand(time(NULL)); display_chars(off,off2,places); /* ----------------------------------------- Ask player names and compare to database -----------------------------------------------------------------------*/ gotoxy(1,16); cout << "Player 1? "; cin >> player1; cout << "Player 2? "; cin >> player2; file_check(player1,player2); /* ----------------------------------------- Determine who moves first -----------------------------------------------------------------------*/ do { n1=(rand()%6)+1; n2=(rand()%6)+1; if (n1==n2) continue; cout << '\n' << player1 << " rolled " << n1; cout << '\n' << player2 << " rolled " << n2; if (n1>n2) { cout << "\n\n" << player1 << ", you go first!"; turn=1; break; } else { cout << "\n\n" << player2 << ", you go first!"; turn=2; break; } } while (n1==n2); cout << " <Press a key>"; getch(); /* ----------------------------------------- Main -----------------------------------------------------------------------*/ win=move(player1,player2,turn,off,off2,places); /* ----------------------------------------- End game -----------------------------------------------------------------------*/ clrscr(); if (off==WIN) cout << "Congratulations, " << player1 << ", you win!\n\n"; else cout << "Congratulations, " << player2 << ", you win!\n\n"; /* ----------------------------------------- File Appendages -----------------------------------------------------------------------*/ file_chg(player1,player2,win); }
static int file_flush(lua_State *L) { lua_apr_file *file = file_check(L, 1, 1); apr_status_t status = flush_buffer(L, &file->output, 0); return push_file_status(L, file, status); }
int DialogClone::restore_image_partition() { QString befehl; int pos; QString partition_exist; QString partition_exist_size; QString part_name; Qt::CheckState state; lbl_save->setText (tr("already restored", "bereits zurückgeschrieben")); state = chk_zip->checkState(); flag_clone = 3; partition_exist_size_int = img_partition_size.toInt(); if (img_partition_clone == "" ){ QMessageBox::about(this, tr("Note", "Hinweis"), tr("You must select a partition.", "Sie müssen eine Partitiom auswählen.\n")); return 0; } if (folder_clone == "" ){ QMessageBox::about(this, tr("Note", "Hinweis"), tr("You must select a part.fsa file or an part.fsa.gz file.", "Sie müssen eine part.fsa- oder eine part.fsa.gz-Datei auswählen.\n")); return 0; } if (file_check() == 1) return 0; // Prüfen, ob gesicherte und wiederherzustellende Partition übereinstimmt. // Partition aus folder_clone extrahieren pos = folder_clone.indexOf("-gz.part"); if (pos > -1) part_name = folder_clone.mid(pos-15,4); pos = folder_clone.indexOf("-part"); if (pos > -1) part_name = folder_clone.mid(pos-15,4); //Prüfen ob Partition zeistellig ist pos = part_name.indexOf("sd"); if (pos == -1) part_name= "s" + part_name; if (folder_clone.indexOf(img_partition_clone) == -1) pos = questionMessage(tr("Partition to restore ", "Die wiederherzustellende Partition ") + part_name + tr(" does not coincide with the saved ", " stimmt nicht mit der gesicherten ") + img_partition_clone + tr(" Do you want to continue restore?", " überein. Wollen Sie trotzdem die Wiederherstellung durchführen?")); if (pos == 2) //nicht wiederherstellen return 0; // Überprüfen, ob System oder Home-Partition auf der Festplatte vorhanden ist int part_art_clone = mountpoint(img_partition_clone); if (part_art_clone == 1){ QMessageBox::about(this, tr("Note", "Hinweis"), tr("On the hard drive exist a root or a home partition. You must need a live-CD.", "Auf der Festplatte ist eine root- oder home Partition. Sie müssen eine Live-CD benutzen.\n")); return 0; } partition_name = partition_exist.right(partition_exist.size() -4); //Prüfen ob img.fsa oder gz.fsa Datei if (folder_clone.indexOf("-gz.part.fsa") > -1) befehl = "gunzip -c " + folder_clone + " | sudo dd of=/dev/" + img_partition_clone; if (folder_clone.indexOf("-part.fsa") > -1) befehl = "dd if=" + folder_clone + " of=/dev/" + img_partition_clone + " bs=1M 2>" + homepath + "/.config/qt5-fsarchiver/disk.txt"; int ret = questionMessage(tr(" Do you want really restore an image of a partition? ", " Wollen Sie wirklich ein Abbild einer Partition zurückschreiben? ") ); if (ret == 2) return 0; if (ret == 1){ bt_end->setEnabled(false); bt_save->setEnabled(false); thread2.setValues( 0,befehl); ViewProzent(); this->setCursor(Qt::WaitCursor); pos = folder_clone.indexOf("gz.part"); if (pos > 0){ read_write_hd(); startThread2(1); } else startThread2(0); qDebug() << "The image is written back"; } return 0; }
void worker(int len, int lenc, int output_options, char* filename, char* filenamec, char* filenameA, int TC, int As, int GT, int Namps) { FILE* table=file_check(filename); // file is open to read if (table==NULL) exit(1); // if the file is not good we exit int i; gem* pool[len]; int pool_length[len]; pool[0]=malloc(2*sizeof(gem)); pool_length[0]=2; gem_init(pool[0] ,1,1.000000,1,0); // grade damage crit bbound gem_init(pool[0]+1,1,1.186168,0,1); // BB has more dmg int prevmax=pool_from_table(pool, pool_length, len, table); // killgem spec pool filling fclose(table); if (prevmax<len-1) { // if the killgems are not enough for (i=0;i<=prevmax;++i) free(pool[i]); // free if (prevmax>0) printf("Gem table stops at %d, not %d\n",prevmax+1,len); exit(1); } gem* poolf[len]; int poolf_length[len]; KGSPEC_COMPRESSION printf("Gem speccing pool compression done!\n"); FILE* tableA=file_check(filenameA); // fileA is open to read if (tableA==NULL) exit(1); // if the file is not good we exit int lena=len; // see which is bigger between spec len and comb len if (lenc > len) lena=lenc; // and we'll get the amp pool till there gemY** poolY=malloc(lena*sizeof(gemY*)); int* poolY_length=malloc(lena*sizeof(int)); poolY[0]=malloc(sizeof(gemY)); poolY_length[0]=1; gem_init_Y(poolY[0],1,1,1); int prevmaxA=pool_from_table_Y(poolY, poolY_length, lena, tableA); // amps pool filling fclose(tableA); if (prevmaxA<lena-1) { for (i=0;i<=prevmaxA;++i) free(poolY[i]); // free if (prevmaxA>0) printf("Amp table stops at %d, not %d\n",prevmaxA+1,lena); exit(1); } gemY** poolYf=malloc(lena*sizeof(gemY*)); // if not malloc-ed 140k is the limit int poolYf_length[lena]; AMPS_COMPRESSION gemY poolYc[poolYf_length[lenc-1]]; int poolYc_length=poolYf_length[lenc-1]; for (i=0; i<poolYf_length[lenc-1]; ++i) { // amps fast access combining pool poolYc[i]=poolYf[lenc-1][i]; } printf("Amp combining pool compression done!\n"); FILE* tablec=file_check(filenamec); // file is open to read if (tablec==NULL) exit(1); // if the file is not good we exit gem** poolc=malloc(lenc*sizeof(gem*)); int* poolc_length=malloc(lenc*sizeof(int)); poolc[0]=malloc(sizeof(gem)); poolc_length[0]=1; gem_init(poolc[0],1,1,1,1); int prevmaxc=pool_from_table(poolc, poolc_length, lenc, tablec); // killgem comb pool filling fclose(tablec); if (prevmaxc<lenc-1) { // if the killgems are not enough for (i=0;i<=prevmaxc;++i) free(poolc[i]); // free if (prevmaxc>0) printf("Gem table stops at %d, not %d\n",prevmaxc+1,lenc); exit(1); } gem* poolcf; int poolcf_length; KGCOMB_COMPRESSION printf("Killgem comb compressed pool size:\t%d\n",poolcf_length); int cpairs_length; cpair* cpairs; { // cpair compression int length = poolcf_length*poolYc_length; cpair* temp_array=malloc(length*sizeof(cpair)); int index=0; for (int l=0; l<poolcf_length; ++l) { for (int m=0; m<poolYc_length; ++m) { double power = gem_power(poolcf[l]); double rdmg = poolYc[m].damage/poolcf[l].damage; double rcrit = poolYc[m].crit / poolcf[l].crit; temp_array[index++] = (cpair){power, rdmg, rcrit, poolcf+l, poolYc+m, 0}; } } cpair_sort_rcrit(temp_array,length); /* work starts */ double lastrcrit=-1; int tree_cell=0; for (int l=0; l<length; ++l) { if (temp_array[l].rcrit == lastrcrit) temp_array[l].place=tree_cell-1; else { temp_array[l].place=tree_cell++; lastrcrit = temp_array[l].rcrit; } } cpair_sort_xyz(temp_array,length); int broken=0; int tree_length= 1 << (int)ceil(log2(tree_cell)); /* this is pow(2, ceil()) bitwise */ double* tree=malloc((tree_length*2)*sizeof(double)); for (int l=0; l<tree_length*2; ++l) tree[l]=0; /* init also tree[0], it's faster */ for (int l=length-1; l>=0; --l) { /* start from large rdmg */ cpair* p_cpair=temp_array+l; if (dtree_check_after(tree, tree_length, p_cpair->place, p_cpair->power)) { dtree_add_element(tree, tree_length, p_cpair->place, p_cpair->power); } else { p_cpair->combg=NULL; broken++; } } for (int l=0; l<tree_length*2; ++l) tree[l]=0; /* BgDaCa - iDa - iCa compression */ for (int l=0; l<length; ++l) { /* start from low rdmg */ cpair* p_cpair=temp_array+l; if (p_cpair->combg==NULL) continue; int place = tree_length -1 - p_cpair->place; /* reverse crit order */ if (dtree_check_after(tree, tree_length, place, cpair_BgDaCa(*p_cpair))) { dtree_add_element(tree, tree_length, place, cpair_BgDaCa(*p_cpair)); } else { p_cpair->combg=NULL; broken++; } } for (int l=0; l<tree_length*2; ++l) tree[l]=0; /* BgDaCg - iDa - Ca compression */ for (int l=0; l<length; ++l) { /* start from low rdmg */ cpair* p_cpair=temp_array+l; if (p_cpair->combg==NULL) continue; int place = p_cpair->place; /* regular crit order */ if (dtree_check_after(tree, tree_length, place, cpair_BgDaCg(*p_cpair))) { dtree_add_element(tree, tree_length, place, cpair_BgDaCg(*p_cpair)); } else { p_cpair->combg=NULL; broken++; } } for (int l=0; l<tree_length*2; ++l) tree[l]=0; /* BgDgCa - Da - iCa compression */ for (int l=length-1; l>=0; --l) { /* start from large rdmg */ cpair* p_cpair=temp_array+l; if (p_cpair->combg==NULL) continue; int place = tree_length -1 - p_cpair->place; /* reverse crit order */ if (dtree_check_after(tree, tree_length, place, cpair_BgDgCa(*p_cpair))) { dtree_add_element(tree, tree_length, place, cpair_BgDgCa(*p_cpair)); } else { p_cpair->combg=NULL; broken++; } } free(tree); cpairs_length=length-broken; cpairs=malloc(cpairs_length*sizeof(cpair)); index=0; for (int j=0; j<length; ++j) { if (temp_array[j].combg!=NULL) { cpairs[index] = temp_array[j]; index++; } } free(temp_array); } printf("Combine pairs pool size:\t%d\n\n",cpairs_length); int j,k,h,l; // let's choose the right gem-amp combo gem gems[len]; // for every speccing value gemY amps[len]; // we'll choose the best amps gem gemsc[len]; // and the best NC combine gemY ampsc[len]; // for both double powers[len]; gem_init(gems,1,1,1,0); gem_init_Y(amps,0,0,0); gem_init(gemsc,1,1,0,0); gem_init_Y(ampsc,0,0,0); powers[0]=0; double iloglenc=1/log(lenc); double crit_ratio =Namps*(0.15+As/3*0.004)*2*(1+0.03*TC)/(1.0+TC/3*0.1); double damage_ratio=Namps*(0.20+As/3*0.004) * (1+0.03*TC)/(1.2+TC/3*0.1); double NT=pow(2, GT-1); if (!(output_options & mask_quiet)) { printf("Killgem spec\n"); gem_print(gems); printf("Amplifier spec (x%d)\n", Namps); gem_print_Y(amps); printf("Spec base power: \t0\n\n\n"); } for (i=1;i<len;++i) { // for every gem value gems[i]=(gem){0}; // we init the gems amps[i]=(gemY){0}; // to extremely weak ones gemsc[i]=(gem){0}; ampsc[i]=(gemY){0}; // first we compare the gem alone for (l=0; l<poolcf_length; ++l) { // first search in the NC gem comb pool if (gem_power(poolcf[l]) > gem_power(gemsc[i])) { gemsc[i]=poolcf[l]; } } for (k=0;k<poolf_length[i];++k) { // and then in the compressed gem pool if (gem_power(poolf[i][k]) > gem_power(gems[i])) { gems[i]=poolf[i][k]; } } int NS=i+1; double c0 = log(NT/(i+1))*iloglenc; // last we compute the combination number powers[i] = pow(gem_power(gemsc[i]),c0) * gem_power(gems[i]); // now we compare the whole setup for (j=0, NS+=Namps; j<i+1; ++j, NS+=Namps) { // for every amp value from 1 to to gem_value double c = log(NT/NS)*iloglenc; // we compute the combination number for (l=0; l<cpairs_length; ++l) { // then we search in the comb pair pool double Cg = pow(cpairs[l].power,c); double Rd = damage_ratio*pow(cpairs[l].rdmg, c); double Rc = crit_ratio * pow(cpairs[l].rcrit,c); for (h=0; h<poolYf_length[j]; ++h) { // then in the reduced amp pool double Pad = Rd * poolYf[j][h].damage; double Pac = Rc * poolYf[j][h].crit ; for (k=0; k<poolf_length[i]; ++k) { // and in the gem pool double Pext = Cg * poolf[i][k].bbound * poolf[i][k].bbound; double Pdamage = poolf[i][k].damage + Pad; double Pcrit = poolf[i][k].crit + Pac; double power = Pext * Pdamage * Pcrit ; if (power>powers[i]) { powers[i]=power; gems[i]=poolf[i][k]; amps[i]=poolYf[j][h]; gemsc[i]=*(cpairs[l].combg); ampsc[i]=*(cpairs[l].comba); } } } } } if (!(output_options & mask_quiet)) { printf("Killgem spec\n"); printf("Value:\t%d\n",i+1); if (output_options & mask_debug) printf("Pool:\t%d\n",poolf_length[i]); gem_print(gems+i); printf("Amplifier spec (x%d)\n", Namps); printf("Value:\t%d\n",gem_getvalue_Y(amps+i)); if (output_options & mask_debug) printf("Pool:\t%d\n",poolYf_length[gem_getvalue_Y(amps+i)-1]); gem_print_Y(amps+i); printf("Killgem combine\n"); printf("Comb:\t%d\n",lenc); if (output_options & mask_debug) printf("P.pool:\t%d\n", cpairs_length); gem_print(gemsc+i); printf("Amplifier combine\n"); printf("Comb:\t%d\n",lenc); gem_print_Y(ampsc+i); printf("Spec base power: \t%#.7g\n", gem_amp_power(gems[i], amps[i], damage_ratio, crit_ratio)); printf("Global power at g%d:\t%#.7g\n\n\n", GT, powers[i]); } } if (output_options & mask_quiet) { // outputs last if we never seen any printf("Killgem spec\n"); printf("Value:\t%d\n",len); gem_print(gems+len-1); printf("Amplifier spec (x%d)\n", Namps); printf("Value:\t%d\n",gem_getvalue_Y(amps+len-1)); gem_print_Y(amps+len-1); printf("Killgem combine\n"); printf("Comb:\t%d\n",lenc); if (output_options & mask_debug) printf("P.pool:\t%d\n", cpairs_length); gem_print(gemsc+len-1); printf("Amplifier combine\n"); printf("Comb:\t%d\n",lenc); gem_print_Y(ampsc+len-1); printf("Spec base power: \t%#.7g\n", gem_amp_power(gems[len-1], amps[len-1], damage_ratio, crit_ratio)); printf("Global power at g%d:\t%#.7g\n\n\n", GT, powers[len-1]); } gem* gemf = gems+len-1; // gem that will be displayed gemY* ampf = amps+len-1; // amp that will be displayed gem* gemfc=gemsc+len-1; // gemc that will be displayed gemY* ampfc=ampsc+len-1; // ampc that will be displayed if (output_options & mask_upto) { double best_pow=0; int best_index=0; for (i=0; i<len; ++i) { if (powers[i] > best_pow) { best_index=i; best_pow=powers[i]; } } printf("Best setup up to %d:\n\n", len); printf("Killgem spec\n"); printf("Value:\t%d\n", gem_getvalue(gems+best_index)); gem_print(gems+best_index); printf("Amplifier spec (x%d)\n", Namps); printf("Value:\t%d\n", gem_getvalue_Y(amps+best_index)); gem_print_Y(amps+best_index); printf("Killgem combine\n"); printf("Comb:\t%d\n",lenc); gem_print(gemsc+best_index); printf("Amplifier combine\n"); printf("Comb:\t%d\n",lenc); gem_print_Y(ampsc+best_index); printf("Spec base power: \t%#.7g\n", gem_amp_power(gems[best_index], amps[best_index], damage_ratio, crit_ratio)); printf("Global power at g%d:\t%#.7g\n\n\n", GT, powers[best_index]); gemf = gems+best_index; ampf = amps+best_index; gemfc = gemsc+best_index; ampfc = ampsc+best_index; } gem* gem_array; gem red; if (output_options & mask_red) { if (len < 3) printf("I could not add red!\n\n"); else { int value=gem_getvalue(gemf); int valueA= gem_getvalue_Y(ampf); double NS = value + Namps*valueA; double c = log(NT/NS)*iloglenc; double ampd_resc_coeff = pow((ampfc->damage/gemfc->damage), c); double ampc_resc_coeff = pow((ampfc->crit/gemfc->crit), c); double amp_damage_scaled = damage_ratio * ampd_resc_coeff * ampf->damage; double amp_crit_scaled = crit_ratio * ampc_resc_coeff * ampf->crit; gemf = gem_putred(poolf[value-1], poolf_length[value-1], value, &red, &gem_array, amp_damage_scaled, amp_crit_scaled); printf("Setup with red added:\n\n"); printf("Killgem spec\n"); printf("Value:\t%d\n", value); // made to work well with -u gem_print(gemf); printf("Amplifier spec (x%d)\n", Namps); printf("Value:\t%d\n", valueA); gem_print_Y(ampf); printf("Killgem combine\n"); printf("Comb:\t%d\n",lenc); gem_print(gemfc); printf("Amplifier combine\n"); printf("Comb:\t%d\n",lenc); gem_print_Y(ampfc); if (output_options & mask_debug) printf("Damage rescaling coeff.: \t%f\n", ampd_resc_coeff); if (output_options & mask_debug) printf("Crit rescaling coeff.: \t%f\n", ampc_resc_coeff); printf("Spec base power with red:\t%#.7g\n", gem_amp_power(*gemf, *ampf, damage_ratio, crit_ratio)); double CgP = pow(gem_power(*gemfc), c); printf("Global power w. red at g%d:\t%#.7g\n\n\n", GT, CgP*gem_cfr_power(*gemf, amp_damage_scaled, amp_crit_scaled)); } } if (output_options & mask_parens) { printf("Killgem speccing scheme:\n"); print_parens_compressed(gemf); printf("\n\n"); printf("Amplifier speccing scheme:\n"); print_parens_compressed_Y(ampf); printf("\n\n"); printf("Killgem combining scheme:\n"); print_parens_compressed(gemfc); printf("\n\n"); printf("Amplifier combining scheme:\n"); print_parens_compressed_Y(ampfc); printf("\n\n"); } if (output_options & mask_tree) { printf("Killgem speccing tree:\n"); print_tree(gemf, ""); printf("\n"); printf("Amplifier speccing tree:\n"); print_tree_Y(ampf, ""); printf("\n"); printf("Killgem combining tree:\n"); print_tree(gemfc, ""); printf("\n"); printf("Amplifier combining tree:\n"); print_tree_Y(ampfc, ""); printf("\n"); } if (output_options & mask_table) print_omnia_table(gems, amps, powers, len); if (output_options & mask_equations) { // it ruins gems, must be last printf("Killgem speccing equations:\n"); print_equations(gemf); printf("\n"); printf("Amplifier speccing equations:\n"); print_equations_Y(ampf); printf("\n"); printf("Killgem combining equations:\n"); print_equations(gemfc); printf("\n"); printf("Amplifier combining equations:\n"); print_equations_Y(ampfc); printf("\n"); } for (i=0;i<len;++i) free(pool[i]); // free gems for (i=0;i<len;++i) free(poolf[i]); // free gems compressed for (i=0;i<lenc;++i) free(poolc[i]); // free gems free(poolc); free(poolc_length); free(poolcf); for (i=0;i<lena;++i) free(poolY[i]); // free amps for (i=0;i<lena;++i) free(poolYf[i]); // free amps compressed free(poolY); free(poolY_length); free(poolYf); free(cpairs); if (output_options & mask_red && len > 2) { free(gem_array); } }