// Print out the basis set specification in the format: // (example is C atom in 3-21G basis set) // BASIS: 6-31G // Total no. of cgbfs: 9 // Total no. of primitives: 9 // =============== // Specification // =============== // Atom Shell #CGBFs #Prims // ...................................... // C s 3 6 // p 6 3 // (if full = true, then continue with this) // =============== // Basis Functions // =============== // Atom Shell BF Coeff Exponent // ................................................. // C s 1 0.0617669 172.2560 // 0.358794 25.91090 // 0.700713 5.533350 // etc... void Logger::print(Basis& b, bool full) const { // Collect the data needed for printing int nbfs = b.getNBFs(); // Store number of cgbfs and prims int nprims = 0; Vector qs = b.getCharges(); // Sort the qs and get rid of duplicates qs.sort(); Vector qtemp(qs.size()); qtemp[0] = qs(0); int k = 1; for (int i = 1; i < qs.size(); i++){ if (qs(i) != qtemp[k-1]){ qtemp[k] = qs(i); k++; } } qs = qtemp; qs.resizeCopy(k); // Now sum over all basis functions to get the number of prims Vector c(3); c[0] = 0.0; c[1] = 0.0; c[2] = 0.0; BF bftemp(c, 0, 0, 0, c, c); for (int i = 0; i < nbfs; i++){ bftemp = b.getBF(i); nprims += bftemp.getNPrims(); } // Start printing title("Basis Set"); outfile << "BASIS: " << b.getName() << "\n"; outfile << "Total no. of cgbfs: " << nbfs << "\n"; outfile << "Total no. of prims: " << nprims << "\n"; title("Specification"); outfile << std::setw(8) << "Atom"; outfile << std::setw(8) << "Shell"; outfile << std::setw(8) << "#CGBFs"; outfile << std::setw(8) << "#Prims\n"; outfile << std::string(35, '.') << "\n"; // loop over the atom types outfile << std::setprecision(2); Vector subshells; Vector sublnums; for (int i = 0; i < k; i++){ int nc = 0; int np = 0; outfile << std::setw(8) << getAtomName(qs(i)); subshells = b.getShells(qs[i]); sublnums = b.getLnums(qs[i]); outfile << std::setw(8) << getShellName(sublnums[0]); outfile << std::setw(8) << subshells[0]; for (int j = 0; j < subshells[0]; j++){ np += b.getBF(qs[i], j).getNPrims(); } nc += subshells[0]; outfile << std::setw(8) << np << "\n"; for (int j = 1; j < subshells.size(); j++){ outfile << std::setw(8) << ""; outfile << std::setw(8) << getShellName(sublnums[j]); outfile << std::setw(8) << subshells[j]; np = 0; for (int l = 0; l < subshells[j]; l++){ np += b.getBF(qs[i], nc + l).getNPrims(); } nc += subshells[j]; outfile << std::setw(8) << np << "\n"; } } outfile << std::setprecision(8); // Now print out basis functions if required if (full) { title("Basis Functions"); outfile << std::setw(8) << "Atom"; outfile << std::setw(8) << "Shell"; outfile << std::setw(5) << "BF"; outfile << std::setw(18) << "Coeff"; outfile << std::setw(18) << "Exponent\n"; outfile << std::string(58, '.') << "\n"; // Loop over all the basis functions Vector subshell; Vector sublnums; Vector coeffs; Vector exps; std::string filler = ""; for (int i = 0; i < k; i++){ subshell = b.getShells(qs(i)); sublnums = b.getLnums(qs(i)); // Loop over shells int sum = 0; for (int r = 0; r < subshell.size(); r++){ // Loop over bfs for (int s = 0; s < subshell[r]; s++){ bftemp = b.getBF(qs(i), s+sum); coeffs = bftemp.getCoeffs(); exps = bftemp.getExps(); // Loop over coeffs/exps for (int t = 0; t < coeffs.size(); t++){ filler = ((r == 0 && s==0 && t==0) ? getAtomName(qs[i]) : ""); outfile << std::setw(8) << filler; filler = ((s == 0 && t == 0) ? getShellName(sublnums[r]) : ""); outfile << std::setw(8) << filler; filler = (t == 0 ? std::to_string(s+1) : ""); outfile << std::setw(5) << filler; outfile << std::setw(18) << std::setprecision(8) << coeffs(t); outfile << std::setw(18) << std::setprecision(8) << exps(t) << "\n"; } } sum += subshell[r]; } } } }
int main(int argc, char * argv[], char **envp) { //The following two functions catch and process the interrupt and stop signals //AKA signals sent by the Ctrl-C and Ctrl-Z commands if (signal(SIGINT,signal_catcher)==SIG_ERR) { perror("Sigset cannot set SIGINT"); exit(SIGINT); } if (signal(SIGTSTP, signal_catcher)==SIG_ERR) { perror("Sigset can not set SIGTSTP"); exit(SIGTSTP); } //Declaring and initializing variables to be used later initHistory(); initAlias(); int this_input = 0; char * input = (char *) malloc(sizeof(char)*64); strcpy (input, "noexit"); char *shellname = (char *) malloc(sizeof(char)*32); strcpy (shellname, "myshell"); setShellName(shellname); printf ("[%s]%% ", shellname); input = getLine(input, 100); //Making sure the program does not crash if the input simply the return key while (strcmp(input,"\0") == 0) { printf ("[%s]%% ", shellname); input = getLine(input, 100); } setHistory(input); breakLine (input); this_input = whichInput(); char ** argrv = getargrv(); int argrc = getargrc(); int loop = 1; while (loop != 0) { //Loop and process commands until the exist command is entered if(this_input==4) { if(strcmp(argrv[argrc-1], "&")==0) { //printf("Before forking PID:%d\n", getpid()); int pid = fork(); if(pid==0) { //sleep(2); //putting a delay in to emphasize background process //printf("\nchild PID: %d\n", getpid()); decrargrc(); list(); //printf("\nIn the child process - ended.\n\n"); return 0; } else { //printf("PPID:%d\n", getpid()); //printf("In the parent process.\n"); printf("%s process running in background", argrv[0]); } } else list(); } else if(this_input==3) { if(strcmp(argrv[argrc-1], "&")==0) { int pid = fork(); if(pid==0) { decrargrc(); pwd(); return 0; } else printf("%s process running in background", argrv[0]); } else pwd(); } else if(this_input==6) { if(strcmp(argrv[argrc-1], "&")==0) { int pid = fork(); if(pid==0) { decrargrc(); prompt(); shellname = getShellName(); return 0; } else printf("%s process running in background", argrv[0]); } else { prompt(); shellname = getShellName(); } } else if(this_input==2) { if(strcmp(argrv[argrc-1], "&")==0) { int pid = fork(); if(pid==0) { decrargrc(); dirChange(); return 0; } else printf("%s process running in background", argrv[0]); } else dirChange(); } else if(this_input==5) { if(strcmp(argrv[argrc-1], "&")==0) { int pid = fork(); if(pid==0) { decrargrc(); mypid(); return 0; } else printf("%s process running in background", argrv[0]); } else mypid(); } else if(this_input==1) { if (getargrc() == 1) { loop = 0; free (input); free (shellname); input = NULL; shellname = NULL; freeDynamicMem(); return 0; } else { printf("%s: Arguments not valid.", argrv[0]); } } else if(this_input==7) { if(strcmp(argrv[argrc-1], "&")==0) { int pid = fork(); if(pid==0) { decrargrc(); printHistory(); return 0; } else printf("%s process running in background", argrv[0]); } else printHistory(); } else if(this_input==8) { if(strcmp(argrv[argrc-1], "&")==0) { int pid = fork(); if(pid==0) { printf("\n***I've put a 3 second delay in to emphasize this background process\n"); sleep(3); //putting a delay in to emphasize background proces decrargrc(); printEnv(envp); return 0; } else printf("%s process running in background", argrv[0]); } else printEnv(envp); }else if(this_input==9) { if(strcmp(argrv[argrc-1], "&")==0) { int pid = fork(); if(pid==0) { decrargrc(); alias(); return 0; } else printf("%s process running in background", argrv[0]); } else alias(); }else if(this_input==10) { if(strcmp(argrv[argrc-1], "&")==0) { int pid = fork(); if(pid==0) { decrargrc(); murder(); return 0; } else printf("%s process running in background", argrv[0]); } else murder(); }else { nocmd(input); } printf ("\n[%s]%% ", shellname); input = getLine(input, 100); while (strcmp(input,"\0") == 0) { printf ("[%s]%% ", shellname); input = getLine(input, 100); } setHistory(input); breakLine (input); this_input = whichInput(); argrv = getargrv(); argrc = getargrc(); } return 0; }