Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Fortran 77到C+的翻译+-它是如何工作的?_C++_Fortran_Fortran77 - Fatal编程技术网

C++ Fortran 77到C+的翻译+-它是如何工作的?

C++ Fortran 77到C+的翻译+-它是如何工作的?,c++,fortran,fortran77,C++,Fortran,Fortran77,我试图将下面的FORTRAN 77子程序复制到C++中。 subroutine calcul(nb, m, sd, x_min, n, y_w) common / speed_1 / v_0 common / dat1 / x_m common / dat2 / x_l0, x_r0, x_lq, e_l, e_r, a1, a2, b1 common / sor_arr / x(6500), y(6500), z(6500) co

我试图将下面的FORTRAN 77子程序复制到C++中。
     subroutine calcul(nb, m, sd, x_min, n, y_w)

     common / speed_1 / v_0
     common / dat1 / x_m
     common / dat2 / x_l0, x_r0, x_lq, e_l, e_r, a1, a2, b1 
     common / sor_arr / x(6500), y(6500), z(6500)
     common / ef_mat / x_f(35000), y_f(35000)

     y_m = y_w - rl_h
     y_ma = rl_h
     y_mi = -rl_h
     x_ma = rb_h
     x_mi = -rb_h

     do 10 i = m, 1, -1
     y_y = z(i) - y_m

     if (y_y.gt.y_ma) goto 10
     if (y_y.le.y_mi) goto 10

     c1_s = y(i) / v_0
     x_l = x_l0 + e_l*c1_s**a1
     x_r = x_r0 + e_r*c1_s**a2
     cl_r = x_r - x_l
     c2_s = x(i) + x_min

    i1 = 1
    i2 = nb
    i3 = 1
    if (mod(i, 2).eq. 0) goto 20
    i1 = nb
    i2 = 1
    i3 = -1

 20 do 30 i = i1, i2, i3
    r_m1 = float(i - 1)
    x_q = c2_s + r_m1*sd - x_l
    x_q = x_q * b1 / c1_r + xl_q

    x_x = x_q - x_m
    if (x_x.gt.x_ma) goto 30
    if (x_x.le.x_mi) goto 30

    n = n + 1
    y_f(n) = y_y
    x_f(n) = x_x

 30 continue
 10 continue

    return
    end  
这是我的译文

 #include "stdafx.h"
 #include <iostream>



 using namespace std;




 void calcul(int& nb, int& m, double& sd, double& x_min, int& n, double& y_w);


struct speed
{
   double v_0;
};

struct dat1
{
double x_m;
};

struct dat2
{
double x_l0, x_r0, x_lq, e_l, e_r, rl_h, rb_h, a1, a2, b1;
};


struct sor_arr
{
double x[6500], y[6500], z[6500];
};


struct ef_mat
{
double x_f[35000], y_f[35000];
};




int main()
{
int nb1 = 10;
int m1 = 250;
double sd1 = 16;
double x1nmin = 1.e38;
int n1 = 0;
double yw1 = 0;




calcul(nb1, m1, sd1, x1nmin, n1, yw1);


system("PAUSE");
return 0;
}

void calcul(int& nb, int& m, double& sd, double& x_min, int& n, double& y_w)
{
struct speed sp;
struct dat1 d1;
struct dat2 d2;
struct sor_arr s;
struct ef_mat ef;

int i1;
int i2;
int i3;


double y_m;
double y_ma;
double y_mi;
double x_ma;
double x_mi;
double y_y;
double x_x;
double c1_s;
double x_l;
double x_r;
double cl_r;
double c2_s;
double r_m1;
double x_q;





y_m = y_w - d2.rl_h;
y_ma = d2.rl_h;
y_mi = -d2.rl_h;
x_ma = d2.rb_h;
x_mi = -d2.rb_h;

for (int i = m; i > 1;  i--)
{
    y_y = s.z[i] - y_m;

    if (y_y > y_ma)
    {
        continue;
    }

    if (y_y <= y_ma)
    {
        continue;
    }

    c1_s = s.y[i] / sp.v_0;
    x_l = d2.x_l0 + d2.e_l * pow(c1_s, d2.a1);
    x_r = d2.x_r0 + d2.e_r * pow(c1_s, d2.a2);
    cl_r = x_r - x_l;
    c2_s = s.x[i] + x_min;

    i1 = 1;
    i2 = nb;
    i3 = 1;

    if (fmod(i,2)== 0)
    {


        for (int i = i1; i < i2; i+= i3)
        {
            r_m1 = float(i - 1);
            x_q = c2_s + r_m1 * sd - x_l;
            x_q = x_q * d2.b1 / cl_r + d2.x_lq;
            x_x = x_q - d1.x_m;


            if (x_x >= x_ma)
            {
                continue;
            }

            if (x_x < x_ma)
            {
                continue;
            }

            n = n + 1;
            ef.y_f[n] = y_y;
            ef.x_f[n] = x_x;


        }

        i1 = nb;
        i2 = 1;
        i3 = -1;

    }


   }

}

这有点疯狂和大胆,但您可以尝试初始化局部变量

例如:

struct speed sp = {0};
struct dat1 d1 = {0};
struct dat2 d2 = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
<> P>如果你真的疯了,你甚至可以考虑使用其他的值,而不是0个在这个算法中真正有意义的东西!p>
注意:我对Fortran一点也不了解,也没有进一步研究代码中的问题。

这是因为您使用的是未初始化的局部变量……首先,它说的是“警告”。不是错误。所以你应该能够编译和运行。。。再说一次,如果我真的试图按原样编译代码,它确实会出错。因此,您应该做的第一件事是修复您帖子中的代码,以便我们能够重现您的问题。但真正让我感兴趣的是
未初始化的局部变量“sp”使用了哪一部分
您在理解上有困难吗?请不要诋毁您的问题。评论不用于扩展讨论;这段对话太激烈了,太激进了!
struct speed sp = {0};
struct dat1 d1 = {0};
struct dat2 d2 = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};