/********************************************************/ /* code for finding the spec for each of the star */ /* within the catalogue */ /* compilation: */ /* gcc -g -O0 -Wall -I/usr/include -I/usr/include/cfitsio -L/lib64 -lcfitsio -lm main.c -o main */ /* usage: */ /* code/main file.par cat.list spec/Ext_odonnell94_R3.1_CK04W.fits */ /*********************************************************/ #include #include #include #include #include #include #include "utils.c" // #include "csst_spec_interp.h" //#include //#include //#include #define MAXSTRLEN 200 //#define G_const 6.67384E-8 #define lgG log10(6.67384E-8) #define lgMsun log10(1.9891E33) #define lgExp log10(exp(1.)) #define twolgpc2cm 2.*log10(3.086e+18) struct SPECLIB { float Z; char name[MAXSTRLEN]; int nspec; int nwv; float *logts; float *UniqueLogts; int *iLogts; int NULogts; float *loggs; float *UniqueLoggs; int *iLoggs; int NULoggs; float *wvs; float **specs; }; struct STAR { float logte; float logg; //float logL; float Mass; float Av; float mu0; float Z; //float mbolmag; }; void replace(char * o_string, char * s_string, char * r_string); void SortedUniqueElements(float in_array[], float out_array[], int size, int *NU); int interp1D (float x, float *v, int *n, int nmax); float locateitin1Dtab (float x, float *v, int n, int *i1, int *i2, int flagrange, int flaglimits, int flaglog); float locateitin1Dtab(float, float *, int, int *, int *, int, int, int); void printerror(int); int loadSpecLibs(char *, char *); void loadExts(char *); void interpSingleStar(struct STAR, float *, float *); int NZ=0,NWV=0; struct SPECLIB *speclibs=NULL; float *Exts=NULL; //float *outspec=NULL; void printerror( int status) { /*****************************************************/ /* Print out cfitsio error messages and exit program */ /*****************************************************/ if (status) { fits_report_error(stderr, status); /* print error report */ exit( status ); /* terminate the program, returning error status */ } return; } int loadSpecLibs(char *file_par, char *specDir) { fitsfile *fp_spec; FILE *fp_par; char tmpstr[MAXSTRLEN]; int iZ,icol,imod,iwv, nspec_table, itable, icol_start, ispec, Nbyte=4; int status=0,nfound,hdutype,nullval,anynulls; long naxes[2]; //load the spec libs fp_par=fopen(file_par,"r"); fscanf(fp_par, "%d", &NZ); printf("%d different metallicity tables of spec lib\n",NZ); fgets(tmpstr, MAXSTRLEN, fp_par); speclibs=malloc(sizeof(struct SPECLIB)*NZ); for (iZ=0; iZ1) { fits_close_file(fp_spec, &status); continue;} icol_start=2; } //for (icol=icol_start; icolspeclibs[NZ-1].Z) { iZsub=NZ-1;iZup=NZ-1; } else { for (iZ=1;iZ