90 printf(
" cdInit was not called first - this must be the first call.\n");
97 "cdDrive: lgOptimr=%1i lgVaryOn=%1i lgNoVary=%1i input.nSave:%li\n",
118 fprintf(
ioQQQ,
"cdDrive: calling grid_do\n");
125 fprintf(
ioQQQ,
"cdDrive: calling cloudy\n");
137 fprintf(
ioQQQ,
"cdDrive: returning failure during call. \n");
181 fprintf( ioOUT,
"%s",
warnings.chRgcln[0] );
182 fprintf( ioOUT ,
"\n" );
184 fprintf( ioOUT,
"%s",
warnings.chRgcln[1] );
185 fprintf( ioOUT ,
"\n" );
209 fprintf( ioPNT,
"%s",
warnings.chWarnln[i] );
210 fprintf( ioPNT,
"\n" );
236 fprintf( ioOUT,
"%s",
warnings.chCaunln[i] );
237 fprintf( ioOUT,
"\n" );
263 *TTherm =
timesc.time_therm_long;
266 *THRecom =
timesc.time_Hrecom_long;
292 fprintf( ioOUT,
"%s",
warnings.chBangln[i] );
293 fprintf( ioOUT,
"\n" );
319 fprintf( ioOUT,
"%s",
warnings.chNoteln[i] );
320 fprintf( ioOUT,
"\n" );
437#include <sys/resource.h>
450#if defined(_MSC_VER) || defined(__HP_aCC)
455 clock_dat->tv_sec = clock_val/CLOCKS_PER_SEC;
456 clock_dat->tv_usec = 1000000*(clock_val-(clock_dat->tv_sec*CLOCKS_PER_SEC))/CLOCKS_PER_SEC;
460 struct rusage rusage;
461 if(getrusage(RUSAGE_SELF,&rusage) != 0)
463 fprintf(
ioQQQ,
"DISASTER cdClock called getrusage with invalid arguments.\n" );
464 fprintf(
ioQQQ,
"Sorry.\n" );
467 clock_dat->tv_sec = rusage.ru_utime.tv_sec;
468 clock_dat->tv_usec = rusage.ru_utime.tv_usec;
485 struct timeval clock_dat;
493 return (
double)(clock_dat.tv_sec-
before.tv_sec)+1e-6*(
double)(clock_dat.tv_usec-
before.tv_usec);
499 fprintf(
ioQQQ,
"DISASTER cdExecTime was called before SetExecTime, impossible.\n" );
500 fprintf(
ioQQQ,
"Sorry.\n" );
516 fprintf( ioOUT,
" Input commands follow:\n" );
517 fprintf( ioOUT,
"c ======================\n" );
519 for( i=0; i <=
input.nSave; i++ )
521 fprintf( ioOUT,
"%s\n",
input.chCardSav[i] );
523 fprintf( ioOUT,
"c ======================\n" );
574 long int ipEmisType = 0;
578 strcpy( chCARD, chLabel );
597 *emiss =
LineSv[j].emslin[ipEmisType];
651 char chLABEL_CAPS[20];
656 if( chLabel[4] !=
'\0' || strlen(chLabel) != 4 )
658 fprintf(
ioQQQ,
" cdColm called with insane chLabel (between quotes) \"%s\", must be exactly 4 characters long.\n",
663 strcpy( chLABEL_CAPS, chLabel );
672 fprintf(
ioQQQ,
" cdColm called with insane ion, =%li\n",
681 if( strcmp( chLABEL_CAPS ,
"H2 " )==0 )
687 else if( strcmp( chLABEL_CAPS ,
"H- " )==0 )
693 else if( strcmp( chLABEL_CAPS ,
"H2+ " )==0 )
699 else if( strcmp( chLABEL_CAPS ,
"H3+ " )==0 )
705 else if( strcmp( chLABEL_CAPS ,
"H2G " )==0 )
711 else if( strcmp( chLABEL_CAPS ,
"H2* " )==0 )
717 else if( strcmp( chLABEL_CAPS ,
"HEH+" )==0 )
723 else if( strcmp( chLABEL_CAPS ,
"CO " )==0 )
729 else if( strcmp( chLABEL_CAPS ,
"OH " )==0 )
735 else if( strcmp( chLABEL_CAPS ,
"H2O " )==0 )
741 else if( strcmp( chLABEL_CAPS ,
"O2 " )==0 )
747 else if( strcmp( chLABEL_CAPS ,
"SIO " )==0 )
753 else if( strcmp( chLABEL_CAPS ,
"C2 " )==0 )
759 else if( strcmp( chLABEL_CAPS ,
"C3 " )==0 )
765 else if( strcmp( chLABEL_CAPS ,
"CN " )==0 )
771 else if( strcmp( chLABEL_CAPS ,
"CH " )==0 )
777 else if( strcmp( chLABEL_CAPS ,
"CH+ " )==0 )
786 else if( strcmp( chLABEL_CAPS ,
"CII*" )==0 )
788 *theocl =
colden.C2Colden[1];
790 else if( strcmp( chLABEL_CAPS ,
"C11*" )==0 )
792 *theocl =
colden.C1Colden[0];
794 else if( strcmp( chLABEL_CAPS ,
"C12*" )==0 )
796 *theocl =
colden.C1Colden[1];
798 else if( strcmp( chLABEL_CAPS ,
"C13*" )==0 )
800 *theocl =
colden.C1Colden[2];
802 else if( strcmp( chLABEL_CAPS ,
"O11*" )==0 )
804 *theocl =
colden.O1Colden[0];
806 else if( strcmp( chLABEL_CAPS ,
"O12*" )==0 )
808 *theocl =
colden.O1Colden[1];
810 else if( strcmp( chLABEL_CAPS ,
"O13*" )==0 )
812 *theocl =
colden.O1Colden[2];
815 else if( strcmp( chLABEL_CAPS ,
"C30*" )==0 )
817 *theocl =
colden.C3Colden[1];
819 else if( strcmp( chLABEL_CAPS ,
"C31*" )==0 )
821 *theocl =
colden.C3Colden[2];
823 else if( strcmp( chLABEL_CAPS ,
"C32*" )==0 )
825 *theocl =
colden.C3Colden[3];
827 else if( strcmp( chLABEL_CAPS ,
"SI2*" )==0 )
829 *theocl =
colden.Si2Colden[1];
831 else if( strcmp( chLABEL_CAPS ,
"HE1*" )==0 )
836 else if( strncmp(chLABEL_CAPS ,
"H2" , 2 ) == 0 )
838 long int iVib = chLABEL_CAPS[2] -
'0';
839 long int iRot = chLABEL_CAPS[3] -
'0';
840 if( iVib<0 || iRot < 0 )
842 fprintf(
ioQQQ,
" cdColm called with insane v,J for H2=\"%4.4s\" caps=\"%4.4s\"\n",
843 chLabel , chLABEL_CAPS );
852 fprintf(
ioQQQ,
" cdColm called with unknown element chLabel, org=\"%4.4s \" 0 caps=\"%4.4s\" 0\n",
853 chLabel , chLABEL_CAPS );
863 strncmp(chLABEL_CAPS,
elementnames.chElementNameShort[nelem],4) != 0 )
875 if( ion >
MAX2(3,nelem + 2) )
878 " cdColm asked to return ionization stage %ld for element %s but this is not physical.\n",
884 *theocl =
mean.xIonMean[0][nelem][ion-1][0];
895 " cdColm did not understand this combination of ion %4ld and element %4.4s.\n",
925 cdNwcns(&lgAbort_loc,&nw,&nc,&nn,&ns,&nte,&npe, &nIone, &nEdene );
928 if( nw || nc || nte || npe || nIone || nEdene || lgAbort_loc )
931 fprintf( ioOUT,
"%75.75s\n",
input.chTitle );
934 fprintf(ioOUT,
" Calculation ended with abort!\n");
950 fprintf( ioOUT ,
"Te failures=%4ld\n", nte );
955 fprintf( ioOUT ,
"Pressure failures=%4ld\n", npe );
960 fprintf( ioOUT ,
"Ionization failures=%4ld\n", nte );
965 fprintf( ioOUT ,
"Electron density failures=%4ld\n", npe );
982 for( nz = 0; nz<
nzone; ++nz )
984 cdDepth[nz] =
struc.depth[nz];
1003 double TotalPressure[],
1005 double GasPressure[],
1007 double RadiationPressure[])
1013 for( nz = 0; nz<
nzone; ++nz )
1015 TotalPressure[nz] =
struc.pressure[nz];
1016 GasPressure[nz] =
struc.GasPressure[nz];
1017 RadiationPressure[nz] =
struc.pres_radiation_lines_curr[nz];
1037 *PresRad =
pressure.pres_radiation_lines_curr;
1038 *PresTotal =
pressure.PresTotlCurr;
1074 const char *chLabel,
1081 const char *chWeight ,
1095 strcpy( chCARD, chWeight );
1100 if( strcmp(chCARD,
"RADIUS") == 0 )
1102 else if( strcmp(chCARD,
"AREA") == 0 )
1104 else if( strcmp(chCARD,
"VOLUME") == 0 )
1108 fprintf(
ioQQQ,
" cdIonFrac: chWeight=%6.6s makes no sense to me, valid options are RADIUS, AREA, and VOLUME\n",
1115 strcpy( chCARD, chLabel );
1122 if( strcmp(chCARD,
"H2 " ) == 0 )
1130 fprintf(
ioQQQ,
" cdIonFrac: ion stage of zero and element %s makes no sense to me\n",
1142 strcmp(chCARD,
elementnames.chElementNameShort[nelem]) != 0 )
1151 fprintf(
ioQQQ,
" cdIonFrac called with unknown element chLabel, =%4.4s\n",
1163 if( (ion > nelem+1 || ion < 0 ) && !(nelem==
ipHYDROGEN&&ion==2))
1165 fprintf(
ioQQQ,
" cdIonFrac asked to return ionization stage %ld for element %4.4s but this is not physical.\n",
1166 IonStage, chLabel );
1176 mean.MeanIon(
'i',nelem,dim,&ip,aaa,lgDensity);
1177 *fracin = pow((
realnum)10.f,aaa[ion]);
1210 printf(
"%s\n",
LineSv[j].chALab);
1214 printf(
" hits = %li\n", kount );
1229 const char *chLabel,
1242 const char *chLabel,
1258 j, index_of_closest=LONG_MIN,
1259 index_of_closest_w_correct_label=-1;
1261 smallest_error_w_correct_label=
BIGFLOAT;
1265 if( LineType<0 || LineType>3 )
1267 fprintf(
ioQQQ,
" cdLine called with insane nLineType - it must be between 0 and 3.\n");
1283 if( chLabel[4] !=
'\0' || strlen(chLabel) != 4 )
1285 fprintf(
ioQQQ,
" cdLine called with insane chLabel (between quotes) \"%s\", must be exactly 4 characters long.\n",
1291 cap4(chFind, chLabel);
1295 for( j=0; j<=3; j++ )
1297 if( chFind[j] ==
'\t' )
1307 enum{DEBUG_LOC=
false};
1308 if( DEBUG_LOC && fabs(
wavelength-1000.)<0.01 )
1310 fprintf(
ioQQQ,
"cdDrive wl %.4e error %.3e\n",
1326 if( current_error < smallest_error )
1328 index_of_closest = j;
1329 smallest_error = current_error;
1332 if( current_error < smallest_error_w_correct_label &&
1333 (strcmp(chCaps,chFind) == 0) )
1335 index_of_closest_w_correct_label = j;
1336 smallest_error_w_correct_label = current_error;
1341 if( current_error <= errorwave ||
1346 if( strcmp(chCaps,chFind) == 0 )
1354 *relint =
LineSv[ipobs].SumLine[LineType]/
1364 if(
LineSv[ipobs].SumLine[LineType] > 0. )
1366 *absint = log10(
LineSv[ipobs].SumLine[LineType]) +
1382 fprintf(
ioQQQ,
" PROBLEM cdLine did not find line with label (between quotes) \"%4s\" and wavelength ", chFind );
1384 if( index_of_closest >= 0 )
1386 fprintf(
ioQQQ,
".\n The closest line (any label) was \"%4s\"\t",
1387 LineSv[index_of_closest].chALab );
1389 if( index_of_closest_w_correct_label >= 0 )
1391 fprintf(
ioQQQ,
"\n The closest with correct label was \"%4s\"\t", chFind );
1393 fprintf(
ioQQQ,
"\n" );
1396 fprintf(
ioQQQ,
"\n No line found with label \"%s\".\n", chFind );
1397 fprintf(
ioQQQ,
"\n" );
1401 fprintf(
ioQQQ,
".\n PROBLEM No close line was found\n" );
1438 if( LineType<0 || LineType>3 )
1440 fprintf(
ioQQQ,
" cdLine_ip called with insane nLineType - it must be between 0 and 3.\n");
1485 long int *NumberWarnings,
1486 long int *NumberCautions,
1487 long int *NumberNotes,
1488 long int *NumberSurprises,
1490 long int *NumberTempFailures,
1492 long int *NumberPresFailures,
1494 long int *NumberIonFailures,
1496 long int *NumberNeFailures )
1510 *NumberTempFailures =
conv.nTeFail;
1511 *NumberPresFailures =
conv.nPreFail;
1512 *NumberIonFailures =
conv.nIonFail;
1513 *NumberNeFailures =
conv.nNeFail;
1524 if( *filename !=
'\0' )
1526 save.chOutputFile = filename;
1530void cdInput(
const char* filename,
const char *mode )
1537 if( *filename !=
'\0' )
1554 called.lgTalk = lgTOn &&
cpu.i().lgMPI_talk();
1556 called.lgTalkForcedOff = !lgTOn;
1570 ret =
mean.TempB_HarMean[0][0]/
mean.TempB_HarMean[0][1];
1604 const char *chLabel,
1611 const char *chWeight )
1623 strcpy( chWGHT, chWeight );
1625 strcpy( chELEM, chLabel );
1630 if( strcmp(chWGHT,
"RADIUS") == 0 )
1632 else if( strcmp(chWGHT,
"AREA") == 0 )
1634 else if( strcmp(chWGHT,
"VOLUME") == 0 )
1638 fprintf(
ioQQQ,
" cdTemp: chWeight=%6.6s makes no sense to me, the options are RADIUS, AREA, and VOLUME.\n",
1647 if( strcmp(chELEM,
"21CM") == 0 )
1650 *TeMean =
mean.TempHarMean[dim][0]/
mean.TempHarMean[dim][1];
1656 else if( strcmp(chELEM,
"SPIN") == 0 )
1658 *TeMean =
mean.TempH_21cmSpinMean[dim][0] /
SDIV(
mean.TempH_21cmSpinMean[dim][1]);
1661 else if( strcmp(chELEM,
"OPTI") == 0 )
1668 else if( strcmp(chELEM,
"H2 ") == 0 )
1678 else if( strcmp(chELEM,
"TENE") == 0 )
1681 *TeMean =
mean.TempEdenMean[dim][0]/
mean.TempEdenMean[dim][1];
1686 else if( strcmp(chELEM,
" ") == 0 )
1689 *TeMean =
mean.TempMean[dim][0]/
mean.TempMean[dim][1];
1695 fprintf(
ioQQQ,
" cdTemp called with ion=0 and unknown quantity, =%4.4s\n",
1707 strcmp(chELEM,
elementnames.chElementNameShort[nelem]) != 0 )
1715 fprintf(
ioQQQ,
" cdTemp called with unknown element chLabel, =%4.4s\n",
1727 if( ion > nelem+1 || ion < 0 )
1729 fprintf(
ioQQQ,
" cdTemp asked to return ionization stage %ld for element %4.4s but this is not physical.\n",
1730 IonStage, chLabel );
1737 mean.MeanIon(
't', nelem,dim,&ip,aaa,
false);
1738 *TeMean = pow((
realnum)10.f,aaa[ion]);
1754 const char *chInputLine )
1767 printf(
" cdInit was not called first - this must be the first call.\n");
1776 chInputLine[0] ==
'\n' || chInputLine[0] ==
' ' ) &&
1778 ! ( chInputLine[0] ==
'C' || chInputLine[0] ==
'c' ) )
1798 " Too many line images entered to cdRead. The limit is %d\n",
1801 " The limit to the number of allowed input lines is %d. This limit was exceeded. Sorry.\n",
1804 " This limit is set by the variable NKRD which appears in input.h \n" );
1806 " Increase it everywhere it appears.\n" );
1816 fprintf(
ioQQQ,
" PROBLEM cdRead, while parsing the following input line:\n %s\n",
1818 fprintf(
ioQQQ,
" found that the line is longer than %i characters, the longest possible line.\n",
1820 fprintf(
ioQQQ,
" Please make the command line no longer than this limit.\n");
1825 if( (chEOL =
strchr_s(chLocal,
'\n' ) ) != NULL )
1829 if( (chEOL =
strchr_s(chLocal,
'%' ) ) != NULL )
1834 if( (chEOL =
strchr_s(chLocal,
'#' ) ) != NULL )
1838 if( (chEOL =
strchr_s(chLocal,
';' ) ) != NULL )
1842 if( (chEOL =
strstr_s(chLocal,
"//" ) ) != NULL )
1849 if( (chEOL =
strchr_s( chLocal,
'\0' )) == NULL )
1856 strcat( chLocal,
" " );
1860 strcpy(
input.chCardSav[
input.nSave], chLocal );
1863 strcpy( chCARD, chLocal );
1868 if( strncmp(chCARD ,
"C ", 2 )==0 )
1870 bool lgTitle = ( strncmp(chCARD,
"TITL", 4) == 0 );
1873 if( strncmp(chCARD,
"TRACE",5) == 0 )
1874 trace.lgTrace =
true;
1884 strcpy( chTemp ,
input.chCardSav[
input.nSave] );
1885 GetQuote( chFilename , chCARD , chTemp ,
false );
1888 if( !lgComment && !lgTitle &&
nMatch(
"VARY",chCARD) )
1893 if( strncmp(chCARD,
"NO VARY",7) == 0 )
1897 if( strncmp(chCARD,
"GRID",4) == 0 )
1900 ++
grid.nGridCommands;
1905 if( strncmp(chCARD,
"NO BUFF",7) == 0 )
1910 FILE *test = stdout;
1913 fprintf(
ioQQQ,
" cdRead found NO BUFFERING command, redirecting output to stderr now.\n" );
1918 setvbuf(
ioQQQ, NULL, _IONBF, 0);
1920 input.lgSetNoBuffering =
true;
1922 else if( !
save.chOutputFile.empty() )
1924 fprintf(
ioQQQ,
" cdRead found NO BUFFERING command, reopening file %s now.\n",
1925 save.chOutputFile.c_str() );
1933 fprintf(
ioQQQ,
" cdRead failed to reopen %s, aborting!\n",
1934 save.chOutputFile.c_str() );
1937 if( setvbuf(
ioQQQ, NULL, _IONBF, 0 ) != 0 )
1938 fprintf(
ioQQQ,
" PROBLEM -- cdRead failed to set NO BUFFERING mode.\n" );
1940 input.lgSetNoBuffering =
true;
1945 if( strncmp(chCARD,
"OPTI",4) == 0 || strncmp(chCARD,
"GRID",4) == 0 )
long nMatch(const char *chKey, const char *chCard)
const int INPUT_LINE_LENGTH
void cap4(char *chCAP, const char *chLab)
const char * strstr_s(const char *haystack, const char *needle)
int GetQuote(char *chLabel, char *chCard, char *chCardRaw, bool lgABORT)
const char * strchr_s(const char *s, int c)
bool fp_equal(sys_float x, sys_float y, int n=3)
NORETURN void TotalInsanity(void)
sys_float SDIV(sys_float x)
#define DEBUG_ENTRY(funcname)
void cdDepth_depth(double cdDepth[])
int cdColm(const char *chLabel, long int ion, double *theocl)
void cdCautions(FILE *ioOUT)
void cdPrintCommands(FILE *ioOUT)
long int cdEmis(char *chLabel, realnum wavelength, double *emiss)
void cdLine_ip(long int ipLine, double *relint, double *absint)
void cdPressure_last(double *PresTotal, double *PresGas, double *PresRad)
void cdSurprises(FILE *ioOUT)
void cdNotes(FILE *ioOUT)
int cdRead(const char *chInputLine)
int cdIonFrac(const char *chLabel, long int IonStage, double *fracin, const char *chWeight, bool lgDensity)
void cdEmis_ip(long int ipLine, double *emiss, bool lgEmergent)
static struct timeval before
void cdPrtWL(FILE *io, realnum wl)
void cdInput(const char *filename, const char *mode)
void cdTimescales(double *TTherm, double *THRecom, double *TH2)
void cdNwcns(bool *lgAbort_ret, long int *NumberWarnings, long int *NumberCautions, long int *NumberNotes, long int *NumberSurprises, long int *NumberTempFailures, long int *NumberPresFailures, long int *NumberIonFailures, long int *NumberNeFailures)
void cdDate(char chString[])
void cdVersion(char chString[])
void cdWarnings(FILE *ioPNT)
STATIC void cdClock(struct timeval *clock_dat)
long int cdLine(const char *chLabel, realnum wavelength, double *relint, double *absint)
void cdErrors(FILE *ioOUT)
void cdPressure_depth(double TotalPressure[], double GasPressure[], double RadiationPressure[])
int cdTemp(const char *chLabel, long int IonStage, double *TeMean, const char *chWeight)
long debugLine(realnum wavelength)
void cdReasonGeo(FILE *ioOUT)
void cdOutput(const char *filename, const char *mode)
double cdH2_colden(long iVib, long iRot)
static t_version & Inst()
FILE * open_data(const char *fname, const char *mode, access_scheme scheme)
UNUSED const realnum BIGFLOAT
t_elementnames elementnames
t_iso_sp iso_sp[NISO][LIMELM]
realnum WavlenErrorGet(realnum wavelength)
molezone * findspecieslocal(const char buf[])
static realnum * wavelength
void CloseSaveFiles(bool lgFinal)
void prt_wl(FILE *ioOUT, realnum wl)
TransitionList HFLines("HFLines", &AnonStates)