- #1
ronny45
- 21
- 0
Using Fortran 77, I'm trying write a program which will read in the coordinates of the atoms in a molecule from this input file:
21
Aspirin
C 0.8641 0.1885 -0.0550
C 1.6904 1.2832 -0.0518
C 3.0579 1.1437 -0.0197
C 3.6120 -0.1296 0.0167
C 2.7571 -1.2117 0.0051
C 1.3999 -1.0697 -0.0319
C 3.8348 2.4466 -0.0147
O 3.1949 3.5035 -0.0635
O 5.2264 2.5396 0.0432
O 5.0391 -0.2600 0.0701
C 5.8568 -1.4155 0.2362
O 5.5015 -2.5866 0.4359
C 7.3030 -1.1536 0.2016
H -0.1283 0.3101 -0.0742
H 1.2910 2.1997 -0.0732
H 3.1452 -2.1331 0.0245
H 0.8059 -1.8741 -0.0419
H 5.4969 3.4603 0.0349
H 7.8008 -2.0121 0.3247
H 7.5452 -0.5201 0.9364
H 7.5482 -0.7503 -0.6801
The eventual aim is to calculate interatomic distances and the like, but for the moment I'm having trouble reading the numbers in correctly. My current program looks like this:
PROGRAM Aspirin
REAL ARRAY1(1:21,1:3)
OPEN(UNIT=10, FILE='aspirin.xyz', STATUS='old')
READ (10,5),((ARRAY1(I,J),J=1,3),I=1,21)
PRINT *,'Array:'
PRINT 6,((ARRAY1(I,J),J=1,3),I=1,21)
5 FORMAT(1X,F8.4,F8.4,F8.4)
6 FORMAT(F8.4,F8.4,F8.4)
PAUSE
END
This prints out the array perfectly when I deleted the two lines above the array in the input file; unfortunately, I don't know how to start reading on the third line.
I've tried reading in two blank lines(using //) in the read statement, but this doesn't work since they don't have the correct format. I've tried inserting // into the format state, but this skips two lines between each record. I've tried assigning two variables A and B as character strings for the first two lines, but I can't put them in the same READ statement then as the format's wrong, and if I put it in a separate statement the array tries to read from the beginning of the file anyway. I even tried reading in the array for i=3:23, but again the format was wrong for the first two lines and it wouldn't work.
Basically, what it boils down to is that there must be a way to specify reading an array from a part of a file other than the beginning, but I don't know what it is. Any help would be gratefully appreciated!
21
Aspirin
C 0.8641 0.1885 -0.0550
C 1.6904 1.2832 -0.0518
C 3.0579 1.1437 -0.0197
C 3.6120 -0.1296 0.0167
C 2.7571 -1.2117 0.0051
C 1.3999 -1.0697 -0.0319
C 3.8348 2.4466 -0.0147
O 3.1949 3.5035 -0.0635
O 5.2264 2.5396 0.0432
O 5.0391 -0.2600 0.0701
C 5.8568 -1.4155 0.2362
O 5.5015 -2.5866 0.4359
C 7.3030 -1.1536 0.2016
H -0.1283 0.3101 -0.0742
H 1.2910 2.1997 -0.0732
H 3.1452 -2.1331 0.0245
H 0.8059 -1.8741 -0.0419
H 5.4969 3.4603 0.0349
H 7.8008 -2.0121 0.3247
H 7.5452 -0.5201 0.9364
H 7.5482 -0.7503 -0.6801
The eventual aim is to calculate interatomic distances and the like, but for the moment I'm having trouble reading the numbers in correctly. My current program looks like this:
PROGRAM Aspirin
REAL ARRAY1(1:21,1:3)
OPEN(UNIT=10, FILE='aspirin.xyz', STATUS='old')
READ (10,5),((ARRAY1(I,J),J=1,3),I=1,21)
PRINT *,'Array:'
PRINT 6,((ARRAY1(I,J),J=1,3),I=1,21)
5 FORMAT(1X,F8.4,F8.4,F8.4)
6 FORMAT(F8.4,F8.4,F8.4)
PAUSE
END
This prints out the array perfectly when I deleted the two lines above the array in the input file; unfortunately, I don't know how to start reading on the third line.
I've tried reading in two blank lines(using //) in the read statement, but this doesn't work since they don't have the correct format. I've tried inserting // into the format state, but this skips two lines between each record. I've tried assigning two variables A and B as character strings for the first two lines, but I can't put them in the same READ statement then as the format's wrong, and if I put it in a separate statement the array tries to read from the beginning of the file anyway. I even tried reading in the array for i=3:23, but again the format was wrong for the first two lines and it wouldn't work.
Basically, what it boils down to is that there must be a way to specify reading an array from a part of a file other than the beginning, but I don't know what it is. Any help would be gratefully appreciated!