-
Notifications
You must be signed in to change notification settings - Fork 0
/
fit_sed_skynet.cpp
3075 lines (3018 loc) · 126 KB
/
fit_sed_skynet.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Comments prefixed with F77 are original Fortran code.
// {F77} c ===========================================================================
// {F77} PROGRAM FIT_SED
// {F77} c ---------------------------------------------------------------------------
// {F77} c Authors : E. da Cunha & S. Charlot
// {F77} c Latest revision : Sep. 16th, 2010
// {F77} c ---------------------------------------------------------------------------
// {F77} c Model & Method descibed in detail in:
// {F77} c da Cunha, Charlot & Elbaz, 2008, MNRAS 388, 1595
// {F77} c ---------------------------------------------------------------------------
// {F77} c Compares model fluxes with observed fluxes from the ultraviolet to the
// {F77} c far-infrared by computing the chi^2 goodness-of-fit of each model.
// {F77} c The probability of each model is exp(-1/2 chi^2)
// {F77} c The code also builds the likelihood distribution of each parameter
// {F77} c
// {F77} c INPUTS:
// {F77} c - filter file - define USER_FILTERS in .galsbit_tcshrc
// {F77} c - file with redshifts & observed fluxes of the
// {F77} c galaxies - define USER_OBS in .magphys_tcshrc
// {F77} c - file with redshifts at which libraries
// {F77} c were computed "zlibs.dat"
// {F77} c - .lbr files generated with get_optic_colors.f
// {F77} c & get_infrared_colors.f
// {F77} c - number of the galaxy to fit: i_gal
// {F77} c
// {F77} c OUTPUTS: - "name".fit file containing:
// {F77} c -- observed fluxes
// {F77} c -- mininum chi2
// {F77} c -- best-fit model parameters & fluxes
// {F77} c -- likelihood distribution of each parameter
// {F77} c -- 2.5th, 16th, 50th, 84th, 97.5th percentile
// {F77} c of each parameter
// {F77} c - "name".sed file containing the best-fit SED
// {F77} c ===========================================================================
// {F77}
// {F77}
// {F77} c ===========================================================================
// {F77} c Author : Kevin Vinsen
// {F77} c Date : 29th May 2012
// {F77} c ---------------------------------------------------------------------------
// {F77} c Added minor changes to allow the code to run from the command line and not
// {F77} c to perform the normalisation against the models. Instead it writes the
// {F77} c parameters required to normalise it later.
// {F77} c The skyNet project is a citizen science project and we cannot expect the
// {F77} c general public to download the 3 large .bin files
// {F77} c ===========================================================================
// {F77}
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string.h>
#define NMAX 50
#define GALMAX 5000
#define NMOD 50001
#define NPROP_SFH 24
#define NPROP_IR 8
#define NZMAX 5000
#define NBINMAX1 3000
#define NBINMAX2 300
#define MIN_HPBV 0.00001
//Function prototypes for old FORTRAN functions.
double get_cosmol_c(double h,double omega,double omega_lambda,double* q);
double get_funl(double x);
void get_midpnt(double (*func)(double),double a,double b,double* s,double n);
double get_dl(double h,double q,double z);
void sort2(double arr1[],double arr2[], int left, int right);
void get_histgrid(double dv,double vmin,double vmax,int* nbin,double vout[]);
void get_percentiles(int n,double par[],double probability[],double percentile[]);
void degrade_hist(double delta,double min,double max,int nbin1,int * nbin2,double hist1[], double hist2[],double prob1[],double prob2[]);
double get_hpbv(double hist1[],double hist2[],int nbin);
// TODO : Bad! Get rid of this eventually.
static double omega0;
using namespace std;
int main(int argc, char *argv[]){
// Mimic output to that of fortran write.
cout.precision(15);
// cout.setf(ios::scientific);
// {F77} implicit none
// {F77} integer isave,i,j,k,i_gal,io,largo
int isave,i,j,k,i_gal,io,largo;
// {F77} integer nmax,galmax,nmod
// {F77} parameter(nmax=50,galmax=5000) !nmax: maxium number of photometric points/filters
// {F77} integer n_obs,n_models,ibin !galmax: maximum number of galaxies in one input file
static int n_obs,n_models,ibin;
// {F77} integer kfilt_sfh(nmax),kfilt_ir(nmax),nfilt_sfh,nfilt_ir,nfilt_mix
static int kfilt_sfh[NMAX],kfilt_ir[NMAX],nfilt_sfh,nfilt_ir,nfilt_mix;
// {F77} integer nprop_sfh,nprop_ir
// {F77} integer n_sfh,n_ir,i_ir,i_sfh,ir_sav,sfh_sav
static int n_sfh,n_ir,i_ir,i_sfh,ir_sav,sfh_sav;
// {F77} integer nfilt,filt_id(nmax),fit(nmax),ifilt
static int nfilt,filt_id[NMAX],fit[NMAX],ifilt;
// {F77} parameter(nmod=50001,nprop_sfh=24,nprop_ir=8)
// {F77} character*12 filt_name(nmax)
static char filt_name[NMAX][12];
// {F77} character*100 outfile1,outfile2
static char outfile1[100],outfile2[100];
// {F77} character*500 filter_header
static char filter_header[500];
// {F77} character*30 gal_name(galmax),aux_name
static char gal_name[GALMAX][30],aux_name[30];
// {F77} character*6 numz
static char numz[7];
// {F77} character optlib*34,irlib*26
static char optlib[35],irlib[27];
// {F77} character filters*80,obs*80
static char filters[81],obs[81];
// {F77} c redshift libs
// {F77} integer nz,nzmax
static int nz;
// {F77} parameter(nzmax=5000)
// {F77} real*8 zlib(nzmax),diffz(nzmax)
static double zlib[NZMAX],diffz[NZMAX];
// {F77} c observations, filters, etc.
// {F77} real*8 w(galmax,nmax),redshift(galmax),dist(galmax)
static double w[NMAX][GALMAX],redshift[GALMAX],dist[GALMAX];
// {F77} real*8 flux_obs(galmax,nmax),sigma(galmax,nmax),aux
static double flux_obs[NMAX][GALMAX],sigma[NMAX][GALMAX],aux;
// {F77} real*8 flux_sfh(nmod,nmax),ssfr(nmod)
static double flux_sfh[NMAX][NMOD],ssfr[NMOD];
// {F77} real*8 lambda_eff(nmax),lambda_rest(nmax)
static double lambda_eff[NMAX],lambda_rest[NMAX];
// {F77} c model libraries, parameters, etc.
// {F77} integer n_flux,indx(nmod)
static int n_flux,indx[NMOD];
// {F77} real*8 fprop_sfh(nmod,nprop_sfh),fmu_sfh(nmod)
static double fprop_sfh[NPROP_SFH][NMOD],fmu_sfh[NMOD];
// {F77} real*8 fprop_ir(nmod,nprop_ir),fmu_ir(nmod)
static double fprop_ir[NPROP_IR][NMOD],fmu_ir[NMOD];
// {F77} real*8 ldust(nmod),mstr1(nmod),logldust(nmod),lssfr(nmod)
static double ldust[NMOD],mstr1[NMOD],logldust[NMOD],lssfr[NMOD];
// {F77} real*8 flux_ir(nmod,nmax),tvism(nmod),tauv(nmod),mu(nmod)
static double flux_ir[NMAX][NMOD],tvism[NMOD],tauv[NMOD],mu[NMOD];
// {F77} real*8 tbg1(nmod),tbg2(nmod),xi1(nmod),xi2(nmod),xi3(nmod)
static double tbg1[NMOD],tbg2[NMOD],xi1[NMOD],xi2[NMOD],xi3[NMOD];
// {F77} real*8 fmu_ism(nmod),mdust(nmod),lmdust(nmod)
static double fmu_ism[NMOD],mdust[NMOD],lmdust[NMOD];
// {F77} c chi2, scaling factors, etc.
// {F77} real*8 flux_mod(nmax)
static double flux_mod[NMAX];
// {F77} real*8 chi2,chi2_sav,chi2_new,df
static double chi2,chi2_sav,chi2_new,df;
// {F77} real*8 a,num,den,a_sav
static double a,num,den,a_sav;
// {F77} real*8 ptot,prob,chi2_new_opt,chi2_new_ir
static double ptot,prob,chi2_new_opt,chi2_new_ir;
// {F77} real*8 chi2_opt,chi2_ir,chi2_sav_opt,chi2_sav_ir
static double chi2_opt,chi2_ir,chi2_sav_opt,chi2_sav_ir;
// {F77} c histograms
// {F77} real*8 fmu_min,fmu_max,dfmu
static double fmu_min,fmu_max,dfmu;
// {F77} real*8 ssfr_min,ssfr_max,dssfr
static double ssfr_min,ssfr_max,dssfr;
// {F77} real*8 fmuism_min,fmuism_max,dfmu_ism
static double fmuism_min,fmuism_max,dfmu_ism;
// {F77} real*8 mu_min,mu_max,dmu
static double mu_min,mu_max,dmu;
// {F77} real*8 tv_min,tv_max,dtv,dtvism
static double tv_min,tv_max,dtv,dtvism;
// {F77} real*8 sfr_min,sfr_max,dsfr
static double sfr_min,sfr_max,dsfr;
// {F77} real*8 a_min,a_max,da
static double a_min,a_max,da;
// {F77} real*8 md_min,md_max,dmd
static double md_min,md_max,dmd;
// {F77} real*8 ld_min,ld_max,dldust
static double ld_min,ld_max,dldust;
// {F77} real*8 tbg1_min,tbg1_max,dtbg,tbg2_min,tbg2_max
static double tbg1_min,tbg1_max,dtbg,tbg2_min,tbg2_max;
// {F77} real*8 xi_min,xi_max,dxi
static double xi_min,xi_max,dxi;
// {F77} real*8 pct_sfr(5),pct_fmu_sfh(5),pct_fmu_ir(5)
static double pct_sfr[5],pct_fmu_sfh[5],pct_fmu_ir[5];
// {F77} real*8 pct_mu(5),pct_tv(5),pct_mstr(5)
static double pct_mu[5],pct_tv[5],pct_mstr[5];
// {F77} real*8 pct_ssfr(5),pct_ld(5),pct_tbg2(5)
static double pct_ssfr[5],pct_ld[5],pct_tbg2[5];
// {F77} real*8 pct_tbg1(5),pct_xi1(5),pct_xi2(5)
static double pct_tbg1[5],pct_xi1[5],pct_xi2[5];
// {F77} real*8 pct_xi3(5),pct_tvism(5),pct_ism(5),pct_md(5)
static double pct_xi3[5],pct_tvism[5],pct_ism[5],pct_md[5];
// {F77} integer nbinmax1,nbinmax2
// {F77} c theSkyNet parameter (nbinmax1=1500,nbinmax2=150)
// {F77} parameter (nbinmax1=3000,nbinmax2=300)
// {F77} real*8 psfh2(nbinmax2),pir2(nbinmax2),pmu2(nbinmax2)
static double psfh2[NBINMAX2],pir2[NBINMAX2],pmu2[NBINMAX2];
// {F77} real*8 ptv2(nbinmax2),pxi2_2(nbinmax2),pssfr2(nbinmax2)
static double ptv2[NBINMAX2],pxi2_2[NBINMAX2],pssfr2[NBINMAX2];
// {F77} real*8 pa2(nbinmax2),pldust2(nbinmax2)
static double pa2[NBINMAX2],pldust2[NBINMAX2];
// {F77} real*8 ptbg1_2(nbinmax2),ptbg2_2(nbinmax2),pxi1_2(nbinmax2)
static double ptbg1_2[NBINMAX2],ptbg2_2[NBINMAX2],pxi1_2[NBINMAX2];
// {F77} real*8 ptvism2(nbinmax2),pism2(nbinmax2),pxi3_2(nbinmax2)
static double ptvism2[NBINMAX2],pism2[NBINMAX2],pxi3_2[NBINMAX2];
// {F77} real*8 fmuism2_hist(nbinmax2),md2_hist(nbinmax2)
static double fmuism2_hist[NBINMAX2],md2_hist[NBINMAX2];
// {F77} real*8 ssfr2_hist(nbinmax2),psfr2(nbinmax2),pmd_2(nbinmax2)
static double ssfr2_hist[NBINMAX2],psfr2[NBINMAX2],pmd_2[NBINMAX2];
// {F77} real*8 fmu2_hist(nbinmax2),mu2_hist(nbinmax2),tv2_hist(nbinmax2)
static double fmu2_hist[NBINMAX2],mu2_hist[NBINMAX2],tv2_hist[NBINMAX2];
// {F77} real*8 sfr2_hist(nbinmax2),a2_hist(nbinmax2),ld2_hist(nbinmax2)
static double sfr2_hist[NBINMAX2],a2_hist[NBINMAX2],ld2_hist[NBINMAX2];
// {F77} real*8 tbg1_2_hist(nbinmax2),tbg2_2_hist(nbinmax2),xi2_hist(nbinmax2)
static double tbg1_2_hist[NBINMAX2],tbg2_2_hist[NBINMAX2],xi2_hist[NBINMAX2];
// {F77} real*8 tvism2_hist(nbinmax2)
static double tvism2_hist[NBINMAX2];
// {F77} c theSkyNet
// {F77} c The highest probability bin values
// {F77} real*8 hpbv, get_hpbv
static double hpbv;
// {F77} real*8 min_hpbv
// {F77} parameter(min_hpbv = 0.00001)
// {F77} c theSkyNet
// {F77} integer nbin_fmu,nbin_mu,nbin_tv,nbin_a,nbin2_tvism
static int nbin_fmu,nbin_mu,nbin_tv,nbin_a,nbin2_tvism;
// {F77} integer nbin_tbg1,nbin_tbg2,nbin_xi,nbin_sfr,nbin_ld
static int nbin_tbg1,nbin_tbg2,nbin_xi,nbin_sfr,nbin_ld;
// {F77} integer nbin2_fmu,nbin2_mu,nbin2_tv,nbin2_a,nbin_fmu_ism
static int nbin2_fmu,nbin2_mu,nbin2_tv,nbin2_a,nbin_fmu_ism;
// {F77} integer nbin2_fmu_ism,nbin_md,nbin2_md,nbin_ssfr,nbin2_ssfr
static int nbin2_fmu_ism,nbin_md,nbin2_md,nbin_ssfr,nbin2_ssfr;
// {F77} integer nbin2_tbg1,nbin2_tbg2,nbin2_xi,nbin2_sfr,nbin2_ld
static int nbin2_tbg1,nbin2_tbg2,nbin2_xi,nbin2_sfr,nbin2_ld;
// {F77} real*8 fmu_hist(nbinmax1),psfh(nbinmax1),pism(nbinmax1)
static double fmu_hist[NBINMAX1],psfh[NBINMAX1],pism[NBINMAX1];
// {F77} real*8 pir(nbinmax1),ptbg1(nbinmax1)
static double pir[NBINMAX1],ptbg1[NBINMAX1];
// {F77} real*8 mu_hist(nbinmax1),pmu(nbinmax1),ptbg2(nbinmax1)
static double mu_hist[NBINMAX1],pmu[NBINMAX1],ptbg2[NBINMAX1];
// {F77} real*8 tv_hist(nbinmax1),ptv(nbinmax1),ptvism(nbinmax1)
static double tv_hist[NBINMAX1],ptv[NBINMAX1],ptvism[NBINMAX1];
// {F77} real*8 sfr_hist(nbinmax1),psfr(nbinmax1),fmuism_hist(nbinmax1)
static double sfr_hist[NBINMAX1],psfr[NBINMAX1],fmuism_hist[NBINMAX1];
// {F77} real*8 pssfr(nbinmax1),a_hist(nbinmax1),pa(nbinmax1)
static double pssfr[NBINMAX1],a_hist[NBINMAX1],pa[NBINMAX1];
// {F77} real*8 ld_hist(nbinmax1),pldust(nbinmax1)
static double ld_hist[NBINMAX1],pldust[NBINMAX1];
// {F77} real*8 tbg1_hist(nbinmax1),tbg2_hist(nbinmax1)
static double tbg1_hist[NBINMAX1],tbg2_hist[NBINMAX1];
// {F77} real*8 ssfr_hist(nbinmax1),xi_hist(nbinmax1),pxi1(nbinmax1)
static double ssfr_hist[NBINMAX1],xi_hist[NBINMAX1],pxi1[NBINMAX1];
// {F77} real*8 pxi2(nbinmax1),pxi3(nbinmax1)
static double pxi2[NBINMAX1],pxi3[NBINMAX1];
// {F77} real*8 md_hist(nbinmax1),pmd(nbinmax1)
static double md_hist[NBINMAX1],pmd[NBINMAX1];
// {F77} real*8 i_fmu_sfh(nmod),i_fmu_ir(nmod)
static double i_fmu_sfh[NMOD],i_fmu_ir[NMOD];
// {F77} real*8 i_mu(nmod),i_tauv(nmod),i_tvism(nmod)
static double i_mu[NMOD],i_tauv[NMOD],i_tvism[NMOD];
// {F77} real*8 i_lssfr(nmod),i_fmu_ism(nmod)
static double i_lssfr[NMOD],i_fmu_ism[NMOD];
// {F77} real*8 i_tbg1(nmod),i_xi1(nmod),i_xi2(nmod),i_xi3(nmod)
static double i_tbg1[NMOD],i_xi1[NMOD],i_xi2[NMOD],i_xi3[NMOD];
// {F77} real*8 i_tbg2(nmod)
static double i_tbg2[NMOD];
// {F77} c cosmological parameters
// {F77} real*8 h,omega,omega_lambda,clambda,q
static double h,omega,omega_lambda,clambda,q;
// {F77} real*8 cosmol_c,dl
static double cosmol_c,dl;
// {F77} c histogram parameters: min,max,bin width
// {F77} data fmu_min/0./,fmu_max/1.0005/,dfmu/0.001/
fmu_min=0,fmu_max=1.0005,dfmu=0.001;
// {F77} data fmuism_min/0./,fmuism_max/1.0005/,dfmu_ism/0.001/
fmuism_min=0,fmuism_max=1.0005,dfmu_ism=0.001;
// {F77} data mu_min/0./,mu_max/1.0005/,dmu/0.001/
mu_min=0,mu_max=1.0005,dmu=0.001;
// {F77} data tv_min/0./,tv_max/6.0025/,dtv/0.005/
tv_min=0,tv_max=6.0025,dtv=0.005;
// {F77} data ssfr_min/-13./,ssfr_max/-5.9975/,dssfr/0.05/
ssfr_min=-13,ssfr_max=-5.9975,dssfr=0.05;
// {F77} c theSkyNet data sfr_min/-3./,sfr_max/3.5005/,dsfr/0.005/
// {F77} c theSkyNet data a_min/7./,a_max/13.0025/,da/0.005/
// {F77} c theSkyNet data ld_min/7./,ld_max/13.0025/,dldust/0.005/
// {F77} data sfr_min/-8./,sfr_max/3.5005/,dsfr/0.005/
sfr_min=-8,sfr_max=3.5005,dsfr=0.005;
// {F77} data a_min/2./,a_max/13.0025/,da/0.005/
a_min=2,a_max=13.0025,da=0.005;
// {F77} data ld_min/2./,ld_max/13.0025/,dldust/0.005/
ld_min=2,ld_max=13.0025,dldust=0.005;
// {F77} data tbg1_min/30./,tbg1_max/60.0125/,dtbg/0.025/
tbg1_min=30,tbg1_max=60.0125,dtbg=0.025;
// {F77} data tbg2_min/15./,tbg2_max/25.0125/
tbg2_min=15,tbg2_max=25.0125;
// {F77} data xi_min/0./,xi_max/1.0001/,dxi/0.001/
xi_min=0,xi_max=1.0001,dxi=0.001;
// {F77} c theSkyNet data md_min/3./,md_max/9./,dmd/0.005/
// {F77} data md_min/-2./,md_max/9./,dmd/0.005/
md_min=-2,md_max=9,dmd=0.005;
// {F77} c cosmology
// {F77} data h/70./,omega/0.30/,omega_lambda/0.70/
h=70,omega=0.30,omega_lambda=0.70;
// {F77} data isave/0/
isave=0;
// {F77} c save parameters
// {F77} save flux_ir,flux_sfh,fmu_ir,fmu_sfh
// {F77} save mstr1,ssfr,ldust,mu,tauv,fmu_ism
// {F77} save lssfr,logldust,tvism
// {F77} save tbg1,tbg2,xi1,xi2,xi3
// {F77} save flux_obs,sigma,dist
// {F77} save mdust
// {F77}
// {F77}
// {F77} c ---------------------------------------------------------------------------
// {F77} c Are we in skynet mode
// {F77} c ---------------------------------------------------------------------------
// {F77} integer numargs
// {F77} character*80 arg
// {F77} logical skynet
static bool skynet;
// {F77} integer ios
// {F77} character*100 buffer1, buffer2
// {F77} logical found_old_entry
// {F77} integer gal_number_found
// {F77}
// {F77} numargs = iargc ( )
// {F77} if (numargs .eq. 0) then
if(argc == 1){
// {F77} c Do nothing as this is the normal model
// {F77} skynet = .FALSE.
skynet = false;
// {F77} else if (numargs .eq. 3) then
} else if(argc == 4){
// {F77} skynet = .TRUE.
skynet = true;
// {F77} call getarg ( 1, arg )
// {F77} read( arg, *) i_gal
// We subtract 1 from i_gal to suit C standard array indexing.
i_gal = atoi(argv[1])-1;
// {F77} call getarg( 2, filters)
strcpy(filters,argv[2]);
// {F77} call getarg( 3, obs)
strcpy(obs,argv[3]);
// {F77} else
} else{
// {F77} write(*,*) "Requires arguments: pixel to fit, filters file, observations file"
cout << "Requires arguments: pixel to fit, filters file, observations file" << endl;
// {F77} call EXIT(-1)
exit(-1);
// {F77} endif
}
// {F77}
// {F77} c ---------------------------------------------------------------------------
// {F77}
// {F77} c ---------------------------------------------------------------------------
// {F77} c Set things up: what filters to use, observations and models:
// {F77} c ---------------------------------------------------------------------------
// {F77}
// {F77} c READ FILTER FILE: "filters.dat"
// {F77} if (skynet .eqv. .FALSE.) then
// {F77} call getenv('USER_FILTERS',filters)
// {F77} endif
char * env;
if(!skynet){
env = getenv("USER_FILTERS");
if(env){
strcpy(filters,env);
} else {
exit(-1);
}
}
// {F77} close(22)
// {F77} open(22,file=filters,status='old')
// {F77} do i=1,1
// {F77} read(22,*)
// {F77} enddo
// {F77} io=0
// {F77} ifilt=0
// {F77} do while(io.eq.0)
// {F77} ifilt=ifilt+1
// {F77} read(22,*,iostat=io) filt_name(ifilt),lambda_eff(ifilt),filt_id(ifilt),fit(ifilt)
// {F77} enddo
// {F77} nfilt=ifilt-1
// {F77} close(22)
ifstream infs;
infs.open(filters);
if(!infs.is_open()){
cerr << "Error opening filters file: " << filters << endl;
exit(-1);
}
stringstream ss;
nfilt=0;
string line;
while(getline(infs,line)){
if(line[0] != '#'){
ss.str("");
ss.clear();
ss << line;
ss >> filt_name[nfilt] >> lambda_eff[nfilt] >> filt_id[nfilt] >> fit[nfilt];
nfilt++;
}
}
infs.close();
// {F77}
// {F77} c READ FILE WITH OBSERVATIONS:
// {F77} if (skynet .eqv. .FALSE.) then
// {F77} call getenv('USER_OBS',obs)
// {F77} endif
if(!skynet){
env = getenv("USER_OBS");
if(env){
strcpy(obs,env);
}
}
// {F77} close(20)
// {F77} open(20,file=obs,status='old')
// {F77} do i=1,1
// {F77} read(20,*)
// {F77} enddo
// {F77} io=0stringstream format
// {F77} n_obs=0
// {F77} do while(io.eq.0)
// {F77} n_obs=n_obs+1
// {F77} read(20,*,iostat=io) gal_name(n_obs),redshift(n_obs),
// {F77} + (flux_obs(n_obs,k),sigma(n_obs,k),k=1,nfilt)
// {F77} enddo
// {F77} n_obs=n_obs-1
// {F77} close(20)
infs.open(obs);
if(!infs.is_open()){
cerr << "Error opening observations file: " << obs << endl;
exit(-1);
}
n_obs=0;
while(getline(infs,line)){
if(line[0] != '#'){
ss.str("");
ss.clear();
ss << line;
ss >> gal_name[n_obs] >> redshift[n_obs];
for(k=0; k < nfilt; k++){
ss >> flux_obs[k][n_obs] >> sigma[k][n_obs];
}
n_obs++;
}
}
infs.close();
// {F77}
// {F77} c READ FILE WITH REDSHIFTS OF THE MODEL LIBRARIES
// {F77} close(24)
// {F77} open(24,file='zlibs.dat',status='old')
// {F77} io=0
// {F77} nz=0
// {F77} do while(io.eq.0)
// {F77} nz=nz+1
// {F77} read(24,*,iostat=io) i,zlib(nz)
// {F77} enddo
// {F77} nz=nz-1
// {F77} close(24)
// {F77}
infs.open("zlibs.dat");
if(!infs.is_open()){
cerr << "Error opening zlibs.dat" << endl;
exit(-1);
}
nz=0;
while(getline(infs,line)){
if(line[0] != '#'){
ss.str("");
ss.clear();
ss << line;
ss >> i >> zlib[nz];
nz++;
}
}
infs.close();
// {F77} c CHOOSE GALAXY TO FIT (enter corresponding i)
// {F77} if (skynet .eqv. .FALSE.) then
// {F77} write (6,'(x,a,$)') 'Choose galaxy - enter i_gal: '
// {F77} read (5,*) i_gal
// {F77} endif
// {F77} write(*,*) i_gal, n_obs
if(!skynet){
// TODO: Take input
}
cout << i_gal+1 << "\t" << n_obs << endl;
// {F77}
// {F77} c Do we have the observation
// {F77} if (i_gal .gt. n_obs) then
// {F77} write(*,*) 'Observation does not exist'
// {F77} call EXIT(0)
// {F77} endif
if(i_gal+1 > n_obs){
cerr << "Observation does not exist" << endl;
exit(-1);
}
// {F77}
// {F77} c WHAT OBSERVATIONS DO YOU WANT TO FIT?
// {F77} c fit(ifilt)=1: fit flux from filter ifilt
// {F77} c fit(ifilt)=0: do not fit flux from filter ifilt (set flux=-99)
// {F77} do ifilt=1,nfilt
// {F77} if (fit(ifilt).eq.0) then
// {F77} flux_obs(i_gal,ifilt)=-99.
// {F77} sigma(i_gal,ifilt)=-99.
// {F77} endif
// {F77} enddo
for(ifilt=0; ifilt < nfilt; ifilt++){
if(fit[ifilt] == 0){
flux_obs[ifilt][i_gal]=-99;
sigma[ifilt][i_gal]=-99;
}
}
// {F77}
// {F77} c Count number of non-zero fluxes (i.e. detections) to fit
// {F77} n_flux=0
// {F77} do k=1,nfilt
// {F77} if (flux_obs(i_gal,k).gt.0) then
// {F77} n_flux=n_flux+1
// {F77} endif
// {F77} enddo
n_flux=0;
for(k=0; k < nfilt; k++){
if(flux_obs[k][i_gal] > 0){
n_flux++;
}
}
// {F77}
// {F77} c theSkyNet
// {F77} write(*,*) 'n_flux =',n_flux
// {F77} if (n_flux < 4) then
// {F77} call EXIT(0)
// {F77} endif
cout << "n_flux = " << n_flux << endl;
if(n_flux < 4){
exit(-1);
}
// {F77} c theSkyNet
// {F77}
// {F77} c COMPUTE LUMINOSITY DISTANCE from z given cosmology
// {F77} c Obtain cosmological constant and q
// {F77} clambda=cosmol_c(h,omega,omega_lambda,q)
clambda=get_cosmol_c(h,omega,omega_lambda,&q);
// {F77}
// {F77} c Compute distance in Mpc from the redshifts z
// {F77} dist(i_gal)=dl(h,q,redshift(i_gal))
// {F77} dist(i_gal)=dist(i_gal)*3.086e+24/dsqrt(1.+redshift(i_gal))
dist[i_gal]=get_dl(h,q,redshift[i_gal]);
dist[i_gal]=dist[i_gal]*(3.086e+24)/sqrt(1+redshift[i_gal]);
// {F77}
// {F77}
// {F77} c OUTPUT FILES
// {F77} c name.fit: fit results, PDFs etc
// {F77} c name.sed: best-fit SED
// {F77} aux_name=gal_name(i_gal)
// {F77} close(31)
// {F77} c ---------------------------------------------------------------------------
// {F77} if (skynet .eqv. .FALSE.) then
// {F77} outfile1=aux_name(1:largo(aux_name))//'.fit'
// {F77} outfile2=aux_name(1:largo(aux_name))//'.sed'
// {F77} open (31, file=outfile1, status='unknown')
// {F77} c ---------------------------------------------------------------------------
// {F77} else
// {F77} write(outfile1, '(I0,a)') i_gal, '.fit'
// {F77} open (31, file=outfile1, status='unknown')
// {F77} write(31, *) '####### ',gal_name(i_gal)
// {F77} endif
strcpy(aux_name,gal_name[i_gal]);
FILE * fitfp;
if (!skynet){
// TODO : Handle manual
} else {
sprintf(outfile1, "%d.fit",i_gal+1);
fitfp = fopen(outfile1,"w");
if(!fitfp){
cerr << "Could not open fit file: " << outfile1 << endl;
}
fprintf(fitfp," ####### %s\n",gal_name[i_gal]);
}
// {F77}
// {F77} c Choose libraries according to the redshift of the source
// {F77} c Find zlib(i) closest of the galaxie's redshift
// {F77} do i=1,nz
// {F77} diffz(i)=abs(zlib(i)-redshift(i_gal))
// {F77} enddo
for(i=0; i<nz; i++){
diffz[i]=fabs(zlib[i]-redshift[i_gal]);
}
// {F77} call sort2(nz,diffz,zlib)
sort2(diffz,zlib,0,nz-1);
// {F77} c diff(1): minimum difference
// {F77} c zlib(1): library z we use for this galaxy
// {F77} c (if diffz(1) not gt 0.005)
// {F77} if (diffz(1).gt.0.005.and.mod(redshift(i_gal)*1000,10.).ne.5) then
// {F77} write(*,*) 'No model library at this galaxy redshift...'
// {F77} stop
// {F77} endif
if(diffz[0] > 0.005 && fmod(redshift[i_gal]*1000,10) != 5){
cerr << "No model library at this galaxy redshift..." << endl;
exit(-1);
}
// {F77}
// {F77} write(numz,'(f6.4)') zlib(1)
// {F77} optlib = 'starformhist_cb07_z'//numz//'.lbr'
// {F77} irlib = 'infrared_dce08_z'//numz//'.lbr'
// {F77}
// {F77} write(*,*) 'z= ',redshift(i_gal)
// {F77} write(*,*) 'optlib=',optlib
// {F77} write(*,*) 'irlib=',irlib
snprintf(numz, 7, "%f6.4",zlib[0]);
snprintf(optlib, 35, "starformhist_cb07_z%s.lbr",numz);
snprintf(irlib, 27, "infrared_dce08_z%s.lbr",numz);
cout << "z = " << redshift[i_gal] << endl;
cout << "optlib = " << optlib << endl;
cout << "irlib = " << irlib <<endl;
// {F77}
// {F77} c ---------------------------------------------------------------------------
// {F77} c What part of the SED are the filters sampling at the redshift of the galaxy?
// {F77} c - lambda(rest-frame) < 2.5 mic : emission purely stellar (attenuated by dust)
// {F77} c - 2.5 mic < lambda(rest-frame) < 10 mic : stellar + dust emission
// {F77} c - lambda(rest-frame) > 10 mic : emission purely from dust
// {F77} c ---------------------------------------------------------------------------
// {F77}
// {F77} nfilt_sfh=0 !nr of filters sampling the stellar emission
// {F77} nfilt_ir=0 !nr of filters sampling the dust emission
// {F77} nfilt_mix=0 !nr of filters sampling stellar+dust emission
// {F77} do i=1,nfilt
// {F77} lambda_rest(i)=lambda_eff(i)/(1.+redshift(i_gal))
// {F77} if (lambda_rest(i).lt.10.) then
// {F77} nfilt_sfh=nfilt_sfh+1
// {F77} kfilt_sfh(nfilt_sfh)=i
// {F77} endif
// {F77} if (lambda_rest(i).gt.2.5) then
// {F77} nfilt_ir=nfilt_ir+1
// {F77} kfilt_ir(nfilt_ir)=i
// {F77} endif
// {F77} if (lambda_rest(i).gt.2.5.and.lambda_rest(i).le.10) then
// {F77} nfilt_mix=nfilt_mix+1
// {F77} endif
// {F77} enddo
// {F77}
// {F77} write(*,*) ' '
// {F77} write(*,*) 'At this redshift: '
nfilt_sfh = nfilt_ir = nfilt_mix = 0;
for(i=0; i<nfilt; i++){
lambda_rest[i] = lambda_eff[i]/(1+redshift[i_gal]);
if(lambda_rest[i] < 10){
kfilt_sfh[nfilt_sfh]=i;
nfilt_sfh++;
}
if(lambda_rest[i] > 2.5){
kfilt_ir[nfilt_ir]=i;
nfilt_ir++;
}
if (lambda_rest[i] > 2.5 && lambda_rest[i] <= 10){
nfilt_mix++;
}
}
cout << " " << endl;
cout << "At this redshift: " << endl;
// {F77}
// {F77} do k=1,nfilt_sfh-nfilt_mix
// {F77} write(*,*) 'purely stellar... ',filt_name(k)
// {F77} enddo
// {F77} do k=nfilt_sfh-nfilt_mix+1,nfilt_sfh
// {F77} write(*,*) 'mix stars+dust... ',filt_name(k)
// {F77} enddo
// {F77} do k=nfilt_sfh+1,nfilt
// {F77} write(*,*) 'purely dust... ',filt_name(k)
// {F77} enddo
for(k=0; k < (nfilt_sfh-nfilt_mix); k++){
cout << "purely stellar... " << filt_name[k] << endl;
}
for(k=nfilt_sfh-nfilt_mix; k < nfilt_sfh; k++){
cout << "mix stars+dust... " << filt_name[k] << endl;
}
for(k=nfilt_sfh; k < nfilt; k++){
cout << "purely dust... " << filt_name[k] << endl;
}
// {F77}
// {F77} c ---------------------------------------------------------------------------
// {F77} c MODELS: read libraries of models with parameters + AB mags at z
// {F77} c attenuated stellar emission - optlib: starformhist_cb07_z###.lbr
// {F77} c --> nfilt_sfh model absolute AB mags
// {F77} c dust emission - irlib: infrared_dce08_z###.lbr
// {F77} c --> nfilt_ir model absolute AB mags
// {F77} c ---------------------------------------------------------------------------
// {F77}
// {F77} if (isave.eq.0) then
// {F77} io=0
if(isave == 0){
// {F77}
// {F77} c READ OPTLIB
// {F77} close(21)
// {F77} open(21,file=optlib,status='old')
// {F77} do i=1,2
// {F77} read(21,*) !2 lines of header
// {F77} enddo
// {F77} write(*,*) 'Reading SFH library...'
// {F77} i_sfh=0
// {F77} io=0
// {F77} do while(io.eq.0)
// {F77} i_sfh=i_sfh+1
// {F77} read(21,*,iostat=io) indx(i_sfh),(fprop_sfh(i_sfh,j),j=1,nprop_sfh),
// {F77} + (flux_sfh(i_sfh,j),j=1,nfilt_sfh)
// {F77} if (io.eq.0) then
// {F77} c Relevant physical parameters
// {F77} fmu_sfh(i_sfh)=fprop_sfh(i_sfh,22) ! fmu parameter Ld(ISM)/Ld(tot) - optical
// {F77} mstr1(i_sfh)=fprop_sfh(i_sfh,6) ! stellar mass
// {F77} ldust(i_sfh)=fprop_sfh(i_sfh,21)/mstr1(i_sfh) ! total luminosity of dust (normalize to Mstar)
// {F77} logldust(i_sfh)=dlog10(ldust(i_sfh)) ! log(Ldust)
// {F77} mu(i_sfh)=fprop_sfh(i_sfh,5) ! mu parameter (CF00 model)
// {F77} tauv(i_sfh)=fprop_sfh(i_sfh,4) ! optical V-band depth tauV (CF00 model)
// {F77} ssfr(i_sfh)=fprop_sfh(i_sfh,10)/mstr1(i_sfh) ! recent SSFR_0.01Gyr / stellar mass
// {F77} lssfr(i_sfh)=dlog10(ssfr(i_sfh)) ! log(SSFR_0.01Gyr)
// {F77} tvism(i_sfh)=mu(i_sfh)*tauv(i_sfh) ! mu*tauV=V-band optical depth for ISM
// {F77} c .lbr contains absolute AB magnitudes -> convert to fluxes Fnu in Lo/Hz
// {F77} c Convert all magnitudes to Lo/Hz (except H lines luminosity: in Lo)
// {F77} c Normalise SEDs to stellar mass
// {F77} do k=1,nfilt_sfh
// {F77} flux_sfh(i_sfh,k)=3.117336e+6
// {F77} + *10**(-0.4*(flux_sfh(i_sfh,k)+48.6))
// {F77} flux_sfh(i_sfh,k)=flux_sfh(i_sfh,k)/mstr1(i_sfh)
// {F77} c 1+z factor which is required in model fluxes
// {F77} flux_sfh(i_sfh,k)=flux_sfh(i_sfh,k)/(1+redshift(i_gal))
// {F77} enddo
// {F77} endif
// {F77} enddo
// {F77} close(21)
// {F77} n_sfh=i_sfh-1
infs.open(optlib);
if(!infs.is_open()){
cerr << "Failed to open SFH library: " << optlib << endl;
exit(-1);
}
cout << "Reading SFH library..." << endl;
n_sfh=0;
while(getline(infs,line)){
if(line[0] != '#'){
ss.str("");
ss.clear();
ss << line;
ss >> indx[n_sfh];
for(j=0; j < NPROP_SFH; j++){
ss >> fprop_sfh[j][n_sfh];
}
for(j=0; j < nfilt_sfh; j++){
ss >> flux_sfh[j][n_sfh];
}
// We need to subtract array index by 1 due to fortran difference.
fmu_sfh[n_sfh]=fprop_sfh[22-1][n_sfh];
mstr1[n_sfh]=fprop_sfh[6-1][n_sfh];
ldust[n_sfh]=fprop_sfh[21-1][n_sfh]/mstr1[n_sfh];
logldust[n_sfh]=log10(ldust[n_sfh]);
mu[n_sfh]=fprop_sfh[5-1][n_sfh];
tauv[n_sfh]=fprop_sfh[4-1][n_sfh];
ssfr[n_sfh]=fprop_sfh[10-1][n_sfh]/mstr1[n_sfh];
lssfr[n_sfh]=log10(ssfr[n_sfh]);
tvism[n_sfh]=mu[n_sfh]*tauv[n_sfh];
for(k=0; k < nfilt_sfh; k++){
flux_sfh[k][n_sfh]=3.117336e+6*pow(10,-0.4*(flux_sfh[k][n_sfh]+48.6));
flux_sfh[k][n_sfh]=flux_sfh[k][n_sfh]/mstr1[n_sfh];
flux_sfh[k][n_sfh]=flux_sfh[k][n_sfh]/(1+redshift[i_gal]);
}
n_sfh++;
}
}
infs.close();
// {F77}
// {F77} c READ IRLIB
// {F77} close(20)
// {F77} open(20,file=irlib,status='old')
// {F77} do i=1,2
// {F77} read(20,*) !2 lines of header
// {F77} enddo
// {F77} write(*,*) 'Reading IR dust emission library...'
// {F77} i_ir=0
// {F77} io=0
// {F77} do while(io.eq.0)
// {F77} i_ir=i_ir+1
// {F77} read(20,*,iostat=io) (fprop_ir(i_ir,j),j=1,nprop_ir),
// {F77} + (flux_ir(i_ir,j),j=1,nfilt_ir)
// {F77} c IR model parameters
// {F77} fmu_ir(i_ir)=fprop_ir(i_ir,1) ! fmu parameter Ld(ISM)/Ld(tot) - infrared
// {F77} fmu_ism(i_ir)=fprop_ir(i_ir,2) ! xi_C^ISM [cont. cold dust to Ld(ISM)]
// {F77} tbg2(i_ir)=fprop_ir(i_ir,4) ! T_C^ISM [eq. temp. cold dust in ISM]
// {F77} tbg1(i_ir)=fprop_ir(i_ir,3) ! T_W^BC [eq. temp. warm dust in birth clouds]
// {F77} xi1(i_ir)=fprop_ir(i_ir,5) ! xi_PAH^BC Ld(PAH)/Ld(BC)
// {F77} xi2(i_ir)=fprop_ir(i_ir,6) ! xi_MIR^BC Ld(MIR)/Ld(BC)
// {F77} xi3(i_ir)=fprop_ir(i_ir,7) ! xi_W^BC Ld(warm)/Ld(BC)
// {F77} mdust(i_ir)=fprop_ir(i_ir,8) !dust mass
// {F77} c .lbr contains absolute AB magnitudes -> convert to fluxes Fnu in Lo/Hz
// {F77} c Convert all magnitudes to Lo/Hz
// {F77} do k=1,nfilt_ir
// {F77} flux_ir(i_ir,k)=3.117336e+6
// {F77} + *10**(-0.4*(flux_ir(i_ir,k)+48.6))
// {F77} flux_ir(i_ir,k)=flux_ir(i_ir,k)/(1+redshift(i_gal))
// {F77} enddo
// {F77} c Re-define IR parameters: xi^tot
// {F77} xi1(i_ir)=xi1(i_ir)*(1.-fmu_ir(i_ir))+
// {F77} + 0.550*(1-fmu_ism(i_ir))*fmu_ir(i_ir) ! xi_PAH^tot Ld(PAH)/Ld(tot)
// {F77} xi2(i_ir)=xi2(i_ir)*(1.-fmu_ir(i_ir))+
// {F77} + 0.275*(1-fmu_ism(i_ir))*fmu_ir(i_ir) ! xi_MIR^tot Ld(MIR)/Ld(tot)
// {F77} xi3(i_ir)=xi3(i_ir)*(1.-fmu_ir(i_ir))+
// {F77} + 0.175*(1-fmu_ism(i_ir))*fmu_ir(i_ir) ! xi_W^tot Ld(warm)/Ld(tot)
// {F77} fmu_ism(i_ir)=fmu_ism(i_ir)*fmu_ir(i_ir) ! xi_C^tot Ld(cold)/Ld(tot)
// {F77} enddo
// {F77} 201 format(0p7f12.3,1pe12.3,1p14e12.3,1p3e12.3)
// {F77} close(20)
// {F77} n_ir=i_ir-1
infs.open(irlib);
if(!infs.is_open()){
cerr << "Failed to open IR dust emission library: " << irlib << endl;
exit(-1);
}
cout << "Reading IR dust emission library..." << endl;
n_ir=0;
while(getline(infs,line)){
if(line[0] != '#'){
ss.str("");
ss.clear();
ss << line;
for(j=0; j < NPROP_IR; j++){
ss >> fprop_ir[j][n_ir];
}
for(j=0; j < nfilt_ir; j++){
ss >> flux_ir[j][n_ir];
}
// We need to subtract array index by 1 due to fortran difference.
fmu_ir[n_ir]=fprop_ir[1-1][n_ir];
fmu_ism[n_ir]=fprop_ir[2-1][n_ir];
tbg2[n_ir]=fprop_ir[4-1][n_ir];
tbg1[n_ir]=fprop_ir[3-1][n_ir];
xi1[n_ir]=fprop_ir[5-1][n_ir];
xi2[n_ir]=fprop_ir[6-1][n_ir];
xi3[n_ir]=fprop_ir[7-1][n_ir];
mdust[n_ir]=fprop_ir[8-1][n_ir];
for(k=0; k < nfilt_ir; k++){
flux_ir[k][n_ir]=3.117336e+6*pow(10,-0.4*(flux_ir[k][n_ir]+48.6));
flux_ir[k][n_ir]=flux_ir[k][n_ir]/(1+redshift[i_gal]);
}
xi1[n_ir]=xi1[n_ir]*(1-fmu_ir[n_ir])+0.550*(1-fmu_ism[n_ir])*fmu_ir[n_ir];
xi2[n_ir]=xi2[n_ir]*(1-fmu_ir[n_ir])+0.275*(1-fmu_ism[n_ir])*fmu_ir[n_ir];
xi3[n_ir]=xi3[n_ir]*(1-fmu_ir[n_ir])+0.175*(1-fmu_ism[n_ir])*fmu_ir[n_ir];
fmu_ism[n_ir]=fmu_ism[n_ir]*fmu_ir[n_ir];
n_ir++;
}
}
infs.close();
// {F77} isave=1
// {F77} endif
isave=1;
}
// {F77}
// {F77} c ---------------------------------------------------------------------------
// {F77} c COMPARISON BETWEEN MODELS AND OBSERVATIONS:
// {F77} c
// {F77} c Compare everything in the sample units:
// {F77} c Lnu (i.e. luminosity per unit frequency) in Lsun/Hz
// {F77} c
// {F77} c Model fluxes: already converted from AB mags to Lnu in Lsun/Hz
// {F77} c Fluxes and physical parameters from optical library per unit Mstar=1 Msun
// {F77} c Fluxes and physical parameters from infrared library per unit Ldust=1 Lsun
// {F77} c
// {F77} c Observed fluxes & uncertainties
// {F77} c Convert from Fnu in Jy to Lnu in Lo/Hz [using luminosity distance dist(i_gal)]
// {F77} c ---------------------------------------------------------------------------
// {F77}
// {F77} c Observed fluxes: Jy -> Lsun/Hz
// {F77} do k=1,nfilt
// {F77} if (flux_obs(i_gal,k).gt.0) then
// {F77} flux_obs(i_gal,k)=flux_obs(i_gal,k)*1.e-23
// {F77} + *3.283608731e-33*(dist(i_gal)**2)
// {F77} sigma(i_gal,k)=sigma(i_gal,k)*1.e-23
// {F77} + *3.283608731e-33*(dist(i_gal)**2)
// {F77} endif
// {F77} if (sigma(i_gal,k).lt.0.05*flux_obs(i_gal,k)) then
// {F77} sigma(i_gal,k)=0.05*flux_obs(i_gal,k)
// {F77} endif
// {F77} enddo
// {F77}
// {F77} do k=1,nfilt
// {F77} if (sigma(i_gal,k).gt.0.0) then
// {F77} w(i_gal,k) = 1.0 / (sigma(i_gal,k)**2)
// {F77} endif
// {F77} enddo
for(k=0; k<nfilt; k++){
if (flux_obs[k][i_gal] > 0){
flux_obs[k][i_gal]=flux_obs[k][i_gal]*1.0e-23*3.283608731e-33*pow(dist[i_gal],2);
sigma[k][i_gal]=sigma[k][i_gal]*1.0e-23*3.283608731e-33*pow(dist[i_gal],2);
}
if (sigma[k][i_gal] < 0.05*flux_obs[k][i_gal]){
sigma[k][i_gal]=0.05*flux_obs[k][i_gal];
}
}
for(k=0; k<nfilt; k++){
if (sigma[k][i_gal] > 0.0){
w[k][i_gal] = 1.0/(pow(sigma[k][i_gal],2));
}
}
// {F77}
// {F77} c ---------------------------------------------------------------------------
// {F77} c Initialize variables:
// {F77} n_models=0
// {F77} chi2_sav=1.e+30
// {F77} ptot=0.
// {F77} prob=0.
// {F77} do k=1,nfilt
// {F77} flux_mod(k)=0.
// {F77} enddo
n_models=0;
chi2_sav=1.0e30;
ptot=0;
prob=0;
for(k=0; k<nfilt; k++){
flux_mod[k]=0;
}
// {F77}
// {F77} c theSkyNet do i=1,1500
// {F77} do i=1,3000
// {F77} psfh(i)=0.
// {F77} pir(i)=0.
// {F77} pmu(i)=0.
// {F77} ptv(i)=0.
// {F77} ptvism(i)=0.
// {F77} pssfr(i)=0.
// {F77} psfr(i)=0.
// {F77} pa(i)=0.
// {F77} pldust(i)=0.
// {F77} ptbg1(i)=0.
// {F77} ptbg2(i)=0.
// {F77} pism(i)=0.
// {F77} pxi1(i)=0.
// {F77} pxi2(i)=0.
// {F77} pxi3(i)=0.
// {F77} pmd(i)=0.
// {F77} enddo
for(i=0; i<3000; i++){
psfh[i]=0;
pir[i]=0;
pmu[i]=0;
ptv[i]=0;
ptvism[i]=0;
pssfr[i]=0;
psfr[i]=0;
pa[i]=0;
pldust[i]=0;
ptbg1[i]=0;
ptbg2[i]=0;
pism[i]=0;
pxi1[i]=0;
pxi2[i]=0;
pxi3[i]=0;
pmd[i]=0;
}
// {F77}
// {F77} c ---------------------------------------------------------------------------
// {F77} c Compute histogram grids of the parameter likelihood distributions before
// {F77} c starting the big loop in which we compute chi^2 for each allowed combination
// {F77} c of stellar+dust emission model (to save time).
// {F77} c
// {F77} c The high-resolution marginalized likelihood distributions will be
// {F77} c computed on-the-run
// {F77} c ---------------------------------------------------------------------------
// {F77}
// {F77} c f_mu (SFH) & f_mu (IR)
// {F77} call get_histgrid(dfmu,fmu_min,fmu_max,nbin_fmu,fmu_hist)
get_histgrid(dfmu,fmu_min,fmu_max,&nbin_fmu,fmu_hist);
// {F77} c mu parameter
// {F77} call get_histgrid(dmu,mu_min,mu_max,nbin_mu,mu_hist)
get_histgrid(dmu,mu_min,mu_max,&nbin_mu,mu_hist);
// {F77} c tauv (dust optical depth)
// {F77} call get_histgrid(dtv,tv_min,tv_max,nbin_tv,tv_hist)
get_histgrid(dtv,tv_min,tv_max,&nbin_tv,tv_hist);
// {F77} c sSFR
// {F77} call get_histgrid(dssfr,ssfr_min,ssfr_max,nbin_ssfr,ssfr_hist)
get_histgrid(dssfr,ssfr_min,ssfr_max,&nbin_ssfr,ssfr_hist);
// {F77} c SFR
// {F77} call get_histgrid(dsfr,sfr_min,sfr_max,nbin_sfr,sfr_hist)
get_histgrid(dsfr,sfr_min,sfr_max,&nbin_sfr,sfr_hist);
// {F77} c Mstars
// {F77} call get_histgrid(da,a_min,a_max,nbin_a,a_hist)
get_histgrid(da,a_min,a_max,&nbin_a,a_hist);
// {F77} c Ldust
// {F77} call get_histgrid(dldust,ld_min,ld_max,nbin_ld,ld_hist)