From 6ddb175d7f9267c044fecf2943d55a1ba4f765c2 Mon Sep 17 00:00:00 2001
From: Rolf Bork <rolf.bork@ligo.org>
Date: Wed, 1 Jun 2016 15:26:36 +0000
Subject: [PATCH] Bug Fix for loading individual filter coeffs (#1008 and
 #1014).

git-svn-id: https://redoubt.ligo-wa.caltech.edu/svn/advLigoRTS/trunk@4223 6dcd42c9-f523-4c6d-aada-af552506706e
---
 NEWS                  |  4 +++
 src/drv/fmReadCoeff.c | 62 ++++++++++++++++++++++++++++++++++++-------
 src/epics/seq/main.c  |  2 ++
 3 files changed, 58 insertions(+), 10 deletions(-)

diff --git a/NEWS b/NEWS
index db8731d71..bd73fb398 100644
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,10 @@ Changes for X.X
 - Bug Fix (513): Cleanup debug schemes.  Also created separate udp_rcvr files, fixed mx_rcvr header
 - Bug Fix (1015): Update daqd,nds build for ldas-tools 2.5
 ==================================================================================================
+Changes for 3.0.3
+==================================================================================================
+- Bug Fix for loading individual filter coeffs (#1008 and #1014).
+==================================================================================================
 Changes for 3.0.2
 ==================================================================================================
 - Bug Fix to SUM.pm part connection checking.
diff --git a/src/drv/fmReadCoeff.c b/src/drv/fmReadCoeff.c
index e6c2e62cc..dc45f5e82 100644
--- a/src/drv/fmReadCoeff.c
+++ b/src/drv/fmReadCoeff.c
@@ -947,6 +947,9 @@ int fmCreatePartial(char *cfDir, char *cfName, char *filtName)
   int foundFilt = 0;
   char cpCmd[256];
   int status;
+  char *words[10];
+  int nwords;
+  char myline[100];
 
   strcpy(fName[FMC_PHOTON],cfDir);
   strcpy(fName[FMC_LOAD],cfDir);
@@ -980,11 +983,16 @@ int fmCreatePartial(char *cfDir, char *cfName, char *filtName)
   	if(fstart && fstop < 2) {
 		strcat(newcoeffs,line);
 	}
-	if(strstr(line,searchPattern) != NULL && fstart == 0) {
-		fstart = 1;
-		foundFilt = 1;
-		strcat(newcoeffs,line);
-  		printf("Found the filter %s\n",filtName);
+	if(strstr(line,searchPattern) != NULL && fstart == 0 ) {
+		strcpy(myline,line);
+		nwords = getwords(myline,words,10);
+		if(strcmp(filtName,words[1]) == 0) {
+			fstart = 1;
+			foundFilt = 1;
+			strcat(newcoeffs,line);
+			printf("Found the filter %s  %s\n",filtName,line);
+			printf("Found %d words = %s %s\n",nwords,words[0],words[1]);
+		}
 	}
 	if(fstart > 0 && strstr(line,stopPattern) != NULL) {
 		fstop += 1;
@@ -1018,11 +1026,17 @@ int fmCreatePartial(char *cfDir, char *cfName, char *filtName)
 		fprintf(fptmp,"%s",line);
 	}
 	if(strstr(line,searchPattern) != NULL && fstart == 0) {
-		fstart = 1;
-		foundFilt = 1;
-  		printf("Found the filter %s\n",filtName);
-		// Write all of the new stuff extracted from the Photon file
-		fprintf(fptmp,"%s",newcoeffs);
+		strcpy(myline,line);
+		nwords = getwords(myline,words,10);
+		if(strcmp(filtName,words[1]) == 0) {
+			fstart = 1;
+			foundFilt = 1;
+			printf("Found the filter %s\n",filtName);
+			// Write all of the new stuff extracted from the Photon file
+			fprintf(fptmp,"%s",newcoeffs);
+		} else {
+			fprintf(fptmp,"%s",line);
+		}
 	}
 	if(fstart > 0 && strstr(line,stopPattern) != NULL) {
 		fstop += 1;
@@ -1096,6 +1110,34 @@ printCoefs(fmReadCoeff *fmc, int subsystems) {
   }
 }
 
+getwords(char *line, char *words[], int maxwords)
+{
+char *p = line;
+int nwords = 0;
+
+while(1)
+	{
+	while(isspace(*p))
+		p++;
+
+	if(*p == '\0')
+		return nwords;
+
+	words[nwords++] = p;
+
+	while(!isspace(*p) && *p != '\0')
+		p++;
+
+	if(*p == '\0')
+		return nwords;
+
+	*p++ = '\0';
+
+	if(nwords >= maxwords)
+		return nwords;
+	}
+}
+
 #ifdef unix_test
 fmSubSysMap itmxMap[5] = { { "ULSEN", 0 }, { "LLSEN", 1 }, { "URSEN", 2 }, { "LRSEN", 3 }, { "SDSEN", 4 } };
 fmSubSysMap itmyMap[5] = { { "ULSEN", 5 }, { "LLSEN", 6 }, { "URSEN", 7 }, { "LRSEN", 8 }, { "SDSEN", 9 } };
diff --git a/src/epics/seq/main.c b/src/epics/seq/main.c
index d222367a6..d09accebc 100644
--- a/src/epics/seq/main.c
+++ b/src/epics/seq/main.c
@@ -3641,6 +3641,8 @@ sleep(5);
 			if(fotonFileCrc != prevFotonFileCrc || prevCoeffFileCrc != coeffFileCrc) {
 				sprintf(myDiffCmd,"%s %s %s %s %s","diff",fotonFile,coeffFile," > ",fotonDiffFile);
 				status = system(myDiffCmd);
+				prevFotonFileCrc = fotonFileCrc;
+				prevCoeffFileCrc = coeffFileCrc;
 			}
 			status = checkFileCrc(sdffileloaded);
 			if(status == -1) {
-- 
GitLab