public void doMagCdf(int first, int last, int date) throws CDFException{
      int numOfRecs = last - first;
      int[] 
         frameGroup = new int[numOfRecs],
         q = new int[numOfRecs]; 
      long[] epoch = new long[numOfRecs];

      float[] 
         magx = new float[numOfRecs],
         magy = new float[numOfRecs],
         magz = new float[numOfRecs],
         magTot = new float[numOfRecs];

      System.out.println("\nSaving Magnetometer Level Two CDF...");

      //extract the nominal magnetometer value and calculate |B|
      float fill = CDFVar.getIstpVal("FLOAT_FILL").floatValue();
      for(int rec_i = 0, data_i = first; data_i < last; rec_i++, data_i++){
         if(CDF_Gen.data.magx[data_i] != fill){
            magx[rec_i] = (CDF_Gen.data.magx[data_i] - 8388608.0f) / 83886.070f;
         }else{
            magx[rec_i] = fill;
         }
         if(CDF_Gen.data.magy[data_i] != fill){
            magy[rec_i] = (CDF_Gen.data.magy[data_i] - 8388608.0f) / 83886.070f;
         }else{
            magx[rec_i] = fill;
         }
         if(CDF_Gen.data.magz[data_i] != fill){
            magz[rec_i] = (CDF_Gen.data.magz[data_i] - 8388608.0f) / 83886.070f;
         }else{
            magx[rec_i] = fill;
         }
         
         if(magx[rec_i] != fill && magy[rec_i] != fill && magz[rec_i] != fill){
            magTot[rec_i] = 
               (float)Math.sqrt(
                  (magx[rec_i] * magx[rec_i]) + 
                  (magy[rec_i] * magy[rec_i]) +
                  (magz[rec_i] * magz[rec_i]) 
               );
         }else{
            magTot[rec_i] = fill;
         }

         frameGroup[rec_i] = CDF_Gen.data.frame_4Hz[data_i];
         epoch[rec_i] = CDF_Gen.data.epoch_4Hz[data_i];
         q[rec_i] = CDF_Gen.data.magn_q[data_i];
      }

      //store the nominal mag values
      String destName = 
         outputPath + "/" + date + "/" + "bar_" + id + 
         "_l2_" + "magn" + "_20" + date +  "_v" + revNum + ".cdf";
     
      Magn magn = new Magn(destName, "bar_" + id, date, 2);
      System.out.println("MAG_X");
      magn.getCDF().addData("MAG_X", magx);
      System.out.println("MAG_Y...");
      magn.getCDF().addData("MAG_Y", magy);
      System.out.println("MAG_Z...");
      magn.getCDF().addData("MAG_Z", magz);
      System.out.println("Total...");
      magn.getCDF().addData("Total", magTot);
      System.out.println("FrameGroup...");
      magn.getCDF().addData("FrameGroup", frameGroup);
      System.out.println("Epoch...");
      magn.getCDF().addData("Epoch", epoch);
      System.out.println("Q...");
      magn.getCDF().addData("Q", q);

      magn.close();
   }