global actpara drtact
%This script writes an action file for SCAPS. It includes all
%parameters to run the measurement simulations. Any further parameters
%that need modification can be inserted behind the string of the row and
%replaced by %d, %d, etc. in the string


% set random default values if calculation should not be executed
if isfield(actpara, 'IV')==0
actpara.IVstart=0;          %V
actpara.IVstop=0.8;         %V
actpara.IVinc=0.02;         %V
end
if isfield(actpara, 'CV')==0
actpara.CVstart=0;          %V
actpara.CVstop=0.8;         %V
actpara.CVinc=0.02;         %V
end
if isfield(actpara, 'Cf')==0
actpara.Cfstart=1e-9;       %Hz
actpara.Cfstop=1e9;         %Hz
actpara.Cfppd=10;           %points per decade
end
if isfield(actpara, 'QE')==0
actpara.QEstart=300;        %nm
actpara.QEstop=900;         %nm
actpara.QEinc=10;           %nm
end

fip=fopen(drtact, 'w');     %open file for writing. Previous content is deleted.

%% define working point
fprintf(fip, 'Temperature :   %f K\n', actpara.T);
fprintf(fip, 'Voltage :     %f V\n',actpara.WPvolt);
fprintf(fip, 'Frequency :   %f Hz\n', actpara.WPfreq);
fprintf(fip, 'Number of points :   5\n');
%% AM 1.5G spectrum
fprintf(fip, 'dark :  %g\n', actpara.dark);
fprintf(fip, 'incident illumination specified\n');            
fprintf(fip, 'incident spectrum from file :AM1_5G 1 sun.spe\n');           
%parameters for defined spectrum
fprintf(fip, 'spectrum cut off :  0\n');
fprintf(fip, 'short wavelength cut off :   200.00 nm\n');
fprintf(fip, 'long wavelength cut off :  4000.00 nm\n');
fprintf(fip, 'neutral density :     0.0000\n');
fprintf(fip, 'transmission :   100.0000 %% \n');
fprintf(fip, 'attenuation :   100.0000 %% \n');
fprintf(fip, 'Secondworkpoint Temperature :   300.00 K\n');
fprintf(fip, 'Secondworkpoint Voltage :     0.0000 V\n');
fprintf(fip, 'Secondworkpoint Number of points :   5\n');
fprintf(fip, 'Secondworkpoint dark :  1\n');
fprintf(fip, 'Secondworkpoint incident illumination specified\n');
fprintf(fip, 'Secondworkpoint incident spectrum from file :AM1_5G 1 sun.spe\n');
fprintf(fip, 'Secondworkpoint spectrum cut off :  0\n');
fprintf(fip, 'Secondworkpoint short wavelength cut off :     0.00 nm\n');
fprintf(fip, 'Secondworkpoint long wavelength cut off :  2000.00 nm\n');
fprintf(fip, 'Secondworkpoint neutral density :     0.0000\n');
fprintf(fip, 'Secondworkpoint transmission :   100.0000 %% \n');
fprintf(fip, 'Secondworkpoint attenuation :   100.0000 %% \n');

% %% define generation model
% fprintf(fip, 'dark :  %g\n', actpara.dark);
% fprintf(fip, 'generation G(x) specified\n');            %or calculate
% fprintf(fip, 'generation G(x) from model\n');           %or from file
% fprintf(fip, 'generation model :constant generation\n');
% fprintf(fip, 'generation model, value of parameter 1 :   %f \n',actpara.Grate);
% %parameters for defined spectrum
% fprintf(fip, 'spectrum cut off :  0\n');
% fprintf(fip, 'short wavelength cut off :   200.00 nm\n');
% fprintf(fip, 'long wavelength cut off :  4000.00 nm\n');
% fprintf(fip, 'neutral density :     0.0000\n');
% fprintf(fip, 'transmission :   100.0000 %% \n');
% fprintf(fip, 'attenuation :   100.0000 %% \n');
% fprintf(fip, 'Secondworkpoint Temperature :   300.00 K\n');
% fprintf(fip, 'Secondworkpoint Voltage :     0.0000 V\n');
% fprintf(fip, 'Secondworkpoint Number of points :   5\n');
% fprintf(fip, 'Secondworkpoint dark :  1\n');
% fprintf(fip, 'Secondworkpoint incident illumination specified\n');
% fprintf(fip, 'Secondworkpoint incident spectrum from file :AM1_5G 1 sun.spe\n');
% fprintf(fip, 'Secondworkpoint spectrum cut off :  0\n');
% fprintf(fip, 'Secondworkpoint short wavelength cut off :     0.00 nm\n');
% fprintf(fip, 'Secondworkpoint long wavelength cut off :  2000.00 nm\n');
% fprintf(fip, 'Secondworkpoint neutral density :     0.0000\n');
% fprintf(fip, 'Secondworkpoint transmission :   100.0000 %% \n');
% fprintf(fip, 'Secondworkpoint attenuation :   100.0000 %% \n');

%% IV-measurements
fprintf(fip, 'pause :  0\n');
fprintf(fip, 'IV_startV :     %f V\n', actpara.IVstart);
fprintf(fip, 'IV_stopV :     %f V\n', actpara.IVstop);
fprintf(fip, 'IV_points :  %f\n', (actpara.IVstop-actpara.IVstart)/actpara.IVinc+1);
fprintf(fip, 'IV_increment :     %f V\n', actpara.IVinc);
fprintf(fip, 'IV_calculate :  %g\n',isfield(actpara, 'IV'));
fprintf(fip, 'stop after Voc :  0\n');

%% CV-measurements
fprintf(fip, 'CV_startV :    %f V\n', actpara.CVstart);
fprintf(fip, 'CV_stopV :     %f V\n', actpara.CVstop);
fprintf(fip, 'CV_points :  %f\n', (actpara.CVstop-actpara.CVstart)/actpara.CVinc+1);
fprintf(fip, 'CV_increment :     %f V\n', actpara.CVinc);
fprintf(fip, 'CV_calculate :  %g\n', isfield(actpara,'CV'));
fprintf(fip, 'MIS CV_calculate :  0\n');

%% Cf-measurements
fprintf(fip, 'Cf_startf :    %f Hz\n', actpara.Cfstart);
fprintf(fip, 'Cf_stopf :    %f Hz\n', actpara.Cfstop);
fprintf(fip, 'Cf_total points : %f\n', (log10(actpara.Cfstop)-log10(actpara.Cfstart))*actpara.Cfppd+1);
fprintf(fip, 'Cf_points per decade :  %f\n', actpara.Cfppd);
fprintf(fip, 'Cf_calculate :  %f\n', isfield(actpara, 'Cf'));

%% QE-measurements
fprintf(fip, 'QE_startlambda :   %f nm\n', actpara.QEstart);
fprintf(fip, 'QE_stoplambda :   %f nm\n', actpara.QEstop);
fprintf(fip, 'QE_points :  %f\n', (actpara.QEstop-actpara.QEstart)/actpara.QEinc+1);
fprintf(fip, 'QE_increment :    %f nm\n', actpara.QEinc);
fprintf(fip, 'QE_calculate :  %f\n', isfield(actpara, 'QE'));

fclose(fip);
clear fip