function meta=prepare_climb_runtime(projectRoot) % Preserve R23-HE2.0.0; apply only the five-argument Vz default fix privately. sourcePackage=fullfile(projectRoot,'reports','04_models','R23-001','matlab','+r23'); runtimeRoot=fullfile(projectRoot,'reports','05_simulation','R23-001','mission-climb-runtime','.local','R23-HE2p1'); runtimePackage=fullfile(runtimeRoot,'+r23'); assert(isfolder(sourcePackage),'Original frozen r23 package missing'); if ~isfolder(runtimePackage),mkdir(runtimePackage);end files=dir(fullfile(sourcePackage,'*.m')); assert(~isempty(files),'Original package is empty'); sources=struct('path',{},'sha256',{}); for k=1:numel(files) from=fullfile(sourcePackage,files(k).name); target=fullfile(runtimePackage,files(k).name); sources(end+1)=struct('path',from,'sha256',file_hash(from)); %#ok [ok,msg]=copyfile(from,target,'f');assert(ok,'%s',msg); end originalPower=fullfile(sourcePackage,'power.m'); patchedPower=fullfile(runtimePackage,'power.m'); text=fileread(originalPower); before='if nargin<6,Vz=0;end';after='if nargin<5,Vz=0;end'; assert(isscalar(strfind(text,before)),'Unexpected original default-argument implementation'); patched=strrep(text,before,after); fid=fopen(patchedPower,'w');assert(fid>=0,'Cannot write private patched function'); guard=onCleanup(@()fclose(fid)); fwrite(fid,unicode2native(patched,'UTF-8'),'uint8');clear guard; assert(strcmp(strrep(fileread(patchedPower),after,before),text),'Patch changed more than Vz default guard'); for k=1:numel(sources) assert(strcmp(file_hash(sources(k).path),sources(k).sha256),'Frozen source changed during runtime preparation'); end clear('r23.power','r23.propulsion_power','r23.simulate_mission','r23.maximize_work'); addpath(runtimeRoot,'-begin');rehash; resolved=which('r23.power'); assert(strcmpi(resolved,patchedPower),'Corrected power function does not have path precedence'); meta=struct('model_version','R23-HE2.1.0','original_model_version','R23-HE2.0.0', ... 'reason','Five-argument power function must retain the fifth climb-speed argument', ... 'runtime_root',runtimeRoot,'runtime_package',runtimePackage,'resolved_power_function',resolved, ... 'original_power_path',originalPower,'original_power_sha256',file_hash(originalPower), ... 'patched_power_sha256',file_hash(patchedPower),'patch_before',before,'patch_after',after, ... 'helper_path',[mfilename('fullpath') '.m'],'helper_sha256',file_hash([mfilename('fullpath') '.m']), ... 'original_package_sources',sources,'original_sources_unchanged',true, ... 'scope','New equal-storage/range and corrected reference mission only; previous fits/upper bounds/results not rerun'); end function value=file_hash(path) fid=fopen(path,'rb');assert(fid>=0,'Cannot read source for SHA256'); guard=onCleanup(@()fclose(fid));bytes=fread(fid,Inf,'*uint8');clear guard; md=java.security.MessageDigest.getInstance('SHA-256');md.update(bytes); digest=typecast(md.digest(),'uint8');value=lower(reshape(dec2hex(digest,2).',1,[])); end