APMP Round-robin GPS Campaign 2004
Round 1: NMI Sydney

Obtaining an estimate for the internal delay of the inline antenna amplifier, using data recorded at Lindfield.

Off[General::spell1];
Off[General::spell1];
Needs["Graphics`Graphics`"];
Needs["Statistics`LinearRegression`"];
Needs["Statistics`NonlinearFit`"];

SetOptions[ListPlot, Frame -> True, Axes -> False, 
        TextStyle -> $TextStyle];
title[str_] := 
        Sequence[
          FrameLabel -> {"", "", str, ""}];

Definitions

Read data file (single or dual frequency)

HexString[num_, minlen_] := 
        StringJoin[Join[CharacterRange["0", "9"], 
              CharacterRange["A", "F"]][[(# + 
                    1) & /@ 
              IntegerDigits[num, 16, 
                minlen]]]];

\(\(StoreExtra[str_] := 
        Module[{instr, tag, value, pos}, 
instr = 
            StringToStream[str]; 
tag = 
            Read[instr, Word]; 
pos = 
            Position[{"X", "Y", "Z", "INT", "REF", "CAB"}, tag]; 
If[MatchQ[pos, {}], 
            Return[]]; 
If[
            pos[[1, 1]] > 
              3, 
value = 
              Read[instr, 
                Word]; 
If[\(! StringMatchQ[
                  value, "DLY"]\), Return[]]; 
tag = 
              StringJoin[tag, " ", value]]; 
Read[
            instr, Word]; 
value = 
            Read[instr, Number]; 
Close[
            instr]; 
pos = 
            Position[store, tag]; 
If[MatchQ[pos, {}], 
            AppendTo[store, {tag, {}}]; \ pos = Length[store], 
            pos = pos[[1, 
                1]]]; 
store[[pos, \(-1\)]] = 
            Union[store[[
                pos, \(-1\)]], {value}];
];\)\)

\(\(ReadCCTF[name_, opts___] := 
        Module[{filename, infile, str, checksum, count = 0, fail = 0, 
            flag = False, data = {}, format}, 
format = 
            Table[Number, {i, 
                If[\(DualFrequency /. {opts}\) /. Options[ReadCCTF], 21, 
                  18]}]; 
filename = 
            If[NumberQ[name], StringJoin[ToString[name], ".cctf"], 
              name]; 
If[\(UseDataPath /. {opts}\) /. 
              Options[ReadCCTF], 
            filename = 
              StringJoin[dataPath, filename]]; 
infile = 
            OpenRead[filename]; 
          format[[2]] = \(format[[\(-1\)]] = 
              Word\); 
While[
            True, 
If[\((str = 
                    Read[infile, String])\) == EndOfFile, 
              Break[]]; 
\(count++\); 
If[
              StringPosition[str, " = "] ≠ {}, 
              StoreExtra[str]]; 
If[
              StringPosition[str, "hhmmss"] ≠ {}, 
              flag = True; \ 
              Continue[]]; 
If[\((\(Header /. {opts}\) /. 
                    Options[ReadCCTF])\)\  && \ \(! flag\), 
              Continue[]]; 
instr = 
              StringToStream[str]; 
AppendTo[data, 
              Flatten[ReadList[instr, format]]]; 
Close[
              instr]; 
checksum = 
              HexString[Mod[Plus @@ Drop[ToCharacterCode[str], \(-2\)], 256], 
                2]; 
If[
              data[[\(-1\), \(-1\)]] == EndOfFile, 
data = 
                Drop[data, \(-1\)]; 
If[\(ShowErrors /. {opts}\) /. Options[ReadCCTF], 
                Print["! Bad format for ", filename, " at line ", 
                  count]]; 
Continue[];
]; 
If[\(! StringMatchQ[data[[\(-1\), \(-1\)]], 
                  checksum]\), 
 (*\ \(Print["! ", 
                    data[[\(-1\), \(-1\)]], " does not match ", checksum, " at line ", 
                    count];\)\ *) 
data = 
                Drop[data, \(-1\)]; 
\(fail++\);
];
]; 
Close[
            infile]; 
If[\(Verbose /. {opts}\) /. 
              Options[ReadCCTF], 
Print["> Read ", 
              Length[data], " tracks from ", 
              filename]]; 
If[\((fail > 
                  0)\)\  && \ \((\(ShowErrors /. {opts}\) /. 
                  Options[ReadCCTF])\), 
            Print["! ", 
              fail, " tracks did not match checksum"]]; 
Return[
            data];
];\)\)
Options[ReadCCTF] := {Header -> True, Verbose -> True, 
          ShowErrors -> True, UseDataPath -> True, 
          DualFrequency -> False};

