Пример #1
0
void dblist(void)
{
    char *next, *wfdb = getwfdb();
    int first = 1;
   
    while (*wfdb) {
	/* Isolate the next component of the WFDB path. */
	for (next = wfdb; *next && next - wfdb < MFNLEN - 6; next++)
	    if (*next == ' ') { *next++ = '\0'; break; }
	/* Look for a "DBS" file in the next possible location. */
	sprintf(wfdb_filename, "%s/DBS", wfdb);
	if ((ifile = wfdb_fopen(wfdb_filename, "rb")) != NULL) {
	    if (first) printf("{ \"database\": [\n");
	    while (wfdb_fgets(buf, sizeof(buf), ifile)) {
		char *p, *name, *desc;

		for (p = buf; p < buf + sizeof(buf) && *p != '\t'; p++)
		    ;
		if (*p != '\t') continue;
		*p++ = '\0';
		while (p < buf + sizeof(buf) - 1 && *p == '\t')
		    p++;
		p[strlen(p)-1] = '\0';
		if (!first) printf(",\n");
		else first = 0;
		name = strjson(buf);
		desc = strjson(p);
		printf("    { \"name\": %s,\n      \"desc\": %s\n    }",
		       name, desc);
		SFREE(desc);
		SFREE(name);
	    }
	    wfdb_fclose(ifile);
	    first = 0; /* ensure that the database array will be closed in the
			  output even if the DBS file was empty */
	}
	wfdb = next;  /* prepare to search the next location in the WFDB path */
    }
    if (!first) {
	printf("\n  ],\n");
	printf("  \"version\": \"%s\",\n", LWVER);
        lwpass();
    }
    else {
	lwfail("The list of databases could not be read");
    }
}
Пример #2
0
void rlist(void)
{
    sprintf(buf, "%s/RECORDS", db);
    if (ifile = wfdb_open(buf, NULL, WFDB_READ)) {
	char *p;
        int first = 1;

        printf("{ \"record\": [\n");
	while (wfdb_fgets(buf, sizeof(buf), ifile)) {
	    buf[strlen(buf)-1] = '\0';
	    if (!first) printf(",\n");
	    else first = 0;
	    printf("    %s", p = strjson(buf));
	    SFREE(p);
	}
	printf("\n  ],\n");
	lwpass();
	wfdb_fclose(ifile);
    }
    else
	lwfail("The list of records could not be read");
}
Пример #3
0
/* Function newcal generates a calibration file based on the contents of the
   calibration list. */
FINT newcal(char *cfname)
{
    WFDB_FILE *cfile;

    if (wfdb_checkname(cfname, "calibration file") < 0)
	return (-1);

    if ((cfile = wfdb_open(cfname, (char *)NULL, WFDB_WRITE)) == NULL) {
	wfdb_error("newcal: can't create calibration file %s\n", cfname);
	return (-1);
    }

    for (this_cle = first_cle; this_cle; this_cle = this_cle->next) {
	char *pulsetype;

	(void)wfdb_fprintf(cfile, "%s\t", this_cle->sigtype);
	if (this_cle->caltype & WFDB_DC_COUPLED)
	    (void)wfdb_fprintf(cfile, "%g ", this_cle->low);
	else
	    (void)wfdb_fprintf(cfile, "- ");
	if (this_cle->high != this_cle->low)
	    (void)wfdb_fprintf(cfile, "%g ", this_cle->high);
	else
	    (void)wfdb_fprintf(cfile, "- ");
	switch (this_cle->caltype & (~WFDB_DC_COUPLED)) {
	  case WFDB_CAL_SQUARE:	pulsetype = "square"; break;
	  case WFDB_CAL_SINE:	pulsetype = "sine"; break;
	  case WFDB_CAL_SAWTOOTH:	pulsetype = "sawtooth"; break;
	  default:		pulsetype = "undefined"; break;
	}
	(void)wfdb_fprintf(cfile, "%s %g %s\r\n",
		      pulsetype,
		      this_cle->scale,
		      this_cle->units);
    }
    (void)wfdb_fclose(cfile);
    return (0);
}
Пример #4
0
/* Function calopen reads the specified calibration file;  if called with
   a NULL argument, it takes the value of the environment variable WFDBCAL
   to be the name of the calibration file.  If the calibration file name
   does not begin with "+", calopen empties the calibration list first;
   otherwise, the "+" is discarded before attempting to open the file,
   which may be in any directory in the WFDB path.  If the file can be read,
   its contents are appended to the calibration list. */
