%
% DESCRIPTION: Program to create the Strain gauge deformation GDF file in the Matlab format.
% 
% [TimeZone] and [Description] have text format so the values give in ''


clear;clc;
[FormatName] = 'GDF';
[FormatVersion] = 2.1;
[CRS] = 'n/a'%['EPSG:' num2str(input('[CRS] EPSG code (just number) = '))];
[TimeZone] = 'UTC' %input('TimeZone (char) = ');
[Description] = 'Description of the dataset' %input('Description of data (char) = ');
         
[FieldDescription] = {
    'Station_codename','Code name of the station/point of measurement of anchorded broheole extensometer'
    'Lat','Initial latitude of station/measurement point'
    'Long','Initial  longitude of station/measurement point'
    'Elevation','Elevation of each station in meters above sea level'
    'Depth','Depth of each station from surface'
    'Date','Date of measurement for each station'
    'DefZ','Measurement of deformation in vertical direction relative to initial station position (downward negative; upward positive)'
    };
[FieldType] = {
    'Station_codename',3
    'Lat',24
    'Long',14
    'Elevation',2
    'Depth',14
    'Date',5
    'DefZ',1
    };
[FieldUnit] = {
    'Station_codename','char'
    'Lat','deg'
    'Long','deg'
    'Elevation','m'
    'Depth','km'
    'Date','datenum'
    'DefZ','m'
    };
[d] = struct();

[Sc, La, Lo, El, Dh] = textread('input_data_station_info.txt','%s %f %f %f %f','delimiter',';','headerlines',1);

[Sc2, Da, Dz] = textread('input_data_Insitu_deformation.txt','%s %s %f ','delimiter',';','headerlines',1);

for k=1:length(Sc)
    d(k).Station_codename = Sc{k,1};
    d(k).Lat = La(k,1);
    d(k).Long = Lo(k,1);
    d(k).Elevation = El(k,1);
    d(k).Depth = Dh(k,1);
    d(k).Date = datenum(Da(strcmp(Sc2,Sc{k,1})));
    d(k).DefZ = Dz(strcmp(Sc2,Sc{k,1}));
    
     display([Sc{k,1} ' - done'])
end

clear k Sc La Lo El Dh Sc2 Da Dz

save('GDF_EpisodeName_Insitu_deformation_example.mat')
