16 #if defined(_BIG_ENDIAN)
27 # define HtoNL(A) ((((A) & 0xff000000) >> 24) | \
28 (((A) & 0x00ff0000) >> 8) | \
29 (((A) & 0x0000ff00) << 8) | \
30 (((A) & 0x000000ff) << 24))
40 #define ByteSwap5(x) ByteSwap((unsigned char *) &x,sizeof(x))
42 #if !defined(_BIG_ENDIAN)
65 const char ModelUnits[2][17] = {
"'dimensionless '",
"'photons/cm^2/s'" };
70 realnum **paramData,
long nintparm,
long naddparm,
71 long *numParamValues );
75 long totNumModels,
long numEnergies );
77 long totNumModels,
long ipLo,
long ipHi,
long ipNorm,
long nintparm,
long naddparm );
82 STATIC long addKeyword_txt(
const char *theKeyword,
const void *theValue,
const char *theComment,
long Str_Or_Log );
107 FILE* asciiDump =
open_data(
"gridspectra.con",
"w" );
133 bool lgAdditiveModel = ( option != 10 );
134 bool lgNormalize = ( Enorm > 0.f );
139 long numEnergies = ipHi-ipLo+1;
164 const char *ModelName =
"'CLOUDY'";
168 int iunit = ( lgAddModel && !lgNormalize ) ? 1 : 0;
172 fixit(
"bitpix is wrong when realnum is double?");
182 if( lgAddModel ==
true )
213 long naxis, naxis1, naxis2;
225 naxis2 = nintparm+naddparm;
261 bytesAdded +=
addKeyword_txt(
"HDUCLASS",
"'OGIP '",
"Format conforms to OGIP/GSFC conventions", 0 );
262 bytesAdded +=
addKeyword_txt(
"HDUCLAS1",
"'XSPEC TABLE MODEL'",
"model spectra for XSPEC", 0 );
263 bytesAdded +=
addKeyword_txt(
"HDUCLAS2",
"'PARAMETERS'",
"Extension containing paramter info", 0 );
264 bytesAdded +=
addKeyword_txt(
"HDUVERS" ,
"'1.0.0 '",
"Version of format (OGIP memo OGIP-92-001)", 0 );
265 bytesAdded +=
addKeyword_num(
"NINTPARM", nintparm,
"Number of interpolation parameters" );
266 bytesAdded +=
addKeyword_num(
"NADDPARM", naddparm,
"Number of additional parameters" );
286 long *numParamValues )
295 for( i=0; i<nintparm+naddparm; i++ )
301 paramMethods[i] =
HtoNL(paramMethods[i]);
303 numTemp =
HtoNL(numParamValues[i]);
307 paramRange[i][0] = (
realnum)
exp10( (
double)paramRange[i][0] );
308 paramRange[i][1] = (
realnum)
exp10( (
double)paramRange[i][1] );
309 paramRange[i][2] = (
realnum)
exp10( (
double)paramRange[i][2] );
310 paramRange[i][3] = (
realnum)
exp10( (
double)paramRange[i][3] );
311 paramRange[i][4] = (
realnum)
exp10( (
double)paramRange[i][4] );
312 paramRange[i][5] = (
realnum)
exp10( (
double)paramRange[i][5] );
315 #if !defined(_BIG_ENDIAN)
325 for( j=0; j<numParamValues[i]; j++ )
329 paramData[i][j] = (
realnum)
exp10( (
double)paramData[i][j] );
332 #if !defined(_BIG_ENDIAN)
352 for( i=0; i<nintparm+naddparm; i++ )
354 paramMethods[i] =
HtoNL(paramMethods[i]);
356 #if !defined(_BIG_ENDIAN)
366 for( j=0; j<numParamValues[i]; j++ )
368 #if !defined(_BIG_ENDIAN)
385 long naxis, naxis1, naxis2;
394 naxis2 = numEnergies;
430 for(
long i=ipLo; i <= ipHi; i++ )
436 #if !defined(_BIG_ENDIAN)
451 long totNumModels,
long numEnergies )
453 long i, numFields = 2+naddparm;
454 long naxis, naxis1, naxis2;
455 char theKeyword1[30];
456 char theKeyword2[30];
457 char theKeyword3[30];
458 char theComment1[47];
468 naxis1 = ( numEnergies*(naddparm+1) + nintparm ) * (long)
sizeof(
realnum);
469 naxis2 = totNumModels;
470 int iunit = ( lgAddModel && !lgNormalize ) ? 1 : 0;
495 bytesAdded +=
addKeyword_txt(
"TFORM2" , theValue.c_str(),
"data format of the field: 4-byte REAL", 0 );
501 for( i=1; i<=naddparm; i++ )
503 sprintf( theKeyword1,
"%s%ld",
"TTYPE", i+2 );
504 sprintf( theKeyword2,
"%s%ld",
"TFORM", i+2 );
505 sprintf( theKeyword3,
"%s%ld",
"TUNIT", i+2 );
507 ostringstream theValue1;
508 theValue1 <<
"'ADDSP" << setw(2) << setfill(
'0') << i <<
"'";
510 sprintf( theComment1,
"%s%ld",
"label for field ", i+2 );
512 bytesAdded +=
addKeyword_txt( theKeyword1 , theValue1.str().c_str(), theComment1, 0 );
513 bytesAdded +=
addKeyword_txt( theKeyword2 , theValue.c_str(),
"data format of the field: 4-byte REAL", 0 );
517 bytesAdded +=
addKeyword_txt(
"EXTNAME" ,
"'SPECTRA '",
"name of this binary table extension", 0 );
518 bytesAdded +=
addKeyword_txt(
"HDUCLASS",
"'OGIP '",
"Format conforms to OGIP/GSFC conventions", 0 );
519 bytesAdded +=
addKeyword_txt(
"HDUCLAS1",
"'XSPEC TABLE MODEL'",
"model spectra for XSPEC", 0 );
520 bytesAdded +=
addKeyword_txt(
"HDUCLAS2",
"'MODEL SPECTRA'",
"Extension containing model spectra", 0 );
521 bytesAdded +=
addKeyword_txt(
"HDUVERS" ,
"'1.0.0 '",
"Version of format (OGIP memo OGIP-92-001)", 0 );
535 long totNumModels,
long ipLo,
long ipHi,
long ipNorm,
long nintparm,
long naddparm )
538 long naxis2 = totNumModels;
545 for( i=0; i < naxis2; i++ )
552 fluxNorm = theSpectrum[option][i][ipNorm]/binwidth_keV;
555 for(
long j=ipLo; j <= ipHi; j++ )
557 flux[j] = theSpectrum[option][i][j];
562 #if !defined(_BIG_ENDIAN)
563 for(
long j=ipLo; j <= ipHi; j++ )
568 for(
long j = 0; j < nintparm; j++ )
579 #if !defined(_BIG_ENDIAN)
581 for(
long j=0; j < nintparm; j++ )
592 fprintf(
ioQQQ,
" Additional parameters not currently supported.\n" );
605 long naxis, naxis1, naxis2;
613 naxis1 = numFields*(long)
sizeof(
realnum);
658 #if !defined(_BIG_ENDIAN)
674 char timeString[30]=
"";
685 strcpy( timeString , ctime(&now) );
689 for(
long i=0; i<30; i++ )
691 if( timeString[i] ==
'\n' )
697 strcpy( tempString,
"Generated by Cloudy " );
699 strncat( tempString,
t_version::Inst().chVersion,
sizeof(tempString)-strlen(tempString)-1 );
702 strcpy( tempString,
"--- " );
703 strcat( tempString, timeString );
709 char firstLine[70], extraLine[64];
718 size_t k =
sizeof(firstLine)-1;
724 size_t l =
sizeof(extraLine)-1;
726 strcpy( tempString,
"cont> " );
727 strcat( tempString, extraLine );
734 STATIC long addKeyword_txt(
const char *theKeyword,
const void *theValue,
const char *theComment,
long Str_Or_Log )
736 long numberOfBytesWritten = 0;
741 if( Str_Or_Log == 0 )
752 ASSERT( Str_Or_Log == 1 );
762 return numberOfBytesWritten;
767 long numberOfBytesWritten = 0;
779 return numberOfBytesWritten;
787 string tempString =
"COMMENT " + CommentToAdd.substr(0, 69) + string(70,
' ');
790 for(
size_t i=10; i <
LINESIZE; i++ )
792 if( tempString[i] ==
'\t' )
798 long numberOfBytesWritten =
fprintf(
ioFITS_OUTPUT,
"%s", tempString.substr(0,LINESIZE).c_str() );
800 ASSERT( numberOfBytesWritten%LINESIZE == 0 );
801 return numberOfBytesWritten;
811 oss2 <<
"'" << left << setw(8) << oss1.str() <<
"'";
void GridRetrieveXSPECData(int option)
FILE * open_data(const char *fname, const char *mode, access_scheme scheme)
static const int RECORDSIZE
STATIC void punchFITS_ParamData(char **paramNames, long *paramMethods, realnum **paramRange, realnum **paramData, long nintparm, long naddparm, long *numParamValues)
double widflx(size_t i) const
STATIC void punchFITS_GenericData()
STATIC long addKeyword_num(const char *theKeyword, long theValue, const char *theComment)
STATIC void punchFITS_EnergyData(long ipLo, long ipHi)
void cdSPEC2(int Option, realnum ReturnedSpectrum[])
double anu(size_t i) const
STATIC void writeCloudyDetails(void)
static t_version & Inst()
STATIC void punchFITS_SpectraHeader(bool lgAdditiveModel, bool lgNormalize, long nintparm, long naddparm, long totNumModels, long numEnergies)
realnum ** interpParameters
STATIC long addKeyword_txt(const char *theKeyword, const void *theValue, const char *theComment, long Str_Or_Log)
STATIC void punchFITS_GenericHeader()
size_t ipointC(double anu) const
STATIC void punchFITS_PrimaryHeader(bool lgAddModel, bool lgNormalize)
long numParamValues[LIMPAR]
STATIC long addComment(const string &CommentToAdd)
static FILE * ioFITS_OUTPUT
STATIC void punchFITS_ParamHeader(long nintparm, long naddparm)
void saveFITSfile(FILE *io, int option, realnum Elo=0.f, realnum Ehi=0.f, realnum Enorm=0.f)
const int NUM_OUTPUT_TYPES
static long maxParamValues
multi_arr< realnum, 3 > Spectra
double anumin(size_t i) const
STATIC void ByteSwap(unsigned char *b, int n)
static const int LINESIZE
void wr_block(const void *ptr, size_t len, FILE *fdes)
const char ModelUnits[2][17]
#define DEBUG_ENTRY(funcname)
int fprintf(const Output &stream, const char *format,...)
string int2string(int val)
STATIC void punchFITS_EnergyHeader(long numEnergies)
double anumax(size_t i) const
STATIC void punchFITS_SpectraData(realnum **interpParameters, multi_arr< realnum, 3 > &theSpectrum, int option, long totNumModels, long ipLo, long ipHi, long ipNorm, long nintparm, long naddparm)