Results 1 to 3 of 3

Thread: Ricker Wavelet application crashes on execution, exit code 255

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2018
    Posts
    6
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Ricker Wavelet application crashes on execution, exit code 255

    Hi everyone,
    I´m a beginner on programming and Qt, but as liked the framework I´m trying to improve my skills and write my C++ codes on it. I got a task of writting a Ricker wavelet code and then plot it.
    I divided it in two tasks, first make the ricker code works, and when it is running, then implement a way to plot it, I will use qcustomplot for it.
    I got a code from C and I´m trying to adapt it to Qt. Although it doesn´t give any errors during compilation, when executing it crashes, with the following message:

    Invalid parameter passed to C runtime function.
    C:/Users/Flavio/Documents/qtTest/build-ricker2-Desktop_Qt_5_11_0_MinGW_32bit-Debug/debug/ricker2.exe exited with code 255

    The code I´m supposed to translate is:

    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    float *rickerwavelet(float fpeak, float dt, int *nwricker);
    int main(int argc, char **argv)
    {
    int i;
    float dt;
    float fpeak;

    float *wricker=NULL;
    int nwricker;

    fpeak = atof(argv[1]);
    dt = atof(argv[2]);

    wricker = rickerwavelet(fpeak, dt, &nwricker);

    /* show value of ricker wavelets */
    for (i=0; i<nwricker; i++)
    printf("%i. %3.5f \n", i, wricker[i]);

    free(wricker);
    return(1);
    }

    /* ricker wavelet function, return an array ricker wavelets */
    float *rickerwavelet(float fpeak, float dt, int *nwricker)
    {
    int i, k;
    int nw;
    int nc;
    float pi;
    float nw1, alpha, beta;
    float *wricker=NULL;

    pi = 3.141592653589793;
    nw1 = 2.2/fpeak/dt;
    nw = 2*floor(nw1/2)+1;
    nc = floor(nw/2);

    wricker = (float*) calloc (nw, sizeof(float));
    for (i=0; i<nw; i++)
    {
    k = i+1;
    alpha = (nc-k+1)*fpeak*dt*pi;
    beta = pow(alpha, 2.0);
    wricker[i] = (1 - (beta*2)) * exp(-beta);
    }

    (*nwricker) = nw;
    return(wricker);
    }


    The code i wrote on Qt is:

    #include <QCoreApplication>
    #include <qmath.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <QDebug>

    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);
    int i,k,nw,nc;
    double *wricker=NULL;
    int nwricker = 60;
    int wavelet_freq = 30;
    int polarity=1;
    int sampling_rate=0.004;
    float nw1, alpha, beta;
    const double pi = 3.141592653589793238460;

    nw1 = 2.2/wavelet_freq/sampling_rate;
    nw = 2*floor(nw1/2)+1;
    nc = floor(nw/2);


    wricker = (double*)calloc (nw, sizeof(double));
    for (i=0; i<nw; i++)
    {
    k = i+1;
    alpha = (nc-k+1)*wavelet_freq*sampling_rate*pi;
    beta = pow(alpha, 2.0);
    wricker[i] = polarity*((1 - (beta*2)) * exp(-beta));
    };
    /* show value of ricker wavelets */
    for (i=0; i<nwricker; i++)
    {
    qDebug()<<i<<wricker[i];
    };

    free(wricker);

    return a.exec();
    }




    Analytic expression

    The amplitude A of the Ricker wavelet with peak frequency f at time t is computed like so:

    A = (1-2 *pi^2* f^2* t^2) e^{-pi^2* f^2* t^2}

    A py code for it would be:


    import numpy as np
    import matplotlib.pyplot as plt

    def ricker(f, length=0.128, dt=0.001):
    t = np.arange(-length/2, (length-dt)/2, dt)
    y = (1.0 - 2.0*(np.pi**2)*(f**2)*(t**2)) * np.exp(-(np.pi**2)*(f**2)*(t**2))
    return t, y

    f = 25 # A low wavelength of 25 Hz
    t, w = ricker(f)

    What seems quite simple.

    Does anyone have any idea what is wrong in my code???

    Thanks in advance.
    Attached Images Attached Images
    Attached Files Attached Files

Similar Threads

  1. Replies: 8
    Last Post: 29th December 2016, 17:42
  2. Replies: 1
    Last Post: 13th September 2011, 09:56
  3. Replies: 2
    Last Post: 21st November 2010, 18:03
  4. Replies: 3
    Last Post: 2nd November 2010, 22:36
  5. QThread crashes on exit
    By mhoover in forum Qt Programming
    Replies: 8
    Last Post: 26th August 2009, 20:19

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.