2
** NEW VERSION OF READ_FILE11() TO READ PAST ALL THE OLD ENTRIES ON TOP
4
** David Sherrill - June 1993
15
/* global variables */
16
char line1[MAX_LINE] ;
19
** READ_FILE11(): This function reads 'file11.dat' and prints out again
20
** some of the info to an output file.
23
** label = character string to hold file11 label field
24
** natom = pointer to variable to hold number of atoms
25
** energy = pointer to var to hold energy
26
** X, Y, Z = pointers to arrays of cartesian coordinates (assume bohr)
27
** (these are currently allocated in THIS function)
28
** AN = pointer to atomic number array (allocated here)
29
** fpo = file pointer for output
31
** Returns: success (1) or failure (0)
34
int read_file11(label, natom, energy, X, Y, Z, AN, fpo)
38
double **X, **Y, **Z, **AN ;
41
int i ; /* loop variable */
42
FILE *fpi ; /* pointer for input file file11.dat */
43
double g1, g2, g3; /* junk variables for gradients */
45
/* open file 11 for reading */
46
if ((fpi = fopen("file11.dat", "r")) == NULL) {
47
printf("(read_file11): Error opening file11.dat\n");
51
/* get first file11 label */
52
if (fgets(label, MAX_LINE, fpi) == NULL)
53
prf_abort(fpo, "(read_file11): Trouble reading label\n") ;
56
/* now read the number of atoms and the energy */
57
fgets(line1, MAX_LINE, fpi) ;
58
if (sscanf(line1, "%d %lf", natom, energy) != 2)
59
prf_abort(fpo, "(read_file11): Trouble reading natoms and energy\n") ;
61
/* now make room for the Cartesian coordinates */
62
*X = (double *) malloc (*natom * sizeof(double)) ;
63
malloc_check(*X, "(read_file11): Trouble allocating Cartesian array\n") ;
64
*Y = (double *) malloc (*natom * sizeof(double)) ;
65
malloc_check(*Y, "(read_file11): Trouble allocating Cartesian array\n") ;
66
*Z = (double *) malloc (*natom * sizeof(double)) ;
67
malloc_check(*Z, "(read_file11): Trouble allocating Cartesian array\n") ;
68
*AN = (double *) malloc (*natom * sizeof(double)) ;
69
malloc_check(*AN, "(read_file11): Trouble allocating atomic num array\n") ;
71
/* now rewind file11 and read it one chunk at a time */
74
/* loop over each chunk */
75
/* read number of atoms and energy */
76
while (fgets(label, MAX_LINE, fpi) != NULL) {
77
fgets(line1, MAX_LINE, fpi) ;
78
if (sscanf(line1, "%d %lf", natom, energy) != 2)
79
prf_abort(fpo, "(read_file11): Trouble reading natoms and energy\n") ;
82
for (i=0; i<(*natom); i++) {
83
if (fscanf(fpi, "%lf %lf %lf %lf", (*AN+i), (*X+i), (*Y+i),
85
prf_abort(fpo, "(read_file11): Trouble reading Cartesian coords\n");
89
for (i=0; i<(*natom); i++) {
90
if (fscanf(fpi, "%lf %lf %lf", &g1, &g2, &g3) != 3)
91
prf_abort(fpo, "(read_file11): Trouble reading gradients\n");
93
fgets(line1, MAX_LINE, fpi) ; /* go to end of line */
94
} /* end loop over file11 chunk */
103
** PRINT_FILE11(): Function prints out the information from file11.dat
104
** obtained from the read_file11() function.
107
** label = character string to hold file11 label field
108
** natom = number of atoms
109
** energy = energy from file11
110
** X, Y, Z = arrays of cartesian coordinates (assume bohr)
111
** AN = atomic number array (allocated here)
112
** fpo = file pointer for output
114
void print_file11(label, natom, energy, X, Y, Z, AN, fpo)
118
double *X, *Y, *Z, *AN ;
123
fprintf(fpo, "DATA FROM FILE11.DAT\n") ;
124
fprintf(fpo, "Label :\n%s\n", label) ;
125
fprintf(fpo, "Number of atoms = %d\n", natom) ;
126
fprintf(fpo, "Energy = %.10lf\n", energy) ;
127
fprintf(fpo, "\nCartesian coordinates (bohr) :\n") ;
128
for (i=0; i<natom; i++) {
129
fprintf(fpo, " %11.6lf %12.7lf %12.7lf %12.7lf\n",
130
AN[i], X[i], Y[i], Z[i]) ;