(************** Content-type: application/mathematica **************
                     CreatedBy='Mathematica 5.0'

                    Mathematica-Compatible Notebook

This notebook can be used with any Mathematica-compatible
application, such as Mathematica, MathReader or Publicon. The data
for the notebook starts with the line containing stars above.

To get the notebook into a Mathematica-compatible application, do
one of the following:

* Save the data starting with the line of stars above into a file
  with a name ending in .nb, then open the file inside the
  application;

* Copy the data starting with the line of stars above to the
  clipboard, then use the Paste menu command inside the application.

Data for notebooks contains only printable 7-bit ASCII and can be
sent directly in email or through ftp in text mode.  Newlines can be
CR, LF or CRLF (Unix, Macintosh or MS-DOS style).

NOTE: If you modify the data for this notebook not in a Mathematica-
compatible application, you must delete the line below containing
the word CacheID, otherwise Mathematica-compatible applications may
try to use invalid cache data.

For more information on notebooks and Mathematica-compatible 
applications, contact Wolfram Research:
  web: http://www.wolfram.com
  email: info@wolfram.com
  phone: +1-217-398-0700 (U.S.)

Notebook reader applications are available free of charge from 
Wolfram Research.
*******************************************************************)

(*CacheID: 232*)


(*NotebookFileLineBreakTest
NotebookFileLineBreakTest*)
(*NotebookOptionsPosition[     71566,       1370]*)
(*NotebookOutlinePosition[     72212,       1392]*)
(*  CellTagsIndexPosition[     72168,       1388]*)
(*WindowFrame->Normal*)



