Here is the first part of the program:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int n_atoms; //number of atoms in the file
char space[3]; //for holding blank lines or ignorable entries
float** coords; //2-d array where coordinates are stored
float sigma;
float epsilon;
FILE*fp;
int i,j;
int read_intconfig(){
//open the source coordinates file
fp = fopen("intconfig1.xyz","r");
//read the first readable
fscanf(fp,"%i",&n_atoms);
//allocate array
int i;
coords= (float**)malloc(sizeof(float*)*n_atoms);
for(i=0; i<n_atoms; i++)
coords[i] = (float*)malloc(sizeof(float)*3);
//read in coordinates
for(i=0; i<n_atoms; i++){
fscanf(fp,"%s%f%f%f",space,&coords[i][0],&coords[i][1],&coords[i][2]);
}
//print out coordinates
for(i=0; i<n_atoms; i++){
printf("%f\t%f\t%f\n",coords[i][0],coords[i][1],coords[i][2]);
}
return 0;
}
where it tries to access this file:
Code:
21
Disorder Model
Ar 0.303895 4.327322 8.279128
Ar 9.145204 2.342695 4.070601
Ar 8.182916 0.717535 1.654591
Ar 7.572462 6.656014 5.097832
Ar 5.738435 0.753646 9.701556
Ar 0.544729 8.344379 0.667417
Ar 4.999589 0.738486 6.580141
Ar 4.890845 3.251438 7.711195
Ar 1.967732 1.611031 4.274032
Ar 9.068198 7.436556 7.508925
Ar 5.754537 6.052998 1.575422
Ar 2.424211 6.041687 9.465409
Ar 7.808051 4.058478 6.402670
Ar 1.617716 4.503045 4.084561
Ar 9.114211 0.470067 8.364241
Ar 1.318087 1.643199 1.284136
Ar 3.026772 8.354662 5.635452
Ar 4.534749 1.072564 2.679395
Ar 7.152873 9.594938 4.546791
Ar 4.228917 5.481427 5.809191
Ar 7.462603 3.352339 9.202824