DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download
Index: ┃ T v

⟦4a9a211f1⟧ TextFile

    Length: 3047 (0xbe7)
    Types: TextFile
    Names: »validata.c«

Derivation

└─⟦87ddcff64⟧ Bits:30001253 CPHDIST85 Tape, 1985 Autumn Conference Copenhagen
    └─ ⟦this⟧ »cph85dist/stat/src/validata.c« 

TextFile

#include "unixstat.h"
PGM(validata,Data Validation and Consistency Checking,5.0,3/4/85)
/* Copyright (c) 1982 Gary Perlman (see Copyright file) */

/*
	validata looks at a data file to see what sort of columns it has.
	It complains if there are not an equal number of columns
	for each line in the input.  At the end, it prints the type
	of each column depending on what types of data appeared in them.
*/

#define	MAXCOLS		100
int 	nalnum[MAXCOLS];
int 	nalpha[MAXCOLS];
int 	nint[MAXCOLS];
int 	nfloat[MAXCOLS];
int 	nother[MAXCOLS];
int 	ntotal[MAXCOLS];
double	minvalue[MAXCOLS];
double	maxvalue[MAXCOLS];

main (argc, argv) int argc; char **argv;
	{
	char	line[BUFSIZ];
	char	*col[MAXCOLS];
	int 	other;
	int 	linecount = 0;
	int 	ncols;
	int 	maxcols = 0;
	int 	colcount = -1;
	int 	colno;
	double	value;
	char	*s;
	ARGV0;
	ERROPT (1);
	checkstdin (Argv0);
	while (gets (line))
		{
		linecount++;
		ncols = parseline (line, col, MAXCOLS);
		if (ncols > MAXCOLS)
			ERRMANY (columns, MAXCOLS)
		if (ncols > maxcols) maxcols = ncols;
		if (ncols != colcount)
			{
			if (linecount != 1)
				fprintf (stderr, "Variable number of columns at line %d\n", linecount);
			colcount = ncols;
			}
		if (ncols == 0)
			fprintf (stderr, "Line %d is empty\n", linecount);
		other = 1;
		for (colno = 0; colno < ncols; colno++)
			{
			s = col[colno];
			ntotal[colno]++;
			if (stralnum (s))
				{
				other = 0;
				nalnum[colno]++;
				if (stralpha (s))
					nalpha[colno]++;
				}
			if (strfloat (s))
				{
				other = 0;
				nfloat[colno]++;
				if (strint (s))
					nint[colno]++;
				value = atof (s);
				if (nfloat[colno] == 1)
					minvalue[colno] = maxvalue[colno] = value;
				if (value > maxvalue[colno]) maxvalue[colno] = value;
				else if (value < minvalue[colno]) minvalue[colno] = value;
				}
			if (other) nother[colno]++;
			else other = 1;
			}
		}

	if (isatty (1)) printf ("%d lines read\n", linecount);
	printf ("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",
		"Column", "total", "alnum", "alpha", "int", "float", "other", "min", "max");
	for (colno = 0; colno < maxcols; colno++)
	printf ("%d\t%d\t%d\t%d\t%d\t%d\t%d\t%g\t%g\n",
		colno+1,  ntotal[colno],
		nalnum[colno], nalpha[colno], nint[colno],
		nfloat[colno], nother[colno], minvalue[colno], maxvalue[colno]);
	exit (0);
	}

stralnum (s) char *s;
	{
	while (isspace (*s)) s++;
	while (*s)
		if (!isalnum (*s)) return (0);
		else s++;
	return (1);
	}

stralpha (s) char *s;
	{
	while (isspace (*s)) s++;
	while (*s)
		if (!isalpha (*s)) return (0);
		else s++;
	return (1);
	}

strint (s) char *s;
	{
	while (isspace (*s)) s++;
	if (*s == '+' || *s == '-') s++;
	while (*s)
		if (!isdigit (*s)) return (0);
		else s++;
	return (1);
	}

strfloat (s) char *s;
	{
	while (isspace (*s)) s++;
	if (!*s) return (0);
	if (*s == '+' || *s == '-') s++;
	while (isdigit (*s)) s++;
	if (*s == '.') s++;
	while (isdigit (*s)) s++;
	if (*s == 'E' || *s == 'e')
		{
		s++;
		if (*s == '+' || *s == '-') s++;
		while (isdigit (*s)) s++;
		}
	while (isspace (*s)) s++;
	return (*s == NULL);
	}