int read_list(char *basepath, const char *filename) { size_t len = 0; FILE *f = NULL; char * line = NULL; int confLidas, revsLidas, confsRej, revsRej; confLidas = 0; revsLidas = 0; confsRej = 0; revsRej = 0; int naut = 0; char *absolute = NULL; absolute = (char *) malloc(sizeof (char) *(strlen(basepath) + strlen(filename))); strcat(absolute, basepath); strcat(absolute, filename); initTA(); f = fopen(absolute, "r"); if (f != NULL) { line = (char *) calloc(MAX_CHAR, sizeof (char)); line = fgets(line, MAX_CHAR, f); min_pag = atoi(line); do { line = (char *) calloc(MAX_CHAR, sizeof (char)); line = fgets(line, MAX_CHAR, f); if (line != NULL) { len = strlen(line); if (line[len - 1] == '\n') line[len - 1] = '\0'; absolute = (char *) malloc(sizeof (char) * (strlen(basepath) + len)); clear_str(absolute, strlen(basepath) + len); strcat(absolute, basepath); strcat(absolute, line); if (line[0] == 'c') confLidas += readC(absolute, &confsRej); if (line[0] == 'j') revsLidas += readJ(absolute, &revsRej); } } while (line != NULL && line != "" && !feof(f)); fclose(f); } if (absolute != NULL) { free(absolute); absolute = NULL; } free(line); logStats(confLidas, revsLidas, confsRej, revsRej); return 0; }
void compFlux(float *arr, double L, int k, char *dir) { FILE *QPtr, *NPtr; int ei, ti, i, li, nout, iofEbot; double mag, P, Q, epsm, alpha_eq, v, crunch, gamma; double I=0.0, x, g, field, Phi_p, b=1.0, vcm, fcgs; double v_tot_arr[NUM_E], E_tot_arr[NUM_E], dE_arr[NUM_E]; double Jdiff[NUM_E], long_reduce; float alpha, J[100][100], *arrtmp, *Qarr, *Narr; char *NS, QFile[128], NFile[128]; // Open up Phi, Q, N file for writing if(k==0) {NS = "N";} else {NS="S";} sprintf( QFile, "%s/QLong_%g_%s", dir, L, NS ); sprintf( NFile, "%s/NLong_%g_%s", dir, L, NS ); printf("Calculating Q, N for L = %g, E > %g", L, E_MIN); NUM_LONGS = (int) (LONG_TOP - LONG_BOT)/DLONG; if(E_MIN < 1e-3) { iofEbot = 0; } else { // remember E_MIN is in KeV iofEbot = floor((log10(E_MIN*1000)-E_EXP_BOT)/DE_EXP); } arrtmp = getArr(NUM_E, NUM_TIMES); Qarr = getArr( NUM_LONGS, NUM_TIMES ); Narr = getArr( NUM_LONGS, NUM_TIMES ); if( (QPtr=fopen(QFile, "w"))==NULL ) { printf("\nProblem opening %s\n", QFile); exit(0); } if( (NPtr=fopen(NFile, "w"))==NULL ) { printf("\nProblem opening %s\n", NFile); exit(0); } epsm = (1/L)*(R_E+H_IONO)/R_E; crunch = sqrt(1+3*(1-epsm))/pow(epsm,3) ; alpha_eq = asin(sqrt( 1/crunch )); readJ(J); // Precalculate energy and velocity values for(i=0; i<NUM_E; i++) { //Energy in eV E_tot_arr[i] = pow(10, (E_EXP_BOT+(DE_EXP/2)+DE_EXP*i) ); // Energy differential dE in keV dE_arr[i] = 1e-3 * pow(10, (E_EXP_BOT+ (DE_EXP/2))) * exp(DE_EXP*i / log10(NAPe)) * DE_EXP / log10(NAPe); // Differential flux @ this Energy Jdiff[i] = getJdiff( J, E_tot_arr[i], alpha_eq ); // Velocity corresponding to this Energy v_tot_arr[i] = C*sqrt(1 - pow( (E_EL/(E_EL+E_tot_arr[i])) ,2) ); } printf("\n"); for(li=0; li < NUM_LONGS; li++) { // loop over longitudes long_reduce = reduceFactor( li*DLONG ); printf("Now doing long: %g\n", li*DLONG); for(ei=0; ei<NUM_E; ei++) { if(SQUARE) { v = v_tot_arr[ei]; vcm = v*100; // v in cm for distrib fn calculation gamma = 1/sqrt( 1 - v*v/(C*C) ); fcgs = 4.9e5/pow( (vcm*gamma) ,4) - 8.3e14/pow( (vcm*gamma) ,5) + 5.4e23/pow( (vcm*gamma) ,6); // fcgs = 7.034e26 / pow(vcm,6); //10^8/E^2 distribution b = (v*v/M_EL)*pow( sqrt(1 - (v*v)/(C*C)), 3) * 1.6e-8 * fcgs; // b = 1e8 / pow(E_tot_arr[i],2); } else { b = Jdiff[ei]*1000; } for(ti=0; ti<NUM_TIMES; ti++) { alpha = long_reduce * arr[ei*NUM_TIMES+ti] ; mag = 1.4142135623731*alpha; // sqrt(2)*alpha_RMS = peak P = mag/2; //[ alpha_lc - (alpha_lc-mag) ] /2 Q = alpha_eq - mag/2; //[ alpha_lc + (alpha_lc-mag) ] /2 I = 0.0; if(mag > 1e-8 && mag < 1) { for(i=0; i<5; i++) { x = P*t5[i] + Q ; if(SQUARE) { g = (P/PI)*sin(2*x)*( asin((x-alpha_eq)/mag)+ (PI/2) ); } else { g = (P/PI)*sin(2*x)*((x - alpha_eq) * ( asin((x-alpha_eq)/mag)+ (PI/2) ) + sqrt(mag*mag-pow((x-alpha_eq),2))); } I += ( beta5[i]*g ); } // for(i ... ) -> Gauss quad integration } // if mag != 0 Phi_p = PI*crunch*b*I; if(Phi_p<0) { printf("\nPhi_p<0, at ti: %d, ei: %d, li: %d, NS: %s, L: %g\n", ti,ei,li, NS, L_TARG); printf("PI: %g, crunch: %g, b: %g, I: %g, alpha: %g\n", PI, crunch, b, I, alpha); Phi_p = 0; } if( isnan(Phi_p) ) { printf("\nPhi_p isnan, at ti: %d, ei: %d, li: %d, NS: %s, L: %g\n", ti,ei,li, NS, L_TARG); printf("PI: %g, crunch: %g, b: %g, I: %g, alpha: %g\n", PI, crunch, b, I, alpha); Phi_p = 0; } // Now do the integration to get Q and N if(ei >= iofEbot) { Qarr[li*NUM_TIMES+ti] += (float)( Phi_p * E_tot_arr[ei] * dE_arr[ei] * 1.602e-9); Narr[li*NUM_TIMES+ti] += (float)( Phi_p * dE_arr[ei]); //eV->keV } } // for(ti ... ) } // for(ei ... ) } //li nout=fwrite(Qarr, sizeof(float), (NUM_LONGS*NUM_TIMES), QPtr); if(nout!=NUM_LONGS*NUM_TIMES) printf("\n\aProblem writing Q\n"); nout=fwrite(Narr, sizeof(float), (NUM_LONGS*NUM_TIMES), NPtr); if(nout!=NUM_LONGS*NUM_TIMES) printf("\n\aProblem writing N\n"); fclose(QPtr); fclose(NPtr); }