Ejemplo n.º 1
0
int main(int argc, char **argv)
{
    Params params;
    params.m = 1;
    params.r = 2;
    params.Pr = 60;
    params.Pi = 60;
    params.peps = 0.2;
    params.t = 0.0;
    params.smear = 0;
    params.sigma = 0.0;

    const char* opt_prefix = "";
    int opt_select = OPT_SELECT_INTEGRAL;
    int opt_contour = OPT_CONTOUR_M;
    gsl_complex opt_z0 = { { 0.0 } };
    gsl_complex opt_z1 = { { 0.0 } };
    int opt_n = 10000;

    const char* const short_options = "";

    const struct option long_options[] = {
      { "help",         0, NULL, 'h' },
      { "envelope",     0, &opt_select, OPT_SELECT_ENVELOPE },
      { "integrand",    0, &opt_select, OPT_SELECT_INTEGRAND },
      { "bessel",       0, &opt_select, OPT_SELECT_BESSEL },
      { "contour-II",   0, &opt_contour, OPT_CONTOUR_II },
      { "contour-IUI",  0, &opt_contour, OPT_CONTOUR_IUI },
      { "d",            1, NULL, 'd' },
      { "n",            1, NULL, 'n' },
      { "m",            1, NULL, 'm' },
      { "prefix",       1, NULL, 'p' },
      { "r",            1, NULL, 'r' },
      { "t",            1, NULL, 't' },
      { "z0",           1, NULL, '0' },
      { "z1",           1, NULL, '1' },
      { "Pr",           1, NULL, 'P' },
      { "Pi",           1, NULL, 'I' },
      { "smear",        1, NULL, 's' },
      { NULL,           0, NULL, 0   } /* end */
    };

    int next_option;
    do {
        next_option = getopt_long(argc, argv, short_options,
                long_options, NULL);
        switch (next_option)
        {
            case 'h':
                print_usage(stdout, 0);

            case 'd':
                parse_double(optarg, &params.d);
                break;

            case 'm':
                parse_double(optarg, &params.m);
                break;

            case 'n':
                opt_n = atoi(optarg);
                if (opt_n < 1)
                    opt_n = 1;
                break;

            case 'p':
                opt_prefix = optarg;
                break;

            case 'r':
                parse_double(optarg, &params.r);
                break;

            case 's':
                parse_double(optarg, &params.sigma);
                params.smear = 1;
                break;

            case 't':
                parse_double(optarg, &params.t);
                break;

            case '?':
                // invalid option
                print_usage(stderr, 1);

            case '0':
                parse_complex(optarg, &opt_z0);
                break;

            case '1':
                parse_complex(optarg, &opt_z1);
                break;

            case 'P':
                parse_double(optarg, &params.Pr);
                break;

            case 'I':
                parse_double(optarg, &params.Pi);
                break;

            case 0:  break; // flag handled
            case -1: break; // end of options

            default:
                abort();
        }
    }
    while (next_option != -1);

    PlotContext ctx;
    memset(&ctx, 0, sizeof(ctx));
    ctx.filename_contour = alloc_sprintf("%sCONTOUR.dat", opt_prefix);
    ctx.filename_data = alloc_sprintf("%sFUNCTION.dat", opt_prefix);

    if (opt_select != OPT_SELECT_INTEGRAL)
    {
        FILE *os = fopen(ctx.filename_data, "w");
        ComplexFunction func;
        switch (opt_select)
        {
            case OPT_SELECT_ENVELOPE : func = (ComplexFunction) &f_envelope; break;
            case OPT_SELECT_INTEGRAND: func = (ComplexFunction) &f_integrand; break;
            case OPT_SELECT_BESSEL   : func = (ComplexFunction) &f_bessel; break;
            default: abort();
        }
        tabulate(os, func, &params, opt_z0, opt_z1, opt_n);
        fclose(os);

        Contour contour;
        define_contour_line_segment(opt_z0, opt_z1, &contour);

        os = fopen(ctx.filename_contour, "w");
        emit_contour_points(&params, &contour, os);
        fclose(os);
    }
    else
    {
        Contour contour;
        switch (opt_contour)
        {
            case OPT_CONTOUR_II:
                define_contour_II(&params, params.d, &contour);
                break;
            case OPT_CONTOUR_IUI:
                define_contour_M(&params, params.d, 1, &contour);
                break;
            case OPT_CONTOUR_M:
                define_contour_M(&params, params.d, 0, &contour);
                break;
            default: abort();
        }

        FILE *os = fopen(ctx.filename_data, "w");
        tabulate_integral(
            &params,
            &contour,
            GSL_REAL(opt_z0), GSL_REAL(opt_z1),
            opt_n, os);
        fclose(os);

        os = fopen(ctx.filename_contour, "w");
        emit_contour_points(&params, &contour, os);
        fclose(os);
    }

    return 0;
}
Ejemplo n.º 2
0
/**
 * Parses the byte stream according to the given document type
 * and creates a document model from it.
 *
 * @param p0 the destination (Hand over as reference!)
 * @param p1 the destination count
 * @param p2 the destination size
 * @param p3 the source
 * @param p4 the source count
 * @param p5 the type
 * @param p6 the type count
 */
