Bug 134465 - PHASE functionality to dirfile format
Summary: PHASE functionality to dirfile format
Status: RESOLVED FIXED
Alias: None
Product: kst
Classification: Applications
Component: general (show other bugs)
Version: 1.x
Platform: Compiled Sources Linux
: NOR wishlist
Target Milestone: ---
Assignee: Adam Treat
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-09-21 19:00 UTC by Bill Jones
Modified: 2006-10-06 18:19 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments
Add PHASE field feature to dirfile datasource (7.71 KB, patch)
2006-09-21 23:12 UTC, Adam Treat
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Bill Jones 2006-09-21 19:00:49 UTC
Version:           1.2.1 (using KDE KDE 3.5.1)
Installed from:    Compiled From Sources
Compiler:          gcc v 4.1.0 
OS:                Linux

> I have a kst request (more dirfile, really).  It would be handy to add
> functionality to the "format" file that would allow you to create a field
> that is phase-shifted by some amount.  For example, an example format file
> might look like this
>
> >less format
>
> fastdata      RAW     d       12
> sluggishdata  RAW     d       6
> slowdata      RAW     d       1
> shiftfast     PHASE   fastdata        -231
>
> Where here the "shiftfast" field would simply be the "fastdata", shifted
> back by 231 fast samples.
>
Comment 1 Adam Treat 2006-09-21 23:12:59 UTC
Created attachment 17867 [details]
Add PHASE field feature to dirfile datasource

Please review.
Comment 2 Nicolas Brisset 2006-09-22 00:54:56 UTC
I'm not sure I understand this correctly, but to me it looks very much like what the shift filter plugin already does (create a new vector that is shifted by a given number of samples). To test it, RMB->Filter, then select shift and enter the value (positive or negative).
Comment 3 Adam Treat 2006-10-06 18:19:32 UTC
SVN commit 593046 by treat:

Add dirfile PHASE functionality to the datasource plugin.

BUG: 134465


 M  +8 -0      dirfile.cpp  
 M  +93 -1     getdata.c  
 M  +8 -0      getdata_struct.h  


--- trunk/extragear/graphics/kst/src/datasources/dirfile/dirfile.cpp #593045:593046
@@ -63,6 +63,10 @@
       _fieldList.append(ft->bitEntries[i].field);
     }
 
+    for (int i = 0; i < ft->n_phase; i++) {
+      _fieldList.append(ft->phaseEntries[i].field);
+    }
+
     for (int i = 0; i < ft->n_raw; i++) {
       _fieldList.append(ft->rawEntries[i].field);
     }
@@ -198,6 +202,10 @@
       fieldList.append(ft->bitEntries[i].field);
     }
 
+    for (int i = 0; i < ft->n_phase; i++) {
+      fieldList.append(ft->phaseEntries[i].field);
+    }
+
     for (int i = 0; i < ft->n_raw; i++) {
       fieldList.append(ft->rawEntries[i].field);
     }
--- trunk/extragear/graphics/kst/src/datasources/dirfile/getdata.c #593045:593046
@@ -264,6 +264,7 @@
   if (F->n_linterp >0) free(F->linterpEntries);
   if (F->n_mplex > 0) free(F->mplexEntries);
   if (F->n_bit > 0) free(F->bitEntries);
+  if (F->n_phase > 0) free(F->phaseEntries);
 }
 
 /***************************************************************************/
@@ -425,6 +426,23 @@
 
 /***************************************************************************/
 /*                                                                         */
+/*   ParsePhase: parse PHASE data type entry in formats file               */
+/*                                                                         */
+/***************************************************************************/
+static int ParsePhase(char in_cols[MAX_IN_COLS][MAX_LINE_LENGTH], int n_cols,
+    struct PhaseEntryType *P, const char* format_file, int line)
+{
+  strcpy(P->field, in_cols[0]); /* field */
+  strncpy(P->raw_field, in_cols[2], FIELD_LENGTH); /* field */
+
+  P->shift=atoi(in_cols[3]); /*shift*/
+
+  /*FIXME make sure the shift is within the range of the raw field...*/
+  return SetGetDataError(GD_E_OK, 0, NULL, 0, NULL);
+}
+
+/***************************************************************************/
+/*                                                                         */
 /*   Compare functions for sorting the lists (using stdlib qsort)          */
 /*                                                                         */
 /***************************************************************************/
@@ -458,6 +476,11 @@
         ((struct BitEntryType *)B)->field));
 }
 
+static int PhaseCmp(const void *A, const void *B) {
+  return (strcmp(((struct PhaseEntryType *)A)->field,
+        ((struct PhaseEntryType *)B)->field));
+}
+
 /***************************************************************************/
 /*                                                                         */
 /*  ParseFormatFile: Perform the actual parsing of the format file.  This  */
@@ -529,6 +552,13 @@
             F->n_bit*sizeof(struct BitEntryType));
       error_code = ParseBit(in_cols, n_cols, F->bitEntries+F->n_bit - 1,
           format_file, linenum);
