Fortran to Matlab GOTO
    8 次查看(过去 30 天)
  
       显示 更早的评论
    
Hi everyone, I want to translate a Fortran Code to Matlab and I'm stuck in this part of the code specifically with the goto statement. Here is the part of the code I can't understand how to translate it.
      DO 11 J=2,N1
      Q10=Q1
      V10=V1
      IF(DU(J).EQ.0) GO TO 15    
      IF(DB(J).EQ.0) GO TO 515   
      QPU=0.
      QPB=0.
      V2=0.5*(V(J)+V(J-1)+Q(J)-Q(J-1))/(1.+0.5*ET*DX)
      Q2=Q(J-1)+V2-V(J-1)
      V1=V2
      Q1=Q(J)-V1+V(J)   
      DU3=DU(J)-V2*DT             
      DB3=DB(J)+V2*DT           
      IF(DU3.LE.0.) GO TO 50    
      IF(DB3.LE.0.) GO TO 550 
      GO TO 20
   15 QPU=Q(J-1)-Q(J)-V(J)-V(J-1)
      IF(QPU.GT.0.) GO TO 30    
      V2=0.
      Q2=Q(J-1)-V(J-1)
      V1=0.
      Q1=Q(J)+V(J)
      GO TO 111
   30 QPU=0.                   
      V2=0.5*(V(J)+V(J-1)+Q(J)-Q(J-1))/(1.+0.5*ET*DX)
      Q2=Q(J-1)+V2-V(J-1)
      V1=V2
      Q1=Q(J)-V1+V(J)
      DU3=-D2U(J)-V2*DT  
      DB3=DB(J)+V2*DT
      IF(DU3.GE.0.) THEN
      DU(J)=DU3      
      D2U(J)=0.      
      IF(DB3.LT.0.) GO TO 550
      ELSE
      DU(J)=0.      
      D2U(J)=ABS(DU3)     
      ENDIF
      DB(J)=DB3
      D2B(J)=0.
      GO TO 111
   20 DU(J)=DU3
      DB(J)=DB3
      D2U(J)=0.
      D2B(J)=0.
      GO TO 111
   50 DU(J)=0.
      D2U(J)=ABS(DU3)
      DB(J)=DB3
      D2B(J)=0.
      GO TO 111
515 QPB=Q(J-1)-Q(J)-V(J)-V(J-1)
    IF(QPB.LT.0.) GO TO 530
      V2=0.
      Q2=Q(J-1)-V(J-1)
      V1=0.
      Q1=Q(J)+V(J)
      GO TO 111
530 QPB=0.
    V2=0.5*(V(J)+V(J-1)+Q(J)-Q(J-1))/(1.+0.5*ET*DX)
    Q2=Q(J-1)+V2-V(J-1)
    V1=V2
    Q1=Q(J)-V1+V(J)
    DB3=-D2B(J)+V2*DT
    DU3=DU(J)-V2*DT
    IF(DB3.GE.0.) THEN
    DB(J)=DB3
    D2B(J)=0.
    IF(DU3.LT.0.) GO TO 50
    ELSE
    DB(J)=0.
    D2B(J)=ABS(DB3)
    ENDIF
    DU(J)=DU3
    D2U(J)=0.
    GO TO 111
550 DB(J)=0.
    D2B(J)=ABS(DB3)
    DU(J)=DU3
    D2U(J)=0.
111 Q(J-1)=Q10+Q2-Q(J-1)
    V(J-1)=V10+V2-V(J-1)
      U(J)=U(J)+V2*DT
      UPU(J)=U(J)-D2U(J)
      UPB(J)=U(J)+D2B(J)  
      11 CONTINUE
Thank you very much,
Carlos
0 个评论
回答(2 个)
  dpb
      
      
 2014-5-16
        First branch; similar for the rest altho may be more rework and need some other refactorization than just simple IF...ELSE...ENDIF branching
       DO 11 J=2,N1                             DO 11 j=2,n1
         Q10=Q1                                   Q10=Q1
         V10=V1                                   V10=V1
         IF(DU(J).EQ.0) GO TO 15                  IF(DU(J)<>0) then
         ...                                        ... 
   15    CONTINUE                                 ENDIF 
         QPU=Q(J-1)-Q(J)-V(J)-V(J-1)              QPU=Q(J-1)-Q(J)-V(J)-V(J-1)  % target line 15
         ...                                      ...
Probably the simpler is one of either
a) rewrite the functional requirements in Matlab syntax rather than try to transliterate, or
b) turn the existing Fortran into a mex file and call from Matlab.
0 个评论
  Yao Li
      
 2014-5-16
        There are many options:
- Create a function for each destination of "goto". ie. Create a fuction for 111
- Copy and paste the corresponding portion to where it is called
- Create a classdef and include all the functions in the classdef script
0 个评论
另请参阅
类别
				在 Help Center 和 File Exchange 中查找有关 Fortran with MATLAB 的更多信息
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


