我其实更希望找人合作来完善我的 fortran2julia 翻译器。谁有兴趣吗?
楼上没看出来我这是 step in door
你直接给我 door on face
优秀
这个任务不需要你看懂代码在干什么,只需要保证 Fortran 和 Julia 两边跑出一样的结果。我自己干的话可能一天就能弄完,三天是上限
上面对应的原 Fortran 代码
subroutine get_kgroup(Nk_irr,nsymq,SKI,rg,pg,nnp,gk,Gshift,kphase)
implicit none
integer,intent(in) :: Nk_irr, nsymq,rg(3,3,nsymq),pg(3,nsymq),nnp
real(8),intent(in) :: SKI(3,Nk_irr)
logical,intent(out) :: gk(Nk_irr,nsymq)
integer,intent(out) :: Gshift(3,Nk_irr,nsymq)
complex(8),intent(out) :: kphase(Nk_irr,nsymq)
integer :: ik,iop,jop,kop,tmp2(3)
logical :: flag
real(8) :: err=0.00001, tmp(3)
real(8),parameter :: pi = acos(-1d0)
complex(8),parameter :: ii = (0,1)
gk = .false.
flag = .false.
kphase=1d0
do ik=1,Nk_irr
do iop=1,nsymq
tmp(1)=sum(rg(1,:,iop)*SKI(:,ik))-SKI(1,ik)
tmp(2)=sum(rg(2,:,iop)*SKI(:,ik))-SKI(2,ik)
tmp(3)=sum(rg(3,:,iop)*SKI(:,ik))-SKI(3,ik)
Gshift(1,ik,iop)=nint(tmp(1))
Gshift(2,ik,iop)=nint(tmp(2))
Gshift(3,ik,iop)=nint(tmp(3))
gk(ik,iop)=(abs(tmp(1)-Gshift(1,ik,iop))<err).and.&
&(abs(tmp(2)-Gshift(2,ik,iop))<err).and.&
&(abs(tmp(3)-Gshift(3,ik,iop))<err)
end do
end do
do ik=1,Nk_irr
do iop=1,nsymq
kphase(ik,iop)=exp(-ii*sum(SKI(:,ik)*pg(:,iop))*2*pi/nnp)
end do
end do
end subroutine get_kgroup
机器翻译的代码示例
function get_kgroup(nk_irr,nsymq,ski,rg,pg,nnp,gk,gshift,kphase) # #N[811]
#implicit none #LABEL[#FORTRAN_CONTROL[implicit]] #N[812]
#integer,intent(in) :: nk_irr, nsymq,rg(3,3,nsymq),pg(3,nsymq),nnp #LABEL[#FORTRAN_CONTROL[integer]] #N[813]
#real(8),intent(in) :: ski(3,nk_irr) #LABEL[#FORTRAN_CONTROL[real]] #N[814]
#logical,intent(out) :: gk(nk_irr,nsymq) #LABEL[#FORTRAN_CONTROL[logical]] #N[815]
#integer,intent(out) :: gshift(3,nk_irr,nsymq) #LABEL[#FORTRAN_CONTROL[integer]] #N[816]
#complex(8),intent(out) :: kphase(nk_irr,nsymq) #LABEL[#FORTRAN_CONTROL[complex]] #N[817]
# #N[818]
#integer :: ik,iop,jop,kop,tmp2(3) #LABEL[#FORTRAN_CONTROL[integer]] #N[819]
#logical :: flag #LABEL[#FORTRAN_CONTROL[logical]] #N[820]
#real(8) :: err=0.00001, tmp(3) #LABEL[#FORTRAN_CONTROL[real]] #N[821]
#real(8),parameter :: pi = acos(-1d0) #LABEL[#FORTRAN_CONTROL[real]] #N[822]
#complex(8),parameter :: ii = (0,1) #LABEL[#FORTRAN_CONTROL[complex]] #N[823]
# #N[824]
gk = false # #N[825]
flag = false # #N[826]
kphase = 1e0 # #N[827]
# #N[828]
# #N[829]
for ik = 1 : nk_irr # #N[830]
for iop = 1 : nsymq # #N[831]
tmp[1] = sum(rg[1,:,iop]*ski[:,ik])-ski[1,ik] # #N[832]
tmp[2] = sum(rg[2,:,iop]*ski[:,ik])-ski[2,ik] # #N[833]
tmp[3] = sum(rg[3,:,iop]*ski[:,ik])-ski[3,ik] # #N[834]
gshift[1,ik,iop] = nint(tmp[1]) # #N[835]
gshift[2,ik,iop] = nint(tmp[2]) # #N[836]
gshift[3,ik,iop] = nint(tmp[3]) # #N[837]
# #N[838]
gk[ik,iop] = (abs(tmp[1]-gshift[1,ik,iop])<err) && &(abs(tmp[2]-gshift[2,ik,iop])<err) && &(abs(tmp[3]-gshift[3,ik,iop])<err) # #N[841]
# #N[842]
end # #LABEL[#FORTRAN_END[for]] #N[843]
end # #LABEL[#FORTRAN_END[for]] #N[844]
# #N[845]
for ik = 1 : nk_irr # #N[846]
for iop = 1 : nsymq # #N[847]
kphase[ik,iop] = exp(-ii*sum(ski[:,ik]*pg[:,iop])*2*pi/nnp) # #N[848]
end # #LABEL[#FORTRAN_END[for]] #N[849]
end # #LABEL[#FORTRAN_END[for]] #N[850]
# #N[851]
end # #LABEL[#FORTRAN_END[subroutine]get_kgroup] #N[852]
# #N[853]
# #N[854]
上面对应的原 Fortran 代码
subroutine get_kgroup(Nk_irr,nsymq,SKI,rg,pg,nnp,gk,Gshift,kphase)
implicit none
integer,intent(in) :: Nk_irr, nsymq,rg(3,3,nsymq),pg(3,nsymq),nnp
real(8),intent(in) :: SKI(3,Nk_irr)
logical,intent(out) :: gk(Nk_irr,nsymq)
integer,intent(out) :: Gshift(3,Nk_irr,nsymq)
complex(8),intent(out) :: kphase(Nk_irr,nsymq)
integer :: ik,iop,jop,kop,tmp2(3)
logical :: flag
real(8) :: err=0.00001, tmp(3)
real(8),parameter :: pi = acos(-1d0)
complex(8),parameter :: ii = (0,1)
gk = .false.
flag = .false.
kphase=1d0
do ik=1,Nk_irr
do iop=1,nsymq
tmp(1)=sum(rg(1,:,iop)*SKI(:,ik))-SKI(1,ik)
tmp(2)=sum(rg(2,:,iop)*SKI(:,ik))-SKI(2,ik)
tmp(3)=sum(rg(3,:,iop)*SKI(:,ik))-SKI(3,ik)
Gshift(1,ik,iop)=nint(tmp(1))
Gshift(2,ik,iop)=nint(tmp(2))
Gshift(3,ik,iop)=nint(tmp(3))
gk(ik,iop)=(abs(tmp(1)-Gshift(1,ik,iop))<err).and.&
&(abs(tmp(2)-Gshift(2,ik,iop))<err).and.&
&(abs(tmp(3)-Gshift(3,ik,iop))<err)
end do
end do
do ik=1,Nk_irr
do iop=1,nsymq
kphase(ik,iop)=exp(-ii*sum(SKI(:,ik)*pg(:,iop))*2*pi/nnp)
end do
end do
end subroutine get_kgroup
机器翻译的代码示例
function get_kgroup(nk_irr,nsymq,ski,rg,pg,nnp,gk,gshift,kphase) # #N[811]
#implicit none #LABEL[#FORTRAN_CONTROL[implicit]] #N[812]
#integer,intent(in) :: nk_irr, nsymq,rg(3,3,nsymq),pg(3,nsymq),nnp #LABEL[#FORTRAN_CONTROL[integer]] #N[813]
#real(8),intent(in) :: ski(3,nk_irr) #LABEL[#FORTRAN_CONTROL[real]] #N[814]
#logical,intent(out) :: gk(nk_irr,nsymq) #LABEL[#FORTRAN_CONTROL[logical]] #N[815]
#integer,intent(out) :: gshift(3,nk_irr,nsymq) #LABEL[#FORTRAN_CONTROL[integer]] #N[816]
#complex(8),intent(out) :: kphase(nk_irr,nsymq) #LABEL[#FORTRAN_CONTROL[complex]] #N[817]
# #N[818]
#integer :: ik,iop,jop,kop,tmp2(3) #LABEL[#FORTRAN_CONTROL[integer]] #N[819]
#logical :: flag #LABEL[#FORTRAN_CONTROL[logical]] #N[820]
#real(8) :: err=0.00001, tmp(3) #LABEL[#FORTRAN_CONTROL[real]] #N[821]
#real(8),parameter :: pi = acos(-1d0) #LABEL[#FORTRAN_CONTROL[real]] #N[822]
#complex(8),parameter :: ii = (0,1) #LABEL[#FORTRAN_CONTROL[complex]] #N[823]
# #N[824]
gk = false # #N[825]
flag = false # #N[826]
kphase = 1e0 # #N[827]
# #N[828]
# #N[829]
for ik = 1 : nk_irr # #N[830]
for iop = 1 : nsymq # #N[831]
tmp[1] = sum(rg[1,:,iop]*ski[:,ik])-ski[1,ik] # #N[832]
tmp[2] = sum(rg[2,:,iop]*ski[:,ik])-ski[2,ik] # #N[833]
tmp[3] = sum(rg[3,:,iop]*ski[:,ik])-ski[3,ik] # #N[834]
gshift[1,ik,iop] = nint(tmp[1]) # #N[835]
gshift[2,ik,iop] = nint(tmp[2]) # #N[836]
gshift[3,ik,iop] = nint(tmp[3]) # #N[837]
# #N[838]
gk[ik,iop] = (abs(tmp[1]-gshift[1,ik,iop])<err) && &(abs(tmp[2]-gshift[2,ik,iop])<err) && &(abs(tmp[3]-gshift[3,ik,iop])<err) # #N[841]
# #N[842]
end # #LABEL[#FORTRAN_END[for]] #N[843]
end # #LABEL[#FORTRAN_END[for]] #N[844]
# #N[845]
for ik = 1 : nk_irr # #N[846]
for iop = 1 : nsymq # #N[847]
kphase[ik,iop] = exp(-ii*sum(ski[:,ik]*pg[:,iop])*2*pi/nnp) # #N[848]
end # #LABEL[#FORTRAN_END[for]] #N[849]
end # #LABEL[#FORTRAN_END[for]] #N[850]
# #N[851]
end # #LABEL[#FORTRAN_END[subroutine]get_kgroup] #N[852]
# #N[853]
# #N[854]
我有个计划:找来一本 Fortran 教材,按照章节来写翻译模块,最后排序、组装。