ææä¸ä¸ª.datæ件ï¼æè¯å¾éè¡è¯»å并æå°å®ãæ人å¯ä»¥å¸®å¿äºè§£å¦ä½å¨fortranä¸åå°è¿ä¸ç¹åï¼
æåè´è°¢ï¼
æ°æ®ï¼
REMARK GENERATED BY TRJCONVTITLE UNNAMED t= 0.00000REMARK THIS IS A SIMULATION BOXCRYST1 26.178 26.178 26.178 90.00 90.00 90.00 P 1 1MODEL 1ATOM 1 S2 LJ2 1 17.000 15.030 11.630 1.00 0.00 ATOM 2 S2 LJ2 2 13.290 11.340 15.900 1.00 0.00 ATOM 3 S2 LJ2 3 17.030 23.070 14.750 1.00 0.00 ATOM 4 S2 LJ2 4 15.360 14.840 9.480 1.00 0.00 ATOM 5 S2 LJ2 5 15.780 4.560 9.580 1.00 0.00 ATOM 6 S2 LJ2 6 5.350 22.490 11.110 1.00 0.00 ATOM 7 S2 LJ2 7 19.940 3.910 10.840 1.00 0.00 ATOM 8 S2 LJ2 8 20.380 13.360 15.680 1.00 0.00 ATOM 9 S2 LJ2 9 18.340 4.200 7.720 1.00 0.00 ATOM 10 S2 LJ2 10 18.610 16.530 9.910 1.00 0.00 TERENDMDL
代çï¼
program atom_testimplicit none character (LEN=75) ::inputdatafile,outputfile real,dimension(100) :: x, y integer :: i,n,nframescharacter (len=200),dimension(3000):: command print *,"Give the datafile name:" read *,inputdatafileoutputfile=inputdatafile(1:len(trim(inputdatafile))-4)//"_output.dat"!write(*,*)outputfileOpen(9, file=inputdatafile, status='old')call linesFile(inputdatafile,n)write(*,*)ndo i=1,n read(*,*),command(i) write (*,*)command(i)end doclose(9)end program atom_test!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! find the number of lines in a file!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!subroutine linesFile(fileIn,n)implicit none Character(len = 50) :: fileIninteger, intent(out) :: n! localsinteger :: iostatus, unit_readreal :: dummyunit_read = 9open(unit=unit_read, file=fileIn)n =0DO READ(unit_read, *, IOSTAT=iostatus) dummy IF (iostatus < 0) EXIT n = n + 1END DO ! WRITE(*, '(i8, a, a)') n, ' bins read from file: ', fileIn close(unit_read)end subroutine linesFile
é´äºæç¡®ççæ¡å·¥ä½æ£å¸¸ãç±äºææ¯Fortrançæ°æï¼æè¿æä¸ä¸ªé®é¢ä¸æ¤ç¸å ³ãææ³ä»æçæ°æ®æ件ä¸çATOMè¡ä¸åç¬è·åå ç´ä¾å¦ï¼åå1 S2 LJ2 1 17.000 15.030 11.630 1.00 0.00
from here i want to store 1,s2,LJ2,1,17.000,15.030 each in different parameters. In that case I am using this
/ *代çæ记为æ£ç¡®
ncount=0 do i = 1, n IF (command(i)(1:4).eq.'ATOM') THEN ncount=ncount+1 read(read_unit,*) p, p2, p3,p4,xatom(ncount) write(*,*),p endifend do
ä½å®æ²¡æç¨ãä½è½å¦ç»æä¸ä¸ªå ³äºå¦ä½ä»ä»¥ATOMå¼å¤´çé£äºæ¹é¢åç¬é 读ç建议ï¼æå谢谢ï¼
2 个çæ¡:
çæ¡ 0 :(å¾åï¼2)
æç«å³æ³¨æå°äºä¸äºäºæ ï¼
- è¡
read(*, *) command(i)
读åæåè¾å ¥ç第ä¸ä¸ªå ç´ï¼èä¸æ¯æ件ãææ³ä½æ³è¦read(9, *)
ã - å®é
ä¸ï¼æ¨å¯è½æ³è¦
read(9, '(A)')
ï¼å为æ¨æ³è¦è¯»åæ´è¡ï¼èä¸æ¯ç´å°ç¬¬ä¸ä¸ªå ç´åé符ï¼å³ç©ºæ¼æéå·ï¼ã -
å¨åç¨åºä¸ï¼å¨åä¸åå ä¸å次æå¼æ件ãé£æ¯......å±é©ï¼å¦æ没æéãæ好åªè¯»åæ件ï¼ç¶å使ç¨
rewind
å½ä»¤å°è¯»åä½ç½®ç§»åæ件çå¼å¤´ãprogram atom_test implicit none integer :: ios integer, parameter :: read_unit = 99 character(len=200), allocatable :: command(:) character(len=200) :: line integer :: n, i open(unit=read_unit, file='data.dat', iostat=ios) if ( ios /= 0 ) stop "Error opening file data.dat" n = 0 do read(read_unit, '(A)', iostat=ios) line if (ios /= 0) exit n = n + 1 end do print*, "File contains ", n, "commands" allocate(command(n)) rewind(read_unit) do i = 1, n read(read_unit, '(A)') command(i) end do close(read_unit) do i = 1, n print*, command(i) end doend program atom_test
-
å¦ææ¨å¨å¼å§æ¶å·²ç»æå ¥äº3000è¡ï¼é£ä¹æ²¡æçç±å读两éï¼
program atom_test implicit none integer :: ios integer, parameter :: read_unit = 99 character(len=200) :: command(3000) integer :: n, i open(unit=read_unit, file='data.dat', iostat=ios) if ( ios /= 0 ) stop "Error opening file data.dat" n = 0 do read(read_unit, '(A)', iostat=ios) command(n+1) if (ios /= 0) exit n = n + 1 end do print*, "File contains ", n, "commands" close(read_unit) do i = 1, n print*, command(i) end doend program atom_test
-
å¨æ¨çåç¨åºä¸è¯»åæ件ä¸çè¡æ°ï¼æ¨å°è¯ä»ç¬¬ä¸ä¸ªåè¯é常ä¸æ¯æ°åçæ件ä¸è¯»å
REAL
ãè¿å¯è½å¯¼è´IOSTAT
éé¶ï¼å³ä½¿æ¨å°æªå°è¾¾æ件æ«å°¾ã请å¡å¿ é 读character
åéã é>
çæ¡ 1 :(å¾åï¼1)
è¿ç¯æç«æä¾äºOPè¯è®ºççæ¡ï¼
ÂÂææ³å°å ç´ä¸æ°æ®æ件ä¸çATOMè¡åå¼è·å
å设input.txt
çèµ·æ¥åï¼
ATOM 1 S2 LJ2 1 17.000 15.030 11.630 1.00 0.00 ATOM 2 S2 LJ2 2 13.290 11.340 15.900 1.00 0.00 ATOM 3 S2 LJ2 3 17.030 23.070 14.750 1.00 0.00 ATOM 4 S2 LJ2 4 15.360 14.840 9.480 1.00 0.00 ATOM 5 S2 LJ2 5 15.780 4.560 9.580 1.00 0.00 ATOM 6 S2 LJ2 6 5.350 22.490 11.110 1.00 0.00 ATOM 7 S2 LJ2 7 19.940 3.910 10.840 1.00 0.00 ATOM 8 S2 LJ2 8 20.380 13.360 15.680 1.00 0.00 ATOM 9 S2 LJ2 9 18.340 4.200 7.720 1.00 0.00 ATOM 10 S2 LJ2 10 18.610 16.530 9.910 1.00 0.00
ä½å¯ä»¥
- å°åè¯»å ¥å符串
- ä»å符串ä¸è¯»åå®æ°
- è¾åºç»æ é>
- å°åè¯»å ¥åéï¼å符串ï¼æ´æ°æå®æ°ï¼
- è¾åºç»æ é>
program fort integer n, i parameter (n=10) real r1(n), r2(n), r3(n), r4(n), r5(n), r6(n), r7(n) character(len=255) format, s1(n), s2(n), s3(n), s4(n), s5(n), & s6(n), s7(n), s8(n), s9(n), s10(n) i=1 open(unit=99, file='input.txt') 2 read(99,3,end=1) s1(i), s2(i), s3(i), s4(i), s5(i), & s6(i), s7(i), s8(i), s9(i), s10(i) i=i+1 goto 2 3 format(a6,2a4,a5,a4,3a8,a6,a4) 4 format(a6,f4.1,2x,2a4,f4.1,5f8.3) 1 close(99) read(s2,*) r1 read(s5,*) r2 read(s6,*) r3 read(s7,*) r4 read(s8,*) r5 read(s9,*) r6 read(s10,*) r7 do i=1,n write(*,4) s1(i), r1(i), s3(i), s4(i), r2(i), & r3(i), r4(i), r5(i), r6(i), r7(i) enddo end
è¾åºï¼
ATOM 1.0 S2 LJ2 1.0 17.000 15.030 11.630 1.000 0.000ATOM 2.0 S2 LJ2 2.0 13.290 11.340 15.900 1.000 0.000ATOM 3.0 S2 LJ2 3.0 17.030 23.070 14.750 1.000 0.000ATOM 4.0 S2 LJ2 4.0 15.360 14.840 9.480 1.000 0.000ATOM 5.0 S2 LJ2 5.0 15.780 4.560 9.580 1.000 0.000ATOM 6.0 S2 LJ2 6.0 5.350 22.490 11.110 1.000 0.000ATOM 7.0 S2 LJ2 7.0 19.940 3.910 10.840 1.000 0.000ATOM 8.0 S2 LJ2 8.0 20.380 13.360 15.680 1.000 0.000ATOM 9.0 S2 LJ2 9.0 18.340 4.200 7.720 1.000 0.000ATOM 10.0 S2 LJ2 10.0 18.610 16.530 9.910 1.000 0.000
æ´å¥½çæ¹æ³æ¯
program fort integer n, i parameter (n=10) integer i1(n), i2(n) real r1(n), r2(n), r3(n), r4(n), r5(n) character(len=255) format, s1(n), s2(n), s3(n), s4(n), s5(n), & s6(n), s7(n), s8(n), s9(n), s10(n) i=1 open(unit=99, file='input.txt') 2 read(99,3,end=1) s1(i), i1(i), s3(i), s4(i), i2(i), & r1(i), r2(i), r3(i), r4(i), r5(i) i=i+1 goto 2 3 format(a6,i4,a4,a5,i4,3f8.3,2f6.2) 4 format(a6,i4,2x,2a4,i4,5f8.3) 1 close(99) do i=1,n write(*,4) s1(i), i1(i), s3(i), s4(i), i2(i), & r1(i), r2(i), r3(i), r4(i), r5(i) enddo end