aboutsummaryrefslogtreecommitdiff
path: root/utils/calculate-atmospheric-oscillations
diff options
context:
space:
mode:
Diffstat (limited to 'utils/calculate-atmospheric-oscillations')
0 files changed, 0 insertions, 0 deletions
ef='#n66'>66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
/* Copyright (c) 2019, Anthony Latorre <tlatorre at uchicago>
 *
 * This program 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, either version 3 of the License, or (at your option)
 * any later version.

 * This program 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
 * this program. If not, see <https://www.gnu.org/licenses/>.
 */

#include "pmt.h"
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include "vector.h"
#include "util.h"

static int initialized = 0;

pmt pmts[MAX_PMTS];

void get_pmt_type_string(int pmt_type, char *s)
{
    switch (pmt_type) {
    case 1:
        sprintf(s,"Normal");
        break;
    case 2:
        sprintf(s,"OWL");
        break;
    case 3:
        sprintf(s,"LG");
        break;
    case 4:
        sprintf(s,"BUTT");
        break;
    case 5:
        sprintf(s,"NECK");
        break;
    case 6:
        sprintf(s,"CALIBRATION");
        break;
    case 10:
        sprintf(s,"SPARE");
        break;
    case 11:
        sprintf(s,"INVALID");
        break;
    default:
        sprintf(s,"???");
    }

    return;
}

int load_pmt_info()
{
    int i, j;
    char line[256];
    char *str;
    double value;
    int n;

    FILE *f = open_file("pmt.txt", "r");

    if (!f) {
        fprintf(stderr, "failed to open pmt.txt: %s\n", strerror(errno));
        return -1;
    }

    i = 0;
    n = 0;
    /* For the first pass, we just count how many values there are. */
    while (fgets(line, sizeof(line), f)) {
        size_t len = strlen(line);
        if (len && (line[len-1] != '\n')) {
            fprintf(stderr, "got incomplete line on line %i: '%s'\n", i, line);
            goto err;
        }

        i += 1;

        if (!len) continue;
        else if (line[0] == '#') continue;

        str = strtok(line," \n");

        j = 0;
        while (str) {
            value = strtod(str, NULL);
            switch (j) {
            case 0:
            case 1:
            case 2:
                pmts[n].pos[j] = value/10.0;
                break;
            case 3:
            case 4:
            case 5:
                pmts[n].normal[j-3] = value;
                break;
            case 6:
                pmts[n].pmt_type = value;
                break;
            }
            j += 1;
            str = strtok(NULL," \n");
        }

        normalize(pmts[n].normal);

        n += 1;
    }

    fclose(f);

    initialized = 1;

    return 0;

err:
    fclose(f);

    return -1;
}