FOR EACH spectrum and response file: totalexposure = totalexposure + EXPOSURE FOR EACH spectrum channel: IF ( acceptable QUALITY ) channelexp = EXPOSURE * AREASCAL backscalexp = BACKSCAL totalcounts = totalcounts + COUNTS Then: Accumulate counts, backscalexp and channelexp or staterrquad ELSE do not add counts FOR EACH response bin (rows): FOR EACH response channel (columns): IF ( corresponding spectrum channel not discarded ) newresponse = newresponse + MATRIX * EXPOSURE * AREASCAL FOR EACH spectrum channel: IF (all quality bad over all spectra files) Set quality flag to 1 Finalareascal = channelexp / totalexposure Finalbackscal = backscalexp / totalexposure Finalresponse = newresponse / Finalareascal