//3456789012345678901234567890123456789012345678901234567890123456789012 // * -----XRAYACSc.cpp----- * // ********************************************************************* #include #include #include #include #include #include #include #include #include #define NN 10 // Number of possible Intensity Controls (for DRDACS) #define NNN 200 // Number of possible measurement for each Control (DRDACS) int intro1(); int helpcad(); // Function Prototypes. int helpdrd(); // Since these functions come after they are int helpabs(); // called for, these prototypes are needed. int helpfof(); int cadacs(char file1[16]); int drdacs(char file1[16], int power); int absacs(char file1[16], int power); int fofabs(char file1[16], int power); int findrun(char file[16], int run[4]); int capitalise(char letter); int help(); // Function Prototypes from MAKEINS int getfile(char file[16]); int makedir(char file[16]); int copydata(char file[16]); int copydrd(char file[16]); int makecel(char file[16]); int makeins(char file[16]); int main() { char file[16]; // constant, unchanged first part of input filename char file1[16]; // input file passed to Functions (gets changed) // So before each Function it is reassigned using 'file' int power=0; // 1 for F and 2 for F^2 char powerans; // reads the answer as character and finds the power // otherwise, character input leads to looping!!! int run[4]={0,0,0,0}; struct time tt; struct date dd; gettime(&tt); getdate(&dd); int hour = toascii(tt.ti_hour); int minute = toascii(tt.ti_min); int day = toascii(dd.da_day); int month = toascii(dd.da_mon); cout << "\n\tCurrent Time is: " << hour << ":"; if (minute<10) cout <<"0"; // otherwise it writes like 12:1 for 12:01 cout << minute << " on " << day << "-" << month << "-" << dd.da_year << endl; intro1(); //prints the program name and functions.... getfile(file); makedir(file); makecel(file); copydata(file); copydrd(file); findrun(file,run); // QUESTIONS AND ANSWERS TO FIND F or F^2 if(run[1] ==1 || run[2] ==1 || run[3] ==1) { power1: powerans=NULL; cout << "DO YOU WANT TO OUTPUT F OR F^2? (1=F^1, 2=F^2): "; cin >> powerans; if (powerans=='1') power=1; if (powerans=='2') power=2; if (power != 1 && power !=2) goto power1; } if (run[0]==1) {strcpy(file1,file); cadacs(file1);} if (run[1]==1) {strcpy(file1,file); drdacs(file1,power);} if (run[2]==1) {strcpy(file1,file); absacs(file1,power);} if (run[3]==1) {strcpy(file1,file); fofabs(file1,power);} makeins(file); return 0; }//end of MAIN function //********************************************************************** int getfile(char file[16]) { char answer[4]; askagain: answer[0]='0'; cout << "Do you want to run the XRAYACS program for a X-Ray data? [Y/N/H]: "; cin >> answer; answer[0]=capitalise(answer[0]); if (answer[0] == 'N' || answer[0] == 'S' || answer[0]=='Q') exit(0); if (answer[0] == 'H' || answer[0] == '?') {help(); goto askagain; } if (answer[0] != 'Y') goto askagain; getagain: cout << "\nPlease choose a name for this X-Ray data: "; cin >> file; if(strlen(file) > 11) {cout << "Please use less than 11 characters! "; goto getagain;} if(file[0] < 65 || file[0] > 122) {cout << "Please use only english characters for first letter! "; goto getagain;} if(file[0] > 90 && file[0] < 97) {cout << "Please use only english characters for first letter! "; goto getagain;} for (unsigned int i=1; i 122) {cout << "Please use only english characters and numbers! "; goto getagain;} if(file[i] > 57 && file[i] < 65) {cout << "Please use only english characters and numbers! "; goto getagain;} if(file[i] > 90 && file[i] < 97) {cout << "Please use only english characters and numbers! "; goto getagain;}} cout << endl; return 0; } //********************************************************************** int makedir(char file[16]) { char infofile[16]; char answer[4]; askagain: answer[0]='0'; cout << "Do you want to create and/or change to folder [/CRY/" << file << "] ?[Y/N]: "; cin >> answer; answer[0]=capitalise(answer[0]); if (answer[0] == 'N' || answer[0] == 'S' || answer[0]=='Q') return 0; if (answer[0] != 'Y') goto askagain; cout << "\n ***** MAKING a NEW Folder ..... ***** \n"; if(!chdir("/cry")) {mkdir("/cry", S_IWUSR); chdir("/cry"); } // S_IWUSR is a (mode) dummy in DOS if(mkdir(file, S_IWUSR)) { // if can not make new, complain ! cout << "WARNING: Folder ["<< file << "] already exists in /CRY folder! Using this!\n"; } chdir(file); strcpy(infofile,file); strcat(infofile,".out"); ofstream fout(infofile); cout << "\n PLEASE SEE THE FILE [" << infofile << "] FOR SOME MORE USEFUL INFORMATION.\n"; fout << "The chosen name for the current X-Ray data is : " << file << endl<> FF; if (FF == 1.0) FF=21.586; cout << "Please input the Monochromator Angle [1=6.00]: "; cin >> MA; if(MA == 1.0) MA = 6.00; cout << "Please input the X-Ray Wave Length [1=0.71073; 1=Mo, 2=Cu]: "; cin >> WL; if(WL==1.0) WL=0.71073; if(WL==2.0) WL=1.5418; askcell: cout << "Please input the cell lengths (in "<> AA >> BB >> CC; if (AA < 1.0 || BB < 1.0 || CC < 1.0) {cout << "Too small cell!!! Give better values!"; goto askcell;} askangle: cout << "Please input the cell angles (in "<> AL >> BE >> GA; if (AL < 10.0 || BE < 10.0 || GA < 10.0) {cout << "Too narrow angles!!! Give better values!"; goto askangle;} if (AL > 170.0 || BE > 170.0 || GA > 170.0) {cout << "Too wide angles!!! Give better values!"; goto askangle;} cout << "Please input the number of Intensity Controls used : "; cin >> nint; nint=abs(nint); fout << FF << " " << MA << " " << WL << " " << AA << " " << BB << " " << CC << " " << AL << " " << BE << " " << GA << " " << nint << endl; fout.close(); return 0; } // ******************************************************************** int copydata(char file[16]) { char filedat1[18]="A:",filedat2[16]; char answer[4], ch[64]; strcpy(filedat2,file); strcat(filedat2,".dat"); cout << endl; askagain: answer[0]='0'; cout << "Do you want to copy the [" <> answer; answer[0]=capitalise(answer[0]); if (answer[0] == 'N' || answer[0] == 'S' || answer[0]=='Q') return 0; if (answer[0] != 'Y') goto askagain; strcat(filedat1,filedat2); ifstream fin(filedat1); if(!__file_exists(filedat1)) {cout << "File [" << filedat1 << "] not found !!! "; return 0;} if(__file_exists(filedat2)) {cout << "File [" << filedat2 << "] already exists !!! \n "; cout << "OVERWRITE?[Y/N]"; answer[0]='0'; cin >> answer; if(answer[0] != 'Y' && answer[0] != 'y') return 0;} ofstream fout(filedat2); while (fin.getline(ch, 64)) {fout << ch << endl;} fin.close(); fout.close(); return 0; } // ******************************************************************** int copydrd(char file[16]) { char filedrd1[18]="A:",filedrd2[16]; char answer[4], ch[51]; strcpy(filedrd2,file); strcat(filedrd2,".drd"); cout << endl; askagain1: answer[0]='0'; cout << "Do you want to copy the [" <> answer; answer[0]=capitalise(answer[0]); if (answer[0] == 'N' || answer[0] == 'S' || answer[0]=='Q') return 0; if (answer[0] != 'Y') goto askagain1; strcat(filedrd1,filedrd2); ifstream fin(filedrd1); if(!__file_exists(filedrd1)) {cout << "File [" << filedrd1 << "] not found !!! "; return 0;} if(__file_exists(filedrd2)) {cout << "File [" << filedrd2 << "] already exists !!! \n "; cout << "OVERWRITE?[Y/N]"; answer[0]='0'; cin >> answer; if(answer[0] != 'Y' && answer[0] != 'y') return 0;} ofstream fout(filedrd2); while (fin.getline(ch, 51)) {fout << ch << endl;} fin.close(); fout.close(); return 0; } // ******************************************************************** int findrun(char file[16], int run[4]) { char answer[4]; // Y/N/H answer for question about CADACS // QUESTIONS AND ANSWERS TO FIND WHICH PROGRAMS TO RUN char * program[4]={"CADACS","DRDACS","ABSACS","FOFABS"}; cout << endl; for (int i=0; i<4; i++) { askagain: answer[0]='0'; cout << "Do you want to run " << program[i] << " program? [Y/N/H]: "; cin >> answer; answer[0]=capitalise(answer[0]); if (answer[0] == 'S' || answer[0]=='Q') exit(0); if (answer[0] == 'H' || answer[0] == '?') {if (i==0) helpcad(); if (i==1) helpdrd(); if (i==2) helpabs(); if (i==3) helpfof(); goto askagain; } if (answer[0] == 'Y') {run[i]=1; goto endi;} if (answer[0] != 'N') goto askagain; endi: ;} return 0; } //********************************************************************** // ***** The FUNCTION of CADACS begins ***** int cadacs(char file1[16]) { char file2[16]; // output file char infofile[16]; char check; // character 25/26 to be checked for N or I char wcheck; // character 28/29 to be checked for W char ch[63]; // read 63 characters in each line as variable 'ch' short int line=0; // count number of lines written to the output file short int ncheck=25; // check character 25 at first (goes upto 30) short int nwrite=0; // used in skipping (0 for ncheck=25, 1 for 26...) short int nweak=0; // starting number of weak data is set to zero float ratio; // Ratio declared as floating point number strcpy(file2,file1); strcpy(infofile,file1); strcat(file2,".drd"); strcat(file1,".dat"); strcat(infofile,".out"); FILE * outputfile=fopen(infofile, "a"); cout << "\n ***** DOING CADACS..... ***** \n"; cout << "\tInput file is : " << file1 << endl; cout << "\tOutput file is: " << file2 << endl < 5) { cout << "!!! WARNING: No lines written to the output file !!! \n"; cout << (char) 7; goto error; // makes bell sound & stops after 5 attempts } ncheck++; nwrite++; fin.open(file1); goto recheck; //check next characters } fout.close(); ratio=(line-nweak)*100.0/line; cout << "Number of reflections written in the output file: " << line << endl; cout << "Number of declared weak reflections: " << nweak << endl; cout << "Observed/Total reflections ratio = "; printf ("%5.2f", ratio); cout << " %" << endl << endl; cout << " ***** CADACS COMPLETED. ***** \n\n"; fprintf(outputfile, "Number of reflections written in the output file: %4i\n", line); fprintf(outputfile, "Number of declared weak reflections: %4i\n", nweak); fprintf(outputfile, "Observed/Total reflections ratio = %5.2f %% \n\n", ratio); fprintf(outputfile, " ***** CADACS COMPLETED. ***** \n\n"); fclose(outputfile); error: cout << (char) 7; // makes bell sound return 0;} // ***** The FUNCTION of CADACS ends ***** // ******************************************************************** // ***** The FUNCTION of DRDACS begins ***** int drdacs(char file1[16], int power) { char file2[16]; // input CELL data file char file3[16]; // output file char infofile[16], answerexp; char CODE1, CODE2, CODE3, CODE4, CODE5, CODE6; char * AMES="*** OMIT THIS REFLECTION ***"; int scaleoption; int MI=1, NI=1, NC, II, NREF=0, NREF1=0, NREF2=0; int REF_NUMBER, NWEAK=0, IALL=0, MMAX, IMAX; int NMAX[NNN],HST[NN],KST[NN],LST[NN],NSECT[NNN], H, K, L; float FF, MA, WL, AA, BB, CC, AL, BE, GA; float SPEED,LEFT,COUNTS,RIGHT, BRR, SCALED; float SI[NNN][NN],SCALE1[NNN],SCALE[NNN],TSI[NN],ASCAL[NN], ESD; float ALL=0.0, TN=0.0; float RAD, COSA, COSB, COSG, SINA, SINB, SING, DD, AST, BST, CST, DH, DK, DL, MAC1; float SINTH, SINTH1, SINTH2, SIN2T, COSTH, COS2T, MAC2, SLP, FSQ, SIGF2; float SIGF, INTENSITY, SIGMA, TXTAL; float meandecay=0.0, finaldecay=0.0, DECAY; float BSCALE, BSCALE1,RDECAY,WRONG; strcpy(file2,file1); strcpy(file3,file1); strcpy(infofile,file1); strcat(file1,".cel"); strcat(file2,".drd"); strcat(infofile,".out"); if (power==1) strcat(file3,".ff1"); else strcat(file3,".hkl"); cout << "\n ***** DOING DRDACS..... ***** \n"; cout << "\tInput file1 is: " << file1 << endl; cout << "\tInput file2 is: " << file2 << endl; cout << "\tOutput file is: " << file3 << endl <> FF >> MA >> WL >> AA >> BB >> CC >> AL >> BE >> GA; if(!(fin >> IMAX)) {cout << "Please include the Number of Intensity Controls in the [" << file1 << "] file.\n"; abort(); } cout << "Filter Factor = \t\t" << FF << endl; cout << "Monochromator Angle = \t\t" << MA << " " << char(248) << endl; cout << "X-Ray WaveLength = \t\t" << WL << " " << char(143) << endl; cout << "Number of Intensity Controls = \t" << IMAX << endl << endl; cout << "The cell parameters are :" << endl; cout << "\tA = " << AA << "; B = " << BB << "; C = " << CC << " " << char(143) << endl; cout << "\t" << char(224) <<" = " << AL << "; " << char(225) << " = " << BE; cout << "; " << char(226) << " = " << GA << " " << char(248) << endl << endl; fout << "Filter Factor = \t\t" << FF << endl; fout << "Monochromator Angle = \t\t" << MA << " " << char(248) << endl; fout << "X-Ray WaveLength = \t\t" << WL << " " << char(143) << endl; fout << "Number of Intensity Controls = \t" << IMAX << endl << endl; fout << "The cell parameters are :" << endl; fout << "\tA = " << AA << "; B = " << BB << "; C = " << CC << " " << char(143) << endl; fout << "\t" << char(224) <<" = " << AL << "; " << char(225) << " = " << BE; fout << "; " << char(226) << " = " << GA << " " << char(248) << endl << endl; if(AA <1.0 || BB < 1.0 || CC < 1.0) { cout << " PLEASE CHECK THE INPUT FILE " << file1 << " and RERUN AGAIN!" <> REF_NUMBER >> H >> K >> L >> CODE1 >> CODE2 >> CODE3 >> CODE4 >> CODE5 >> CODE6; fin >> SPEED >> LEFT >> COUNTS >> RIGHT; if(H == 999 && K == 999 && L == 999) goto READINGSDONE1; if(H == 999) goto FIRSTREADING; if(H == 0 && K == 0 && L == 0) goto FIRSTREADING; if (SPEED == 0.0) goto ERROR1; NC=1; // used in checking if the intensity control belongs to next set of measurements. NREF=NREF+1; // Total count of Reflections; the final number IS used later. NSECT[MI]=NSECT[MI]+1; // Count of reflections in each section if(CODE1 != 'I') goto FIRSTREADING; if(MI == 1) {HST[NI]=H; KST[NI]=K; LST[NI]=L; } PREVIOUS1: // 105 CONTINUE if(H != HST[NI] || K != KST[NI] || L != LST[NI]) goto NEXT1; if(SPEED == 0.0) goto ERROR1; if (SPEED < 0.0) SPEED=fabs(SPEED/FF); INTENSITY=(COUNTS-2*(LEFT+RIGHT))/SPEED; SI[MI][NI]=INTENSITY; ALL=ALL+1.0; // ALL is the total number of control set measurements (1-600) NI=NI+1; // NI is the number of the control reflection within the set (1-10) if(NI < IMAX+1) goto FIRSTREADING; NMAX[MI]=ALL; TN=TN+ALL; ALL=0.0; NI=1; MI=MI+1; NSECT[MI]=0; goto FIRSTREADING; NEXT1: //115 CONTINUE SI[MI][NI]=0.0; NI=NI+1; if(NI < IMAX+1) goto PREVIOUS1; MI=MI+1; NI=1; NC=NC+1; if(NC == 2) goto PREVIOUS1; ERROR1: cout << "ERROR !!!; CHECK LINE NUMBER " << NREF+1 << " IN FILE: "<< file2 << endl; cout << "Check, Correct and RERUN AGAIN!\n"; exit(0); READINGSDONE1: // 110 CONTINUE END-OF-FILE SENDS HERE MMAX=MI-1; if(NI < IMAX+1 && NI > 1) MMAX=MI; ALL=0.0; for (NI=1; NI < IMAX+1; NI++) { // from this point, NI & MI are fresh; TSI[NI]=0.0; for (MI=1; MI < MMAX+1; MI++) { if(SI[MI][NI] > 0.0) {TSI[NI]=TSI[NI]+SI[MI][NI]; ALL=ALL+1.0;}} ASCAL[NI]=TSI[NI]/ALL; ALL=0.0; } fout << " VARIATION ANALYSIS OF INTENSITY CONTROL REFLECTIONS\n"; fout << " H K L VARIATION DECAY(?) No. of DATA Mean Intensity\n"; //This LOOP is only to print the decay values, not used in calculations. for (NI=1; NI < IMAX+1; NI++) { ESD=0.0; II=0; // II is used in counting I-ALL for (MI=2; MI < MMAX+1; MI++) { if(SI[MI][NI] > 0) {ESD=ESD+fabs(1.0-SI[MI][NI]/ASCAL[NI]); II=II+1; }} ESD=ESD*100.0/II; meandecay=meandecay+ESD; DECAY=(SI[1][NI]-SI[MMAX][NI])/SI[1][NI]*100; finaldecay=finaldecay+DECAY; IALL=IALL+II+1; fout.setf(ios::right); fout.width(4); fout << HST[NI]; fout.width(4); fout << KST[NI]; fout.width(4); fout << LST[NI] << " "; fout.setf(ios::left); fout.width(8); fout << ESD << " % "; fout.width(9); fout << DECAY << " % "; fout.width(4); fout << II+1 << " "; fout.width(8); fout << ASCAL[NI] << endl; //fout << " " << HST[NI] << " " << KST[NI] << " " << LST[NI] << " " << ESD; //fout << " % " << DECAY << " % " << II+1 << " " << ASCAL[NI] << endl; } if(NREF < 1) NREF=1; scaleoption=0; meandecay=meandecay*2.0/IMAX; finaldecay=finaldecay/IMAX; cout << " Linear Mean Decay = " << meandecay << " % ; Final Decay = "; cout << finaldecay << " %.\n"; fout << " Linear Mean Decay = " << meandecay << " % ; Final Decay = "; fout << finaldecay << " %.\n\n"; if(meandecay > 10.0) { meandecay=meandecay/100.0; TXTAL=1.0-(finaldecay/100.0); TXTAL=log(1.0/TXTAL); cout << "\n The default DECAY CORRECTION is linear between two\n"; cout << " Controls. Use the default for MULTI-XTAL DATA.\n"; cout << " Do you want EXPONENTIAL DECAY CORRECTION? [Y/N]:"; cin >> answerexp; cout << endl; if(answerexp == 'Y' || answerexp == 'y') scaleoption=1; } ALL=0.0; BSCALE=0.0; // BSCALE is regional/batch scale for correction. SCALE1[0]=0.0; SCALE[0]=0.0; for (MI=1; MI < MMAX+1; MI++) { for (NI=1; NI < IMAX+1; NI++) { if(SI[MI][NI] > 0) { BSCALE=BSCALE+1.0-SI[MI][NI]/SI[1][NI]; ALL=ALL+1.0; }} SCALE1[MI]=BSCALE/ALL; SCALE[MI]=SCALE1[MI]-SCALE1[MI-1]; WRONG=(-1.0)*ALL; if(SCALE[MI] == WRONG) SCALE[MI]=0.0; RDECAY=SCALE[MI]*100.0; if (MI > 1) { fout << " DECAY WITHIN TWO INTENSITY CONTROLS = " << RDECAY << " %\n"; fout << " NUMBER OF REFLNS IN THIS SECTION = " << NSECT[MI] << "\n\n"; } ALL=0.0; BSCALE=0.0; BSCALE1=0.0; } scaledone: MI=1; NI=1; II=1; fin.close(); fin.open(file2); switch(scaleoption) { case 1: fout << "\n*** An Approximate EXPONENTIAL Decay Correction Applied! ***\n"; break; case 2: fout << "\n*** WARNING: NO Intensity Controls Used! ***\n"; break; default: fout << "\n*** An Approximate LINEAR Decay Correction Applied! ***\n"; break; } fout << "\nList of BAD Reflections with BackGround ratio > 4.0 (if any):\n"; //fprintf(outputfile, "HKLF -%1i\n", (power+2)); // ********************* Second Part of DRDACS *************** SECONDREADING: // 150 H=999;K=999;L=999;SPEED=0.0;LEFT=0.0;COUNTS=0.0;RIGHT=0.0; //INITIALIZING fin >> REF_NUMBER >> H >> K >> L >> CODE1 >> CODE2 >> CODE3 >> CODE4 >> CODE5 >> CODE6; fin >> SPEED >> LEFT >> COUNTS >> RIGHT; if(H == 999 && K == 999 && L == 999) goto READINGSDONE2; if(H == 999) goto SECONDREADING; if(LEFT == 0.0) LEFT=1.0; if(RIGHT == 0.0) RIGHT=1.0; if(SPEED == 0.0) goto SECONDREADING; if(H == 0 && K == 0 && L == 0) goto SECONDREADING; if (SPEED < 0.0) SPEED=fabs(SPEED/FF); NREF1++; // total count from beginning (used in EXP correction). NREF2++; // regional count (between two controls). if(LEFT > RIGHT) BRR=LEFT/RIGHT; else BRR=RIGHT/LEFT; // BRR = Background Ratio if(LEFT > COUNTS || RIGHT > COUNTS || BRR > 4.0) { if(LEFT > COUNTS || RIGHT > COUNTS || BRR > 10.0) { cout << "\t" << H << " " << K << " " << L << "\t" << LEFT << " " << COUNTS << " " << RIGHT << "\t" << AMES << endl; fout << "\t" << H << " " << K << " " << L << "\t" << LEFT << " " << COUNTS << " " << RIGHT << "\t" << AMES << endl; } else fout << "\t" << H << " " << K << " " << L << "\t" << LEFT << " " << COUNTS << " " << RIGHT << endl; } if(CODE1 == 'I') { // This section finds the current NI++; // Intensity scaling region. if(NI < NMAX[MI]+1) goto SECONDREADING; MI++; NI=1; NREF2=0; if(MI < MMAX+1) goto SECONDREADING; if(IMAX == 0) goto SECONDREADING; goto READINGSDONE2; } INTENSITY=(COUNTS-2.0*(LEFT+RIGHT))/SPEED; switch(scaleoption) { case 1: SCALED=TXTAL*NREF1/NREF; SCALED=exp(SCALED); break; case 2: break; default: SCALED=1.0/(1.0-SCALE1[MI-1]-SCALE[MI]*NREF2/NSECT[MI]); break; } INTENSITY=INTENSITY*SCALED; SIGMA=(COUNTS+2.0*(RIGHT+LEFT))*SCALED*SCALED/SPEED/SPEED; SINTH1= pow(H*AST,2.0) + pow(K*BST,2.0) + pow(L*CST,2.0); SINTH2=2.0*(H*K*AST*BST*DL+H*L*AST*CST*DK+K*L*BST*CST*DH); SINTH=sqrt(SINTH1+SINTH2); SINTH=SINTH*WL/2.0; COSTH=sqrt(1.0-pow(SINTH,2.0)); COS2T=pow(COSTH,2.0)-pow(SINTH,2.0); MAC2=pow(COS2T,2.0); // Monochromator Angle Correction (2 of 2) SIN2T=2.0*SINTH*COSTH; SLP=(1.0+MAC1)*SIN2T/(MAC1+MAC2); FSQ=INTENSITY*SLP; SIGF2=sqrt(SIGMA+pow(0.01*INTENSITY,2.0))*SLP; if(power == 1) { if (FSQ < 0.25) { FF=FSQ; if(FF < 0.0) FF=0.0; FF=sqrt(FF); SIGF=SIGF2; } else { FF=sqrt(FSQ); SIGF=sqrt((SIGMA+pow(0.01*INTENSITY,2.0))/INTENSITY*SLP)/2.0; } if(FF < 4.0*SIGF) NWEAK++; fprintf(outputfile, "%4i%4i%4i%8.2f%8.2f\n", H,K,L,FF,SIGF) ; } else { if(FSQ < 2.0*SIGF2) NWEAK++; fprintf(outputfile, "%4i%4i%4i%8.1f%8.2f\n", H,K,L,FSQ,SIGF2) ; } goto SECONDREADING; READINGSDONE2: //2000 CONTINUE fprintf(outputfile, "\nEND\n"); fout << "\nTOTAL NUMBER OF MEASUREMENTS = " << NREF1 << endl; fout << "TOTAL NUMBER OF REFLECTIONS = " << (NREF1-IALL) << endl; fout << "TOTAL NUMBER OF WEAK REFLECTIONS = " << NWEAK << "\n"; fout << "Observed/Total Reflections Ratio = " << (NREF1-IALL-NWEAK)*100.0/(NREF1-IALL) << " %.\n\n"; fout << "\n ***** DRDACS COMPLETED. ***** \n\n"; fin.close(); fclose(outputfile); fout.close(); cout << "\nTOTAL NUMBER OF MEASUREMENTS = " << NREF1 << endl; cout << "TOTAL NUMBER OF REFLECTIONS = " << (NREF1-IALL) << endl; cout << "TOTAL NUMBER OF WEAK REFLECTIONS = " << NWEAK << endl; cout << "Observed/Total Reflections Ratio = " << (NREF1-IALL-NWEAK)*100.0/(NREF1-IALL) << " %.\n"; cout << "\n ***** DRDACS COMPLETED. ***** \n\n"; return 0;} // ***** The FUNCTION of DRDACS ends ***** // ******************************************************************** // ***** The FUNCTION of ABSACS begins ***** int absacs(char file1[16], int power) { char file2[16]; // input reduced data file char file3[16]; // output file cout << "\n ***** DOING ABSACS..... ***** \n"; cout << "ABSACS C version is not available yet!! Please use Fortran version!\n"; cout << (char) 7; cout << (char) 7; strcpy(file2,file1);strcpy(file3,file1); strcat(file1,".psi"); if (power==1) strcat(file2,".ff1"); else strcat(file2,".hkl"); strcat(file3,".abs"); cout << "\tInput file1 is: " << file1 << endl; cout << "\tInput file2 is: " << file2 << endl; cout << "\tOutput file is: " << file3 << endl <> yesno; if (yesno[0] != 'y' && yesno[0] != 'Y') return 0; cin.ignore(80,'\n'); cout << "\n\n ***** MAKING .INS file ..... ***** \n\n"; checkinsfile: if(__file_exists(file1)) {cout << "File [" << file1 << "] already exists !!! \n"; cout << " Please provide another first name for the INS file!:"; cin >> filenew1; strcpy(file1,filenew1); strcat(file1,".ins"); goto checkinsfile; } ifstream fin(file2); checkcelfile: if(!__file_exists(file2)) {cout << "File [" << file2 << "] NOT found !!! \n"; cout << " Please provide another first name for the CEL file!:"; cin >> filenew2; strcpy(file2,filenew2); strcat(file2,".cel"); goto checkcelfile; } fin >> FF >> MA >> WL >> AA >> BB >> CC >> AL >> BE >> GA; fin.close(); RAD=1.0/57.29577951; COSA=cos(AL*RAD); COSB=cos(BE*RAD); COSG=cos(GA*RAD); VOLUME=1.0-(COSA*COSA)-(COSB*COSB)-(COSG*COSG)+2.0*COSA*COSB*COSG; VOLUME=sqrt(VOLUME); VOLUME=VOLUME*AA*BB*CC; ofstream fout(file1); struct time tt; struct date dd; gettime(&tt); getdate(&dd); fout << "TITL This file was generated by XRAYACSC program at "; int hour = toascii(tt.ti_hour); int minute = toascii(tt.ti_min); int day = toascii(dd.da_day); int month = toascii(dd.da_mon); fout << hour << ":"; if (minute<10) fout <<"0"; // otherwise it writes like 12:1 for 12:01 fout << minute << " on " << day << "-" << month << "-" << dd.da_year << endl; fout << "TITL " << file <> ZZ; if (ZZ < 1 || ZZ > 64) {cout << "The answer is not valid! (use 1-64)"; goto zerr1;} zerr2: cout << "Please input Errors for cell parameters: "; cin >> EAA >> EBB >> ECC >> EAL >> EBE >> EGA; if (EAA < 0.0 || EBB < 0.0 || ECC < 0.0 || EAL < 0.0 || EBE < 0.0 || EGA < 0.0 || EAA > 1.0 || EBB > 1.0 || ECC > 1.0 || EAL > 1.0 || EBE > 1.0 || EGA > 1.0 ) {cout << "Invalid Values! (use 0.0-1.0)"; goto zerr2;} fout << "ZERR " << ZZ << " " << EAA << " " << EBB << " " << ECC << " " << EAL << " " << EBE << " " << EGA << endl; cin.ignore(80,'\n'); if (AL != 90.0 && BE != 90.0 && GA != 90.0) goto nosymm; cout << "Please input Lattice type number (1=P,7=C,3=R,4=F; - for Non-centric) : "; cin >> latt; fout << "LATT " << latt << endl; cin.ignore(80,'\n'); // from number to character change of input results in // the character input being the from last input!!! cout << "Please give symmetry operators(exclude X,Y,Z): "; moresymm: cin.getline(symm,20); for (unsigned int nsymm=0; nsymm < strlen(symm); nsymm++) {symm[nsymm]=capitalise(symm[nsymm]);} //{ if(symm[nsymm] > 96 && symm[nsymm] < 123) symm[nsymm]=symm[nsymm]-32;} if (symm[0] == 'Q') goto nosymm; fout << "SYMM " << symm << endl; symm[0]='0'; cout << "Please input more symmetry operators (Q/q ends) : "; goto moresymm; nosymm: cout << "Please give all the types of atoms present (use spaces ONLY);\n\t C H first):"; cin.getline(sfac,30); for (unsigned int nsfac=0; nsfac < strlen(sfac); nsfac++) {sfac[nsfac]=capitalise(sfac[nsfac]); //{ if(sfac[nsfac] > 96 && sfac[nsfac] < 123) sfac[nsfac]=sfac[nsfac]-32; if(sfac[nsfac] == ' ' && sfac[nsfac+1] != ' ') numatoms=numatoms+1;} fout << "SFAC " << sfac << endl; fout << "UNIT "; cout << "Please input numbers of " << numatoms << " types of atoms present in the Molecule \n(in the same order): "; for (int nunits=1; nunits < numatoms+1; nunits++) {cin >> unit; fout << unit*ZZ << " "; if (nunits!=2) totalatoms=totalatoms+unit;} fout << endl; cout << "[Total non-hydrogen atoms in the asymmetric unit = " << totalatoms <<" ]\n"; cout << "[Cell Volume = " << VOLUME << " ; Atomic volume = " << VOLUME/totalatoms/ZZ << " " << char(143) << "^3.]\n"; cout << "[Expected atomic volume range is 15 - 23; around 19 is most common!]\n"; askmethod: cin.ignore(80,'\n'); cout << "\nDo you want to run Direct methods or Patterson?[D/P]: "; cin.getline(DP,10); if (DP[0] !='D' && DP[0] != 'd' && DP[0] != 'P' && DP[0] != 'p') goto askmethod; if (DP[0] =='D' || DP[0] == 'd') fout << "TREF 100" << endl; if (DP[0] =='P' || DP[0] == 'p') fout << "PATT" << endl; fout << "HKLF -4" << endl; strcpy(file2,filenew2); strcat(file2,".hkl"); if(!__file_exists(file2)) {cout << "\nFile [" << file2 << "] NOT found !!! So the .INS file is incomplete!\n"; fout.close(); return 0; } fin.open(file2); while(fin.getline(ch,30)) {fout << ch ; fout < 96 && letter < 123) letter=letter-32; return letter; } // ******************************************************************** int intro1() { cout << "\n *** XRAYACSC: ***\n"; cout << " A Program for DATA REDUCTION and CORRECTIONS.\n"; cout << " Compiled in C by Dr. A.CHANDRASEKARAN\n"; cout << " DATED: 01-MAR-99\n"; cout << " It has 4 Programs: First 2 were written by and\n"; cout << " last 2 were extremely modified/improved by Dr. ACS.\n"; cout << " The Programs are: CADACS, DRDACS, ABSACS & FOFABS.\n"; cout << " All these are compatible with SHELX programs only.\n"; cout << " It also includes MAKEINS program which will create the required Folder.\n"; cout << " It also creates the required .CEL file to be used with DRDACS program.\n"; cout << " In the end, it creates the .INS file ready to run the SHELXS program!!!\n"; cout << " FOR MORE INFORMATION ASK 'H'.\n"; cout << " **** IF USEFUL, IT DESERVES TO BE REFERRED! ****\n\n"; cout << " A.Chandrasekaran, XRAYACS: program for single crystal X-ray data corrections,\n"; cout << " 1999, Chemistry Department, University of Massachusetts, Amherst, USA.\n"; cout << " WRITE PROBLEMS TO: chandru-at-chemistry.umass.edu\n\n"; return 0; } //********************************************************************** int help() { cout << "\n First this program goes to /CRY folder (if it is not there, creates it!).\n"; cout << " Then it creates a folder in the X-Ray data name and goes there. \n"; cout << " (If such a folder already exits, it simply goes to that folder)\n"; cout << " Then in the X-Ray data name folder, it creates both CEL and INS files.\n"; cout << " DATANAME.CEL is created first by asking the required information.\n"; cout << " (If DATANAME.CEL file already exists, it does not make any .CEL file. \n"; cout << " Then it runs data reduction programs (if any is requested).\n"; cout << " Finally it creates DATANAME.INS ready for SHELXS program.\n"; cout << " (If DATANAME.INS file already exists, it asks for another name.\n"; cout << " But does not create a new folder or new .CEL file!)\n\n"; cout << " User need to supply A, B, C, Alpha, Beta, Gamma and other data.\n"; cout << " User need to supply cell contents also.\n"; cout << " This program can not generate SYMMetry information and user need to provide\n"; cout << " the exact symmetry operations from International Tables or by working out.\n"; cout << " If the DATANAME.HKL file exists, this can generate complete file to run\n"; cout << " the SHELXS program for structure solution!\n\n"; return 0; } // ******************************************************************** int helpcad() { cout << "\n THIS REMOVES THE UNNECESSARY LINES FROM THE\n"; cout << " RAW DATA AND MAKES THE INPUT COMPACT.\n"; cout << " IT IS NEEDED TO RUN THE NEXT PROGRAM, DRDACS.\n"; cout << " THE INPUT FILE IS NAME.DAT\n"; cout << " THE OUTPUT IS NAME.DRD\n"; cout << " NAME IS ANY NAME.\n\n"; return 0; } //********************************************************************** int helpdrd() { cout << "\n THIS PROGRAM APPLIES APPROXIMATE ISOTROPIC DECAY CORRECTION: LINEAR BETWEEN\n"; cout << " EACH 2 SETS OF INTENSITY CONTROLS OR OVERALL-EXPONENTIAL BASED ON THE\n"; cout << " NUMBER OF THE REFLN, AND ALSO APPLIES LP CORRECTIONS TO THE DATA.\n"; cout << " IT CAN OUTPUT EITHER F OR F^2 BY YOUR CHOICE.\n"; cout << " INPUT FILES ARE NAME.CEL AND NAME.DRD\n"; cout << " NAME.CEL CONTAINS AF,MA,WAVE,A,B,C,AL,BE,GA,INTCR.\n"; cout << " AF= ATTENUATION FACTOR; MA= MONOCHROMATOR ANGLE;\n"; cout << " WAVE= WAVE LENGTH; INTCR= NUMBER OF INT. CONTROLS.\n"; cout << " THE NAME.CEL FILE IS IN FREE FORMAT\n"; cout << " NAME.DRD FILE IS PRODUCED BY THE CADACS PART.\n"; cout << " NAME IS ANY NAME.\n\n"; return 0; } //********************************************************************** int helpabs() { cout << "\n THIS PROGRAM APPLIES ABSORPTION CORRECTION USING PSI DATA WITH A\n"; cout << " SEVENTH ORDER SMOOTH CURVE OF VARIATION OF INTENSITIES IN THE PSI DATA.\n"; cout << " IT CAN CORRECT F OR F^2 AND CAN USE SEVERAL PSI DATA AT ONCE (UPTO 100!).\n"; cout << " * IT GIVES A PSIPLOT TOO! *\n"; cout << " Please edit the .OUT file and check the columns INTCAL for each PSI\n"; cout << " data and if any abnormal values are there, remove that set of PSI data\n"; cout << " and rerun the program.\n"; cout << " THE INPUT FILES ARE NAME.PSI & NAME.FF1/NAME.HKL\n"; cout << " NAME.PSI SHOULD HAVE:\n"; cout << " TITLE (1st LINE)\n"; cout << " LAMBDA, NO OF DATA SETS (2nd ; FREE FORMAT)\n"; cout << " ORIENTATION MATRIX (3rd....; FREE FORMAT!!)\n"; cout << " THEN THE PSI DATA SHOULD FOLLOW.\n"; cout << " NAME.FF1 IS THE FILE WITH H,K,L,F,DF AND\n"; cout << " NAME.HKL IS H,K,L,F2,DF2 (3I4,2F8.2)\n"; cout << " THESE NAME.FF1/NAME.HKL COMES FROM DRDACS.\n"; cout << " NAME IS ANY NAME.\n\n"; return 0; } //********************************************************************** int helpfof() { cout << "\n THIS PROGRAM DOES ABSORPTION CORRECTION BASED ON \n"; cout << " THE METHOD OF N.WALKER AND D.STUART, ACTA CRYST., A39, 158-166 (1983).\n"; cout << " PROGRAM OF F.UGOZZOLI, COMPUT. CHEM., 11, 109-120 (1987).\n\n"; cout << " MODIFIED BY DR. A.CHANDRASEKARAN IN SEP-1994.\n\n"; cout << " THE INPUTS FILES ARE NAME.MAT & NAME.FCF\n"; cout << " NAME.MAT SHOULD HAVE TITLE(1st LINE),LAMBDA(2nd)\n"; cout << " ORIENTATION MATRIX(3rd LINE ONWARDS; FREE FORMAT!!)\n"; cout << " THEN NUMBER OF CYCLES OF REFINEMENT (DEF.=2).\n"; cout << " NAME.FCF IS THE FILE PRODUCED BY SHELX PROGRAMS. AFTER HAVING ALL\n"; cout << " NON-H ATOMS WITH ISOTROPIC THERMAL PARAMETERS, REFINE WITH\n"; cout << " OMIT 0, LIST 5, AFLS 3, WGHT 0 (SHELX76) or\n"; cout << " LIST 4, L.S. 3, WGHT 0.1 AND NO OMIT (SHELX93)\n"; cout << " THE UNNECESSARY LINES SHOULD BE DELETED AND THE\n"; cout << " FILE SHOULD BE NAMED AS NAME.FCF\n"; cout << " NAME.FFF (H,K,L,FO,DF,FC; 3I4,2F12.2,F10.2) CAN ALSO BE\n"; cout << " USED INSTEAD OF NAME.FCF; NAME IS ANY NAME.\n\n"; return 0; } //**********************************************************************