folderName = '/Applications/eclipse_3.7.2/workspace_gym_20141209/MyProject';
fileNames = dir([folderName '/*.h5']);

ids = {'SI-001226','SI-001592','SI-000386','SI-000211','SI-001152','SI-001122'};
labels = {'Left Arm','Left Leg','Right Leg','','Lumbar','Right Arm'};

newLabelList = {};
for iFile = 1:length(fileNames)
    
    fileName = [folderName '/' fileNames(iFile).name];
    
    monitorCaseIDList = hdf5read(fileName, '/', 'CaseIdList');
    monitorLabelList = hdf5read(fileName, '/', 'MonitorLabelList');
    
    originalIDs = {};
    for iMonitor = 1:length(monitorCaseIDList)
        monitorID = monitorCaseIDList(iMonitor).data;
        monitorLabel = monitorLabelList(iMonitor).data;
        iID = strmatch(monitorID, ids);
        if isempty(iID)
            newLabelList{iMonitor} = monitorLabel;
            display(['Monitor ID ' monitorID ' not found in file'])
        else
            newLabelList{iMonitor} = labels{iID};
        end
        originalIDs{iMonitor} = monitorID;
    end
    
    fileID = H5F.open(fileName,'H5F_ACC_RDWR','H5P_DEFAULT');
    fileIDCleanUp = onCleanup(@()H5F.close(fileID));
    % Open the dataset/group
    locID  = H5O.open(fileID, '/','H5P_DEFAULT');
    locIDCleanUp = onCleanup(@()H5O.close(locID));
    %open the attribute.
    attID = H5A.open(locID, 'MonitorLabelList', 'H5P_DEFAULT');
    H5A.close(attID);
    H5A.delete(locID, 'MonitorLabelList');
    
    details.AttachedTo = '/';
    details.AttachType = 'group';
    details.Name = 'MonitorLabelList';
    hdf5write(fileName, details, newLabelList, 'WriteMode', 'append');
    display(['Done processing file: ' fileName]);
end