OBJECT *line2ob(char *line){
    char *tmpline;  /* temp copy */
    OBJECT *pob;
    char *token;
    int ntokens;
    NUMBER val;
    int i;

    ntokens = counttokens(line);
    pob = oballoc(ntokens);

    /* copy, because strtok() messed up tmpline */
    tmpline=strdup(line);

    assert(ntokens>0); /* no empty lines */
    i=0;
    token = strtok(tmpline, BLANKS);
    /* atof did not work! */
    /* val = (NUMBER) atof( token); */
    sscanf( token, "%lf", &val);
    obput(pob, i, val);
    for(i=1; i< ntokens; i++){
        token = strtok( (char *)NULL, BLANKS);
    	sscanf( token, "%lf", &val);
	obput(pob, i,val);
    }
    free(tmpline);
    return(pob);
}
/* measures the number of columns of the first line */
int countcolumns(FILE *fp){
    char *line;

    myrewind(fp);

    line= getline(fp);
    return( counttokens( line) );


}
BOOLEAN checkfile(FILE *fp){
    char *line;
    int nold, nnew;
    int linecount;
    BOOLEAN kosher = TRUE;

    myrewind(fp);

    /* read in the first line */
    line= getline(fp);
    linecount =1;
    if( feof(fp) ){
       return; /*empty file */
    }else{
	nold = counttokens(line);
#ifdef DEBUG
	/* printf("%d:\t%s", nold, line); */
#endif
    }

    line = getline(fp);
    while( !feof(fp) ){
	linecount ++;
        nnew = counttokens(line);
#ifdef DEBUG
	/* printf("%d:\t%s", nnew, line); */
#endif
	if( nnew != nold){ 
	   kosher = FALSE;
	   fprintf(stderr, "line %d has %d tokens; line %d has %d\n",
	      1, nold, linecount, nnew);
	}
	/* assert( nnew == nold ); */
	line = getline(fp);
    }

    myrewind(fp);
    return (kosher);
}
Esempio n. 4
0
int getnumpars(const char* key)
/*< get number of pars >*/
{
  char* par;
  int numpars=0;
  
  sf_warning("in getnumpars call sf_getstring key=%s\n",key);
  if(NULL==(par=sf_getstring(key)))return 0;
   
  numpars=counttokens(par,",");

  fprintf(stderr,"free(par)\n");
  free(par);
  
  return numpars;
}