real :: a(1000)
integer :: i
Do i = 1 , 10
a(i::10) = i
End Do
vvt 发表于 2017-7-7 15:10
[mw_shl_code=fortran,true]real :: a(1000)
integer :: i
Do i = 1 , 10
a = reshape(spread([1:10],2,100),shape(a))
vvt 发表于 2017-7-7 15:10
real :: a(1000)
integer :: i
Do i = 1 , 10
program aweigh
implicit real*8 (a-h,o-z)
dimension wa(10000,1)
real::a(10000)
parameter(N=14.00672)
parameter(H=1.00795)
parameter(C=12.01078)
open(13,file='aweigh.txt')
do i=1,10
if ((i.eq.1).or.(i.eq.5))
then a(i::10)=N
endif
if ((i.eq.3).or.(i.eq.4).or.(i.eq.8))
then a(i::10)=C
else a(i::10)=H
endif
enddo
do i=1,10000
write(3,*)a(i)
enddo
close(13)
end
百事可乐 发表于 2017-7-7 15:27
还有更简便的写法
...
program aweigh
implicit none !//这句话非常非常重要!!请一定要写 implicit none
real(8) :: a(10000)
integer :: i
Real(8) , parameter :: N=14.00672 !// N 要定义成 real8
Real(8) , parameter :: H=1.00795
Real(8) , parameter :: C=12.01078
open(13,file='aweigh.txt')
do i=1,10
Select Case( i ) !//用 Select 语句,方便直观
Case(1,5)
a(i::10)=N
Case(3,4,8)
a(i::10)=C
Case Default
a(i::10)=H
End Select
enddo
do i=1,10000
write(3,*)a(i)
enddo
close(13)
end program aweigh
vvt 发表于 2017-7-7 16:31
[mw_shl_code=fortran,true]program aweigh
implicit none !//这句话非常非常重要!!请一定要写 implici ...
PROGRAM test
IMPLICIT NONE
! "(8)" compiler dependent (NAG/Silverfrost not accept), avoid to use
REAL(8) , PARAMETER :: N=14.00672
REAL(8) , PARAMETER :: H= 1.00795
REAL(8) , PARAMETER :: C=12.01078
INTEGER, PARAMETER :: r8=SELECTED_REAL_KIND(P=15)
REAL(r8) , PARAMETER :: NN=14.00672_r8
REAL(r8) , PARAMETER :: HH= 1.00795_r8
REAL(r8) , PARAMETER :: CC=12.01078_r8
WRITE(*,*) N, NN
WRITE(*,*) H, HH
WRITE(*,*) C, CC
END PROGRAM test
168.19 KB, 下载次数: 3
欢迎光临 Fortran Coder (http://bbs.fcode.cn/) | Powered by Discuz! X3.2 |