1. Chris Lee-Messer
  2. python-axonbinaryfile

Commits

ch...@lee-messer.net  committed dd38122

have working get_cmdwaveform (just remember to start episodes count at 1

  • Participants
  • Parent commits 44f6bdc
  • Branches default

Comments (0)

Files changed (1)

File axonbinaryfile/_abfmodule.cpp

View file
  • Ignore whitespace
   DWORD dwEpisode;
   UINT uMaxSamples = START_DATA_BUFSIZE; 
   UINT uNumSamples;
-
+  char inFname[1024];  /* don't remember what's this for !!! */
   
 
   if(!PyArg_ParseTuple(args, "sii", &file_name,&episode_num,&channel_num)) {
     return NULL;
   }
-  printf("file_name: %s, episode_num: %d, channel_num:%d\n", file_name, episode_num, channel_num);
+  /* printf("file_name: %s, episode_num: %d, channel_num:%d\n", file_name, episode_num, channel_num); */
 
   BOOL bSuccess= ABF_ReadOpen(file_name, &hFile, ABF_DATAFILE, &FH,
 			      &uMaxSamples, &dwMaxEpi, &nError);
   
   /* figure out size of a cmd waveform*/
   uNumSamples = FH.lNumSamplesPerEpisode/FH.nADCNumChannels;
-  printf("uNumSamples=%u\n", uNumSamples);
+  /* printf("uNumSamples=%u\n", uNumSamples); */
 
   npy_intp dims[1];
   dims[0] = uNumSamples;
   float *fptr= (float*)PyArray_DATA(arrobj);
   
   /* GetWaveform stuff */
-  dwEpisode=episode_num;
+  dwEpisode=episode_num; /* think that they might start counting at 1*/
   bSuccess=ABF_GetWaveform(hFile, &FH, channel_num, dwEpisode, fptr, &nError);
   if (!bSuccess) {
+    /* FIXME!!! set python exception*/
+    printf("No success getting waveform %s\n", file_name);
+    ShowABFError(inFname, nError);
+    if (!ABF_Close( hFile, &nError )) {
+      ShowABFError(inFname, nError);
+    }
     return NULL;
   }
 
-  char inFname[1024];  /* don't remember what's this for !!! */
   if (!ABF_Close( hFile, &nError )) {
     ShowABFError(inFname, nError);
   }
     printf("Out of mem\n");
     return FALSE;
   }
-  for(DWORD i=1; i<=(DWORD)pFH->lActualEpisodes; I++) {
+  printf("pszFileName=%s,nFile=%d,nChannel=%d, uNumSamples:%d\n",
+	 pszFileName,
+	 nFile,
+	 nChannel,
+	 uNumSamples);
+  for(DWORD i=1; i<=(DWORD)pFH->lActualEpisodes; I++,i++) {
     if(!ABF_GetWaveform(nFile, pFH, nChannel, I, pfBuffer,&nError)) {
-      free(pfBuffer);
+      /* free(pfBuffer); */
       return ShowABFError(pszFileName, nError);
     }
-    printf("Episode %lu\n", i);
+    printf("Episode %lu (note axon example starts counting from 1 not zero)\n", i);
     for(UINT j=0; j<uNumSamples;j++) {
       printf("%g\n", pfBuffer[j]);
     }
   return TRUE;
 }
 
+static PyObject*
+abf_show_waveforms_test(PyObject *self, PyObject *args)
+/* abf_get_cmdwaveform(file_name, episode, channel) */
+{
+  char *file_name;
+  int episode_num;
+  int channel_num;
+  int hFile;
+  int nError;
+  ABFFileHeader FH;
+  DWORD dwMaxEpi = 0;
+  DWORD dwEpisode;
+  UINT uMaxSamples = START_DATA_BUFSIZE; 
+  UINT uNumSamples = 0;
+  
+  char test_file_name[] = "/home/clee/code/python-axonbinaryfile/tests/simple-vc-MT-2.abf"; 
 
+  if(!PyArg_ParseTuple(args, "s", &file_name)) {
+    return NULL;
+  }
+  printf("ignoring file_name, using test_file_name: %s\n", test_file_name);
 
+  BOOL bSuccess= ABF_ReadOpen(tets_file_name, &hFile, ABF_DATAFILE, &FH,
+			      &uMaxSamples, &dwMaxEpi, &nError);
+  printf("past attempt open, bSuccess=%d\n", bSuccess);
+  if (!bSuccess) {
+    return NULL;
+  }
+  printf("success");
+  ShowWaveforms(file_name, hFile, &FH, 0);
+  
+  if (!ABF_Close( hFile, &nError )) {
+    ShowABFError(file_name, nError);
+  }
+
+  Py_RETURN_NONE;
+}
 
 static PyMethodDef _abf_methods[] = {
   //  {"abf_smoke_test", abf_test, METH_VARARGS, "test out module compilation"},
   {"get_cmdwaveform", abf_get_cmdwaveform, METH_VARARGS, ""
    "Read a axon binary file and return the command waveform for that recorded in episodic mode.\n"
    " arr = get_cmdwaveform('filename.abf',dac_channel_num, episode_num)\n"
+   "Axon's C function appears to count episodes starting at 1\n"
    " arr is 1 dimensional numpy array of floats (32 bit).\n"},
+  {"show_waveforms_test", abf_show_waveforms_test, METH_VARARGS,"test function to show a files waveforms by printf'ing them out"},
   {NULL,NULL, 0, NULL}
 };