 
         do
         {
-            addIonsAB(b_mass, (float) charge, spec);
-            addIonsY (y_mass, (float) charge, spec);
+            addIonsAB(b_mass, (float) charge, spec, len_spec);
+            addIonsY (y_mass, (float) charge, spec, len_spec);
         }
         while (++charge < max_charge);
     }

    float        *b_ions,
    float        *y_ions,
    int          *spec,
    unsigned int len_ions
)
{
    unsigned int idx = threadIdx.x + blockDim.x * blockIdx.x;

 * corresponding to the neutral losses of H2O and NH3.
 */
__device__ void
addIonsAB(float mass, float charge, int *spec, unsigned int N)
{
    int   idx;
    float m;

    // A
    idx = bin(ionMZ(mass - massCO, charge));
    if (0 <= idx && idx < N) atomicMax(&spec[idx], 10);

    // B
    m   = ionMZ(mass, charge);
    idx = bin(m);

    if (1 <= idx && idx < N-1)
    {
        atomicMax(&spec[idx],   50);
        atomicMax(&spec[idx+1], 25);
        atomicMax(&spec[idx-1], 25);
    }

    idx = bin(m - massH2O/charge);
    if (0 <= idx && idx < N) atomicMax(&spec[idx], 10);

    idx = bin(m - massNH3/charge);
    if (0 <= idx && idx < N) atomicMax(&spec[idx], 10);
}


__device__ void
addIonsY(float mass, float charge, int *spec, unsigned int N)
{
    float m   = ionMZ(mass + massH2O, charge);
    int   idx = bin(m);

    if (1 <= idx && idx < N-1)
    {
        atomicMax(&spec[idx],   50);
        atomicMax(&spec[idx+1], 25);
        atomicMax(&spec[idx-1], 25);
    }

    idx = bin(m - massNH3/charge);
    if (0 <= idx && idx < N) atomicMax(&spec[idx], 10);
}


