void MonteCarlo(collector *C, int NMC, REAL emean, REAL estdv, REAL sigma, REAL angle, REAL azimuth) { particle *P; trace *T; int NF; unsigned int seed; NF = 0; #if DEBUG printf("entering MonteCarlo for %d samples and storing into %lx (%d)\n", NMC, (long unsigned int) C, C->NTOTAL); #endif /* create the trace and particle */ fast_srand(&seed); T = alloc_trace(); P = (particle *) malloc(sizeof(particle)); /* the Monte Carlo loop */ //what is sigma?? if (sigma > AS_REAL(0.0)) { while (NF++ < NMC) { MakeParticle(P, normal(emean, estdv,&seed), angle+normal(AS_REAL(0.0), sigma,&seed), azimuth+normal(AS_REAL(0.0), sigma,&seed), &seed); reset_trace(T); while (P->energy > AS_REAL(0.0)) { proton_event(P, T, &seed); //stepping() } if (TRACE) dump_trace(stdout, T, P); collect(C, P, T); //Hits collection } } else { while (NF++ < NMC) { MakeParticle(P, normal(emean, estdv,&seed), angle, azimuth, &seed); reset_trace(T); while (P->energy > AS_REAL(0.0)) { proton_event(P, T, &seed); } if (TRACE) dump_trace(stdout, T, P); collect(C, P, T); } } }
void com_resume(wordlist *wl) { struct dbcomm *db; int err; /*rawfile output saj*/ bool dofile = FALSE; char buf[BSIZE_SP]; bool ascii = AsciiRawFile; /*end saj*/ NG_IGNORE(wl); /*saj fix segment*/ if (!ft_curckt) { fprintf(cp_err, "Error: there aren't any circuits loaded.\n"); return; } else if (ft_curckt->ci_ckt == NULL) { /* Set noparse? */ fprintf(cp_err, "Error: circuit not parsed.\n"); return; } /*saj*/ if (ft_curckt->ci_inprogress == FALSE) { fprintf(cp_err, "Note: run starting\n"); com_run(NULL); return; } ft_curckt->ci_inprogress = TRUE; ft_setflag = TRUE; reset_trace(); for (db = dbs, resumption = FALSE; db; db = db->db_next) if (db->db_type == DB_IPLOT || db->db_type == DB_IPLOTALL) resumption = TRUE; /*rawfile output saj*/ if (last_used_rawfile) dofile = TRUE; if (cp_getvar("filetype", CP_STRING, buf)) { if (eq(buf, "binary")) ascii = FALSE; else if (eq(buf, "ascii")) ascii = TRUE; else fprintf(cp_err, "Warning: strange file type \"%s\" (using \"ascii\")\n", buf); } if (dofile) { if (!last_used_rawfile) rawfileFp = stdout; #if defined(__MINGW32__) || defined(_MSC_VER) /* ask if binary or ASCII, open file with w or wb hvogt 15.3.2000 */ else if (ascii) { if ((rawfileFp = fopen(last_used_rawfile, "a")) == NULL) { setvbuf(rawfileFp, rawfileBuf, _IOFBF, RAWBUF_SIZE); perror(last_used_rawfile); ft_setflag = FALSE; return; } } else if (!ascii) { if ((rawfileFp = fopen(last_used_rawfile, "ab")) == NULL) { setvbuf(rawfileFp, rawfileBuf, _IOFBF, RAWBUF_SIZE); perror(last_used_rawfile); ft_setflag = FALSE; return; } } /*---------------------------------------------------------------------------*/ #else else if (!(rawfileFp = fopen(last_used_rawfile, "a"))) { setvbuf(rawfileFp, rawfileBuf, _IOFBF, RAWBUF_SIZE); perror(last_used_rawfile); ft_setflag = FALSE; return; } #endif rawfileBinary = !ascii; } else { rawfileFp = NULL; } /* if dofile */ /*end saj*/ err = if_run(ft_curckt->ci_ckt, "resume", NULL, ft_curckt->ci_symtab); /*close rawfile saj*/ if (rawfileFp) { if (ftell(rawfileFp) == 0) { (void) fclose(rawfileFp); (void) unlink(last_used_rawfile); } else { (void) fclose(rawfileFp); } } /*end saj*/ if (err == 1) { /* The circuit was interrupted somewhere. */ fprintf(cp_err, "simulation interrupted\n"); } else if (err == 2) { fprintf(cp_err, "simulation aborted\n"); ft_curckt->ci_inprogress = FALSE; } else { ft_curckt->ci_inprogress = FALSE; } }
void trace_stack (int argc, char **argv) { enum stack_type trace_type = STACK_REPORT; int c; if (argc < 2) usage(argv); if (strcmp(argv[1], "stack") != 0) usage(argv); for (;;) { int option_index = 0; static struct option long_options[] = { {"start", no_argument, NULL, OPT_start}, {"stop", no_argument, NULL, OPT_stop}, {"reset", no_argument, NULL, OPT_reset}, {"help", no_argument, NULL, '?'}, {NULL, 0, NULL, 0} }; c = getopt_long (argc-1, argv+1, "+h?", long_options, &option_index); if (c == -1) break; switch (c) { case 'h': usage(argv); break; case OPT_start: trace_type = STACK_START; break; case OPT_stop: trace_type = STACK_STOP; break; case OPT_reset: trace_type = STACK_RESET; break; default: usage(argv); } } test_available(); switch (trace_type) { case STACK_START: start_trace(); break; case STACK_STOP: stop_trace(); break; case STACK_RESET: reset_trace(); break; default: read_trace(); break; } return; }