From: Diemo S. <di...@us...> - 2009-08-10 16:16:30
|
Update of /cvsroot/sdif/SDIF/tools In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv11653 Modified Files: querysdif.c Log Message: - reimplemented querysdif using SdifQuery for consistency - added header printing Index: querysdif.c =================================================================== RCS file: /cvsroot/sdif/SDIF/tools/querysdif.c,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** querysdif.c 10 Dec 2008 19:22:45 -0000 1.14 --- querysdif.c 10 Aug 2009 16:16:18 -0000 1.15 *************** *** 15,18 **** --- 15,22 ---- $Log$ + Revision 1.15 2009/08/10 16:16:18 diemo + - reimplemented querysdif using SdifQuery for consistency + - added header printing + Revision 1.14 2008/12/10 19:22:45 bogaards support for frames that do not contain any matrix *************** *** 103,117 **** "Usage: querysdif [options] [sdif-file]\n" "\n" ! "Options:\n" " -a view ASCII chunks\n" " -d view data\n" " -b view data brief (output in SDIF selection syntax)\n" - /* todo: " -n view NVTs (name value tables)\n" " -T view type declarations in sdif-file\n" " -D view all type declarations in effect\n" - " -s view stream id table\n" */ " -t <sdif types file> specify file with additional sdif types\n" " -h this help\n" "\n" --- 107,122 ---- "Usage: querysdif [options] [sdif-file]\n" "\n" ! "Options: (no options mean: show all information)\n" " -a view ASCII chunks\n" " -d view data\n" " -b view data brief (output in SDIF selection syntax)\n" " -n view NVTs (name value tables)\n" " -T view type declarations in sdif-file\n" + /* todo: " -D view all type declarations in effect\n" */ + " -H view file header info\n" " -t <sdif types file> specify file with additional sdif types\n" + " -V print SDIF library version\n" " -h this help\n" "\n" *************** *** 124,216 **** } ! typedef struct ! { ! float min, max; ! } minmax; ! ! #define initminmax(m) ((m).min = FLT_MAX, (m).max = FLT_MIN) ! #define minmax(m, v) { if ((v) < (m).min) (m).min = (v); \ ! if ((v) > (m).max) (m).max = (v); } ! ! ! /* Count occurence of signatures as frame or matrix under ! different parent frames. */ ! #define MaxSignatures 1024 ! int nsig = 0; ! ! struct TwoLevelTree ! { ! /* common fields */ ! SdifSignature sig; ! int count; ! int parent; /* 0 for frames, index to parent frame for matrices */ ! ! /* frame fields */ ! int stream; ! minmax time, nmatrix; ! ! /* matrix fields */ ! minmax ncol, nrow; ! ! } sigs [MaxSignatures]; ! ! ! int SigEqual (SdifSignature s, int parent, int stream, int i) ! { ! return sigs [i].sig == s ! && sigs [i].stream == stream ! && sigs [i].parent == parent; ! } ! ! int GetSigIndex (SdifSignature s, int parent, int stream) { ! int i = 0; ! ! while (i < nsig && !SigEqual (s, parent, stream, i)) ! i++; ! ! if (i == nsig) ! { /* add new signature */ ! if (nsig >= MaxSignatures) ! { ! fprintf (SdifStdErr, "Too many different signatures, " ! "can't handle more than %d!\n", MaxSignatures); ! exit (1); ! } ! ! sigs [i].sig = s; ! sigs [i].parent = parent; ! sigs [i].stream = stream; ! sigs [i].count = 0; ! initminmax(sigs [i].time); ! initminmax(sigs [i].nmatrix); ! initminmax(sigs [i].ncol); ! initminmax(sigs [i].nrow); ! nsig++; } ! return (i); ! } ! ! int CountFrame (SdifSignature s, int stream, float time, int nmatrix) ! { ! int i = GetSigIndex (s, -1, stream); ! ! sigs [i].count++; ! minmax(sigs [i].time, time); ! minmax(sigs [i].nmatrix, nmatrix); ! ! return (i); ! } ! ! void CountMatrix (SdifSignature s, int parent, int nrow, float ncol) ! { ! int i = GetSigIndex (s, parent, -1); ! sigs [i].count++; ! minmax(sigs [i].nrow, nrow); ! minmax(sigs [i].ncol, ncol); } --- 129,160 ---- } + /* flags with default values */ + int vall = 1, + vascii = 0, + vdata = 0, + vbrief = 0, + vnvt = 0, + vtypes = 0, + valltypes = 0, + vheader = 0; ! static int PrintHeaders (SdifFileT *file, void *userdata) { ! file->TextStream = stdout; /* SdifFPrint* functions need this */ ! if (vall || vheader) ! { ! printf("Header info of file %s:\n\n", file->Name); ! printf("Format version: %d\n", file->FormatVersion); ! printf("Types version: %d\n\n", file->TypesVersion); } ! if (vall || vascii) ! { ! printf("Ascii chunks of file %s:\n\n", file->Name); ! SdifFPrintAllASCIIChunks(file); ! } ! return vall || vdata; /* continue reading data */ } *************** *** 232,254 **** #endif { ! int i, m, eof = 0; ! size_t bytesread = 0, nread = 0; ! SdifFileT *in; ! int result; /* arguments with default values */ ! char *infile = NULL, ! *types = NULL; ! int vall = 1, ! vascii = 0, ! vdata = 0, ! vbrief = 0; ! #if 0 ! /* todo */ ! vnvt = 0, ! vtypes = 0, ! valltypes = 0, ! vstream = 0; ! #endif SdifStdErr = stderr; --- 176,186 ---- #endif { ! SdifFileT *in; ! SdifQueryTreeT *sigs; ! int nread, i, m; /* arguments with default values */ ! char *infile = NULL, ! *types = NULL; SdifStdErr = stderr; *************** *** 265,276 **** case 'd': vall = 0; vdata = 1; break; case 'b': vall = 0; vdata = vbrief = 1; break; ! /* todo: case 'n': vall = 0; vnvt = 1; break; case 'T': vall = 0; vtypes = 1; break; ! case 'D': vall = 0; valltypes = 1; break; ! case 's': vall = 0; vstream = 1; break; ! */ case 't': /* no arg after last option, complain */ if (i == argc - 1) usage (); types = argv [++i]; break; default : usage(); break; } --- 197,209 ---- case 'd': vall = 0; vdata = 1; break; case 'b': vall = 0; vdata = vbrief = 1; break; ! case 'n': vall = 0; vnvt = 1; break; case 'T': vall = 0; vtypes = 1; break; ! /* todo: case 'D': vall = 0; valltypes = 1; break; ! */ case 'H': vall = 0; vheader = 1; break; ! case 't': /* no arg after last option, complain */ if (i == argc - 1) usage (); types = argv [++i]; break; + case 'V': SdifPrintVersion(); break; default : usage(); break; } *************** *** 297,420 **** infile = "stdin"; ! if (!(in = SdifFOpen (infile, eReadFile))) ! { ! fprintf (SdifStdErr, "Can't open input file %s.\n", infile); ! SdifGenKill (); ! exit (1); ! } ! in->TextStream = stdout; /* SdifFPrint* functions need this */ ! ! if ((nread = SdifFReadGeneralHeader(in)) == 0) ! { ! SdifGenKill (); ! exit(1); ! } ! bytesread += SdifFReadAllASCIIChunks (in) + nread; ! eof = SdifFCurrSignature(in) == eEmptySignature; ! ! if (vall || vascii) ! { ! printf ("Ascii chunks of file %s:\n\n", infile); ! SdifFPrintGeneralHeader(in); ! SdifFPrintAllASCIIChunks(in); ! } if (vall || vdata) ! { ! /* ! * read, count frame loop ! */ ! ! while (!eof) ! { ! int frameidx; ! ! /* Read frame header. Current signature has already been read ! by SdifFReadAllASCIIChunks or the last loop.) */ ! bytesread += SdifFReadFrameHeader (in); ! ! /* count frame */ ! frameidx = CountFrame (SdifFCurrSignature(in), SdifFCurrID(in), ! SdifFCurrTime(in), SdifFCurrNbMatrix(in)); ! ! /* for matrices loop */ ! for (m = 0; m < SdifFCurrNbMatrix (in); m++) ! { ! /* Read matrix header */ ! bytesread += SdifFReadMatrixHeader (in); ! ! /* count matrix and do statistics about rows/columns */ ! CountMatrix (SdifFCurrMatrixSignature (in), frameidx, ! SdifFCurrNbRow (in), SdifFCurrNbCol (in)); ! ! /* We're not actually interested in the matrix data, ! so we skip it. */ ! bytesread += SdifFSkipMatrixData (in); ! } /* end for matrices */ ! ! eof = SdifFGetSignature (in, &bytesread) == eEof; ! } /* end while frames */ ! ! ! /* ! * print results ! */ if (vbrief) { /* brief selection-syntax output without counts */ ! for (i = 0; i < nsig; i++) { ! if (sigs[i].parent == -1) ! { /* search children matrices of this frame */ ! int numChildMatrices = 0; ! for (m = 0; m < nsig; m++) ! { ! if (sigs[m].parent == i){ ! printf ("#%d:%s/%s@%f-%f\n", ! sigs[i].stream, ! SdifSignatureToString (sigs[i].sig), ! SdifSignatureToString (sigs[m].sig), ! sigs[i].time.min, ! sigs[i].time.max); ! numChildMatrices++; ! } ! } ! if(numChildMatrices == 0){ ! // frame had no child matrix. This can be the case for 1MRK frames that consist of only a time ! printf ("#%d:%s@%f-%f\n", ! sigs[i].stream, ! SdifSignatureToString (sigs[i].sig), ! sigs[i].time.min, ! sigs[i].time.max); ! } ! } } } else { ! printf ("Data in file %s (%u bytes):\n", infile, (unsigned int) bytesread); ! for (i = 0; i < nsig; i++) { ! if (sigs [i].parent == -1) { /* frames */ printf ("%5d %s frames in stream %d between time %f and %f containing\n", ! sigs [i].count, ! SdifSignatureToString (sigs [i].sig), ! sigs [i].stream, ! sigs [i].time.min, ! sigs [i].time.max); /* search children matrices of this frame */ ! for (m = 0; m < nsig; m++) { ! if (sigs [m].parent == i) printf (" %5d %s matrices with %3g --%3g rows, %3g --%3g columns\n", ! sigs [m].count, ! SdifSignatureToString (sigs [m].sig), ! sigs [m].nrow.min, ! sigs [m].nrow.max, ! sigs [m].ncol.min, ! sigs [m].ncol.max); } } --- 230,297 ---- infile = "stdin"; ! /* init query tree struct */ ! sigs = SdifCreateQueryTree(1024); ! /* perform query */ ! nread = SdifQuery(infile, PrintHeaders, sigs); if (vall || vdata) ! { /* print data content */ if (vbrief) { /* brief selection-syntax output without counts */ ! for (i = 0; i < sigs->num; i++) { ! if (sigs->elems[i].parent == -1) ! { /* search children matrices of this frame */ ! int numChildMatrices = 0; ! for (m = 0; m < sigs->num; m++) ! { ! if (sigs->elems[m].parent == i){ ! printf ("#%d:%s/%s@%f-%f\n", ! sigs->elems[i].stream, ! SdifSignatureToString (sigs->elems[i].sig), ! SdifSignatureToString (sigs->elems[m].sig), ! sigs->elems[i].time.min, ! sigs->elems[i].time.max); ! numChildMatrices++; ! } ! } ! if(numChildMatrices == 0){ ! // frame had no child matrix. This can be the case for 1MRK frames that consist of only a time ! printf ("#%d:%s@%f-%f\n", ! sigs->elems[i].stream, ! SdifSignatureToString (sigs->elems[i].sig), ! sigs->elems[i].time.min, ! sigs->elems[i].time.max); ! } ! } } } else { ! printf ("Data in file %s (%u bytes):\n", infile, (unsigned int) nread); ! for (i = 0; i < sigs->num; i++) { ! if (sigs->elems[i].parent == -1) { /* frames */ printf ("%5d %s frames in stream %d between time %f and %f containing\n", ! sigs->elems[i].count, ! SdifSignatureToString (sigs->elems[i].sig), ! sigs->elems[i].stream, ! sigs->elems[i].time.min, ! sigs->elems[i].time.max); /* search children matrices of this frame */ ! for (m = 0; m < sigs->num; m++) { ! if (sigs->elems[m].parent == i) printf (" %5d %s matrices with %3g --%3g rows, %3g --%3g columns\n", ! sigs->elems[m].count, ! SdifSignatureToString (sigs->elems[m].sig), ! sigs->elems[m].nrow.min, ! sigs->elems[m].nrow.max, ! sigs->elems[m].ncol.min, ! sigs->elems[m].ncol.max); } } *************** *** 424,437 **** } - /* check for error */ - if (SdifFLastError(in) == NULL) - result = 0; - else - result = 1; - /* cleanup */ ! SdifFClose (in); SdifGenKill (); ! return result; } --- 301,308 ---- } /* cleanup */ ! SdifFreeQueryTree(sigs); SdifGenKill (); ! return nread > 0; } |