function build_piper_batch_script(export_folder, file_pointers)
% Generates a .py file for the batch execution of a specific model.
%
% :param export_folder: string - Name of folder to place BAT file.
%                                It is assumed the python file will also
%                                exist in this folder.
% :param file_pointers: struct - Struct with file names. Needs to contain
%                                at least the fields "pmr_file",
%                               "piper_script_name", "tcp_out_name" and
%                               "scp_out_name".
%
% :return None: Nothing is return. If successful, a file is created.
%
% created by : ABR august@lightness.eu
% date : 2024-04-24

% Prepare strings
path_to_write = [export_folder file_pointers.piper_script_name];
input_pmr_file = strrep([export_folder file_pointers.pmr_file_name],'\','\\');
input_tcp_file = strrep([export_folder file_pointers.tcp_out_name],'\','\\');
input_scp_file = strrep([export_folder file_pointers.scp_out_name],'\','\\');
output_dir = strrep([export_folder file_pointers.morphed_dir_name filesep],'\','\\');

fileID = fopen(path_to_write,'w');
fprintf(fileID,'import math \n');
fprintf(fileID,'import os.path \n');
fprintf(fileID,'import piper.app \n')
fprintf(fileID,'import piper.hbm \n')
fprintf(fileID,'import piper.KrigingDeformation \n')
fprintf(fileID,'project = piper.app.Project() \n')
fprintf(fileID,'projectFile = os.path.join("%s")\n', input_pmr_file)
fprintf(fileID,'project.importModel(projectFile) \n')
fprintf(fileID,'targetFile = os.path.join("%s")\n', input_tcp_file)
fprintf(fileID,'piper.app.loadTargetCPs(project, targetFile, "trg") \n')
fprintf(fileID,'sourceFile = os.path.join("%s")\n', input_scp_file)
fprintf(fileID,'piper.app.loadSourceCPs(project, sourceFile, "src") \n')
fprintf(fileID,'cpPairs = piper.app.mapStringString({"trg": "src"}) \n')
fprintf(fileID,'project.model().metadata().interactionControlPoint("src").setGlobalAssociationSkin(1) \n');
fprintf(fileID,'project.model().metadata().interactionControlPoint("src").setGlobalAssociationBones(1) \n');
fprintf(fileID,'sourceCPs = piper.hbm.InteractionControlPoint() \n');
fprintf(fileID,'targetCPs = piper.hbm.InteractionControlPoint() \n');
fprintf(fileID,'project.collectControlPoints(sourceCPs, targetCPs, cpPairs) \n');
fprintf(fileID,'kr = piper.KrigingDeformation.IntermediateTargetsInterface(project.model()) \n');
fprintf(fileID,'project.moduleParameter().setInt("Kriging", "splitThresholdCP", 10000) \n')
fprintf(fileID,'kr.setControlPoints(sourceCPs, targetCPs) \n')
fprintf(fileID,'piper.app.applyCPScalingTarget(project, kr, False) \n')
fprintf(fileID,'resultDir = os.path.join("%s")\n', output_dir)
fprintf(fileID,'project.exportModel(resultDir) \n')
fclose(fileID);
