function [event, metadata] = new_ingest_GLM_L1b_NetCDF(files)
%
%  [events, metadata] = new_ingest_GLM_L1b_NetCDF(files);
%
%  Reads a boatload of GLM L1b NetCDF files and processes them into a Matlab
%  structures of events, and other stuff (metadata).
%
%  Input:
%     files = Matlab "dir" structure of the files to be ingested
%
%  Output:
%     events = structure of event data
%     metadata = structure of all other data in the NetCDF files
%

%
%  See how many files to read
%
file_count = length(files)
%
%  Loop all the files
%
file_directory = files(1).folder;
[file_directory, files(1).name]
parfor file_index=1:file_count
   file_directory = files(file_index).folder;
   file_name = [file_directory, '\', files(file_index).name];
   if floor(file_index/500)*500 == file_index
      fprintf('Fraction done:%0.2f\n',file_index/file_count)
   end
   %
   %  Read file
   %
   [NetCDF_data_structure, ~, NetCDF_info] = extract_NetCDF(file_name, 'y');
   %
   %  There are only events
   %
   events(file_index) = NetCDF_data_structure;
   %
   %  Now the "other stuff"
   %
   metadatas(file_index) = NetCDF_info;
end
%
%  Now we have the data, reformat it so the structures are smaller and
%  easier to use
%
e_field_names = fields(events);
e_num_fields = length(e_field_names);
for field_index=1:e_num_fields
   temp_var = vertcat(events.(e_field_names{field_index}));
   event.(e_field_names{field_index}) = temp_var;
end
m_field_names = fields(metadatas);
m_num_fields = length(m_field_names);
for field_index=1:m_num_fields
   temp_var = vertcat(metadatas.(m_field_names{field_index}));
   metadata.(m_field_names{field_index}) = temp_var;
end
%
%  This should produce mtime values
%  The time in the L1b files SHOULD be seconds from 1 Jan 2000 12:00:00
%  this bit will convert that time into matlab mtime
%
event_time = event.event_time;
L1b_start = datenum([2000,1,1,12,0,0]);
mtime = L1b_start + event_time/86400;
event.mtime = mtime;
return;
