24小时热门版块排行榜    

查看: 1059  |  回复: 4

Russellxys

新虫 (初入文坛)

[求助] 帮忙看看人工合成地震记录的小程序的错误点,始终运行不了,又找不到错在哪里?谢谢 已有1人参与

//正演(合成地震记录)

/**************************************************/
//库头文件
#include"stdio.h"
#include"stdlib.h"
#include"math.h"

/***************************************************/
//预处理宏定义
#define L_R 69
#define Trace 31
#define dx 1                //道间距
#define sample 512
#define dt 0.001
#define pi 3.1415926

/****************************************************/
//声明函数
int Ricker(float *x,float y);//雷克子波
int Reflect(float *x,float *y,float r[]);//反射系数
int Conv(float *x,float la,float *y,float lb,float c[]);//褶积

/****************************************************/
//主函数部分
int main()
{
        FILE *fp_reflect,*fp_conv;
        if((fp_reflect=fopen("reflect.dat","wb")==NULL)
                printf("can not open the reflect file\n";
        if((fp_conv=fopen("conv.dat","wb")==NULL)
                printf("can not open the conv file\n";
        int i;
        float F;//子波主频
        float Ri[L_R]={0.},Re[sample],Co[sample],P[3],VP[3];

        //定义地层模型参数
        for(i=0;i<3;i++)
        {
                printf("please input the magnitude of VP[%d]\n",i);
                scanf("%f",VP+i);
                printf("please input the magnitude of P[%d]\n",i);
                scanf("%f",P+i);
        }
        printf("please input the frequency of wave\n";
        scanf("%d",&F);

        for(i=0;i<Trace;i++)
        {
                Reflect(VP,P,Re);
                Conv(Re,sample,Ri,L_R,Co);
                fwrite(Re,sizeof(float),sample,fp_reflect );//frite读一个实数或者结构体变量的值
                fwrite(Co,sizeof(float),sample,fp_conv );
        }
        fclose(fp_reflect);
        fclose(fp_conv);
}

/****************************************************/
//定义子函数
int Ricker(float *x,float y)
{
        FILE *fp;
        if((fp=(fopen("Ricker.txt","w"))==NULL)
                printf("can not open the file\n";
        int i;
        float t;
        for(i=1;i<=L_R/2;i++)
        {
                t=i*dt;
                *(x+L_R/2) = 1.0;
                x[L_R/2+i] = cos(2*pi*y*t)*exp(-pow(pi*y*t,2));
        x[L_R/2-i] = x[L_R/2+i];
        }
        for(i=0;i<L_R;i++)
        {
                fprintf(fp,"%f",x+i);
        }
        fclose(fp);
        return 1;
}

int Reflect(float *x,float *y,float r[])
{
        int i,Z1,Z2;
        static int h=25;
        Z1=(int)h/x[0]*dt;
        Z2=(int)Z1+h/x[1]*dt;
        for(i=0;i<sample;i++)
        {
                if(i==Z1)
                        r=(x[1]*y[1]-x[0]*y[0])/(x[1]*y[1]+x[0]*y[0]);
                if(i==Z2)
                        r=(x[2]*y[2]-x[1]*y[1])/(x[1]*y[1]+x[2]*y[2]);
                else
                        r=0.;
        }
        return 1;
}
int Conv(float *x,float la,float *y,float lb,float c[])
{
        int i,j;
        for(i=1;i<=la+lb-1;i++)
        {
                c=0.;
                for(j=0;j<i&&i-j<lb;j++)
                {
                        c=c+x[j]*x[i-j-1];
                }
        }
        return 1;
}
回复此楼
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

1014511134

专家顾问 (正式写手)

【答案】应助回帖

编译器没有提供错误信息吗?还是能运行出不来结果?
2楼2015-10-12 10:27:31
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

匿名

用户注销 (正式写手)

本帖仅楼主可见
3楼2019-04-19 13:53:51
已阅   申请EPI   回复此楼   编辑   查看我的主页

baobiao007

木虫 (职业作家)

中国特色

引用回帖:
3楼: Originally posted by 泰罗 at 2019-04-19 13:53:51
同行但是我不会

这么老的帖子都被你翻起来了
我同意叔本华的观点,人们投身艺术和科学领域的强烈愿望之一就是逃离痛苦、残酷和枯燥无味的现实生活,逃离自己飘忽不定的七情六欲的桎梏。--爱因斯坦
4楼2019-04-19 19:20:01
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

匿名

用户注销 (正式写手)

本帖仅楼主可见
5楼2019-04-19 19:21:41
已阅   申请EPI   回复此楼   编辑   查看我的主页
相关版块跳转 我要订阅楼主 Russellxys 的主题更新
信息提示
请填处理意见