- Timestamp:
- Dec 9, 2015, 3:42:26 PM (11 years ago)
- Location:
- trunk/Ohana/src
- Files:
-
- 1 added
- 18 edited
-
addstar/src/mkcmf.c (modified) (13 diffs)
-
fakeastro/Makefile (modified) (1 diff)
-
fakeastro/src/make_2mass_measures.c (modified) (1 diff)
-
fakeastro/src/make_fake_stars_catalog.c (modified) (1 diff)
-
fakeastro/src/make_fakeqsos.c (modified) (1 diff)
-
fakeastro/src/make_fakestars.c (modified) (2 diffs)
-
libohana/Makefile (modified) (1 diff)
-
libohana/include/ohana.h (modified) (1 diff)
-
libohana/src/gaussdev.c (added)
-
misc/src/fakedist.c (modified) (5 diffs)
-
misc/src/fakepop.c (modified) (5 diffs)
-
misc/src/fakestars.c (modified) (3 diffs)
-
misc/src/fitdist.c (modified) (4 diffs)
-
misc/src/magtoage.c (modified) (4 diffs)
-
misc/src/magtomass.c (modified) (4 diffs)
-
misc/src/mkgauss.c (modified) (3 diffs)
-
opihi/cmd.data/gaussdeviate.c (modified) (3 diffs)
-
opihi/lib.data/Makefile (modified) (2 diffs)
-
opihi/mana/simsignal.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/addstar/src/mkcmf.c
r39121 r39242 13 13 # define FLAGS 0x1101 14 14 15 void gauss_init (int Nbin);16 double rnd_gauss (double mean, double sigma);17 15 void writeStars_PS1_V5_Lensing (FTable *ftable, double *X, double *Y, double *M, unsigned int *Flag, int Nstars); 18 16 void writeStars_PS1_V5 (FTable *ftable, double *X, double *Y, double *M, unsigned int *Flag, int Nstars); … … 282 280 } 283 281 284 gauss _init (2048);282 gaussdev_init (); 285 283 286 284 // load test stars from a file: … … 564 562 565 563 566 static int Ngaussint = 0;567 static double *gaussint;568 569 extern double drand48();570 571 double gaussian (double x, double mean, double sigma) {572 573 double f;574 575 f = exp (-0.5 * SQ(x - mean) / SQ(sigma)) / sqrt(2 * M_PI * SQ(sigma));576 577 return (f);578 579 }580 581 /* integrate a gaussian from -5 sigma to +5 sigma */582 void gauss_init (int Nbin) {583 584 int i;585 double val, x, dx, dx1, dx2, dx3, df;586 double mean, sigma;587 588 /* no need to generate this if it already exists */589 if (Ngaussint == Nbin) return;590 591 // A = time(NULL);592 // // XXX this is expensive if called a lot (1 sec min)593 // // for (B = 0; A == time(NULL); B++);594 // B = A + 10000;595 // srand48(B);596 597 Ngaussint = Nbin;598 ALLOCATE (gaussint, double, Ngaussint + 1);599 600 val = 0;601 dx = 1.0 / Ngaussint;602 dx1 = dx / 3.0;603 dx2 = 2.0*dx/3.0;604 dx3 = dx;605 mean = 0.0;606 sigma = 1.0;607 608 for (i = 0, x = -7.0; (i < Ngaussint) && (x < 7.0); x += dx) {609 df = (3.0*gaussian(x , mean, sigma) +610 9.0*gaussian(x+dx1, mean, sigma) +611 9.0*gaussian(x+dx2, mean, sigma) +612 3.0*gaussian(x+dx3, mean, sigma)) * (dx1/8.0);613 val += df;614 if (val > (i + 0.5) / (double) Ngaussint) {615 gaussint[i] = x + dx / 2.0;616 i++;617 }618 }619 }620 621 double rnd_gauss (double mean, double sigma) {622 623 int i;624 double y;625 626 y = drand48();627 i = Ngaussint*y;628 y = gaussint[i]*sigma + mean;629 630 return (y);631 632 }633 634 double int_gauss (int i) {635 double y;636 y = gaussint[i];637 return (y);638 }639 640 564 void writeStars_PS1_DEV_0 (FTable *ftable, double *X, double *Y, double *M, int Nstars) { 641 565 … … 654 578 655 579 if (ADDNOISE) { 656 X[i] += FX * fSN * rnd_gauss(0.0, 1.0);657 Y[i] += FY * fSN * rnd_gauss(0.0, 1.0);658 M[i] += fSN* rnd_gauss(0.0, 1.0);580 X[i] += FX * fSN * gaussdev_rnd(0.0, 1.0); 581 Y[i] += FY * fSN * gaussdev_rnd(0.0, 1.0); 582 M[i] += fSN*gaussdev_rnd(0.0, 1.0); 659 583 flux = pow (10.0, -0.4*M[i]); 660 584 fSN = 1.0 / sqrt(flux); … … 700 624 701 625 if (ADDNOISE) { 702 X[i] += FX * fSN * rnd_gauss(0.0, 1.0);703 Y[i] += FY * fSN * rnd_gauss(0.0, 1.0);704 M[i] += fSN* rnd_gauss(0.0, 1.0);626 X[i] += FX * fSN * gaussdev_rnd(0.0, 1.0); 627 Y[i] += FY * fSN * gaussdev_rnd(0.0, 1.0); 628 M[i] += fSN*gaussdev_rnd(0.0, 1.0); 705 629 flux = pow (10.0, -0.4*M[i]); 706 630 fSN = 1.0 / sqrt(flux); … … 749 673 750 674 if (ADDNOISE) { 751 X[i] += FX * fSN * rnd_gauss(0.0, 1.0);752 Y[i] += FY * fSN * rnd_gauss(0.0, 1.0);753 M[i] += fSN* rnd_gauss(0.0, 1.0);675 X[i] += FX * fSN * gaussdev_rnd(0.0, 1.0); 676 Y[i] += FY * fSN * gaussdev_rnd(0.0, 1.0); 677 M[i] += fSN*gaussdev_rnd(0.0, 1.0); 754 678 flux = pow (10.0, -0.4*M[i]); 755 679 fSN = 1.0 / sqrt(flux); … … 800 724 801 725 if (ADDNOISE) { 802 X[i] += FX * fSN * rnd_gauss(0.0, 1.0);803 Y[i] += FY * fSN * rnd_gauss(0.0, 1.0);804 M[i] += fSN* rnd_gauss(0.0, 1.0);726 X[i] += FX * fSN * gaussdev_rnd(0.0, 1.0); 727 Y[i] += FY * fSN * gaussdev_rnd(0.0, 1.0); 728 M[i] += fSN*gaussdev_rnd(0.0, 1.0); 805 729 flux = pow (10.0, -0.4*M[i]); 806 730 fSN = 1.0 / sqrt(flux); … … 857 781 858 782 if (ADDNOISE) { 859 X[i] += FX * fSN * rnd_gauss(0.0, 1.0);860 Y[i] += FY * fSN * rnd_gauss(0.0, 1.0);861 M[i] += fSN* rnd_gauss(0.0, 1.0);783 X[i] += FX * fSN * gaussdev_rnd(0.0, 1.0); 784 Y[i] += FY * fSN * gaussdev_rnd(0.0, 1.0); 785 M[i] += fSN*gaussdev_rnd(0.0, 1.0); 862 786 flux = pow (10.0, -0.4*M[i]); 863 787 fSN = 1.0 / sqrt(flux); … … 918 842 919 843 if (ADDNOISE) { 920 X[i] += FX * fSN * rnd_gauss(0.0, 1.0);921 Y[i] += FY * fSN * rnd_gauss(0.0, 1.0);922 M[i] += fSN* rnd_gauss(0.0, 1.0);844 X[i] += FX * fSN * gaussdev_rnd(0.0, 1.0); 845 Y[i] += FY * fSN * gaussdev_rnd(0.0, 1.0); 846 M[i] += fSN*gaussdev_rnd(0.0, 1.0); 923 847 flux = pow (10.0, -0.4*M[i]); 924 848 fSN = 1.0 / sqrt(flux); … … 987 911 988 912 if (ADDNOISE) { 989 X[i] += FX * fSN * rnd_gauss(0.0, 1.0);990 Y[i] += FY * fSN * rnd_gauss(0.0, 1.0);991 M[i] += fSN* rnd_gauss(0.0, 1.0);913 X[i] += FX * fSN * gaussdev_rnd(0.0, 1.0); 914 Y[i] += FY * fSN * gaussdev_rnd(0.0, 1.0); 915 M[i] += fSN*gaussdev_rnd(0.0, 1.0); 992 916 flux = pow (10.0, -0.4*M[i]); 993 917 fSN = 1.0 / sqrt(flux); … … 1094 1018 1095 1019 if (ADDNOISE) { 1096 X[i] += FX * fSN * rnd_gauss(0.0, 1.0);1097 Y[i] += FY * fSN * rnd_gauss(0.0, 1.0);1098 M[i] += fSN* rnd_gauss(0.0, 1.0);1020 X[i] += FX * fSN * gaussdev_rnd(0.0, 1.0); 1021 Y[i] += FY * fSN * gaussdev_rnd(0.0, 1.0); 1022 M[i] += fSN*gaussdev_rnd(0.0, 1.0); 1099 1023 flux = pow (10.0, -0.4*M[i]); 1100 1024 fSN = 1.0 / sqrt(flux); … … 1198 1122 1199 1123 if (ADDNOISE) { 1200 X[i] += FX * fSN * rnd_gauss(0.0, 1.0);1201 Y[i] += FY * fSN * rnd_gauss(0.0, 1.0);1202 M[i] += fSN * rnd_gauss(0.0, 1.0);1124 X[i] += FX * fSN * gaussdev_rnd(0.0, 1.0); 1125 Y[i] += FY * fSN * gaussdev_rnd(0.0, 1.0); 1126 M[i] += fSN * gaussdev_rnd(0.0, 1.0); 1203 1127 flux = pow(10.0, -0.4 * M[i]); 1204 1128 fSN = 1.0 / sqrt(flux); … … 1324 1248 1325 1249 if (ADDNOISE) { 1326 X[i] += FX * fSN * rnd_gauss(0.0, 1.0);1327 Y[i] += FY * fSN * rnd_gauss(0.0, 1.0);1328 M[i] += fSN* rnd_gauss(0.0, 1.0);1250 X[i] += FX * fSN * gaussdev_rnd(0.0, 1.0); 1251 Y[i] += FY * fSN * gaussdev_rnd(0.0, 1.0); 1252 M[i] += fSN*gaussdev_rnd(0.0, 1.0); 1329 1253 flux = pow (10.0, -0.4*M[i]); 1330 1254 fSN = 1.0 / sqrt(flux); -
trunk/Ohana/src/fakeastro/Makefile
r37846 r39242 38 38 $(SRC)/fakestar_io.$(ARCH).o \ 39 39 $(SRC)/insert_fakestar.$(ARCH).o \ 40 $(SRC)/gaussian.$(ARCH).o \41 40 $(SRC)/fakeastro_images.$(ARCH).o \ 42 41 $(SRC)/fakeastro_images_region.$(ARCH).o \ -
trunk/Ohana/src/fakeastro/src/make_2mass_measures.c
r38986 r39242 80 80 81 81 // uR,uD in linear arcsec 82 double dRsee = rnd_gauss(0.0, 1.0 / SN);83 double dDsee = rnd_gauss(0.0, 1.0 / SN);82 double dRsee = gaussdev_rnd (0.0, 1.0 / SN); 83 double dDsee = gaussdev_rnd (0.0, 1.0 / SN); 84 84 85 85 double dRoff = (dRpm + dRsee) / 3600.0; -
trunk/Ohana/src/fakeastro/src/make_fake_stars_catalog.c
r37807 r39242 113 113 114 114 // uR,uD in linear arcsec 115 double dRsee = rnd_gauss(0.0, 1.0 / SN);116 double dDsee = rnd_gauss(0.0, 1.0 / SN);115 double dRsee = gaussdev_rnd (0.0, 1.0 / SN); 116 double dDsee = gaussdev_rnd (0.0, 1.0 / SN); 117 117 118 118 double dRoff = (dRpm + dRsee) / 3600.0; -
trunk/Ohana/src/fakeastro/src/make_fakeqsos.c
r37807 r39242 51 51 52 52 // Mr will be interpretted as m_r 53 double Mr = rnd_gauss(18.0, 1.5);53 double Mr = gaussdev_rnd (18.0, 1.5); 54 54 55 55 stars[i].R = R; -
trunk/Ohana/src/fakeastro/src/make_fakestars.c
r37807 r39242 48 48 int inPatch = FALSE; 49 49 while (!inPatch) { 50 z = rnd_gauss(0.0, FAKEASTRO_ZGAL);50 z = gaussdev_rnd (0.0, FAKEASTRO_ZGAL); 51 51 r = sqrt(drand48()) * FAKEASTRO_RGAL; 52 52 Lrad = drand48() * 2 * M_PI; … … 98 98 double Mr; 99 99 if (bigPeak) { 100 Mr = rnd_gauss(11.25, 1.0);100 Mr = gaussdev_rnd (11.25, 1.0); 101 101 } else { 102 Mr = rnd_gauss(10.00, 2.5);102 Mr = gaussdev_rnd (10.00, 2.5); 103 103 } 104 104 -
trunk/Ohana/src/libohana/Makefile
r39058 r39242 35 35 $(SRC)/sorts.$(ARCH).o \ 36 36 $(SRC)/bisection.$(ARCH).o \ 37 $(SRC)/gaussdev.$(ARCH).o \ 37 38 $(SRC)/string.$(ARCH).o \ 38 39 $(SRC)/findexec.$(ARCH).o \ -
trunk/Ohana/src/libohana/include/ohana.h
r39040 r39242 486 486 int sprintf_double (char *output, double value); 487 487 488 # endif 488 /* in gaussdev.c */ 489 double gaussian (double x, double mean, double sigma); 490 void gaussdev_init (void); 491 void gaussdev_free (void); 492 double gaussdev_rnd (double mean, double sigma); 493 494 # endif -
trunk/Ohana/src/misc/src/fakedist.c
r15487 r39242 1 1 # include <ohana.h> 2 3 # define NGAUSS 20484 double drand48();5 double gaussint[NGAUSS];6 double gaussian();7 double rnd_gauss();8 2 9 3 # define MMIN 1.0 … … 45 39 init_outmatrix (); 46 40 47 gauss _init ();41 gaussdev_init (); 48 42 49 43 read_datafiles (); … … 349 343 if (noise < dMo) { 350 344 *Noise = noise; 351 *mag = rnd_gauss(v, noise);352 *color = rnd_gauss(uv, 1.4*noise);345 *mag = gaussdev_rnd (v, noise); 346 *color = gaussdev_rnd (uv, 1.4*noise); 353 347 return; 354 348 } … … 414 408 415 409 /*****************************************************************************/ 416 417 double418 rnd_gauss (mean, sigma)419 double mean, sigma;420 {421 422 int i;423 double y;424 425 y = drand48();426 i = NGAUSS*y;427 y = gaussint[i]*sigma + mean;428 429 return (y);430 431 }432 433 gauss_init ()434 {435 436 int i;437 long A, B;438 double val, x, dx, dx1, dx2, dx3, df;439 double mean, sigma;440 441 A = time(NULL);442 for (B = 0; A == time(NULL); B++);443 srand48(B);444 445 val = 0;446 dx = 0.001;447 dx1 = dx / 3.0;448 dx2 = 2.0*dx/3.0;449 dx3 = dx;450 mean = 0.0;451 sigma = 1.0;452 453 for (i = 0, x = -7.0; (i < NGAUSS) && (x < 7.0); x += dx) {454 df = (3.0*gaussian(x , mean, sigma) +455 9.0*gaussian(x+dx1, mean, sigma) +456 9.0*gaussian(x+dx2, mean, sigma) +457 3.0*gaussian(x+dx3, mean, sigma)) * (dx1/8.0);458 val += df;459 if (val > (i / (double) NGAUSS)) {460 gaussint[i] = x + dx / 2.0;461 i++;462 }463 }464 return (x + dx / 2.0);465 }466 467 double468 gaussian (x, mean, sigma)469 double x, mean, sigma;470 {471 472 double f, X;473 474 f = exp (-0.5 * SQ(x - mean) / SQ(sigma)) / sqrt(2 * M_PI * SQ(sigma));475 476 return (f);477 478 }479 410 480 411 /*****************************************************************************/ … … 505 436 Ngood = 1.0; 506 437 for (k = 0; k < NTRY; k++) { 507 v = rnd_gauss(mag, noise);508 uv = rnd_gauss(color, 1.4*noise);438 v = gaussdev_rnd (mag, noise); 439 uv = gaussdev_rnd (color, 1.4*noise); 509 440 x = (uv - UV0 - 0.7*A_V) / DUV; 510 441 y = (v - V0 - Dist - A_V) / DV; -
trunk/Ohana/src/misc/src/fakepop.c
r7080 r39242 2 2 # define MMIN 1.0 3 3 # define MMAX 120.0 4 extern double drand48();5 4 extern double rnd_mass(); 6 5 double rnd_mass(); 7 6 double term; 8 extern double rnd_gauss();9 extern double rnd_integrate ();10 extern double gaussian ();11 12 double gaussian();13 double rnd_gauss();14 double rnd_integrate();15 16 # define NGAUSS 204817 double gaussint[NGAUSS];18 7 19 8 double AgeS, AgeE, alpha, d, Av, dMo, dVo, dVref; … … 47 36 gfits_scan (&UV_h, "DEC_Y", "%lf", 1, &ldM); 48 37 49 gauss _init ();38 gaussdev_init (); 50 39 51 40 fprintf (stderr, "beginning main loop\n"); … … 68 57 v = gfits_get_matrix_value (&V_i, X, Y) + d + Av; 69 58 noise = dVo*sqrt(1.0 + pow (10.0, (0.4*(v - dVref)))); 70 V = rnd_gauss(v, noise);71 UV = rnd_gauss(uv, 1.4*noise);59 V = gaussdev_rnd (v, noise); 60 UV = gaussdev_rnd (uv, 1.4*noise); 72 61 if (noise < dMo) { 73 62 fprintf (stdout, "%f %f %f %f %f %f\n", V, noise, V+UV, noise, mass, age); … … 96 85 } 97 86 98 99 double100 rnd_gauss (mean, sigma)101 double mean, sigma;102 {103 104 int i;105 double y;106 107 y = drand48();108 i = NGAUSS*y;109 y = gaussint[i]*sigma + mean;110 111 return (y);112 113 }114 115 116 gauss_init ()117 {118 119 int i;120 long A, B;121 double val, x, dx, dx1, dx2, dx3, df;122 double mean, sigma;123 124 A = time(NULL);125 for (B = 0; A == time(NULL); B++);126 srand48(B);127 128 val = 0;129 dx = 0.001;130 dx1 = dx / 3.0;131 dx2 = 2.0*dx/3.0;132 dx3 = dx;133 mean = 0.0;134 sigma = 1.0;135 136 for (i = 0, x = -7.0; (i < NGAUSS) && (x < 7.0); x += dx) {137 df = (3.0*gaussian(x , mean, sigma) +138 9.0*gaussian(x+dx1, mean, sigma) +139 9.0*gaussian(x+dx2, mean, sigma) +140 3.0*gaussian(x+dx3, mean, sigma)) * (dx1/8.0);141 val += df;142 if (val > (i / (double) NGAUSS)) {143 gaussint[i] = x + dx / 2.0;144 i++;145 }146 }147 return (x + dx / 2.0);148 }149 87 150 88 double … … 172 110 return (x + dx / 2.0); 173 111 } 174 175 double176 gaussian (x, mean, sigma)177 double x, mean, sigma;178 {179 180 double f, X;181 182 f = exp (-0.5 * SQ(x - mean) / SQ(sigma)) / sqrt(2 * M_PI * SQ(sigma));183 184 return (f);185 186 }187 188 112 189 113 /*****************************************************************************/ -
trunk/Ohana/src/misc/src/fakestars.c
r27435 r39242 17 17 int found; 18 18 } Stars; 19 20 void gauss_init ();21 double gaussian (double x, double mean, double sigma);22 double rnd_gauss (double mean, double sigma);23 19 24 20 /* … … 45 41 offset = atof (argv[4]); 46 42 47 gauss _init ();43 gaussdev_init (); 48 44 49 45 /* load header, open file */ … … 98 94 dMr = 0.001 * stars[i].dM; 99 95 dMo = hypot (dMs, dMr); 100 dM = rnd_gauss(0.0, dMo);96 dM = gaussdev_rnd (0.0, dMo); 101 97 stars[i].M += dM + offset; 102 98 } -
trunk/Ohana/src/misc/src/fitdist.c
r8301 r39242 1 1 # include <ohana.h> 2 3 # define NGAUSS 20484 double drand48();5 double gaussint[NGAUSS];6 double gaussian();7 double rnd_gauss();8 2 9 3 # define MMIN 1.0 … … 45 39 fprintf (stderr, "read in parameters\n"); 46 40 47 gauss _init ();41 gaussdev_init (); 48 42 49 43 read_datafiles (); … … 360 354 /*****************************************************************************/ 361 355 362 double363 rnd_gauss (mean, sigma)364 double mean, sigma;365 {366 367 int i;368 double y;369 370 y = drand48();371 i = NGAUSS*y;372 y = gaussint[i]*sigma + mean;373 374 return (y);375 376 }377 378 gauss_init ()379 {380 381 int i;382 long A, B;383 double val, x, dx, dx1, dx2, dx3, df;384 double mean, sigma;385 386 A = time(NULL);387 for (B = 0; A == time(NULL); B++);388 srand48(B);389 390 val = 0;391 dx = 0.001;392 dx1 = dx / 3.0;393 dx2 = 2.0*dx/3.0;394 dx3 = dx;395 mean = 0.0;396 sigma = 1.0;397 398 for (i = 0, x = -7.0; (i < NGAUSS) && (x < 7.0); x += dx) {399 df = (3.0*gaussian(x , mean, sigma) +400 9.0*gaussian(x+dx1, mean, sigma) +401 9.0*gaussian(x+dx2, mean, sigma) +402 3.0*gaussian(x+dx3, mean, sigma)) * (dx1/8.0);403 val += df;404 if (val > (i / (double) NGAUSS)) {405 gaussint[i] = x + dx / 2.0;406 i++;407 }408 }409 return (x + dx / 2.0);410 }411 412 double413 gaussian (x, mean, sigma)414 double x, mean, sigma;415 {416 417 double f, X;418 419 f = exp (-0.5 * SQ(x - mean) / SQ(sigma)) / sqrt(2 * M_PI * SQ(sigma));420 421 return (f);422 423 }424 425 356 /*****************************************************************************/ 426 357 … … 453 384 Ngood = 1.0; 454 385 for (k = 0; k < NTRY; k++) { 455 v = rnd_gauss(Mag, Noise);456 uv = rnd_gauss(Color, 1.4*Noise);386 v = gaussdev_rnd (Mag, Noise); 387 uv = gaussdev_rnd (Color, 1.4*Noise); 457 388 x = (uv - UV0 - 0.7*A_V) / DUV; 458 389 y = (v - V0 - Dist - A_V) / DV; -
trunk/Ohana/src/misc/src/magtoage.c
r7080 r39242 2 2 # define MMIN 1.0 3 3 # define MMAX 120.0 4 extern double drand48();5 extern double rnd_gauss();6 extern double rnd_integrate ();7 extern double gaussian ();8 9 double gaussian();10 double rnd_gauss();11 double rnd_integrate();12 4 13 5 void main (argc, argv) … … 29 21 long A, B; 30 22 23 gaussdev_init(); 24 31 25 lAo = 0.0; 32 26 ldA = 1.0; … … 118 112 } 119 113 else { 120 v = rnd_gauss(V, dV);121 uv = rnd_gauss((U-V), dUV);114 v = gaussdev_rnd (V, dV); 115 uv = gaussdev_rnd ((U-V), dUV); 122 116 } 123 117 x = (uv - UV0 - 0.7*Av) / DUV; … … 167 161 } 168 162 169 double170 rnd_gauss (mean, sigma)171 double mean, sigma;172 {173 174 double range, x;175 176 range = drand48();177 x = rnd_integrate (*gaussian, range, mean, sigma);178 179 return (x);180 181 }182 183 184 double185 rnd_integrate (function, range, mean, sigma)186 double (*function) ();187 double range, mean, sigma;188 {189 190 double val, x, dx, dx1, dx2, dx3, df;191 192 range += 0.0001;193 val = 0;194 dx = sigma / 10.0;195 dx1 = dx / 3.0;196 dx2 = 2.0*dx/3.0;197 dx3 = dx;198 199 for (x = mean - 7*sigma; (val < range) && (x < mean + 7*sigma); x += dx) {200 df = (3.0*function(x , mean, sigma) +201 9.0*function(x+dx1, mean, sigma) +202 9.0*function(x+dx2, mean, sigma) +203 3.0*function(x+dx3, mean, sigma)) * (dx1/8.0);204 val += df;205 }206 return (x + dx / 2.0);207 }208 209 double210 gaussian (x, mean, sigma)211 double x, mean, sigma;212 {213 214 double f, X;215 216 f = exp (-0.5 * SQ(x - mean) / SQ(sigma)) / sqrt(2 * M_PI * SQ(sigma));217 218 return (f);219 220 }221 -
trunk/Ohana/src/misc/src/magtomass.c
r7080 r39242 1 1 # include <ohana.h> 2 extern double drand48();3 extern double rnd_gauss();4 extern double rnd_integrate ();5 extern double gaussian ();6 2 # define NEWWAY 1 7 8 double gaussian();9 double rnd_gauss();10 double rnd_integrate();11 12 # define NGAUSS 204813 double gaussint[NGAUSS];14 3 15 4 void main (argc, argv) … … 52 41 fprintf (stderr, "using mags in columns %d & %d\n", col1, col2); 53 42 54 gauss _init ();43 gaussdev_init (); 55 44 56 45 lAo = 0.1; … … 147 136 Ngood = 1.0; 148 137 for (k = 0; k < Ntry; k++) { 149 v = rnd_gauss(V, dV);150 uv = rnd_gauss((U-V), dUV);138 v = gaussdev_rnd (V, dV); 139 uv = gaussdev_rnd ((U-V), dUV); 151 140 x = (uv - UV0 - 0.7*Av) / DUV; 152 141 y = (v - d - V0 - Av) / DV; … … 202 191 */ 203 192 204 double205 rnd_gauss (mean, sigma)206 double mean, sigma;207 {208 209 int i;210 double y;211 212 y = drand48();213 i = NGAUSS*y;214 y = gaussint[i]*sigma + mean;215 216 return (y);217 218 }219 220 221 gauss_init ()222 {223 224 int i;225 long A, B;226 double val, x, dx, dx1, dx2, dx3, df;227 double mean, sigma;228 229 A = time(NULL);230 for (B = 0; A == time(NULL); B++);231 srand48(B);232 233 val = 0;234 dx = 0.001;235 dx1 = dx / 3.0;236 dx2 = 2.0*dx/3.0;237 dx3 = dx;238 mean = 0.0;239 sigma = 1.0;240 241 for (i = 0, x = -7.0; (i < NGAUSS) && (x < 7.0); x += dx) {242 df = (3.0*gaussian(x , mean, sigma) +243 9.0*gaussian(x+dx1, mean, sigma) +244 9.0*gaussian(x+dx2, mean, sigma) +245 3.0*gaussian(x+dx3, mean, sigma)) * (dx1/8.0);246 val += df;247 if (val > (i / (double) NGAUSS)) {248 gaussint[i] = x + dx / 2.0;249 i++;250 }251 }252 return (x + dx / 2.0);253 }254 255 double256 rnd_integrate (function, range, mean, sigma)257 double (*function) ();258 double range, mean, sigma;259 {260 261 double val, x, dx, dx1, dx2, dx3, df;262 263 range += 0.0001;264 val = 0;265 dx = sigma / 100.0;266 dx1 = dx / 3.0;267 dx2 = 2.0*dx/3.0;268 dx3 = dx;269 270 for (x = mean - 7*sigma; (val < range) && (x < mean + 7*sigma); x += dx) {271 df = (3.0*function(x , mean, sigma) +272 9.0*function(x+dx1, mean, sigma) +273 9.0*function(x+dx2, mean, sigma) +274 3.0*function(x+dx3, mean, sigma)) * (dx1/8.0);275 val += df;276 }277 return (x + dx / 2.0);278 }279 280 double281 gaussian (x, mean, sigma)282 double x, mean, sigma;283 {284 285 double f, X;286 287 f = exp (-0.5 * SQ(x - mean) / SQ(sigma)) / sqrt(2 * M_PI * SQ(sigma));288 289 return (f);290 291 }292 -
trunk/Ohana/src/misc/src/mkgauss.c
r34088 r39242 1 1 # include <ohana.h> 2 3 void gauss_init ();4 double gaussian (double x, double mean, double sigma);5 double rnd_gauss (double mean, double sigma);6 7 /* NGAUSS defines the resolution of the distribution */8 # define NGAUSS 20489 static double gaussint[NGAUSS];10 2 11 3 int main (int argc, char **argv) { … … 23 15 Npts = atoi (argv[3]); 24 16 25 gauss _init ();17 gaussdev_init (); 26 18 27 19 for (i = 0; i < Npts; i++) { 28 f = rnd_gauss(mean, sigma);20 f = gaussdev_rnd (mean, sigma); 29 21 fprintf (stdout, "%f\n", f); 30 22 } … … 33 25 } 34 26 35 void gauss_init () {36 37 int i;38 long A, B;39 double val, x, dx, dx1, dx2, dx3, df;40 41 A = time(NULL);42 for (B = 0; A == time(NULL); B++);43 srand48(B);44 45 val = 0;46 dx = 0.001;47 dx1 = dx / 3.0;48 dx2 = 2.0*dx/3.0;49 dx3 = dx;50 51 for (i = 0, x = -7.0; (i < NGAUSS) && (x < 7.0); x += dx) {52 df = (3.0*gaussian(x , 0.0, 1.0) +53 9.0*gaussian(x+dx1, 0.0, 1.0) +54 9.0*gaussian(x+dx2, 0.0, 1.0) +55 3.0*gaussian(x+dx3, 0.0, 1.0)) * (dx1/8.0);56 val += df;57 if (val > (i / (double) NGAUSS)) {58 gaussint[i] = x + dx / 2.0;59 i++;60 }61 }62 return;63 }64 65 double gaussian (double x, double mean, double sigma) {66 double f;67 68 f = exp (-0.5 * SQ(x - mean) / SQ(sigma)) / sqrt(2 * M_PI * SQ(sigma));69 return (f);70 }71 72 double rnd_gauss (double mean, double sigma) {73 74 int i;75 double y;76 77 i = 0;78 while ((i == 0) || (i == NGAUSS - 1)) {79 y = drand48();80 i = MIN (NGAUSS - 1, MAX (0, NGAUSS*y));81 }82 y = gaussint[i]*sigma + mean;83 84 return (y);85 } -
trunk/Ohana/src/opihi/cmd.data/gaussdeviate.c
r34088 r39242 17 17 ResetVector (vec, OPIHI_FLT, Npts); 18 18 19 gauss _init (2048);19 gaussdev_init (); 20 20 for (i = 0; i < Npts; i++) { 21 vec[0].elements.Flt[i] = rnd_gauss(mean, sigma);21 vec[0].elements.Flt[i] = gaussdev_rnd (mean, sigma); 22 22 } 23 23 return (TRUE); … … 28 28 29 29 } 30 31 double int_gauss (int i);32 30 33 31 int gaussintegral (int argc, char **argv) { … … 46 44 ResetVector (vec, OPIHI_FLT, Npts); 47 45 48 gauss _init (Npts);46 gaussdev_init (); 49 47 for (i = 0; i < Npts; i++) { 50 vec[0].elements.Flt[i] = int_gauss(i);48 vec[0].elements.Flt[i] = gaussian_int (i); 51 49 } 52 50 return (TRUE); -
trunk/Ohana/src/opihi/lib.data/Makefile
r36679 r39242 30 30 $(SDIR)/starfuncs.$(ARCH).o \ 31 31 $(SDIR)/hermitian.$(ARCH).o \ 32 $(SDIR)/gaussian.$(ARCH).o \33 32 $(SDIR)/graphtools.$(ARCH).o \ 34 33 $(SDIR)/queues.$(ARCH).o \ … … 36 35 $(SDIR)/open_kapa.$(ARCH).o \ 37 36 $(SDIR)/style_args.$(ARCH).o 37 38 # moved to libohana 39 # $(SDIR)/gaussian.$(ARCH).o \ 38 40 39 41 # fix malloc -
trunk/Ohana/src/opihi/mana/simsignal.c
r7917 r39242 6 6 float *buf; 7 7 double cvalue, dvalue, sigma, SN, period; 8 double rnd_gauss ();9 8 10 9 if (argc != 5) { … … 28 27 ivalue = scale * 0.5 * (sin (i*2*M_PI/period) + 1) + 0.5; 29 28 /* 30 dvalue = rnd_gauss(cvalue, sigma);29 dvalue = gaussdev_rnd (cvalue, sigma); 31 30 cvalue = (dvalue + range) / (2.0*range); 32 31 dvalue = MAX (0, MIN (0.99999, cvalue)); … … 44 43 8 bit = 2^8 45 44 46 gauss _init (2*scale);45 gaussdev_init (); 47 46 sigma = 2.0 / SN; 48 47 range = 1 + 5*sigma;
Note:
See TracChangeset
for help on using the changeset viewer.
