
% create synthetic GPS files
% Note: I am creating these "GPS" files to list where the EM27 was each day
% it was mobile so that I don't forget.
% Q&A - Does EGI need GPS csv files?  No, the location can be directly used
% as an input.  However, as time goes on, and we go to more and more
% different locations it gets difficult to remember exactly where the
% instrument was on which day, and it is difficult to remember to actually
% put in the correct date as an input.
% -How do I run this? Just enter in the 4 inputs below.  The file will be
% created in the directory you are working in.


% clear all;
% fclose('all'); 

% inputs
% chino: 34, -117.65, 218
% dryden: 34.960, -117.881, 696
lat = 34;
long = -117.65;
masl = 218;
dateyyyymmdd = [2015, 1, 16];


% basic calculations
lcl_start_hr = 5;
lcl_end_hr = 12+8;
time_step_min = 0.5;
srl_date = datenum(dateyyyymmdd); % UTC serial date
approx_tz = round(long/15); %approximate timezone

start_time = srl_date - approx_tz/24 + lcl_start_hr/24;
end_time = srl_date - approx_tz/24 + lcl_end_hr/24;

time_list = (start_time:(time_step_min/(60*24)):end_time)'; %list of all times

% format outputs
utc_serial = cellstr(num2str(time_list, '%12.5f'));
lat_formatted = cellstr(num2str(lat*ones(length(time_list),1), '%10.4f'));
long_formatted = cellstr(num2str(long*ones(length(time_list),1), '%9.4f'));
masl_formatted = cellstr(num2str(masl*ones(length(time_list),1), '%7.1f'));
outtext = [utc_serial, lat_formatted, long_formatted, masl_formatted];
header = {'CompSrlDate', 'Lat', 'Long', 'masl'};


% specify and write file
writeformat = [repmat('%s  ', 1, size(outtext, 2)), '\r\n'];

filenameout = [datestr(srl_date, 'yyyymmdd'), '_syntheticGPS_00.txt'];

fileID = fopen(filenameout,'w'); % write the file
fprintf(fileID, writeformat, header{:});
for row = 1:size(outtext,1); 
    fprintf(fileID, writeformat, outtext{row, :});
end
fclose('all');


