#ifndef _UTILS_H
#define _UTILS_H

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/time.h>
/* linear scheduler definitions */
#define MAX_SCHEDULES 16
#define MAX_SCHEDULE_TOKEN_SIZE 32
#define MAX_SCHEDULE_N 32
#define MAX_SCHEDULE_INPUT (16*MAX_SCHEDULE_N)
#define SCHEDULE_NONSENSE (-176943285.213)
#define SCHEDULE_TINY (5E-13)
struct schedule_list
{
    char token[MAX_SCHEDULE_TOKEN_SIZE]; /* schedule name */
    int n; /* number of control points */
    double *s; /* time and value of control points */
    int nontrivial;
    struct schedule_list *next;
};

double frandom();
void randnorm (int n, double x[]);
int freetowrite (char filename[]);
double watch(char token[], int command);
void waitfor (double seconds);
char *earth_time (double seconds);
void mateqv(double A[3][3], double B[3][3]);
void matran(double A[3][3], double B[3][3]);
void matadd(double A[3][3], double B[3][3], double C[3][3]);
void matsub(double A[3][3], double B[3][3], double C[3][3]);
void matmul(double A[3][3], double B[3][3], double C[3][3]);
double matinv(double A[3][3], double B[3][3]);
char *diag3 (double A[3][3], double eigval[3], double Q[3][3]);
double trace_decompose (double A[3][3], double B[3][3], double C[3][3]);
void quicksort (int n, double arr[], int idx[]);
struct schedule_list *add_schedule
(char token[], char buf[], double tmin, double tmax);
double schedule (char token[], double t);
double *calm_period (char token[], double t1, double t2);
void cancel_schedule (char token[]);
void cancel_all_schedules();
void make_space (int idx[], int list[], int i, int min, int max);
void safe_append (int idx[], int list[], int value, int i, int min, int max);
#endif