Doxygen Source Code Documentation
ent16.c File Reference
#include "mrilib.h"
Go to the source code of this file.
Defines | |
#define | NBUF 16384 |
Functions | |
int | main (int argc, char *argv[]) |
Define Documentation
|
Definition at line 3 of file ent16.c. Referenced by main(). |
Function Documentation
|
\** File : SUMA.c
Input paramters :
Definition at line 5 of file ent16.c. References argc, ENTROPY_accumulate(), ENTROPY_compute(), ENTROPY_setdown(), ENTROPY_setup(), machdep(), NBUF, and strtod().
00006 { 00007 char buf[NBUF] ; 00008 int nn ; double ee,pp , cutper=0.0 ; 00009 00010 if( argc > 1 ){ 00011 if( strcmp(argv[1],"-help") == 0 ){ 00012 printf("Usage: ent16 [-%%nn]\n" 00013 "Computes an estimate of the entropy of stdin.\n" 00014 "If the flag '-%%75' is given (e.g.), then the\n" 00015 " exit status is 1 only if the input could be\n" 00016 " compressed at least 75%%, otherwise the exit\n" 00017 " status is 0. Legal values of 'nn' are 1..99.\n" 00018 "In any case, the entropy and compression estimates\n" 00019 " are printed to stdout, even if no '-%%nn' flag is.\n" 00020 " given.\n" 00021 "\n" 00022 "METHOD: entropy is estimated by building a histogram\n" 00023 " of all 16 bit words in the input, then summing\n" 00024 " over -p[i]*log2(p[i]), i=0..65535. Compression\n" 00025 " estimate seems to work pretty good for gzip -1\n" 00026 " in most cases of binary image data.\n" 00027 "\n" 00028 "SAMPLE USAGE (csh syntax):\n" 00029 " ent16 -%%75 < fred+orig.BRIK\n" 00030 " if( $status == 1 ) gzip -1v fred+orig.BRIK\n" 00031 ) ; 00032 exit(0) ; 00033 00034 } else if( strncmp(argv[1],"-%",2) == 0 ){ 00035 cutper = strtod( argv[1]+2 , NULL ) ; 00036 if( cutper < 1.0 || cutper > 99.0 ) cutper = 0.0 ; 00037 00038 } else { 00039 fprintf(stderr,"++ ent16: Unknown option %s ignored!\n",argv[1]) ; 00040 } 00041 } 00042 00043 machdep() ; 00044 00045 /*--------------------------*/ 00046 00047 ENTROPY_setup() ; 00048 do{ 00049 nn = fread( buf , 1 , NBUF , stdin ) ; 00050 if( nn <= 0 ) break ; 00051 ENTROPY_accumulate( nn , buf ) ; 00052 } while(1) ; 00053 00054 /*--------------------------*/ 00055 00056 ee = ENTROPY_compute() ; ENTROPY_setdown() ; 00057 pp = 100.0*(1.0-ee/16.0) ; 00058 00059 printf("entropy=%6.3f bits/word compression=%5.2f%%\n", 00060 ee , pp ) ; 00061 00062 if( cutper > 0.0 && pp >= cutper ) exit(1) ; 00063 exit(0) ; 00064 } |