Select data columns

SV[list_] := 
        list[[1]];
TrackMJD[list_] := 
        list[[3]];
TrackTime[list_] := 
        list[[4]];
TrackLength[list_] := 
        list[[5]];
Elevation[list_] := 
        list[[6]];
Azimuth[list_] := 
        list[[7]];
RefSV[list_] := 
        list[[8]]/
          10;
SlopeSV[list_] := 
        list[[9]];
RefGPS[list_] := 
        list[[10]]/
          10;
SlopeGPS[list_] := 
        list[[11]];
DSG[list_] := 
        list[[12]];
ModIono[list_] := 
        list[[16]]/
          10;
MeasIono[list_] := 
        list[[18]]/
          10;
SMSIO[list_] := 
        list[[19]];
ISG[list_] := 
        list[[20]];

    
TrackLength2[list_] := 
        list[[5 + 
            21]];
RefSV2[list_] := 
        list[[8 + 21]]/
          10;
RefGPS2[list_] := 
        list[[10 + 21]]/
          10;
ModIono2[list_] := 
        list[[16 + 21]]/
          10;

Sort data (into time order then SV order)

OrderCCTF[a_, b_] := 
        If[a[[3]] == 
            b[[3]], 
          If[a[[4]] == 
              b[[4]], 
            First[a] < First[b], 
            a[[4]] < 
              b[[4]]], 
          a[[3]] < 
            b[[3]]];

