/*
 * cpldosc_slowvf_main2.c
 *
 *  This file compute the solution of the slow flow, and stops
 *  when the solution reaches a fold.
 *  The initial conditions, parameter values (for sigma1, sigma2,
 *  and omega), and the stop time (in case it doesn't reach a fold)
 *  are given on the command line.
 */


#include <stdio.h>
#include <stdlib.h>

int cpldosc_fhat(double *x, double *p, double *q);
int cpldosc_slowvf_solve(double y[2], const double p[3], const double tfinal);

int main (int argc, char *argv[])
    {
    double y[2];
    double q[2];
    double p[3];

    if (argc != 7)
        {
        fprintf(stderr,"use: %s v1 v2 sigma1 sigma2 omega time_duration\n",argv[0]);
        exit(-1);
        }

    /*
     *  Get the values given on the command line.
     */
    double v1     = atof(argv[1]);
    double v2     = atof(argv[2]);
    double sigma1 = atof(argv[3]);
    double sigma2 = atof(argv[4]);
    double omega  = atof(argv[5]);
    double t1     = atof(argv[6]);

    y[0] = v1;
    y[1] = v2;

    p[0] = sigma1;
    p[1] = sigma2;
    p[2] = omega;

    /*
     *  Call the function to solve the slow vector field.
     */
    int status = cpldosc_slowvf_solve(y, p, t1);

    /*
     *  Call cpldosc_fhat to get the q values corresponding
     *  to the values of (v1,v2) in y.
     */
    cpldosc_fhat(y, p, q);

    fprintf(stderr,"Final:             %.12e %.12e %.12e %.12e\n",y[0],y[1],q[0],q[1]);
    if (status != 0)
        fprintf(stderr,"The solution did not reach a fold!\n");
    }

