/*Reads CORSIKA longitudinal files*/ #include #include #include #include FILE *inputfile; FILE *outputfile; char line[500]; char ch; char str_file_in[50]; char str_file_out[50]; char str1[50],str2[50],str3[50],str4[50],str5[50],str6[50],str7[50],str8[50],str9[50],str10[50],str11[50],str12[50]; int ishower=0,nsteps; float step; float depth[205],gammas[205],positrons[205],electrons[205],mu_plus[205],mu_minus[205],hadrons[205],charged[205],nuclei[205],cherenkov[250]; float sgammas[205]={205*0.},spositrons[205]={205*0.},selectrons[205]={205*0.},smu_plus[205]={205*0.},smu_minus[205]={205*0.},shadrons[205]={205*0.},scharged[205]={205*0.},snuclei[205]={205*0.},scherenkov[250]={205*0.}; float dgammas[205]={205*0.},dpositrons[205]={205*0.},delectrons[205]={205*0.},dmu_plus[205]={205*0.},dmu_minus[205]={205*0.},dhadrons[205]={205*0.},dcharged[205]={205*0.},dnuclei[205]={205*0.},dcherenkov[250]={205*0.}; float ex[205]={205*0.}; float depth_ed[205],gamma_ed[300],em_ion[300],em_cut[300],mu_ion[300],mu_cut[300],had_ion[300],had_cut[300],neutrino[300],sum[300]; int i; float p1,p2,p3,p4,p5,p6; float chi2dof,avdev; main() { printf("Enter DATxxxxxx file code (6 digits)\n"); gets(str1); strcpy(str_file_in,"DAT"); strcat(str_file_in,str1); strcat(str_file_in,".long"); strcpy(str_file_out,"OUT"); strcat(str_file_out,str1); strcat(str_file_out,str1); inputfile=fopen(str_file_in,"r"); if (inputfile==NULL) { (void)printf("Can't open inputfile %s\n",str_file_in); return 0;} outputfile=fopen(str_file_out,"w"); if (outputfile==NULL) { (void)printf("Can't open outputfile %s\n",str_file_out); return 0;} (void)fprintf(outputfile,"# %s\n",str_file_in); while (1){ ch=fgetc(inputfile); if (ch==EOF){ (void)printf("%d showers analyzed\n",ishower); (void)fprintf(outputfile,"# EOF\n %d showers analyzed\n",ishower); break;} (void)ungetc(ch,inputfile); (void)fgets(line,sizeof(line),inputfile); (void)sscanf(line,"%s %s %s %s %s %s %s %s %s",&str1,&str2,&str3,&str4,&str5,&str6,&str7,&str8,&str9); // if (ishower<=10){(void)printf("%s \n",str1);} if ((strcmp(str1,"LONGITUDINAL")==0)&&(strcmp(str2,"DISTRIBUTION")==0)&&(strcmp(str3,"IN")==0)){ nsteps=atoi(str4); step=atof(str8); //ishower=atoi(str12); ishower++; //if (ishower<=10){(void)printf("nsteps=%d step=%f ishower=%d \n",nsteps,step,ishower);} (void)fprintf(outputfile,"# SHOWER %d\n# Longitudinal particle distribution for %d levels:\n",ishower,nsteps); (void)fgets(line,sizeof(line),inputfile); for(i=0;i