%
% 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 measurement device and provides information about strain gauge orientation e.g. G01_X is Gauge sensor 1, oriented in X direction'
    'Lat','Latitude of station/measurement point'
    'Long','Longitude of station/measurement point'
    'Elevation','Elevation of each station in meters above sea level'
    'X','X coordinate of station/measurement point'
    'Y','Y coordinate of station/measurement point'
    'Z','Z coordinate of station/measurement point'
    'Date','Time of measurement for each station'
    'StrainZ','Strain gauge measurements according Z direction gauge orientation for each station/measurement point'
    };
[FieldType] = {
    'Station_codename',3
    'Lat',24
    'Long',14
    'Elevation',1
    'X',1
    'Y',1
    'Z',1
    'Date',5
    'StrainZ',1
    };
[FieldUnit] = {
    'Station_codename','char'
    'Lat','deg'
    'Long','deg'
    'Elevation','m'
    'X','m'
    'Y','m'
    'Z','m'
    'Date','datenum'
    'StrainZ','microstrain'
    };
[d] = struct();

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

[Sc2, Da, St] = textread('input_data_Strain_gauge_measurement.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).X = Xc(k,1);
    d(k).Y = Yc(k,1);
    d(k).Z = Zc(k,1);
    d(k).Date = datenum(Da(strcmp(Sc2,Sc{k,1})));
    d(k).StrainZ = St(strcmp(Sc2,Sc{k,1}));
    
     display([Sc{k,1} ' - done'])
end

clear k Sc La Lo El Xc Yc Zc Sc2 Da St

save('GDF_EpisodeName_strain_gauge_measurement_example.mat')