SortCCTF[data_] := Sort[data, OrderCCTF[#1, #2] &];

Merge two CCTF data sets on matching tracks

\(\(MergeCCTF[data1_, data2_, opts___] := 
        Module[{d1, d2, i, j, data = {}}, 
d1 = 
            SortCCTF[data1]; 
d2 = 
            SortCCTF[data2]; 
j = 1; 
For[
            i = 1, i ≤ 
              Length[d1], \(i++\), 
While[\((j <= 
                    Length[d2])\)\  && \ 
\((\((d2[[j, 3]] < 
                        d1[[i, 
                          3]])\)\  || \ 
\((\((d2[[j, 
                              3]] == 
                            d1[[i, 
                              3]])\)\  && \ 
\((\((d2[[j, 4]] < 
                                d1[[i, 
                                  4]])\)\  || \ 
\((\((d2[[j, 
                                      4]] == 
                                    d1[[i, 
                                      4]])\)\  && \ 
\((d2[[j, 1]] < 
                                    d1[[i, 
                                      1]])\))\))\))\))\), 
\(j++\)]; 
If[\((j ≤ 
                    Length[d2])\)\  && 
\((d2[[j, 3]] == 
                    d1[[i, 
                      3]])\) && \((d2[[
                      j, 4]] == 
                    d1[[i, 
                      4]])\)\  && \ \((d2[[j, 1]] == 
                    d1[[i, 
                      1]])\), 
AppendTo[
                data, Flatten[{d1[[i]], 
                    d2[[
                      j]]}]]];
]; 
If[\(Verbose /. {opts}\) /. 
              Options[MergeCCTF], 
Print["> First ", 
              Length[d1], " tracks, second ", 
              Length[d2], " tracks, matching ", 
              Length[data], " tracks"]]; 
Return[
            data];
];\)\)
Options[MergeCCTF] := {Verbose -> True};

Miscellaneous

MJD[day_, month_, year_] := 
        Module[{f, jday}, 
f = 
            Floor[(14 - month)/12]; 
jday = 
            Floor[30.61 (month + 1 + 12 f) + day + 
                Floor[365.25 (year - f)]]; 
jday = 
            jday - Floor[(Floor[(year - f)/100] + 1) 0.75] + 
              1720997 - 2400001; 
Return[
            jday]
];

MJDToDate[mjd_] := 
        Module[{julian, y2, day, month, year}, 
julian = 
            mjd + 2400001; 
y2 = 
            julian - 1721119.1 + 
              Floor[0.75 Floor[(julian - 1684594.75)/
                      36524.25]]; 
day = 
            Floor[y2 - Floor[365.25 Floor[y2/365.25]] + 
                122.2]; 
year = 
            Floor[y2/365.25] + Floor[day/429]; 
month = 
            Floor[day/30.61] - 1 - 
              Floor[day/429]*12; 
day = 
            day - Floor[
                30.61*Floor[day/30.61]]; 
Return[{year, 
              month, day}];
];

TimeValue[list_] := 
        Module[{val, h, m, s}, 
val = 
            TrackTime[list]; 
h = 
            Quotient[val, 10000]; 
m = 
            Quotient[Mod[val, 10000], 100]; 
s = 
            Mod[val, 100]; 
Return[
            3600 h  +  60 m  +  s];
];

DateValue[list_] := 
        TrackMJD[list] + TimeValue[list]/86400;

Filter[list_, fn_] := 
        Module[{result}, 
result = 
            Select[list, fn]; 
Print["> ", 
            Length[result], " of ", 
            Length[list], " tracks selected."]; 
Return[
            result];
];

Tweak[graph_] := 
        Module[{fix = graph, pos, grid, }, 
pos = 
            Position[fix, 
              GridLines]; 
pos[[1, -1]]++; 
grid = 
            AbsoluteOptions[fix, 
              GridLines]; 
fix[[
              Sequence @@ 
                pos[[1]]]] = 
            Replace[grid[[1, -1]], {RGBColor[__] -> RGBColor[0.705882,  1,  1], 
                AbsoluteThickness[__] -> AbsoluteThickness[0.5]}, 
              Infinity];  
Return[
            fix];
];

NMI (1)

dataPath = "G:\\time\\share\\GPS Cal\\APMP GPS \
Cal\\ReprocessingSep04\\NMI 1\\";
{mjd1, mjd2} = {52969, 53040};
{t1, t2} = {52977, 53012};

Load

store = {};
dataHost = {};
For[mjd = mjd1, mjd ≤ mjd2, mjd++, 
        dataHost = 
          Join[dataHost, 
            ReadCCTF[
              StringJoin["cctf_host\\", ToString[mjd], ".cctf"], 
              DualFrequency -> True, 
              Verbose -> True]]];
store1 = store

TableForm[{#[[1]], 
            PaddedForm[#[[2, 1]], {10, 
                3}, ExponentFunction -> (Null  &)]} & /@ 
        Take[store1, 3]]

store = {};
dataTrav = {};
For[mjd = mjd1, mjd ≤ mjd2, mjd++, 
        dataTrav = 
          Join[dataTrav, 
            ReadCCTF[
              StringJoin["cctf_data\\", ToString[mjd], ".cctf"], 
              DualFrequency -> True, 
              Verbose -> True]]];
store2 = store

TableForm[{#[[1]], 
            PaddedForm[#[[2, 1]], {10, 
                3}, ExponentFunction -> (Null  &)]} & /@ 
        Take[store2, 3]]

Sqrt[
      Plus @@ (#[[2, 1]]^2 & /@ 
            Take[store1 - store2, 3])]

