00001
00002
00003
00004
00005 #include "cddefines.h"
00006 #include "cddrive.h"
00007 #include "assertresults.h"
00008 #include "called.h"
00009 #include "version.h"
00010 #include "input.h"
00011 #include "parse.h"
00012 #include "atmdat.h"
00013 #include "zero.h"
00014 #include "date.h"
00015 #include "optimize.h"
00016 #include "grid.h"
00017 #include "path.h"
00018
00019
00020
00021
00022
00023 #ifdef MPI
00024 # include <mpi.h>
00025 #endif
00026
00027 static char chMonth[12][4] ={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec" };
00028 static char chMonthInt[12][3] ={"01","02","03","04","05","06","07","08","09","10","11","12" };
00029
00030 #include <stdio.h>
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 static bool lgMPI;
00044
00045
00046
00047 void cdMPI(void)
00048 {
00049 lgMPI = true;
00050 return;
00051 }
00052
00053
00054 void cdInit(void)
00055 {
00056 long i;
00057 double vtest;
00058 static bool lgDateSet=false;
00059
00060
00061 ioQQQ = stdout;
00062
00063
00064 ioStdin = stdin;
00065
00066
00067 lgcdInitCalled = true;
00068
00069
00070 ioPrnErr = stderr;
00071
00072
00073 lgPrnErr = false;
00074
00075
00076 lgMPI = false;
00077
00078
00079 char *path = getenv( "CLOUDY_DATA_PATH" );
00080 if( path != NULL )
00081 {
00082 lgDataPathSet = true;
00083
00084
00085 size_t len = strlen(path);
00086 if( len < sizeof(chDataPath) )
00087 strcpy( chDataPath , path );
00088 else
00089 {
00090 fprintf( ioQQQ, " User-defined path doesn't fit in chDataPath\n" );
00091 puts( "[Stop in cdInit]" );
00092 cdEXIT(EXIT_FAILURE);
00093 }
00094
00095
00096 char *chEnd = chDataPath + len - 1;
00097
00098
00099 if( *chEnd != '/' && *chEnd != ']' && *chEnd != '\\' )
00100 {
00101
00102
00103
00104 if( ++len >= sizeof(chDataPath) )
00105 {
00106 fprintf( ioQQQ, " No room to append in chDataPath\n" );
00107 puts( "[Stop in cdInit]" );
00108 cdEXIT(EXIT_FAILURE);
00109 }
00110
00111
00112
00113
00114 if( strchr( chDataPath, '/' ) != NULL )
00115 {
00116
00117 strcat( chDataPath , "/" );
00118 }
00119 else if( strchr( chDataPath, '\\' ) != NULL )
00120 {
00121
00122 strcat( chDataPath, "\\" );
00123 }
00124 else if( strchr( chDataPath, '[' ) != NULL )
00125 {
00126
00127
00128 strcat( chDataPath, "]" );
00129 }
00130
00131
00132
00133 }
00134 }
00135
00136
00137 if( !lgDateSet )
00138 {
00139
00140 int nDecade = (YEAR-100)/10;
00141 char chDecade[2];
00142
00143
00144 version.chDate = (char *)MALLOC( sizeof(char)*INPUT_LINE_LENGTH );
00145 version.chVersion = (char *)MALLOC( sizeof(char)*INPUT_LINE_LENGTH );
00146
00147 lgDateSet = true;
00148 sprintf(chDecade,"%i", nDecade );
00149
00150 if( nDecade > 9 )
00151 {
00152 fprintf(ioQQQ,"must update formation of chDate in cdInit \n");
00153 TotalInsanity();
00154 }
00155 if( DAY < 10 )
00156 {
00157 sprintf( version.chDate , "%s%1i%s0%1i",
00158 chDecade,
00159 YEAR-100-nDecade*10,
00160 chMonth[MONTH],
00161 DAY );
00162 sprintf( version.chVersion , "%s%1i.%s.0%1i",
00163 chDecade,
00164 YEAR-100-nDecade*10,
00165 chMonthInt[MONTH],
00166 DAY );
00167 }
00168 else
00169 {
00170 sprintf( version.chDate , "%s%1i%s%2i",
00171 chDecade,
00172 YEAR-100-nDecade*10,
00173 chMonth[MONTH],
00174 DAY );
00175 sprintf( version.chVersion , "%s%1i.%s.%2i",
00176 chDecade,
00177 YEAR-100-nDecade*10,
00178 chMonthInt[MONTH],
00179 DAY );
00180 }
00181
00182 version.chCitation = CITATION;
00183 version.chCitationLatex = CITATION_LATEX;
00184 version.chCitationShort = CITATION_SHORT;
00185
00186
00187 version.lgRelease = true;
00188
00189
00190 version.nBetaVer = 0;
00191
00192
00193
00194
00195 strcat( version.chDate , "*" );
00196
00197 char mode[6];
00198 if( sizeof(long) == 4 )
00199 strncpy( mode, "ILP32", 6 );
00200 else if( sizeof(long) == 8 )
00201 strncpy( mode, "LP64", 6 );
00202 else
00203 strncpy( mode, "?????", 6 );
00204
00205
00206 sprintf(version.chInfo ,
00207 "cdInit compiled on %s in OS %s using the %s %i compiler in %s mode." ,
00208 __DATE__ ,__OS , __COMP , __COMP_VER, mode);
00209 }
00210
00211
00212
00213
00214
00215
00216 cdDefines();
00217
00218
00219
00220
00221 if( sizeof(int16) != 2 || sizeof(uint16) != 2 || sizeof(int32) != 4 || sizeof(uint32) != 4 )
00222 TotalInsanity();
00223
00224
00225
00226
00227
00228 vtest = 1e-35;
00229 vtest /= 1e35;
00230 if( vtest == 0. )
00231 {
00232 fprintf( ioQQQ, " Something is wrong with the double precision. Use /g_floating on a VAX\n" );
00233 }
00234
00235
00236
00237
00238
00239 # if BROKEN_COMPILER
00240 fprintf(ioQQQ,"HELP!!! You compiled me with %s %d!\n",__COMP,__COMP_VER);
00241 fprintf(ioQQQ,"This version of %s cannot compile Cloudy and must not be used!\n",__COMP);
00242 fprintf(ioQQQ,"Please update %s to a functional version.\n",__COMP);
00243 puts( "[Stop in cdInit]" );
00244 cdEXIT(EXIT_FAILURE);
00245 # endif
00246
00247
00248
00249
00250
00251 called.lgTalk = true;
00252
00253 called.lgTalkIsOK = true;
00254
00255 called.lgTalkForcedOff = false;
00256
00257 optimize.lgNoVary = false;
00258 optimize.lgVaryOn = false;
00259 optimize.lgOptimr = false;
00260 grid.lgGrid = false;
00261
00262 for( i=0; i<NUM_OUTPUT_TYPES; i++ )
00263 {
00264 grid.lgOutputTypeOn[i] = false;
00265 }
00266
00267 for( i=0; i<LIMPAR; i++ )
00268 {
00269 grid.numParamValues[i] = 0;
00270 }
00271
00272
00273
00274
00275 lgAssertsOK = true;
00276 lgBigBotch = false;
00277 lgPrtSciNot = false;
00278
00279
00280
00281
00282 input.nSave = -1;
00283
00284
00285
00286
00287
00288 input.nRead = -1;
00289
00290
00291 input.nSaveIni = 0;
00292 input.lgUnderscoreFound = false;
00293 input.lgBracketFound = false;
00294
00295
00296 for( i=0; i < NKRD; i++ )
00297 {
00298 strcpy( input.chCardSav[i], "error! - no line image input" );
00299 }
00300
00301
00302 cdSetExecTime();
00303
00304
00305 zero();
00306
00307 DEBUG_EXIT( "cdInit()" );
00308 return;
00309 }
00310
00311
00312
00313
00314 NORETURN void cdEXIT(int iexit)
00315 {
00316
00317 enum {DEBUG_LOC=false};
00318
00319 if( DEBUG_LOC )
00320 {
00321 fprintf(ioQQQ," cdEXIT called\n");
00322 }
00323
00324
00325
00326 fflush( ioQQQ );
00327
00328 ClosePunchFiles();
00329
00330
00331
00332
00333 if( lgMPI )
00334 {
00335 fprintf(ioQQQ," MPI_Finalize called.\n");
00336 # ifdef MPI
00337 MPI_Finalize();
00338 # endif
00339 }
00340 exit( iexit );
00341 }
00342
00343