From 2f2f8a5a2f510183baba37e8c939c4f4ea214d68 Mon Sep 17 00:00:00 2001
From: Arthur Coolen <coolen@astron.nl>
Date: Mon, 10 Jan 2011 11:11:45 +0000
Subject: [PATCH] Bug1365: renamed Z into H for height values. Added missing
 values out of new ITRF2005 AntennaField config files

---
 MAC/Navigator2/panels/Hardware/Station.pnl    | 118 +--
 .../panels/objects/Hardware/Station_HBA.pnl   |  12 +-
 .../panels/objects/Hardware/Station_LBA.pnl   |  12 +-
 MAC/Navigator2/scripts/readStationConfigs.ctl | 676 ++++++++++--------
 4 files changed, 468 insertions(+), 350 deletions(-)

diff --git a/MAC/Navigator2/panels/Hardware/Station.pnl b/MAC/Navigator2/panels/Hardware/Station.pnl
index 663c5e89a42..689b2f7c0e4 100644
--- a/MAC/Navigator2/panels/Hardware/Station.pnl
+++ b/MAC/Navigator2/panels/Hardware/Station.pnl
@@ -31,17 +31,17 @@ PANEL,-1 -1 1013 750 N "_3DFace" 0
 
     bool fill=true;
     for (int i=0; i<=1;i++) {
-      if (dpConnect(\"updatePositions\",fill,sysName+\"remoteStation.\"+arrayList.text(i)+\".centerOL\",
-                                       sysName+\"remoteStation.\"+arrayList.text(i)+\".centerNB\",
-                                       sysName+\"remoteStation.\"+arrayList.text(i)+\".centerH\",
+      if (dpConnect(\"updatePositions\",fill,sysName+\"remoteStation.\"+arrayList.text(i)+\".centerX\",
+                                       sysName+\"remoteStation.\"+arrayList.text(i)+\".centerY\",
+                                       sysName+\"remoteStation.\"+arrayList.text(i)+\".centerZ\",
                                        sysName+\"remoteStation.N_RSPBoards\",        
                                        sysName+\"remoteStation.N_TBBoards\",
                                        sysName+\"remoteStation.N_LBAS\",
                                        sysName+\"remoteStation.N_HBAS\",
                                        sysName+\"remoteStation.HBA_Split\",         
                                        sysName+\"remoteStation.wide_LBAS\",
-                                       sysName+\"remoteStation.\"+arrayList.text(i)+\".centerOL:_online.._invalid\") == -1) {
-        LOG_DEBUG(\"LOFAR_Netherlands.pnl:main| couldn't connect to \"+sysName+\"remoteStation.\"+arrayList.text(i)+\".centerOL \"+ getLastError());
+                                       sysName+\"remoteStation.\"+arrayList.text(i)+\".centerX:_online.._invalid\") == -1) {
+        LOG_DEBUG(\"LOFAR_Netherlands.pnl:main| couldn't connect to \"+sysName+\"remoteStation.\"+arrayList.text(i)+\".centerX \"+ getLastError());
       }  
 
       if (fill) {
@@ -71,9 +71,9 @@ void doAction(string aDP, string anAction) {
   }
 }
 
-void updatePositions(string dp1, float cOL,
-                     string dp2, float cNB,
-                     string dp3, float cH,
+void updatePositions(string dp1, float cX,
+                     string dp2, float cY,
+                     string dp3, float cZ,
                      string dp4, int nrsp,
                      string dp5, int ntbb,
                      string dp6, int nlbas,
@@ -96,23 +96,23 @@ void updatePositions(string dp1, float cOL,
   HBASplit=hbasplit;         
   WideLBAs=widelbas;
   
-  dyn_string unsortOL=dpNames(sysName+txt+\"*.deltaX;\",\"Antenna\");
-  dyn_string unsortNB=dpNames(sysName+txt+\"*.deltaY;\",\"Antenna\");
-  dyn_string unsortH= dpNames(sysName+txt+\"*.deltaH;\",\"Antenna\");
-  dyn_string OL=unsortOL;
-  dyn_string NB=unsortNB;
-  dyn_string H=unsortH;
+  dyn_string unsortX=dpNames(sysName+txt+\"*.deltaX;\",\"Antenna\");
+  dyn_string unsortY=dpNames(sysName+txt+\"*.deltaY;\",\"Antenna\");
+  dyn_string unsortZ= dpNames(sysName+txt+\"*.deltaZ;\",\"Antenna\");
+  dyn_string X=unsortX;
+  dyn_string Y=unsortY;
+  dyn_string Z=unsortZ;
   
   // since we have Antenna's with 1 digit and 2 digits we need to resort the dynstrings here, otherwise we get them as:
   // HBA0 HBA1 HBA10 HBA11-HBA19 HBA 2 HBA 20 etc
   //
   
-  for (int i=1; i<= dynlen(unsortOL);i++) {
-    string ant = strsplit(unsortOL[i],\":.\" )[2];
+  for (int i=1; i<= dynlen(unsortX);i++) {
+    string ant = strsplit(unsortX[i],\":.\" )[2];
     int idx = substr(ant,3);
-    OL[idx+1]=unsortOL[i];
-    NB[idx+1]=unsortNB[i];
-    H[idx+1]=unsortH[i];         
+    X[idx+1]=unsortX[i];
+    Y[idx+1]=unsortY[i];
+    Z[idx+1]=unsortZ[i];         
   }
 
   
@@ -120,12 +120,12 @@ void updatePositions(string dp1, float cOL,
         
   // found match, save found strings and redraw screen
   
-  centerOL = cOL;
-  centerNB = cNB;
-  centerH  = cH;
-  dpGet(OL,antennaOffsetsOL);
-  dpGet(NB,antennaOffsetsNB);
-  dpGet(H,antennaOffsetsH);
+  centerX = cX;
+  centerY = cY;
+  centerZ  = cZ;
+  dpGet(X,antennaOffsetsX);
+  dpGet(Y,antennaOffsetsY);
+  dpGet(Z,antennaOffsetsZ);
   
 
   
@@ -157,12 +157,12 @@ bool HBASplit=false;
 bool WideLBAs=false;
 
 
-float centerOL;
-float centerNB;
-float centerH;
-dyn_float antennaOffsetsOL;
-dyn_float antennaOffsetsNB;
-dyn_float antennaOffsetsH;
+float centerX;
+float centerY;
+float centerZ;
+dyn_float antennaOffsetsX;
+dyn_float antennaOffsetsY;
+dyn_float antennaOffsetsZ;
 
 string strPanelName;
 string strModuleName;
@@ -207,9 +207,9 @@ void redraw(string mode) {
   }
    
   // determine max values and calculate scaling factors
-  for (int i=1; i<= dynlen(antennaOffsetsOL); i++) { 
-    if ( maxXOffsetValue < fabs(antennaOffsetsOL[i]) ) maxXOffsetValue = fabs(antennaOffsetsOL[i]);
-    if ( maxYOffsetValue < fabs(antennaOffsetsNB[i]) ) maxYOffsetValue = fabs(antennaOffsetsNB[i]);
+  for (int i=1; i<= dynlen(antennaOffsetsX); i++) { 
+    if ( maxXOffsetValue < fabs(antennaOffsetsX[i]) ) maxXOffsetValue = fabs(antennaOffsetsX[i]);
+    if ( maxYOffsetValue < fabs(antennaOffsetsY[i]) ) maxYOffsetValue = fabs(antennaOffsetsY[i]);
   }
 
   LOG_DEBUG(\"Station.pnl:redraw|mainpanel_midX: \"+mainpanel_midX);
@@ -246,7 +246,7 @@ void redraw(string mode) {
   
   //  now start adding symbols to panel
   int ref =   1;
-  for (int i = 1; i <= dynlen(antennaOffsetsOL); i++ ) {
+  for (int i = 1; i <= dynlen(antennaOffsetsX); i++ ) {
     int XRCU;
     int YRCU;
     if (i-1 < NRSP*8/2) {
@@ -266,17 +266,17 @@ void redraw(string mode) {
       dynAppend(g_RCUList,YRCU);
     }
     refNames[ref]=\"ant\"+(ref);
-    xPos_AddSymbol = (mainpanel_midX+shiftFactorX) + (antennaOffsetsOL[i] * expandFactorX);
-    yPos_AddSymbol = (mainpanel_midY+shiftFactorY) - (antennaOffsetsNB[i] * expandFactorY);
+    xPos_AddSymbol = (mainpanel_midX+shiftFactorX) + (antennaOffsetsX[i] * expandFactorX);
+    yPos_AddSymbol = (mainpanel_midY+shiftFactorY) - (antennaOffsetsY[i] * expandFactorY);
       
     if (  addSymbol(  strModuleName,                   // Stay in this modul
                                   \"\",                  // Name of this panel
 		      addPanelName,                    // Panel to add
 		      refNames[ref],                     // Ref of the addedPanel
 		      makeDynString( \"$aNr:\" + (i-1) ,     // Define all $values
-		                     \"$aOL:\" + antennaOffsetsOL[i]  ,    
-		                     \"$aNB:\" + antennaOffsetsNB[i]  ,
-		                     \"$aH:\"  + antennaOffsetsH[i]),                  // of particular addedpanel
+		                     \"$aX:\" + antennaOffsetsX[i]  ,    
+		                     \"$aY:\" + antennaOffsetsY[i]  ,
+		                     \"$aZ:\"  + antennaOffsetsZ[i]),                  // of particular addedpanel
 		      xPos_AddSymbol,                  // Xpos of the AddedSymbol
 		      yPos_AddSymbol,                  // Ypos of the AddedSymbol
 		      0,                               // angle
@@ -302,38 +302,38 @@ void updateField() {
   // Check if the update concerns the current view
   string txt= arrayList.text(arrayList.number());
 
-  dyn_string unsortOL=dpNames(sysName+txt+\"*.deltaX;\",\"Antenna\");
-  dyn_string unsortNB=dpNames(sysName+txt+\"*.deltaY;\",\"Antenna\");
-  dyn_string unsortH= dpNames(sysName+txt+\"*.deltaH;\",\"Antenna\");
-  dyn_string OL=unsortOL;
-  dyn_string NB=unsortNB;
-  dyn_string H=unsortH;
+  dyn_string unsortX=dpNames(sysName+txt+\"*.deltaX;\",\"Antenna\");
+  dyn_string unsortY=dpNames(sysName+txt+\"*.deltaY;\",\"Antenna\");
+  dyn_string unsortZ= dpNames(sysName+txt+\"*.deltaZ;\",\"Antenna\");
+  dyn_string X=unsortX;
+  dyn_string Y=unsortY;
+  dyn_string Z=unsortZ;
                
   
   // since we have Antenna's with 1 digit and 2 digits we need to resort the dynstrings here, otherwise we get them as:
   // HBA0 HBA1 HBA10 HBA11-HBA19 HBA 2 HBA 20 etc
   //
   
-  for (int i=1; i<= dynlen(unsortOL);i++) {
-    string ant = strsplit(unsortOL[i],\":.\" )[2];
+  for (int i=1; i<= dynlen(unsortX);i++) {
+    string ant = strsplit(unsortX[i],\":.\" )[2];
     int idx = substr(ant,3);
-    OL[idx+1]=unsortOL[i];
-    NB[idx+1]=unsortNB[i];
-    H[idx+1]=unsortH[i];         
+    X[idx+1]=unsortX[i];
+    Y[idx+1]=unsortY[i];
+    Z[idx+1]=unsortZ[i];         
   }
   
     
 
   
   string field=sysName+\"remoteStation.\"+txt;
-  if (dpExists(field+\".centerOL:_online.._value\")) {
+  if (dpExists(field+\".centerX:_online.._value\")) {
     // found match, save found strings and redraw screen
-    dpGet(field+\".centerOL:_online.._value\",centerOL,
-          field+\".centerNB:_online.._value\",centerNB,
-          field+\".centerH:_online.._value\",centerH);
-    dpGet(OL,antennaOffsetsOL);          
-    dpGet(NB,antennaOffsetsNB);          
-    dpGet(H,antennaOffsetsH);
+    dpGet(field+\".centerX:_online.._value\",centerX,
+          field+\".centerY:_online.._value\",centerY,
+          field+\".centerZ:_online.._value\",centerZ);
+    dpGet(X,antennaOffsetsX);          
+    dpGet(Y,antennaOffsetsY);          
+    dpGet(Z,antennaOffsetsZ);
     dpGet(sysName+\"remoteStation.N_RSPBoards\",NRSP);         
     dpGet(sysName+\"remoteStation.N_TBBoards\",NTBB);         
     dpGet(sysName+\"remoteStation.N_LBAS\",NLBA);         
@@ -343,7 +343,7 @@ void updateField() {
  
     redraw(txt);
   } else {
-    LOG_ERROR(\"Station.pnl:updateField|Error, couldn't find:\"+field+\".centerOL:_online.._value\");
+    LOG_ERROR(\"Station.pnl:updateField|Error, couldn't find:\"+field+\".centerOX:_online.._value\");
   }
 }
 
diff --git a/MAC/Navigator2/panels/objects/Hardware/Station_HBA.pnl b/MAC/Navigator2/panels/objects/Hardware/Station_HBA.pnl
index b15a4c1429e..fbdd13d059f 100644
--- a/MAC/Navigator2/panels/objects/Hardware/Station_HBA.pnl
+++ b/MAC/Navigator2/panels/objects/Hardware/Station_HBA.pnl
@@ -4,10 +4,10 @@ LANG:1 4 aHBA
 LANG:6 0 
 LANG:30 0 
 PANEL,-1 -1 241 145 N "_3DFace" 4
-"$aH"
-"$aNB"
 "$aNr"
-"$aOL"
+"$aX"
+"$aY"
+"$aZ"
 "main()
 {
   baseDP  = g_currentDatapoint;
@@ -53,9 +53,9 @@ PANEL,-1 -1 241 145 N "_3DFace" 4
   strToolTip += \"---------\";
   strToolTip += \" (HBA\" + curHBA + \")\";
 
-  strToolTip += \"\\n diff from centerOL:\" + $aOL;
-  strToolTip += \"\\n diff from centerNB:\" + $aNB;
-  strToolTip += \"\\n diff from centerH:\"  + $aH;
+  strToolTip += \"\\n diff from centerOL:\" + $aX;
+  strToolTip += \"\\n diff from centerNB:\" + $aY;
+  strToolTip += \"\\n diff from centerH:\"  + $aZ;
     
   antennaHighlight.toolTipText  = strToolTip;
   aNr.toolTipText   = strToolTip;
diff --git a/MAC/Navigator2/panels/objects/Hardware/Station_LBA.pnl b/MAC/Navigator2/panels/objects/Hardware/Station_LBA.pnl
index c4760ff7e12..c4f546bc760 100644
--- a/MAC/Navigator2/panels/objects/Hardware/Station_LBA.pnl
+++ b/MAC/Navigator2/panels/objects/Hardware/Station_LBA.pnl
@@ -4,10 +4,10 @@ LANG:1 4 aLBA
 LANG:6 0 
 LANG:30 0 
 PANEL,-1 -1 241 145 N "_3DFace" 4
-"$aH"
-"$aNB"
 "$aNr"
-"$aOL"
+"$aX"
+"$aY"
+"$aZ"
 "main()
 {
   baseDP  = g_currentDatapoint;
@@ -53,9 +53,9 @@ PANEL,-1 -1 241 145 N "_3DFace" 4
   strToolTip += \"---------\";
   strToolTip += \" (LBA\" + curLBA + \")\";
 
-  strToolTip += \"\\n diff from centerOL:\" + $aOL;
-  strToolTip += \"\\n diff from centerNB:\" + $aNB;
-  strToolTip += \"\\n diff from centerH:\"  + $aH;
+  strToolTip += \"\\n diff from centerOL:\" + $aX;
+  strToolTip += \"\\n diff from centerNB:\" + $aY;
+  strToolTip += \"\\n diff from centerH:\"  + $aZ;
     
   antennaHighlight.toolTipText  = strToolTip;
   aNr.toolTipText   = strToolTip;
diff --git a/MAC/Navigator2/scripts/readStationConfigs.ctl b/MAC/Navigator2/scripts/readStationConfigs.ctl
index 8f955d18fcd..3ea9b661e20 100644
--- a/MAC/Navigator2/scripts/readStationConfigs.ctl
+++ b/MAC/Navigator2/scripts/readStationConfigs.ctl
@@ -1,279 +1,397 @@
-//# readStationConfigs.ctl
-//#
-//#  Copyright (C) 2007-2008
-//#  ASTRON (Netherlands Foundation for Research in Astronomy)
-//#  P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl
-//#
-//#  This program is free software; you can redistribute it and/or modify
-//#  it under the terms of the GNU General Public License as published by
-//#  the Free Software Foundation; either version 2 of the License, or
-//#  (at your option) any later version.
-//#
-//#  This program is distributed in the hope that it will be useful,
-//#  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-//#  GNU General Public License for more details.
-//#
-//#  You should have received a copy of the GNU General Public License
-//#  along with this program; if not, write to the Free Software
-//#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-//#
-//#  $Id$
-#uses "GCFCommon.ctl"
-
-/**
-  * Controller that will be run once during station startup.
-  * it will search for different conf files in /opt/lofar/etc/
-  * and will fill the pvss database types for those config files.
- 
-  * For now we have: 
-
-  * AntennaArrays.conf.
-  * This will be used to fill: Antenna deltaX deltaY and deltaH fields for 
-  * LBA and HBA antenna configurations. 
-  *
-  * Allowed for now are :  LBA-HBA When LBA is missing LBA_X will be used 
-  * (if available)
-  *
-  * The files contain fieldcenter coordinates in OL-NB-Height
-  * and Antenna positions in OL-NB-Height Offsets from the fieldCenter.
-  * As FieldCenter now the GPS coordinates are taken, this is not correct
-  *
-  * For future compatibility we have to consider other earth coordinates also
-  
-  * RemoteStation.conf
-  * This will fill the RemoteStation point with all data available for this station.
-  *
-  */
-main()
-{ 
-
-  bool showDebug = true;
-  bool foundLBA  = false;
-  
-  bool bDebug    = false;
-  int nr_ofAnt   = 0,
-      index      = 1,
-      OL         = 1,                // ArrayIndexnumber of dda_splittedLinesAntConfFile
-      NB         = 2,                // ArrayIndexnumber of dda_splittedLinesAntConfFile
-      H          = 3;                // ArrayIndexnumber of dda_splittedLinesAntConfFile;
-       
-  string strCurConfig;
-  
-  string strDataDir             = ""; 
-  if (isdir("/opt/lofar/etc/") ) {
-    strDataDir = "/opt/lofar/etc/";
-  } else if ( isdir ("d:/data/CS20_CS001/data/configs/") ) {
-    strDataDir = "d:/data/CS20_CS001/data/configs/";
-  } else {
-    DebugN("Could not find datadir to work with, leaving and no antenne data read.");
-    return;
-  }
-    
-  string strAntArrayConfFile      = strDataDir+"AntennaArrays.conf";
-  string strRemoteStationConfFile = strDataDir+"RemoteStation.conf";
-
-  dyn_string dynStr_fileContent;
-   
-  //
-  // AntennaArray cycle
-  //		
-  dynStr_fileContent = lto_getFile_asDynStr(strAntArrayConfFile);
-
-  while (dynlen(dynStr_fileContent) > 3  && index < dynlen(dynStr_fileContent)) {
-    float centerOL,
-          centerNB,
-          centerH;
-    dyn_float antConfFileOL;
-    dyn_float antConfFileNB;
-    dyn_float antConfFileH;
-    // read ConfigurationName
-    string str;
-    sscanf(dynStr_fileContent[index++],"%s",str);
-    if (strlen(str) > 0 && str[0] != " " && str[0] != "#") {
-      strCurConfig=strtoupper(str);
-      Debug("readStationConfigs.ctl:main|Reading  Config for: "+strCurConfig);
-
-    
-      // read fieldcenter
-      sscanf(dynStr_fileContent[index++],"%*d %*s %f %f %f",centerOL,centerNB,centerH);
-      if (bDebug) DebugN("Reading  Config for center OL,NB,H:" + centerOL + " " + centerNB + " " + centerH);
-
-      // read nr of antennas
-      sscanf(dynStr_fileContent[index++],"%d",nr_ofAnt);
-      if (bDebug) DebugN("Nr of Antenna's in this Config: "+nr_ofAnt);
-   
-      // Select on allowed configurations
-      if (strCurConfig == "LBA" || 
-          strCurConfig == "HBA" ||
-          (strCurConfig == "LBA_X" && !foundLBA)
-          ) {
-        DebugN("--> will be read");
-        bool splitArray=false;   //LBAXarray is 48 lines, 1st col(x3) contains 0-47  2ndco(x3) contain 48-96 
-        if (strCurConfig == "LBA") foundLBA=true;
-        if (strCurConfig == "LBA_X") {
-          strCurConfig="LBA";
-          splitArray=true;
-        }
-      
-
-        for (int ix = index; ix < nr_ofAnt + index; ix++ )
-        {
-       
-          float deltaOL;
-          float deltaNB;
-          float deltaH;
-          float deltaOL2;
-          float deltaNB2;
-          float deltaH2;
-      
-          // read new line of delta's
-          if (splitArray) {
-            sscanf(dynStr_fileContent[ix],"%lf %lf %lf %lf %lf %lf",deltaOL,deltaNB,deltaH,deltaOL2,deltaNB2,deltaH2);
-          } else {
-            sscanf(dynStr_fileContent[ix],"%lf %lf %lf",deltaOL,deltaNB,deltaH);
-          }    
-          if (bDebug) DebugN("OL :"+deltaOL+ " NB: "+ deltaNB+ " H: "+deltaH);
-          if (bDebug) DebugN("ix: " + ix + " index: " + index);
-          if (bDebug) DebugN("Filling array at index: "+ (ix+1-index));
-          antConfFileOL[(ix+1-index)] = deltaOL;
-          antConfFileNB[(ix+1-index)] = deltaNB;
-          antConfFileH[(ix+1-index)]  = deltaH;
-          if (splitArray) {
-            if (bDebug) DebugN("OL2 :"+deltaOL2+ " NB2: "+ deltaNB2+ " H2: "+deltaH2);
-            if (bDebug) DebugN("Filling array at index: "+ (ix+1-index+48));
-            antConfFileOL[(ix+1-index+48)] = deltaOL2;
-            antConfFileNB[(ix+1-index+48)] = deltaNB2;
-            antConfFileH[(ix+1-index+48)]  = deltaH2;
-          }
-        }
-      
-        if (bDebug) DebugN("antConfFileOL: "+antConfFileOL);
-      
-        // All the reading has been done.
-        dpSet("remoteStation."+strCurConfig+".centerOL",centerOL,
-              "remoteStation."+strCurConfig+".centerNB",centerNB,
-              "remoteStation."+strCurConfig+".centerH",centerH);
-      
-        int ix=nr_ofAnt;
-        if (splitArray) ix *= 2;
-        for (int i=1; i<= ix;i++) {
-          string ant=(i-1);
-          dpSet(strCurConfig+ant+".deltaX",antConfFileOL[i],
-                strCurConfig+ant+".deltaY",antConfFileNB[i],
-                strCurConfig+ant+".deltaH",antConfFileH[i]);
-        }
-      } else {
-        DebugN("--> will be skipped");
-      }
-      index +=nr_ofAnt+1;
-    }
-  }
-  
-  //
-  // RemoteStation cycle
-  //	
-  
-  dynStr_fileContent = lto_getFile_asDynStr(strRemoteStationConfFile);
-  if (bDebug) DebugN("fileContent: "+dynStr_fileContent);
-  
-  for (index=1;index <= dynlen(dynStr_fileContent);index++) {
-    if (strpos(dynStr_fileContent[index],"RS.STATION_ID")>-1) {
-      dyn_string value = strsplit(dynStr_fileContent[index],"=");
-      if (dynlen(value) > 1) {
-        dpSet("remoteStation.stationID",value[2]);
-      }
-    }
-    
-    if (strpos(dynStr_fileContent[index],"RS.N_RSPBOARDS")>-1) {
-      dyn_string value = strsplit(dynStr_fileContent[index],"=");
-      if (dynlen(value) > 1) {
-        dpSet("remoteStation.N_RSPBoards",value[2]);
-      }
-    }
-    
-    if (strpos(dynStr_fileContent[index],"RS.N_TBBOARDS")>-1) {
-      dyn_string value = strsplit(dynStr_fileContent[index],"=");
-      if (dynlen(value) > 1) {
-        dpSet("remoteStation.N_TBBoards",value[2]);
-      }
-    }
-
-    if (strpos(dynStr_fileContent[index],"RS.N_LBAS")>-1) {
-      dyn_string value = strsplit(dynStr_fileContent[index],"=");
-      if (dynlen(value) > 1) {
-        dpSet("remoteStation.N_LBAS",value[2]);
-      }
-    }
-      
-    if (strpos(dynStr_fileContent[index],"RS.N_HBAS")>-1) {
-      dyn_string value = strsplit(dynStr_fileContent[index],"=");
-      if (dynlen(value) > 1) {
-        dpSet("remoteStation.N_HBAS",value[2]);
-      }
-    }
-  
-    if (strpos(dynStr_fileContent[index],"RS.HBA_SPLIT")>-1) {
-      dyn_string value = strsplit(dynStr_fileContent[index],"=");
-      if (dynlen(value) > 1) {
-        if (substr(value[2],0,1) == "N" ||
-            substr(value[2],0,1) == "n" ||
-            substr(value[2],0,1) == "F" ||
-            substr(value[2],0,1) == "f") {
-          dpSet("remoteStation.HBA_Split",false);
-        } else {
-          dpSet("remoteStation.HBA_Split",true);
-        }
-      }
-    }
-  
-
-    if (strpos(dynStr_fileContent[index],"RS.WIDE_LBAS")>-1) {
-      dyn_string value = strsplit(dynStr_fileContent[index],"=");
-      if (dynlen(value) > 1) {
-        if (substr(value[2],0,1) == "N" ||
-            substr(value[2],0,1) == "n" ||
-            substr(value[2],0,1) == "F" ||
-            substr(value[2],0,1) == "f") {
-          dpSet("remoteStation.wide_LBAS",false);
-        } else {
-          dpSet("remoteStation.wide_LBAS",true);
-        }
-      }
-    }
-  }
-}
-
-dyn_string lto_getFile_asDynStr(string aFileName)
-{
-  // Local vars
-  dyn_string aFile_asDynStr;     // dyn_string returnvalue
-  string     aFile_asStr;
-
-  file f;                        // our file
-  int err;                           // error code
-  
-  f=fopen(aFileName,"r");        // open for reading
-  if (f > 0) 
-  {
-    err=ferror(f);                 // export error
-
-    if (err!=0) 
-    {
-      DebugN("readStationConfigs.ctl:lto_getFile_asDynStr|Error during read no. " + err);
-    }
-    else
-    {
-      if ( fileToString (aFileName, aFile_asStr) )
-      {
-        aFile_asDynStr = strsplit(aFile_asStr, "\n");
-      }	
-    }
-    fclose(f); // close file
-  } else {
-    DebugN("readStationConfigs.ctl:lto_getFile_asDynStr|Error opening file: " + aFileName);
-  }
-    
-  return aFile_asDynStr;
-}
-
+//# readStationConfigs.ctl
+//#
+//#  Copyright (C) 2007-2008
+//#  ASTRON (Netherlands Foundation for Research in Astronomy)
+//#  P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl
+//#
+//#  This program is free software; you can redistribute it and/or modify
+//#  it under the terms of the GNU General Public License as published by
+//#  the Free Software Foundation; either version 2 of the License, or
+//#  (at your option) any later version.
+//#
+//#  This program is distributed in the hope that it will be useful,
+//#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//#  GNU General Public License for more details.
+//#
+//#  You should have received a copy of the GNU General Public License
+//#  along with this program; if not, write to the Free Software
+//#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+//#
+//#  $Id$
+#uses "GCFCommon.ctl"
+
+/**
+  * Controller that will be run once during station startup.
+  * it will search for different conf files in /opt/lofar/etc/
+  * and will fill the pvss database types for those config files.
+ 
+  * For now we have: 
+
+  * AntennaArrays.conf.
+  * This will be used to fill: Antenna deltaX deltaY and deltaH fields for 
+  * LBA and HBA antenna configurations. 
+  *
+  * Allowed for now are :  LBA-HBA When LBA is missing LBA_X will be used 
+  * (if available)
+  *
+  * The files contain fieldcenter coordinates in OL-NB-Height
+  * and Antenna positions in OL-NB-Height Offsets from the fieldCenter.
+  * As FieldCenter now the GPS coordinates are taken, this is not correct
+  *
+  * For future compatibility we have to consider other earth coordinates also
+  
+  * RemoteStation.conf
+  * This will fill the RemoteStation point with all data available for this station.
+  *
+  */
+  global dyn_string dynStr_fileContent;
+  global int index=1;
+  global bool bDebug    = false;
+  global bool norVecLBAFound=false;
+  global bool norVecHBA0Found=false;
+  global bool norVecHBA1Found=false;
+  global bool rotMatLBAFound=false;
+  global bool rotMatHBA0Found=false;
+  global bool rotMatHBA1Found=false;
+  global bool centerLBAFound=false;
+  global bool centerHBAFound=false;
+  global bool deltasLBAFound=false;
+  global bool deltasHBAFound=false;
+  global bool centerHBA0Found=false;
+  global bool centerHBA1Found=false;
+
+  
+main()
+{ 
+
+  bool foundLBA  = false;
+  
+  string strCurConfig;
+  
+  string strDataDir             = ""; 
+  if (isdir("/opt/lofar/etc/") ) {
+    strDataDir = "/opt/lofar/etc/";
+  } else if ( isdir ("d:/data/CS20_CS001/data/configs/") ) {
+    strDataDir = "d:/data/CS20_CS001/data/configs/";
+  } else {
+    DebugN("Could not find datadir to work with, leaving and no antenne data read.");
+    return;
+  }
+    
+//  string strAntArrayConfFile      = strDataDir+"AntennaArrays.conf";
+  string strAntArrayConfFile      = strDataDir+"AntennaField.conf";
+  string strRemoteStationConfFile = strDataDir+"RemoteStation.conf";
+
+   
+  //
+  // AntennaArray cycle
+  //		
+  dynStr_fileContent = lto_getFile_asDynStr(strAntArrayConfFile);
+   
+
+  while (dynlen(dynStr_fileContent) > 3  && index < dynlen(dynStr_fileContent)) {
+    
+    // read ConfigurationName
+    string str1="",str2="";
+    sscanf(dynStr_fileContent[index++],"%s %s",str1,str2);
+    if (strlen(str1) <= 0 || str1[0] == " " || str1[0] == "#") {
+      continue;
+    }
+      
+    if (bDebug) DebugN("working on: ",dynStr_fileContent[index-1]);    
+    if (bDebug) DebugN("str1: ",str1," str2: ",str2);
+    
+    if (strtoupper(str1) == "NORMAL_VECTOR" ) {
+      if (strtoupper(str2) != "LBA" && strtoupper(str2) != "HBA0" && strtoupper(str2) != "HBA1") {
+        DebugN("readStationConfigs.ctl | Unknown NORMAL_VECTOR target found: ", str2);
+        continue;
+      } else {
+       // read Normal Vector
+        processNormalVector(strtoupper(str2));
+      }
+    } else if (strtoupper(str1) == "ROTATION_MATRIX" ) {
+      if (strtoupper(str2) != "LBA" && strtoupper(str2) != "HBA0" && strtoupper(str2) != "HBA1") {
+        DebugN("readStationConfigs.ctl | Unknown ROTATION_MATRIX target found: ", str2);
+        continue;
+      } else {
+       // read Rotation Matrix
+        processRotationMatrix(strtoupper(str2));
+      }
+    } else if (strtoupper(str1) == "LBA" || strtoupper(str1) == "HBA") {
+      strCurConfig=strtoupper(str1); 
+        
+      // read fieldcenter
+      processFieldCenter(strCurConfig);
+
+      // read field Deltas
+      processFieldDeltas(strCurConfig);      
+    } else if (strtoupper(str1) == "HBA0" || strtoupper(str1)=="HBA1") {
+      // read fieldcenter
+      processFieldCenter(strtoupper(str1));
+    } else {
+      DebugN(str1," -----> Unknown, will not be read");
+    }
+  }
+    
+  if (!norVecLBAFound ) {
+    DebugN("Error? NORMAL_VECTOR for LBA not found.");
+  }
+  if (!norVecHBA0Found ) {
+    DebugN("Error? NORMAL_VECTOR for HBA0 not found.");
+  }
+  if (!norVecHBA1Found ) {
+    DebugN("Error? NORMAL_VECTOR for HBA1 not found.");
+  }      
+  if (!rotMatLBAFound ) {
+    DebugN("Error? ROTATION_MATRIX for LBA not found.");
+  }      
+  if (!rotMatHBA0Found ) {
+    DebugN("Error? ROTATION_MATRIX for HBA0 not found.");
+  }      
+  if (!rotMatHBA1Found ) {
+    DebugN("Error? ROTATION_MATRIX for HBA1 not found.");
+  }      
+  if (!centerLBAFound ) {
+    DebugN("Error? FieldCenter for LBA not found.");
+  }      
+  if (!centerHBAFound ) {
+    DebugN("Error? FieldCenter for HBA not found.");
+  }
+  if (!deltasLBAFound ) {
+    DebugN("Error? Deltas for LBA not found.");
+  }      
+  if (!deltasHBAFound ) {
+    DebugN("Error? Deltas for HBA not found.");
+  }
+
+
+  
+  //
+  // RemoteStation cycle
+  //	
+  
+  dynStr_fileContent = lto_getFile_asDynStr(strRemoteStationConfFile);
+  if (bDebug) DebugN("fileContent: "+dynStr_fileContent);
+  
+  for (index=1;index <= dynlen(dynStr_fileContent);index++) {
+    if (strpos(dynStr_fileContent[index],"RS.STATION_ID")>-1) {
+      dyn_string value = strsplit(dynStr_fileContent[index],"=");
+      if (dynlen(value) > 1) {
+        dpSet("remoteStation.stationID",value[2]);
+      }
+    }
+    
+    if (strpos(dynStr_fileContent[index],"RS.N_RSPBOARDS")>-1) {
+      dyn_string value = strsplit(dynStr_fileContent[index],"=");
+      if (dynlen(value) > 1) {
+        dpSet("remoteStation.N_RSPBoards",value[2]);
+      }
+    }
+    
+    if (strpos(dynStr_fileContent[index],"RS.N_TBBOARDS")>-1) {
+      dyn_string value = strsplit(dynStr_fileContent[index],"=");
+      if (dynlen(value) > 1) {
+        dpSet("remoteStation.N_TBBoards",value[2]);
+      }
+    }
+
+    if (strpos(dynStr_fileContent[index],"RS.N_LBAS")>-1) {
+      dyn_string value = strsplit(dynStr_fileContent[index],"=");
+      if (dynlen(value) > 1) {
+        dpSet("remoteStation.N_LBAS",value[2]);
+      }
+    }
+      
+    if (strpos(dynStr_fileContent[index],"RS.N_HBAS")>-1) {
+      dyn_string value = strsplit(dynStr_fileContent[index],"=");
+      if (dynlen(value) > 1) {
+        dpSet("remoteStation.N_HBAS",value[2]);
+      }
+    }
+  
+    if (strpos(dynStr_fileContent[index],"RS.HBA_SPLIT")>-1) {
+      dyn_string value = strsplit(dynStr_fileContent[index],"=");
+      if (dynlen(value) > 1) {
+        if (substr(value[2],0,1) == "N" ||
+            substr(value[2],0,1) == "n" ||
+            substr(value[2],0,1) == "F" ||
+            substr(value[2],0,1) == "f") {
+          dpSet("remoteStation.HBA_Split",false);
+        } else {
+          dpSet("remoteStation.HBA_Split",true);
+        }
+      }
+    }
+  
+
+    if (strpos(dynStr_fileContent[index],"RS.WIDE_LBAS")>-1) {
+      dyn_string value = strsplit(dynStr_fileContent[index],"=");
+      if (dynlen(value) > 1) {
+        if (substr(value[2],0,1) == "N" ||
+            substr(value[2],0,1) == "n" ||
+            substr(value[2],0,1) == "F" ||
+            substr(value[2],0,1) == "f") {
+          dpSet("remoteStation.wide_LBAS",false);
+        } else {
+          dpSet("remoteStation.wide_LBAS",true);
+        }
+      }
+    }
+  }
+}
+
+
+dyn_string lto_getFile_asDynStr(string aFileName) {
+  // Local vars
+  dyn_string aFile_asDynStr;     // dyn_string returnvalue
+  string     aFile_asStr;
+
+  file f;                        // our file
+  int err;                           // error code
+  
+  f=fopen(aFileName,"r");        // open for reading
+  if (f > 0) 
+  {
+    err=ferror(f);                 // export error
+
+    if (err!=0) 
+    {
+      DebugN("readStationConfigs.ctl:lto_getFile_asDynStr|Error during read no. " + err);
+    }
+    else
+    {
+      if ( fileToString (aFileName, aFile_asStr) )
+      {
+        aFile_asDynStr = strsplit(aFile_asStr, "\n");
+      }	
+    }
+    fclose(f); // close file
+  } else {
+    DebugN("readStationConfigs.ctl:lto_getFile_asDynStr|Error opening file: " + aFileName);
+  }
+    
+  return aFile_asDynStr;
+}
+
+void processNormalVector(string aS) {
+  float fX=0,fY=0,fZ=0;
+  sscanf(dynStr_fileContent[index++],"%*d %*s %lf %lf %lf",fX,fY,fZ);
+  if (bDebug) DebugN("Reading NORMAL_VECTOR "+aS+" X,Y,Z :" + fX + " " + fY + " " + fZ);
+  if (aS == "LBA" ) {
+    norVecLBAFound=true;
+    dpSet("remoteStation.LBA.NormalVector.X",fX,
+          "remoteStation.LBA.NormalVector.Y",fY,
+          "remoteStation.LBA.NormalVector.Z",fZ);    
+  } else if (aS == "HBA0") {
+    norVecHBA0Found=true;
+    dpSet("remoteStation.HBA.HBA0.NormalVector.X",fX,
+          "remoteStation.HBA.HBA0.NormalVector.Y",fY,
+          "remoteStation.HBA.HBA0.NormalVector.Z",fZ);    
+  } else if (aS == "HBA1") {
+    norVecHBA1Found=true;
+    dpSet("remoteStation.HBA.HBA1.NormalVector.X",fX,
+          "remoteStation.HBA.HBA1.NormalVector.Y",fY,
+          "remoteStation.HBA.HBA1.NormalVector.Z",fZ);    
+  }
+} 
+
+void processRotationMatrix(string aS) {
+  dyn_float fX,fY,fZ;
+  int nr_rows=0;
+  // read nr of rows
+  sscanf(dynStr_fileContent[index++],"%d",nr_rows);
+  if (bDebug) DebugN("index: "+(index-1)+" nr_rows: "+nr_rows);
+  for (int i = 1; i <= nr_rows; i++) {
+    sscanf(dynStr_fileContent[index++],"%lf %lf %lf",fX[i],fY[i],fZ[i]);
+    if (bDebug) DebugN("Reading rotationMatrix "+aS+"line "+i+" X,Y,Z:" + fX[i] + " " + fY[i] + " " + fZ[i]);
+  }
+  index++;
+  if (aS == "LBA" ) {
+    rotMatLBAFound=true;
+    dpSet("remoteStation.LBA.RotationMatrix.X",fX,
+          "remoteStation.LBA.RotationMatrix.Y",fY,
+          "remoteStation.LBA.RotationMatrix.Z",fZ);    
+  } else if (aS == "HBA0") {
+    rotMatHBA0Found=true;
+    dpSet("remoteStation.HBA.HBA0.RotationMatrix.X",fX,
+          "remoteStation.HBA.HBA0.RotationMatrix.Y",fY,
+          "remoteStation.HBA.HBA0.RotationMatrix.Z",fZ);    
+  } else if (aS == "HBA1") {
+    rotMatHBA1Found=true;
+    dpSet("remoteStation.HBA.HBA1.RotationMatrix.X",fX,
+          "remoteStation.HBA.HBA1.RotationMatrix.Y",fY,
+          "remoteStation.HBA.HBA1.RotationMatrix.Z",fZ);   
+  }
+
+
+}   
+
+void processFieldCenter(string aS) {
+  float fX=0,fY=0,fZ=0;
+  sscanf(dynStr_fileContent[index++],"%*d %*s %lf %lf %lf",fX,fY,fZ);
+  if (bDebug) DebugN("Reading  fieldcenter "+aS+"X,Y,Z:" + fX + " " + fY + " " + fZ);
+  if (aS== "LBA") {
+    centerLBAFound=true;
+    dpSet("remoteStation."+aS+".centerX",fX,
+        "remoteStation."+aS+".centerY",fY,
+        "remoteStation."+aS+".centerZ",fZ);
+  } else if (aS == "HBA") {
+    centerHBAFound=true;
+    dpSet("remoteStation."+aS+".centerX",fX,
+        "remoteStation."+aS+".centerY",fY,
+        "remoteStation."+aS+".centerZ",fZ);
+  } else if (aS == "HBA0") {
+    centerHBA0Found=true;
+    dpSet("remoteStation.HBA.HBA0.centerX",fX,
+          "remoteStation.HBA.HBA0.centerY",fY,
+          "remoteStation.HBA.HBA0.centerZ",fZ);
+  } else if (aS == "HBA1") {
+    centerHBA1Found=true;
+    dpSet("remoteStation.HBA.HBA1.centerX",fX,
+          "remoteStation.HBA.HBA1.centerY",fY,
+          "remoteStation.HBA.HBA1.centerZ",fZ);
+  }
+}
+
+void processFieldDeltas(string aS) {
+  int nr_ofAnt   = 0; 
+  float deltaX;
+  float deltaY;
+  float deltaZ;
+  dyn_float antConfFileX;
+  dyn_float antConfFileY;
+  dyn_float antConfFileZ;
+
+  if (aS== "LBA") {
+    deltasLBAFound=true;
+  } else if (aS == "HBA") {
+    deltasHBAFound=true;
+  }
+
+  // read nr of antennas
+  sscanf(dynStr_fileContent[index++],"%d",nr_ofAnt);
+  if (bDebug) DebugN("Nr of Antenna's in this Config: "+nr_ofAnt);
+  DebugN(aS,"--> will be read");
+  for (int ix = index; ix < nr_ofAnt + index; ix++ ) {
+    // read new line of delta's
+    sscanf(dynStr_fileContent[ix],"%lf %lf %lf",deltaX,deltaY,deltaZ);
+    if (bDebug) DebugN("X :"+deltaX+ " Y: "+ deltaY+ " Z: "+deltaZ);
+    if (bDebug) DebugN("ix: " + ix + " index: " + index);
+    if (bDebug) DebugN("Filling array at index: "+ (ix+1-index));
+    antConfFileX[(ix+1-index)] = deltaX;
+    antConfFileY[(ix+1-index)] = deltaY;
+    antConfFileZ[(ix+1-index)] = deltaZ;
+  }
+    
+  int ix=nr_ofAnt;
+  for (int i=1; i<= ix;i++) {
+    string ant=(i-1);
+    dpSet(aS+ant+".deltaX",antConfFileX[i],
+          aS+ant+".deltaY",antConfFileY[i],
+          aS+ant+".deltaZ",antConfFileZ[i]);
+  }
+  index +=nr_ofAnt+1;
+}
+    
+
-- 
GitLab