int main(int argc, char *argv[]) { double T = -1, Q = -1; double lfac = 5; int i, n = -1, m = -1; int lmax = 0; int buffering_flag = 0, verbose_flag = 0; printf("# %s", argv[0]); for(i = 1; i < argc; i++) printf(", %s", argv[i]); printf("\n"); while (1) { int c; struct option long_options[] = { { "verbose", no_argument, &verbose_flag, 1 }, { "buffering", no_argument, &buffering_flag, 1 }, { "help", no_argument, 0, 'h' }, { "lscale", required_argument, 0, 'l' }, { 0, 0, 0, 0 } }; /* getopt_long stores the option index here. */ int option_index = 0; c = getopt_long (argc, argv, "Q:T:n:m:s:a:l:L:vqh", long_options, &option_index); /* Detect the end of the options. */ if (c == -1) break; switch (c) { case 0: /* If this option set a flag, do nothing else now. */ if (long_options[option_index].flag != 0) break; case 'Q': Q = atof(optarg); break; case 'T': T = atof(optarg); break; case 'L': lmax = atoi(optarg); case 'v': verbose_flag = 1; break; case 'l': lfac = atof(optarg); break; case 'n': n = atoi(optarg); break; case 'm': m = atoi(optarg); break; case 'h': usage(stdout); exit(0); case '?': /* getopt_long already printed an error message. */ break; default: abort(); } } // disable buffering if(!buffering_flag) { fflush(stdin); fflush(stderr); setvbuf(stdout, NULL, _IONBF, 0); setvbuf(stderr, NULL, _IONBF, 0); } if(lfac <= 0) { fprintf(stderr, "--lfac must be positive\n\n"); usage(stderr); exit(1); } if(Q <= 0 || Q >= 1) { fprintf(stderr, "-Q must be in 0 < Q < 1\n\n"); usage(stderr); exit(1); } if(T <= 0) { fprintf(stderr, "positive value for -T required\n\n"); usage(stderr); exit(1); } if(n < 0 || m < 0) { fprintf(stderr, "n,m >= 0\n\n"); usage(stderr); exit(1); } if(lmax <= 0) lmax = MAX((int)ceil(Q/(1-Q)*lfac), 5); printf("# lfac=%g\n", lfac); printf("# Q = %g\n", Q); printf("# n = %d\n", n); printf("# m = %d\n", m); printf("# lmax = %d\n", lmax); printf("#\n"); { casimir_t casimir; casimir_mie_cache_t cache; double value, start_time = now(); double nTRbyScriptL = n*T*Q; casimir_init(&casimir, Q, T); casimir_set_verbose(&casimir, verbose_flag); casimir_set_lmax(&casimir, lmax); casimir_mie_cache_init(&cache, nTRbyScriptL); casimir_mie_cache_alloc(&casimir, &cache); value = casimir_logdetD(&casimir, n, m, &cache); casimir_mie_cache_free(&cache); casimir_free(&casimir); printf("# Q,T,n,m,value,lmax,time\n"); printf("%.15g, %.15g, %d, %d, %.15g, %d, %g\n", Q, T, n, m, value, casimir.lmax, now()-start_time); } return 0; }
int main(int argc, char *argv[]) { double precision = DEFAULT_PRECISION; double lfac = DEFAULT_LFAC; double lT[4] = { 0,0,0,SCALE_LIN }; /* start, stop, N, lin/log */ double lLbyR[4] = { 0,0,0,SCALE_LIN }; /* start, stop, N, lin/log */ int i, iT, iLbyR; int cores = 1; int lmax = 0; int buffering_flag = 0, quiet_flag = 0, verbose_flag = 0, extrapolate_flag = 0; /* parse command line options */ while (1) { int c; struct option long_options[] = { { "verbose", no_argument, &verbose_flag, 1 }, { "quiet", no_argument, &quiet_flag, 1 }, { "buffering", no_argument, &buffering_flag, 1 }, { "extrapolate", no_argument, &extrapolate_flag, 1 }, { "help", no_argument, 0, 'h' }, { "LbyR", required_argument, 0, 'x' }, { "lscale", required_argument, 0, 'l' }, { "cores", required_argument, 0, 'c' }, { "precision", required_argument, 0, 'p' }, { 0, 0, 0, 0 } }; /* getopt_long stores the option index here. */ int option_index = 0; c = getopt_long (argc, argv, "x:T:c:s:a:l:L:p:Xvqh", long_options, &option_index); /* Detect the end of the options. */ if (c == -1) break; switch (c) { case 0: /* If this option set a flag, do nothing else now. */ if (long_options[option_index].flag != 0) break; case 'x': parse_range('x', optarg, lLbyR); break; case 'T': parse_range('T', optarg, lT); break; case 'L': lmax = atoi(optarg); break; case 'q': quiet_flag = 1; break; case 'c': cores = atoi(optarg); break; case 'v': verbose_flag = 1; break; case 'l': lfac = atof(optarg); break; case 'p': precision = atof(optarg); break; case 'h': usage(stdout); exit(0); case '?': /* getopt_long already printed an error message. */ break; default: abort(); } } // disable buffering if(!buffering_flag) { fflush(stdin); fflush(stderr); setvbuf(stdout, NULL, _IONBF, 0); setvbuf(stderr, NULL, _IONBF, 0); } /* check command line arguments */ { if(lfac <= 0) { fprintf(stderr, "--lfac must be positive\n\n"); usage(stderr); exit(1); } if(precision <= 0) { fprintf(stderr, "--precision must be positive\n\n"); usage(stderr); exit(1); } if(lLbyR[0] <= 0 || lLbyR[1] <= 0) { fprintf(stderr, "-x must be positive; LbyR > 0\n\n"); usage(stderr); exit(1); } if(lT[0] <= 0) { fprintf(stderr, "positive value for -T required\n\n"); usage(stderr); exit(1); } } /* print information to stdout */ { /* print command line */ printf("# %s", argv[0]); for(i = 1; i < argc; i++) printf(", %s", argv[i]); printf("\n"); printf("# precision=%g\n", precision); if(lmax > 0) printf("# lmax=%d\n", lmax); else printf("# lfac=%g\n", lfac); printf("# cores=%d\n", cores); if(lLbyR[2] == 1) printf("# LbyR=%g\n", lLbyR[0]); else printf("# LbyR=%g...%g (%d)\n", lLbyR[0],lLbyR[1],(int)lLbyR[2]); if(lT[2] == 1) printf("# T=%g\n", lT[0]); else printf("# T=%g...%g (%d)\n", lT[0],lT[1],(int)lT[2]); printf("# extrapolate=%s\n", extrapolate_flag ? "yes" : "no"); printf("#\n"); printf("# LbyR, T, F, lmax, nmax, time\n"); } i = 0; for(iLbyR = 0; iLbyR < lLbyR[2]; iLbyR++) for(iT = 0; iT < lT[2]; iT++) { casimir_t casimir; double start_time = now(); int nmax; double F,LbyR,T,Q; if(lLbyR[3] == SCALE_LIN) LbyR = linspace(lLbyR[0], lLbyR[1], lLbyR[2], iLbyR); else LbyR = logspace(lLbyR[0], lLbyR[1], lLbyR[2], iLbyR); if(lT[3] == SCALE_LIN) T = linspace(lT[0], lT[1], lT[2], iT); else T = logspace(lT[0], lT[1], lT[2], iT); Q = 1/(1+LbyR); casimir_init(&casimir, Q, T); casimir_set_cores(&casimir, cores); casimir_set_precision(&casimir, precision); casimir_set_verbose(&casimir, verbose_flag); casimir_set_extrapolate(&casimir, extrapolate_flag); if(lmax > 0) casimir_set_lmax(&casimir, lmax); else casimir_set_lmax(&casimir, MAX((int)ceil(lfac/LbyR), DEFAULT_LFAC)); F = casimir_F(&casimir, &nmax); casimir_free(&casimir); printf("%.15g, %.15g, %.15g, %d, %d, %g\n", LbyR, T, F, casimir.lmax, nmax, now()-start_time); if(!quiet_flag) fprintf(stderr, "# %6.2f%%, L/R=%g, T=%g\n", ++i*100/(lLbyR[2]*lT[2]), LbyR, T); } return 0; }