[Kst] getdata patch

Matthew D Truch matt at truch.net
Fri Jan 6 19:52:22 CET 2006


Attached is a patch I'd like to apply to getdata (the 'library' for the
dirfile reader), but I'm going to ask here first.  It modifies no code
that kst uses; it merely adds a new function to getdata that lets you
close all the open files getdata has for a given dirfile.  I'd like to
apply it just to make things easy in keeping kst's getdata in sync with
the getdata we use in other blast analysis programs.  

The reason I want the close function is: when you read files over nfs,
often there are errors (nfs sucks).  Generally this causes the file to
become stale; a re-read will continue to fail, unless you close and
reopen the file first.  With GetDataClose(), you can close all the
files, and the next time you try and read them, GetData will open and
read for you.  

-- 
"If you drop your keys into a river of molten lava, forget about them, they're gone!"
--------------------------
Matthew Truch
Department of Physics
Brown University
matt at truch.net
http://matt.truch.net/
-------------- next part --------------
Index: kst/kst/datasources/dirfile/getdata.h
===================================================================
--- kst/kst/datasources/dirfile/getdata.h	(revision 494990)
+++ kst/kst/datasources/dirfile/getdata.h	(working copy)
@@ -75,4 +75,14 @@
 #endif
 struct FormatType *GetFormat(const char *filedir, int *error_code);
 
+/***************************************************************************/
+/*                                                                         */
+/*    Close all open file descriptors for a given dirfile                  */
+/*                                                                         */
+/***************************************************************************/
+#ifdef __cplusplus
+extern "C"
 #endif
+int GetDataClose(const char *filename_in, int *error_code);
+
+#endif
Index: kst/kst/datasources/dirfile/getdata.c
===================================================================
--- kst/kst/datasources/dirfile/getdata.c	(revision 494990)
+++ kst/kst/datasources/dirfile/getdata.c	(working copy)
@@ -1850,5 +1850,49 @@
 
   return GetSPF(field_name, F, error_code);
 }
+
+/***************************************************************************/
+/*                                                                         */
+/*    Close all the open file descriptors for raw fields in a dirfile      */
+/*    Returns the number of files closed and sets error_code as appropriate*/
+/*                                                                         */
+/***************************************************************************/
+int GetDataClose(const char *filename_in, int *error_code) {
+  struct FormatType *F;
+  char filename[MAX_FILENAME_LENGTH+1];
+  int i;
+  int n_closed;
+
+  *error_code = GD_E_OK;
+  n_closed = 0;
+
+  if (first_time) {
+    Formats.n = 0;
+    Formats.F = NULL;
+    first_time = 0;
+    return n_closed;
+  }
+  
+  strncpy(filename, filename_in, MAX_FILENAME_LENGTH);
+  if (filename[strlen(filename)-1]=='/') filename[strlen(filename)-1]='\0';
+  F = GetFormat(filename, error_code);
+  if (*error_code!=GD_E_OK) {
+    return n_closed;
+  }
+  
+  if (!F || F->n_raw==0) {
+    *error_code = GD_E_FORMAT;
+    return n_closed;
+  }
+
+  for (i = 0; i < F->n_raw; i++) {
+    if (close(F->rawEntries[i].fp) == 0)
+      n_closed++;
+    F->rawEntries[i].fp = -1;
+  }
+  
+  return n_closed;
+}
+
 /* vim: ts=2 sw=2 et
 */
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.kde.org/pipermail/kst/attachments/20060106/f6d6711f/attachment.pgp


More information about the Kst mailing list