<commit_before>/*
  This file is part of the Astrometry.net suite.
  Copyright 2006, 2007 <NAME>, <NAME> and <NAME>.

  The Astrometry.net suite is free software; you can redistribute
  it and/or modify it under the terms of the GNU General Public License
  as published by the Free Software Foundation, version 2.

  The Astrometry.net suite is distributed in the hope that it will be
  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with the Astrometry.net suite ; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
*/

#include <stdio.h>

#include <assert.h>
#include <stddef.h>
#include <errno.h>
#include <string.h>

#include "an-catalog.h"
#include "fitsioutils.h"
#include "starutil.h"
#include "gnu-specific.h"
#include "errors.h"

// This is a naughty preprocessor function because it uses variables
// declared in the scope from which it is called.
#define ADDCOL(ctype, ftype, col, units, member)                        \
    if (write) {                                                        \
        fitstable_add_column_struct                                     \
            (tab, ctype, 1, offsetof(an_entry, member),                 \
             ftype, col, units, TRUE);                                  \
    } else {                                                            \
        fitstable_add_column_struct                                     \
            (tab, ctype, 1, offsetof(an_entry, member),                 \
             any, col, units, TRUE);                                    \
    }

static void add_columns(fitstable_t* tab, bool write) {
    tfits_type any = fitscolumn_any_type();
    tfits_type d = fitscolumn_double_type();
    tfits_type f = fitscolumn_float_type();
    tfits_type u8 = fitscolumn_u8_type();
    tfits_type i = fitscolumn_int_type();
    tfits_type i64 = fitscolumn_i64_type();
    tfits_type c = fitscolumn_char_type();
    int ob;
    char* nil = " ";

    ADDCOL(d, d, "RA",  "deg", ra);
    ADDCOL(d, d, "DEC", "deg", dec);
    ADDCOL(f, f, "SIGMA_RA",  "deg", sigma_ra);
    ADDCOL(f, f, "SIGMA_DEC", "deg", sigma_dec);
    ADDCOL(f, f, "MOTION_RA",  "arcsec/yr", motion_ra);
    ADDCOL(f, f, "MOTION_DEC", "arcsec/yr", motion_dec);
    ADDCOL(f, f, "SIGMA_MOTION_RA",  "arcsec/yr", sigma_motion_ra);
    ADDCOL(f, f, "SIGMA_MOTION_DEC", "arcsec/yr", sigma_motion_dec);
    ADDCOL(u8, u8, "NOBSERVATIONS", nil, nobs);
    ADDCOL(i64, i64, "ID", nil, id);

	for (ob=0; ob<AN_N_OBSERVATIONS; ob++) {
		char fld[32];
		sprintf(fld, "CATALOG_%i", ob);
        ADDCOL(c, c, fld, nil, obs[ob].catalog);
		sprintf(fld, "BAND_%i", ob);
        ADDCOL(c, c, fld, nil, obs[ob].band);
		sprintf(fld, "ID_%i", ob);
        ADDCOL(i, i, fld, nil, obs[ob].id);
		sprintf(fld, "MAG_%i", ob);
        ADDCOL(f, f, fld, "mag", obs[ob].mag);
		sprintf(fld, "SIGMA_MAG_%i", ob);
        ADDCOL(f, f, fld, "mag", obs[ob].sigma_mag);
    }
}
#undef ADDCOL

int an_catalog_read_entries(an_catalog* cat, int offset,
							int count, an_entry* entries) {
    return fitstable_read_structs(cat, entries, sizeof(an_entry),
                                  offset, count);
}

an_entry* an_catalog_read_entry(an_catalog* cat) {
    return (an_entry*)fitstable_next_struct(cat);
}

