You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: Atlas_Anatomy2CAT12.m
    path of file: ./repos/cat12/development
    
    the code of the file until where you have to start completion: function Atlas_Anatomy2CAT12
% Convert Anatomy3 atlas to CAT12 atlas
%_______________________________________________________________________
%
% Christian Gaser, Robert Dahnke
% Structural Brain Mapping Group (https://neuro-jena.github.io)
% Departments of Neurology and Psychiatry
% Jena University Hospital
% ______________________________________________________________________
% $Id$

load JuBrain_Data_public_v30.mat

V = JuBrain.Vo;
V.fname ='Anatomy3_refined.nii';
V.pinfo(1) = 1;

    
function Atlas_Anatomy2CAT12
% Convert Anatomy3 atlas to CAT12 atlas
%_______________________________________________________________________
%
% Christian Gaser, Robert Dahnke
% Structural Brain Mapping Group (https://neuro-jena.github.io)
% Departments of Neurology and Psychiatry
% Jena University Hospital
% ______________________________________________________________________
% $Id$

load JuBrain_Data_public_v30.mat

V = JuBrain.Vo;
V.fname ='Anatomy3_refined.nii';
V.pinfo(1) = 1;
atlas = zeros(V.dim);
n_structures = numel(JuBrain.Namen);

% flip hemisphere coding
JuBrain.lr = 2 - JuBrain.lr;

fid = fopen('anatomy3.csv','w');
fprintf(fid,'ROIid;ROIabbr;ROIname;ROIoname\n');

% code left/right hemispheres
tmp = 2*JuBrain.mpm - JuBrain.lr;

% correct atlas regions that were zero before
tmp(JuBrain.mpm == 0) = 0;
atlas(JuBrain.idx) = tmp;

% replace remaining holes with median value
holes = atlas > 0;
holes = (cat_vol_morph(holes,'c') - holes) > 0;
tmp = cat_vol_median3c(single(atlas));
atlas(holes) = double(tmp(holes));

spm_write_vol(V,atlas);

% write csv file for CAT12
for i=1:n_structures  
  fprintf(fid,'%d;l%s;Left %s;%s\n',2*i-1,deblank(JuBrain.Files{i}),deblank(JuBrain.Namen{i}),deblank(JuBrain.Namen{i}));
  fprintf(fid,'%d;r%s;Right %s;%s\n',2*i-1,deblank(JuBrain.Files{i}),deblank(JuBrain.Namen{i}),deblank(JuBrain.Namen{i}));
end