Ejemplo n.º 1
0
static inline int read_csv_file(proc_instance_t * proc, wsdata_t * tdata) {
     int hasdata = 0;
     char buf[READ_BUFSIZE];
     //read from stdin.. list of files..
     if (proc->fp && gzgets(proc->fp, buf, READ_BUFSIZE)) {
          hasdata = 1;
     }
     else if (!proc->straight_data && local_scour_stdin(proc)) {
          if (proc->fp && gzgets(proc->fp, buf, READ_BUFSIZE)) {
               hasdata = 1;
          }
     }
     if (!hasdata) {
          //proc->badline_cnt++;
          return 0;
     }

     int len = strlen(buf);
     if (len <= 1) {
          dprint("line too short, ignoring");
          proc->badline_cnt++;
          return 1;
     }

     // ignore comments
     if (buf[0] == '#') {
          dprint("line is comment, ignoring");
          return 1;
     }

     return read_csv_buffer(proc, tdata, buf, len);
}
Ejemplo n.º 2
0
long int csv_compressed_read_vector_grid(char *filename_csv,  
                          long int ni, long int nj, long int nk,
                          double *v0, double *v1, double *v2) {
  gzFile *fp;
  long int i, j, k, count;
  char text[1024];
  char filename[1024];
  double f, g, h;

  if(filename_csv == NULL || v0 == NULL || v1 == NULL || v2 == NULL) {
    printf("error: passed null arguments to csv_read_scalar_grid\n");
    return -1;
  }

  strncpy(filename, filename_csv, strlen(filename_csv) + 1);
  strncat(filename, ".gz", 3);
  fp = gzopen(filename, "r");

  if(fp == NULL) {
    printf("error: csv_compressed_read_vector_grid cannot open %s to read\n", filename);
    return -1;
  }

  if(!gzgets(fp, text, sizeof(text)))
  { 
    if(!gzeof(fp)) {
      printf("error: gzgets in csv_compressed_read_vector_grid\n");
      return(-1);
    }
    return 0;
  }

  count=0;
  while(!gzeof(fp))
  {
    if(!gzgets(fp, text, sizeof(text)))
    { 
      if(!gzeof(fp)) {
        printf("error: gzgets in csv_compressed_read_vector_grid\n");
        return(-1);
      }
      break;
    }
    sscanf(text, "%ld%*c %ld%*c %ld%*c %lf%*c %lf%*c %lf%*c", &i, &j, &k, &f, &g, &h);
    
    if(i>ni || j>nj || k>nk) {
      printf("error: data out of bounds in csv_compressed_read_vector_grid\n");
      break;
    }

    v0[CELL_INDEX(i,j,k)] = f;
    v1[CELL_INDEX(i,j,k)] = g;
    v2[CELL_INDEX(i,j,k)] = h;
    count++;
  }

  gzclose(fp);

  return count;
}
Ejemplo n.º 3
0
long int csv_compressed_read_integer_grid(char *filename_csv,  
                          long int ni, long int nj, long int nk,
                          int *scalars) {
  FILE *fp;
  long int i, j, k, count;
  char text[1024];
  char filename[1024];
  int f;

  if(filename_csv == NULL || scalars == NULL) {
    printf("error: passed null arguments to csv_read_scalar_grid\n");
    return -1;
  }

  strncpy(filename, filename_csv, strlen(filename_csv) + 1);
  strncat(filename, ".gz", 3);
  fp = gzopen(filename, "r");

  if(fp == NULL) {
    printf("error: csv_compressed_read_scalar_grid cannot open %s to read\n", filename);
    return -1;
  }

  if(!gzgets(fp, text, sizeof(text)))
  { 
    if(!gzeof(fp)) {
      printf("error: fgets in csv_compressed_read_scalar_grid\n");
      return(-1);
    }
    return 0;
  }

  count=0;
  while(!gzeof(fp))
  {
    if(!gzgets(fp, text, sizeof(text)))
    { 
      if(!gzeof(fp)) {
        printf("error: gzgets in csv_compressed_read_integer_grid\n");
        return(-1);
      }
      break;
    }
    sscanf(text, "%ld%*c %ld%*c %ld%*c %d", &i, &j, &k, &f);
    
    if(i>ni || j>nj || k>nk) {
      printf("error: data out of bounds in csv_compressed_read_integer_grid\n");
      break;
    }

    scalars[CELL_INDEX(i,j,k)] = f;
    count++;
  }

  gzclose(fp);

  return count;
}
Ejemplo n.º 4
0
/**
 * Loads a feature vector form a file stream
 * @param z Stream point
 * @return Feature vector
 */