int an_catalog_write_entry(an_catalog* cat, an_entry* entry) {
    return fitstable_write_struct(cat, entry);
}
<commit_msg>catalog field should be a u8, not a char<commit_after>/*
  This file is part of the Astrometry.net suite.
  Copyright 2006, 2007 <NAME>, <NAME> and <NAME>.

  The Astrometry.net suite is free software; you can redistribute
  it and/or modify it under the terms of the GNU General Public License
  as published by the Free Software Foundation, version 2.

  The Astrometry.net suite is distributed in the hope that it will be
  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with the Astrometry.net suite ; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
*/

#include <stdio.h>

#include <assert.h>
#include <stddef.h>
#include <errno.h>
#include <string.h>

#include "an-catalog.h"
#include "fitsioutils.h"
#include "starutil.h"
#include "gnu-specific.h"
#include "errors.h"

// This is a naughty preprocessor function because it uses variables
// declared in the scope from which it is called.
#define ADDCOL(ctype, ftype, col, units, member)                        \
    if (write) {                                                        \
        fitstable_add_column_struct                                     \
            (tab, ctype, 1, offsetof(an_entry, member),                 \
             ftype, col, units, TRUE);                                  \
    } else {                                                            \
        fitstable_add_column_struct                                     \
            (tab, ctype, 1, offsetof(an_entry, member),                 \
             any, col, units, TRUE);                                    \
    }

static void add_columns(fitstable_t* tab, bool write) {
    tfits_type any = fitscolumn_any_type();
    tfits_type d = fitscolumn_double_type();
    tfits_type f = fitscolumn_float_type();
    tfits_type u8 = fitscolumn_u8_type();
    tfits_type i = fitscolumn_int_type();
    tfits_type i64 = fitscolumn_i64_type();
    tfits_type c = fitscolumn_char_type();
    int ob;
    char* nil = " ";

    ADDCOL(d, d, "RA",  "deg", ra);
    ADDCOL(d, d, "DEC", "deg", dec);
    ADDCOL(f, f, "SIGMA_RA",  "deg", sigma_ra);
    ADDCOL(f, f, "SIGMA_DEC", "deg", sigma_dec);
    ADDCOL(f, f, "MOTION_RA",  "arcsec/yr", motion_ra);
    ADDCOL(f, f, "MOTION_DEC", "arcsec/yr", motion_dec);
    ADDCOL(f, f, "SIGMA_MOTION_RA",  "arcsec/yr", sigma_motion_ra);
    ADDCOL(f, f, "SIGMA_MOTION_DEC", "arcsec/yr", sigma_motion_dec);
    ADDCOL(u8, u8, "NOBSERVATIONS", nil, nobs);
    ADDCOL(i64, i64, "ID", nil, id);

	for (ob=0; ob<AN_N_OBSERVATIONS; ob++) {
		char fld[32];
		sprintf(fld, "CATALOG_%i", ob);
        ADDCOL(u8, u8, fld, nil, obs[ob].catalog);
		sprintf(fld, "BAND_%i", ob);
        ADDCOL(c, c, fld, nil, obs[ob].band);
		sprintf(fld, "ID_%i", ob);
        ADDCOL(i, i, fld, nil, obs[ob].id);
		sprintf(fld, "MAG_%i", ob);
        ADDCOL(f, f, fld, "mag", obs[ob].mag);
		sprintf(fld, "SIGMA_MAG_%i", ob);
        ADDCOL(f, f, fld, "mag", obs[ob].sigma_mag);
    }
}
#undef ADDCOL

int an_catalog_read_entries(an_catalog* cat, int offset,
							int count, an_entry* entries) {
    return fitstable_read_structs(cat, entries, sizeof(an_entry),
                                  offset, count);
}

an_entry* an_catalog_read_entry(an_catalog* cat) {
    return (an_entry*)fitstable_next_struct(cat);
}

int an_catalog_write_entry(an_catalog* cat, an_entry* entry) {
    return fitstable_write_struct(cat, entry);
}

{'fraction_non_alphanumeric': 0.11876973774543458, 'fraction_numerical': 0.010572566250171632, 'mean_word_length': 2.4603325415676958, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6566977', 'n_tokens_mistral': 2553, 'n_tokens_neox': 2450, 'n_words': 700}