現在、puttedディレクトリのファイルを開き、そのデータを整数と文字の2つの異なる配列にソートすることができるコードを作成しました。.xyzファイルを配列に読み込む
1817
Plot50.0.xyz
C 0.70900 0.00000 0.00000
C 0.00000 1.22802 0.00000
C 2.12700 0.00000 0.00000
C 2.83600 1.22802 0.00000
C 4.96300 0.00000 0.00000
C 4.25400 1.22802 0.00000
C 6.38100 0.00000 0.00000
C 7.09000 1.22802 0.00000
C 9.21700 0.00000 0.00000
C 8.50800
今、私は、ファイル(フォーマットなど)を開くときに多分私はすべてを正しく割り当てられていないのかはわからないが、ここでコード[作業]である:入力ファイルは次のようになります:後で計算に使用されている間
program test01
character(len=40) :: filename !Storing the file name
character(len=20) :: nam !Collecting the file name within the file
integer(8) :: N !Number of coordinates within the file
real(8), allocatable :: coa(:,:) !Array containing xyz coordinates
character(len=6), allocatable :: atom(:,:) !Array containing the atomic make up
integer(8) :: i,j,k !Do loop parameters
filename = ''
write (6,*) 'Enter file name'
read (5,*) filename
open (10, file=filename, status='OLD')
write (6,*) 'Sucessfully opened file:', filename
read(10,*) N
allocate (coa(N,4))
allocate (atom(N,1))
read (10,*) nam
print*, nam
i = 0
do while (i < N)
read(10,*) atom(i,1), coa(i,2:4)
i = i+1
end do
print*, atom(0,1), atom(1,1), atom(4,1), atom(1818,1) !checking
print*, coa(0,2), coa(1500,3) !checking
close (10)
end program test01
だから私の主な質問はであり、配列を作成するために任意のより良い方法があるが(私は文字と実際に混在させることはできません信じているように、2つにする必要がある、とcoa
配列)そして特にextファイルから特定のデータを読み込みます(配列を作成しようとしたときにすべての問題を引き起こしていたので、ファイルの行2を文字に挿入するのではなく、行2をスキップします)。
ようこそ。データファイルをテキストとして挿入してください。画像は受け入れられません。 [ask] –
を読んでください。コードが正常に機能している場合は、代わりにhttp://codereview.stackexchange.comにアクセスしてください。両方のサイトで聞かないでください。 –
Fortranの初心者であれば、 'real(8)'と 'integer(8)'を使わないことを考えてください。これはコード臭であり、すべてのコンパイラには移植できません。 8バイトの変数を意味するものではありません。 http://stackoverflow.com/documentation/fortran/939/data-types/4390/precision-of-floating-point-numbers#t=201701280943571374653同様に、 'read(5、*)'を使わないでください。と 'write(6、*)'ではなく、 '(*、*)'です。これらのアドバイスはすべて、http://codereview.stackexchange.comのサイトでより良いものになります。 –