00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00030 #ifdef HAVE_CONFIG_H
00031 #include <config.h>
00032 #endif
00033
00034 #include <stdio.h>
00035 #include <stdlib.h>
00036 #include <math.h>
00037 #include <string.h>
00038
00039 #include "../libcpixe/libcpixe.h"
00040 #include "../libcpixe/compilopt.h"
00041
00042
00043 int main(int argc, char *argv[]);
00044 int cpixemain(int NCALL);
00045
00046 STATFILENAME inputfilename="input.in";
00047
00054 int main(int argc, char *argv[])
00055 {
00056 extern STATFILENAME inputfilename;
00057
00058 if(argc>1)strcpy(inputfilename,argv[1]);
00059 cpixemain(0);
00060 cpixemain(1);
00061 cpixemain(-1);
00062
00063 return EXIT_SUCCESS;
00064 }
00065
00077 int cpixemain(int NCALL)
00078 {
00079 extern STATFILENAME inputfilename;
00080 STATFILENAME fckfilename="";
00081 STATFILENAME abscoeffilename="";
00082 STATFILENAME xenerfilename="";
00083
00084
00085 LYR *lyr;
00086 CalibYld *XYldSums;
00087 int i,j,l;
00088 EXP_PARAM *pExpPar;
00089 SIM_PARAM *pSimPar;
00090
00091
00092 static int *PresentElems;
00093 static CPIXERESULTS *CalcFlags;
00094
00095 static CalibYld *LinesEnerArray;
00096 static CalibYld *EffArray;
00097 static FluorCKCoef *FCKCoefArray;
00098 static AbsCoef *TotAbsCoefArray;
00099 static SPT *SPTArray;
00100 static SFCListElem *SFCList;
00101 static int nSFCList;
00102 static int lastNcall=-1;
00103 static FILTER Filter;
00104
00105 static EXP_PARAM ExpPar;
00106 static foil *Sample;
00107 static int NFoil, NFoilUsed, dimSums;
00108 static FILE *outputfile;
00109 static EXTRAINFO ExtraInfo;
00110
00111 #if CPIXEVERBOSITY > 0
00112 printf("\n\n\n************ BEGIN OF CPIXE OUTPUT ****************\n\n");
00113 #endif
00114
00115 pExpPar=&ExpPar;
00116 pSimPar=&pExpPar->simpar;
00117
00118 if(NCALL>0){
00119 if(lastNcall<0){fprintf(stderr,"\n ERROR: CPIXEMAIN: CPIXEMAIN was not initialized.\n");exit(1);}
00120
00121
00122
00123
00124
00125
00126
00127
00128 if(Filter.changes){
00129
00130 FilterTrans(pExpPar->simpar.MaxZinsample, LinesEnerArray, TotAbsCoefArray, PresentElems, &Filter);
00132 Filter.changes=0;
00133 }
00134
00135
00136 initlyrarray(pExpPar, Sample, LinesEnerArray, TotAbsCoefArray, SPTArray, PresentElems, NFoil, &NFoilUsed, &lyr);
00137 dimSums=pSimPar->MaxZinsample+1;
00138 XYldSums=(CalibYld*)calloc(dimSums,sizeof(CalibYld));
00139
00140 integrate_Simpson2(pExpPar, TotAbsCoefArray, FCKCoefArray, EffArray ,NFoilUsed, &Filter, lyr, XYldSums);
00141
00142
00143
00144
00145 #if CPIXEVERBOSITY > 0
00146
00147
00148 printf("\n\n Ebeam=%lf IncAng=%lf DetAng=%lf \n",
00149 pExpPar->BeamEner, pExpPar->IncAng/DEG2RAD, pExpPar->DetAng/DEG2RAD);
00150 printf("\n Charge=%lf DTCC=%lf DetColFac=%lf\n",
00151 pExpPar->simpar.ColCharge, pExpPar->simpar.DTCC, pExpPar->DetColFac);
00152
00153 printf("\n\nIteration %d\n",NCALL);
00154
00155 for(i=0;i<NFoil;i++){
00156 printf("\nSample[%d] (%d elem)\n",i,Sample[i].nfoilelm);
00157 printf("\n---Eff. thickness=%.3le (%d sublyrs)\n",lyr[i+1].ThickIn,lyr[i+1].FESxlen);
00158
00159 for(j=0;j<Sample[i].comp.nelem;j++){
00160 printf("'%s'(Z=%d) X[%d]=%lf (%lfat%% / %lfM%%)\n",
00161 ChemicalSymbol[Sample[i].comp.elem[j].Z],Sample[i].comp.elem[j].Z,j,Sample[i].comp.X[j],100*Sample[i].comp.xn[j],100*Sample[i].comp.w[j]);
00162 }
00163 printf("\nFinal Energy in this layer=%lf keV\n\n",lyr[i+1].FoilOutEner);
00164 }
00165
00166 for(i=0;i<Filter.nlyr;i++){
00167 printf("\nFilter[%d] (%lf 1e15at/cm2) (%d elem) \n",i,Filter.foil[i].thick,Filter.foil[i].nfoilelm);
00168 for(j=0;j<Filter.foil[i].comp.nelem;j++){
00169 printf("(Z=%d) X[%d]=%lf (%lfat%% / %lfM%%)\n",
00170 Filter.foil[i].comp.elem[j].Z,j,Filter.foil[i].comp.X[j],100*Filter.foil[i].comp.xn[j],100*Filter.foil[i].comp.w[j]);
00171 }
00172 }
00173
00174 for(i=0;i<dimSums;i++){
00175 if(i<=pSimPar->MaxZinsample && PresentElems[i]){
00176 printf("\n\n ************RESULTS for %s (Z=%d)\n",ChemicalSymbol[i],i);
00177
00178 for (j = 1; j <= 3; j++)
00179 if(XYldSums[i].K_[j] > 0.) {
00180 fprintf(stdout,"\n%10s (%2.2lfkeV)\t%le counts (Eff=%.3le Flt=%.2le)", LineNm[1][j], LinesEnerArray[i].K_[j], XYldSums[i].K_[j],EffArray[i].K_[j],Filter.Trans[i].K_[j]);
00181 fprintf(stdout,"\n%10s \texp:\t%le counts (err=%.1le) ", "", CalcFlags[i].simareas.K_[j],CalcFlags[i].err.K_[j]);
00182 }
00183
00184 for (j = 1; j <= 3; j++)
00185 for (l = 1; l <= 3; l++)
00186 if(XYldSums[i].L_[j][l] > 0.){
00187 fprintf(stdout,"\n%10s (%2.2lfkeV)\t%le counts (cal=%.3le Flt=%.2le)", LineNm[j+1][l], LinesEnerArray[i].L_[j][l], XYldSums[i].L_[j][l],EffArray[i].L_[j][l],Filter.Trans[i].L_[j][l]);
00188 fprintf(stdout,"\n%10s \texp:\t%le counts (err=%.1le) ", "", CalcFlags[i].simareas.L_[j][l],CalcFlags[i].err.L_[j][l]);
00189 }
00190
00191 for (j = 1; j <= 3; j++)
00192 if(XYldSums[i].M_[j] > 0.) {
00193 fprintf(stdout,"\n%10s (%2.2lfkeV)\t%le counts (cal=%.3le Flt=%.2le)",LineNm[5][j], LinesEnerArray[i].M_[j], XYldSums[i].M_[j],EffArray[i].M_[j],Filter.Trans[i].M_[j]);
00194 fprintf(stdout,"\n%10s \texp:\t%le counts (err=%.1le) ", "", CalcFlags[i].simareas.M_[j],CalcFlags[i].err.M_[j]);
00195 }
00196 }
00197 }
00198
00199
00200 #endif
00201
00202
00203
00204 if(ExtraInfo.WantOutputfile){
00205 fprintf(outputfile,"\n\n Ebeam=%lf IncAng=%lf DetAng=%lf \n",
00206 pExpPar->BeamEner, pExpPar->IncAng/DEG2RAD, pExpPar->DetAng/DEG2RAD);
00207 fprintf(outputfile,"\n Charge=%lf DTCC=%lf DetColFac=%lf\n",
00208 pExpPar->simpar.ColCharge, pExpPar->simpar.DTCC, pExpPar->DetColFac);
00209
00210 fprintf(outputfile,"\n\nIteration %d\n",NCALL);
00211
00212 for(i=0;i<NFoil;i++){
00213 fprintf(outputfile,"\nSample[%d] (%d elem)\n",i,Sample[i].nfoilelm);
00214 fprintf(outputfile,"\n---Eff. thickness=%.3le (%d sublyrs)\n",lyr[i+1].ThickIn,lyr[i+1].FESxlen);
00215
00216 for(j=0;j<Sample[i].comp.nelem;j++){
00217 fprintf(outputfile,"'%s'(Z=%d) X[%d]=%lf (%lfat%% / %lfM%%)\n",
00218 ChemicalSymbol[Sample[i].comp.elem[j].Z],Sample[i].comp.elem[j].Z,j,Sample[i].comp.X[j],100*Sample[i].comp.xn[j],100*Sample[i].comp.w[j]);
00219 }
00220 fprintf(outputfile,"\nFinal Energy in this layer=%lf keV\n\n",lyr[i+1].FoilOutEner);
00221 }
00222
00223 for(i=0;i<Filter.nlyr;i++){
00224 fprintf(outputfile,"\nFilter[%d] (%lf 1e15at/cm2) (%d elem) \n",i,Filter.foil[i].thick,Filter.foil[i].nfoilelm);
00225 for(j=0;j<Filter.foil[i].comp.nelem;j++){
00226 fprintf(outputfile,"(Z=%d) X[%d]=%lf (%lfat%% / %lfM%%)\n",
00227 Filter.foil[i].comp.elem[j].Z,j,Filter.foil[i].comp.X[j],100*Filter.foil[i].comp.xn[j],100*Filter.foil[i].comp.w[j]);
00228 }
00229 }
00230 for(i=0;i<dimSums;i++){
00231 if(i<=pSimPar->MaxZinsample && PresentElems[i]){
00232 fprintf(outputfile,"\n\n ************RESULTS for %s (Z=%d)\n",ChemicalSymbol[i],i);
00233
00234 for (j = 1; j <= 3; j++)
00235 if(XYldSums[i].K_[j] > 0.) {
00236 fprintf(outputfile,"\n%10s (%2.2lfkeV)\t%le counts (Eff=%.3le Flt=%.2le)", LineNm[1][j], LinesEnerArray[i].K_[j], XYldSums[i].K_[j],EffArray[i].K_[j],Filter.Trans[i].K_[j]);
00237 fprintf(outputfile,"\n%10s \texp:\t%le counts (err=%.1le) ", "", CalcFlags[i].simareas.K_[j],CalcFlags[i].err.K_[j]);
00238 }
00239
00240 for (j = 1; j <= 3; j++)
00241 for (l = 1; l <= 3; l++)
00242 if(XYldSums[i].L_[j][l] > 0.){
00243 fprintf(outputfile,"\n%10s (%2.2lfkeV)\t%le counts (cal=%.3le Flt=%.2le)", LineNm[j+1][l], LinesEnerArray[i].L_[j][l], XYldSums[i].L_[j][l],EffArray[i].L_[j][l],Filter.Trans[i].L_[j][l]);
00244 fprintf(outputfile,"\n%10s \texp:\t%le counts (err=%.1le) ", "", CalcFlags[i].simareas.L_[j][l],CalcFlags[i].err.L_[j][l]);
00245 }
00246
00247 for (j = 1; j <= 3; j++)
00248 if(XYldSums[i].M_[j] > 0.) {
00249 fprintf(outputfile,"\n%10s (%2.2lfkeV)\t%le counts (cal=%.3le Flt=%.2le)",LineNm[5][j], LinesEnerArray[i].M_[j], XYldSums[i].M_[j],EffArray[i].M_[j],Filter.Trans[i].M_[j]);
00250 fprintf(outputfile,"\n%10s \texp:\t%le counts (err=%.1le) ", "", CalcFlags[i].simareas.M_[j],CalcFlags[i].err.M_[j]);
00251 }
00252 }
00253 }
00254 }
00255
00256
00257
00258 freeReusable(NFoil,&lyr,&Sample,&XYldSums);
00259
00260 if(Filter.changes)freeFilter(&Filter);
00261
00262 }
00263
00264
00265 else if(NCALL==0){
00266
00267
00268
00269
00270
00271
00272
00273 readINPUT(inputfilename, pExpPar, &ExtraInfo);
00274
00276 if(!ExtraInfo.useefficiencies){
00277 fprintf(stderr,"\nERROR: The DATTPIXE calibration scheme is now deprecated. Use Efficiencies instead.\n");exit(1);}
00278
00279 readsample(ExtraInfo.SampleFileNm, &pSimPar->MaxZinsample, &NFoil, &Sample);
00280 readFilter(ExtraInfo.FilterFileNm, &Filter);
00281
00282 Filter.changes=1;
00283
00284 snprintf(fckfilename, FILENMLENGTH,"%sSC_PRA74.fck",ExtraInfo.DBpath);
00285 snprintf(abscoeffilename, FILENMLENGTH,"%sxabs.abs",ExtraInfo.DBpath);
00286 snprintf(xenerfilename, FILENMLENGTH,"%sxener.dat",ExtraInfo.DBpath);
00287
00288 #if CPIXEVERBOSITY > 0
00289 printf("\nInitializing. Reading databases...\n\n");
00290 printf("\nStopping Coefs DB: '%sSCOEF.95[A/B]'",ExtraInfo.DBpath);
00291 printf("\nAbsorption Coefs DB: '%s'",abscoeffilename);
00292 printf("\nFluorescence Coefs DB: '%s'",fckfilename);
00293 printf("\nX-ray Energies DB: '%s'",xenerfilename);
00294 printf("\nDetector Calibration DB: '%s'",ExtraInfo.CalibFileNm);
00295 printf("\nLines to calculate defined in: '%s'\n",ExtraInfo.AreasFileNm);
00296 #endif
00297
00298 createPresentElems(pSimPar->MaxZinsample, NFoil, Sample, &PresentElems);
00299 readCalcFlags(ExtraInfo.AreasFileNm, PresentElems, pSimPar->MaxZinsample, ExtraInfo.AreasFormat, &CalcFlags);
00300
00301
00302
00303
00304
00305
00306 readLinesEner(xenerfilename, PresentElems, pSimPar->MaxZinsample, &LinesEnerArray);
00307
00308
00309
00310
00311
00312
00313 readFCK(fckfilename, pSimPar->MaxZinsample,&FCKCoefArray);
00314
00315 readAbsCoef(abscoeffilename, pSimPar->MaxZinsample, &TotAbsCoefArray);
00316 createSPTs(ExtraInfo.DBpath,pExpPar, pSimPar->MaxZinsample, PresentElems, (double)(2*pExpPar->ion.A), &SPTArray);
00317
00318
00319 readEff3(ExtraInfo.CalibFileNm, PresentElems, pSimPar->MaxZinsample, LinesEnerArray, &EffArray);
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332 if(ExtraInfo.WantOutputfile){
00333 outputfile = fopen(ExtraInfo.OutputFileNm, "w");
00334 if(outputfile== NULL)
00335 {fprintf(stderr,"\nERROR: Could not open file '%s' for write.\n",ExtraInfo.OutputFileNm);exit(1);}
00336 fprintf(outputfile,"\nCPIXE Output File\n\n");
00337 fprintf(outputfile,"\nStopping Coefs DB: '%sSCOEF.95[A/B]'",ExtraInfo.DBpath);
00338 fprintf(outputfile,"\nAbsorption Coefs DB: '%s'",abscoeffilename);
00339 fprintf(outputfile,"\nFluorescence Coefs DB: '%s'",fckfilename);
00340 fprintf(outputfile,"\nX-ray Energies DB:'%s'",xenerfilename);
00341 fprintf(outputfile,"\nDetector Calibration DB: '%s'",ExtraInfo.CalibFileNm);
00342 fprintf(outputfile,"\nLines to calculate defined in: '%s'\n",ExtraInfo.AreasFileNm);
00343 }
00344 }
00345
00346 else if(NCALL<0){
00347
00348
00349 #if CPIXEVERBOSITY > 0
00350 printf("\nCleaning CPIXE Memory usage...\n\n");
00351 #endif
00352
00353
00354 if(!Filter.changes)freeFilter(&Filter);
00355
00356 for(i=1; i<=pSimPar->MaxZinsample ;i++){
00357 if(PresentElems[i]){
00358 free(SPTArray[i].S);
00359 free(SPTArray[i].E);
00360 free(SPTArray[i].dSdE);
00361 }
00362 }
00363 free(SPTArray);
00364 free(PresentElems);
00365 free(EffArray);
00366 free(LinesEnerArray);
00367 free(FCKCoefArray);
00368 free(TotAbsCoefArray);
00369 free(CalcFlags);
00370
00371
00372 if(ExtraInfo.WantOutputfile)fclose(outputfile);
00373 freeExtraInfo(&ExtraInfo);
00374
00375
00376 }
00377
00378
00379 lastNcall=NCALL;
00380
00381 #if CPIXEVERBOSITY > 0
00382 printf("\n\n\n************ END OF CPIXE OUTPUT ****************\n\n");
00383 #endif
00384
00385 return EXIT_SUCCESS;
00386 }
00387
00388
00389
00390
00391