开发者

Writing Java equivalent of the Fortran program

开发者 https://www.devze.com 2023-04-06 14:41 出处:网络
I have something like this in fortran. 20:call TESTBEGIN(a,b,c) if(c<1) g开发者_运维问答oto 40

I have something like this in fortran.

20:  call TESTBEGIN(a,b,c)
      if(c<1) g开发者_运维问答oto 40
30:  call TESTMIDDLE(e,f,g)
      if(g==1) goto 20
40:  return        

But my code is like this

   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


Something like that?

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

For the second code snippet try a state machine:

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;
}

Or better try to reconsider the algorithm, I think you could do it more easy to read and understand using Java.

0

精彩评论

暂无评论...
验证码 换一张
取 消