FINT calopen(char *cfname)
{
    WFDB_FILE *cfile;
    char buf[128], *p1, *p2, *p3, *p4, *p5, *p6;

    /* If no calibration file is specified, return immediately. */
    if (cfname == NULL && (cfname = getenv("WFDBCAL")) == NULL &&
	(cfname = DEFWFDBCAL) == NULL)
	return (0);

    if (*cfname == '+')		/* don't empty the calibration list */
	cfname++;		/* discard the '+' prefix */
    else flushcal();		/* empty the calibration list */

    /* Quit if file can't be found or opened. */
    if ((cfile = wfdb_open(cfname, (char *)NULL, WFDB_READ)) == NULL) {
	wfdb_error("calopen: can't read calibration file %s\n", cfname);
	return (-2);
    }

    /* Read a line of the calibration file on each iteration.  See wfdbcal(5)
       for a description of the format. */
    while (wfdb_fgets(buf, 127, cfile)) {
	/* ignore leading whitespace */
	for (p1 = buf; *p1 == ' ' || *p1 == '\t' || *p1 == '\r'; p1++)
	    ;
	/* skip comments, empty lines, and improperly formatted lines */
	if (*p1 == '#' ||
	    (p1 = strtok(p1, "\t")) == NULL ||		    /* signal type */
	    (p2 = strtok((char *)NULL, " \t")) == NULL ||   /* low, or '-' */
	    (p3 = strtok((char *)NULL, " \t")) == NULL ||   /* high, or '-' */
	    (p4 = strtok((char *)NULL, " \t")) == NULL ||   /* pulse type */
	    (p5 = strtok((char *)NULL, " \t")) == NULL ||   /* scale */
	    (p6 = strtok((char *)NULL, " \t\r\n")) == NULL) /* units */
	    continue;

	/* This line appears to be a correctly formatted entry.  Allocate
	   memory for a calibration list entry. */
	SUALLOC(this_cle, 1, (sizeof(struct cle)));

	/* Fill in the fields of the new calibration list entry. */
	SSTRCPY(this_cle->sigtype, p1);
	if (strcmp(p2, "-") == 0) {
	    this_cle->caltype = WFDB_AC_COUPLED;
	    this_cle->low = 0.0;
	}
	else {
	    this_cle->caltype = WFDB_DC_COUPLED;
	    this_cle->low = atof(p2);
	}
	if (strcmp(p3, "-") == 0)
	    this_cle->high = this_cle->low = 0.0;
	else
	    this_cle->high = atof(p3);
	if (strcmp(p4, "square") == 0)
	    this_cle->caltype |= WFDB_CAL_SQUARE;
	else if (strcmp(p4, "sine") == 0)
	    this_cle->caltype |= WFDB_CAL_SINE;
	else if (strcmp(p4, "sawtooth") == 0)
	    this_cle->caltype |= WFDB_CAL_SAWTOOTH;
	/* otherwise pulse shape is undefined */
	this_cle->scale = atof(p5);
	SSTRCPY(this_cle->units, p6);
	this_cle->next = NULL;

	/* Append the new entry to the end of the list. */
	if (first_cle) {
	    prev_cle->next = this_cle;
	    prev_cle = this_cle;
	}
	else
	    first_cle = prev_cle = this_cle;
    }

    (void)wfdb_fclose(cfile);
    return (0);
}