/* types for ultrathin-film approximation
generalized for multilayers */

#ifdef __cplusplus
extern "C"
{
#endif

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#ifdef mokesim		//version built into mokesim
#include "../mokesim.h"
#include "../nrutil.h"
#endif

//maximal number of ferromagn. layers
#define tf_MAXL 250
//maximal number of different frequencies
#define MAXFREQS 36            
//expect angle input in degrees not radians
#define USEDEGREES
//maximal length of a line in input-files
#define LINELENGTH 256

#ifndef mokesim		//standalone version
#include "nrutil.h"
#define VERSION "0.3.0"
#define MAXLAYERS tf_MAXL
#define MAXRAMPPTR 32
#define LINELENGTH 256
#define TOKENLENGTH 64
//machine floating point precision = float
#define EPS 3e-8
#define TINY_VAL 1e-35
#define Sign(a) ((a) >= 0.0 ? 1 : -1)  
#define mu0  (4e-7*M_PI)
#ifdef USEDEGREES
#define sin(a) degsin((a))
#define cos(a) degcos((a))
#endif

#endif 	//end standalone version (non-mokesim)

//make sure Pi is there
#ifndef M_PI
#define M_PI 3.14159265358979323846     /* pi */
#endif


int perp_fmr;			//set to 1 for perpendicular FMR
extern int ramp_start;

typedef struct l    
{
  double d;  //layer thickness
  double M;  //Ms 
  double K;  //Kc1
  double U;  //Ku
  double S;  //Ks
  double X;  //Keb	
  double D;
  double gamma;
  double j1,j2,j3;
  double theta_M;
  double theta_K; //e.a w.r.t Kc
  double theta_U; //e.a w.r.t Ku
  double theta_X; //EBD 
  double s;       //spacer thickness
  double re_L, im_L, re_P, im_P, //MOKE-response-coefficients longitudinal polar
                re_A, im_A, re_C, im_C; //MOKE-coefficients-coefficients l*t p*t

  int fmlayer_subdivisions;       
}
tf_Layer;

typedef struct g
{
  double B;
  double theta_B;
  double q;  
  double theta_q;
  double omega;
  int n_layers;
  double f1,f2,d_f;
  int output_type;
  char yehmoke_file[LINELENGTH];


#ifndef mokesim
double *ramp1 [MAXRAMPPTR];
double *ramp2 [MAXRAMPPTR];
double ramp_1_start, ramp_1_stop;
double ramp_2_start, ramp_2_stop;
int ramp_1_steps, ramp_2_steps;
char ramp_1_label[TOKENLENGTH], ramp_2_label[TOKENLENGTH];
FILE *outp;
#endif

}
tf_Global;

typedef struct h
{
double log;
double sign;
}
Huge_real;

void tf_det(double **m,int dimension,Huge_real *det);
int tf_findfreq(tf_Layer *l, tf_Global *g, double *freq);
void tf_buildmatrix(double **M, tf_Layer * l, tf_Global g);
void  showvalues(tf_Layer *l, tf_Global *g);
void cp_matrix(double **dest, double **source,int N);
void tf_updateM(double **M, tf_Layer * l, tf_Global g);
int get_mocoeff(tf_Layer *l,tf_Global *g);
#ifndef mokesim
void help();
void scanfile(char *inifile, tf_Global *g, tf_Layer *l);
void showval(tf_Global g, tf_Layer *l);
void init(tf_Global *g, tf_Layer *l);
extern double zbrent(double (*func)(double), double, double, double);
void zrhqr (double *, int, double *, double *);
double sqr (double);
extern double fmax (double f1, double f);
extern double degsin(double);
extern double degcos(double);
void printmodeprofiles(tf_Layer *l, tf_Global g, double *Freq, int i);
extern double modeenergy(tf_Layer *l, tf_Global g, double **A, double *m);
extern int svdcmp (double **a, int m, int n, double w[], double **v);
char* lineget (char *buffer, FILE * file);
#endif

#ifdef __cplusplus
}
#endif

