/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * This program shifts x, y, z co-ordinates of any system based on the value of dx, dy, dz and writes the new set of (x,y,z) in a new file. INPUT : Input file must have the name 'shift-xyz-input.xyz' and (x,y,z) co-ordinates must be in the following format (space or tab separated) First Line : Number of atoms, N Next N Lines : x, y, z of each atom DESCRIPTION OF VARIABLES : Nbuf First line of the input file, stored as string Abuf Atomic Number of the atom, stored as string xbuf x co-ordinate of the atom, stored as string ybuf y co-ordinate of the atom, stored as string zbuf z co-ordinate of the atom, stored as string N Nbuf converted to integer, using atoi() Number of atoms Atom[i] Abuf converted to integer, using atoi() One dimensional array for atomic number of N atoms x[i] xbuf converted to double precision number, using atof() One dimensional array for storing x co-ordinate of N atoms y[i] ybuf converted to double precision number, using atof() One dimensional array for storing y co-ordinate of N atoms z[i] zbuf converted to double precision number, using atof() One dimensional array for storing z co-ordinate of N atoms COMPILATION/EXECUTION PROCEDURE : gcc -o shift-xyz.x shift-xyz.c -lm ./shift-xyz.x OUTPUT : If the compilation and execution is successful, the program writes an output file named in 'shift-xyz-ouput.xyz' format with shifted (x,y,z) co-ordinates First written : Gowtham, Thu Dec 22 19:32:02 EST 2005 Last modified : Gowtham, Thu Dec 22 21:22:51 EST 2005 For comments and/or suggestions, please contact mail@sgowtham.net * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include #include #include #include main() { /* Defines input and output files */ FILE *input; FILE *output; /* Declaration and initialization of variables */ char Nbuf[100]={'\0'}; char Abuf[100]={'\0'}; char xbuf[100]={'\0'}; char ybuf[100]={'\0'}; char zbuf[100]={'\0'}; int Atom[100]={0}; double x[100]={0}; double y[100]={0}; double z[100]={0}; int i, N; double dx, dy, dz; dx=0.500; /* Change this value to indicate dx */ dy=0.500; /* Change this value to indicate dy */ dz=0.500; /* Change this value to indicate dz */ /* Opens the input file for reading */ input = fopen("shift-xyz-input.xyz", "r"); if (input == NULL) { printf("\nInput File empty or corrupted! Exiting...\n"); exit (1); } /* Creates the output file and opens it for writing */ output = fopen("shift-xyz-ouput.xyz", "w"); /* Reads the first line of the input file and stores it as N */ fscanf(input, "%s", Nbuf); N = atoi(Nbuf); /* Reads and stores the (x, y, z) for each atom, first as a string (buffer) and later stores it as an array element using appropriate conversion mechanism */ for(i=0; i