1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

convert fortran to C++

Discussion in 'C++' started by norainon, Jul 9, 2008.

  1. norainon

    norainon New Member

    i have a question regarding to convert from fortran language to C++ programming especially in diognal array

    for example;

    DO 10 I=1,3*(X+2)
    10 ID(I)=(I-1)*m+1

    how do i convert into C++ programming

    please someone help me
     
  2. xpi0t0s

    xpi0t0s Mentor

    I'm not clear what the above code has to do with diagonal arrays; ID looks like a simple array to me.
    How about something like:
    int ID[SUITABLE_LIMIT];
    for (int i=1; i<=3*(x+2); i++) ID=(i-1)*m+1;
    Don't forget C++ arrays are zero based so SUITABLE_LIMIT must be at least the maximum value of 3*(x+2) PLUS ONE. Also the above loop doesn't initialise ID[0]; watch out for that one, maybe use an array name that indicates it's 1-based rather than zero based, something along the lines of Hungarian Notation but simpler, e.g int ID_nz[..], nz meaning "no zero element". I always end up confusing myself if I use some arrays that are zero based and some that are not, in the same program.
     
  3. abdunabi

    abdunabi New Member

    I have a question regarding to convert from fortran language to C++ programming. How I convert into C++ programming , Please someone help me!!!
    Code:
       DIMENSION TK(15), PK(15), TC(15),DT(15),DP(15),H(15),PAR(15),Q(15), M(15), PO(15), PO1(15), PO2(15), PI(15), 
        1 FORMAT (213)
        5 FORMAT (2F8.4,I3)
        3 FORMAT (3F10.4,I3) 
       15 FORMAT (///,8F10.5,/)
          READ (5,1) NG, M1
          READ (5,3) A,B,P,M2
          READ (5,5) DTF,DPF,Z
       25 FORMAT (F10.3)
       98 READ (5,25) T
          IF(T.EQ.0) GO TO 99
          DO 100 I=1, NG
          M(I)=M1+I-1
          TK(I)=A*(8*M(I)+M2)**P+8
          DT(I)=(M(I)-1)*0.02+DTF
          TC(I)=TK(I)/(0.567+DT(I)-DT(I)**2)
          DP(I)=(M(I)-1)*0.227+DPF
          PK(I)=(14*M(I)+Z)/(DP(I)+0.34)**2
          H(I)=(TK(I)/TC(I))*(ALOG10(PK(I))/(1-TK(I)/TC(I)))
          PAR(I)=ALOG10(PK(I))+H(I)*(1-TC(I)/T)
          PO2(I)=(14*M(I)+Z)/(82.06*TK(I))
          PI(I)=5*(T/TC(I)-1)
          PO1(I)=PO2(I)*10**PI(I)
          PO3=1
          PO(I)=PO1(I)+PO3*(1-T/TC(I))**0.3
      100 Q(I)=10**PAR(I)
       20 FORMAT (//,10F10.5,/)  
          WRITE(6,20) T
          WRITE(6,15) (Q(I),I=1,NG)
          WRITE(6,6) (PO(I),I=1,NG)
        6 FORMAT (///,8F10.6,/)
          GO TO 98
       99 CONTINUE
          STOP
          END
     
    Last edited by a moderator: Mar 7, 2012

Share This Page