&安培;在Fortran中不适用于长公式 [英] & doesn't work for long equation in Fortran

查看:185
本文介绍了&安培;在Fortran中不适用于长公式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  if(i == 1)then $ b (i,j + 1)= u(i,j)-c * dt / 2 / dx *(u(i + 1,j)-u(imax-1,j))& 
+(c * c * dt * dt)/ 2 / dx / dx *(u(i + 1,j)-2 * u(i,j)+ u(imax-1,j))

更多代码在这里:

  select case(case_no)
C .. 1 - Lax Wendroff一步计划
案例(1)
写入(6,*)'Lax- Wendroff one step method'
t = dt
do(t <= 18)
do i = 1,41
if(i == 1)then
u (i,j + 1)= u(i,j)-c * dt / 2 / dx *(u(i + 1,j)-u(imax-1,j))&
+ c * c * dt * dt / 2 / dx / dx *(u(i + 1,j)-2 * u(i,j)&b
+ u(imax- j))
else if(i == 41)then
u(i,j + 1)= u(i,j)-c * dt / 2 / dx *(u(i + j)-u(i-1,2))& (i,j)-2 * u(i,j)&
+ u(i-1, 2))
else
u(i,j + 1)= u(i,j)-c * dt / 2 / dx *(u(i + 1,j)-u ,j))& (i,j)-2 * u(i,j)&
+ u(i-1, j))
end if
j = j + 1
t = t + dt
end do
end do

方程太长,我想用'&'将它分成两行。但是编译器在'u(i,j + 1)'
处表示
1.可分类陈述2.在'+'处名称无效

<我是Fortran的新手。非常感谢。

解决方案

您有固定的表单源代码功能(您在第一列中使用C来开始注释),但是您询问有关免费表格续行。您需要确定您使用的是哪种源表单(自由格式最好是不需要与古代代码保持一致),请告诉编译器您正在以适当方式使用自由格式(通常使用.f90文件扩展名),然后确保评论风格,令牌拆分和续行方面与该表单一致。


Anyone can figure out what is wrong with these lines in Fortran :

if (i==1) then
    u(i,j+1)=u(i,j)-c*dt/2/dx*(u(i+1,j)-u(imax-1,j)) &
    + (c*c*dt*dt)/2/dx/dx*(u(i+1,j)-2*u(i,j)+u(imax-1,j))

more codes here:

      select case (case_no)
C.. 1--Lax Wendroff one step scheme
      case (1)
          write (6,*) 'Entrance for the Lax-Wendroff one step method'
          t=dt            
          do while (t<=18)
              do i=1,41
                  if (i==1) then
                      u(i,j+1)=u(i,j)-c*dt/2/dx*(u(i+1,j)-u(imax-1,j))    &
                      + c*c*dt*dt/2/dx/dx*(u(i+1,j)-2*u(i,j)    &
                      + u(imax-1,j))
                  else if (i==41) then
                      u(i,j+1)=u(i,j)-c*dt/2/dx*(u(i+1,j)-u(i-1,2))    &  
                      + c*c*dt*dt/2/dx/dx*(u(i+1,j)-2*u(i,j)    &
                      + u(i-1,2))
                  else 
                      u(i,j+1)=u(i,j)-c*dt/2/dx*(u(i+1,j)-u(i-1,j))    & 
                      + c*c*dt*dt/2/dx/dx*(u(i+1,j)-2*u(i,j)    & 
                      +u(i-1,j))
                  end if 
                  j=j+1
                  t=t+dt
              end do
          end do

Equation is too long and I wanna use '&' to separate it into two lines. But the compiler said 1. classifiable statement at 'u(i,j+1)' 2. invalid character in name at '+'

I am new to Fortran. Many thanks.

解决方案

You have fixed form source features (you are using a C in column one to start comments) but you are asking about free form line continuation. You need to decide which source form you are using (free form is best in the absence of a need to remain consistent with ancient code), tell the compiler that you are using free form in the appropriate manner (typically using a .f90 file extension) and then make sure that the comment style, token splitting and line continuation aspects are consistent with that form.

这篇关于&安培;在Fortran中不适用于长公式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