77*
88* %I
99* Written by: Victor Laliena
10- * Date: 2018-2019
10+ * Date: 27.10.18 (last version, 09.07.19)
11+ * Version: $Revision: 0.1 $
1112* Origin: University of Zaragoza
1213*
1314* Component for simulating textured powder in Union components
@@ -250,7 +251,7 @@ double plgndr(int l, int m, double x)
250251 printf("Bad arguments in routine plgndr\n");
251252 printf("m: %d l: %d x: %f\n",m,l,x);
252253 printf("Exiting...\n");
253- exit(- 1);
254+ exit(1);
254255 }
255256 //Compute Pmm
256257 pmm=1.0;
@@ -304,27 +305,20 @@ struct legendre * initLegendre(int lmax)
304305 printf("initLegendre: negative lmax = %d\n",lmax);
305306 printf("Exiting...\n");
306307 fflush(stdout);
307- exit(- 1);
308+ exit(1);
308309 }
309310
310311 nlm = (lmax+1)*(lmax+1);
311312
312313 lgdr = (struct legendre *)malloc(sizeof(struct legendre));
313- if (!lgdr) {
314- fprintf(stderr,"Texture_process: Failed struct malloc() in initLegendre. Exit!\n");
315- exit(-1);
316- }
314+
317315 lgdr->lmax = lmax;
318316 lgdr->index = (int **)malloc((lmax+1)*sizeof(int *));
319317 lgdr->l = (int *)malloc(nlm*sizeof(int));
320318 lgdr->m = (int *)malloc(nlm*sizeof(int));
321319 lgdr->nplm = (int *)malloc(nlm*sizeof(int));
322320 lgdr->x = (double **)malloc(nlm*sizeof(double *));
323321 lgdr->Plm = (double **)malloc(nlm*sizeof(double *));
324- if (!lgdr->index || !lgdr->l || !lgdr->m || !lgdr->nplm || !lgdr->x || !lgdr->Plm) {
325- fprintf(stderr,"Texture_process: Failed malloc() in initLegendre. Exit!\n");
326- exit(-1);
327- }
328322 i = -1;
329323 for(l=0;l<=lmax;l++) {
330324 lgdr->index[l] = (int *)malloc((2*l+1)*sizeof(int));
@@ -401,14 +395,10 @@ double total_hkl_XS(double k, double kct, double kphi, struct hkl_data_texture *
401395 //printf("Exiting...");
402396 fflush(stdout);
403397 filep = fopen("negativeXS.txt","a");
404- if(filep) {
405- fprintf(filep,"%d %d %d %.6e %.6e %.6e %.6e %.6e %.6e %.6e\n",
406- L->h,L->k,L->l,L->Gx,L->Gy,L->Gz,k,kct,kphi,XS);
407- fclose(filep);
408- } else {
409- fprintf(stderr,"Texture_process/routine total_hkl_XS: failed fopen in add mode for file 'negativeXS.txt'. Exit!\n");
410- exit(-1);
411- }
398+ fprintf(filep,"%d %d %d %.6e %.6e %.6e %.6e %.6e %.6e %.6e\n",
399+ L->h,L->k,L->l,L->Gx,L->Gy,L->Gz,k,kct,kphi,XS);
400+ fclose(filep);
401+ //exit(1);
412402 }
413403
414404 // this is not the cross section. A different name (reflectivity??) would be appropriate
@@ -448,14 +438,9 @@ double total_hkl_XS_interp(double k, double kct, double kphi, struct hkl_data_te
448438 printf("total_hkl_XS: negative XS: %.6e\n",XS);
449439 fflush(stdout);
450440 filep = fopen("negativeXS.txt","a");
451- if(filep) {
452- fprintf(filep,"%d %d %d %.6e %.6e %.6e %.6e %.6e %.6e %.6e\n",
453- L->h,L->k,L->l,L->Gx,L->Gy,L->Gz,k,kct,kphi,XS);
454- fclose(filep);
455- } else {
456- fprintf(stderr,"Texture_process/total_hkl_XS_interp: failed fopen in add mode for file 'negativeXS.txt'. Exit!\n");
457- exit(-1);
458- }
441+ fprintf(filep,"%d %d %d %.6e %.6e %.6e %.6e %.6e %.6e %.6e\n",
442+ L->h,L->k,L->l,L->Gx,L->Gy,L->Gz,k,kct,kphi,XS);
443+ fclose(filep);
459444 }
460445
461446 // this is not the cross section. A different name (reflectivity??)
@@ -579,7 +564,7 @@ int computeV(struct fourier_coef *fc, struct legendre *lgdr, struct hkl_data_tex
579564 printf("computeV: negative lmax = %d\n",lmax);
580565 printf("Exiting...\n");
581566 fflush(stdout);
582- exit(- 1);
567+ exit(1);
583568 }
584569
585570 Gct = L->Gct;
@@ -899,10 +884,6 @@ int sampleKprime_hkl(double *kf, double *ki, struct hkl_data_texture *L, struct
899884 printf("find distribution probability in file sampleKprime_hkl_fail.txt\n");
900885 //sprintf(fn,"probPhiQ_%d%d%d.txt",L->h,L->k,L->l);
901886 filep = fopen("sampleKprime_hkl_fail.txt","w");
902- if(!filep) {
903- fprintf(stderr,"Texture_process/sampleKprime_hkl: failed fopen write mode for file 'sampleKprime_hkl_fail.txt'. Exit!\n");
904- exit(-1);
905- }
906887 //filep = fopen(fn,"a");
907888 fprintf(filep,"#Plane hkl: %d %d %d\n",L->h,L->k,L->l);
908889 fprintf(filep,"#Incoming neutron:\n");
@@ -925,7 +906,7 @@ int sampleKprime_hkl(double *kf, double *ki, struct hkl_data_texture *L, struct
925906 fclose(filep);
926907 printf("Exiting\n");
927908 fflush(stdout);
928- exit(- 1);
909+ exit(1);
929910}
930911
931912double probPhiq(double ctq, double phiq, struct hkl_data_texture *L, struct legendre *lgdr)
@@ -1318,10 +1299,6 @@ int read_hkl_data_texture(char *SC_file, struct hkl_info_struct_texture *info)
13181299
13191300 // print crystal info
13201301 filep = fopen("crystal.txt","w");
1321- if(!filep) {
1322- fprintf(stderr,"Texture_process: failed fopen write mode for file 'crystal.txt'. Exit!\n");
1323- exit(-1);
1324- }
13251302 fprintf(filep,"Direct lattice:\n");
13261303 fprintf(filep,"a: %f %f %f\n",info->m_ax,info->m_ay,info->m_az);
13271304 fprintf(filep,"b: %f %f %f\n",info->m_bx,info->m_by,info->m_bz);
@@ -1412,7 +1389,7 @@ void readFourierCoef(char *filename, struct fourier_coef *c)
14121389 printf("%s\n",filename);
14131390 printf("not found. Exiting...\n");
14141391 fflush(stdout);
1415- exit(- 1);
1392+ exit(1);
14161393 }
14171394
14181395 str[0]=0;
@@ -1443,7 +1420,7 @@ void readFourierCoef(char *filename, struct fourier_coef *c)
14431420 printf("with no spaces or other characters) is exactly");
14441421 printf(" present just above the data\n");
14451422 printf("Exiting...\n");
1446- exit(- 1);
1423+ exit(1);
14471424 }
14481425
14491426 np = 0;
@@ -1456,7 +1433,7 @@ void readFourierCoef(char *filename, struct fourier_coef *c)
14561433 printf("different than expected\n");
14571434 printf("lmax: %d np: %d nlines: %d\n",lmax,np,nlines);
14581435 printf("Exiting...\n");
1459- exit(- 1);
1436+ exit(1);
14601437 }
14611438
14621439 printf("readFourierCoef: lmax: %d np: %d nlines: %d\n",lmax,np,nlines);
@@ -1513,13 +1490,6 @@ void readFourierCoef(char *filename, struct fourier_coef *c)
15131490
15141491 // check reality of ODF
15151492 filep = fopen("coef_original.txt","w");
1516- if(!filep) {
1517- printf("readFourierCoef: fourier coefficient file\n");
1518- printf("%s\n",filename);
1519- printf("not found. Exiting...\n");
1520- fflush(stdout);
1521- exit(-1);
1522- }
15231493 rmax = 0;
15241494 for(l=0;l<=lmax;l++) {
15251495 for(m=-l;m<=l;m++) {
@@ -1582,10 +1552,6 @@ void readFourierCoef(char *filename, struct fourier_coef *c)
15821552 // print new coefficients
15831553 rmax = 0;
15841554 filep = fopen("coef_modified.txt","w");
1585- if(!filep) {
1586- fprintf(stderr,"Texture_process: failed fopen write mode for file 'coef_modified.txt'. Exit!\n");
1587- exit(-1);
1588- }
15891555 for(l=0;l<=lmax;l++) {
15901556 for(m=-l;m<=l;m++) {
15911557 for(n=-l;n<=l;n++) {
@@ -1670,7 +1636,7 @@ double interp(double x, int n, double *xp, double *yp)
16701636 printf("x[n-1] = %.16e\n",xp[n-1]);
16711637 printf("Exiting...\n");
16721638 fflush(stdout);
1673- exit(- 1);
1639+ exit(1);
16741640 }
16751641 i1 = 0;
16761642 i2 = n-1;
@@ -1686,7 +1652,7 @@ double interp(double x, int n, double *xp, double *yp)
16861652 printf("x[1] = %.16e\n",xp[1]);
16871653 printf("Exiting...\n");
16881654 fflush(stdout);
1689- exit(- 1);
1655+ exit(1);
16901656 }
16911657 return yp[i1]+((x-xp[i1])/(xp[i2]-xp[i1]))*(yp[i2]-yp[i1]);
16921658}
@@ -1705,7 +1671,7 @@ double interp2D(double x, double y, int nx, int ny, double *xp, double *yp, doub
17051671 } else {
17061672 printf("interp2D: bad i: %d, nx: %d x: %.16e y: %.16e\n",i,nx,x,y);
17071673 fflush(stdout);
1708- exit(- 1);
1674+ exit(1);
17091675 }
17101676 } else if(i>0 && x<xp[i]) {
17111677 i = i-1;
@@ -1717,7 +1683,7 @@ double interp2D(double x, double y, int nx, int ny, double *xp, double *yp, doub
17171683 } else {
17181684 printf("interp2D: bad j: %d, ny: %d x: %.16e y: %.16e\n",j,ny,x,y);
17191685 fflush(stdout);
1720- exit(- 1);
1686+ exit(1);
17211687 }
17221688 } else if(j>0 && y<yp[j]) {
17231689 j = j-1;
@@ -1735,7 +1701,7 @@ double interp2D(double x, double y, int nx, int ny, double *xp, double *yp, doub
17351701 printf("interp2D: bad t: %.6e, u: %.6e x: %f y: %f i: %d nx: %d\n",t,u,x,y,i,nx);
17361702 printf("%f %f %f\n",x,xp[i],xp[i+1]);
17371703 fflush(stdout);
1738- //exit(- 1);
1704+ //exit(1);
17391705 }
17401706 if(u<0 || u>1) {
17411707 printf("interp2D: bad u: %.6e, t: %.6e x: %f y: %f j: %d ny: %d\n",u,t,x,y,j,ny);
@@ -1745,7 +1711,7 @@ double interp2D(double x, double y, int nx, int ny, double *xp, double *yp, doub
17451711 printf("\n");
17461712 for(j=0;j<ny;j++) { printf("%f\n",yp[j]); }
17471713 fflush(stdout);
1748- exit(- 1);
1714+ exit(1);
17491715 }
17501716
17511717 return (1-t)*(1-u)*f1 + t*(1-u)*f2 + t*u*f3 + (1-t)*u*f4;
@@ -1842,16 +1808,12 @@ int initData(char *coef_fn, char *crystal_fn, struct hkl_info_struct_texture *in
18421808 printf("Exiting...\n");
18431809 fclose(filep);
18441810 fflush(stdout);
1845- exit(- 1);
1811+ exit(1);
18461812 }
18471813 Li->lv = (int *)malloc((Li->numV)*sizeof(int));
18481814 Li->mv = (int *)malloc((Li->numV)*sizeof(int));
18491815 Li->RV = (double *)malloc((Li->numV)*sizeof(double));
18501816 Li->phiV = (double *)malloc((Li->numV)*sizeof(double));
1851- if (!Li->lv || !Li->mv || !Li->RV || !Li->phiV) {
1852- fprintf(stderr,"Texture_process / initData: Failed malloc(s). Exit!\n");
1853- exit(-1);
1854- }
18551817 for(j=0;j<Li->numV;j++) {
18561818 fscanf(filep,"%d %d %d %d %d %d %lf %lf",
18571819 &lm,&hm,&km,&jj,(Li->lv)+j,(Li->mv)+j,(Li->RV)+j,(Li->phiV)+j);
@@ -1864,7 +1826,7 @@ int initData(char *coef_fn, char *crystal_fn, struct hkl_info_struct_texture *in
18641826 printf("Exiting...\n");
18651827 fclose(filep);
18661828 fflush(stdout);
1867- exit(- 1);
1829+ exit(1);
18681830 }
18691831 }
18701832 }
@@ -2184,7 +2146,7 @@ int Texture_physics_scattering(double *k_final, double *k_initial, double *weigh
21842146 printf("%d %.6e %.6e\n",i,cumProb_hkl[i],r);
21852147 }
21862148 fflush(stdout);
2187- exit(- 1);
2149+ exit(1);
21882150 }
21892151
21902152 // sampling kprime
@@ -2263,7 +2225,7 @@ INITIALIZE
22632225 if ( initData(fcoef_fn, crystal_fn, &hkl_info_texture, maxNeutronSaved) ) {
22642226 printf("Texture_process: %s: Error in initData: Aborting.\n", NAME_CURRENT_COMP);
22652227 fflush(stdout);
2266- exit(- 1);
2228+ exit(1);
22672229 }
22682230
22692231 // precomputed factors
@@ -2354,15 +2316,11 @@ struct hkl_info_struct_texture *hkl_info
23542316printf("numReused: %.6e\n",hkl_info->numReused);
23552317// print rejection statistics
23562318FILE *filep = fopen("rejectioStatistics.txt","w");
2357- if (!filep) {
2358- struct hkl_data_texture *L = hkl_info->list;
2359- for(i=0;i<hkl_info->num_hkl;i++) {
2360- fprintf(filep,"%d %d %d %.6e %.6e\n",L[i].h,L[i].k,L[i].l,L[i].numReject,L[i].numScatt);
2361- }
2362- fclose(filep);
2363- } else {
2364- fprintf("Texture_process %s WARNING: Failed to open file 'rejectioStatistics.txt' in write mode. No data saved!\n", NAME_CURRENT_COMP);
2365- }
2319+ struct hkl_data_texture *L = hkl_info->list;
2320+ for(i=0;i<hkl_info->num_hkl;i++) {
2321+ fprintf(filep,"%d %d %d %.6e %.6e\n",L[i].h,L[i].k,L[i].l,L[i].numReject,L[i].numScatt);
2322+ }
2323+ fclose(filep);
23662324// deallocate allocated memory, etc.
23672325free_texture(hkl_info);
23682326%}
0 commit comments