编写Java等效的Fortran程序

时间:2011-09-22 16:59:39

标签: fortran

我在fortran中有类似的东西。

20:  call TESTBEGIN(a,b,c)
      if(c<1) goto 40
30:  call TESTMIDDLE(e,f,g)
      if(g==1) goto 20
40:  return        

但我的代码就像这样

   Subroutine testCase()
20:   CALL beginTest(a,b)
     IF (b.EQ.-1) GOTO 999
30:   CALL middleTest(c,b)
       IF (b.EQ.-1) GOTO 20
40:   CALL endTest(d,b)
     IF (b.EQ.-1) GOTO 30
     CALL  LastTest(e,b)
      IF (.b.EQ.-1) GOTO 40
      DO I =1,j
      DTEMP(j)=1.0
     END DO
some code
999:return

1 个答案:

答案 0 :(得分:1)

那样的东西?

do
{
    c = TESTBEGIN(a,b);
    if (c < 1) break;
    g = TESTMIDDLE(e,f);
} while ( g == 1 );

对于第二个代码段,请尝试使用状态机:

for(int state = 1; state != 0; )
{
  switch(state)
  {
  case 1:
    state = (beginTest(a) == -1) ? 0 : 2;
    break;
  case 2:
    state = (middleTest(c) == -1) ? 1 : 3;
    break;
  case 3:
    state = (endTest(d) == -1) ? 2 : 4;
    break;
  case 4:
    state = (lastTest(e) == -1) ? 3 : 5;
    break;
  }
  case 5:
    state = 0;
//   DO I =1,j // Honestly I don't know what does it do.
//      DTEMP(j)=1.0
    break;
}

或者更好地尝试重新考虑算法,我认为您可以使用Java更容易阅读和理解。