+    } else if (strcmp(in_cols[1], "PHASE")==0) {
+      F->n_phase++;
+      F->phaseEntries =
+        realloc(F->phaseEntries,
+            F->n_phase*sizeof(struct PhaseEntryType));
+      error_code = ParsePhase(in_cols, n_cols, F->phaseEntries+F->n_phase - 1,
+          format_file, linenum);
     } else if (strcmp(in_cols[0], "FRAMEOFFSET")==0) {
       F->frame_offset = atoi(in_cols[1]);
     } else if (strcmp(in_cols[0], "INCLUDE")==0) {
@@ -632,7 +662,7 @@
   }
 
   strcpy(F->FileDirName, filedir);
-  F->n_raw = F->n_lincom = F->n_multiply = F->n_linterp = F->n_mplex = F->n_bit
+  F->n_raw = F->n_lincom = F->n_multiply = F->n_linterp = F->n_mplex = F->n_bit = F->n_phase
     = 0;
   F->frame_offset = 0;
   F->rawEntries = NULL;
@@ -641,6 +671,7 @@
   F->linterpEntries = NULL;
   F->mplexEntries = NULL;
   F->bitEntries = NULL;
+  F->phaseEntries = NULL;
 
   /* Parse the file.  This will take care of any necessary inclusions */
   i_include = 1;
@@ -696,6 +727,10 @@
     qsort(F->bitEntries, F->n_bit, sizeof(struct BitEntryType),
         BitCmp);
   }
+  if (F->n_phase > 1) {
+    qsort(F->phaseEntries, F->n_phase, sizeof(struct PhaseEntryType),
+        PhaseCmp);
+  }
   return(F);
 }
 
@@ -1029,6 +1064,8 @@
   struct MultiplyEntryType *M;
   struct BitEntryType tB;
   struct BitEntryType *B;
+  struct PhaseEntryType tP;
+  struct PhaseEntryType *P;
   struct LinterpEntryType tI;
   struct LinterpEntryType *I;
   int spf;
@@ -1110,6 +1147,21 @@
   }
 
   /***************************************/
+  /** Check to see if it is a phase entry **/
+  /* binary search for the field */
+  /* make a PhaseEntry we can compare to */
+  strncpy(tP.field, field_code, FIELD_LENGTH);
+  /** use the stdlib binary search */
+  P = bsearch(&tP, F->phaseEntries, F->n_phase,
+      sizeof(struct PhaseEntryType), PhaseCmp);
+  if (P!=NULL) {
+    recurse_level++;
+    spf = GetSPF(P->raw_field, F, error_code);
+    recurse_level--;
+    return(spf);
+  }
+
+  /***************************************/
   /** Check to see if it is a linterp entry **/
   /* binary search for the field */
   /* make a LinterpEntry we can compare to */
@@ -1663,6 +1715,40 @@
 
 /***************************************************************************/
 /*                                                                         */
+/*   Look to see if the field code belongs to phasefield.  If so, parse it.*/
+/*                                                                         */
+/***************************************************************************/
+static int DoIfPhase(struct FormatType *F, const char *field_code,
+    int first_frame, int first_samp,
+    int num_frames, int num_samp,
+    char return_type, void *data_out,
+    int *error_code, int *n_read) {
+  struct PhaseEntryType tP;
+  struct PhaseEntryType *P;
+
+  /******* binary search for the field *******/
+  /* make a PhaseEntry we can compare to */
+  strncpy(tP.field, field_code, FIELD_LENGTH);
+  /** use the stdlib binary search */
+  P = bsearch(&tP, F->phaseEntries, F->n_phase,
+      sizeof(struct PhaseEntryType), PhaseCmp);
+  if (P==NULL) return(0);
+
+  /*****************************************/
+  /** if we got here, we found the field! **/
+  recurse_level++;
+  *n_read = DoField(F, P->raw_field,
+      first_frame, first_samp + P->shift,
+      num_frames, num_samp,
+      return_type, data_out,
+      error_code);
+  recurse_level--; 
+
+  return(1);
+}
+
+/***************************************************************************/
+/*                                                                         */
 /*   ReadLinterpFile: Read in the linterp data for this field              */
 /*                                                                         */
 /***************************************************************************/
@@ -1891,6 +1977,12 @@
         return_type, data_out,
         error_code, &n_read)) {
     return(n_read);
+  } else if (DoIfPhase(F, field_code,
+        first_frame, first_samp,
+        num_frames, num_samp,
+        return_type, data_out,
+        error_code, &n_read)) {
+    return(n_read);
   } else if (DoIfLinterp(F, field_code,
         first_frame, first_samp,
         num_frames, num_samp,
--- trunk/extragear/graphics/kst/src/datasources/dirfile/getdata_struct.h #593045:593046
@@ -67,6 +67,12 @@
   int numbits;
 };
 
+struct PhaseEntryType {
+  char field[FIELD_LENGTH+1];
+  char raw_field[FIELD_LENGTH+1];
+  int shift;
+};
+
 struct FormatType {
   char FileDirName[MAX_FILENAME_LENGTH];
   int frame_offset;
@@ -83,6 +89,8 @@
   int n_mplex;
   struct BitEntryType *bitEntries;
   int n_bit;
+  struct PhaseEntryType *phaseEntries;
+  int n_phase;
 };
 
 #endif