void parse(void* p0, void* p1, void* p2, const void* p3, const void* p4,
           const void* p5, const void* p6) {

    // The comparison result.
    int r = 0;

    if (r != 1) {

        compare_arrays(p5, p6, (void*) CYBOL_ABSTRACTION, (void*) CYBOL_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

        if (r == 1) {

            parse_xml(p0, p1, p2, p3, p4);
        }
    }

    if (r != 1) {

        compare_arrays(p5, p6, (void*) OPERATION_ABSTRACTION, (void*) OPERATION_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

        if (r == 1) {

            parse_string(p0, p1, p2, p3, p4);
        }
    }

    if (r != 1) {

        compare_arrays(p5, p6, (void*) STRING_ABSTRACTION, (void*) STRING_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

        if (r == 1) {

            parse_string(p0, p1, p2, p3, p4);
        }
    }

    if (r != 1) {

        compare_arrays(p5, p6, (void*) BOOLEAN_ABSTRACTION, (void*) BOOLEAN_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

        if (r == 1) {

            parse_boolean(p0, p1, p2, p3, p4);
        }
    }

    if (r != 1) {

        compare_arrays(p5, p6, (void*) INTEGER_ABSTRACTION, (void*) INTEGER_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

        if (r == 1) {

            parse_integer(p0, p1, p2, p3, p4);
        }
    }

    if (r != 1) {

        compare_arrays(p5, p6, (void*) VECTOR_ABSTRACTION, (void*) VECTOR_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

        if (r == 1) {

            parse_vector(p0, p1, p2, p3, p4);
        }
    }

    if (r != 1) {

        compare_arrays(p5, p6, (void*) DOUBLE_ABSTRACTION, (void*) DOUBLE_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

        if (r == 1) {

            parse_double(p0, p1, p2, p3, p4);
        }
    }

    if (r != 1) {

        compare_arrays(p5, p6, (void*) FRACTION_ABSTRACTION, (void*) FRACTION_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

        if (r == 1) {

            parse_fraction(p0, p1, p2, p3, p4);
        }
    }

    if (r != 1) {

        compare_arrays(p5, p6, (void*) COMPLEX_ABSTRACTION, (void*) COMPLEX_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

        if (r == 1) {

            parse_complex(p0, p1, p2, p3, p4);
        }
    }

    if (r != 1) {

        compare_arrays(p5, p6, (void*) TIME_ABSTRACTION, (void*) TIME_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

        if (r == 1) {

            parse_time(p0, p1, p2, p3, p4);
        }
    }

    if (r != 1) {

        compare_arrays(p5, p6, (void*) CONFIGURATION_ABSTRACTION, (void*) CONFIGURATION_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

        if (r == 1) {

            parse_xml(p0, p1, p2, p3, p4);
        }
    }

    /*??
        //?? Later, distinguish file types according to abstraction,
        //?? for example xml, html, sxi, txt, rtf,
        //?? adl (from OpenEHR), KIF, ODL etc.!
        //?? For now, only the cybol file format is considered.

        if (r != 1) {

            compare_arrays(p5, p6, (void*) SXW_ABSTRACTION, (void*) SXW_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

            if (r == 1) {

                //?? For other kinds of file (stream) formats,
                //?? for example from special applications like Open Office,
                //?? use a similar handling like for compound above!

                //?? Images possibly also have to be handled that way.
                //?? At first, the single image parameters have to be parsed
                //?? and written into a special parameter model in memory;
                //?? then that model has to be decoded into a knowledge model!
                //?? May be this idea is rubbish and will not work!
                //?? For the beginning, better handle images as primitve types.
            }
        }
    */
}