static void mem_warn(char *name,int size,int exitcode) { static char buf[128]; aprintf("\n" ANSI_RED "\aCannot allocate enough memory for " "function %s." ANSI_NORMAL "\n",name); comma_print(buf,size); aprintf(" " ANSI_RED "(Needed %s bytes.)" ANSI_NORMAL "\n\n",buf); if (exitcode!=0) { aprintf(" " ANSI_RED "Program terminated." ANSI_NORMAL "\n\n"); exit(exitcode); } }
int main(int argc, char** argv) { int64 counter=0; if (argc < 2) { usage_and_exit(); } const char* config_url = argv[1]; struct sconfig* config=sconfig_read(config_url); // this is the beginning of the table struct lensum_hash* hash = NULL; struct lensum* lensum = lensum_new(config->nbin); struct lensum* lensum_tot = lensum_new(config->nbin); while (lensum_read(stdin, lensum)) { counter++; if (counter == 1) { wlog("first lensum: %ld %ld %.8g %ld\n", lensum->index, lensum->zindex, lensum->weight, lensum->totpairs); } if ((counter % 10000) == 0) { wlog("."); } if (((counter+1) % 1000000) == 0) { wlog("\n"); comma_print(stderr,counter+1); wlog("\n"); } struct lensum_hash* this_lens = find_lens(hash, lensum->zindex); if (this_lens == NULL) { // copy of lensum made inside struct lensum_hash* lh = lensum_hash_fromlensum(lensum); // this gets expanded to lh->lensum->zindex HASH_ADD_INT64(hash, lensum->zindex, lh); } else { lensum_add(this_lens->lensum, lensum); } lensum_add(lensum_tot, lensum); } wlog("\nlast lensum: %ld %ld %.8g %ld\n", lensum->index, lensum->zindex, lensum->weight, lensum->totpairs); wlog("Read a total of %ld\n", counter); // this is the summary lensum_print(lensum_tot); wlog("Writing results to stdout\n"); struct lensum_hash *tlensum=NULL; for(tlensum=hash; tlensum != NULL; tlensum=tlensum->hh.next) { lensum_write(tlensum->lensum, stdout); } wlog("Done\n"); return 0; }