Notebook[{
Cell[BoxData[
    \(\(\(\ \)\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\(\
\[IndentingNewLine]\)\( (*\ 
      Routine\ for\ Data\ Reduction\ of\ Seeing\ data\  - \ 
        on\ the\ wave\ crest\ *) \)\(\[IndentingNewLine]\)\(\
\[IndentingNewLine]\)\(\[IndentingNewLine]\)\)\)], "Input"],

Cell[BoxData[
    \( (*\ 
      See\ the\ commented\ version\ for\ full\ details\ and\ explanations; \ 
      here\ we\ will\ give\ minimum\ comments\ in\ order\ to\ proceed\ with\ \
data\ reduction; \ 
      the\ routines\ only\ stop\ when\ strictly\ necessary\ \((for\ \
inspection\ and\ decisions\ before\ resuming)\)\ *) \)], "Input"],

Cell[BoxData[
    \( (*\ Obviously, \ 
      change\ the\ SetDirectory\ according\ to\ the\ place\ where\ you\ have\ \
the\ CCD\ text\ file; \ 
      and\ place\ its\ name\ on\ "\<ReadList\>"\ *) \)], "Input"],

Cell[BoxData[
    \( (*\ Input\ textfile\ in\ \(ReadList : \ 
          CCD\ flat - calibrated\ raw\ data\)\ *) \)], "Input"],

Cell[BoxData[
    \( (*\ Initial\ ADU\ maximum\ in\ the\ plot\ is\ set\ at\ 60000, \ 
      but\ can\ be\ changed; \ 
      only\ change\ the\ viewpoint\ as\ a\ last\ resource\ *) \)], "Input"],

Cell[BoxData[
    \(\(\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\
\( (*\ Routine\ 1\  - \ 
        Initial\ look\ at\ the\ data\ *) \)\(\[IndentingNewLine]\)\(\
\[IndentingNewLine]\)\(\[IndentingNewLine]\)\)\)], "Input"],

Cell[BoxData[{
    RowBox[{
      StyleBox[\(Off[General::spell1]\),
        "MR"], 
      StyleBox[";",
        "MR"], \(matx = 
        Input["\<Please enter the x-direction number of pixels in the CCD \
chip:\>"]\), 
      ";", \(maty = 
        Input["\<Please enter the y-direction number of pixels in the CCD \
chip:\>"]\), ";", \(SetDirectory["\<C:\Users\FullDirectoryPathHERE\>"]\), ";",
       " ", \(a = ReadList["\<FILE_NAME_HERE.txt\>", Table[Number, {matx}]]\),
       ";"}], "\[IndentingNewLine]", \(ListPlot3D[a, 
      ColorFunction \[Rule] Hue, 
      PlotRange -> {{0, matx}, {0, maty}, {0, 60000}}, 
      ViewPoint \[Rule] {1, 1,  .2}]; m = Max[a]; 
    Print["\<Peak value (ADU):  \>", m]\)}], "Input"],

Cell[BoxData[
    \( (*\ Work\ now\ towards\ a\ "\<nice looking\>"\ 3  
        D\ plot\ of\ the\ Polaris\ \(path : \ 
          tighter\ \((x1, x2)\) - \((y1, y2)\)\ base\ matrix\ and\ lower\ z - 
            maximum\ \((ADU)\) 
              but\ still\ avoiding\ to\ chop\ data\ out\); \ \ change\ \
viewpoint\ if\ necessary\ *) \)], "Input"],

Cell[BoxData[
    \(\(\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\
\( (*\ Routine\ 2\  - \ 
        Interact\ with\ the\ \(data : \ 
            final\ graph\ production\ and\ view\)\ *) \)\(\[IndentingNewLine]\
\)\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\)\)], "Input"],

Cell[BoxData[
    \(ListPlot3D[a, ColorFunction \[Rule] Hue, 
      PlotRange -> {{275, 425}, {100, 250}, {0, 40000}}, 
      ViewPoint \[Rule] { .2, 4, 2.5}]\)], "Input"],

Cell[BoxData[
    \( (*\ Final\ \((x1 - x2)\) - \((y1 - 
              y2)\)\ values\ are\ now\ inserted, \ 
      and\ there\ we\ \(go!\)\ \ *) \)], "Input"],

Cell[BoxData[
    \(\(\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\
\( (*\ Routine\ 3\ \((Main)\)\  - \ 
        Organizing\ the\ data\ into\ 2  x2\ pixels, \ 
      preparing\ vectors\ c\ and\ f\ for\ analysis; \ be\ patient, \ 
      it\ might\ take\ a\ few\ \(minutes!\)\ *) \)\(\[IndentingNewLine]\)\(\
\[IndentingNewLine]\)\(\[IndentingNewLine]\)\)\)], "Input"],

Cell[BoxData[{
    \(nx1 = Input["\<x1?\>"]; nx2 = Input["\<x2?\>"]; ny1 = Input["\<y1?\>"]; 
    ny2 = Input["\<y2?\>"]; 
    Print["\<x1= \>", nx1, "\<, x2= \>", nx2, "\<, y1= \>", \ 
      ny1, \ "\<, y2= \>", \ ny2]; b = Transpose[a]; \ \ x = 1; y = 1; 
    mx = 0; my = 0; 
    While[y < maty + 1, \ 
      While[x < matx + 1, \ 
        If[b[\([x, y]\)] == m, mx = x; my = y; x = matx + 1; y = maty + 1, 
          x = x + 1, Print["\<erro\>"]]]; x = 1; y = y + 1]; \ 
    topgr = m + 5000; x = mx - 1; y = my - 1; i = 0; j = 0; u = 100; 
    While[y < my + 2, 
      While[x < mx + 2, 
        If[b[\([x, y]\)] > u, u = b[\([x, y]\)]; i = x; j = y]; x = x + 1]; 
      y = y + 2; x = mx - 1]; 
    If[b[\([mx - 1, my]\)] > u, u = b[\([mx - 1, my]\)]; i = mx - 1; 
      j = my]; \ 
    If[b[\([mx + 1, my]\)] > u, u = b[\([mx + 1, my]\)]; i = mx + 1; j = my]; 
    m2 = u; \ m2x = i; m2y = j; esq = 0; drt = 0; cim = 0; bxo = 0; dx = 0; 
    dy = 0; dm = 0; es = 0; d = {}; e = {}; i = 0; j = 0; 
    If[Abs[mx - m2x] \[Equal] 1, i = 1, i = 0]; \ 
    If[Abs[my - m2y] \[Equal] 1, j = 1, j = 0]; 
    If[i + j \[Equal] 2, 
      If[mx > m2x && m2y > my, dx = mx - 0.5; dy = my + 0.5; 
        dm = N[Mean[{m, m2, b[\([mx - 1, my]\)], b[\([mx, my + 1]\)]}]]; 
        es = N[StandardDeviation[{m, m2, b[\([mx - 1, my]\)], 
                b[\([mx, my + 1]\)]}]]; d = Append[d, {dx, dy, dm}]; 
        e = Append[e, {dx, dy, es}], 
        If[m2x > mx && m2y > my, dx = mx + 0.5; dy = my + 0.5; 
          dm = N[Mean[{m, m2, b[\([mx + 1, my]\)], b[\([mx, my + 1]\)]}]]; 
          es = N[StandardDeviation[{m, m2, b[\([mx + 1, my]\)], 
                  b[\([mx, my + 1]\)]}]]; d = Append[d, {dx, dy, dm}]; 
          e = Append[e, {dx, dy, es}], 
          If[m2x > mx && my > m2y, dx = mx + 0.5; dy = my - 0.5; 
            dm = N[Mean[{m, m2, b[\([mx + 1, my]\)], b[\([mx, my - 1]\)]}]]; 
            es = N[StandardDeviation[{m, m2, b[\([mx + 1, my]\)], 
                    b[\([mx, my - 1]\)]}]]; d = Append[d, {dx, dy, dm}]; 
            e = Append[e, {dx, dy, es}], 
            If[mx > m2x && my > m2y, dx = mx - 0.5; dy = my - 0.5; 
              dm = N[Mean[{m, m2, b[\([mx - 1, my]\)], 
                      b[\([mx, my - 1]\)]}]]; 
              es = 
                N[StandardDeviation[{m, m2, b[\([mx - 1, my]\)], 
                      b[\([mx, my - 1]\)]}]]; d = Append[d, {dx, dy, dm}]; 
              e = Append[e, {dx, dy, es}]]]]], 
      If[m2x == mx && m2y > my, 
        esq = Max[b[\([mx - 1, my + 1]\)], b[\([mx - 1, my]\)]]; 
        dir = Max[b[\([mx + 1, my + 1]\)], b[\([mx + 1, my]\)]]; 
        If[esq > dir, dx = mx - 0.5; dy = my + 0.5; 
          dm = N[Mean[{m, m2, b[\([mx - 1, my]\)], 
                  b[\([mx - 1, my + 1]\)]}]]; 
          es = N[StandardDeviation[{m, m2, b[\([mx - 1, my]\)], 
                  b[\([mx - 1, my + 1]\)]}]]; d = Append[d, {dx, dy, dm}]; 
          e = Append[e, {dx, dy, es}], dx = mx + 0.5; dy = my + 0.5; 
          dm = N[Mean[{m, m2, b[\([mx + 1, my]\)], 
                  b[\([mx + 1, my + 1]\)]}]]; 
          es = N[StandardDeviation[{m, m2, b[\([mx + 1, my]\)], 
                  b[\([mx + 1, my + 1]\)]}]]; d = Append[d, {dx, dy, dm}]; 
          e = Append[e, {dx, dy, es}]]]; 
      If[m2x == mx && m2y < my, 
        esq = Max[b[\([mx - 1, my - 1]\)], b[\([mx - 1, my]\)]]; 
        dir = Max[b[\([mx + 1, my - 1]\)], b[\([mx + 1, my]\)]]; 
        If[esq > dir, dx = mx - 0.5; dy = my - 0.5; 
          dm = N[Mean[{m, m2, b[\([mx - 1, my]\)], 
                  b[\([mx - 1, my - 1]\)]}]]; 
          es = N[StandardDeviation[{m, m2, b[\([mx - 1, my]\)], 
                  b[\([mx - 1, my - 1]\)]}]]; d = Append[d, {dx, dy, dm}]; 
          e = Append[e, {dx, dy, es}], dx = mx + 0.5; dy = my - 0.5; 
          dm = N[Mean[{m, m2, b[\([mx + 1, my]\)], 
                  b[\([mx + 1, my - 1]\)]}]]; 
          es = N[StandardDeviation[{m, m2, b[\([mx + 1, my]\)], 
                  b[\([mx + 1, my - 1]\)]}]]; d = Append[d, {dx, dy, dm}]; 
          e = Append[e, {dx, dy, es}]]]; 
      If[m2y == my && m2x < mx, 
        cim = Max[b[\([mx - 1, my + 1]\)], b[\([mx, my + 1]\)]]; 
        bxo = Max[b[\([mx - 1, my - 1]\)], b[\([mx, my - 1]\)]]; 
        If[cim > bxo, dx = mx - 0.5; dy = my + 0.5; 
          dm = N[Mean[{m, m2, b[\([mx - 1, my + 1]\)], 
                  b[\([mx, my + 1]\)]}]]; 
          es = N[StandardDeviation[{m, m2, b[\([mx - 1, my + 1]\)], 
                  b[\([mx, my + 1]\)]}]]; d = Append[d, {dx, dy, dm}]; 
          e = Append[e, {dx, dy, es}], dx = mx - 0.5; dy = my - 0.5; 
          dm = N[Mean[{m, m2, b[\([mx - 1, my - 1]\)], 
                  b[\([mx, my - 1]\)]}]]; 
          es = N[StandardDeviation[{m, m2, b[\([mx - 1, my - 1]\)], 
                  b[\([mx, my - 1]\)]}]]; d = Append[d, {dx, dy, dm}]; 
          e = Append[e, {dx, dy, es}]]]; 
      If[m2y == my && m2x > mx, 
        cim = Max[b[\([mx + 1, my + 1]\)], b[\([mx, my + 1]\)]]; 
        bxo = Max[b[\([mx + 1, my - 1]\)], b[\([mx, my - 1]\)]]; 
        If[cim > bxo, dx = mx + 0.5; dy = my + 0.5; 
          dm = N[Mean[{m, m2, b[\([mx + 1, my + 1]\)], 
                  b[\([mx, my + 1]\)]}]]; 
          es = N[StandardDeviation[{m, m2, b[\([mx + 1, my + 1]\)], 
                  b[\([mx, my + 1]\)]}]]; d = Append[d, {dx, dy, dm}]; 
          e = Append[e, {dx, dy, es}], dx = mx + 0.5; dy = my - 0.5; 
          dm = N[Mean[{m, m2, b[\([mx + 1, my - 1]\)], 
                  b[\([mx, my - 1]\)]}]]; 
          es = N[StandardDeviation[{m, m2, b[\([mx + 1, my - 1]\)], 
                  b[\([mx, my - 1]\)]}]]; d = Append[d, {dx, dy, dm}]; 
          e = Append[e, {dx, dy, es}]]]]; mx = dx; my = dy; m = dm; ordd = 0; 
    ul = 0; ur = 0; dl = 0; dr = 0; i = dx - 0.5; j = dy - 0.5; dx = 0; 
    dy = 0; dm = 0; es = 0; xlo = 1; xhi = matx; ylo = 1; yhi = maty; d = {}; 
    e = {}; d1 = {}; \ d2 = {}; \ 
    If[EvenQ[IntegerPart[j]] \[Equal] True, ylo = 2; yhi = maty - 1]; 
    If[EvenQ[IntegerPart[i]] \[Equal] False, xhi = matx - 1, xlo = 2]; 
    y = ylo; v = yhi; x = xlo; l = xhi; 
    While[y < v + 1, 
      While[x < l + 1, dl = b[\([x, y]\)]; dr = b[\([x + 1, y]\)]; 
        ul = b[\([x, y + 1]\)]; ur = b[\([x + 1, y + 1]\)]; dx = x + 0.5; 
        dy = y + 0.5; dm = N[Mean[{dl, dr, ul, ur}]]; 
        es = N[StandardDeviation[{dl, dr, ul, ur}]]; 
        d = Append[d, {dx, dy, dm}]; d2 = Append[d2, dm]; 
        d2 = Append[d2, dm]; 
        If[dx == mx && dy \[Equal] my, ordd = Length[d]]; 
        e = Append[e, {dx, dy, es}]; x = x + 2]; x = xlo; 
      d1 = Append[d1, d2]; d1 = Append[d1, d2]; d2 = {}; y = y + 2]; 
    d3 = Transpose[d1]; c = {{mx, my, m}}; k = 0; l = 0; m2xyADU = 0; 
    u = 10001; ordem = ordd - IntegerPart[\((matx + 3)\)/2]; 
    While[l < 2, 
      While[k < 3, ordem = ordem + 1; 
        If[d[\([ordem, 3]\)] > 10000 && d[\([ordem, 3]\)] > u, 
          u = d[\([ordem, 3]\)]; m2xyADU = ordem]; k = k + 1]; k = 0; 
      ordem = ordem + matx - 4; l = l + 1]; ordem = ordd - 3; 
    While[k < 2, ordem = ordem + 2; 
      If[d[\([ordem, 3]\)] > 10000 && d[\([ordem, 3]\)] > u, 
        u = d[\([ordem, 3]\)]; m2xyADU = ordem]; k = k + 1]; m2 = u; 
    m2x = d[\([m2xyADU, 1]\)]; m2y = d[\([m2xyADU, 2]\)]; 
    If[m2 > 10000, c = Append[c, {m2x, m2y, m2}]]; k = 0; l = 0; m3xyADU = 0; 
    u = 10001; ordem = ordd - IntegerPart[\((matx + 3)\)/2]; f = {}; 
    While[l < 2, 
      While[k < 3, ordem = ordem + 1; 
        If[d[\([ordem, 3]\)] > 10000 && d[\([ordem, 3]\)] > u && 
            d[\([ordem, 1]\)] \[NotEqual] m2x && 
            d[\([ordem, 2]\)] \[NotEqual] m2y, u = d[\([ordem, 3]\)]; 
          m3xyADU = ordem]; k = k + 1]; k = 0; ordem = ordem + matx - 4; 
      l = l + 1]; ordem = ordd - 3; 
    While[k < 2, ordem = ordem + 2; 
      If[d[\([ordem, 3]\)] > 10000 && d[\([ordem, 3]\)] > u && 
          d[\([ordem, 1]\)] \[NotEqual] m2x && 
          d[\([ordem, 2]\)] \[NotEqual] m2y, u = d[\([ordem, 3]\)]; 
        m3xyADU = ordem]; k = k + 1]; m3 = u; m3x = d[\([m3xyADU, 1]\)]; 
    m3y = d[\([m3xyADU, 2]\)]; If[m3 > 10000, f = Append[f, {m3x, m3y, m3}]]; 
    st = 0; temporario = 0; ciclos1 = 0; m1xyADU = ordd; m2ADU = m2xyADU; 
    val382 = IntegerPart[\((matx - 1)\)/2];\), "\[IndentingNewLine]", 
    \(While[st == 0 && ciclos1 < 100, orddif = m2xyADU - ordd; 
      tempor = m2xyADU; u = 0; chave = Abs[val382 - Abs[orddif]]; ordem = 0; 
      teste = 0; 
      If[d[\([ordd + 2*orddif, 3]\)] > 10000 && 
          d[\([ordd + 2*orddif, 3]\)] > u, u = d[\([ordd + 2*orddif, 3]\)]; 
        ordem = ordd + 2*orddif]; \[IndentingNewLine]If\ [chave == 1, 
        teste = orddif - val382; 
        If[teste \[Equal] 1 || teste \[Equal] \(-matx\) + 2, 
          If[d[\([ordd + 2*orddif - 1, 3]\)] > 10000 && 
              d[\([ordd + 2*orddif - 1, 3]\)] > u, 
            u = d[\([ordd + 2*orddif - 1, 3]\)]; 
            ordem = ordd + 2*orddif - 1]; 
          If[d[\([ordd + orddif + 1, 3]\)] > 10000 && 
              d[\([ordd + orddif + 1, 3]\)] > u, 
            u = d[\([ordd + orddif + 1, 3]\)]; ordem = ordd + orddif + 1], 
          If[d[\([ordd + 2*orddif + 1, 3]\)] > 10000 && 
              d[\([ordd + 2*orddif + 1, 3]\)] > u, 
            u = d[\([ordd + 2*orddif + 1, 3]\)]; 
            ordem = ordd + 2*orddif + 1]; 
          If[d[\([ordd + orddif - 1, 3]\)] > 10000 && 
              d[\([ordd + orddif - 1, 3]\)] > u, 
            u = d[\([ordd + orddif - 1, 3]\)]; ordem = ordd + orddif - 1]], 
        If[chave \[Equal] 0, 
          If[d[\([ordd + 2*orddif + 1, 3]\)] > 10000 && 
              d[\([ordd + 2*orddif + 1, 3]\)] > u, 
            u = d[\([ordd + 2*orddif + 1, 3]\)]; 
            ordem = ordd + 2*orddif + 1]; 
          If[d[\([ordd + 2*orddif - 1, 3]\)] > 10000 && 
              d[\([ordd + 2*orddif - 1, 3]\)] > u, 
            u = d[\([ordd + 2*orddif - 1, 3]\)]; 
            ordem = ordd + 2*orddif - 1], 
          If[d[\([tempor + \((val382 + 1)\)*orddif, 3]\)] > 10000 && 
              d[\([tempor + \((val382 + 1)\)*orddif, 3]\)] > u, 
            u = d[\([tempor + \((val382 + 1)\)*orddif, 3]\)]; 
            ordem = tempor + \((val382 + 1)\)*orddif]; 
          If[d[\([tempor - \((val382 - 1)\)*orddif, 3]\)] > 10000 && 
              d[\([tempor - \((val382 - 1)\)*orddif, 3]\)] > u, 
            u = d[\([tempor - \((val382 - 1)\)*orddif, 3]\)]; 
            ordem = tempor - \((val382 - 1)\)*orddif]]]; m2 = u; 
      m2x = d[\([ordem, 1]\)]; m2y = d[\([ordem, 2]\)]; m2xyADU = ordem; 
      ordd = tempor; ciclos1 = ciclos1 + 1; 
      If[m2 > 10000, c = Append[c, {m2x, m2y, m2}], st = 1]]; st = 0; 
    ciclos2 = 0; orddif = 0; temporario = 0; ordd = m1xyADU; 
    m3ADU = m3xyADU;\), "\[IndentingNewLine]", 
    \(While[st == 0 && ciclos2 < 100, orddif = m3xyADU - ordd; 
      temporario = m3xyADU; u = 0; chave = Abs[val382 - Abs[orddif]]; 
      ordem = 0; teste = 0; 
      If[d[\([ordd + 2*orddif, 3]\)] > 10000 && 
          d[\([ordd + 2*orddif, 3]\)] > u, u = d[\([ordd + 2*orddif, 3]\)]; 
        ordem = ordd + 2*orddif]; \[IndentingNewLine]If\ [chave == 1, 
        teste = orddif - val382; 
        If[teste \[Equal] 1 || teste \[Equal] \(-matx\) + 2, 
          If[d[\([ordd + 2*orddif - 1, 3]\)] > 10000 && 
              d[\([ordd + 2*orddif - 1, 3]\)] > u, 
            u = d[\([ordd + 2*orddif - 1, 3]\)]; 
            ordem = ordd + 2*orddif - 1]; 
          If[d[\([ordd + orddif + 1, 3]\)] > 10000 && 
              d[\([ordd + orddif + 1, 3]\)] > u, 
            u = d[\([ordd + orddif + 1, 3]\)]; ordem = ordd + orddif + 1], 
          If[d[\([ordd + 2*orddif + 1, 3]\)] > 10000 && 
              d[\([ordd + 2*orddif + 1, 3]\)] > u, 
            u = d[\([ordd + 2*orddif + 1, 3]\)]; 
            ordem = ordd + 2*orddif + 1]; 
          If[d[\([ordd + orddif - 1, 3]\)] > 10000 && 
              d[\([ordd + orddif - 1, 3]\)] > u, 
            u = d[\([ordd + orddif - 1, 3]\)]; ordem = ordd + orddif - 1]], 
        If[chave \[Equal] 0, 
          If[d[\([ordd + 2*orddif + 1, 3]\)] > 10000 && 
              d[\([ordd + 2*orddif + 1, 3]\)] > u, 
            u = d[\([ordd + 2*orddif + 1, 3]\)]; 
            ordem = ordd + 2*orddif + 1]; 
          If[d[\([ordd + 2*orddif - 1, 3]\)] > 10000 && 
              d[\([ordd + 2*orddif - 1, 3]\)] > u, 
            u = d[\([ordd + 2*orddif - 1, 3]\)]; 
            ordem = ordd + 2*orddif - 1], 
          If[d[\([temporario + \((val382 + 1)\)*orddif, 3]\)] > 10000 && 
              d[\([temporario + \((val382 + 1)\)*orddif, 3]\)] > u, 
            u = d[\([temporario + \((val382 + 1)\)*orddif, 3]\)]; 
            ordem = temporario + \((val382 + 1)\)*orddif]; 
          If[d[\([temporario - \((val382 - 1)\)*orddif, 3]\)] > 10000 && 
              d[\([temporario - \((val382 - 1)\)*orddif, 3]\)] > u, 
            u = d[\([temporario - \((val382 - 1)\)*orddif, 3]\)]; 
            ordem = temporario - \((val382 - 1)\)*orddif]]]; m3 = u; 
      m3x = d[\([ordem, 1]\)]; m3y = d[\([ordem, 2]\)]; m3xyADU = ordem; 
      ordd = temporario; ciclos2 = ciclos2 + 1; 
      If[m3 > 10000, f = Append[f, {m3x, m3y, m3}], st = 1]]; l = 1; e = {}; 
    n2 = Length[c]; 
    While[l \[LessEqual] n2, e = Append[e, {c[\([l, 1]\)], c[\([l, 2]\)]}]; 
      l = l + 1]; 
    ListPlot[e, PlotRange \[Rule] All, PlotStyle -> PointSize[0.013]]; \ 
    Print["\<Cycles of vector c, which includes the peak:  \>", ciclos1 + 1]; 
    Print["\<Coordinates of the peak (x,y):  \>", 
      d[\([m1xyADU, 1]\)], "\<   \>", d[\([m1xyADU, 2]\)]]; 
    Print["\<Coordinates of the 2nd maximum (x,y):  \>", 
      d[\([m2ADU, 1]\)], "\<   \>", d[\([m2ADU, 2]\)]]; 
    Print["\< Vector C:  \>", c]; l = 1; e = {}; n2 = Length[f]; 
    While[l \[LessEqual] n2, e = Append[e, {f[\([l, 1]\)], f[\([l, 2]\)]}]; 
      l = l + 1]; 
    ListPlot[e, PlotRange \[Rule] All, PlotStyle -> PointSize[0.013]]; 
    Print["\<Cycles of vector f, which does not include the peak:  \>", 
      ciclos2]; 
    Print["\<Coordinates of the 3rd maximum (x,y):  \>", 
      d[\([m3ADU, 1]\)], "\<   \>", d[\([m3ADU, 2]\)]]; 
    Print["\< Vector F:  \>", f];\)}], "Input"],

Cell[BoxData[
    \(\(\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\
\( (*\ Routine\ 4\ \((Cycles)\)\  - \ 
        eventually\ redefining\ vector\ c\ and/
            or\ vector\ f\ \
*) \)\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\)\)\
], "Input"],

Cell[BoxData[
    \(lma = 
      Input["\<In the case of vector C cycles reaching 101, please say in \
which point you want to stop (number) or, if all is ok, write the number \
0.\>"]; \ If[lma \[NotEqual] 0, xcycl = {}; l = 1; 
      While[l < lma + 1, xcycl = Append[xcycl, c[\([l]\)]]; l = l + 1]; 
      c = xcycl]; 
    mma = Input["\<In the case of vector F cycles reaching 100, please say in \
which point you want to stop (number) or, if all is ok, write the number \
0.\>"]; \ If[mma \[NotEqual] 0, ycycl = {}; m = 1; 
      While[m < mma + 1, ycycl = Append[ycycl, f[\([m]\)]]; m = m + 1]; 
      f = ycycl]; l = 1; e = {}; n2 = Length[c]; 
    While[l \[LessEqual] n2, e = Append[e, {c[\([l, 1]\)], c[\([l, 2]\)]}]; 
      l = l + 1]; 
    ListPlot[e, PlotRange \[Rule] All, PlotStyle -> PointSize[0.013]]; \ 
    Print["\<NEW Vector C:  \>", c]; l = 1; e = {}; n2 = Length[f]; 
    While[l \[LessEqual] n2, e = Append[e, {f[\([l, 1]\)], f[\([l, 2]\)]}]; 
      l = l + 1]; 
    ListPlot[e, PlotRange \[Rule] All, PlotStyle -> PointSize[0.013]]; 
    Print["\<NEW Vector F:  \>", f];\)], "Input"],

Cell[BoxData[
    \(\(\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\
\( (*\ Routine\ 5\ \((Path)\)\  - \ edit\ "\<h=Join[g,c]\>"\ if\ necessary; \ 
      and/or\ BEFORE\ the\ full\ line\ "\<While...e=Append...l=1;\>"\ \(put : \
\ "\<e=h[[Ordering[h[[All,2]]]]];h=e;e={};\>"\)\ *) \)\(\ \)\(\
\[IndentingNewLine]\)\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\)\)], \
"Input"],

Cell[BoxData[
    \(compf = Length[f]; k = 0; g = {}; i = 0; 
    While[k < compf, i = f[\([compf - k]\)]; g = Append[g, i]; i = 0; 
      k = k + 1]; h = {}; h = Join[g, c]; Print["\<Vector h:   \>", h]; 
    l = 1; h3 = {}; n = Length[h]; 
    Print["\<Number of points in vector h:  \>", n]; e = {}; n2 = Length[h]; 
    While[l \[LessEqual] n2, e = Append[e, {h[\([l, 1]\)], h[\([l, 2]\)]}]; 
      l = l + 1]; l = 1; 
    While[l \[LessEqual] n, h3 = Append[h3, h[\([l, 3]\)]]; l = l + 1]; 
    Print["\<Maximum 4-pix of vector h:  \>", Max[h3]]; 
    Print["\<Minimum 4-pix of vector h:  \>", Min[h3]]; 
    ListPlot[h3, PlotRange \[Rule] All, PlotStyle -> PointSize[0.013], 
      Frame -> True, Axes -> False]; 
    e1 = ListPlot[e, PlotRange \[Rule] All, PlotStyle -> PointSize[0.013]]; 
    e2 = ContourGraphics[a, 
        PlotRange -> {{nx1, nx2}, {ny1, ny2}, {0, topgr}}]; Show[e2]; 
    Show[e2, e1]; 
    q2 = ContourGraphics[d1, 
        PlotRange -> {{nx1, nx2}, {ny1, ny2}, {0, topgr}}]; Show[q2]; 
    Show[q2, e1];\)], "Input"],

Cell[BoxData[
    \(\(\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\( (*\ 
      Note\ that\ the\ seeing\ determination\ will\ take\ place\ only\ if\ \
there\ is\ no\ "\<LOBE work\>"\ to\ be\ made; \ 
      if\ this\ is\ not\ the\ case, \ 
      jump\ to\ the\ Special\ Lobe\ Section; \ otherwise, \ 
      carry\ on\ with\ Routine\ 6\ *) \)\(\[IndentingNewLine]\)\(\
\[IndentingNewLine]\)\)\)], "Input"],

Cell[BoxData[
    \(\(\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\
\( (*\ Routine\ 6\ \((seeing)\)\ *) \)\(\[IndentingNewLine]\)\(\
\[IndentingNewLine]\)\(\[IndentingNewLine]\)\)\)], "Input"],

Cell[BoxData[
    \( (*\ Routine\ 6.1\ \((Circle\ Fitting)\)\ *) \)], "Input"],

Cell[BoxData[
    \( (*\ 
      If\ the\ path\ is\ too\ vertical\ Sort\ may\ not\ work\ properly; \ 
      thus, \ replace\ "\<Sort[e]\>"\ by\ "\<e[[Ordering[e[[All,2]]]]]\>"\ *) \
\)], "Input"],

Cell[BoxData[
    \(ess = {}; ess = Sort[e]; e = ess; 
    circfit1 = 
      FindFit[e, 
        atr + Sqrt[
            3233^2 - \((UnitStep[r - nx1]*UnitStep[nx2 - r]*r - 
                    btr)\)^2], {atr, btr}, r, MaxIterations \[Rule] 50000, 
        Method -> LevenbergMarquardt]; atrstr = ToString[circfit1[\([1]\)]]; 
    btrstr = ToString[circfit1[\([2]\)]]; latrstr = StringLength[atrstr]; 
    lbtrstr = StringLength[btrstr]; 
    atr2 = ToExpression[StringTake[atrstr, {8, latrstr}]]; 
    btr2 = ToExpression[StringTake[btrstr, {8, lbtrstr}]]; 
    circfit2 = 
      FindFit[e, 
        atm - Sqrt[
            3233^2 - \((UnitStep[r - nx1]*UnitStep[nx2 - r]*r - 
                    btm)\)^2], {atm, btm}, r, MaxIterations \[Rule] 50000, 
        Method -> LevenbergMarquardt]; atmstr = ToString[circfit2[\([1]\)]]; 
    btmstr = ToString[circfit2[\([2]\)]]; latmstr = StringLength[atmstr]; 
    lbtmstr = StringLength[btmstr]; 
    atm2 = ToExpression[StringTake[atmstr, {8, latmstr}]]; 
    btm2 = ToExpression[StringTake[btmstr, {8, lbtmstr}]]; 
    e10 = Plot[atr2 + Sqrt[3233^2 - \((r - btr2)\)^2], {r, nx1, nx2}, 
        PlotStyle \[Rule] {RGBColor[0, 1, 0], AbsoluteThickness[2]}]; 
    e20 = Plot[atm2 - Sqrt[3233^2 - \((r - btm2)\)^2], {r, nx1, nx2}, 
        PlotStyle \[Rule] {RGBColor[0, 1, 0], AbsoluteThickness[2]}]; 
    Show[e10, e1]; \(\(Show[e20, e1]\)\(\ \)\); Show[q2, e10]; Show[q2, e20]; 
    ans = Input["\<After careful eye inspection of both plots, in points and \
in greyscale, including curvature analysis, which one is better? If the 1st \
one (or the two cannot be distinguished), please place '1' below (only the \
number). If the 2nd one, please place '2'.\>"]; 
    If[ans \[Equal] 2, at = atm2; bt = btm2; sinal = \(-1\), at = atr2; 
      bt = btr2; sinal = 1]; l = 1; n2 = Length[h]; distancirc = {}; 
    somasqr = 0; 
    While[l \[LessEqual] n2, 
      sdf = Minimize[
          Sqrt[\((t - h[\([l, 1]\)])\)^2 + \((at + 
                    sinal*Sqrt[Abs[3233^2 - \((t - bt)\)^2]] - 
                    h[\([l, 2]\)])\)^2], t]; 
      distancirc = Append[distancirc, sdf[\([1]\)]]; 
      somasqr = somasqr + sdf[\([1]\)]^2; l = l + 1]; 
    seeingPh = Median[distancirc]; seeingVis = 2*seeingPh; 
    seeingPh2 = Sqrt[somasqr/n2]; \ seeingVis2 = 2*seeingPh2; 
    sddev = seeingVis2*0.77/
          206265; \ \ Print["\<CCD Seeing (R.M.S.) - CIRCLE FIT in arcseconds \
=  \>", seeingPh2*0.77\ ]; 
    r0 = \((6.88/\((0.25*
                sddev^2*\((2\ Pi)\)^2*\((420.45\ \
10^\(-9\))\)^\((\(-2\))\)*\((0.106)\)^\((1/3)\))\))\)^\((3/5)\); 
    b1 =  .90018077103124072; b2 = \(- .44942005216093051\); 
    b3 = \ \(-1.1559547452503143\); b4 =  .097676737867950225; Diam =  .106; 
    Deff = r0*\((b1*Exp[b2*\((Diam/r0)\)^b3] + b4)\); DiamL = 1.25; 
    DeffL = r0*\((b1*Exp[b2*\((DiamL/r0)\)^b3] + b4)\); 
    Finalseeing = 1.22*420.45\ 10^\(-9\)/Deff*206265; 
    FinalseeingL = 1.22*420.45\ 10^\(-9\)/DeffL*206265; \ u1 = h[\([1, 1]\)]; 
    t1 = h[\([1, 2]\)]; w1 = h[\([n2, 1]\)]; v1 = h[\([n2, 2]\)]; 
    angyy = Abs[ArcTan[Abs[u1 - w1]/Abs[t1 - v1]]]; 
    If[angyy >  .78539816344, angyy = Pi/2 - angyy]; 
    fatorredutor = Sqrt[1 + \((Tan[angyy])\)^2]; 
    fluct1 = \((c[\([1, 3]\)] - h[\([1, 3]\)])\)*
        fatorredutor*100/c[\([1, 3]\)]; 
    fluct2 = \((c[\([1, 3]\)] - h[\([n2, 3]\)])\)*
        fatorredutor*100/c[\([1, 3]\)]; \ 
    Print["\<Peak-to-1st-path-point fluctuation: \>", fluct1, \ "\<%\>"]; 
    Print["\<Peak-to-last-path-point fluctuation: \>", fluct2, \ "\<%\>"]; 
    l = 1; n2 = Length[h]; flutuacoes = {}; fluct = 0; 
    While[l < n2, u1 = h[\([l, 1]\)]; t1 = h[\([l, 2]\)]; 
      w1 = h[\([l + 1, 1]\)]; v1 = h[\([l + 1, 2]\)]; 
      If[t1 - v1 \[NotEqual] 0, 
        angyy = Abs[ArcTan[Abs[u1 - w1]/Abs[t1 - v1]]]; 
        If[angyy >  .78539816344, angyy = Pi/2 - angyy]; 
        fatorredutor = Sqrt[1 + \((Tan[angyy])\)^2], fatorredutor = 1]; 
      fluct = Abs[\((h[\([l, 3]\)] - h[\([l + 1, 3]\)])\)*fatorredutor]*100/
            h[\([l, 3]\)]; flutuacoes = Append[flutuacoes, fluct]; 
      l = l + 1]; seeinglong = Median[flutuacoes]; 
    Print["\<Longitudinal 'seeing' (percentage of brightness variations along \
path):  \>", seeinglong, \ "\< %\>"];\)], "Input"],

Cell[BoxData[
    \(\(\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\
\( (*\ Routine\ 6.2\ \((Parabole\ Fitting)\)\ *) \)\)\)], "Input"],

Cell[BoxData[
    \(\(\(Export["\<parabole.dat\>", h]\) \); \(\(a3 = 
        Input["\<Please insert the results from the Zunzun fit as follows \
(coefficients) noting that no scientific notation is allowed! So, first, \
please insert a, the independent coefficient:  \>"\ ]\) \); \(\(a2 = 
        Input["\<Now, please insert b, the coefficient in x (bx):    \>"]\) \
\); \(\(a1 = 
        Input["\<Finally, please insert c, the coefficient in x ^2(c x^2):    \
\>"]\) \); \(\(e3 = 
        Plot[a3 + a2\ x + a1\ x^2, {x, nx1, nx2}, 
          PlotStyle \[Rule] {RGBColor[0, 1, 0], 
              AbsoluteThickness[2]}]\) \); \(\(Show[e3, e1]\) \); \(\(Show[
        q2, e3]\) \); \(\(l = 1\) \); \(\(n2 = 
        Length[h]\) \); \(\(distancia = {}\) \); \(\(somasqr = 
        0\) \); \(\(While[l \[LessEqual] n2, 
        sdf = Minimize[
            Sqrt[\((t - h[\([l, 1]\)])\)^2 + \((a3 + a2\ t + a1\ t^2 - 
                      h[\([l, 2]\)])\)^2], t]; 
        distancia = Append[distancia, sdf[\([1]\)]]; 
        somasqr = somasqr + sdf[\([1]\)]^2; l = l + 1]\) \); \(\(seeingPh = 
        Median[distancia]\) \); seeingVis = 2*seeingPh; 
    seeingPh2 = 
      Sqrt[somasqr/n2]; \ \(\(seeingVis2 = 2*seeingPh2\) \); \(\(sddev = 
        seeingVis2*0.77/206265\) \); \ 
    Print["\<CCD Seeing (R.M.S.) - PARABOLE FIT in arcseconds =  \>", 
      seeingPh2*0.77\ ]; u1 = h[\([1, 1]\)]; t1 = h[\([1, 2]\)]; 
    w1 = h[\([n2, 1]\)]; v1 = h[\([n2, 2]\)]; 
    angyy = Abs[ArcTan[Abs[u1 - w1]/Abs[t1 - v1]]]; 
    If[angyy >  .78539816344, angyy = Pi/2 - angyy]; 
    fatorredutor = Sqrt[1 + \((Tan[angyy])\)^2]; 
    fluct1 = \((c[\([1, 3]\)] - h[\([1, 3]\)])\)*
        fatorredutor*100/c[\([1, 3]\)]; 
    fluct2 = \((c[\([1, 3]\)] - h[\([n2, 3]\)])\)*
        fatorredutor*100/c[\([1, 3]\)]; \ 
    Print["\<Peak-to-1st-path-point fluctuation: \>", fluct1, \ "\<%\>"]; 
    Print["\<Peak-to-last-path-point fluctuation: \>", fluct2, \ "\<%\>"]; 
    l = 1; n2 = 
      Length[h]; \(\(flutuacoes = {}\) \); \(\(fluct = 0\) \); \(\(While[
        l < n2, u1 = h[\([l, 1]\)]; t1 = h[\([l, 2]\)]; 
        w1 = h[\([l + 1, 1]\)]; v1 = h[\([l + 1, 2]\)]; 
        If[t1 - v1 \[NotEqual] 0, 
          angyy = Abs[ArcTan[Abs[u1 - w1]/Abs[t1 - v1]]]; 
          If[angyy >  .78539816344, angyy = Pi/2 - angyy]; 
          fatorredutor = Sqrt[1 + \((Tan[angyy])\)^2], fatorredutor = 1]; 
        fluct = Abs[\((h[\([l, 3]\)] - h[\([l + 1, 3]\)])\)*fatorredutor]*100/
              h[\([l, 3]\)]; flutuacoes = Append[flutuacoes, fluct]; 
        l = l + 1]\) \); \(\(seeinglong = Median[flutuacoes]\) \); 
    Print["\<Longitudinal 'seeing' (percentage of brightness variations along \
path):  \>", seeinglong, \ "\< %\>"];\)], "Input"],

Cell[BoxData[
    \(\(\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\
\( (*\ Routine\ 6.3\ \(("\<Horizontal\>"\ Fitting)\)\ *) \)\)\)], "Input"],

Cell[BoxData[
    \(l = 1; n2 = Length[h]; distancirc = {}; xarcocirculo = {}; valor = 0; 
    sdf = 0; somasqr = 0; 
    ArcoCirculo = at + sinal*Sqrt[3233^2 - \((t - bt)\)^2]; 
    While[l \[LessEqual] n2, 
      xarcocirculo = Solve[ArcoCirculo == h[\([l, 2]\)], t]; 
      valor = t\  /. \ xarcocirculo[\([1]\)]; 
      sdf = Abs[valor - h[\([l, 1]\)]]; distancirc = Append[distancirc, sdf]; 
      somasqr = somasqr + sdf^2; l = l + 1; xarcocirculo = {}; sdf = 0; 
      valor = 0]; seeingPh = Median[distancirc]; seeingVis = 2*seeingPh; 
    seeingPh2 = Sqrt[somasqr/n2]; \ seeingVis2 = 2*seeingPh2; 
    sddev = seeingVis2*0.77/
          206265; \ \ Print["\<CCD Seeing (R.M.S.) - HORIZONTAL FIT in \
arcseconds =  \>", seeingPh2*0.77\ ];\)], "Input"],

Cell[BoxData[
    \(\(\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\
\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\( (*\ 
      Section\  - \ Lobe\ Fit\ \((if\ necessary)\); \ 
      Lobe\ 1\ *) \)\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\(\
\[IndentingNewLine]\)\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\(\
\[IndentingNewLine]\)\)\)], "Input"],

Cell[BoxData[
    \( (*\ 
      What\ follows\ essentially\ repeats\ all\ the\ routines\ above\ except\ \
for\ two\ crucial\ \(steps : \ 
          save\ current\ vector\ h\ as\ vector\ h1\ for\ later\ \
combination\); \ \ the\ initial\ file\ imported\ \((into\ vector\ a)\)\ will\ \
be\ transformed\ on\ input\ into\ vector\ al1, \ 
      before\ proceeding\ as\ before; \ 
      some\ common\ values\ to\ the\ above\ routines\ are\ not\ input\ here\ *) \
\)], "Input"],

Cell[BoxData[
    \(\(\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\
\( (*\ Routine\ 1\  - \ 
        Initial\ look\ at\ the\ data\ *) \)\(\[IndentingNewLine]\)\(\
\[IndentingNewLine]\)\(\[IndentingNewLine]\)\)\)], "Input"],

Cell[BoxData[{
    \(h1 = h; \ b = Transpose[a]; 
    ax1 = Input["\<Please insert the limits of the rectangle you want to \
'remove' from the data as follows:  x1?\>"]; ax2 = Input["\<x2?\>"]; 
    ay1 = Input["\<y1?\>"]; 
    ay2 = Input["\<y2?\>"]; \ \ Print["\<You defined the following EXTRACTION \
square: x1= \>", ax1, "\<, x2= \>", ax2, "\<, y1= \>", \ 
      ay1, \ "\<, y2= \>", \ ay2]; x = ax1; y = ay1; 
    While[y < ay2 + 1, \ 
      While[x < ax2 + 1, \ b[\([x, y]\)] = 100; x = x + 1]; x = ax1; 
      y = y + 1];\), "\[IndentingNewLine]", 
    \(al1 = b; m = Max[al1]; 
    Print["\<Peak value of Lobe 1 (ADU):  \>", m];\)}], "Input"],

Cell[BoxData[
    \(\(\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\
\( (*\ Repeat\ here\ the\ maximum\ \((ADU)\) you\ used\ in\ the\ final\ 3  
        D\ plot\ of\ the\ main\ part; \ 
      the\ rest\ are\ what\ you\ already\ defined; \ Routine\ 2\ is, \ 
      thus, \ skipped\ here\ \
*) \)\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\)\)\
], "Input"],

Cell[BoxData[
    \(\(\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\
\( (*\ Routine\ 3\ \((Main)\)\  - \ 
        Organizing\ the\ data\ into\ 2  x2\ pixels, \ 
      preparing\ vectors\ c\ and\ f\ for\ analysis; \ be\ patient, \ 
      it\ might\ take\ a\ few\ \(minutes!\)\ *) \)\(\[IndentingNewLine]\)\(\
\[IndentingNewLine]\)\(\[IndentingNewLine]\)\)\)], "Input"],

Cell[BoxData[{
    \(x = 1; y = 1; mx = 0; my = 0; 
    While[y < maty + 1, \ 
      While[x < matx + 1, \ 
        If[b[\([x, y]\)] == m, mx = x; my = y; x = matx + 1; y = maty + 1, 
          x = x + 1, Print["\<erro\>"]]]; x = 1; y = y + 1]; \ 
    topgr = m + 5000; x = mx - 1; y = my - 1; i = 0; j = 0; u = 100; 
    While[y < my + 2, 
      While[x < mx + 2, 
        If[b[\([x, y]\)] > u, u = b[\([x, y]\)]; i = x; j = y]; x = x + 1]; 
      y = y + 2; x = mx - 1]; 
    If[b[\([mx - 1, my]\)] > u, u = b[\([mx - 1, my]\)]; i = mx - 1; 
      j = my]; \ 
    If[b[\([mx + 1, my]\)] > u, u = b[\([mx + 1, my]\)]; i = mx + 1; j = my]; 
    m2 = u; \ m2x = i; m2y = j; esq = 0; drt = 0; cim = 0; bxo = 0; dx = 0; 
    dy = 0; dm = 0; es = 0; d = {}; e = {}; i = 0; j = 0; 
    If[Abs[mx - m2x] \[Equal] 1, i = 1, i = 0]; \ 
    If[Abs[my - m2y] \[Equal] 1, j = 1, j = 0]; 
    If[i + j \[Equal] 2, 
      If[mx > m2x && m2y > my, dx = mx - 0.5; dy = my + 0.5; 
        dm = N[Mean[{m, m2, b[\([mx - 1, my]\)], b[\([mx, my + 1]\)]}]]; 
        es = N[StandardDeviation[{m, m2, b[\([mx - 1, my]\)], 
                b[\([mx, my + 1]\)]}]]; d = Append[d, {dx, dy, dm}]; 
        e = Append[e, {dx, dy, es}], 
        If[m2x > mx && m2y > my, dx = mx + 0.5; dy = my + 0.5; 
          dm = N[Mean[{m, m2, b[\([mx + 1, my]\)], b[\([mx, my + 1]\)]}]]; 
          es = N[StandardDeviation[{m, m2, b[\([mx + 1, my]\)], 
                  b[\([mx, my + 1]\)]}]]; d = Append[d, {dx, dy, dm}]; 
          e = Append[e, {dx, dy, es}], 
          If[m2x > mx && my > m2y, dx = mx + 0.5; dy = my - 0.5; 
            dm = N[Mean[{m, m2, b[\([mx + 1, my]\)], b[\([mx, my - 1]\)]}]]; 
            es = N[StandardDeviation[{m, m2, b[\([mx + 1, my]\)], 
                    b[\([mx, my - 1]\)]}]]; d = Append[d, {dx, dy, dm}]; 
            e = Append[e, {dx, dy, es}], 
            If[mx > m2x && my > m2y, dx = mx - 0.5; dy = my - 0.5; 
              dm = N[Mean[{m, m2, b[\([mx - 1, my]\)], 
                      b[\([mx, my - 1]\)]}]]; 
              es = N[StandardDeviation[{m, m2, b[\([mx - 1, my]\)], 
                      b[\([mx, my - 1]\)]}]]; d = Append[d, {dx, dy, dm}]; 
              e = Append[e, {dx, dy, es}]]]]], 
      If[m2x == mx && m2y > my, 
        esq = Max[b[\([mx - 1, my + 1]\)], b[\([mx - 1, my]\)]]; 
        dir = Max[b[\([mx + 1, my + 1]\)], b[\([mx + 1, my]\)]]; 
        If[esq > dir, dx = mx - 0.5; dy = my + 0.5; 
          dm = N[Mean[{m, m2, b[\([mx - 1, my]\)], 
                  b[\([mx - 1, my + 1]\)]}]]; 
          es = N[StandardDeviation[{m, m2, b[\([mx - 1, my]\)], 
                  b[\([mx - 1, my + 1]\)]}]]; d = Append[d, {dx, dy, dm}]; 
          e = Append[e, {dx, dy, es}], dx = mx + 0.5; dy = my + 0.5; 
          dm = N[Mean[{m, m2, b[\([mx + 1, my]\)], 
                  b[\([mx + 1, my + 1]\)]}]]; 
          es = N[StandardDeviation[{m, m2, b[\([mx + 1, my]\)], 
                  b[\([mx + 1, my + 1]\)]}]]; d = Append[d, {dx, dy, dm}]; 
          e = Append[e, {dx, dy, es}]]]; 
      If[m2x == mx && m2y < my, 
        esq = Max[b[\([mx - 1, my - 1]\)], b[\([mx - 1, my]\)]]; 
        dir = Max[b[\([mx + 1, my - 1]\)], b[\([mx + 1, my]\)]]; 
        If[esq > dir, dx = mx - 0.5; dy = my - 0.5; 
          dm = N[Mean[{m, m2, b[\([mx - 1, my]\)], 
                  b[\([mx - 1, my - 1]\)]}]]; 
          es = N[StandardDeviation[{m, m2, b[\([mx - 1, my]\)], 
                  b[\([mx - 1, my - 1]\)]}]]; d = Append[d, {dx, dy, dm}]; 
          e = Append[e, {dx, dy, es}], dx = mx + 0.5; dy = my - 0.5; 
          dm = N[Mean[{m, m2, b[\([mx + 1, my]\)], 
                  b[\([mx + 1, my - 1]\)]}]]; 
          es = N[StandardDeviation[{m, m2, b[\([mx + 1, my]\)], 
                  b[\([mx + 1, my - 1]\)]}]]; d = Append[d, {dx, dy, dm}]; 
          e = Append[e, {dx, dy, es}]]]; 
      If[m2y == my && m2x < mx, 
        cim = Max[b[\([mx - 1, my + 1]\)], b[\([mx, my + 1]\)]]; 
        bxo = Max[b[\([mx - 1, my - 1]\)], b[\([mx, my - 1]\)]]; 
        If[cim > bxo, dx = mx - 0.5; dy = my + 0.5; 
          dm = N[Mean[{m, m2, b[\([mx - 1, my + 1]\)], 
                  b[\([mx, my + 1]\)]}]]; 
          es = N[StandardDeviation[{m, m2, b[\([mx - 1, my + 1]\)], 
                  b[\([mx, my + 1]\)]}]]; d = Append[d, {dx, dy, dm}]; 
          e = Append[e, {dx, dy, es}], dx = mx - 0.5; dy = my - 0.5; 
          dm = N[Mean[{m, m2, b[\([mx - 1, my - 1]\)], 
                  b[\([mx, my - 1]\)]}]]; 
          es = N[StandardDeviation[{m, m2, b[\([mx - 1, my - 1]\)], 
                  b[\([mx, my - 1]\)]}]]; d = Append[d, {dx, dy, dm}]; 
          e = Append[e, {dx, dy, es}]]]; 
      If[m2y == my && m2x > mx, 
        cim = Max[b[\([mx + 1, my + 1]\)], b[\([mx, my + 1]\)]]; 
        bxo = Max[b[\([mx + 1, my - 1]\)], b[\([mx, my - 1]\)]]; 
        If[cim > bxo, dx = mx + 0.5; dy = my + 0.5; 
          dm = N[Mean[{m, m2, b[\([mx + 1, my + 1]\)], 
                  b[\([mx, my + 1]\)]}]]; 
          es = N[StandardDeviation[{m, m2, b[\([mx + 1, my + 1]\)], 
                  b[\([mx, my + 1]\)]}]]; d = Append[d, {dx, dy, dm}]; 
          e = Append[e, {dx, dy, es}], dx = mx + 0.5; dy = my - 0.5; 
          dm = N[Mean[{m, m2, b[\([mx + 1, my - 1]\)], 
                  b[\([mx, my - 1]\)]}]]; 
          es = N[StandardDeviation[{m, m2, b[\([mx + 1, my - 1]\)], 
                  b[\([mx, my - 1]\)]}]]; d = Append[d, {dx, dy, dm}]; 
          e = Append[e, {dx, dy, es}]]]]; mx = dx; my = dy; m = dm; ordd = 0; 
    ul = 0; ur = 0; dl = 0; dr = 0; i = dx - 0.5; j = dy - 0.5; dx = 0; 
    dy = 0; dm = 0; es = 0; xlo = 1; xhi = matx; ylo = 1; yhi = maty; d = {}; 
    e = {}; d1 = {}; \ d2 = {}; \ 
    If[EvenQ[IntegerPart[j]] \[Equal] True, ylo = 2; yhi = maty - 1]; 
    If[EvenQ[IntegerPart[i]] \[Equal] False, xhi = matx - 1, xlo = 2]; 
    y = ylo; v = yhi; x = xlo; l = xhi; 
    While[y < v + 1, 
      While[x < l + 1, dl = b[\([x, y]\)]; dr = b[\([x + 1, y]\)]; 
        ul = b[\([x, y + 1]\)]; ur = b[\([x + 1, y + 1]\)]; dx = x + 0.5; 
        dy = y + 0.5; dm = N[Mean[{dl, dr, ul, ur}]]; 
        es = N[StandardDeviation[{dl, dr, ul, ur}]]; 
        d = Append[d, {dx, dy, dm}]; d2 = Append[d2, dm]; 
        d2 = Append[d2, dm]; 
        If[dx == mx && dy \[Equal] my, ordd = Length[d]]; 
        e = Append[e, {dx, dy, es}]; x = x + 2]; x = xlo; 
      d1 = Append[d1, d2]; d1 = Append[d1, d2]; d2 = {}; y = y + 2]; 
    d3 = Transpose[d1]; c = {{mx, my, m}}; k = 0; l = 0; m2xyADU = 0; 
    u = 10001; ordem = ordd - IntegerPart[\((matx + 3)\)/2]; 
    While[l < 2, 
      While[k < 3, ordem = ordem + 1; 
        If[d[\([ordem, 3]\)] > 10000 && d[\([ordem, 3]\)] > u, 
          u = d[\([ordem, 3]\)]; m2xyADU = ordem]; k = k + 1]; k = 0; 
      ordem = ordem + matx - 4; l = l + 1]; ordem = ordd - 3; 
    While[k < 2, ordem = ordem + 2; 
      If[d[\([ordem, 3]\)] > 10000 && d[\([ordem, 3]\)] > u, 
        u = d[\([ordem, 3]\)]; m2xyADU = ordem]; k = k + 1]; m2 = u; 
    m2x = d[\([m2xyADU, 1]\)]; m2y = d[\([m2xyADU, 2]\)]; 
    If[m2 > 10000, c = Append[c, {m2x, m2y, m2}]]; k = 0; l = 0; m3xyADU = 0; 
    u = 10001; ordem = ordd - IntegerPart[\((matx + 3)\)/2]; f = {}; 
    While[l < 2, 
      While[k < 3, ordem = ordem + 1; 
        If[d[\([ordem, 3]\)] > 10000 && d[\([ordem, 3]\)] > u && 
            d[\([ordem, 1]\)] \[NotEqual] m2x && 
            d[\([ordem, 2]\)] \[NotEqual] m2y, u = d[\([ordem, 3]\)]; 
          m3xyADU = ordem]; k = k + 1]; k = 0; ordem = ordem + matx - 4; 
      l = l + 1]; ordem = ordd - 3; 
    While[k < 2, ordem = ordem + 2; 
      If[d[\([ordem, 3]\)] > 10000 && d[\([ordem, 3]\)] > u && 
          d[\([ordem, 1]\)] \[NotEqual] m2x && 
          d[\([ordem, 2]\)] \[NotEqual] m2y, u = d[\([ordem, 3]\)]; 
        m3xyADU = ordem]; k = k + 1]; m3 = u; m3x = d[\([m3xyADU, 1]\)]; 
    m3y = d[\([m3xyADU, 2]\)]; If[m3 > 10000, f = Append[f, {m3x, m3y, m3}]]; 
    st = 0; temporario = 0; ciclos1 = 0; m1xyADU = ordd; m2ADU = m2xyADU; 
    val382 = IntegerPart[\((matx - 1)\)/2];\), "\[IndentingNewLine]", 
    \(While[st == 0 && ciclos1 < 100, orddif = m2xyADU - ordd; 
      tempor = m2xyADU; u = 0; chave = Abs[val382 - Abs[orddif]]; ordem = 0; 
      teste = 0; 
      If[d[\([ordd + 2*orddif, 3]\)] > 10000 && 
          d[\([ordd + 2*orddif, 3]\)] > u, u = d[\([ordd + 2*orddif, 3]\)]; 
        ordem = ordd + 2*orddif]; \[IndentingNewLine]If\ [chave == 1, 
        teste = orddif - val382; 
        If[teste \[Equal] 1 || teste \[Equal] \(-matx\) + 2, 
          If[d[\([ordd + 2*orddif - 1, 3]\)] > 10000 && 
              d[\([ordd + 2*orddif - 1, 3]\)] > u, 
            u = d[\([ordd + 2*orddif - 1, 3]\)]; 
            ordem = ordd + 2*orddif - 1]; 
          If[d[\([ordd + orddif + 1, 3]\)] > 10000 && 
              d[\([ordd + orddif + 1, 3]\)] > u, 
            u = d[\([ordd + orddif + 1, 3]\)]; ordem = ordd + orddif + 1], 
          If[d[\([ordd + 2*orddif + 1, 3]\)] > 10000 && 
              d[\([ordd + 2*orddif + 1, 3]\)] > u, 
            u = d[\([ordd + 2*orddif + 1, 3]\)]; 
            ordem = ordd + 2*orddif + 1]; 
          If[d[\([ordd + orddif - 1, 3]\)] > 10000 && 
              d[\([ordd + orddif - 1, 3]\)] > u, 
            u = d[\([ordd + orddif - 1, 3]\)]; ordem = ordd + orddif - 1]], 
        If[chave \[Equal] 0, 
          If[d[\([ordd + 2*orddif + 1, 3]\)] > 10000 && 
              d[\([ordd + 2*orddif + 1, 3]\)] > u, 
            u = d[\([ordd + 2*orddif + 1, 3]\)]; 
            ordem = ordd + 2*orddif + 1]; 
          If[d[\([ordd + 2*orddif - 1, 3]\)] > 10000 && 
              d[\([ordd + 2*orddif - 1, 3]\)] > u, 
            u = d[\([ordd + 2*orddif - 1, 3]\)]; 
            ordem = ordd + 2*orddif - 1], 
          If[d[\([tempor + \((val382 + 1)\)*orddif, 3]\)] > 10000 && 
              d[\([tempor + \((val382 + 1)\)*orddif, 3]\)] > u, 
            u = d[\([tempor + \((val382 + 1)\)*orddif, 3]\)]; 
            ordem = tempor + \((val382 + 1)\)*orddif]; 
          If[d[\([tempor - \((val382 - 1)\)*orddif, 3]\)] > 10000 && 
              d[\([tempor - \((val382 - 1)\)*orddif, 3]\)] > u, 
            u = d[\([tempor - \((val382 - 1)\)*orddif, 3]\)]; 
            ordem = tempor - \((val382 - 1)\)*orddif]]]; m2 = u; 
      m2x = d[\([ordem, 1]\)]; m2y = d[\([ordem, 2]\)]; m2xyADU = ordem; 
      ordd = tempor; ciclos1 = ciclos1 + 1; 
      If[m2 > 10000, c = Append[c, {m2x, m2y, m2}], st = 1]]; st = 0; 
    ciclos2 = 0; orddif = 0; temporario = 0; ordd = m1xyADU; 
    m3ADU = m3xyADU;\), "\[IndentingNewLine]", 
    \(While[st == 0 && ciclos2 < 100, orddif = m3xyADU - ordd; 
      temporario = m3xyADU; u = 0; chave = Abs[val382 - Abs[orddif]]; 
      ordem = 0; teste = 0; 
      If[d[\([ordd + 2*orddif, 3]\)] > 10000 && 
          d[\([ordd + 2*orddif, 3]\)] > u, u = d[\([ordd + 2*orddif, 3]\)]; 
        ordem = ordd + 2*orddif]; \[IndentingNewLine]If\ [chave == 1, 
        teste = orddif - val382; 
        If[teste \[Equal] 1 || teste \[Equal] \(-matx\) + 2, 
          If[d[\([ordd + 2*orddif - 1, 3]\)] > 10000 && 
              d[\([ordd + 2*orddif - 1, 3]\)] > u, 
            u = d[\([ordd + 2*orddif - 1, 3]\)]; 
            ordem = ordd + 2*orddif - 1]; 
          If[d[\([ordd + orddif + 1, 3]\)] > 10000 && 
              d[\([ordd + orddif + 1, 3]\)] > u, 
            u = d[\([ordd + orddif + 1, 3]\)]; ordem = ordd + orddif + 1], 
          If[d[\([ordd + 2*orddif + 1, 3]\)] > 10000 && 
              d[\([ordd + 2*orddif + 1, 3]\)] > u, 
            u = d[\([ordd + 2*orddif + 1, 3]\)]; 
            ordem = ordd + 2*orddif + 1]; 
          If[d[\([ordd + orddif - 1, 3]\)] > 10000 && 
              d[\([ordd + orddif - 1, 3]\)] > u, 
            u = d[\([ordd + orddif - 1, 3]\)]; ordem = ordd + orddif - 1]], 
        If[chave \[Equal] 0, 
          If[d[\([ordd + 2*orddif + 1, 3]\)] > 10000 && 
              d[\([ordd + 2*orddif + 1, 3]\)] > u, 
            u = d[\([ordd + 2*orddif + 1, 3]\)]; 
            ordem = ordd + 2*orddif + 1]; 
          If[d[\([ordd + 2*orddif - 1, 3]\)] > 10000 && 
              d[\([ordd + 2*orddif - 1, 3]\)] > u, 
            u = d[\([ordd + 2*orddif - 1, 3]\)]; 
            ordem = ordd + 2*orddif - 1], 
          If[d[\([temporario + \((val382 + 1)\)*orddif, 3]\)] > 10000 && 
              d[\([temporario + \((val382 + 1)\)*orddif, 3]\)] > u, 
            u = d[\([temporario + \((val382 + 1)\)*orddif, 3]\)]; 
            ordem = temporario + \((val382 + 1)\)*orddif]; 
          If[d[\([temporario - \((val382 - 1)\)*orddif, 3]\)] > 10000 && 
              d[\([temporario - \((val382 - 1)\)*orddif, 3]\)] > u, 
            u = d[\([temporario - \((val382 - 1)\)*orddif, 3]\)]; 
            ordem = temporario - \((val382 - 1)\)*orddif]]]; m3 = u; 
      m3x = d[\([ordem, 1]\)]; m3y = d[\([ordem, 2]\)]; m3xyADU = ordem; 
      ordd = temporario; ciclos2 = ciclos2 + 1; 
      If[m3 > 10000, f = Append[f, {m3x, m3y, m3}], st = 1]]; l = 1; e = {}; 
    n2 = Length[c]; 
    While[l \[LessEqual] n2, e = Append[e, {c[\([l, 1]\)], c[\([l, 2]\)]}]; 
      l = l + 1]; 
    ListPlot[e, PlotRange \[Rule] All, PlotStyle -> PointSize[0.013]]; \ 
    Print["\<Cycles of vector c, which includes the peak:  \>", ciclos1 + 1]; 
    Print["\<Coordinates of the peak (x,y):  \>", 
      d[\([m1xyADU, 1]\)], "\<   \>", d[\([m1xyADU, 2]\)]]; 
    Print["\<Coordinates of the 2nd maximum (x,y):  \>", 
      d[\([m2ADU, 1]\)], "\<   \>", d[\([m2ADU, 2]\)]]; 
    Print["\< Vector C:  \>", c]; l = 1; e = {}; n2 = Length[f]; 
    While[l \[LessEqual] n2, e = Append[e, {f[\([l, 1]\)], f[\([l, 2]\)]}]; 
      l = l + 1]; 
    ListPlot[e, PlotRange \[Rule] All, PlotStyle -> PointSize[0.013]]; 
    Print["\<Cycles of vector f, which does not include the peak:  \>", 
      ciclos2]; 
    Print["\<Coordinates of the 3rd maximum (x,y):  \>", 
      d[\([m3ADU, 1]\)], "\<   \>", d[\([m3ADU, 2]\)]]; 
    Print["\< Vector F:  \>", f];\)}], "Input"],

Cell[BoxData[
    \(\(\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\
\( (*\ Routine\ 4\ \((Cycles)\)\  - \ 
        Eventually\ redefining\ vector\ c\ and/or\ vector\ f; \ 
      if\ this\ was\ the\ case, \ 
      must\ go\ back\ to\ Routine\ 3\ *) \)\(\[IndentingNewLine]\)\(\
\[IndentingNewLine]\)\(\[IndentingNewLine]\)\)\)], "Input"],

Cell[BoxData[
    \(lma = 
      Input["\<In the case of vector C cycles reaching 101, please say in \
which point you want to stop (number) or, if all is ok, write the number \
0.\>"]; \ If[lma \[NotEqual] 0, xcycl = {}; l = 1; 
      While[l < lma + 1, xcycl = Append[xcycl, c[\([l]\)]]; l = l + 1]; 
      Print["\<New Vector C:   \>", c = xcycl]]; 
    mma = Input["\<In the case of vector F cycles reaching 100, please say in \
which point you want to stop (number) or, if all is ok, write the number \
0.\>"]; \ If[mma \[NotEqual] 0, ycycl = {}; m = 1; 
      While[m < mma + 1, ycycl = Append[ycycl, f[\([m]\)]]; m = m + 1]; 
      Print["\<New Vector F:   \>", f = ycycl]];\)], "Input"],

Cell[BoxData[
    \(\(\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\
\( (*\ Routine\ 5\ \((Path)\)\  - \ 
        edit\ "\<h2=Join[g,c]\>"\ if\ necessary; \ and/or, \ if\ necessary, \ 
      BEFORE\ the\ full\ line\ "\<While...e=Append...l=1;\>"\ \(put : \ \
"\<e=h2[[Ordering[h2[[All,2]]]]];h2=e;e={};\>"\)\ *) \)\(\ \)\(\
\[IndentingNewLine]\)\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\)\)], \
"Input"],

Cell[BoxData[
    \(compf = Length[f]; k = 0; g = {}; i = 0; 
    While[k < compf, i = f[\([compf - k]\)]; g = Append[g, i]; i = 0; 
      k = k + 1]; h2 = Join[g, c]; Print["\<Vector h:   \>", h2]; l = 1; 
    hl3 = {}; n = Length[h2]; e = {}; n2 = Length[h2]; 
    While[l \[LessEqual] n2, e = Append[e, {h2[\([l, 1]\)], h2[\([l, 2]\)]}]; 
      l = l + 1]; l = 1; 
    While[l \[LessEqual] n, hl3 = Append[hl3, h2[\([l, 3]\)]]; l = l + 1]; 
    ListPlot[hl3, PlotRange \[Rule] All, PlotStyle -> PointSize[0.013], 
      Frame -> True, Axes -> False]; 
    el1 = ListPlot[e, PlotRange \[Rule] All, PlotStyle -> PointSize[0.013]]; 
    el2 = ContourGraphics[a, 
        PlotRange -> {{nx1, nx2}, {ny1, ny2}, {0, topgr}}]; Show[el2]; 
    Show[el2, el1]; 
    ql2 = ContourGraphics[d1, 
        PlotRange -> {{nx1, nx2}, {ny1, ny2}, {0, topgr}}]; Show[ql2]; 
    Show[ql2, el1];\)], "Input"],

Cell[BoxData[
    \(\(\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\
\(\(Section\  - \ Lobe\ Fit\ \((if\ necessary)\); \ 
    Lobe\ 2\)\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\(\
\[IndentingNewLine]\)
    \)\)\)], "Input"],

Cell[BoxData[
    \( (*\ If\ there\ is\ a\ second\ Lobe, \ this\ section\ must\ be\ run; \ 
      otherwise, \ 
      jump\ to\ the\ "\<Section - combining lobes\>"\ at\ the\ end; \ 
      we\ now\ save\ the\ previous\ lobe\ into\ vector\ h2\ *) \)], "Input"],

Cell[BoxData[
    \(\(\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\
\( (*\ Routine\ 1\  - \ 
        Initial\ look\ at\ the\ data\ *) \)\(\[IndentingNewLine]\)\(\
\[IndentingNewLine]\)\(\[IndentingNewLine]\)\)\)], "Input"],

Cell[BoxData[{
    \(b = Transpose[a]; 
    ax1 = Input["\<Please insert the limits of the rectangle you want to \
'remove' from the data as follows:  x1?\>"]; ax2 = Input["\<x2?\>"]; 
    ay1 = Input["\<y1?\>"]; 
    ay2 = Input["\<y2?\>"]; \ \ Print["\<You defined the following EXTRACTION \
square: x1= \>", ax1, "\<, x2= \>", ax2, "\<, y1= \>", \ 
      ay1, \ "\<, y2= \>", \ ay2]; x = ax1; y = ay1; 
    While[y < ay2 + 1, \ 
      While[x < ax2 + 1, \ b[\([x, y]\)] = 100; x = x + 1]; x = ax1; 
      y = y + 1];\), "\[IndentingNewLine]", 
    \(al2 = b; m = Max[al2]; 
    Print["\<Peak value of Lobe 2 (ADU):  \>", m];\)}], "Input"],

Cell[BoxData[
    \(\(\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\( (*\ 
      Repeat\ here\ the\ maximum\ \((ADU)\) you\ used\ in\ the\ final\ 3  
        D\ plot\ of\ the\ main\ part; \ 
      the\ rest\ are\ what\ you\ already\ defined; \ Routine\ 2\ is, \ 
      thus, \ skipped\ here\ *) \)\)\)], "Input"],

Cell[BoxData[
    \(\(\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\
\( (*\ Routine\ 3\ \((Main)\)\  - \ 
        Organizing\ the\ data\ into\ 2  x2\ pixels, \ 
      preparing\ vectors\ c\ and\ f\ for\ analysis; \ be\ patient, \ 
      it\ might\ take\ a\ few\ \(minutes!\)\ *) \)\(\[IndentingNewLine]\)\(\
\[IndentingNewLine]\)\(\[IndentingNewLine]\)\)\)], "Input"],

Cell[BoxData[{
    \(x = 1; y = 1; mx = 0; my = 0; 
    While[y < maty + 1, \ 
      While[x < matx + 1, \ 
        If[b[\([x, y]\)] == m, mx = x; my = y; x = matx + 1; y = maty + 1, 
          x = x + 1, Print["\<erro\>"]]]; x = 1; y = y + 1]; \ 
    topgr = m + 5000; x = mx - 1; y = my - 1; i = 0; j = 0; u = 100; 
    While[y < my + 2, 
      While[x < mx + 2, 
        If[b[\([x, y]\)] > u, u = b[\([x, y]\)]; i = x; j = y]; x = x + 1]; 
      y = y + 2; x = mx - 1]; 
    If[b[\([mx - 1, my]\)] > u, u = b[\([mx - 1, my]\)]; i = mx - 1; 
      j = my]; \ 
    If[b[\([mx + 1, my]\)] > u, u = b[\([mx + 1, my]\)]; i = mx + 1; j = my]; 
    m2 = u; \ m2x = i; m2y = j; esq = 0; drt = 0; cim = 0; bxo = 0; dx = 0; 
    dy = 0; dm = 0; es = 0; d = {}; e = {}; i = 0; j = 0; 
    If[Abs[mx - m2x] \[Equal] 1, i = 1, i = 0]; \ 
    If[Abs[my - m2y] \[Equal] 1, j = 1, j = 0]; 
    If[i + j \[Equal] 2, 
      If[mx > m2x && m2y > my, dx = mx - 0.5; dy = my + 0.5; 
        dm = N[Mean[{m, m2, b[\([mx - 1, my]\)], b[\([mx, my + 1]\)]}]]; 
        es = N[StandardDeviation[{m, m2, b[\([mx - 1, my]\)], 
                b[\([mx, my + 1]\)]}]]; d = Append[d, {dx, dy, dm}]; 
        e = Append[e, {dx, dy, es}], 
        If[m2x > mx && m2y > my, dx = mx + 0.5; dy = my + 0.5; 
          dm = N[Mean[{m, m2, b[\([mx + 1, my]\)], b[\([mx, my + 1]\)]}]]; 
          es = N[StandardDeviation[{m, m2, b[\([mx + 1, my]\)], 
                  b[\([mx, my + 1]\)]}]]; d = Append[d, {dx, dy, dm}]; 
          e = Append[e, {dx, dy, es}], 
          If[m2x > mx && my > m2y, dx = mx + 0.5; dy = my - 0.5; 
            dm = N[Mean[{m, m2, b[\([mx + 1, my]\)], b[\([mx, my - 1]\)]}]]; 
            es = N[StandardDeviation[{m, m2, b[\([mx + 1, my]\)], 
                    b[\([mx, my - 1]\)]}]]; d = Append[d, {dx, dy, dm}]; 
            e = Append[e, {dx, dy, es}], 
            If[mx > m2x && my > m2y, dx = mx - 0.5; dy = my - 0.5; 
              dm = N[Mean[{m, m2, b[\([mx - 1, my]\)], 
                      b[\([mx, my - 1]\)]}]]; 
              es = N[StandardDeviation[{m, m2, b[\([mx - 1, my]\)], 
                      b[\([mx, my - 1]\)]}]]; d = Append[d, {dx, dy, dm}]; 
              e = Append[e, {dx, dy, es}]]]]], 
      If[m2x == mx && m2y > my, 
        esq = Max[b[\([mx - 1, my + 1]\)], b[\([mx - 1, my]\)]]; 
        dir = Max[b[\([mx + 1, my + 1]\)], b[\([mx + 1, my]\)]]; 
        If[esq > dir, dx = mx - 0.5; dy = my + 0.5; 
          dm = N[Mean[{m, m2, b[\([mx - 1, my]\)], 
                  b[\([mx - 1, my + 1]\)]}]]; 
          es = N[StandardDeviation[{m, m2, b[\([mx - 1, my]\)], 
                  b[\([mx - 1, my + 1]\)]}]]; d = Append[d, {dx, dy, dm}]; 
          e = Append[e, {dx, dy, es}], dx = mx + 0.5; dy = my + 0.5; 
          dm = N[Mean[{m, m2, b[\([mx + 1, my]\)], 
                  b[\([mx + 1, my + 1]\)]}]]; 
          es = N[StandardDeviation[{m, m2, b[\([mx + 1, my]\)], 
                  b[\([mx + 1, my + 1]\)]}]]; d = Append[d, {dx, dy, dm}]; 
          e = Append[e, {dx, dy, es}]]]; 
      If[m2x == mx && m2y < my, 
        esq = Max[b[\([mx - 1, my - 1]\)], b[\([mx - 1, my]\)]]; 
        dir = Max[b[\([mx + 1, my - 1]\)], b[\([mx + 1, my]\)]]; 
        If[esq > dir, dx = mx - 0.5; dy = my - 0.5; 
          dm = N[Mean[{m, m2, b[\([mx - 1, my]\)], 
                  b[\([mx - 1, my - 1]\)]}]]; 
          es = N[StandardDeviation[{m, m2, b[\([mx - 1, my]\)], 
                  b[\([mx - 1, my - 1]\)]}]]; d = Append[d, {dx, dy, dm}]; 
          e = Append[e, {dx, dy, es}], dx = mx + 0.5; dy = my - 0.5; 
          dm = N[Mean[{m, m2, b[\([mx + 1, my]\)], 
                  b[\([mx + 1, my - 1]\)]}]]; 
          es = N[StandardDeviation[{m, m2, b[\([mx + 1, my]\)], 
                  b[\([mx + 1, my - 1]\)]}]]; d = Append[d, {dx, dy, dm}]; 
          e = Append[e, {dx, dy, es}]]]; 
      If[m2y == my && m2x < mx, 
        cim = Max[b[\([mx - 1, my + 1]\)], b[\([mx, my + 1]\)]]; 
        bxo = Max[b[\([mx - 1, my - 1]\)], b[\([mx, my - 1]\)]]; 
        If[cim > bxo, dx = mx - 0.5; dy = my + 0.5; 
          dm = N[Mean[{m, m2, b[\([mx - 1, my + 1]\)], 
                  b[\([mx, my + 1]\)]}]]; 
          es = N[StandardDeviation[{m, m2, b[\([mx - 1, my + 1]\)], 
                  b[\([mx, my + 1]\)]}]]; d = Append[d, {dx, dy, dm}]; 
          e = Append[e, {dx, dy, es}], dx = mx - 0.5; dy = my - 0.5; 
          dm = N[Mean[{m, m2, b[\([mx - 1, my - 1]\)], 
                  b[\([mx, my - 1]\)]}]]; 
          es = N[StandardDeviation[{m, m2, b[\([mx - 1, my - 1]\)], 
                  b[\([mx, my - 1]\)]}]]; d = Append[d, {dx, dy, dm}]; 
          e = Append[e, {dx, dy, es}]]]; 
      If[m2y == my && m2x > mx, 
        cim = Max[b[\([mx + 1, my + 1]\)], b[\([mx, my + 1]\)]]; 
        bxo = Max[b[\([mx + 1, my - 1]\)], b[\([mx, my - 1]\)]]; 
        If[cim > bxo, dx = mx + 0.5; dy = my + 0.5; 
          dm = N[Mean[{m, m2, b[\([mx + 1, my + 1]\)], 
                  b[\([mx, my + 1]\)]}]]; 
          es = N[StandardDeviation[{m, m2, b[\([mx + 1, my + 1]\)], 
                  b[\([mx, my + 1]\)]}]]; d = Append[d, {dx, dy, dm}]; 
          e = Append[e, {dx, dy, es}], dx = mx + 0.5; dy = my - 0.5; 
          dm = N[Mean[{m, m2, b[\([mx + 1, my - 1]\)], 
                  b[\([mx, my - 1]\)]}]]; 
          es = N[StandardDeviation[{m, m2, b[\([mx + 1, my - 1]\)], 
                  b[\([mx, my - 1]\)]}]]; d = Append[d, {dx, dy, dm}]; 
          e = Append[e, {dx, dy, es}]]]]; mx = dx; my = dy; m = dm; ordd = 0; 
    ul = 0; ur = 0; dl = 0; dr = 0; i = dx - 0.5; j = dy - 0.5; dx = 0; 
    dy = 0; dm = 0; es = 0; xlo = 1; xhi = matx; ylo = 1; yhi = maty; d = {}; 
    e = {}; d1 = {}; \ d2 = {}; \ 
    If[EvenQ[IntegerPart[j]] \[Equal] True, ylo = 2; yhi = maty - 1]; 
    If[EvenQ[IntegerPart[i]] \[Equal] False, xhi = matx - 1, xlo = 2]; 
    y = ylo; v = yhi; x = xlo; l = xhi; 
    While[y < v + 1, 
      While[x < l + 1, dl = b[\([x, y]\)]; dr = b[\([x + 1, y]\)]; 
        ul = b[\([x, y + 1]\)]; ur = b[\([x + 1, y + 1]\)]; dx = x + 0.5; 
        dy = y + 0.5; dm = N[Mean[{dl, dr, ul, ur}]]; 
        es = N[StandardDeviation[{dl, dr, ul, ur}]]; 
        d = Append[d, {dx, dy, dm}]; d2 = Append[d2, dm]; 
        d2 = Append[d2, dm]; 
        If[dx == mx && dy \[Equal] my, ordd = Length[d]]; 
        e = Append[e, {dx, dy, es}]; x = x + 2]; x = xlo; 
      d1 = Append[d1, d2]; d1 = Append[d1, d2]; d2 = {}; y = y + 2]; 
    d3 = Transpose[d1]; c = {{mx, my, m}}; k = 0; l = 0; m2xyADU = 0; 
    u = 10001; ordem = ordd - IntegerPart[\((matx + 3)\)/2]; 
    While[l < 2, 
      While[k < 3, ordem = ordem + 1; 
        If[d[\([ordem, 3]\)] > 10000 && d[\([ordem, 3]\)] > u, 
          u = d[\([ordem, 3]\)]; m2xyADU = ordem]; k = k + 1]; k = 0; 
      ordem = ordem + matx - 4; l = l + 1]; ordem = ordd - 3; 
    While[k < 2, ordem = ordem + 2; 
      If[d[\([ordem, 3]\)] > 10000 && d[\([ordem, 3]\)] > u, 
        u = d[\([ordem, 3]\)]; m2xyADU = ordem]; k = k + 1]; m2 = u; 
    m2x = d[\([m2xyADU, 1]\)]; m2y = d[\([m2xyADU, 2]\)]; 
    If[m2 > 10000, c = Append[c, {m2x, m2y, m2}]]; k = 0; l = 0; m3xyADU = 0; 
    u = 10001; ordem = ordd - IntegerPart[\((matx + 3)\)/2]; f = {}; 
    While[l < 2, 
      While[k < 3, ordem = ordem + 1; 
        If[d[\([ordem, 3]\)] > 10000 && d[\([ordem, 3]\)] > u && 
            d[\([ordem, 1]\)] \[NotEqual] m2x && 
            d[\([ordem, 2]\)] \[NotEqual] m2y, u = d[\([ordem, 3]\)]; 
          m3xyADU = ordem]; k = k + 1]; k = 0; ordem = ordem + matx - 4; 
      l = l + 1]; ordem = ordd - 3; 
    While[k < 2, ordem = ordem + 2; 
      If[d[\([ordem, 3]\)] > 10000 && d[\([ordem, 3]\)] > u && 
          d[\([ordem, 1]\)] \[NotEqual] m2x && 
          d[\([ordem, 2]\)] \[NotEqual] m2y, u = d[\([ordem, 3]\)]; 
        m3xyADU = ordem]; k = k + 1]; m3 = u; m3x = d[\([m3xyADU, 1]\)]; 
    m3y = d[\([m3xyADU, 2]\)]; If[m3 > 10000, f = Append[f, {m3x, m3y, m3}]]; 
    st = 0; temporario = 0; ciclos1 = 0; m1xyADU = ordd; m2ADU = m2xyADU; 
    val382 = IntegerPart[\((matx - 1)\)/2];\), "\[IndentingNewLine]", 
    \(While[st == 0 && ciclos1 < 100, orddif = m2xyADU - ordd; 
      tempor = m2xyADU; u = 0; chave = Abs[val382 - Abs[orddif]]; ordem = 0; 
      teste = 0; 
      If[d[\([ordd + 2*orddif, 3]\)] > 10000 && 
          d[\([ordd + 2*orddif, 3]\)] > u, u = d[\([ordd + 2*orddif, 3]\)]; 
        ordem = ordd + 2*orddif]; \[IndentingNewLine]If\ [chave == 1, 
        teste = orddif - val382; 
        If[teste \[Equal] 1 || teste \[Equal] \(-matx\) + 2, 
          If[d[\([ordd + 2*orddif - 1, 3]\)] > 10000 && 
              d[\([ordd + 2*orddif - 1, 3]\)] > u, 
            u = d[\([ordd + 2*orddif - 1, 3]\)]; 
            ordem = ordd + 2*orddif - 1]; 
          If[d[\([ordd + orddif + 1, 3]\)] > 10000 && 
              d[\([ordd + orddif + 1, 3]\)] > u, 
            u = d[\([ordd + orddif + 1, 3]\)]; ordem = ordd + orddif + 1], 
          If[d[\([ordd + 2*orddif + 1, 3]\)] > 10000 && 
              d[\([ordd + 2*orddif + 1, 3]\)] > u, 
            u = d[\([ordd + 2*orddif + 1, 3]\)]; 
            ordem = ordd + 2*orddif + 1]; 
          If[d[\([ordd + orddif - 1, 3]\)] > 10000 && 
              d[\([ordd + orddif - 1, 3]\)] > u, 
            u = d[\([ordd + orddif - 1, 3]\)]; ordem = ordd + orddif - 1]], 
        If[chave \[Equal] 0, 
          If[d[\([ordd + 2*orddif + 1, 3]\)] > 10000 && 
              d[\([ordd + 2*orddif + 1, 3]\)] > u, 
            u = d[\([ordd + 2*orddif + 1, 3]\)]; 
            ordem = ordd + 2*orddif + 1]; 
          If[d[\([ordd + 2*orddif - 1, 3]\)] > 10000 && 
              d[\([ordd + 2*orddif - 1, 3]\)] > u, 
            u = d[\([ordd + 2*orddif - 1, 3]\)]; 
            ordem = ordd + 2*orddif - 1], 
          If[d[\([tempor + \((val382 + 1)\)*orddif, 3]\)] > 10000 && 
              d[\([tempor + \((val382 + 1)\)*orddif, 3]\)] > u, 
            u = d[\([tempor + \((val382 + 1)\)*orddif, 3]\)]; 
            ordem = tempor + \((val382 + 1)\)*orddif]; 
          If[d[\([tempor - \((val382 - 1)\)*orddif, 3]\)] > 10000 && 
              d[\([tempor - \((val382 - 1)\)*orddif, 3]\)] > u, 
            u = d[\([tempor - \((val382 - 1)\)*orddif, 3]\)]; 
            ordem = tempor - \((val382 - 1)\)*orddif]]]; m2 = u; 
      m2x = d[\([ordem, 1]\)]; m2y = d[\([ordem, 2]\)]; m2xyADU = ordem; 
      ordd = tempor; ciclos1 = ciclos1 + 1; 
      If[m2 > 10000, c = Append[c, {m2x, m2y, m2}], st = 1]]; st = 0; 
    ciclos2 = 0; orddif = 0; temporario = 0; ordd = m1xyADU; 
    m3ADU = m3xyADU;\), "\[IndentingNewLine]", 
    \(While[st == 0 && ciclos2 < 100, orddif = m3xyADU - ordd; 
      temporario = m3xyADU; u = 0; chave = Abs[val382 - Abs[orddif]]; 
      ordem = 0; teste = 0; 
      If[d[\([ordd + 2*orddif, 3]\)] > 10000 && 
          d[\([ordd + 2*orddif, 3]\)] > u, u = d[\([ordd + 2*orddif, 3]\)]; 
        ordem = ordd + 2*orddif]; \[IndentingNewLine]If\ [chave == 1, 
        teste = orddif - val382; 
        If[teste \[Equal] 1 || teste \[Equal] \(-matx\) + 2, 
          If[d[\([ordd + 2*orddif - 1, 3]\)] > 10000 && 
              d[\([ordd + 2*orddif - 1, 3]\)] > u, 
            u = d[\([ordd + 2*orddif - 1, 3]\)]; 
            ordem = ordd + 2*orddif - 1]; 
          If[d[\([ordd + orddif + 1, 3]\)] > 10000 && 
              d[\([ordd + orddif + 1, 3]\)] > u, 
            u = d[\([ordd + orddif + 1, 3]\)]; ordem = ordd + orddif + 1], 
          If[d[\([ordd + 2*orddif + 1, 3]\)] > 10000 && 
              d[\([ordd + 2*orddif + 1, 3]\)] > u, 
            u = d[\([ordd + 2*orddif + 1, 3]\)]; 
            ordem = ordd + 2*orddif + 1]; 
          If[d[\([ordd + orddif - 1, 3]\)] > 10000 && 
              d[\([ordd + orddif - 1, 3]\)] > u, 
            u = d[\([ordd + orddif - 1, 3]\)]; ordem = ordd + orddif - 1]], 
        If[chave \[Equal] 0, 
          If[d[\([ordd + 2*orddif + 1, 3]\)] > 10000 && 
              d[\([ordd + 2*orddif + 1, 3]\)] > u, 
            u = d[\([ordd + 2*orddif + 1, 3]\)]; 
            ordem = ordd + 2*orddif + 1]; 
          If[d[\([ordd + 2*orddif - 1, 3]\)] > 10000 && 
              d[\([ordd + 2*orddif - 1, 3]\)] > u, 
            u = d[\([ordd + 2*orddif - 1, 3]\)]; 
            ordem = ordd + 2*orddif - 1], 
          If[d[\([temporario + \((val382 + 1)\)*orddif, 3]\)] > 10000 && 
              d[\([temporario + \((val382 + 1)\)*orddif, 3]\)] > u, 
            u = d[\([temporario + \((val382 + 1)\)*orddif, 3]\)]; 
            ordem = temporario + \((val382 + 1)\)*orddif]; 
          If[d[\([temporario - \((val382 - 1)\)*orddif, 3]\)] > 10000 && 
              d[\([temporario - \((val382 - 1)\)*orddif, 3]\)] > u, 
            u = d[\([temporario - \((val382 - 1)\)*orddif, 3]\)]; 
            ordem = temporario - \((val382 - 1)\)*orddif]]]; m3 = u; 
      m3x = d[\([ordem, 1]\)]; m3y = d[\([ordem, 2]\)]; m3xyADU = ordem; 
      ordd = temporario; ciclos2 = ciclos2 + 1; 
      If[m3 > 10000, f = Append[f, {m3x, m3y, m3}], st = 1]]; l = 1; e = {}; 
    n2 = Length[c]; 
    While[l \[LessEqual] n2, e = Append[e, {c[\([l, 1]\)], c[\([l, 2]\)]}]; 
      l = l + 1]; 
    ListPlot[e, PlotRange \[Rule] All, PlotStyle -> PointSize[0.013]]; \ 
    Print["\<Cycles of vector c, which includes the peak:  \>", ciclos1 + 1]; 
    Print["\<Coordinates of the peak (x,y):  \>", 
      d[\([m1xyADU, 1]\)], "\<   \>", d[\([m1xyADU, 2]\)]]; 
    Print["\<Coordinates of the 2nd maximum (x,y):  \>", 
      d[\([m2ADU, 1]\)], "\<   \>", d[\([m2ADU, 2]\)]]; 
    Print["\< Vector C:  \>", c]; l = 1; e = {}; n2 = Length[f]; 
    While[l \[LessEqual] n2, e = Append[e, {f[\([l, 1]\)], f[\([l, 2]\)]}]; 
      l = l + 1]; 
    ListPlot[e, PlotRange \[Rule] All, PlotStyle -> PointSize[0.013]]; 
    Print["\<Cycles of vector f, which does not include the peak:  \>", 
      ciclos2]; 
    Print["\<Coordinates of the 3rd maximum (x,y):  \>", 
      d[\([m3ADU, 1]\)], "\<   \>", d[\([m3ADU, 2]\)]]; 
    Print["\< Vector F:  \>", f];\)}], "Input"],

Cell[BoxData[
    \(\(\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\
\( (*\ Routine\ 4\ \((Cycles)\)\  - \ 
        Eventually\ redefining\ vector\ c\ and/or\ vector\ f; \ 
      if\ this\ was\ the\ case, \ 
      must\ go\ back\ to\ Routine\ 3\ *) \)\(\[IndentingNewLine]\)\(\
\[IndentingNewLine]\)\(\[IndentingNewLine]\)\)\)], "Input"],

Cell[BoxData[
    \(lma = 
      Input["\<In the case of vector C cycles reaching 101, please say in \
which point you want to stop (number) or, if all is ok, write the number \
0.\>"]; \ If[lma \[NotEqual] 0, xcycl = {}; l = 1; 
      While[l < lma + 1, xcycl = Append[xcycl, c[\([l]\)]]; l = l + 1]; 
      Print["\<New Vector C:   \>", c = xcycl]]; 
    mma = Input["\<In the case of vector F cycles reaching 100, please say in \
which point you want to stop (number) or, if all is ok, write the number \
0.\>"]; \ If[mma \[NotEqual] 0, ycycl = {}; m = 1; 
      While[m < mma + 1, ycycl = Append[ycycl, f[\([m]\)]]; m = m + 1]; 
      Print["\<New Vector F:   \>", f = ycycl]];\)], "Input"],

Cell[BoxData[
    \(\(\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\
\( (*\ Routine\ 5\ \((Path)\)\  - \ 
        edit\ "\<h4=Join[g,c]\>"\ if\ necessary; \ and/or, \ if\ necessary, \ 
      BEFORE\ the\ full\ line\ "\<While...e=Append...l=1;\>"\ \(put : \ \
"\<e=h4[[Ordering[h4[[All,2]]]]];h4=e;e={};\>"\)\ *) \)\(\ \)\(\
\[IndentingNewLine]\)\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\)\)], \
"Input"],

Cell[BoxData[
    \(compf = Length[f]; k = 0; g = {}; i = 0; 
    While[k < compf, i = f[\([compf - k]\)]; g = Append[g, i]; i = 0; 
      k = k + 1]; h4 = Join[g, c]; Print["\<Vector h:   \>", h4]; l = 1; 
    hl3 = {}; n = Length[h4]; e = {}; n2 = Length[h4]; 
    While[l \[LessEqual] n2, e = Append[e, {h4[\([l, 1]\)], h4[\([l, 2]\)]}]; 
      l = l + 1]; l = 1; 
    While[l \[LessEqual] n, hl3 = Append[hl3, h4[\([l, 3]\)]]; l = l + 1]; 
    ListPlot[hl3, PlotRange \[Rule] All, PlotStyle -> PointSize[0.013], 
      Frame -> True, Axes -> False]; 
    el1 = ListPlot[e, PlotRange \[Rule] All, PlotStyle -> PointSize[0.013]]; 
    el2 = ContourGraphics[a, 
        PlotRange -> {{nx1, nx2}, {ny1, ny2}, {0, topgr}}]; Show[el2]; 
    Show[el2, el1]; 
    ql2 = ContourGraphics[d1, 
        PlotRange -> {{nx1, nx2}, {ny1, ny2}, {0, topgr}}]; Show[ql2]; 
    Show[ql2, el1];\)], "Input"],

Cell[BoxData[
    \(\(\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\( (*\ Now, \ 
      depending\ on\ how\ many\ lobes\ \((one\ or\ two)\)\ to\ combine, \ 
      we\ use\ the\ next\ section\ routine\ *) \)\(\[IndentingNewLine]\)\(\
\[IndentingNewLine]\)\(\[IndentingNewLine]\)\)\)], "Input"],

Cell[BoxData[
    \(\(\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\
\( (*\ Section\  - \ 
        combining\ lobes\ *) \)\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\
\(\[IndentingNewLine]\)\)\)], "Input"],

Cell[BoxData[
    \( (*\ We\ combine\ all\ parts\ in\ what\ follows; \ 
      note\ that\ if\ more\ than\ one\ lobe\ then\ "\<hr=Join[h1,h2]\>" 
          must\ be\ changed\ accordingly\ \((e . 
              g . \ "\<hr=Join[h1,h2,h4]\>")\)\  - \ never\ use\ h3; \ 
      if\ more\ than\ two\ lobes\ use\ h5, h6, \ \(\(etc\)\(.\)\); 
      Sort\ is\ a\ crucial\ command\ on\ the\ routine\ so, \ 
      in\ situations\ where\ the\ path\ is\ clearly\ more\ vertical\ than\ \
horizontal, \ Sort\ WILL\ NOT\ work; \ 
      instead\ of\ h = Sort[hr]\ use\ "\<h=hr[[Ordering[hr[[All,2]]]]]\>"; \ 
      finally, \ 
      adjust\ AspectRatio\ to\ make\ a\ realistic\ plot\ of\ the\ path\ *) \
\)], "Input"],

Cell[BoxData[
    \( (*\ Important : \ 
        in\ the\ event\ of\ needing\ to\ change\ vector\ h\ \((remove\ \
points)\)\ either\ because\ of\ a\  > 
          33  %\ rise/drop\ or\ of\ the\ "\<border effect\>", \ 
      you\ will\ have\ to\ do\ so\ by\ hand\ [
          unless\ you\ prefer\ to\ go\ up\ again\ and\ remove\ on\ C\ and\ F\ \
routine \((s)\)], \ 
      simply\ copying\ and\ pasting\ the\ current\ h\ and\ then\ selecting\ \
the\ points\ you\ want\ to\ keep\ to\ define\ a\ new\ vector\ h; \ 
      after\ that, \ simply\ run\ the\ routine\ again, \ 
      AFTER\ removing\ the\ first\ two\ commands\ \((Join\ and\ Sort)\)\ *) \
\)], "Input"],

Cell[BoxData[
    \(hr = Join[h1, h2]; \ h = Sort[hr]; 
    Print["\<The combined and sorted vector H:  \>", h]; l = 1; w3 = {}; 
    e = {}; n = Length[h]; 
    While[l \[LessEqual] n, w3 = Append[w3, h[\([l, 3]\)]]; 
      e = Append[e, {h[\([l, 1]\)], h[\([l, 2]\)]}]; l = l + 1]; 
    ListPlot[w3, PlotRange \[Rule] All, PlotStyle -> PointSize[0.013], 
      Frame \[Rule] True, Axes \[Rule] False]; 
    ec1 = ListPlot[e, PlotRange \[Rule] All, PlotStyle -> PointSize[0.013], 
        AspectRatio \[Rule] 1]; Show[e2, ec1]; Show[q2, ec1]; 
    Print["\<Maximum 4-pix of vector h:  \>", Max[w3]]; 
    Print["\<Minimum 4-pix of vector h:  \>", Min[w3]]; 
    Print["\<Number of points in vector h:  \>", n]; e1 = ec1;\)], "Input"],

Cell[BoxData[
    \(\(\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\
\( (*\ And\ now\ you\ are\ ready\ to\ do\ the\ seeing\ fit\ in\ Routine\ 6\ \
above\ *) \)\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\(\
\[IndentingNewLine]\)\)\)], "Input"]
},
FrontEndVersion->"5.0 for Microsoft Windows",
ScreenRectangle->{{0, 1920}, {0, 982}},
WindowSize->{660, 766},
WindowMargins->{{Automatic, 214}, {Automatic, 19}}
]

