From 07b1eefa80db51e39bea1735b3ff4da0ae79179c Mon Sep 17 00:00:00 2001
From: Calvin <calvin@EESI>
Date: Wed, 15 May 2013 13:43:39 -0400
Subject: use zlib natively for sanity, and remove some crap, update makefile
 with -lz

---
 src/c/Makefile          |  2 +-
 src/c/quikr_functions.c | 26 ++++++++------------------
 2 files changed, 9 insertions(+), 19 deletions(-)

(limited to 'src/c')

diff --git a/src/c/Makefile b/src/c/Makefile
index ba0c799..152121a 100644
--- a/src/c/Makefile
+++ b/src/c/Makefile
@@ -1,7 +1,7 @@
 UNAME := $(shell uname)
 CC = gcc
 QUIKR_TRAIN_CFLAGS = -O3 -s -mtune=native -Wall -lm -lz -D$(UNAME)
-QUIKR_CFLAGS = -O3 -s -mtune=native -Wextra -Wall -lm -pthread -L../ -I../ -std=gnu99 -fopenmp -D$(UNAME)
+QUIKR_CFLAGS = -O3 -s -mtune=native -Wextra -Wall -lm -pthread -L../ -I../ -std=gnu99 -fopenmp -D$(UNAME) -lz
 all: quikr_train_ quikr_ multifasta_to_otu_
 
 multifasta_to_otu_:
diff --git a/src/c/quikr_functions.c b/src/c/quikr_functions.c
index 7e18e64..31afb3b 100644
--- a/src/c/quikr_functions.c
+++ b/src/c/quikr_functions.c
@@ -6,6 +6,7 @@
 #include <unistd.h>
 #include <string.h>
 #include <math.h>
+#include <zlib.h>
 
 int count_sequences(char *filename) { 
   char command[512];
@@ -86,19 +87,14 @@ double *load_sensing_matrix(char *filename, int height, int width) {
   int x = 0;
   int y = 0;
 
-  char *line = NULL;
-  char *val;
-  char command[512];
-  size_t len = 0;
-  FILE *sensing_matrix_fh = NULL;
+  gzFile sensing_matrix_fh = NULL;
 
   double *sensing_matrix = malloc(height * width * sizeof(double));
   if(sensing_matrix == NULL) {
     fprintf(stderr, "Could not allocate memory for the sensing matrix\n");
   }
 
-  sprintf(command, "gzip -cd %s", filename);
-  sensing_matrix_fh = popen(command, "r");
+  sensing_matrix_fh = gzopen(filename, "r");
   if(sensing_matrix_fh == NULL) {
     fprintf(stderr, "could not open %s", filename);
     exit(EXIT_FAILURE);
@@ -106,20 +102,14 @@ double *load_sensing_matrix(char *filename, int height, int width) {
 
   // read our sensing matrix in
   for(x = 0; x < height; x++) {
-    getline(&line, &len, sensing_matrix_fh);
-    char *ptr;
-
-    // Read our first element in outside of the loop
-    val = strtok_r(line,"\t", &ptr);
-    sensing_matrix[width*x + 1] = atof(val);
-    // iterate through and load the array
-    for (y = 2; y < width; y++) {
-      val = strtok_r(NULL, "\t", &ptr);
-      sensing_matrix[width*x + y] = atof(val);
+    for (y = 1; y < width; y++) {
+      char buffer[14];
+      gzgets(sensing_matrix_fh, buffer, 14); 
+      sensing_matrix[width*x + y] = atof(buffer);
     }
   }
 
-  pclose(sensing_matrix_fh);
+  gzclose(sensing_matrix_fh);
 
   return sensing_matrix;
 }
-- 
cgit v1.2.3