[語法]從fortran改成c++

看板C_and_CPP (C/C++)作者 (su)時間16年前 (2009/02/14 16:55), 編輯推噓6(603)
留言9則, 2人參與, 最新討論串1/2 (看更多)
老實說我對兩個程式語言都不熟,我也知道程式沒有很難 可是我盡量從fortran改成C++程式,改成這樣還是一堆錯誤 請各位前輩看一下哪邊還需要更改 成功的話 小弟贈予p幣500 自己改的程式碼連接 http://rafb.net/p/PgBVZ999.html 原文程式碼連接 http://src.wtgstudio.com/?cAajG0 -----------------------------這是我改過的程式------------------------------ void u_userNucl (float dtn, /* gaussian distribution parameter */ float dts, /* gaussian distribution parameter */ float nmax, /* gaussian distribution parameter */ double tliq, /* liquidus temperature */ double rtime, /* current time */ double pdt, /* time step */ int ir, /* cell reference number */ double x, /* first cell coordinates */ double y, /* second cell coordinates */ double z, /* third cell coordinates */ float *phi1, /* first Euler angle */ float *phi, /* second Euler angle */ float *phi2, /* third Euler angle */ double tc, /* cell temperature */ float *und, /* current nucleation undercooling */ float dt0, /* initial nucleation undercooling */ double crliq, /* cooling rate in the cell at liquidus */ double tmax, /*maximum temperature reached in the cell*/ int nuclv, /*number of user variables for nucleation*/ float *puv) ; /* array of user variables for nucleation*/ /*rtime*4 int dts,nmax,phi1,phi,phi2,und,dt0,puv(nuclv)*/ int main(void) { if (rtime=0.) puv(1) = .0 int extime=5000+100*(tliq-tc) if (extime<0.) extime=.0 // EXTIME is the typical extinction time of a site which depends on // temperature puv(1) = puv(1) + pdt/extime if (puv(1)>1.) und= 1000. } ----------------------------------這是fortran原文----------------------------- SUBROUTINE USERNUCL(DTN,DTS,DNMAX,TLIQ,RTIME,PDT,IR,X,Y,Z, & I1,PHI,PHI2,TC,UND,DT0,CRLIQ,TMAX,NUCLV,PUV) C C /////////////////////////////////////////////////////////////////// C // C // ** PURPOSE ** C // THIS USER SUBROUTINE DESCRIBES THE CHANGE OF NUCLEATION c // BEHAVIOUR AS THE METAL IS MAINTAINED AT HIGH TEMEPRATURE C // C // C // ** INPUT ARGUMENTS ** C // [S] DTN GAUSSIAN DISTRIBUTION PARAMETER C // [S] DTS GAUSSIAN DISTRIBUTION PARAMETER C // [S] DNMAX GAUSSIAN DISTRIBUTION PARAMETER C // [D] TLIQ LIQUIDUS TEMPERATURE C // [D] RTIME CURRENT TIME C // [D] PDT TIME STEP C // [I] IR CELL REFERENCE NUMBER C // [D] X,Y,Z CELL COORDINATES C // [S] PHI1 1st EULER ANGLE C // [S] PHI 2nd EULER ANGLE C // [S] PHI2 3rd EULER ANGLE C // [D] TC CELL TEMPERATURE C // [S] UND CURRENT NUCLEATION UNDERCOOLING C // [S] DT0 INITIAL NUCLEATION UNDERCOOLING C // [D] CRLIQ COOLING RATE IN THE CELL AT LIQUIDUS C // [D] TMAX MAXIMUM TEMPERATURE REACHED IN THE CELL C // [I] NUCLV NUMBER OF USER VARIABLES FOR NUCLEATION C // [S] PUV ARRAY OF USER VARIABLES FOR NUCLEATION C // C // C // ** OUTPUT ARGUMENTS ** C // [S] UND CURRENT NUCLEATION UNDERCOOLING C // [S] PHI1 1st EULER ANGLE C // [S] PHI 2nd EULER ANGLE C // [S] PHI2 3rd EULER ANGLE C // C // C /////////////////////////////////////////////////////////////////// CC IMPLICIT DOUBLE PRECISION (A-H,O-Z) C REAL*4 DTN,DTS,DNMAX,PHI1,PHI,PHI2,UND,DT0,PUV(NUCLV) CC IF (RTIME .EQ. 0.) THEN PUV(1) = .0 END IF EXTIME =5000 + 100*(TLIQ-TC); IF (EXTIME .LT. 0.) EXTIME = .0 C// EXTIME is the typical extinction time of a site which depends on C// temperature PUV(1) = PUV(1) + PDT/EXTIME IF (PUV(1) .GE. 1.) THEN UND = 1000. END IF END -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.118.198.85 ※ 編輯: Homeparty 來自: 140.118.198.85 (02/14 17:02)

02/15 00:07, , 1F
主函式裡的分號都不見了
02/15 00:07, 1F

02/15 00:11, , 2F
然後後面的部份應該是寫在函式定義裡面…
02/15 00:11, 2F

02/15 00:11, , 3F
而不是寫在main裡面
02/15 00:11, 3F

02/15 00:20, , 4F
請愛用F2C
02/15 00:20, 4F

02/15 00:22, , 5F
然後存取array要用中括號而不是小括號
02/15 00:22, 5F

02/15 00:24, , 6F

02/15 00:25, , 7F
改成這樣至少compile會過了
02/15 00:25, 7F

02/15 00:28, , 8F
再改一個地方… C++的array的index一定要從0開始
02/15 00:28, 8F

02/15 00:29, , 9F
文章代碼(AID): #19beSU8e (C_and_CPP)
討論串 (同標題文章)
文章代碼(AID): #19beSU8e (C_and_CPP)