(*******************************************************************
Cached data follows.  If you edit this Notebook file directly, not
using Mathematica, you must remove the line containing CacheID at
the top of  the file.  The cache data will then be recreated when
you save this file from within Mathematica.
*******************************************************************)

(*CellTagsOutline
CellTagsIndex->{}
*)

(*CellTagsIndex
CellTagsIndex->{}
*)

(*NotebookFileOutline
Notebook[{
Cell[1754, 51, 289, 5, 150, "Input"],
Cell[2046, 58, 338, 6, 90, "Input"],
Cell[2387, 66, 209, 4, 50, "Input"],
Cell[2599, 72, 125, 2, 30, "Input"],
Cell[2727, 76, 193, 3, 50, "Input"],
Cell[2923, 81, 247, 4, 150, "Input"],
Cell[3173, 87, 723, 16, 170, "Input"],
Cell[3899, 105, 345, 6, 90, "Input"],
Cell[4247, 113, 301, 5, 150, "Input"],
Cell[4551, 120, 171, 3, 50, "Input"],
Cell[4725, 125, 158, 3, 30, "Input"],
Cell[4886, 130, 391, 6, 190, "Input"],
Cell[5280, 138, 14162, 248, 3250, "Input"],
Cell[19445, 388, 300, 6, 150, "Input"],
Cell[19748, 396, 1108, 19, 390, "Input"],
Cell[20859, 417, 400, 6, 190, "Input"],
Cell[21262, 425, 1047, 19, 310, "Input"],
Cell[22312, 446, 405, 7, 150, "Input"],
Cell[22720, 455, 217, 3, 150, "Input"],
Cell[22940, 460, 78, 1, 30, "Input"],
Cell[23021, 463, 194, 4, 50, "Input"],
Cell[23218, 469, 4276, 76, 1210, "Input"],
Cell[27497, 547, 159, 2, 90, "Input"],
Cell[27659, 551, 2739, 48, 710, "Input"],
Cell[30401, 601, 167, 2, 90, "Input"],
Cell[30571, 605, 759, 13, 210, "Input"],
Cell[31333, 620, 402, 6, 270, "Input"],
Cell[31738, 628, 470, 9, 130, "Input"],
Cell[32211, 639, 247, 4, 150, "Input"],
Cell[32461, 645, 651, 12, 170, "Input"],
Cell[33115, 659, 404, 7, 190, "Input"],
Cell[33522, 668, 391, 6, 190, "Input"],
Cell[33916, 676, 13918, 243, 3210, "Input"],
Cell[47837, 921, 361, 6, 170, "Input"],
Cell[48201, 929, 694, 11, 290, "Input"],
Cell[48898, 942, 432, 7, 190, "Input"],
Cell[49333, 951, 891, 16, 250, "Input"],
Cell[50227, 969, 252, 5, 150, "Input"],
Cell[50482, 976, 259, 4, 70, "Input"],
Cell[50744, 982, 247, 4, 150, "Input"],
Cell[50994, 988, 641, 12, 170, "Input"],
Cell[51638, 1002, 313, 5, 110, "Input"],
Cell[51954, 1009, 391, 6, 190, "Input"],
Cell[52348, 1017, 13918, 243, 3210, "Input"],
Cell[66269, 1262, 361, 6, 170, "Input"],
Cell[66633, 1270, 694, 11, 290, "Input"],
Cell[67330, 1283, 432, 7, 190, "Input"],
Cell[67765, 1292, 891, 16, 250, "Input"],
Cell[68659, 1310, 293, 4, 150, "Input"],
Cell[68955, 1316, 232, 4, 150, "Input"],
Cell[69190, 1322, 700, 12, 190, "Input"],
Cell[69893, 1336, 660, 12, 190, "Input"],
Cell[70556, 1350, 734, 12, 210, "Input"],
Cell[71293, 1364, 269, 4, 150, "Input"]
}
]
*)



(*******************************************************************
End of Mathematica Notebook file.
*******************************************************************)

