docs: def execute(self, nc_file_list, index_list, in_weight_table,
                  out_nc, grid_type, mp_lock):
  
          """The source code of the tool."""
          if not os.path.exists(out_nc):
              raise Exception("Outfile has not been created. "
                              "You need to run: generateOutputInflowFile "
                              "function ...")
  
          if len(nc_file_list) != len(index_list):
              raise Exception("ERROR: Number of runoff files not equal to "
                              "number of indices ...")
  
          demo_file_list = nc_file_list[0]
          if not isinstance(nc_file_list[0], list):
              demo_file_list = [demo_file_list]
  
          self.data_validation(demo_file_list[0])
          self.read_in_weight_table(in_weight_table)
  
          conversion_factor = self.get_conversion_factor(demo_file_list[0],
                                                         len(demo_file_list))
  
          # get indices of subset of data
          lon_ind_all = [int(i) for i in self.dict_list[self.header_wt[2]]]
          lat_ind_all = [int(j) for j in self.dict_list[self.header_wt[3]]]
  
          # Obtain a subset of  runoff data based on the indices in the
          # weight table
          min_lon_ind_all = min(lon_ind_all)
          max_lon_ind_all = max(lon_ind_all)
          min_lat_ind_all = min(lat_ind_all)
          max_lat_ind_all = max(lat_ind_all)
          lon_slice = slice(min_lon_ind_all, max_lon_ind_all + 1)
          lat_slice = slice(min_lat_ind_all, max_lat_ind_all + 1)
          index_new = []
  
          # combine inflow data
          for nc_file_array_index, nc_file_array in enumerate(nc_file_list):
  
              index = index_list[nc_file_array_index]
  
              if not isinstance(nc_file_array, list):
                  nc_file_array = [nc_file_array]
  
              data_subset_all = None
              for nc_file in nc_file_array:
                  # Validate the netcdf dataset
                  self.data_validation(nc_file)
  
                  # Read the netcdf dataset
                  data_in_nc = Dataset(nc_file)
  
                  # Calculate water inflows
                  runoff_dimension_size = \
                      len(data_in_nc.variables[self.runoff_vars[0]].dimensions)
                  if runoff_dimension_size == 2:
                      # obtain subset of surface and subsurface runoff
                      data_subset_runoff = \
                          data_in_nc.variables[self.runoff_vars[0]][
                              lat_slice, lon_slice]
                      for var_name in self.runoff_vars[1:]:
                          data_subset_runoff += \
                              data_in_nc.variables[var_name][
                                  lat_slice, lon_slice]
  
                      # get runoff dims
                      len_time_subset = 1
                      len_lat_subset = data_subset_runoff.shape[0]
                      len_lon_subset = data_subset_runoff.shape[1]
  
                      # reshape the runoff
                      data_subset_runoff = data_subset_runoff.reshape(
                          len_lat_subset * len_lon_subset)
  
                  elif runoff_dimension_size == 3:
                      # obtain subset of surface and subsurface runoff
                      data_subset_runoff = \
                          data_in_nc.variables[self.runoff_vars[0]][
                              :, lat_slice, lon_slice]
                      for var_name in self.runoff_vars[1:]:
                          data_subset_runoff += \
                              data_in_nc.variables[var_name][
                                  :, lat_slice, lon_slice]
  
                      # get runoff dims
                      len_time_subset = data_subset_runoff.shape[0]
                      len_lat_subset = data_subset_runoff.shape[1]
                      len_lon_subset = data_subset_runoff.shape[2]
                      # reshape the runoff
                      data_subset_runoff = \
                          data_subset_runoff.reshape(
                              len_time_subset,
                              (len_lat_subset * len_lon_subset))
  
                  data_in_nc.close()
  
                  if not index_new:
                      # compute new indices based on the data_subset_surface
                      for r in range(0, self.count):
                          ind_lat_orig = lat_ind_all[r]
                          ind_lon_orig = lon_ind_all[r]
                          index_new.append(
                              (ind_lat_orig - min_lat_ind_all) * len_lon_subset
                              + (ind_lon_orig - min_lon_ind_all))
  
                  # obtain a new subset of data
                  if runoff_dimension_size == 2:
                      data_subset_new = data_subset_runoff[index_new]
                  elif runoff_dimension_size == 3:
                      data_subset_new = data_subset_runoff[:, index_new]
  
                  # FILTER DATA
                  try:
                      # set masked values to zero
                      data_subset_new = data_subset_new.filled(fill_value=0)
                  except AttributeError:
                      pass
                  # set negative values to zero
                  data_subset_new[data_subset_new < 0] = 0
  
                  # combine data
                  if data_subset_all is None:
                      data_subset_all = data_subset_new
                  else:
                      data_subset_all = np.add(data_subset_all, data_subset_new)
  
              if runoff_dimension_size == 3 and len_time_subset > 1:
                  inflow_data = np.zeros((len_time_subset, self.size_stream_id))
              else:
                  inflow_data = np.zeros(self.size_stream_id)
  
              pointer = 0
              for stream_index in xrange(self.size_stream_id):
                  npoints = int(self.dict_list[self.header_wt[4]][pointer])
                  # Check if all npoints points correspond to the same streamID
                  if len(set(self.dict_list[self.header_wt[0]][
                             pointer: (pointer + npoints)])) != 1:
                      print("ROW INDEX {0}".format(pointer))
                      print("COMID {0}".format(
                          self.dict_list[self.header_wt[0]][pointer]))
                      raise Exception(self.error_messages[2])
  
                  area_sqm_npoints = \
                      np.array([float(k) for k in
                                self.dict_list[self.header_wt[1]][
                                pointer: (pointer + npoints)]])
  
                  # assume data is incremental
                  if runoff_dimension_size == 3:
                      data_goal = data_subset_all[:, pointer:(pointer + npoints)]
                  else:
                      data_goal = data_subset_all[pointer:(pointer + npoints)]
  
                  if grid_type == 't255':
                      # A) ERA Interim Low Res (T255) - data is cumulative
                      # from time 3/6/9/12
                      # (time zero not included, so assumed to be zero)
                      ro_first_half = \
                          np.concatenate([data_goal[0:1, ],
                                          np.subtract(data_goal[1:4, ],
                                                      data_goal[0:3, ])])
                      # from time 15/18/21/24
                      # (time restarts at time 12, assumed to be zero)
                      ro_second_half = \
                          np.concatenate([data_goal[4:5, ],
                                          np.subtract(data_goal[5:, ],
                                                      data_goal[4:7, ])])
                      ro_stream = \
                          np.multiply(
                              np.concatenate([ro_first_half, ro_second_half]),
                              area_sqm_npoints)
  
                  else:
                      ro_stream = data_goal * area_sqm_npoints * \
                                  conversion_factor
  
                  # filter nan
                  ro_stream[np.isnan(ro_stream)] = 0
  
                  if ro_stream.any():
                      if runoff_dimension_size == 3 and len_time_subset > 1:
                          inflow_data[:, stream_index] = ro_stream.sum(axis=1)
                      else:
                          inflow_data[stream_index] = ro_stream.sum()
  
                  pointer += npoints
  
              # only one process is allowed to write at a time to netcdf file
              mp_lock.acquire()
              data_out_nc = Dataset(out_nc, "a", format="NETCDF3_CLASSIC")
              if runoff_dimension_size == 3 and len_time_subset > 1:
                  data_out_nc.variables['m3_riv'][
                      index*len_time_subset:(index+1)*len_time_subset, :] = \
                      inflow_data
              else:
                  data_out_nc.variables['m3_riv'][index] = inflow_data
              data_out_nc.close()
              mp_lock.release()