Changeset 39242 for trunk/Ohana/src/addstar
- Timestamp:
- Dec 9, 2015, 3:42:26 PM (11 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/addstar/src/mkcmf.c (modified) (13 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);
Note:
See TracChangeset
for help on using the changeset viewer.
