/* All of the below was authored by me. By using any part of this source code, you agree to waive all liabilities from the author. Furthermore, you agree that you will not use this source code for personal (or corporate) gain. Finally, should you change any part of this source code, you agree to give credit to the author where such credit is due. */ #include #include #include #define pi atan2(0.,-1.) #define n 5120 void deblank (char *s); // " ABCD EF " --> "ABCD EF" void endnull (char *s); // Ensures strings end with nulls int main () { char outfile[n]; int h,k,l,count,exit; double theta,bragg, dhkl, wavelength, a, b, c, max_brag, min_brag; FILE *out; for(exit=1;exit;) { /* Get Lattice Parameters, and Wavelength of Monochromatic X-ray */ do{ printf("Enter Lattice Parameter 'a' (nm): "); scanf("%lf",&a); } while(a<0); do{ printf("Enter Lattice Parameter 'b' (nm): "); scanf("%lf",&b); } while(b<0); do{ printf("Enter Lattice Parameter 'c' (nm): "); scanf("%lf",&c);} while(c<0); do{ printf("Enter Wavelength 'lamda' (nm): "); scanf("%lf",&wavelength); } while (wavelength<0.); do{ printf("Min Desired Bragg Angle (degrees): "); scanf("%lf",&min_brag); } while (min_brag<0. && min_brag<=180.); do{ printf("Max Desired Bragg Angle (degrees): "); scanf("%lf",&max_brag); } while (max_brag Degrees bragg = 2*theta; if(bragg >= min_brag && bragg <= max_brag) { fprintf(out,"(%d%d%d)\t%lf\t%lf\n",h,k,l,dhkl,bragg); count++; } } } } } fprintf(out,"\n\n%d Planes diffract within desired range\nDesired Bragg Angle Range (Degrees):%lf - %lf",count,min_brag,max_brag); printf("Enter 0 to exit: "); scanf("%d",&exit); } return 0; } void deblank (char *s) { char *t=s; for(;*s!='\0';s++) ; s--; for (;*s==' ';s--) *s='\0'; for (s=t;*s==' ';s++) ; for (;*s!='\0';t++,s++) *t=*s; *t='\0'; return; } void endnull (char *s) { int i; for(i=0;i