function [Struct_New] = Org_Avg_N_Convert_inQBlocks(Struct, TimeInterval)
% [Struct_New] = Org_Avg_N_Convert_inQBlocks(Struct, TimeInterval)
% Input measurement struct, throw away record with less than TimeInterval
% data, average qualified record terms, and convert from counts to #/m^3

OPC_ID = {'9284','9290','9281','9278','9287','9286'};
for i = 1:length(OPC_ID)
    j_len = length(Struct.(['OPC',OPC_ID{i}]));
    for j = 1:j_len
        temp_n1 = length(Struct.(['OPC',OPC_ID{i}])(j).n1);
        if temp_n1 < TimeInterval
            Struct_New.(['OPC',OPC_ID{i}])(j).t = NaN;
            for k = 1:8
                Struct_New.(['OPC',OPC_ID{i}])(j).(['n',num2str(k),'avg']) = NaN;
                Struct_New.(['OPC',OPC_ID{i}])(j).(['n',num2str(k),'std']) = NaN;
            end
            Struct_New.(['OPC',OPC_ID{i}])(j).bin_unit = NaN;
            Struct_New.(['OPC',OPC_ID{i}])(j).z = NaN;
        else
            Struct_New.(['OPC',OPC_ID{i}])(j).t = Struct.(['OPC',OPC_ID{i}])(j).t;
            for k = 1:8
                Struct_New.(['OPC',OPC_ID{i}])(j).(['n',num2str(k),'avg']) = mean(Struct.(['OPC',OPC_ID{i}])(j).(['n',num2str(k)]))*60000; 
                % average and unit convertion
                Struct_New.(['OPC',OPC_ID{i}])(j).(['n',num2str(k),'std']) = std(Struct.(['OPC',OPC_ID{i}])(j).(['n',num2str(k)]))*60000; 
                % standard deviation and unit conversion
            end
            Struct_New.(['OPC',OPC_ID{i}])(j).bin_unit = '#/m^3';
            Struct_New.(['OPC',OPC_ID{i}])(j).z = Struct.(['OPC',OPC_ID{i}])(j).z;
        end
    end
    display(['The ',num2str(i),' th (of ', num2str(length(OPC_ID)),') OPC complete']);
end
display('%--- function Org_Avg_N_Convert_inQBlocks() complete ----%');

end