function getMarkersAndHeader(file_handle, readHeader, readMarker)
%get and read markers and headerfields from data file
%   marker and header information will be stored in workspace

    temp = struct();

    if readMarker == 1
        % get number of markers
        numMarkers = uint64(0);
        [DMDReader_ErrorCode, file_handle, numMarkers] = calllib('dmdlib', 'DMDReader_GetNumMarkers', file_handle, numMarkers);
        if (DMDReader_ErrorCode ~= 0)
           error(['Error: ', num2str(DMDReader_ErrorCode), ' DMDReader_GetNumMarkers'])
        end
        
        % read markers
        if numMarkers > 0
            markerEvent = libstruct('DMDReader_MARKEREVENT');
            markerEvent.text = '';
            markerEventPtr = libpointer('DMDReader_MARKEREVENT', markerEvent);
            numMarkers2 = uint64(0);

            for j = 0 : numMarkers - 1
               [DMDReader_ErrorCode, file_handle, markerEvent, numMarkers2] = calllib('dmdlib', 'DMDReader_GetMarkers', file_handle, j, 1, markerEventPtr.Value, numMarkers2);
                temp.marker(j+1) = markerEvent;
               if (DMDReader_ErrorCode ~= 0)
                   error(['Error: ', num2str(DMDReader_ErrorCode), ' DMDReader_GetMarkers'])
               end
            end %for j
            assignin ('base','Markers', temp.marker);

        end
    end
    %%
    if readHeader == 1
        temp = struct();
        % get number of header fields
        numHeaderFields = uint64(0);
        [DMDReader_ErrorCode, file_handle, numHeaderFields] = calllib('dmdlib', 'DMDReader_GetNumHeaderFields', file_handle, numHeaderFields);
        if (DMDReader_ErrorCode ~= 0)
            error(['Error: ', num2str(DMDReader_ErrorCode), ' DMDReader_GetNumHeaderFields'])
        end

        % read headerfields
        if numHeaderFields > 0
            numFields = uint64(0);
            headerfield = libstruct('DMDReader_HEADERFIELD');
            headerfieldPtr = libpointer('DMDReader_HEADERFIELD', headerfield);

            for i = 0 : numHeaderFields - 1
                [DMDReader_ErrorCode, file_handle, headerfield, numFields] = calllib('dmdlib', 'DMDReader_GetHeaderFields', file_handle, i, 1, headerfieldPtr.Value, numFields);    
                %assignin ('base',['Headerfield' num2str(i+1)], headerfield);
                temp.field(i+1) = headerfield;
                if (DMDReader_ErrorCode ~= 0)
                error(['Error: ', num2str(DMDReader_ErrorCode), ' DMDReader_GetHeaderFields'])
                end
            end
            assignin ('base','Headerfields', temp.field);
        end
    end
end

