% Run Finesse bit...
urad=1e6;
infile='H1_IMC_jitter.kat';
outfile='H1_IMC_MC1jitter_mat.kat';
FT=FT_init_Finesse;
npoints=21;
tiltrange=30e-6;

MC1pitchxaxisstr=sprintf('xaxis MC1 ybeta lin %g %g %g',-tiltrange,tiltrange,npoints-1);
MC2pitchxaxisstr=sprintf('xaxis MC2 ybeta lin %g %g %g',-tiltrange,tiltrange,npoints-1);
MC1yawxaxisstr=sprintf('xaxis MC1 xbeta lin %g %g %g',-tiltrange,tiltrange,npoints-1);
MC2yawxaxisstr=sprintf('xaxis MC2 xbeta lin %g %g %g',-tiltrange,tiltrange,npoints-1);

% MC1 pitch
blocks=FT_read_blocks_from_file(infile);
blocks(6)=FT_add_line_to_block(blocks(6),MC1pitchxaxisstr);
FT_write_blocks_into_file(blocks,outfile);
run=FT_create_new_kat_run();
run.filename=outfile;
run=FT_run_kat_simulation(FT,run);
MC1Pmodeloff=run.data(:,1)*urad;
MC1Ptrans=run.data(:,2)/max(run.data(:,2));
% MC1 yaw
blocks=FT_read_blocks_from_file(infile);
blocks(6)=FT_add_line_to_block(blocks(6),MC1yawxaxisstr);
FT_write_blocks_into_file(blocks,outfile);
run=FT_create_new_kat_run();
run.filename=outfile;
run=FT_run_kat_simulation(FT,run);
MC1Ymodeloff=run.data(:,1)*urad;
MC1Ytrans=run.data(:,2)/max(run.data(:,2));
% MC2 pitch
blocks=FT_read_blocks_from_file(infile);
blocks(6)=FT_add_line_to_block(blocks(6),MC2pitchxaxisstr);
FT_write_blocks_into_file(blocks,outfile);
run=FT_create_new_kat_run();
run.filename=outfile;
run=FT_run_kat_simulation(FT,run);
MC2Pmodeloff=run.data(:,1)*urad;
MC2Ptrans=run.data(:,2)/max(run.data(:,2));
% MC2 yaw
blocks=FT_read_blocks_from_file(infile);
blocks(6)=FT_add_line_to_block(blocks(6),MC2yawxaxisstr);
FT_write_blocks_into_file(blocks,outfile);
run=FT_create_new_kat_run();
run.filename=outfile;
run=FT_run_kat_simulation(FT,run);
MC2Ymodeloff=run.data(:,1)*urad;
MC2Ytrans=run.data(:,2)/max(run.data(:,2));
% MC3 same as MC1
MC3Pmodeloff=MC1Pmodeloff;
MC3Ymodeloff=MC1Ymodeloff;
MC3Ptrans=MC1Ptrans;
MC3Ytrans=MC1Ytrans;
save('Finesse_model_results')