fvec_t *fvec_load(gzFile * z)
{
    assert(z);
    fvec_t *f;
    char buf[512], str[512];
    int i, r;

    /* Allocate feature vector (zero'd) */
    f = calloc(1, sizeof(fvec_t));
    if (!f) {
        error("Could not load feature vector");
        return NULL;
    }

    gzgets(z, buf, 512);
    r = sscanf(buf, "feature vector: len=%lu, total=%lu, mem=%lu, src=%s\n",
               (unsigned long *) &f->len, (unsigned long *) &f->total,
               (unsigned long *) &f->mem, str);
    if (r != 4) {
        error("Could not parse feature vector");
        fvec_destroy(f);
        return NULL;
    }

    /* Set source */
    if (!strcmp(str, "(null)"))
        f->src = NULL;
    else
        f->src = strdup(str);

    /* Empty feature vector */
    if (f->len == 0)
        return f;

    /* Allocate arrays */
    f->dim = (feat_t *) malloc(f->len * sizeof(feat_t));
    f->val = (float *) malloc(f->len * sizeof(float));
    if (!f->dim || !f->val) {
        error("Could not allocate feature vector contents");
        fvec_destroy(f);
        return NULL;
    }

    /* Load features */
    for (i = 0; i < f->len; i++) {
        gzgets(z, buf, 512);
        r = sscanf(buf, "  %llx:%g\n", (unsigned long long *) &f->dim[i],
                   (float *) &f->val[i]);
        if (r != 2) {
            error("Could not parse feature vector contents");
            fvec_destroy(f);
            return NULL;
        }
    }

    return f;
}
Ejemplo n.º 5
0
int val_bed(int argc, char**argv){
  if(argc!=1){
    fprintf(stderr,"val_bed FILE.gz \n");
    exit(0);
  }
  char *base = *argv;
  char* outnames_bin = append(base,BIN);
  char* outnames_gz = base;
  fprintf(stderr,"Assuming binfile:%s and gzfile:%s\n",outnames_bin,outnames_gz);
  
  
  BGZF *fp = bgzf_open(outnames_bin,"r");
  gzFile gz =gzopen(outnames_gz,"r");
  char buf[4096];
  gzgets(gz,buf,4096);
  while(1){
    perChr pc = getPerChr(fp);
    if(pc.nSites==0)
      break;
    fprintf(stderr,"pc.chr=%s pc.nSites=%zu firstpos=%d lastpos=%d\n",pc.chr,pc.nSites,pc.posi[0],pc.posi[pc.nSites-1]);
    for(size_t i=0;i<pc.nSites;i++){
      gzgets(gz,buf,4096);
      char *chr = strtok(buf,"\n\t ");
      if(strcmp(chr,pc.chr)!=0){
	fprintf(stderr,"Problem with nonmatching chromosome: \'%s\' vs \'%s\'\n",chr,pc.chr);
	exit(0);
      }
      int posi =atoi(strtok(NULL,"\t\n "));
      if(posi!=pc.posi[i]){
	fprintf(stderr,"Problem with nonmatching position\n");
	exit(0);
      }
      float tW = atof(strtok(NULL,"\t\n "));
      float tP = atof(strtok(NULL,"\t\n "));
      float tF = atof(strtok(NULL,"\t\n "));
      float tH = atof(strtok(NULL,"\t\n "));
      float tL = atof(strtok(NULL,"\t\n "));
      fun(tW,pc.tW[i]);
      fun(tP,pc.tP[i]);
      fun(tF,pc.tF[i]);
      fun(tH,pc.tH[i]);
      fun(tL,pc.tL[i]);
    }
    fprintf(stderr,"FILE: %s chr: %s OK\n",base,pc.chr); 
    dalloc(pc);
  }

  fprintf(stderr,"ALL OK: %s\n",base);
  return 0;
}
Ejemplo n.º 6
0
void *Get_read(gzFile FP,_Fastq_ *read){
	if (gzgets(FP,read->id, 256)!=NULL)
	{
		gzgets(FP,read->seq,256);
		gzgets(FP,read->qual,256);
		gzgets(FP,read->qual,256);
	}else{
		return NULL;
	}
	if(read->seq[strlen(read->seq)-1] == '\n'){read->seq[strlen(read->seq)-1] = '\0';}
	if(read->id[strlen(read->id)-1] == '\n'){read->id[strlen(read->id)-1] = '\0';}
	if(read->qual[strlen(read->qual)-1] == '\n'){read->qual[strlen(read->qual)-1] = '\0';}
	return read;
}
Ejemplo n.º 7
0
char *
fgets2 (char *buffer, int maxlength, FILE *file)
{
#undef  fgets
  fmode2_t fmode = get_fmode (file);

  if (fmode == FM_NORMAL)
    return fgets (buffer, maxlength, file);
  else if (fmode == FM_GZIP)
    {
      char *retval = gzgets (file, buffer, maxlength);
      return retval == Z_NULL ? NULL : retval;
    }
  else if (fmode == FM_ZIP)
    {
      int n = 0, c = 0;
      while (n < maxlength - 1 && (c = fgetc (file)) != EOF)
        {
          buffer[n] = c;                        // '\n' must also be stored in buffer
          n++;
          if (c == '\n')
            {
              buffer[n] = 0;
              break;
            }
        }
      if (n >= maxlength - 1 || c == EOF)
        buffer[n] = 0;
      return n > 0 ? buffer : NULL;
    }
  else
    return NULL;
#define fgets   fgets2
}
Ejemplo n.º 8
0
/* Returns 1 if the city is proper version */ /* AL1 unused in NG 1.1 */
int 
verify_city (char *cname)
{
    gzFile fp;
    char* s;
    char str[256];
    int v;

    if (strlen(cname) == 0) {
	return 0;
    }
    if ((s = (char *) malloc (lc_save_dir_len + strlen(cname) + 2)) == 0)
	malloc_failure ();
    sprintf (s, "%s%c%s", lc_save_dir, PATH_SLASH, cname);
    if (!file_exists(s)) {
	free (s);
	return 0;
    }
    fp = gzopen( s, "r" );
    if (fp == NULL) {
	v = 0;
    } else if (1 != sscanf ( gzgets( fp, str, 256 ) , "%d", &v)) {
	v = 0;
    }
    gzclose(fp);
    free (s);
    return v == VERSION_INT;
}
Ejemplo n.º 9
0
char* mio_gets(const MFP* mfp, char* buf, int len)
{
   char* s = NULL;
   
   assert(mfp_is_valid(mfp));

   switch(mfp->type)
   {
   case MFP_STRG :
      s = strgfile_gets(mfp->fp.strg, buf, len);
      break;
   case MFP_FILE :
   case MFP_PIPE :
      s = fgets(buf, len, mfp->fp.file);
      break;
#ifndef WITHOUT_ZLIB
   case MFP_ZLIB :
      s = gzgets(mfp->fp.zlib, buf, len);
      break;
#endif /* ! WITHOUT_ZLIB */
   default :
      abort();
   }
   return s;
}
Ejemplo n.º 10
0
bool CRapidDownloader::parse()
{
	gzFile fp=gzopen(path.c_str(), "r");
	if (fp==Z_NULL) {
		LOG_ERROR("Could not open %s", path.c_str());
		return false;
	}
	char buf[IO_BUF_SIZE];
	repos.clear();
	int i=0;
	while (gzgets(fp, buf, sizeof(buf))!=Z_NULL) {
		std::string tmp=buf;
		std::string url=getStrByIdx(tmp,',',1);
		i++;
		if (url.size()>0) { //create new repo from url
			CRepo repotmp=CRepo(url, this);
			repos.push_back(repotmp);
		} else {
			LOG_ERROR("Parse Error %s, Line %d: %s",path.c_str(),i,buf);
			return false;
		}
	}
	gzclose(fp);
	LOG_INFO("Found %d repos in %s",repos.size(),path.c_str());
	return true;
}
Ejemplo n.º 11
0
beagle_reader::beagle_reader(int bytesPerLine_a,gzFile gz_a,const aMap *revMap_a,int intName_a,int &nInd_a){
  gz=gz_a;
  revMap=revMap_a;
  bytesPerLine = bytesPerLine_a;
  intName = intName_a;
  
  original=buffer =(char *) malloc(bytesPerLine);
  const char *delims = "\t \n";

  int nCol=1;

  gzgets(gz,buffer,bytesPerLine); 
  if(strlen(buffer)==bytesPerLine-1){
    fprintf(stderr,"\t-> Increase -bytesPerLine value\n");
    exit(0);
  }
  strtok_r(buffer,delims,&buffer);
  while(strtok_r(NULL,delims,&buffer))
    nCol++;
  if(nCol % 3 ){
    fprintf(stderr,"\t-> Number of columns should be a multiple of 3, nCol=%d\n",nCol);
    exit(0);
  } 
  nInd_a=nCol/3-1;
  nInd = nInd_a;
}
Ejemplo n.º 12
0
static TACommandVerdict gzgets_cmd(TAThread thread,TAInputStream stream)
{
    void* file;
    char* buf, *res;
    int len, errnum;

    file = readPointer(&stream);
    buf = (char*)readPointer(&stream);
    len = readInt(&stream);

    START_TARGET_OPERATION(thread);

    res = gzgets(file, buf, len);

    END_TARGET_OPERATION(thread);

    gzerror(file, &errnum);

    writeInt(thread, errnum);
    writePointer(thread, (void*)res);

    sendResponse(thread);

    return taDefaultVerdict;
}
Ejemplo n.º 13
0
aMap readvcf(const char *fname){
  gzFile gz = Z_NULL;
  gz=gzopen(fname,"rb");
  if(gz==Z_NULL){
    fprintf(stderr,"\t-> Problem opening file: %s\n",fname);
    exit(0);
  }
  int at=0;
  char buf[1024];
  aMap am;
  while(gzgets(gz,buf,1024)){
    char chr[1024];
    int pos;
    char al1,al2;
    if(4!=sscanf(buf,"%s\t%d\t%c\t%c\n",chr,&pos,&al1,&al2)){
      fprintf(stderr,"\t-> problem parsing line: %d which looks like: %s\n",at,buf);
    }
    char tmpnam[1024];
    sprintf(tmpnam,"%s %d",chr,pos);
    aMap::iterator it=am.find(tmpnam);
    if(it!=am.end()){
      fprintf(stderr,"\t-> Problem with duplicate positions: %s \n",tmpnam);
      //      exit(0);
    }
    am[strdup(tmpnam)]= at++;
  }
  fprintf(stderr,"\t-> read nsites from vcf:%lu\n",am.size());
  return am;
}
Ejemplo n.º 14
0
char *
uproc_io_gets(char *s, int size, uproc_io_stream *stream)
{
    char *res;
    switch (stream->type) {
        case UPROC_IO_GZIP:
#if HAVE_ZLIB_H
            res = gzgets(stream->s.gz, s, size);
            if (!res) {
                int num;
                const char *msg = gzerror(stream->s.gz, &num);
                if (num != Z_OK && num != Z_STREAM_END) {
                    uproc_error_msg(UPROC_EIO,
                                    "failed to read from gz stream: %d %s", num, msg);
                }
            }
            break;
#endif
        case UPROC_IO_STDIO:
            res = fgets(s, size, stream->s.fp);
            if (!res && ferror(stream->s.fp)) {
                uproc_error_msg(UPROC_EIO, "failed to read from stream");
            }
            break;
        default:
            uproc_error_msg(UPROC_EINVAL, "invalid stream");
            return NULL;
    }
    return res;
}
Ejemplo n.º 15
0
void readGL2(gzFile fp,size_t nSites,int nChr,Matrix<double> &ret){
  //  fprintf(stderr,"[%s] fname:%s nSites:%d nChr:%d\n",__FUNCTION__,fname,nSites,nChr);
  ret.y=nChr+1;
  char buf[LENS];
  size_t i=0;
  while(gzgets(fp,buf,LENS)){
    //strange construct for strtok, because firstcall if with buf, rest with NULL
    for(char *tok = strtok(buf,"\t\n ");tok!=NULL;tok=strtok(NULL,"\t\n ")){
      if(tok[0]=='#')
	continue;
      gzFile gz = getGz(buf);
    
      while(SIG_COND&&gzread(gz,ret.mat[i],sizeof(double)*(nChr+1))){
	for(size_t j=0;j<nChr+1;j++)
	  ret.mat[i][j] = exp(ret.mat[i][j]);
	i++;
      }
      fprintf(stderr,"Done reading file: \'%s\'\n",buf);
      gzclose(gz);
      ret.x=i;
    }
  }
  if(SIG_COND==0)
    exit(0);
  
}
Ejemplo n.º 16
0
void vcf_file::read_line(string &out)
{
	char * tmp;
	out = "";
	if (!compressed)
	{
		getline(*file_in, out);
		out.erase( out.find_last_not_of(" \t\n\r") + 1);	// Trim whitespace at end of line
	}
	else
	{
		bool again = true;
		while (again == true)
		{
			tmp = gzgets(gzfile_in, gz_readbuffer, gzMAX_LINE_LEN);
			if (tmp == NULL)
				return;

			out.append(gz_readbuffer);
			if ((strlen(gz_readbuffer) != gzMAX_LINE_LEN-1) || (gz_readbuffer[gzMAX_LINE_LEN-2] == '\n'))
				again = false;
		}
		out.erase( out.find_last_not_of(" \t\n\r") + 1);	// Trim whitespace at end of line (required in gzipped case!)
	}
}
Ejemplo n.º 17
0
static gboolean
process_log_gzstream (gzFile   fstream,
                      GTimeVal *since)
{
        char     line[MAX_LINE_LEN];
        gboolean hit_since;
        GList   *events;

        events = NULL;
        hit_since = FALSE;
        while (gzgets (fstream, line, sizeof (line)) != Z_NULL) {
                CkLogEvent *event;

                if (strlen (line) == sizeof (line) - 1) {
                        g_warning ("Log line truncated");
                }

                event = parse_event_line (line);
                if (event == NULL) {
                        continue;
                }

                if (since == NULL || event->timestamp.tv_sec >= since->tv_sec) {
                        events = g_list_prepend (events, event);
                } else {
                        hit_since = TRUE;
                }
        }

        all_events = g_list_concat (all_events, events);

        return !hit_since;
}
Ejemplo n.º 18
0
bool CRapidDownloader::parse()
{
	FILE* f = fileSystem->propen(path, "rb");
	if (f == NULL) {
		return false;
	}
	gzFile fp = gzdopen(fileno(f), "rb");
	if (fp == Z_NULL) {
		fclose(f);
		LOG_ERROR("Could not open %s", path.c_str());
		return false;
	}
	char buf[IO_BUF_SIZE];
	repos.clear();
	int i = 0;
	while (gzgets(fp, buf, sizeof(buf)) != Z_NULL) {
		const std::string line = buf;
		const std::vector<std::string> items = tokenizeString(line, ',');
		if (items.size() <= 2) { // create new repo from url
			gzclose(fp);
			fclose(f);
			LOG_ERROR("Parse Error %s, Line %d: %s", path.c_str(), i, buf);
			return false;
		}
		i++;
		CRepo repotmp = CRepo(items[1], items[0], this);
		repos.push_back(repotmp);
	}
	gzclose(fp);
	fclose(f);
	LOG_INFO("Found %d repos in %s", repos.size(), path.c_str());
	return true;
}
Ejemplo n.º 19
0
/*Read gz with two element file into vector
Input: gzip-file-name, size of elements, vector to write to
*/
void read_gzip_2_unsigned_file(string gzip_file_name,
                               unsigned size,
                               vector<pair<unsigned, unsigned>>& output) {
  gzFile gzip_file;
#ifdef DDEBUG
  cerr << gzip_file_name << endl;
#endif
  gzip_file = gzopen(gzip_file_name.c_str(), "r");
  unsigned i = 0;
  while (!gzeof(gzip_file) && i < size) {
    char buffer[256];
    gzgets(gzip_file, buffer, 256);
    unsigned element1, element2;
    sscanf(buffer, "%d,%d", &element1, &element2);
    output.at(i).first = element1;
    output.at(i).second = element2;
    i++;
  }
  gzclose(gzip_file);

  if (i == 0) {
    cerr << "file not open " << gzip_file_name << endl;
    exit(0);
  }
}
Ejemplo n.º 20
0
static cmph_uint32 count_nlfile_keys(gzFile *fd)
{
	cmph_uint32 count = 0;
	gzrewind(fd);
	
//	count=3775790711UL;
//	count=477579071UL;
//	count=1285501694UL; //google 1+2+3 grams;
//	count=1313818354UL; //google 4 grams;
//	count=1176470663UL; //google 5 grams;
	
	fprintf(stderr,"\nCounting Lines in File\n");
	
	register char * ptr;
	while(1)
	{
		if (gzeof(fd)) break; //I had to rearrange the order of this, i should file a bug
		char buf[BUFSIZ];
		ptr = gzgets(fd,buf,BUFSIZ);
		if (buf[strlen(buf) - 1] != '\n') {
			if (gzeof(fd)&&strlen(buf)>1) {++count; break;} //this is in case the last line does not have a \n
			 continue;
		}
		++count;
	}
	gzrewind(fd);
	 
	fprintf(stderr,"\nDone counting.  File is %u lines long\n",count);
	return count;
}
Ejemplo n.º 21
0
gboolean read_data(FILE *file, gboolean is_compressed, GString *data, gboolean *eof) {
	char buffer[256];

	do {
		if (!is_compressed) {
			if (fgets(buffer, 256, file) == NULL) {
				if (feof(file)) {
					*eof= TRUE;
					buffer[0]= '\0';
				} else {
					return FALSE;
				}
			}
		} else {
			if (!gzgets((gzFile)file, buffer, 256)) {
				if (gzeof((gzFile)file)) {
					*eof= TRUE;
					buffer[0]= '\0';
				} else {
					return FALSE;
				}
			}
		}
		g_string_append(data, buffer);
	} while ((buffer[strlen(buffer)] != '\0') && *eof == FALSE);

	return TRUE;
}
Ejemplo n.º 22
0
//----------------------------------------------------
char *zu_gets(ZUFILE *f, char *buf, int len)
{
    int nb = 0;
    int bzerror=BZ_OK;
    char *ret = NULL;
    switch(f->type) {
        case ZU_COMPRESS_NONE :
            if((ret = fgets(buf, len, (FILE*)(f->zfile))))
                nb = strlen(buf);
            break;
        case ZU_COMPRESS_GZIP :
            if((ret = gzgets((gzFile)(f->zfile), buf, len)))
                nb = strlen(buf);
            break;
        case ZU_COMPRESS_BZIP :
            nb = BZ2_bzRead(&bzerror,(BZFILE*)(f->zfile), buf, len-1);
            for(int i=0; i<nb; i++)
                if(buf[i] == '\n') {
                    int seek = f->pos;
                    f->pos += nb;
                    buf[i+1] = '\0';
                    return zu_seek(f, seek + i + 1, SEEK_SET) == -1 ? NULL : buf;
                }
            if(nb > 0) {
                buf[nb] = '\0';
                ret = buf;
            }
    }
    f->pos += nb;
    return ret;
}
bool GenomicRegionCollection<T>::ReadVCF(const std::string & file, const BamHeader& hdr) {

  m_sorted = false;
  idx = 0;

  gzFile fp = NULL;
  fp = strcmp(file.c_str(), "-")? gzopen(file.c_str(), "r") : gzdopen(fileno(stdin), "r");
  
  if (file.empty() || !fp) {
    std::cerr << "VCF file not readable: " << file << std::endl;
    return false;
  }

  // http://www.lemoda.net/c/gzfile-read/
  while (1) {

    int err;                    
    char buffer[GZBUFFER];
    gzgets(fp, buffer, GZBUFFER);
    int bytes_read = strlen(buffer);

    // get one line
    if (bytes_read < GZBUFFER - 1) {
      if (gzeof (fp)) break;
      else {
	const char * error_string;
	error_string = gzerror (fp, &err);
	if (err) {
	  fprintf (stderr, "Error: %s.\n", error_string);
	  exit (EXIT_FAILURE);
	}
      }
    }

    // prepare to loop through each field of BED line
    std::string chr, pos;
    std::string line(buffer);
    std::istringstream iss_line(line);
    std::string val;
    if (line.empty() || line.at(0) == '#')
      continue;

    // read first two columnes
    iss_line >> chr >> pos;

    // construct the GenomicRegion
    T gr;
    try {
      gr = T(chr, pos, pos, hdr);
    } catch (...) {
      std::cerr << "...Could not parse pos: " << pos << std::endl << std::endl
		<< "...on line " << line << std::endl;
      
    }
    if (gr.chr >= 0) 
      m_grv->push_back(gr);
  }

  return true;
}
Ejemplo n.º 24
0
char * znzgets(char* str, int size, znzFile file)
{
  if (file==NULL) { return NULL; }
#ifdef HAVE_ZLIB
  if (file->zfptr!=NULL) return gzgets(file->zfptr,str,size);
#endif
  return fgets(str,size,file->nzfptr);
}
Ejemplo n.º 25
0
void next_line(char *line,int maxline)
{
  if (gzgets(infile,line,maxline) == NULL) {
    if (gzeof(infile)) { line[0] = '\0'; return; }
    perror("reflbin");
    exit(1); /* Read failed unexpectedly */
  }
}
Ejemplo n.º 26
0
/* Scan one frame of the file to compute the frame size for each point. */
int icp_framesize(gzFile infile, int *rows, int *columns, int *values)
{
  char line[MAX_LINE], token[MAX_LINE];
  const char *pline;
  int ch, ncomma=0, nsemicolon=0, nvalues=0;
  z_off_t restore_pos;

  /* Save position */
  restore_pos = gztell(infile);

  /* Get the values line */
  if (gzgets(infile, line, sizeof(line)-1) == NULL) return ICP_READ_ERROR;
  line[sizeof(line)-1] = '\0';

  /* Scan the first detector frame */
  ch = gzgetc(infile); /* Skip format column character */
  if (ch >= 0) ch = gzgetc(infile); /* Peek at first frame character */
  if (ch == ' ' || ch == '-' || ch < 0) {
    /* Empty frame, so return size 0x0 */
    *rows = *columns = 0;
  } else {
    /* Frame isn't empty so count number of commas and semicolons in frame. */
    while (ch >= 0) {
      ch = gzgetc(infile);
      if (ch == ',') ncomma++;
      else if (ch == ';') nsemicolon++;
      else if (ch == '\r') /* ignored */ ;
      else if (ch == '\n') {
	ch = gzgetc(infile); /* Skip format column character */
	if (ch >= 0) ch = gzgetc(infile);
	if (ch==' ' || ch=='-') break;
      }
    }

    /* last row does not end in semicolon so add 1
     * last column does not end in comma so add 1
     */
    *rows = nsemicolon + 1;
    *columns = (ncomma / *rows) + 1;
  }


  /* Count the number of tokens on the line */
  //printf("line=%s\n",line);
  pline = line;
  while (pline) {
    pline = scan_token(pline, sizeof(token), token);
    if (!*token || *token == '\n') break;
    nvalues++;
    //printf("values=%s\n",token);
  }
  *values = nvalues;
  
  /* Restore position */
  gzseek(infile, restore_pos, SEEK_SET);
  return ICP_GOOD;
}
Ejemplo n.º 27
0
char *cfgets(cfp * fp, char *buf, int len)
{
#ifdef HAVE_LIBZ
	if (fp->compressedfp)
		return gzgets(fp->compressedfp, buf, len);
	else
#endif
		return fgets(buf, len, fp->uncompressedfp);
}
Ejemplo n.º 28
0
static int error_log_get_line( error_log_cursor *c )
{
    char   *cptr;
    int    rc = SQLITE_OK;

    c->row++;                          /* advance row (line) counter */
    c->line_ptrs_valid = 0;            /* reset scan flag */
    cptr = gzgets( c->fptr, c->line, LINESIZE );
    if ( cptr == NULL ) {  /* found the end of the file/error */
        if (gzeof( c->fptr ) ) {
            c->eof = 1;
        } else {
            rc = -1;
        }
        return rc;
    }
    /* find end of buffer and make sure it is the end a line... */
    cptr = c->line + strlen( c->line ) - 1;       /* find end of string */
    if ( ( *cptr != '\n' )&&( *cptr != '\r' ) ) { /* overflow? */
        char   buf[1024], *bufptr;
        /* ... if so, keep reading */
        while ( 1 ) {
            bufptr = gzgets( c->fptr, buf, sizeof( buf ) );
            if ( bufptr == NULL ) {  /* found the end of the file/error */
                if (gzeof( c->fptr ) ) {
                    c->eof = 1;
                } else {
                    rc = -1;
                }
                break;
            }
            bufptr = &buf[ strlen( buf ) - 1 ];
            if ( ( *bufptr == '\n' )||( *bufptr == '\r' ) ) {
                break;               /* found the end of this line */
            }
        }
    }

    while ( ( *cptr == '\n' )||( *cptr == '\r' ) ) {
        *cptr-- = '\0';   /* trim new-line characters off end of line */
    }
    c->line_len = ( cptr - c->line ) + 1;
    return rc;
}
bool GenomicRegionCollection<T>::ReadBED(const std::string & file, const BamHeader& hdr) {

  m_sorted = false;
  idx = 0;

  gzFile fp = NULL;
  fp = strcmp(file.c_str(), "-")? gzopen(file.c_str(), "r") : gzdopen(fileno(stdin), "r");

  if (file.empty() || !fp) {
    std::cerr << "BED file not readable: " << file << std::endl;
    return false;
  }

  // http://www.lemoda.net/c/gzfile-read/
  while (1) {

    int err;                    
    char buffer[GZBUFFER];
    gzgets(fp, buffer, GZBUFFER);
    int bytes_read = strlen(buffer);

    // get one line
    if (bytes_read < GZBUFFER - 1) {
      if (gzeof (fp)) break;
      else {
	const char * error_string;
	error_string = gzerror (fp, &err);
	if (err) {
	  fprintf (stderr, "Error: %s.\n", error_string);
	  exit (EXIT_FAILURE);
	}
      }
    }

    // prepare to loop through each field of BED line
    //size_t counter = 0;
    std::string chr, pos1, pos2;
    std::string line(buffer);
    std::istringstream iss_line(line);
    std::string val;
    if (line.find("#") != std::string::npos) 
      continue;
    
    // read first three BED columns
    iss_line >> chr >> pos1 >> pos2;

    // construct the GenomicRegion
    T gr(chr, pos1, pos2, hdr);
    
    if (gr.chr >= 0)
      m_grv->push_back(gr);
  }

  return true;
}
Ejemplo n.º 30
0
gchar * gw_zfile_readline_sb ( gzFile fic, GWStringBuffer **sb)
{
	gchar buf[MAX_LINE+1];
	gchar *line = NULL;
	int ret = 0;
	gulong sb_size = 0;
	gulong sb_len = 0;


#ifdef GW_DEBUG_TOOLS_COMPONENT
	g_print ( "*** GW - %s (%d) :: %s()\n", __FILE__, __LINE__, __PRETTY_FUNCTION__);
#endif

	memset(buf,'\0',MAX_LINE+1);
	if ( *sb == NULL )
	{
		*sb = gw_string_buffer_new ( );
		gw_string_buffer_resize ( *sb, MAX_LINE);
	}

	line = gw_string_buffer_get_str(*sb);
	gw_string_buffer_delete_all ( *sb);
	sb_size = gw_string_buffer_get_size ( *sb);
	line = gw_string_buffer_get_str(*sb);

	do
	{
		memset(buf,'\0',MAX_LINE+1);
		ret = (int)gzgets ( fic, buf, MAX_LINE);
		gw_string_buffer_append_str ( *sb, buf, strlen(buf));
		line = gw_string_buffer_get_str ( *sb);
		sb_len = strlen ( line);
	} while ( (ret != Z_NULL) && (sb_len != 0) && ((line)[sb_len - 1] != '\n'));

	if ( sb_len > 0 )
	{
		/* In order to eraze the final '\n' character. */
		line[sb_len - 1] = '\0';
		memset(&line[sb_len-1],'\0',(gw_string_buffer_get_size ( *sb)-sb_len+1));
	}

#ifdef GW_DEBUG_TOOLS_COMPONENT
	g_print ( "*** GW - %s (%d) :: %s() : current_line=%s\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, line);
#endif

	if ( ret==Z_NULL) {
		line = NULL;
#ifdef GW_DEBUG_TOOLS_COMPONENT
		g_print ( "*** GW - %s (%d) :: %s() : END_OF_FILE\n", __FILE__, __LINE__, __PRETTY_FUNCTION__);
#endif
	}

	return line;
}