/************************************************************ * * * Permission is hereby granted to any individual or * * institution for use, copying, or redistribution of * * this code and associated documentation, provided * * that such code and documentation are not sold for * * profit and the following copyright notice is retained * * in the code and documentation: * * Copyright (c) held by Dianne Cook * * All Rights Reserved. * * * * Questions and comments are welcome, and I request * * that you share any modifications with me. * * * * Dianne Cook * * dicook@iastate.edu * * * ************************************************************/ /* read.c */ #include #include #include #include #include "defs_and_types.h" /* defines for reads */ #define NCOLS 1500 #define INITSTRSIZE 1500 #define COLLABLEN 25 #define ROWLABLEN 50 #define NGLYPHTYPES 7 #define NGLYPHSIZES 5 #define NGLYPHS ((NGLYPHTYPES-1)*NGLYPHSIZES + 1) /* data variables */ float **raw_data; int ncols, ncols_used, nrows, nrows_used; /* variable groups */ int *vgroup_ids; void *gt_2_malloc(size_t our_size) { void *rpt=NULL; if((rpt=malloc(our_size))==NULL) { fprintf(stderr, "Could not allocate memory (gt_2_malloc in read.c)\n"); exit(1); } return(rpt); } void *gt_realloc(void *p, size_t our_size) { void *rpt=NULL; if((rpt=realloc(p, our_size))==NULL) { fprintf(stderr, "Could not allocate memory (gt_realloc in read.c)\n"); exit(1); } return(rpt); } int read_array(char *data_in) { register int ch; int i, j, jrows, jcols, fs; int nitems; float row1[NCOLS]; int nblocks; char fname[100]; FILE *fp; if (strcmp(data_in,"stdin") == 0) fp = stdin; else { if ((fp = fopen(data_in, "r")) == NULL) { strcpy(fname, data_in); strcat(fname, ".dat"); if ((fp = fopen(fname, "r")) == NULL) { (void) fprintf(stderr, "Neither the file %s nor %s exists\n", data_in, fname); return(0); } } } /* * Read in the first row of the data file and calculate ncols. */ ncols_used = 0; while ( (ch = getc(fp)) != '\n') { if (ch == '\t' || ch == ' ') ; else { if ( ungetc(ch, fp) == EOF || fscanf(fp, "%g", &row1[ncols_used++]) < 0 ) { fprintf(stderr, "error in ungetc or fscanf"); return(0); } } } ncols = ncols_used; /* * Allocate space for 500 rows, leaving two extra slots for the * extra variables; one sometimes mapped, one never mapped. */ raw_data = (float **) gt_2_malloc( (unsigned int) 500 * sizeof(float *)); for (i=0; i<500; i++) raw_data[i] = (float *) gt_2_malloc( (unsigned int) ncols * sizeof(float)); /* * Fill in the first row */ for (j=0; j maxid) maxid = vgroup_ids[i]; /* * Find minimum vgroup id, set it to 0. Find next, set it to 1; etc. */ id = 0; newid = -1; while (id <= maxid) { found = 0; for (j=0; j