/* FUNCTION: Calculate a grid of Voigt profiles. */ int calcprofiles(struct transit *tr){ struct transithint *th = tr->ds.th; /* transithint struct */ struct opacity *op=tr->ds.op; /* Opacity struct */ int i, j; /* for-loop indices */ int nDop, nLor; /* Number of Doppler and Lorentz-widths */ double Lmin, Lmax, Dmin, Dmax; /* Minimum and maximum widths */ PREC_VOIGT ***profile; /* Grid of Voigt profiles */ float timesalpha=tr->timesalpha; /* Voigt wings width */ struct timeval tv; /* Time-keeping variables */ double t0=0.0; /* Make logscale grid for the profile widths: */ /* FINDME: Add check that these numbers make sense */ nDop = op->nDop = th->nDop; nLor = op->nLor = th->nLor; Dmin = th->dmin; Dmax = th->dmax; Lmin = th->lmin; Lmax = th->lmax; op->aDop = logspace(Dmin, Dmax, nDop); op->aLor = logspace(Lmin, Lmax, nLor); /* Allocate array for the profile half-size: */ op->profsize = (PREC_NREC **)calloc(nDop, sizeof(PREC_NREC *)); op->profsize[0] = (PREC_NREC *)calloc(nDop*nLor, sizeof(PREC_NREC)); for (i=1; i<nDop; i++) op->profsize[i] = op->profsize[0] + i*nLor; /* Allocate grid of Voigt profiles: */ op->profile = (PREC_VOIGT ***)calloc(nDop, sizeof(PREC_VOIGT **)); op->profile[0] = (PREC_VOIGT **)calloc(nDop*nLor, sizeof(PREC_VOIGT *)); for (i=1; i<nDop; i++){ op->profile[i] = op->profile[0] + i*nLor; } profile = op->profile; tr_output(TOUT_RESULT, "Number of Voigt profiles: %d.\n", nDop*nLor); t0 = timestart(tv, "Begin Voigt profiles calculation."); /* Evaluate the profiles for the array of widths: */ for (i=0; i<nDop; i++){ for (j=0; j<nLor; j++){ /* Skip calculation if Doppler width << Lorentz width: */ /* Set size and pointer to previous profile: */ if (op->aDop[i]*10.0 < op->aLor[j] && i != 0){ op->profsize[i][j] = op->profsize[i-1][j]; profile[i][j] = profile[i-1][j]; } else{ /* Calculate a new profile for given widths: */ op->profsize[i][j] = getprofile(&profile[i][j], tr->wns.d/tr->owns.o, op->aDop[i], op->aLor[j], timesalpha, tr->owns.n); } tr_output(TOUT_DEBUG, "Profile[%2d][%2d] size = %4li (D=%.3g, " "L=%.3g).\n", i, j, 2*op->profsize[i][j]+1, op->aDop[i], op->aLor[j]); } } t0 = timecheck(verblevel, 0, 0, "End Voigt-profile calculation.", tv, t0); return 0; }
char * logfslog(LogfsServer *server, int active, LogMessage *s) { uint size = logfssizeS2M(s); char *errmsg; uchar *p; int takearisk; if(server->trace > 1) { print("%c<< ", active ? 'A' : 'S'); logfsdumpS(s); print("\n"); } if(active) { switch(s->type) { case LogfsLogTremove: case LogfsLogTtrunc: takearisk = 1; break; default: takearisk = 0; } } else takearisk = 0; errmsg = logspace(server, active, takearisk, size, &p, nil); if(errmsg) return errmsg; if(logfsconvS2M(s, p, size) != size) return "bad conversion"; logdirty(server, active); return nil; }
char * logfslogbytes(LogfsServer *server, int active, uchar *msg, uint size) { char *errmsg; uchar *p; errmsg = logspace(server, active, 0, size, &p, nil); if(errmsg) return errmsg; memmove(p, msg, size); logdirty(server, active); return nil; }
void MorletWaveletTransform::init(size_t width, double low_freq, double high_freq, size_t nf, double sample_freq, size_t signal_len) { signal_len_ = signal_len; n_freqs = nf; std::vector<double> freqs = logspace(log10(low_freq), log10(high_freq), nf); morlet_wave_ffts = new MorletWaveFFT[nf]; n_plans = 0; size_t last_len = 0; for(size_t i=0; i<nf; ++i) { size_t len = morlet_wave_ffts[i].init(width, freqs[i], signal_len, sample_freq); if (len != last_len) { last_len = len; ++n_plans; } } // initialize buffers size_t fft_len_max = morlet_wave_ffts[nf-1].len; if (fft_len_max < morlet_wave_ffts[0].len) fft_len_max = morlet_wave_ffts[0].len; prod_buf = (fftw_complex*)fftw_malloc(fft_len_max*sizeof(fftw_complex)); result_buf = (fftw_complex*)fftw_malloc(fft_len_max*sizeof(fftw_complex)); signal_buf = (double*)fftw_malloc(fft_len_max*sizeof(double)); memset(signal_buf, 0, fft_len_max*sizeof(double)); fft_buf = (fftw_complex*)fftw_malloc((fft_len_max/2+1)*sizeof(fftw_complex)); plan_for_signal = new fftw_plan[n_plans]; plan_for_inverse_transform = new fftw_plan[n_plans]; last_len = 0; size_t plan = 0; for (MorletWaveFFT* wavelet=morlet_wave_ffts; wavelet<morlet_wave_ffts+n_freqs; ++wavelet) { size_t len = wavelet->len; if (len != last_len) { last_len = len; plan_for_signal[plan] = fftw_plan_dft_r2c_1d(len, signal_buf, fft_buf, FFTW_PATIENT); plan_for_inverse_transform[plan] = fftw_plan_dft_1d(len, prod_buf, result_buf, FFTW_BACKWARD, FFTW_PATIENT); ++plan; } } }
char * logfslogwrite(LogfsServer *server, int active, u32int path, u32int offset, int count, u32int mtime, u32int cvers, char *muid, uchar *data, u32int *flashaddr) { /* 'w' size[2] path[4] offset[4] count[2] mtime[4] cvers[4] muid[s] flashaddr[4] [data[n]] */ LogMessage s; uint size; char *errmsg; uchar *p; u32int faddr; uint asize; s.type = LogfsLogTwrite; s.path = path; s.u.write.offset = offset; s.u.write.count = count; s.u.write.mtime = mtime; s.u.write.cvers = cvers; s.u.write.muid = muid; s.u.write.data = data; size = logfssizeS2M(&s); errmsg = logspace(server, active, 0, size, &p, &faddr); if(errmsg) return errmsg; if(data) *flashaddr = (faddr + size - count) | LogAddr; s.u.write.flashaddr = *flashaddr; if(server->trace > 1) { print("%c<< ", active ? 'A' : 'S'); logfsdumpS(&s); print("\n"); } if((asize = logfsconvS2M(&s, p, size)) != size) { print("expected %d actual %d\n", size, asize); return "bad conversion"; } logdirty(server, active); return nil; }
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; }
T Linalg< T, H >::logspace( const value_type &a, const value_type &b, size_type n, allocator_type alloc) { T r(alloc); return *logspace(a, b, n, &r); }
Vector<T> logspace(T xmin, int xmax, int n) { return logspace(T(xmin), T(xmax), n ); }
/* This function creates a logarithmic stepped vector of values starting at the given start value, ending with the given stop value and containing points elements. */ void logsweep::create (nr_double_t start, nr_double_t stop, int points) { vector v = logspace (start, stop, points); setSize (points); for (int i = 0; i < points; i++) set (i, real (v.get (i))); }