public void doSspcCdf(int first, int last, int date) throws CDFException{
      float scint_temp = 0, dpu_temp = 0;

      int numOfRecs = last - first;
      float[][] 
         sspc_rebin = new float[numOfRecs][256],
         sspc_error = new float[numOfRecs][256];
      float[] 
         old_edges, 
         std_edges = SpectrumExtract.stdEdges(2, 2.4414f);
      
      float[] peak = new float[numOfRecs];
      int[] 
         frameGroup = new int[numOfRecs],
         q = new int[numOfRecs];
      long[] epoch = new long[numOfRecs];

      System.out.println("\nSaving SSPC...");

      //rebin the sspc spectra
      for(int sspc_rec = 0, hkpg_rec = 0; sspc_rec < numOfRecs; sspc_rec++){
         
         //find correct hkpg_rec
         int target_frame = 
            CDF_Gen.data.frame_mod32[sspc_rec] - 
            (CDF_Gen.data.frame_mod32[sspc_rec] % 40);

         while(
            (CDF_Gen.data.frame_mod40[hkpg_rec] <= target_frame) &&
            (hkpg_rec <= sspc_rec) &&
            (hkpg_rec < CDF_Gen.data.frame_mod40.length)
         ){
            hkpg_rec++;
         }

         //get temperatures
         if(CDF_Gen.data.hkpg[Constants.T0][hkpg_rec] != Constants.HKPG_FILL){
            scint_temp = 
               (CDF_Gen.data.hkpg[Constants.T0][hkpg_rec] * 
               CDF_Gen.data.hkpg_scale[Constants.T0]) + 
               CDF_Gen.data.hkpg_offset[Constants.T0];
         }
         if(CDF_Gen.data.hkpg[Constants.T5][hkpg_rec] != Constants.HKPG_FILL){
            dpu_temp = 
               (CDF_Gen.data.hkpg[Constants.T5][hkpg_rec] * 
               CDF_Gen.data.hkpg_scale[Constants.T5]) + 
               CDF_Gen.data.hkpg_offset[Constants.T5];
         }    

         //get the adjusted bin edges
         old_edges = 
            SpectrumExtract.makeedges(
               2, scint_temp, dpu_temp, CDF_Gen.data.peak511_bin[sspc_rec + first]
            );

         //rebin the spectrum
         sspc_rebin[sspc_rec] = SpectrumExtract.rebin(
            CDF_Gen.data.sspc[sspc_rec + first], old_edges, std_edges
         );

         float fill = CDFVar.getIstpVal("FLOAT_FILL").floatValue();
         for(int bin_i = 0; bin_i < sspc_rebin[sspc_rec].length; bin_i++){
            if(sspc_rebin[sspc_rec][bin_i] != fill){
               float width = std_edges[bin_i + 1] - std_edges[bin_i];
               //get the count error
               sspc_error[sspc_rec][bin_i] =
                  (float)Math.sqrt(sspc_rebin[sspc_rec][bin_i])
                  / (width * 32f);

               //divide counts by bin width and adjust the time scale
               sspc_rebin[sspc_rec][bin_i] /= (width * 32f);
            }
         }
      }

      for(int rec_i = 0, data_i = first; data_i < last; rec_i++, data_i++){
         peak[rec_i] = CDF_Gen.data.peak511_bin[data_i];
         frameGroup[rec_i] = CDF_Gen.data.frame_mod32[data_i];
         epoch[rec_i] = CDF_Gen.data.epoch_mod32[data_i];
         q[rec_i] = CDF_Gen.data.sspc_q[data_i];
      }

      String destName = 
         outputPath + "/" + date + "/" + "bar_" + id + 
         "_l2_" + "sspc" + "_20" + date +  "_v" + revNum + ".cdf";

      SSPC sspc = new SSPC(destName, "bar_" + id, date, 2);

      System.out.println("sspc");
      sspc.getCDF().addData("SSPC", sspc_rebin);
      System.out.println("sspc error");
      sspc.getCDF().addData("cnt_error", sspc_error);
      System.out.println("Peak_511");
      sspc.getCDF().addData("Peak_511", peak);
      System.out.println("FrameGroup");
      sspc.getCDF().addData("FrameGroup", frameGroup);
      System.out.println("Epoch");
      sspc.getCDF().addData("Epoch", epoch);
      System.out.println("Q");
      sspc.getCDF().addData("Q", q);

      sspc.close();
   }