<commit_before>#include <phypp.hpp>

void print_help();

int phypp_main(int argc, char* argv[]) {
    if (argc < 2) {
        print_help();
        return 0;
    }

    uint_t continuum_width = 350; // in spectral element

    read_args(argc-1, argv+1, arg_list(continuum_width));

    // Copy and open cube
    std::string infile = argv[1];
    std::string outfile = file::remove_extension(file::get_basename(infile))+"_contsub.fits";
    file::copy(infile, outfile);

    vec3d cflx, cerr;
    fits::image fimg(outfile);
    fimg.reach_hdu(1);
    fimg.read(cflx);
    fimg.reach_hdu(1);
    fimg.read(cerr);

    // Estimate and subtract the continuum emission
    for (uint_t y : range(cflx.dims[1]))
    for (uint_t x : range(cflx.dims[2])) {
        vec1d tflx = cflx(_,y,x);
        // vec1d twei = 1.0/cerr(_,y,x);
        vec1d twei = 0.0*cerr(_,y,x) + 1.0;

        for (uint_t l : range(cflx.dims[0])) {
            uint_t l0 = max(0, int_t(l)-int_t(continuum_width/2));
            uint_t l1 = min(cflx.dims[0]-1, int_t(l)+int_t(continuum_width/2));
            cflx(l,y,x) -= weighted_median(tflx[l0-_-l1], twei[l0-_-l1]);
        }
    }

    fimg.reach_hdu(1);
    fimg.update(cflx);

    return 0;
}

void print_help() {
    using namespace format;

    print("contsub v1.0");<commit_msg>Fixed harmless warning for sign comparison<commit_after>#include <phypp.hpp>

void print_help();

int phypp_main(int argc, char* argv[]) {
    if (argc < 2) {
        print_help();
        return 0;
    }

    uint_t continuum_width = 350; // in spectral element

    read_args(argc-1, argv+1, arg_list(continuum_width));

    // Copy and open cube
    std::string infile = argv[1];
    std::string outfile = file::remove_extension(file::get_basename(infile))+"_contsub.fits";
    file::copy(infile, outfile);

    vec3d cflx, cerr;
    fits::image fimg(outfile);
    fimg.reach_hdu(1);
    fimg.read(cflx);
    fimg.reach_hdu(1);
    fimg.read(cerr);

    // Estimate and subtract the continuum emission
    for (uint_t y : range(cflx.dims[1]))
    for (uint_t x : range(cflx.dims[2])) {
        vec1d tflx = cflx.safe(_,y,x);
        // vec1d twei = 1.0/cerr(_,y,x);
        vec1d twei = 0.0*cerr.safe(_,y,x) + 1.0;

        for (uint_t l : range(cflx.dims[0])) {
            uint_t l0 = max(0, int_t(l)-int_t(continuum_width/2));
            uint_t l1 = min(cflx.dims[0]-1, l+continuum_width/2);
            cflx.safe(l,y,x) -= weighted_median(tflx.safe[l0-_-l1], twei.safe[l0-_-l1]);
        }
    }

    fimg.reach_hdu(1);
    fimg.update(cflx);

    return 0;
}

void print_help() {
    using namespace format;

    print("contsub v1.0");
{'fraction_non_alphanumeric': 0.16049848942598188, 'fraction_numerical': 0.028700906344410877, 'mean_word_length': 2.704895104895105, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6144575', 'n_tokens_mistral': 1123, 'n_tokens_neox': 1079, 'n_words': 194}