14 static const int MNTS = 200;
58 mpp() { memset(
this, 0,
sizeof(
mpp)); }
180 long,
const double[],
int);
181 STATIC void RauchReadMPP(vector<mpp>&,vector<mpp>&,vector<mpp>&,vector<mpp>&,vector<mpp>&,vector<mpp>&);
183 STATIC void WriteASCIIHead(FILE*,
long,
long,
const vector<string>&,
long,
long,
const string&,
double,
184 const string&,
double,
const vector<mpp>&,
const char*,
int);
199 vector<long>&,
long,vector<realnum>&,
bool,
const realnum[]=NULL,
long=0L);
201 const vector<long>&,vector<long>&,
long,vector<realnum>&,
int);
203 const long[],vector<long>&,
long,
long,vector<realnum>&);
204 template<
class T>
void SortUnique(vector<T>&,vector<T>&);
208 const vector<realnum>&,
double*,
double*);
210 long,
double*,
double*);
214 STATIC void SearchModel(
const vector<mpp>&,
bool,
long,
const vector<double>&,
long,
long*,
long*);
225 long,
const T[],
const realnum[]);
265 fprintf(
ioQQQ,
"\n I will now list all stellar atmosphere grids that are ready to be used (if any).\n" );
266 fprintf(
ioQQQ,
" User-defined stellar atmosphere grids will not be included in this list.\n\n" );
275 fprintf(
ioQQQ,
" table star atlas Z+1.0 <Teff> [ <log(g)> ]\n" );
277 fprintf(
ioQQQ,
" table star atlas Z+0.5 <Teff> [ <log(g)> ]\n" );
279 fprintf(
ioQQQ,
" table star atlas Z+0.3 <Teff> [ <log(g)> ]\n" );
281 fprintf(
ioQQQ,
" table star atlas Z+0.2 <Teff> [ <log(g)> ]\n" );
283 fprintf(
ioQQQ,
" table star atlas Z+0.1 <Teff> [ <log(g)> ]\n" );
285 fprintf(
ioQQQ,
" table star atlas Z+0.0 <Teff> [ <log(g)> ]\n" );
287 fprintf(
ioQQQ,
" table star atlas Z-0.1 <Teff> [ <log(g)> ]\n" );
289 fprintf(
ioQQQ,
" table star atlas Z-0.2 <Teff> [ <log(g)> ]\n" );
291 fprintf(
ioQQQ,
" table star atlas Z-0.3 <Teff> [ <log(g)> ]\n" );
293 fprintf(
ioQQQ,
" table star atlas Z-0.5 <Teff> [ <log(g)> ]\n" );
295 fprintf(
ioQQQ,
" table star atlas Z-1.0 <Teff> [ <log(g)> ]\n" );
297 fprintf(
ioQQQ,
" table star atlas Z-1.5 <Teff> [ <log(g)> ]\n" );
299 fprintf(
ioQQQ,
" table star atlas Z-2.0 <Teff> [ <log(g)> ]\n" );
301 fprintf(
ioQQQ,
" table star atlas Z-2.5 <Teff> [ <log(g)> ]\n" );
303 fprintf(
ioQQQ,
" table star atlas Z-3.0 <Teff> [ <log(g)> ]\n" );
305 fprintf(
ioQQQ,
" table star atlas Z-3.5 <Teff> [ <log(g)> ]\n" );
307 fprintf(
ioQQQ,
" table star atlas Z-4.0 <Teff> [ <log(g)> ]\n" );
309 fprintf(
ioQQQ,
" table star atlas Z-4.5 <Teff> [ <log(g)> ]\n" );
311 fprintf(
ioQQQ,
" table star atlas Z-5.0 <Teff> [ <log(g)> ]\n" );
314 fprintf(
ioQQQ,
" table star atlas odfnew Z+0.5 <Teff> [ <log(g)> ]\n" );
316 fprintf(
ioQQQ,
" table star atlas odfnew Z+0.2 <Teff> [ <log(g)> ]\n" );
318 fprintf(
ioQQQ,
" table star atlas odfnew Z+0.0 <Teff> [ <log(g)> ]\n" );
320 fprintf(
ioQQQ,
" table star atlas odfnew Z-0.5 <Teff> [ <log(g)> ]\n" );
322 fprintf(
ioQQQ,
" table star atlas odfnew Z-1.0 <Teff> [ <log(g)> ]\n" );
324 fprintf(
ioQQQ,
" table star atlas odfnew Z-1.5 <Teff> [ <log(g)> ]\n" );
326 fprintf(
ioQQQ,
" table star atlas odfnew Z-2.0 <Teff> [ <log(g)> ]\n" );
328 fprintf(
ioQQQ,
" table star atlas odfnew Z-2.5 <Teff> [ <log(g)> ]\n" );
331 fprintf(
ioQQQ,
" table star atlas 3-dim <Teff> <log(g)> <log(Z)>\n" );
334 fprintf(
ioQQQ,
" table star atlas odfnew 3-dim <Teff> <log(g)> <log(Z)>\n" );
337 fprintf(
ioQQQ,
" table star costar solar (see Hazy for parameters)\n" );
339 fprintf(
ioQQQ,
" table star costar halo (see Hazy for parameters)\n" );
348 fprintf(
ioQQQ,
" table star rauch H-Ca solar <Teff> [ <log(g)> ]\n" );
350 fprintf(
ioQQQ,
" table star rauch H-Ca halo <Teff> [ <log(g)> ]\n" );
352 fprintf(
ioQQQ,
" table star rauch H-Ca 3-dim <Teff> <log(g)> <log(Z)>\n" );
355 fprintf(
ioQQQ,
" table star rauch H-Ni solar <Teff> [ <log(g)> ]\n" );
357 fprintf(
ioQQQ,
" table star rauch H-Ni halo <Teff> [ <log(g)> ]\n" );
359 fprintf(
ioQQQ,
" table star rauch H-Ni 3-dim <Teff> <log(g)> <log(Z)>\n" );
362 fprintf(
ioQQQ,
" table star rauch pg1159 <Teff> [ <log(g)> ]\n" );
367 fprintf(
ioQQQ,
" table star rauch hydrogen <Teff> [ <log(g)> ]\n" );
370 fprintf(
ioQQQ,
" table star rauch helium <Teff> [ <log(g)> ]\n" );
373 fprintf(
ioQQQ,
" table star rauch H+He <Teff> <log(g)> <frac(He)>\n" );
376 fprintf(
ioQQQ,
" table star \"starburst99.mod\" <age>\n" );
378 fprintf(
ioQQQ,
" table star \"starburst99_2d.mod\" <age> <Z>\n" );
381 fprintf(
ioQQQ,
" table star tlusty OBstar Z+0.3 <Teff> [ <log(g)> ]\n" );
383 fprintf(
ioQQQ,
" table star tlusty OBstar Z+0.0 <Teff> [ <log(g)> ]\n" );
385 fprintf(
ioQQQ,
" table star tlusty OBstar Z-0.3 <Teff> [ <log(g)> ]\n" );
387 fprintf(
ioQQQ,
" table star tlusty OBstar Z-0.7 <Teff> [ <log(g)> ]\n" );
389 fprintf(
ioQQQ,
" table star tlusty OBstar Z-1.0 <Teff> [ <log(g)> ]\n" );
391 fprintf(
ioQQQ,
" table star tlusty OBstar Z-inf <Teff> [ <log(g)> ]\n" );
394 fprintf(
ioQQQ,
" table star tlusty OBstar 3-dim <Teff> <log(g)> <log(Z)>\n" );
397 fprintf(
ioQQQ,
" table star tlusty Bstar Z+0.3 <Teff> [ <log(g)> ]\n" );
399 fprintf(
ioQQQ,
" table star tlusty Bstar Z+0.0 <Teff> [ <log(g)> ]\n" );
401 fprintf(
ioQQQ,
" table star tlusty Bstar Z-0.3 <Teff> [ <log(g)> ]\n" );
403 fprintf(
ioQQQ,
" table star tlusty Bstar Z-0.7 <Teff> [ <log(g)> ]\n" );
405 fprintf(
ioQQQ,
" table star tlusty Bstar Z-1.0 <Teff> [ <log(g)> ]\n" );
407 fprintf(
ioQQQ,
" table star tlusty Bstar Z-inf <Teff> [ <log(g)> ]\n" );
410 fprintf(
ioQQQ,
" table star tlusty Bstar 3-dim <Teff> <log(g)> <log(Z)>\n" );
413 fprintf(
ioQQQ,
" table star tlusty Ostar Z+0.3 <Teff> [ <log(g)> ]\n" );
415 fprintf(
ioQQQ,
" table star tlusty Ostar Z+0.0 <Teff> [ <log(g)> ]\n" );
417 fprintf(
ioQQQ,
" table star tlusty Ostar Z-0.3 <Teff> [ <log(g)> ]\n" );
419 fprintf(
ioQQQ,
" table star tlusty Ostar Z-0.7 <Teff> [ <log(g)> ]\n" );
421 fprintf(
ioQQQ,
" table star tlusty Ostar Z-1.0 <Teff> [ <log(g)> ]\n" );
423 fprintf(
ioQQQ,
" table star tlusty Ostar Z-1.5 <Teff> [ <log(g)> ]\n" );
425 fprintf(
ioQQQ,
" table star tlusty Ostar Z-1.7 <Teff> [ <log(g)> ]\n" );
427 fprintf(
ioQQQ,
" table star tlusty Ostar Z-2.0 <Teff> [ <log(g)> ]\n" );
429 fprintf(
ioQQQ,
" table star tlusty Ostar Z-3.0 <Teff> [ <log(g)> ]\n" );
431 fprintf(
ioQQQ,
" table star tlusty Ostar Z-inf <Teff> [ <log(g)> ]\n" );
434 fprintf(
ioQQQ,
" table star tlusty Ostar 3-dim <Teff> <log(g)> <log(Z)>\n" );
437 fprintf(
ioQQQ,
" table star werner <Teff> [ <log(g)> ]\n" );
440 fprintf(
ioQQQ,
" table star wmbasic <Teff> <log(g)> <log(Z)>\n" );
445 fprintf(
ioQQQ,
" table HM05 quasar <z> [ <factor> ]\n" );
471 lgFail = lgFail ||
lgCompileAtmosphere(
"atlas_fp10k2.ascii",
"atlas_fp10k2.mod", NULL, 0L, pc );
473 lgFail = lgFail ||
lgCompileAtmosphere(
"atlas_fp05k2.ascii",
"atlas_fp05k2.mod", NULL, 0L, pc );
475 lgFail = lgFail ||
lgCompileAtmosphere(
"atlas_fp03k2.ascii",
"atlas_fp03k2.mod", NULL, 0L, pc );
477 lgFail = lgFail ||
lgCompileAtmosphere(
"atlas_fp02k2.ascii",
"atlas_fp02k2.mod", NULL, 0L, pc );
479 lgFail = lgFail ||
lgCompileAtmosphere(
"atlas_fp01k2.ascii",
"atlas_fp01k2.mod", NULL, 0L, pc );
481 lgFail = lgFail ||
lgCompileAtmosphere(
"atlas_fp00k2.ascii",
"atlas_fp00k2.mod", NULL, 0L, pc );
483 lgFail = lgFail ||
lgCompileAtmosphere(
"atlas_fm01k2.ascii",
"atlas_fm01k2.mod", NULL, 0L, pc );
485 lgFail = lgFail ||
lgCompileAtmosphere(
"atlas_fm02k2.ascii",
"atlas_fm02k2.mod", NULL, 0L, pc );
487 lgFail = lgFail ||
lgCompileAtmosphere(
"atlas_fm03k2.ascii",
"atlas_fm03k2.mod", NULL, 0L, pc );
489 lgFail = lgFail ||
lgCompileAtmosphere(
"atlas_fm05k2.ascii",
"atlas_fm05k2.mod", NULL, 0L, pc );
491 lgFail = lgFail ||
lgCompileAtmosphere(
"atlas_fm10k2.ascii",
"atlas_fm10k2.mod", NULL, 0L, pc );
493 lgFail = lgFail ||
lgCompileAtmosphere(
"atlas_fm15k2.ascii",
"atlas_fm15k2.mod", NULL, 0L, pc );
495 lgFail = lgFail ||
lgCompileAtmosphere(
"atlas_fm20k2.ascii",
"atlas_fm20k2.mod", NULL, 0L, pc );
497 lgFail = lgFail ||
lgCompileAtmosphere(
"atlas_fm25k2.ascii",
"atlas_fm25k2.mod", NULL, 0L, pc );
499 lgFail = lgFail ||
lgCompileAtmosphere(
"atlas_fm30k2.ascii",
"atlas_fm30k2.mod", NULL, 0L, pc );
501 lgFail = lgFail ||
lgCompileAtmosphere(
"atlas_fm35k2.ascii",
"atlas_fm35k2.mod", NULL, 0L, pc );
503 lgFail = lgFail ||
lgCompileAtmosphere(
"atlas_fm40k2.ascii",
"atlas_fm40k2.mod", NULL, 0L, pc );
505 lgFail = lgFail ||
lgCompileAtmosphere(
"atlas_fm45k2.ascii",
"atlas_fm45k2.mod", NULL, 0L, pc );
507 lgFail = lgFail ||
lgCompileAtmosphere(
"atlas_fm50k2.ascii",
"atlas_fm50k2.mod", NULL, 0L, pc );
512 lgFail = lgFail ||
lgCompileAtmosphere(
"atlas_fp05k2_odfnew.ascii",
"atlas_fp05k2_odfnew.mod",
516 lgFail = lgFail ||
lgCompileAtmosphere(
"atlas_fp02k2_odfnew.ascii",
"atlas_fp02k2_odfnew.mod",
520 lgFail = lgFail ||
lgCompileAtmosphere(
"atlas_fp00k2_odfnew.ascii",
"atlas_fp00k2_odfnew.mod",
524 lgFail = lgFail ||
lgCompileAtmosphere(
"atlas_fm05k2_odfnew.ascii",
"atlas_fm05k2_odfnew.mod",
528 lgFail = lgFail ||
lgCompileAtmosphere(
"atlas_fm10k2_odfnew.ascii",
"atlas_fm10k2_odfnew.mod",
532 lgFail = lgFail ||
lgCompileAtmosphere(
"atlas_fm15k2_odfnew.ascii",
"atlas_fm15k2_odfnew.mod",
536 lgFail = lgFail ||
lgCompileAtmosphere(
"atlas_fm20k2_odfnew.ascii",
"atlas_fm20k2_odfnew.mod",
540 lgFail = lgFail ||
lgCompileAtmosphere(
"atlas_fm25k2_odfnew.ascii",
"atlas_fm25k2_odfnew.mod",
548 lgFail = lgFail ||
lgCompileAtmosphere(
"atlas_3d_odfnew.ascii",
"atlas_3d_odfnew.mod", NULL, 0L, pc );
556 const char *chMetalicity,
557 const char *chODFNew,
565 grid.
name =
"atlas_";
571 grid.
name += chMetalicity;
574 grid.
name += chODFNew;
582 strcpy( chIdent,
"3-dim" );
586 strcpy( chIdent,
"Z " );
587 strcat( chIdent, chMetalicity );
589 strcat( chIdent, ( strlen(chODFNew) == 0 ?
" Kurucz" :
" ODFNew" ) );
590 grid.
ident = chIdent;
592 grid.
command =
"COMPILE STARS";
633 fprintf(
ioQQQ,
" Creating Sc1_costar_solar.ascii....\n" );
634 lgFail = lgFail ||
CoStarInitialize(
"Sc1_costar_z020_lb.fluxes",
"Sc1_costar_solar.ascii" );
638 fprintf(
ioQQQ,
" Creating Sc1_costar_halo.ascii....\n" );
639 lgFail = lgFail ||
CoStarInitialize(
"Sc1_costar_z004_lb.fluxes",
"Sc1_costar_halo.ascii" );
665 grid.
name = ( lgHalo ?
"Sc1_costar_halo.mod" :
"Sc1_costar_solar.mod" );
669 grid.
ident =
" costar";
671 grid.
command =
"COMPILE STARS";
728 string OutName( InName );
729 string::size_type ptr = OutName.rfind(
'.' );
730 ASSERT( ptr != string::npos );
731 OutName.replace( ptr, string::npos,
".mod" );
743 grid.
ident =
"bogus ident.";
744 grid.
command =
"bogus command.";
750 if( strcmp( grid.
names[0],
"Teff" ) == 0 )
752 fprintf(
ioQQQ,
" GridCompile: checking effective temperatures...\n" );
763 const char *FileName,
771 string chTruncName( FileName );
772 string::size_type ptr = chTruncName.rfind(
'.' );
773 if( ptr != string::npos )
774 chTruncName.replace( ptr, string::npos,
"" );
777 grid.
name = FileName;
782 grid.
ident = chTruncName.substr(0,12);
783 if( grid.
ident.length() < 12 )
784 grid.
ident.append(12-grid.
ident.length(),
' ');
787 grid.
command =
"COMPILE STARS \"" + chTruncName +
".ascii\"";
809 if( version == 2005 )
814 grid.
ident =
" HM05 ";
816 else if( version == 2012 )
819 grid.
ident =
" HM12 ";
825 grid.
name +=
"quasar.ascii";
826 grid.
ident +=
"QUASAR";
830 grid.
name +=
"galaxy.ascii";
831 grid.
ident +=
"GALAXY";
841 vector<realnum> Edges;
842 Edges.push_back(
realnum(RYDLAM/1216.0) );
843 if( version == 2012 )
845 Edges.push_back(
realnum(RYDLAM/1026.0) );
846 Edges.push_back(
realnum(RYDLAM/972.5) );
847 Edges.push_back(
realnum(RYDLAM/949.7) );
848 Edges.push_back(
realnum(RYDLAM/937.8) );
851 Edges.push_back(
realnum(RYDLAM/304.0) );
852 if( version == 2012 )
854 Edges.push_back(
realnum(RYDLAM/256.4) );
855 Edges.push_back(
realnum(RYDLAM/243.1) );
856 Edges.push_back(
realnum(RYDLAM/237.4) );
857 Edges.push_back(
realnum(RYDLAM/234.4) );
859 Edges.push_back(
realnum(RYDLAM/228.0) );
863 long nval = 1, ndim = 1;
864 CheckVal( &grid, &val, &nval, &ndim );
881 oss <<
"ks18_q" << Q <<
".ascii";
882 grid.
name = oss.str();
884 oss2 <<
" KS18, Q=" << Q <<
" ";
885 grid.
ident = oss2.str();
894 long nval = 1, ndim = 1;
895 CheckVal( &grid, &val, &nval, &ndim );
931 grid.
name =
"kurucz79.mod";
935 grid.
ident =
" Kurucz 1979";
937 grid.
command =
"COMPILE STARS";
960 Edges[0] = (
realnum)(RYDLAM/911.204);
961 Edges[1] = (
realnum)(RYDLAM/503.968);
962 Edges[2] = (
realnum)(RYDLAM/227.806);
983 grid.
name =
"mihalas.mod";
987 grid.
ident =
" Mihalas";
989 grid.
command =
"COMPILE STARS";
1006 static const double par2[2] = { 0., -1. };
1009 static const double par3[11] = { 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0 };
1028 RauchReadMPP( telg1, telg2, telg3, telg4, telg5, telg6 );
1032 bool lgFail =
false;
1037 fprintf(
ioQQQ,
" Creating rauch_h-ca_solar.ascii....\n" );
1038 lgFail = lgFail ||
RauchInitialize(
"rauch_h-ca_solar.ascii",
"_solar_bin_0.1",
1044 fprintf(
ioQQQ,
" Creating rauch_h-ca_halo.ascii....\n" );
1045 lgFail = lgFail ||
RauchInitialize(
"rauch_h-ca_halo.ascii",
"_halo__bin_0.1",
1053 fprintf(
ioQQQ,
" Creating rauch_h-ca_3d.ascii....\n" );
1054 lgFail = lgFail ||
RauchInitialize(
"rauch_h-ca_3d.ascii",
"_solar_bin_0.1",
1056 lgFail = lgFail ||
RauchInitialize(
"rauch_h-ca_3d.ascii",
"_halo__bin_0.1",
1061 if(
lgFileReadable(
"0050000_50_solar_iron.bin_0.1", dum, as ) &&
1064 fprintf(
ioQQQ,
" Creating rauch_h-ni_solar.ascii....\n" );
1065 lgFail = lgFail ||
RauchInitialize(
"rauch_h-ni_solar.ascii",
"_solar_iron.bin_0.1",
1069 if(
lgFileReadable(
"0050000_50_halo__iron.bin_0.1", dum, as ) &&
1072 fprintf(
ioQQQ,
" Creating rauch_h-ni_halo.ascii....\n" );
1073 lgFail = lgFail ||
RauchInitialize(
"rauch_h-ni_halo.ascii",
"_halo__iron.bin_0.1",
1077 if(
lgFileReadable(
"0050000_50_solar_iron.bin_0.1", dum, as ) &&
1081 fprintf(
ioQQQ,
" Creating rauch_h-ni_3d.ascii....\n" );
1082 lgFail = lgFail ||
RauchInitialize(
"rauch_h-ni_3d.ascii",
"_solar_iron.bin_0.1",
1084 lgFail = lgFail ||
RauchInitialize(
"rauch_h-ni_3d.ascii",
"_halo__iron.bin_0.1",
1089 if(
lgFileReadable(
"0040000_5.00_33_50_02_15.bin_0.1", dum, as ) &&
1092 fprintf(
ioQQQ,
" Creating rauch_pg1159.ascii....\n" );
1093 lgFail = lgFail ||
RauchInitialize(
"rauch_pg1159.ascii",
"_33_50_02_15.bin_0.1",
1098 if(
lgFileReadable(
"0020000_4.00_H_00005-02000A.bin_0.1", dum, as ) &&
1102 lgFail = lgFail ||
RauchInitialize(
"rauch_hydr.ascii",
"_H_00005-02000A.bin_0.1",
1107 if(
lgFileReadable(
"0050000_5.00_He_00005-02000A.bin_0.1", dum, as ) &&
1110 fprintf(
ioQQQ,
" Creating rauch_helium.ascii....\n" );
1111 lgFail = lgFail ||
RauchInitialize(
"rauch_helium.ascii",
"_He_00005-02000A.bin_0.1",
1116 if(
lgFileReadable(
"0050000_5.00_H+He_1.000_0.000_00005-02000A.bin_0.1", dum, as ) &&
1119 fprintf(
ioQQQ,
" Creating rauch_h+he_3d.ascii....\n" );
1120 lgFail = lgFail ||
RauchInitialize(
"rauch_h+he_3d.ascii",
"_H+He_1.000_0.000_00005-02000A.bin_0.1",
1122 lgFail = lgFail ||
RauchInitialize(
"rauch_h+he_3d.ascii",
"_H+He_0.900_0.100_00005-02000A.bin_0.1",
1124 lgFail = lgFail ||
RauchInitialize(
"rauch_h+he_3d.ascii",
"_H+He_0.800_0.200_00005-02000A.bin_0.1",
1126 lgFail = lgFail ||
RauchInitialize(
"rauch_h+he_3d.ascii",
"_H+He_0.700_0.300_00005-02000A.bin_0.1",
1128 lgFail = lgFail ||
RauchInitialize(
"rauch_h+he_3d.ascii",
"_H+He_0.600_0.400_00005-02000A.bin_0.1",
1130 lgFail = lgFail ||
RauchInitialize(
"rauch_h+he_3d.ascii",
"_H+He_0.500_0.500_00005-02000A.bin_0.1",
1132 lgFail = lgFail ||
RauchInitialize(
"rauch_h+he_3d.ascii",
"_H+He_0.400_0.600_00005-02000A.bin_0.1",
1134 lgFail = lgFail ||
RauchInitialize(
"rauch_h+he_3d.ascii",
"_H+He_0.300_0.700_00005-02000A.bin_0.1",
1136 lgFail = lgFail ||
RauchInitialize(
"rauch_h+he_3d.ascii",
"_H+He_0.200_0.800_00005-02000A.bin_0.1",
1138 lgFail = lgFail ||
RauchInitialize(
"rauch_h+he_3d.ascii",
"_H+He_0.100_0.900_00005-02000A.bin_0.1",
1140 lgFail = lgFail ||
RauchInitialize(
"rauch_h+he_3d.ascii",
"_H+He_0.000_1.000_00005-02000A.bin_0.1",
1145 lgFail = lgFail ||
lgCompileAtmosphere(
"rauch_h-ca_solar.ascii",
"rauch_h-ca_solar.mod", NULL,0L, pc );
1147 lgFail = lgFail ||
lgCompileAtmosphere(
"rauch_h-ca_halo.ascii",
"rauch_h-ca_halo.mod", NULL, 0L, pc );
1149 lgFail = lgFail ||
lgCompileAtmosphere(
"rauch_h-ca_3d.ascii",
"rauch_h-ca_3d.mod", NULL, 0L, pc );
1152 lgFail = lgFail ||
lgCompileAtmosphere(
"rauch_h-ni_solar.ascii",
"rauch_h-ni_solar.mod", NULL,0L, pc );
1154 lgFail = lgFail ||
lgCompileAtmosphere(
"rauch_h-ni_halo.ascii",
"rauch_h-ni_halo.mod", NULL, 0L, pc );
1156 lgFail = lgFail ||
lgCompileAtmosphere(
"rauch_h-ni_3d.ascii",
"rauch_h-ni_3d.mod", NULL, 0L, pc );
1159 lgFail = lgFail ||
lgCompileAtmosphere(
"rauch_pg1159.ascii",
"rauch_pg1159.mod", NULL, 0L, pc );
1161 lgFail = lgFail ||
lgCompileAtmosphere(
"rauch_cowd.ascii",
"rauch_cowd.mod", NULL, 0L, pc );
1164 lgFail = lgFail ||
lgCompileAtmosphere(
"rauch_hydr.ascii",
"rauch_hydr.mod", NULL, 0L, pc );
1167 lgFail = lgFail ||
lgCompileAtmosphere(
"rauch_helium.ascii",
"rauch_helium.mod", NULL, 0L, pc );
1170 lgFail = lgFail ||
lgCompileAtmosphere(
"rauch_h+he_3d.ascii",
"rauch_h+he_3d.mod", NULL, 0L, pc );
1187 grid.
name =
"rauch_h-ca_3d.mod";
1189 grid.
name = ( lgHalo ?
"rauch_h-ca_halo.mod" :
"rauch_h-ca_solar.mod" );
1193 grid.
ident =
" H-Ca Rauch";
1195 grid.
command =
"COMPILE STARS";
1199 CheckVal( &grid, val, nval, ndim );
1219 grid.
name =
"rauch_h-ni_3d.mod";
1221 grid.
name = ( lgHalo ?
"rauch_h-ni_halo.mod" :
"rauch_h-ni_solar.mod" );
1225 grid.
ident =
" H-Ni Rauch";
1227 grid.
command =
"COMPILE STARS";
1231 CheckVal( &grid, val, nval, ndim );
1249 grid.
name =
"rauch_pg1159.mod";
1253 grid.
ident =
"PG1159 Rauch";
1255 grid.
command =
"COMPILE STARS";
1259 CheckVal( &grid, val, nval, ndim );
1277 grid.
name =
"rauch_cowd.mod";
1281 grid.
ident =
"C/O WD Rauch";
1283 grid.
command =
"COMPILE STARS";
1287 CheckVal( &grid, val, nval, ndim );
1305 grid.
name =
"rauch_hydr.mod";
1309 grid.
ident =
" Hydr Rauch";
1311 grid.
command =
"COMPILE STARS";
1315 CheckVal( &grid, val, nval, ndim );
1333 grid.
name =
"rauch_helium.mod";
1337 grid.
ident =
"Helium Rauch";
1339 grid.
command =
"COMPILE STARS";
1343 CheckVal( &grid, val, nval, ndim );
1361 grid.
name =
"rauch_h+he_3d.mod";
1365 grid.
ident =
" H+He Rauch";
1367 grid.
command =
"COMPILE STARS";
1371 CheckVal( &grid, val, nval, ndim );
1380 const char chOutName[],
1386 vector<mpp> telg(
MNTS);
1387 vector<double> wavl, fluxes[
MNTS];
1388 wavl.reserve(
NSB99);
1396 bool lgHeader =
true;
1404 double cage, cwavl, cfl, cfl1, cfl2, cfl3;
1405 if( sscanf( chLine,
" %le %le %le %le %le", &cage, &cwavl, &cfl1, &cfl2, &cfl3 ) != 5 )
1407 fprintf(
ioQQQ,
"syntax error in data of Starburst grid.\n" );
1427 fprintf(
ioQQQ,
"too many time steps in Starburst grid.\n" );
1428 fprintf(
ioQQQ,
"please increase MNTS and recompile.\n" );
1436 fluxes[nmods].reserve(
NSB99);
1438 fluxes[nmods].reserve(fluxes[nmods-1].size());
1439 telg[nmods].par[0] = cage;
1442 if( !
fp_equal(telg[nmods].par[0],cage,10) )
1449 wavl.push_back(cwavl);
1452 if( !
fp_equal(wavl[ngp],cwavl,10) )
1454 fprintf(
ioQQQ,
"wavelength error in Starburst grid.\n" );
1461 fluxes[nmods].push_back(
exp10(cfl - 44.077911) );
1467 if( lgHeader && strncmp( &chLine[1],
"TIME [YR]", 9 ) == 0 )
1474 fprintf(
ioQQQ,
"syntax error in header of Starburst grid.\n" );
1484 FILE *ioOut =
open_data( chOutName,
"w" );
1486 vector<string> names;
1487 names.push_back(
"Age" );
1488 WriteASCIIHead(ioOut,
VERSION_ASCII, 1, names, nmods, ngp,
"lambda", 1.,
"F_lambda", 1., telg,
" %.3e", 4);
1490 for(
long i=0; i < nmods; i++ )
1507 bool lgFail =
false;
1514 lgFail = lgFail ||
lgCompileAtmosphere(
"starburst99.ascii",
"starburst99.mod", NULL, 0L, pc );
1517 lgFail = lgFail ||
lgCompileAtmosphere(
"starburst99_2d.ascii",
"starburst99_2d.mod", NULL, 0L, pc );
1530 bool lgFail =
false;
1532 lgFail = lgFail ||
lgCompileAtmosphere(
"obstar_merged_p03.ascii",
"obstar_merged_p03.mod",NULL,0L,pc);
1534 lgFail = lgFail ||
lgCompileAtmosphere(
"obstar_merged_p00.ascii",
"obstar_merged_p00.mod",NULL,0L,pc);
1536 lgFail = lgFail ||
lgCompileAtmosphere(
"obstar_merged_m03.ascii",
"obstar_merged_m03.mod",NULL,0L,pc);
1538 lgFail = lgFail ||
lgCompileAtmosphere(
"obstar_merged_m07.ascii",
"obstar_merged_m07.mod",NULL,0L,pc);
1540 lgFail = lgFail ||
lgCompileAtmosphere(
"obstar_merged_m10.ascii",
"obstar_merged_m10.mod",NULL,0L,pc);
1542 lgFail = lgFail ||
lgCompileAtmosphere(
"obstar_merged_m99.ascii",
"obstar_merged_m99.mod",NULL,0L,pc);
1545 lgFail = lgFail ||
lgCompileAtmosphere(
"obstar_merged_3d.ascii",
"obstar_merged_3d.mod", NULL, 0L, pc);
1548 lgFail = lgFail ||
lgCompileAtmosphere(
"bstar2006_p03.ascii",
"bstar2006_p03.mod", NULL, 0L, pc );
1550 lgFail = lgFail ||
lgCompileAtmosphere(
"bstar2006_p00.ascii",
"bstar2006_p00.mod", NULL, 0L, pc );
1552 lgFail = lgFail ||
lgCompileAtmosphere(
"bstar2006_m03.ascii",
"bstar2006_m03.mod", NULL, 0L, pc );
1554 lgFail = lgFail ||
lgCompileAtmosphere(
"bstar2006_m07.ascii",
"bstar2006_m07.mod", NULL, 0L, pc );
1556 lgFail = lgFail ||
lgCompileAtmosphere(
"bstar2006_m10.ascii",
"bstar2006_m10.mod", NULL, 0L, pc );
1558 lgFail = lgFail ||
lgCompileAtmosphere(
"bstar2006_m99.ascii",
"bstar2006_m99.mod", NULL, 0L, pc );
1561 lgFail = lgFail ||
lgCompileAtmosphere(
"bstar2006_3d.ascii",
"bstar2006_3d.mod", NULL, 0L, pc );
1564 lgFail = lgFail ||
lgCompileAtmosphere(
"ostar2002_p03.ascii",
"ostar2002_p03.mod", NULL, 0L, pc );
1566 lgFail = lgFail ||
lgCompileAtmosphere(
"ostar2002_p00.ascii",
"ostar2002_p00.mod", NULL, 0L, pc );
1568 lgFail = lgFail ||
lgCompileAtmosphere(
"ostar2002_m03.ascii",
"ostar2002_m03.mod", NULL, 0L, pc );
1570 lgFail = lgFail ||
lgCompileAtmosphere(
"ostar2002_m07.ascii",
"ostar2002_m07.mod", NULL, 0L, pc );
1572 lgFail = lgFail ||
lgCompileAtmosphere(
"ostar2002_m10.ascii",
"ostar2002_m10.mod", NULL, 0L, pc );
1574 lgFail = lgFail ||
lgCompileAtmosphere(
"ostar2002_m15.ascii",
"ostar2002_m15.mod", NULL, 0L, pc );
1576 lgFail = lgFail ||
lgCompileAtmosphere(
"ostar2002_m17.ascii",
"ostar2002_m17.mod", NULL, 0L, pc );
1578 lgFail = lgFail ||
lgCompileAtmosphere(
"ostar2002_m20.ascii",
"ostar2002_m20.mod", NULL, 0L, pc );
1580 lgFail = lgFail ||
lgCompileAtmosphere(
"ostar2002_m30.ascii",
"ostar2002_m30.mod", NULL, 0L, pc );
1582 lgFail = lgFail ||
lgCompileAtmosphere(
"ostar2002_m99.ascii",
"ostar2002_m99.mod", NULL, 0L, pc );
1585 lgFail = lgFail ||
lgCompileAtmosphere(
"ostar2002_3d.ascii",
"ostar2002_3d.mod", NULL, 0L, pc );
1594 const char *chMetalicity,
1603 grid.
name =
"obstar_merged_";
1605 grid.
name =
"bstar2006_";
1607 grid.
name =
"ostar2002_";
1613 grid.
name += chMetalicity;
1614 grid.
name +=
".mod";
1621 strcpy( chIdent,
"3-dim" );
1625 strcpy( chIdent,
"Z " );
1626 strcat( chIdent, chMetalicity );
1629 strcat( chIdent,
" OBstar" );
1631 strcat( chIdent,
" Bstr06" );
1633 strcat( chIdent,
" Ostr02" );
1636 grid.
ident = chIdent;
1638 grid.
command =
"COMPILE STARS";
1642 CheckVal( &grid, val, nval, ndim );
1659 realnum Edges[3] = { 0.99946789f, 1.8071406f, 3.9996377f };
1683 bool lgFail =
false;
1706 grid.
name =
"kwerner.mod";
1710 grid.
ident =
"Klaus Werner";
1712 grid.
command =
"COMPILE STARS";
1716 CheckVal( &grid, val, nval, ndim );
1752 realnum Edges[3] = { 0.9994665f, 1.807140f, 3.999632f };
1756 bool lgFail =
false;
1773 grid.
name =
"wmbasic.mod";
1777 grid.
ident =
" WMBASIC";
1779 grid.
command =
"COMPILE STARS";
1783 CheckVal( &grid, val, nval, ndim );
1792 const char chFNameOut[])
1813 fprintf(
ioQQQ,
" CoStarInitialize fails reading nskip.\n" );
1816 sscanf( chLine,
"%li", &nskip );
1819 for(
long i=0; i < nskip; ++i )
1823 fprintf(
ioQQQ,
" CoStarInitialize fails skipping header.\n" );
1832 fprintf(
ioQQQ,
" CoStarInitialize fails reading nModels, nWL.\n" );
1835 sscanf( chLine,
"%li%li", &nModels, &nWL );
1837 if( nModels <= 0 || nWL <= 0 )
1839 fprintf(
ioQQQ,
" CoStarInitialize scanned off impossible values for nModels=%li or nWL=%li\n",
1845 vector<mpp> telg(nModels);
1848 for(
long i=0; i < nModels; ++i )
1852 fprintf(
ioQQQ,
" CoStarInitialize fails reading model parameters.\n" );
1856 telg[i].chGrid = chLine[0];
1858 sscanf( chLine+1,
"%i", &telg[i].modid );
1860 sscanf( chLine+23,
"%lg", &telg[i].par[0] );
1862 sscanf( chLine+31,
"%lg", &telg[i].par[1] );
1864 sscanf( chLine+7,
"%lg", &telg[i].par[2] );
1866 sscanf( chLine+15,
"%lg", &telg[i].par[3] );
1869 ASSERT( telg[i].par[2] > 10. );
1870 ASSERT( telg[i].par[3] > 10. );
1873 telg[i].par[2] = log10(telg[i].par[2]);
1888 vector<string> names;
1889 names.push_back(
"Teff" );
1890 names.push_back(
"log(g)" );
1891 names.push_back(
"log(M)" );
1892 names.push_back(
"Age" );
1893 WriteASCIIHead(ioOUT,
VERSION_COSTAR, 2, names, nModels, nWL-1,
"lambda", 1.,
"F_nu", PI, telg,
" %.6e", 1);
1896 vector<double> StarWavl(nWL);
1897 vector<double> StarFlux(nWL);
1900 for(
long i=0; i < nModels; ++i )
1905 fprintf(
ioQQQ,
" CoStarInitialize fails reading the skip to next spectrum.\n" );
1908 sscanf( chLine,
"%li", &nskip );
1910 for(
long j=0; j < nskip; ++j )
1914 fprintf(
ioQQQ,
" CoStarInitialize fails doing the skip.\n" );
1920 for(
long j=0; j < nWL; ++j )
1924 fprintf(
ioQQQ,
" CoStarInitialize fails reading the spectral data.\n" );
1927 double help1, help2;
1928 sscanf( chLine,
"%lg %lg", &help1, &help2 );
1932 StarWavl[j] = help1;
1936 StarFlux[j] =
exp10(help2);
1940 ASSERT( StarWavl[j] > StarWavl[j-1] );
1968 switch( grid->
imode )
1977 lval[0] = log10(val[0]);
1983 lval[0] = log10(val[1]);
1988 fprintf(
ioQQQ,
" InterpolateGridCoStar called with insane value for imode: %d.\n", grid->
imode );
1992 long nmodid = (long)(lval[1]+0.5);
2018 vector<realnum> ValTr(grid->
nTracks);
2019 vector<long> indloTr(grid->
nTracks);
2020 vector<long> indhiTr(grid->
nTracks);
2021 vector<long> index(2);
2024 for(
long j=0; j < grid->
nTracks; j++ )
2028 if( grid->
trackLen[j] >= nmodid ) {
2029 index[0] = nmodid - 1;
2040 ValTr[j] = -FLT_MAX;
2045 FindHCoStar( grid, j, lval[1], off, ValTr, indloTr, indhiTr );
2051 for(
long j=0; j < grid->
nTracks; j++ )
2053 if( indloTr[j] >= 0 )
2054 printf(
"track %c: models %c%d, %c%d, val %g\n",
2055 (
char)(
'A'+j), grid->
telg[indloTr[j]].chGrid, grid->
telg[indloTr[j]].modid,
2056 grid->
telg[indhiTr[j]].chGrid, grid->
telg[indhiTr[j]].modid, ValTr[j]);
2060 long useTr[2], indlo[2], indhi[2];
2071 fprintf(
ioQQQ,
" The parameters for the requested CoStar model are out of range.\n" );
2077 ASSERT( indloTr[useTr[0]] >= 0 && indloTr[useTr[0]] < (
int)grid->
nmods );
2078 ASSERT( indhiTr[useTr[0]] >= 0 && indhiTr[useTr[0]] < (
int)grid->
nmods );
2079 ASSERT( indloTr[useTr[1]] >= 0 && indloTr[useTr[1]] < (
int)grid->
nmods );
2080 ASSERT( indhiTr[useTr[1]] >= 0 && indhiTr[useTr[1]] < (
int)grid->
nmods );
2083 printf(
"interpolate between tracks %c and %c\n", (
char)(
'A'+useTr[0]), (
char)(
'A'+useTr[1]) );
2085 indlo[0] = indloTr[useTr[0]];
2086 indhi[0] = indhiTr[useTr[0]];
2087 indlo[1] = indloTr[useTr[1]];
2088 indhi[1] = indhiTr[useTr[1]];
2102 fprintf(
ioQQQ,
"Failed to read atmosphere models.\n" );
2106 for(
size_t i=0; i < grid->
index_list2.size(); ++i )
2109 vector<double> aval(4);
2121 FILE *ioBUG =
open_data(
"interpolated.txt",
"w" );
2133 SetLimits( grid, lval[0], dum, dum, useTr, ValTr, val0_lo, val0_hi );
2138 fprintf(
ioQQQ,
" * #<< FINAL: T_eff = %7.1f, ", aval[0] );
2139 fprintf(
ioQQQ,
"log(g) = %4.2f, M(ZAMS) = %5.1f, age = ", aval[1],
exp10(aval[2]) );
2150 vector<realnum>& ValTr,
2151 vector<long>& indloTr,
2152 vector<long>& indhiTr)
2156 indloTr[track] = -2;
2157 indhiTr[track] = -2;
2158 ValTr[track] = -FLT_MAX;
2161 vector<long> index(2);
2164 for(
long j=0; j < grid->
trackLen[track]; j++ )
2170 if( fabs(par2-grid->
telg[mod1].par[off+1]) <= 10.*FLT_EPSILON*fabs(grid->
telg[mod1].par[off+1]) )
2172 indloTr[track] = mod1;
2173 indhiTr[track] = mod1;
2174 ValTr[track] = (
realnum)grid->
telg[mod1].par[off];
2179 for(
long j=0; j < grid->
trackLen[track]-1; j++ )
2187 if( (par2 - grid->
telg[mod1].par[off+1])*(par2 - grid->
telg[mod2].par[off+1]) < 0. )
2191 indloTr[track] = mod1;
2192 indhiTr[track] = mod2;
2193 frac = (par2 - grid->
telg[mod2].par[off+1])/
2194 (grid->
telg[mod1].par[off+1] - grid->
telg[mod2].par[off+1]);
2195 ValTr[track] = (
realnum)(frac*grid->
telg[mod1].par[off] +
2196 (1.-frac)*grid->
telg[mod2].par[off] );
2205 vector<realnum>& ValTr,
2217 for(
long j=0; j < grid->
nTracks; j++ )
2220 if( ValTr[j] != -FLT_MAX && fabs(par1-(
double)ValTr[j]) <= 10.*FLT_EPSILON*fabs(ValTr[j]) )
2231 for(
long j=0; j < grid->
nTracks-1; j++ )
2233 if( ValTr[j] != -FLT_MAX )
2237 for(
long i = j+1; i < grid->
nTracks; i++ )
2239 if( ValTr[i] != -FLT_MAX )
2247 if( j2 > 0 && ((
realnum)par1-ValTr[j])*((
realnum)par1-ValTr[j2]) < 0.f )
2266 for(
long n=0; n < grid->
nTracks; n++ )
2271 for(
long n = 0; n < maxlen; n++ )
2275 for(
long n = 0; n < maxlen; n++ )
2279 vector<long> index(2);
2280 for( index[1]=0; index[1] < grid->
nTracks; ++index[1] )
2283 double Teff, alogg, Mass;
2291 for( index[0]=0; index[0] < grid->
trackLen[index[1]]; ++index[0] )
2294 Teff = grid->
telg[ptr].par[0];
2295 alogg = grid->
telg[ptr].par[1];
2304 const char chSuff[],
2305 const vector<mpp>& telg,
2309 const double par2[],
2315 vector<double> wavl(
NRAUCH);
2316 vector<double> fluxes(
NRAUCH);
2333 long ndim = ( ngrids == 1 ) ? 2 : 3;
2334 vector<string> names;
2335 names.push_back(
"Teff" );
2336 names.push_back(
"log(g)" );
2338 names.push_back(
"log(Z)" );
2339 else if( ngrids == 11 )
2340 names.push_back(
"f(He)" );
2341 else if( ngrids != 1 )
2344 vector<mpp> mytelg(ngrids*telg.size());
2347 for(
long j=0; j < ngrids; j++ )
2348 for(
size_t i=0; i < telg.size(); i++ )
2350 mytelg[k] = telg[i];
2352 mytelg[k].par[2] = par2[j];
2358 "F_lambda", PI*1.e-8, mytelg,
" %.1f", 4);
2361 for(
long i=0; i < nmods; i++ )
2366 sprintf( chLine,
"%7.7ld_%2ld", (
long)(telg[i].par[0]+0.5), (
long)(10.*telg[i].par[1]+0.5) );
2367 else if( format == 2 )
2368 sprintf( chLine,
"%7.7ld_%.2f", (
long)(telg[i].par[0]+0.5), telg[i].par[1] );
2371 string chFileName( chLine );
2372 chFileName += chSuff;
2388 fprintf(
ioQQQ,
" RauchInitialize error in atmosphere file %ld %ld\n", i, j );
2393 while( chLine[0] ==
'*' )
2397 fprintf(
ioQQQ,
" RauchInitialize error in atmosphere file %ld %ld\n", i, j );
2403 for( j=0; j <
NRAUCH; j++ )
2412 fprintf(
ioQQQ,
" RauchInitialize error in atmosphere file %ld %ld\n", i, j );
2418 if( sscanf( chLine,
"%lf %le", &wl, &ttemp ) != 2 )
2420 fprintf(
ioQQQ,
" RauchInitialize error in atmosphere file %ld %ld\n", i, j );
2431 fprintf(
ioQQQ,
" RauchInitialize error in atmosphere file %ld %ld\n", i, j );
2442 if( i == 0 && n == 1 )
2461 const char fnam[] =
"rauch_models.dat";
2468 istringstream iss( line );
2472 fprintf(
ioQQQ,
" RauchReadMPP: the version of %s is not the current version.\n", fnam );
2473 fprintf(
ioQQQ,
" Please obtain the current version from the Cloudy web site.\n" );
2474 fprintf(
ioQQQ,
" I expected to find version %ld and got %ld instead.\n",
2480 unsigned long ndata;
2481 istringstream iss2( line );
2483 ASSERT( ndata == telg1.size() );
2486 getline( ioDATA, line );
2488 for(
unsigned long i=0; i < ndata; ++i )
2489 ioDATA >> telg1[i].par[0] >> telg1[i].par[1];
2490 getline( ioDATA, line );
2493 istringstream iss3( line );
2495 ASSERT( ndata == telg2.size() );
2496 getline( ioDATA, line );
2498 for(
unsigned long i=0; i < ndata; ++i )
2499 ioDATA >> telg2[i].par[0] >> telg2[i].par[1];
2500 getline( ioDATA, line );
2503 istringstream iss4( line );
2505 ASSERT( ndata == telg3.size() );
2506 getline( ioDATA, line );
2508 for(
unsigned long i=0; i < ndata; ++i )
2509 ioDATA >> telg3[i].par[0] >> telg3[i].par[1];
2510 getline( ioDATA, line );
2513 istringstream iss5( line );
2515 ASSERT( ndata == telg4.size() );
2516 getline( ioDATA, line );
2518 for(
unsigned long i=0; i < ndata; ++i )
2519 ioDATA >> telg4[i].par[0] >> telg4[i].par[1];
2520 getline( ioDATA, line );
2523 istringstream iss6( line );
2525 ASSERT( ndata == telg5.size() );
2526 getline( ioDATA, line );
2528 for(
unsigned long i=0; i < ndata; ++i )
2529 ioDATA >> telg5[i].par[0] >> telg5[i].par[1];
2530 getline( ioDATA, line );
2533 istringstream iss7( line );
2535 ASSERT( ndata == telg6.size() );
2536 getline( ioDATA, line );
2538 for(
unsigned long i=0; i < ndata; ++i )
2539 ioDATA >> telg6[i].par[0] >> telg6[i].par[1];
2540 getline( ioDATA, line );
2543 istringstream iss8( line );
2553 getline( ioDATA, line );
2555 while( line[0] ==
'#' );
2561 const vector<string>& names,
2564 const string& wtype,
2566 const string& ftype,
2568 const vector<mpp>& telg,
2574 long npar = (long)names.size();
2577 ASSERT( wtype ==
"lambda" || wtype ==
"nu" );
2578 ASSERT( ftype ==
"F_lambda" || ftype ==
"F_nu" ||
2579 ftype ==
"H_lambda" || ftype ==
"H_nu" );
2582 fprintf( ioOut,
" %ld\n", version );
2583 fprintf( ioOut,
" %ld\n", ndim );
2584 fprintf( ioOut,
" %ld\n", npar );
2585 for(
long i=0; i < npar; ++i )
2586 fprintf( ioOut,
" %s\n", names[i].c_str() );
2587 fprintf( ioOut,
" %ld\n", nmods );
2588 fprintf( ioOut,
" %ld\n", ngrid );
2589 fprintf( ioOut,
" %s\n", wtype.c_str() );
2590 fprintf( ioOut,
" %.8e\n", wfac );
2591 fprintf( ioOut,
" %s\n", ftype.c_str() );
2592 fprintf( ioOut,
" %.8e\n", ffac );
2595 for( i=0; i < nmods; i++ )
2598 for(
long j=0; j < npar; ++j )
2599 fprintf( ioOut, format, telg[i].par[j] );
2601 fprintf( ioOut,
" %c%d", telg[i].chGrid, telg[i].modid );
2602 if( ((i+1)%nmult) == 0 )
2605 if( (i%nmult) != 0 )
2610 const vector<double>& data,
2618 for( i=0; i < ngrid; i++ )
2620 fprintf( ioOut, format, data[i] );
2621 if( ((i+1)%nmult) == 0 )
2624 if( (i%nmult) != 0 )
2638 fprintf(
ioQQQ,
" ReadAtmosphere fails reading line.\n" );
2642 while( chLine[0] ==
'#' );
2646 if( sscanf( chLine,
"%ld", &version ) != 1 )
2648 fprintf(
ioQQQ,
" ReadAtmosphere failed reading VERSION.\n" );
2654 fprintf(
ioQQQ,
" ReadAtmosphere: there is a version number mismatch in"
2655 " the ascii atmosphere file: %s.\n", grid->
name.c_str() );
2656 fprintf(
ioQQQ,
" ReadAtmosphere: Please recreate this file or download the"
2657 " latest version following the instructions on the Cloudy website.\n" );
2664 fprintf(
ioQQQ,
" ReadAtmosphere failed reading valid dimension of grid.\n" );
2669 if( fscanf( grid->
ioIN,
"%d", &grid->
npar ) != 1 || grid->
npar <= 0 ||
2672 fprintf(
ioQQQ,
" ReadAtmosphere failed reading valid no. of model parameters.\n" );
2676 for(
long nd=0; nd < grid->
npar; nd++ )
2678 if( fscanf( grid->
ioIN,
"%6s", grid->
names[nd] ) != 1 )
2680 fprintf(
ioQQQ,
" ReadAtmosphere failed reading parameter label.\n" );
2686 if( fscanf( grid->
ioIN,
"%d", &grid->
nmods ) != 1 || grid->
nmods <= 0 )
2688 fprintf(
ioQQQ,
" ReadAtmosphere failed reading valid number of models.\n" );
2692 if( fscanf( grid->
ioIN,
"%d", &grid->
ngrid ) != 1 || grid->
ngrid <= 1 )
2694 fprintf(
ioQQQ,
" ReadAtmosphere failed reading valid number of grid points.\n" );
2698 char chDataType[11];
2700 if( fscanf( grid->
ioIN,
"%10s", chDataType ) != 1 )
2702 fprintf(
ioQQQ,
" ReadAtmosphere failed reading wavl DataType string.\n" );
2706 if( strcmp( chDataType,
"lambda" ) == 0 )
2708 else if( strcmp( chDataType,
"nu" ) == 0 )
2711 fprintf(
ioQQQ,
" ReadAtmosphere found illegal wavl DataType: %s.\n", chDataType );
2717 fprintf(
ioQQQ,
" ReadAtmosphere failed reading valid wavl conversion factor.\n" );
2722 if( fscanf( grid->
ioIN,
"%10s", chDataType ) != 1 )
2724 fprintf(
ioQQQ,
" ReadAtmosphere failed reading flux DataType string.\n" );
2728 if( strcmp( chDataType,
"F_lambda" ) == 0 || strcmp( chDataType,
"H_lambda" ) == 0 )
2730 else if( strcmp( chDataType,
"F_nu" ) == 0 || strcmp( chDataType,
"H_nu" ) == 0 )
2733 fprintf(
ioQQQ,
" ReadAtmosphere found illegal flux DataType: %s.\n", chDataType );
2739 fprintf(
ioQQQ,
" ReadAtmosphere failed reading valid flux conversion factor.\n" );
2745 for(
long i=0; i < grid->
nmods; i++ )
2747 for(
long nd=0; nd < grid->
npar; nd++ )
2749 if( fscanf( grid->
ioIN,
"%le", &grid->
telg[i].par[nd] ) != 1 )
2751 fprintf(
ioQQQ,
" ReadAtmosphere failed reading valid model parameter.\n" );
2757 if( fscanf( grid->
ioIN,
" %c%d", &grid->
telg[i].chGrid, &grid->
telg[i].modid ) != 2 )
2759 fprintf(
ioQQQ,
" ReadAtmosphere failed reading valid track ID.\n" );
2770 const vector<long>& index_list)
2775 vector<realnum> StarEner(grid->
ngrid);
2776 vector<realnum> scratch(grid->
ngrid);
2777 vector<realnum> StarFlux(grid->
ngrid);
2780 for(
long i=0; i < grid->
ngrid; i++ )
2783 if( fscanf( grid->
ioIN,
"%lg", &help ) != 1 )
2785 fprintf(
ioQQQ,
" ReadAtmosphere failed reading wavelength.\n" );
2792 if( scratch[i] <= 0.f )
2794 fprintf(
ioQQQ,
" PROBLEM: a non-positive %s was found, value: %e\n",
2795 grid->
lgFreqX ?
"frequency" :
"wavelength", scratch[i] );
2800 bool lgFlip = ( !grid->
lgFreqX && scratch[0] < scratch[1] ) || ( grid->
lgFreqX && scratch[0] > scratch[1] );
2803 for(
long i=0; i < grid->
ngrid; i++ )
2807 scratch[i] /= (
realnum)FR1RYD;
2809 scratch[i] = (
realnum)(RYDLAM/scratch[i]);
2812 StarEner[grid->
ngrid-i-1] = scratch[i];
2814 StarEner[i] = scratch[i];
2817 ASSERT( StarEner[0] > 0.f );
2819 for(
long i=1; i < grid->
ngrid; i++ )
2821 if( StarEner[i] <= StarEner[i-1] )
2823 fprintf(
ioQQQ,
" PROBLEM: the %s grid is not strictly monotonically increasing/decreasing\n",
2824 grid->
lgFreqX ?
"frequency" :
"wavelength" );
2830 size_t ni_end = ( index_list.size() == 0 ) ? grid->
nmods : index_list.size();
2832 for(
long imod=0; imod < grid->
nmods; imod++ )
2837 for(
long i=0; i < grid->
ngrid; i++ )
2840 if( fscanf( grid->
ioIN,
"%lg", &help ) != 1 )
2842 fprintf(
ioQQQ,
" ReadAtmosphere failed reading star flux.\n" );
2850 if( scratch[i] < 0.f )
2852 fprintf(
ioQQQ,
"\n PROBLEM: a negative flux was found, model number %ld, value: %e\n",
2858 for(
long i=0; i < grid->
ngrid; i++ )
2861 StarFlux[grid->
ngrid-i-1] = scratch[i];
2863 StarFlux[i] = scratch[i];
2866 for(
long i=0; i < grid->
ngrid; i++ )
2870 StarFlux[i] *= CONVERT_FNU/
POW2(StarEner[i]);
2871 ASSERT( StarFlux[i] >= 0.f );
2880 if( index_list.size() == 0 || imod == index_list[ni] )
2903 const char chFNameOut[],
2912 grid.
name = chFNameIn;
2921 fprintf(
ioQQQ,
" lgCompileAtmosphere got %s.\n", chFNameIn );
2942 val[1] = (int32)
MDIM;
2943 val[2] = (int32)
MNAM;
2944 val[3] = (int32)grid.
ndim;
2945 val[4] = (int32)grid.
npar;
2946 val[5] = (int32)grid.
nmods;
2948 uval[0] =
sizeof(val) +
sizeof(uval) +
sizeof(dval) +
sizeof(md5sum) +
2955 for(
unsigned int i=0; i <
NMD5; i++ )
2962 if( fwrite( val,
sizeof(val), 1, ioOUT ) != 1 ||
2963 fwrite( uval,
sizeof(uval), 1, ioOUT ) != 1 ||
2965 fwrite( dval,
sizeof(dval), 1, ioOUT ) != 1 ||
2967 fwrite( md5sum,
sizeof(md5sum), 1, ioOUT ) != 1 ||
2968 fwrite( grid.
names,
sizeof(grid.
names), 1, ioOUT ) != 1 ||
2972 fwrite(
get_ptr(SaveAnu), (
size_t)uval[1], 1, ioOUT ) != 1 )
2974 fprintf(
ioQQQ,
" lgCompileAtmosphere failed writing header of output file.\n" );
2983 for(
long imod=0; imod < grid.
nmods; imod++ )
2986 if( fwrite( &grid.
CloudyFlux[imod][0], (
size_t)uval[1], 1, ioOUT ) != 1 )
2988 fprintf(
ioQQQ,
" lgCompileAtmosphere failed writing star flux.\n" );
2995 fprintf(
ioQQQ,
" lgCompileAtmosphere completed ok.\n\n" );
3010 const char* mode = lgASCII ?
"r" :
"rb";
3017 const char* compilemsg = lgASCII ?
"" :
" and compiled with the COMPILE STARS command";
3018 fprintf(
ioQQQ,
" Error: stellar atmosphere file not found.\n" );
3019 fprintf(
ioQQQ,
"\n\n If the path is set then it is possible that the stellar"
3020 " atmosphere data files do not exist.\n");
3021 fprintf(
ioQQQ,
" Have the stellar data files been downloaded%s?\n", compilemsg );
3022 fprintf(
ioQQQ,
" If you are simply running the test suite and do not need the"
3023 " stellar continua then you should simply ignore this failure\n");
3036 strcmp( grid->
names[0],
"Teff" ) == 0 &&
3037 strcmp( grid->
names[1],
"log(g)" ) == 0 );
3052 fprintf(
ioQQQ,
" InitGrid failed reading header.\n" );
3062 int32 version, mdim, mnam;
3063 double mesh_elo, mesh_ehi;
3066 if( fread( &version,
sizeof(version), 1, grid->
ioIN ) != 1 ||
3067 fread( &mdim,
sizeof(mdim), 1, grid->
ioIN ) != 1 ||
3068 fread( &mnam,
sizeof(mnam), 1, grid->
ioIN ) != 1 ||
3069 fread( &grid->
ndim,
sizeof(grid->
ndim), 1, grid->
ioIN ) != 1 ||
3070 fread( &grid->
npar,
sizeof(grid->
npar), 1, grid->
ioIN ) != 1 ||
3071 fread( &grid->
nmods,
sizeof(grid->
nmods), 1, grid->
ioIN ) != 1 ||
3072 fread( &grid->
ngrid,
sizeof(grid->
ngrid), 1, grid->
ioIN ) != 1 ||
3075 fread( &mesh_elo,
sizeof(mesh_elo), 1, grid->
ioIN ) != 1 ||
3076 fread( &mesh_ehi,
sizeof(mesh_ehi), 1, grid->
ioIN ) != 1 ||
3078 fread( md5sum,
sizeof(md5sum), 1, grid->
ioIN ) != 1 )
3080 fprintf(
ioQQQ,
" InitGrid failed reading header.\n" );
3087 fprintf(
ioQQQ,
" InitGrid: there is a version mismatch between"
3088 " the compiled atmospheres file I expected and the one I found.\n" );
3089 fprintf(
ioQQQ,
" InitGrid: Please recompile the stellar"
3090 " atmospheres file with the command: %s.\n", grid->
command.c_str() );
3096 fprintf(
ioQQQ,
" InitGrid: the compiled atmospheres file is produced"
3097 " with an incompatible version of Cloudy.\n" );
3098 fprintf(
ioQQQ,
" InitGrid: Please recompile the stellar"
3099 " atmospheres file with the command: %s.\n", grid->
command.c_str() );
3108 fprintf(
ioQQQ,
" InitGrid: the compiled atmospheres file is produced"
3109 " with an incompatible frequency grid.\n" );
3110 fprintf(
ioQQQ,
" InitGrid: Please recompile the stellar"
3111 " atmospheres file with the command: %s.\n", grid->
command.c_str() );
3122 if( fread( &grid->
names,
sizeof(grid->
names), 1, grid->
ioIN ) != 1 )
3124 fprintf(
ioQQQ,
" InitGrid failed reading names array.\n" );
3132 fprintf(
ioQQQ,
" InitGrid failed reading model parameter block.\n" );
3140 int res = fseek( grid->
ioIN, 0, SEEK_END );
3143 long End = ftell( grid->
ioIN );
3145 if( End != Expected )
3147 fprintf(
ioQQQ,
" InitGrid: Problem performing sanity check for size of binary file.\n" );
3148 fprintf(
ioQQQ,
" InitGrid: I expected to find %ld bytes, but actually found %ld bytes.\n",
3150 fprintf(
ioQQQ,
" InitGrid: Please recompile the stellar"
3151 " atmospheres file with the command: %s.\n", grid->
command.c_str() );
3171 grid.
name = binName;
3176 int32 version, mdim, mnam;
3177 double mesh_elo, mesh_ehi, mesh_res_factor;
3179 if( fread( &version,
sizeof(version), 1, grid.
ioIN ) != 1 ||
3180 fread( &mdim,
sizeof(mdim), 1, grid.
ioIN ) != 1 ||
3181 fread( &mnam,
sizeof(mnam), 1, grid.
ioIN ) != 1 ||
3182 fread( &grid.
ndim,
sizeof(grid.
ndim), 1, grid.
ioIN ) != 1 ||
3183 fread( &grid.
npar,
sizeof(grid.
npar), 1, grid.
ioIN ) != 1 ||
3188 fread( &mesh_elo,
sizeof(mesh_elo), 1, grid.
ioIN ) != 1 ||
3189 fread( &mesh_ehi,
sizeof(mesh_ehi), 1, grid.
ioIN ) != 1 ||
3190 fread( &mesh_res_factor,
sizeof(mesh_res_factor), 1, grid.
ioIN ) != 1 ||
3191 fread( md5sum,
sizeof(md5sum), 1, grid.
ioIN ) != 1 )
3218 int res = fseek( grid.
ioIN, 0, SEEK_END );
3221 long End = ftell( grid.
ioIN );
3223 if( End != Expected )
3242 if( !ioIN.is_open() )
3247 while( getline( ioIN, chLine ) )
3249 if( chLine[0] !=
'#' )
3257 if( sscanf( chLine.c_str(),
"%ld", &version ) != 1 ||
3281 vector<long> index(2);
3287 char track = (char)(
'A'+index[1]);
3291 for(
long i=0; i < grid->
nmods; i++ )
3293 if( grid->
telg[i].chGrid == track && grid->
telg[i].modid == index[0]+1 )
3307 grid->
trackLen[index[1]] = index[0];
3322 *ndim = (long)grid->
ndim;
3326 val[*nval] = grid->
val[1][grid->
nval[1]-1];
3329 if( *ndim != (
long)grid->
ndim )
3331 fprintf(
ioQQQ,
" A %ld-dim grid was requested, but a %ld-dim grid was found.\n",
3332 *ndim, (
long)grid->
ndim );
3337 fprintf(
ioQQQ,
" A %ld-dim grid was requested, but only %ld parameters were entered.\n",
3354 vector<long> indlo(grid->
ndim);
3355 vector<long> indhi(grid->
ndim);
3356 vector<long> index(grid->
ndim);
3357 vector<double> aval(grid->
npar);
3385 for(
long nd=0; nd < grid->
ndim; nd++ )
3388 FindIndex( grid->
val, nd, grid->
nval[nd], val[nd], &indlo[nd], &indhi[nd], &lgInvalid );
3392 " Requested parameter %s = %.2f is not within the range %.2f to %.2f\n",
3393 grid->
names[nd], val[nd], grid->
val[nd][0], grid->
val[nd][grid->
nval[nd]-1] );
3399 lgTakeLog, Edges, nEdges );
3404 if( grid->
npar == 1 )
3406 " * #<< FINAL: %6s = %13.2f"
3408 grid->
names[0], aval[0] );
3409 else if( grid->
npar == 2 )
3411 " * #<< FINAL: %6s = %10.2f"
3412 " %6s = %8.5f >>> *\n",
3413 grid->
names[0], aval[0], grid->
names[1], aval[1] );
3414 else if( grid->
npar == 3 )
3416 " * #<< FINAL: %6s = %7.0f"
3417 " %6s = %5.2f %6s = %5.2f >>> *\n",
3418 grid->
names[0], aval[0], grid->
names[1], aval[1],
3419 grid->
names[2], aval[2] );
3420 else if( grid->
npar >= 4 )
3423 " * #<< FINAL: %4s = %7.0f"
3424 " %6s = %4.2f %6s = %5.2f %6s = ",
3425 grid->
names[0], aval[0], grid->
names[1], aval[1],
3442 FILE *ioBUG =
open_data(
"interpolated.txt",
"w" );
3448 if( strcmp( grid->
names[0],
"Teff" ) == 0 )
3455 vector<realnum> dum;
3456 SetLimits( grid, val[0], indlo, indhi, NULL, dum, Tlow, Thigh );
3461 vector<double>& aval,
3462 const vector<long>& indlo,
3463 const vector<long>& indhi,
3464 vector<long>& index,
3466 vector<realnum>& flux1,
3477 for( map<string,int>::const_iterator p=grid->
caution.begin(); p != grid->
caution.end(); ++p )
3487 fprintf(
ioQQQ,
"Failed to read atmosphere models.\n" );
3491 for(
size_t i=0; i < grid->
index_list2.size(); ++i )
3500 vector<double>& aval,
3501 const vector<long>& indlo,
3502 const vector<long>& indhi,
3503 vector<long>& index,
3505 vector<realnum>& flux1,
3514 long ind, n =
JIndex(grid,index);
3516 ind = ( grid->
jlo[n] >= 0 ) ? grid->
jlo[n] : grid->
jhi[n];
3518 ind = ( grid->
jhi[n] >= 0 ) ? grid->
jhi[n] : grid->
jlo[n];
3519 else if( grid->
ndim == 1 )
3527 fprintf(
ioQQQ,
" The requested interpolation could not be completed, sorry.\n" );
3528 fprintf(
ioQQQ,
" No suitable match was found for a model with" );
3529 for(
long i=0; i < grid->
ndim; i++ )
3535 for(
long i=0; i < grid->
npar; i++ )
3536 aval[i] = grid->
telg[ind].par[i];
3542 if( !
fp_equal(grid->
val[i][index[i]],aval[i],10) )
3545 oss <<
" No exact match was found for a model with";
3546 for(
long j=0; j < grid->
ndim; j++ )
3547 oss <<
" " << grid->
names[j] <<
"=" << grid->
val[j][index[j]] <<
" ";
3548 oss <<
"- using model " << ind+1 <<
" instead.";
3560 while( i < grid->index_list2.size() && grid->
index_list2[i] != ind )
3572 # if !defined NDEBUG
3573 const realnum SECURE = 10.f*FLT_EPSILON;
3582 index[nd] = indlo[nd];
3583 int next_stage = ( nd == 1 ) ? stage|
IS_FIRST : stage;
3584 InterpolateModel( grid, val, aval, indlo, indhi, index, nd, flux1, next_stage );
3587 vector<double> aval2(grid->
npar);
3589 index[nd] = indhi[nd];
3590 next_stage = ( nd == 1 ) ? stage|
IS_SECOND : stage;
3591 InterpolateModel( grid, val, aval2, indlo, indhi, index, nd, flux2, next_stage );
3595 double fr1 = (aval2[nd]-val[nd])/(aval2[nd]-aval[nd]);
3601 double fr2 = 1. - fr1;
3603 ASSERT( 0.-SECURE <= fr1 && fr1 <= 1.+SECURE );
3606 fprintf(
ioQQQ,
"interpolation nd=%ld fr1=%g\n", nd, fr1 );
3609 double fc1 = 0.,
fc2 = 0.;
3610 if( nd == 0 && strcmp( grid->
names[nd],
"Teff" ) == 0 )
3622 fc1 = ( val[nd] > 200000. ) ? log10(val[nd]/grid->
val[nd][indlo[nd]])*4. : 0.;
3623 fc2 = ( val[nd] > 200000. ) ? log10(val[nd]/grid->
val[nd][indhi[nd]])*4. : 0.;
3627 flux1[i] = (
realnum)(fr1*(flux1[i]+fc1) + fr2*(flux2[i]+
fc2));
3629 for(
long i=0; i < grid->
npar; i++ )
3630 aval[i] = fr1*aval[i] + fr2*aval2[i];
3637 vector<double>& aval,
3640 vector<long>& index,
3643 vector<realnum>& flux1)
3649 long ind = ( index[1] == 0 ) ? indlo[index[0]] : indhi[index[0]];
3652 while( i < grid->index_list2.size() && grid->
index_list2[i] != ind )
3659 for(
long j=0; j < grid->npar; j++ )
3660 aval[j] = grid->
telg[ind].par[j];
3664 # if !defined NDEBUG
3665 const realnum SECURE = 10.f*FLT_EPSILON;
3676 bool lgSkip = ( nd == 1 ) ? ( indhi[index[0]] == indlo[index[0]] ) :
3677 ( indlo[0] == indlo[1] && indhi[0] == indhi[1] );
3682 vector<double> aval2(grid->
npar);
3687 double fr1 = (aval2[nd+off]-val[nd])/(aval2[nd+off]-aval[nd+off]);
3688 double fr2 = 1. - fr1;
3691 fprintf(
ioQQQ,
"interpolation nd=%ld fr1=%g\n", nd, fr1 );
3693 ASSERT( 0.-SECURE <= fr1 && fr1 <= 1.+SECURE );
3696 flux1[i] = (
realnum)(fr1*flux1[i] + fr2*flux2[i]);
3698 for(
long i=0; i < grid->
npar; i++ )
3699 aval[i] = fr1*aval[i] + fr2*aval2[i];
3711 sort( in.begin(), in.end() );
3714 out.push_back( lastval );
3715 for(
size_t i=1; i < in.size(); ++i )
3716 if( in[i] != lastval )
3719 out.push_back( lastval );
3724 vector<Energy>& ener)
3732 if( fseek( grid->
ioIN, (
long)(grid->
nOffset), SEEK_SET ) != 0 )
3734 fprintf(
ioQQQ,
" Error finding atmosphere frequency bins\n");
3741 fprintf(
ioQQQ,
" Error reading atmosphere frequency bins\n" );
3749 ener[i].set(data[i]);
3766 ASSERT( ind >= 0 && ind <= grid->nmods );
3774 fprintf(
ioQQQ,
" Error seeking atmosphere %ld\n", ind );
3780 fprintf(
ioQQQ,
" Error trying to read atmosphere %ld\n", ind );
3789 if( grid->
npar == 1 )
3791 " * #<< %s model%5ld read. "
3792 " %6s = %13.2f >>> *\n",
3793 grid->
ident.c_str(), ind, grid->
names[0], grid->
telg[ind-1].par[0] );
3794 else if( grid->
npar == 2 )
3796 " * #<< %s model%5ld read. "
3797 " %6s = %10.2f %6s = %8.5f >>> *\n",
3798 grid->
ident.c_str(), ind, grid->
names[0], grid->
telg[ind-1].par[0],
3799 grid->
names[1], grid->
telg[ind-1].par[1] );
3800 else if( grid->
npar == 3 )
3802 " * #<< %s model%5ld read. "
3803 " %6s=%7.0f %6s=%5.2f %6s=%5.2f >>> *\n",
3804 grid->
ident.c_str(), ind, grid->
names[0], grid->
telg[ind-1].par[0],
3805 grid->
names[1], grid->
telg[ind-1].par[1],
3806 grid->
names[2], grid->
telg[ind-1].par[2] );
3807 else if( grid->
npar >= 4 )
3811 " %4s=%5.0f %6s=%4.2f %6s=%5.2f %6s=",
3812 grid->
ident.c_str(), ind, grid->
names[0], grid->
telg[ind-1].par[0],
3813 grid->
names[1], grid->
telg[ind-1].par[1],
3828 volatile double help = flux[i];
3840 const vector<long>& indlo,
3841 const vector<long>& indhi,
3843 const vector<realnum>& ValTr,
3851 const double SECURE = (1. + 20.*(double)FLT_EPSILON);
3854 vector<long> index(
MDIM);
3858 switch( grid->
imode )
3868 for(
long j=0; j < grid->
nTracks; j++ )
3870 if( ValTr[j] != -FLT_MAX )
3874 exp10((
double)ValTr[j]) : ValTr[j];
3875 *loLim =
MIN2(*loLim,temp);
3876 *hiLim =
MAX2(*hiLim,temp);
3882 index[1] = useTr[0];
3884 index[1] = useTr[1];
3886 *loLim =
MAX2(grid->
telg[ptr0].par[3],grid->
telg[ptr1].par[3]);
3889 printf(
"set limit 0: (models %d, %d) %f %f\n",
3890 ptr0+1, ptr1+1, grid->
telg[ptr0].par[3], grid->
telg[ptr1].par[3] );
3892 index[0] = grid->
trackLen[useTr[0]]-1;
3893 index[1] = useTr[0];
3895 index[0] = grid->
trackLen[useTr[1]]-1;
3896 index[1] = useTr[1];
3898 *hiLim =
MIN2(grid->
telg[ptr0].par[3],grid->
telg[ptr1].par[3]);
3901 printf(
"set limit 1: (models %d, %d) %f %f\n",
3902 ptr0+1, ptr1+1, grid->
telg[ptr0].par[3], grid->
telg[ptr1].par[3] );
3906 fprintf(
ioQQQ,
" SetLimits called with insane value for imode: %d.\n", grid->
imode );
3910 ASSERT( fabs(*loLim) < DBL_MAX && fabs(*hiLim) < DBL_MAX );
3913 if( *hiLim <= *loLim )
3915 fprintf(
ioQQQ,
" no room to optimize: lower limit %.4f, upper limit %.4f.\n",
3925 printf(
"set limits: %g %g\n",*loLim,*hiLim);
3936 const vector<long>& indlo,
3937 const vector<long>& indhi,
3938 vector<long>& index,
3949 double loLoc = +DBL_MAX;
3950 double hiLoc = -DBL_MAX;
3952 for( index[0]=0; index[0] < grid->
nval[0]; ++index[0] )
3960 long n =
JIndex(grid,index);
3961 if( grid->
jlo[n] < 0 && grid->
jhi[n] < 0 )
3965 if( grid->
val[0][index[0]] < val )
3968 if( grid->
val[0][index[0]] > val )
3975 if( grid->
val[0][index[0]] <= val )
3979 if( loLoc == DBL_MAX )
3980 loLoc = grid->
val[0][index[0]];
3982 if( grid->
val[0][index[0]] >= val )
3986 hiLoc = grid->
val[0][index[0]];
3991 ASSERT( fabs(loLoc) < DBL_MAX && fabs(hiLoc) < DBL_MAX && loLoc <= hiLoc );
3993 *loLim =
MAX2(*loLim,loLoc);
3994 *hiLim =
MIN2(*hiLim,hiLoc);
3998 index[nd] = indlo[nd];
3999 SetLimitsSub( grid, val, indlo, indhi, index, nd, loLim, hiLim );
4001 if( indhi[nd] != indlo[nd] )
4003 index[nd] = indhi[nd];
4004 SetLimitsSub( grid, val, indlo, indhi, index, nd, loLim, hiLim );
4020 for(
long nd=0; nd < grid->
ndim; nd++ )
4022 double pval = grid->
telg[0].par[nd];
4023 grid->
val[nd][0] = pval;
4026 for(
long i=1; i < grid->
nmods; i++ )
4031 pval = grid->
telg[i].par[nd];
4041 for(
long j = grid->
nval[nd]-1; j >= i2; j-- )
4042 grid->
val[nd][j+1] = grid->
val[nd][j];
4043 grid->
val[nd][i2] = pval;
4048 jsize *= grid->
nval[nd];
4052 printf(
"%s[%ld]:", grid->
names[nd], grid->
nval[nd] );
4053 for(
long i=0; i < grid->
nval[nd]; i++ )
4054 printf(
" %g", grid->
val[nd][i] );
4059 vector<long> index(grid->
ndim);
4060 vector<double> val(grid->
ndim);
4062 grid->
jlo.resize(jsize);
4063 grid->
jhi.resize(jsize);
4067 FillJ( grid, index, val, grid->
ndim, lgList );
4074 vector<long>& index,
4075 vector<double>& val,
4085 long n =
JIndex(grid,index);
4087 &grid->
jlo[n], &grid->
jhi[n] );
4091 for( index[nd]=0; index[nd] < grid->
nval[nd]; index[nd]++ )
4093 val[nd] = grid->
val[nd][index[nd]];
4094 FillJ( grid, index, val, nd, lgList );
4098 if( lgList && nd ==
MIN2(grid->
ndim-1,1) )
4101 if( grid->
ndim > 2 )
4104 for(
long n = nd+1; n < grid->
ndim; n++ )
4108 if( grid->
ndim > 1 )
4111 for(
long n = 0; n < grid->
nval[1]; n++ )
4115 for(
long n = 0; n < grid->
nval[1]; n++ )
4124 for( index[0]=0; index[0] < grid->
nval[0]; index[0]++ )
4127 if( grid->
ndim > 1 )
4129 for( index[1]=0; index[1] < grid->
nval[1]; index[1]++ )
4147 const vector<long>& index)
4153 for(
long i=0; i < grid->
ndim; i++ )
4155 ind += index[i]*mul;
4156 mul *= grid->
nval[i];
4162 bool lgIsTeffLoggGrid,
4164 const vector<double>& val,
4185 *index_low = *index_high = -2;
4186 double alogg_low = -DBL_MAX, alogg_high = DBL_MAX;
4187 for(
long i=0; i < nmods; i++ )
4189 bool lgNext =
false;
4191 for(
long nd=0; nd < ndim; nd++ )
4193 if( nd != 1 && !
fp_equal(telg[i].par[nd],val[nd],10) )
4203 if( ndim == 1 ||
fp_equal(telg[i].par[1],val[1],10) )
4209 if( lgIsTeffLoggGrid )
4212 if( telg[i].par[1] < val[1] && telg[i].par[1] > alogg_low )
4215 alogg_low = telg[i].par[1];
4218 if( telg[i].par[1] > val[1] && telg[i].par[1] < alogg_high )
4221 alogg_high = telg[i].par[1];
4252 bool lgOutLo = ( x-xval[nd][0] < -10.*DBL_EPSILON*fabs(xval[nd][0]) );
4253 bool lgOutHi = ( x-xval[nd][NVAL-1] > 10.*DBL_EPSILON*fabs(xval[nd][NVAL-1]) );
4255 if( lgOutLo || lgOutHi )
4261 *ind1 = lgOutLo ? -1 : NVAL-1;
4262 *ind2 = lgOutLo ? 0 : NVAL;
4274 for(
long i=0; i < NVAL; i++ )
4285 for(
long i=0; i < NVAL-1; i++ )
4287 if( xval[nd][i] < x && x < xval[nd][i+1] )
4303 string fname = chFnam;
4304 bool lgASCIIfile = ( fname.substr(
max(fname.length(),6)-6) ==
".ascii" );
4305 FILE *ioIN =
open_data( chFnam,
"r", scheme );
4321 const vector<Energy>& anu)
4327 fprintf(
ioQQQ,
" ValidateMesh: the compiled atmospheres file is produced"
4328 " with an incompatible version of Cloudy.\n" );
4329 fprintf(
ioQQQ,
" ValidateMesh: Please recompile the stellar"
4330 " atmospheres file with the command: %s.\n", grid->
command.c_str() );
4356 if( strcmp( grid->
names[0],
"Teff" ) != 0 )
4364 for(
long i=0; i < grid->
nmods; i++ )
4367 for(
long nd=0; nd < grid->
npar; nd++ )
4378 const vector<realnum>& flux,
4389 lumi += (anu[k].Ryd() - anu[k-1].Ryd())*(flux[k] + flux[k-1])/2.;
4392 double chk =
powpq(lumi*FR1RYD/STEFAN_BOLTZ,1,4);
4394 bool lgPassed =
true;
4395 if( fabs(Teff - chk) > toler*Teff ) {
4396 fprintf(
ioQQQ,
"\n*** WARNING, Teff discrepancy for this model, expected Teff %.2f, ", Teff);
4397 fprintf(
ioQQQ,
"integration yielded Teff %.2f, delta %.2f%%\n", chk, (chk/Teff-1.)*100. );
4405 const vector<realnum>& StarFlux,
4414 for(
long j=nCont-1; j >= 0; j-- )
4416 if( StarFlux[j] > 0.f )
4424 vector<long> EdgeInd;
4425 vector<realnum> EdgeLow, EdgeHigh;
4426 for(
long j=0; j < nEdges; j++ )
4430 if( ind >= 1 && ind+2 < nCont )
4432 EdgeInd.push_back( ind );
4433 EdgeLow.push_back( StarEner[ind] );
4434 EdgeHigh.push_back( StarEner[ind+1] );
4438 EdgeInd.push_back( -1 );
4439 EdgeLow.push_back( 0. );
4440 EdgeHigh.push_back( 0. );
4444 vector<realnum> StarPower(nCont-1);
4446 for(
long j=0; j < nCont-1; j++ )
4449 ASSERT( StarEner[j+1] > StarEner[j] );
4453 double ratio_x = (double)StarEner[j+1]/(
double)StarEner[j];
4454 if( StarFlux[j] == 0.f )
4455 StarPower[j] = FLT_MAX;
4456 else if( StarFlux[j+1] == 0.f )
4457 StarPower[j] = -FLT_MAX;
4460 double ratio_y = (double)StarFlux[j+1]/(
double)StarFlux[j];
4461 StarPower[j] = (
realnum)(log(ratio_y)/log(ratio_x));
4470 bool lgDone =
false;
4471 for(
long k=0; k < nEdges; k++ )
4477 ipLo = EdgeInd[k]-1;
4479 ipLo = EdgeInd[k]+1;
4481 if( fabs(StarPower[ipLo]) < fabs(StarPower[EdgeInd[k]]) &&
4482 fabs(StarPower[ipLo]) != FLT_MAX )
4484 CloudyFlux[j] = StarFlux[ipLo]*
4485 pow(
rfield.
anu(j)/StarEner[ipLo],(double)StarPower[ipLo]);
4501 const vector<realnum>& StarPower,
4510 double widflx =
MIN2(BinHigh,StarEner[nCont-1])-BinLow;
4513 if( BinLow < StarEner[0] )
4517 retval = (
realnum)(StarFlux[0]*
pow2(anu/StarEner[0]));
4519 else if( BinLow > StarEner[nCont-1] )
4528 long ipLo =
RebinFind(StarEner,nCont,BinLow);
4529 long ipHi =
RebinFind(StarEner,nCont,BinHigh);
4531 ASSERT( ipLo >= 0 && ipLo < nCont-1 && ipHi >= ipLo );
4546 if( StarPower[ipLo] == -FLT_MAX )
4549 double StarHigh =
min((StarEner[ipLo]+StarEner[ipLo+1])/2.,BinHigh);
4550 retval = StarFlux[ipLo]*
max(StarHigh-BinLow,0.)/widflx;
4552 else if( StarPower[ipLo] == FLT_MAX )
4555 double StarLow =
max((StarEner[ipLo]+StarEner[ipLo+1])/2.,BinLow);
4556 retval = StarFlux[ipLo+1]*
max(BinHigh-StarLow,0.)/widflx;
4561 retval = (
realnum)(StarFlux[ipLo]*pow(anu/StarEner[ipLo],(
double)StarPower[ipLo]));
4576 for(
long i=ipLo; i <=
MIN2(ipHi,nCont-2); i++ )
4578 if( StarPower[i] == -FLT_MAX )
4581 double upper =
min((StarEner[i]+StarEner[i+1])/2.,BinHigh);
4582 double wid =
max(upper-
max(BinLow,StarEner[i]),0.);
4583 sum += StarFlux[i]*wid;
4586 if( StarPower[i] == FLT_MAX )
4589 double lower =
max((StarEner[i]+StarEner[i+1])/2.,BinLow);
4590 double wid =
max(
min(BinHigh,StarEner[i+1])-lower,0.);
4591 sum += StarFlux[i+1]*wid;
4595 double v1, val,
x1,
x2;
4596 double pp1 = StarPower[i] + 1.;
4602 v1 = StarFlux[i]*pow(x1/StarEner[i],(
double)StarPower[i]);
4605 else if( i == ipHi )
4620 if( fabs(pp1) < 0.001 )
4622 double z = log(x2/x1);
4624 val = x1*v1*z*(((zp/24.+1./6.)*zp+1./2.)*zp+1.);
4628 val = pow(x2/x1,pp1) - 1.;
4634 retval = sum/widflx;
4652 if( val < array[0] )
4654 else if( val > array[nArr-1] )
4665 const vector<mpp>& telg,
4675 fprintf( ioBUG,
"######## MODEL %ld", imod+1 );
4676 for(
long nd=0; nd < npar; nd++ )
4677 fprintf( ioBUG,
" %s %g", names[nd], telg[imod].par[nd] );
4678 fprintf( ioBUG,
" ####################\n" );
4680 for(
long k=0; k < nflux; ++k )
4681 fprintf( ioBUG,
"%e %e\n", anu[k], flux[k] );
STATIC realnum RebinSingleCell(long, const realnum[], const realnum[], const vector< realnum > &, long)
static const long int VERSION_BIN
STATIC void RauchReadMPP(vector< mpp > &, vector< mpp > &, vector< mpp > &, vector< mpp > &, vector< mpp > &, vector< mpp > &)
static const bool lgTAKELOG
int WernerCompile(process_counter &pc)
FILE * open_data(const char *fname, const char *mode, access_scheme scheme)
static const int IS_SECOND
bool GridCompile(const char *InName)
STATIC void CoStarListModels(const stellar_grid *)
static const int IS_COLLECT
long RauchInterpolateHydr(double val[], long *nval, long *ndim, bool lgList, double *Tlow, double *Thigh)
void DumpAtmosphere(const char *fnam, long, long, char[MDIM][MNAM+1], const vector< mpp > &, long, const T[], const realnum[])
STATIC void WriteASCIIHead(FILE *, long, long, const vector< string > &, long, long, const string &, double, const string &, double, const vector< mpp > &, const char *, int)
STATIC void InterpolateRectGrid(stellar_grid *, const double[], double *, double *, bool=lgTAKELOG, const realnum[]=NULL, long=0L)
map< string, int > caution
NORETURN void TotalInsanity(void)
static const realnum Edges_CoStar[]
static const int NMODS_PG1159
string mesh_md5sum() const
multi_arr< double, 2 > val
long CoStarInterpolate(double val[], long *nval, long *ndim, IntMode imode, bool lgHalo, bool lgList, double *val0_lo, double *val0_hi)
static const int NMODS_HYDR
long TlustyInterpolate(double val[], long *nval, long *ndim, tl_grid tlg, const char *chMetalicity, bool lgList, double *Tlow, double *Thigh)
STATIC void InitGrid(stellar_grid *, bool, bool=lgREAD_BIN)
static const int NMODS_HpHE
void invalidate_array(T *p, size_t size)
STATIC bool lgValidBinFile(const char *, process_counter &, access_scheme)
multi_arr< realnum, 2 > CloudyFlux
long HaardtMadauInterpolate(double val, int version, bool lgQuasar, double *zlow, double *zhigh)
int TlustyCompile(process_counter &pc)
bool fp_equal_tol(sys_float x, sys_float y, sys_float tol)
STATIC bool lgCompileAtmosphere(const char[], const char[], const realnum[], long, process_counter &)
STATIC void InitGridBin(stellar_grid *)
long RauchInterpolateHCa(double val[], long *nval, long *ndim, bool lgHalo, bool lgList, double *Tlow, double *Thigh)
STATIC long JIndex(const stellar_grid *, const vector< long > &)
STATIC void InitGridCoStar(stellar_grid *)
vector< Energy > tNu[LIMSPC]
STATIC void CheckVal(const stellar_grid *, double[], long *, long *)
STATIC bool lgReadAtmosphereHead(stellar_grid *)
long WMBASICInterpolate(double val[], long *nval, long *ndim, bool lgList, double *Tlow, double *Thigh)
STATIC void SetLimitsSub(const stellar_grid *, double, const vector< long > &, const vector< long > &, vector< long > &, long, double *, double *)
vector< realnum > tslop[LIMSPC]
static const long int VERSION_RAUCH_MPP
static const long int VERSION_COSTAR
STATIC void InterpolateGridCoStar(stellar_grid *, const double[], double *, double *)
STATIC void InterpolateModelCoStar(const stellar_grid *, const double[], vector< double > &, const long[], const long[], vector< long > &, long, long, vector< realnum > &)
double anu(size_t i) const
long hunt_bisect(const T x[], long n, T xval)
STATIC void SearchModel(const vector< mpp > &, bool, long, const vector< double > &, long, long *, long *)
static const long int VERSION_ASCII
int RauchCompile(process_counter &pc)
long int nflux_with_check
bool lgCoStarInterpolationCaution
STATIC void FindVCoStar(const stellar_grid *, double, vector< realnum > &, long[])
const double * anuptr() const
bool fp_equal(sys_float x, sys_float y, int n=3)
long KhaireSrianandInterpolate(double val, int Q, double *zlow, double *zhigh)
STATIC void GetModel(const stellar_grid *, long, realnum *, bool, bool)
long RauchInterpolateHpHe(double val[], long *nval, long *ndim, bool lgList, double *Tlow, double *Thigh)
const ios_base::openmode mode_r
vector< long > index_list
void swap(count_ptr< T > &a, count_ptr< T > &b)
int AtlasCompile(process_counter &pc)
int Kurucz79Compile(process_counter &pc)
STATIC void RebinAtmosphere(const vector< realnum > &, const vector< realnum > &, long, const realnum[], long, realnum[])
static const bool lgREAD_BIN
bool StarburstCompile(process_counter &pc)
long MihalasInterpolate(double val[], long *nval, long *ndim, bool lgList, double *Tlow, double *Thigh)
STATIC bool lgReadAtmosphereTail(stellar_grid *, const realnum[], long, const vector< long > &)
int CoStarCompile(process_counter &pc)
void SortUnique(vector< T > &, vector< T > &)
STATIC bool lgValidASCIIFile(const char *, access_scheme)
const int INPUT_LINE_LENGTH
STATIC void FindHCoStar(const stellar_grid *, long, double, long, vector< realnum > &, vector< long > &, vector< long > &)
STATIC void GetBins(const stellar_grid *, vector< Energy > &)
STATIC void SetLimits(const stellar_grid *, double, const vector< long > &, const vector< long > &, const long[], const vector< realnum > &, double *, double *)
double anumin(size_t i) const
STATIC void InitIndexArrays(stellar_grid *, bool)
void InitGridASCII(stellar_grid *)
STATIC void ValidateMesh(const stellar_grid *, const vector< Energy > &)
void getdataline(fstream &, string &)
int MihalasCompile(process_counter &pc)
static const bool DEBUGPRT
static const int NMODS_HELIUM
long RauchInterpolateCOWD(double val[], long *nval, long *ndim, bool lgList, double *Tlow, double *Thigh)
STATIC void WriteASCIIData(FILE *, const vector< double > &, long, const char *, int)
STATIC void FindIndex(const multi_arr< double, 2 > &, long, long, double, long *, long *, bool *)
STATIC void FillJ(stellar_grid *, vector< long > &, vector< double > &, long, bool)
long WernerInterpolate(double val[], long *nval, long *ndim, bool lgList, double *Tlow, double *Thigh)
#define DEBUG_ENTRY(funcname)
double powpq(double x, int p, int q)
STATIC void InterpolateModel(stellar_grid *, const double[], vector< double > &, const vector< long > &, const vector< long > &, vector< long > &, long, vector< realnum > &, bool, const realnum[]=NULL, long=0L)
STATIC bool RauchInitialize(const char[], const char[], const vector< mpp > &, long, long, long, const double[], int)
static const unsigned int NMD5
static const bool lgVERBOSE
long RauchInterpolateHelium(double val[], long *nval, long *ndim, bool lgList, double *Tlow, double *Thigh)
long GridInterpolate(double val[], long *nval, long *ndim, const char *FileName, bool lgList, double *Tlow, double *Thigh)
STATIC void ValidateGrid(const stellar_grid *, double)
static const bool lgLINEAR
static const int NMODS_HCA
int fprintf(const Output &stream, const char *format,...)
int WMBASICCompile(process_counter &pc)
static const int IS_FIRST
STATIC bool lgValidModel(const vector< Energy > &, const vector< realnum > &, double, double)
char * read_whole_line(char *chLine, int nChar, FILE *ioIN)
long RebinFind(const realnum[], long, realnum)
static const int NMODS_HNI
double anumax(size_t i) const
static const int IS_EXECUTE
vector< long > index_list2
long Kurucz79Interpolate(double val[], long *nval, long *ndim, bool lgList, double *Tlow, double *Thigh)
static const bool lgSILENT
static const bool lgREAD_ASCII
STATIC bool lgValidMesh(const vector< Energy > &)
long RauchInterpolatePG1159(double val[], long *nval, long *ndim, bool lgList, double *Tlow, double *Thigh)
STATIC bool CoStarInitialize(const char[], const char[])
STATIC bool lgFileReadable(const char *, process_counter &, access_scheme)
long RauchInterpolateHNi(double val[], long *nval, long *ndim, bool lgHalo, bool lgList, double *Tlow, double *Thigh)
double getResolutionScaleFactor() const
long AtlasInterpolate(double val[], long *nval, long *ndim, const char *chMetalicity, const char *chODFNew, bool lgList, double *Tlow, double *Thigh)
bool StarburstInitialize(const char chInName[], const char chOutName[], sb_mode mode)