dataHost = 
        Filter[dataHost, (TrackLength[#] == 780) && (DSG[#] < 
                  999) && (MeasIono[#] < 999) && (Abs[SMSIO[#]] < 
                  999) && (ISG[#] < 999) &];

dataTrav = 
        Filter[dataTrav, (TrackLength[#] == 780) && (DSG[#] < 
                  999) && (MeasIono[#] < 999) && (Abs[SMSIO[#]] < 
                  999) && (ISG[#] < 999) &];

Show[
        GraphicsArray[{{
ListPlot[{DateValue[#], 
                      RefGPS[#]} & /@ dataHost, 
                title["Host - Modelled"], 
                DisplayFunction -> 
                  Identity], 
ListPlot[{DateValue[#], 
                      RefGPS[#] + ModIono[#] - MeasIono[#]} & /@ dataHost, 
                title["Host - Measured"], 
                DisplayFunction -> 
                  Identity]}, 
{ListPlot[{DateValue[#], 
                      RefGPS[#]} & /@ dataTrav, 
                title["APMP - Modelled"], 
                DisplayFunction -> 
                  Identity], 
ListPlot[{DateValue[#], 
                      RefGPS[#] + ModIono[#] - MeasIono[#]} & /@ dataTrav, 
                title["APMP - Measured"], 
                DisplayFunction -> 
                  Identity]}
}]];

dMerge = MergeCCTF[dataHost, dataTrav];
diffdataGPS = {DateValue[#1], 
              RefSV[#1] + ModIono[#1] - RefSV2[#1] - ModIono2[#1]} & /@ 
          dMerge;

Process

dsg = DSG /@ dMerge;
{dmin, dmax} = {Min[dsg], Max[dsg]};
\(\(Show[
        Graphics[\(Sequence @@ {Hue[#[[3]]/dmax], Point[Take[#, 2]]} &\) /@ 
            Transpose[
              Append[Transpose[diffdataGPS], dsg]]], 
title[
          StringJoin["DSG: ", ToString[dmin], "..", ToString[dmax]]], 
        Frame -> True];\)\)

tdata = 
        Select[diffdataGPS, #[[1]] < 
              53030 &];
DisplayTogether[
ListPlot[
          tdata], 
Plot[
          m x + c + 
              If[x1 ≤ x ≤ x2, δ, 
                0] /. {m -> 0, c -> 0.5, x1 -> t1, 
              x2 -> t2, δ -> 1}, {x, 
            tdata[[1, 1]], 
            tdata[[-1, 1]]}, 
          PlotStyle -> Hue[0]], 
PlotRange -> 
          All, GridLines -> Automatic
];

udata = 
        Select[tdata, 
          t1 ≤ #[[1]] ≤ t2 &];
vdata = 
        Select[tdata, ! (t1 ≤ #[[1]] ≤ t2) &];
{u = Mean[Last /@ udata], v = Mean[Last /@ vdata], u - v} // 
      N

fit = {};

AppendTo[fit, 
        NonlinearRegress[tdata, 
          m x + c + 
              If[x1 ≤ x ≤ x2, δ, 
                0] /. {m -> 0, x1 -> t1, x2 -> t2}, 
          x, {{c, 221}, {δ, 1}}, 
          RegressionReport -> {BestFit, BestFitParameters, 
              ParameterCITable, ANOVATable}]];
ParameterCITable /. Last[fit]

AppendTo[fit, 
        NonlinearRegress[tdata, 
          m x + c + 
              If[x1 ≤ x ≤ x2, δ, 
                0] /. {x1 -> t1, x2 -> t2}, 
          x, {{m, 0}, {c, 221}, {δ, 1}}, 
          RegressionReport -> {BestFit, BestFitParameters, 
              ParameterCITable, ANOVATable}]];
ParameterCITable /. Last[fit]

\(\(AppendTo[fit, 
        NonlinearRegress[tdata, 
          m\ x + c + 
              If[x1 ≤ x ≤ x2, δ, 
                0] /. {x1 -> t1, x2 -> t2}, 
          x, {{m, 0}, {c, 221}, {δ, 1}}, 
          Weights -> \ \((\(#\^\(-2\) &\) /@ 
                Take[dsg, Length[tdata]])\), 
          RegressionReport -> {BestFit, BestFitParameters, 
              ParameterCITable, ANOVATable}]];\)\)
ParameterCITable /. Last[fit]

DisplayTogether[
ListPlot[tdata, 
          PlotStyle -> AbsolutePointSize[2]], 
Plot[
          BestFit /. fit[[1]], {x, mjd1, 
            tdata[[-1, 1]]}, 
          PlotStyle -> {AbsoluteThickness[3], 
              Hue[0.3]}], 
Plot[
          BestFit /. fit[[2]], {x, mjd1, 
            tdata[[-1, 1]]}, 
          PlotStyle -> {AbsoluteThickness[3], 
              Hue[0]}], 
Plot[
          BestFit /. fit[[3]], {x, mjd1, 
            tdata[[-1, 1]]}, 
          PlotStyle -> {AbsoluteThickness[3], 
              Hue[0.6]}], 
PlotRange -> All, 
        GridLines -> Automatic
];

wdata = 
        Join[vdata, {#[[1]], #[[2]] - δ /. (BestFitParameters /. fit[[2]])} & /@ 
            udata];
{wmin, wmax} = {Min[Last /@ wdata], 
          Max[Last /@ wdata]};
DisplayTogether[
ListPlot[
          wdata], 
ListPlot[{{t1, wmin}, {t1, wmax}}, 
          PlotJoined -> True, 
          PlotStyle -> 
            Hue[0]], 
ListPlot[{{t2, wmin}, {t2, wmax}}, 
          PlotJoined -> True, 
          PlotStyle -> Hue[0]], 
PlotRange -> 
          All
];

NMI (2)

dataPath = "G:\\time\\share\\GPS Cal\\APMP GPS \
Cal\\ReprocessingSep04\\NMI 2\\";
{mjd1, mjd2} = {53082, 53101};
{t1, t2} = {53093 + 4/24, 53096 + 1/24 + 20/1440};

Load

store = {};
dataHost = {};
For[mjd = mjd1, mjd ≤ mjd2, mjd++, 
        dataHost = 
          Join[dataHost, 
            ReadCCTF[
              StringJoin["cctf_host\\", ToString[mjd], ".cctf"], 
              DualFrequency -> True, 
              Verbose -> True]]];
store1 = store

TableForm[{#[[1]], 
            PaddedForm[#[[2, 1]], {10, 
                3}, ExponentFunction -> (Null  &)]} & /@ 
        Take[store1, 3]]

store = {};
dataTrav = {};
For[mjd = mjd1, mjd ≤ mjd2, mjd++, 
        dataTrav = 
          Join[dataTrav, 
            ReadCCTF[
              StringJoin["cctf_data\\", ToString[mjd], ".cctf"], 
              DualFrequency -> True, 
              Verbose -> True]]];
store2 = store

TableForm[{#[[1]], 
            PaddedForm[#[[2, 1]], {10, 
                3}, ExponentFunction -> (Null  &)]} & /@ 
        Take[store2, 3]]

Sqrt[
      Plus @@ (#[[2, 1]]^2 & /@ 
            Take[store1 - store2, 3])]

dataHost = 
        Filter[dataHost, (TrackLength[#] == 780) && (DSG[#] < 
                  999) && (MeasIono[#] < 999) && (Abs[SMSIO[#]] < 
                  999) && (ISG[#] < 999) &];

dataTrav = 
        Filter[dataTrav, (TrackLength[#] == 780) && (DSG[#] < 
                  999) && (MeasIono[#] < 999) && (Abs[SMSIO[#]] < 
                  999) && (ISG[#] < 999) &];

Show[
        GraphicsArray[{{
ListPlot[{DateValue[#], 
                      RefGPS[#]} & /@ dataHost, 
                title["Host - Modelled"], 
                DisplayFunction -> 
                  Identity], 
ListPlot[{DateValue[#], 
                      RefGPS[#] + ModIono[#] - MeasIono[#]} & /@ dataHost, 
                title["Host - Measured"], 
                DisplayFunction -> 
                  Identity]}, 
{ListPlot[{DateValue[#], 
                      RefGPS[#]} & /@ dataTrav, 
                title["APMP - Modelled"], 
                DisplayFunction -> 
                  Identity], 
ListPlot[{DateValue[#], 
                      RefGPS[#] + ModIono[#] - MeasIono[#]} & /@ dataTrav, 
                title["APMP - Measured"], 
                DisplayFunction -> 
                  Identity]}
}]];

dMerge = MergeCCTF[dataHost, dataTrav];
diffdataGPS = {DateValue[#1], 
              RefSV[#1] + ModIono[#1] - RefSV2[#1] - ModIono2[#1]} & /@ 
          dMerge;

Process

dsg = DSG /@ dMerge;
{dmin, dmax} = {Min[dsg], Max[dsg]};
\(\(Show[
        Graphics[\(Sequence @@ {Hue[#[[3]]/dmax], Point[Take[#, 2]]} &\) /@ 
            Transpose[
              Append[Transpose[diffdataGPS], dsg]]], 
title[
          StringJoin["DSG: ", ToString[dmin], "..", ToString[dmax]]], 
        Frame -> True];\)\)

tdata = diffdataGPS;
DisplayTogether[
ListPlot[
          tdata], 
Plot[
          m x + c + 
              If[x1 ≤ x ≤ x2, δ, 
                0] /. {m -> 0, c -> 1, x1 -> t1, 
              x2 -> t2, δ -> 2}, {x, 
            tdata[[1, 1]], 
            tdata[[-1, 1]]}, 
          PlotStyle -> Hue[0]], 
PlotRange -> 
          All, GridLines -> Automatic
];

udata = 
        Select[tdata, 
          t1 ≤ #[[1]] ≤ t2 &];
vdata = 
        Select[tdata, ! (t1 ≤ #[[1]] ≤ t2) &];
{u = Mean[Last /@ udata], v = Mean[Last /@ vdata], u - v} // 
      N

fit = {};

AppendTo[fit, 
        NonlinearRegress[tdata, 
          m x + c + 
              If[x1 ≤ x ≤ x2, δ, 
                0] /. {m -> 0, x1 -> t1, x2 -> t2}, 
          x, {{c, 1}, {δ, 2}}, 
          RegressionReport -> {BestFit, BestFitParameters, 
              ParameterCITable, ANOVATable}]];
ParameterCITable /. Last[fit]

AppendTo[fit, 
        NonlinearRegress[tdata, 
          m x + c + 
              If[x1 ≤ x ≤ x2, δ, 
                0] /. {x1 -> t1, x2 -> t2}, 
          x, {{m, 0}, {c, 1}, {δ, 2}}, 
          RegressionReport -> {BestFit, BestFitParameters, 
              ParameterCITable, ANOVATable}]];
ParameterCITable /. Last[fit]

\(\(AppendTo[fit, 
        NonlinearRegress[tdata, 
          m\ x + c + 
              If[x1 ≤ x ≤ x2, δ, 
                0] /. {x1 -> t1, x2 -> t2}, 
          x, {{m, 0}, {c, 1}, {δ, 2}}, 
          Weights -> \ \((\(#\^\(-2\) &\) /@ 
                Take[dsg, Length[tdata]])\), 
          RegressionReport -> {BestFit, BestFitParameters, 
              ParameterCITable, ANOVATable}]];\)\)
ParameterCITable /. Last[fit]

DisplayTogether[
ListPlot[tdata, 
          PlotStyle -> AbsolutePointSize[2]], 
Plot[
          BestFit /. fit[[1]], {x, mjd1, 
            tdata[[-1, 1]]}, 
          PlotStyle -> {AbsoluteThickness[3], 
              Hue[0.3]}], 
Plot[
          BestFit /. fit[[2]], {x, mjd1, 
            tdata[[-1, 1]]}, 
          PlotStyle -> {AbsoluteThickness[3], 
              Hue[0]}], 
Plot[
          BestFit /. fit[[3]], {x, mjd1, 
            tdata[[-1, 1]]}, 
          PlotStyle -> {AbsoluteThickness[3], 
              Hue[0.6]}], 
PlotRange -> All, 
        GridLines -> Automatic
];

wdata = 
        Join[vdata, {#[[1]], #[[2]] - δ /. (BestFitParameters /. fit[[2]])} & /@ 
            udata];
{wmin, wmax} = {Min[Last /@ wdata], 
          Max[Last /@ wdata]};
DisplayTogether[
ListPlot[
          wdata], 
ListPlot[{{t1, wmin}, {t1, wmax}}, 
          PlotJoined -> True, 
          PlotStyle -> 
            Hue[0]], 
ListPlot[{{t2, wmin}, {t2, wmax}}, 
          PlotJoined -> True, 
          PlotStyle -> Hue[0]], 
PlotRange -> 
          All
];

Plot for report

{wmin, wmax} = {Min[Last /@ tdata], 
          Max[Last /@ tdata]};
plot = 
        Show[GraphicsArray[{
Tweak[
                DisplayTogether[
ListPlot[tdata, 
                    PlotStyle -> 
                      AbsolutePointSize[
                        1]], 
ListPlot[{{t1, wmin}, {t1, 
                        wmax}}, PlotJoined -> True, 
                    PlotStyle -> {AbsoluteThickness[1], 
                        Hue[0]}], 
ListPlot[{{t2, 
                        wmin}, {t2, wmax}}, PlotJoined -> True, 
                    PlotStyle -> {AbsoluteThickness[1], 
                        Hue[0]}], 
PlotRange -> All, 
                  GridLines -> Automatic, 
                  TextStyle -> {FontFamily -> "Helvetica", 
                      FontSize -> 6}, 
                  FrameStyle -> AbsoluteThickness[0.5], 
                  FrameLabel -> {"MJD", "NMI - APMP (ns)"}, 
                  DisplayFunction -> 
                    Identity]], 
Tweak[
                DisplayTogether[
ListPlot[tdata, 
                    PlotStyle -> 
                      AbsolutePointSize[1]], 
Plot[
                    BestFit /. 
                      fit[[2]], {x, 
                      mjd1, tdata[[-1, 
                        1]]}, 
                    PlotStyle -> {AbsoluteThickness[2], 
                        GrayLevel[
                          0.8]}], 
PlotRange -> All, 
                  GridLines -> Automatic, 
                  TextStyle -> {FontFamily -> "Helvetica", 
                      FontSize -> 6}, 
                  FrameStyle -> AbsoluteThickness[0.5], 
                  FrameLabel -> {"MJD", "NMI - APMP (ns)"}, 
                  DisplayFunction -> Identity]]
}], 
          DisplayFunction -> $DisplayFunction];

desktop = "c:\\\\documents and settings\\rw1899\\desktop\\";
inch = 72;
cm = inch/2.54;
Export[StringJoin[desktop, "ampdelay.gif"], plot, 
        ImageSize -> 15 cm, ImageResolution -> 300];

NMI (6)

dataPath = "G:\\time\\share\\GPS Cal\\APMP GPS \
Cal\\ReprocessingSep04\\NMI 6\\";
{mjd1, mjd2} = {53275, 53291};
{t1, t2} = {53285 + 1/24 + 25/1440, 53289 + 2/24};

Load

store = {};
dataHost = {};
For[mjd = mjd1, mjd ≤ mjd2, mjd++, 
        dataHost = 
          Join[dataHost, 
            ReadCCTF[
              StringJoin["cctf_host\\", ToString[mjd], ".cctf"], 
              DualFrequency -> True, 
              Verbose -> True]]];
store1 = store

TableForm[{#[[1]], 
            PaddedForm[#[[2, 1]], {10, 
                3}, ExponentFunction -> (Null  &)]} & /@ 
        Take[store1, 3]]

store = {};
dataTrav = {};
For[mjd = mjd1, mjd ≤ mjd2, mjd++, 
        dataTrav = 
          Join[dataTrav, 
            ReadCCTF[
              StringJoin["cctf_data\\", ToString[mjd], ".cctf"], 
              DualFrequency -> True, 
              Verbose -> True]]];
store2 = store

TableForm[{#[[1]], 
            PaddedForm[#[[2, 1]], {10, 
                3}, ExponentFunction -> (Null  &)]} & /@ 
        Take[store2, 3]]

Sqrt[
      Plus @@ (#[[2, 1]]^2 & /@ 
            Take[store1 - store2, 3])]

dataHost = 
        Filter[dataHost, (TrackLength[#] == 780) && (DSG[#] < 
                  999) && (MeasIono[#] < 999) && (Abs[SMSIO[#]] < 
                  999) && (ISG[#] < 999) &];

dataTrav = 
        Filter[dataTrav, (TrackLength[#] == 780) && (DSG[#] < 
                  999) && (MeasIono[#] < 999) && (Abs[SMSIO[#]] < 
                  999) && (ISG[#] < 999) &];

Show[
        GraphicsArray[{{
ListPlot[{DateValue[#], 
                      RefGPS[#]} & /@ dataHost, 
                title["Host - Modelled"], 
                DisplayFunction -> 
                  Identity], 
ListPlot[{DateValue[#], 
                      RefGPS[#] + ModIono[#] - MeasIono[#]} & /@ dataHost, 
                title["Host - Measured"], 
                DisplayFunction -> 
                  Identity]}, 
{ListPlot[{DateValue[#], 
                      RefGPS[#]} & /@ dataTrav, 
                title["APMP - Modelled"], 
                DisplayFunction -> 
                  Identity], 
ListPlot[{DateValue[#], 
                      RefGPS[#] + ModIono[#] - MeasIono[#]} & /@ dataTrav, 
                title["APMP - Measured"], 
                DisplayFunction -> 
                  Identity]}
}]];

dMerge = MergeCCTF[dataHost, dataTrav];
diffdataGPS = {DateValue[#1], 
              RefSV[#1] + ModIono[#1] - RefSV2[#1] - ModIono2[#1]} & /@ 
          dMerge;

Process

dsg = DSG /@ dMerge;
{dmin, dmax} = {Min[dsg], Max[dsg]};
\(\(Show[
        Graphics[\(Sequence @@ {Hue[#[[3]]/dmax], Point[Take[#, 2]]} &\) /@ 
            Transpose[
              Append[Transpose[diffdataGPS], dsg]]], 
title[
          StringJoin["DSG: ", ToString[dmin], "..", ToString[dmax]]], 
        Frame -> True];\)\)

tdata = diffdataGPS;
DisplayTogether[
ListPlot[
          tdata], 
Plot[
          m x + c + 
              If[x1 ≤ x ≤ x2, δ, 
                0] /. {m -> 0, c -> 2, x1 -> t1, 
              x2 -> t2, δ -> 1}, {x, 
            tdata[[1, 1]], 
            tdata[[-1, 1]]}, 
          PlotStyle -> Hue[0]], 
PlotRange -> 
          All, GridLines -> Automatic
];

udata = 
        Select[tdata, 
          t1 ≤ #[[1]] ≤ t2 &];
vdata = 
        Select[tdata, ! (t1 ≤ #[[1]] ≤ t2) &];
{u = Mean[Last /@ udata], v = Mean[Last /@ vdata], u - v} // 
      N

fit = {};

AppendTo[fit, 
        NonlinearRegress[tdata, 
          m x + c + 
              If[x1 ≤ x ≤ x2, δ, 
                0] /. {m -> 0, x1 -> t1, x2 -> t2}, 
          x, {{c, 1}, {δ, 2}}, 
          RegressionReport -> {BestFit, BestFitParameters, 
              ParameterCITable, ANOVATable}]];
ParameterCITable /. Last[fit]

AppendTo[fit, 
        NonlinearRegress[tdata, 
          m x + c + 
              If[x1 ≤ x ≤ x2, δ, 
                0] /. {x1 -> t1, x2 -> t2}, 
          x, {{m, 0}, {c, 1}, {δ, 2}}, 
          RegressionReport -> {BestFit, BestFitParameters, 
              ParameterCITable, ANOVATable}]];
ParameterCITable /. Last[fit]

\(\(AppendTo[fit, 
        NonlinearRegress[tdata, 
          m\ x + c + 
              If[x1 ≤ x ≤ x2, δ, 
                0] /. {x1 -> t1, x2 -> t2}, 
          x, {{m, 0}, {c, 1}, {δ, 2}}, 
          Weights -> \ \((\(#\^\(-2\) &\) /@ 
                Take[dsg, Length[tdata]])\), 
          RegressionReport -> {BestFit, BestFitParameters, 
              ParameterCITable, ANOVATable}]];\)\)
ParameterCITable /. Last[fit]

DisplayTogether[
ListPlot[tdata, 
          PlotStyle -> AbsolutePointSize[2]], 
Plot[
          BestFit /. fit[[1]], {x, mjd1, 
            tdata[[-1, 1]]}, 
          PlotStyle -> {AbsoluteThickness[3], 
              Hue[0.3]}], 
Plot[
          BestFit /. fit[[2]], {x, mjd1, 
            tdata[[-1, 1]]}, 
          PlotStyle -> {AbsoluteThickness[3], 
              Hue[0]}], 
Plot[
          BestFit /. fit[[3]], {x, mjd1, 
            tdata[[-1, 1]]}, 
          PlotStyle -> {AbsoluteThickness[3], 
              Hue[0.6]}], 
PlotRange -> All, 
        GridLines -> Automatic
];