1 /* getProfile.c */
2
3 #include "../InpMtx.h"
4
5 /*--------------------------------------------------------------------*/
6 int
main(int argc,char * argv[])7 main ( int argc, char *argv[] )
8 /*
9 -----------------------------------------
10 get a log10 profile of the matrix entries
11
12 created -- 97feb14, cca
13 -----------------------------------------
14 */
15 {
16 int ii, msglvl, nbig, npts, nsmall, nzero, rc, size ;
17 InpMtx *inpmtx ;
18 double taubig, tausmall ;
19 double *xvec, *yvec ;
20 DV *xDV, *yDV ;
21 FILE *msgFile ;
22
23 if ( argc != 7 ) {
24 fprintf(stdout,
25 "\n\n usage : %s msglvl msgFile inFile npts tausmall taubig"
26 "\n msglvl -- message level"
27 "\n msgFile -- message file"
28 "\n inFile -- input file, must be *.dinpmtxf or *.dinpmtxb"
29 "\n npts -- number of points in the profile curve"
30 "\n tausmall -- lower cutoff"
31 "\n taubig -- upper cutoff"
32 "\n", argv[0]) ;
33 return(0) ;
34 }
35 msglvl = atoi(argv[1]) ;
36 if ( strcmp(argv[2], "stdout") == 0 ) {
37 msgFile = stdout ;
38 } else if ( (msgFile = fopen(argv[2], "a")) == NULL ) {
39 fprintf(stderr, "\n fatal error in %s"
40 "\n unable to open file %s\n",
41 argv[0], argv[2]) ;
42 return(-1) ;
43 }
44 npts = atoi(argv[4]) ;
45 tausmall = atof(argv[5]) ;
46 taubig = atof(argv[6]) ;
47 fprintf(msgFile,
48 "\n %% %s "
49 "\n %% msglvl -- %d"
50 "\n %% msgFile -- %s"
51 "\n %% inFile -- %s"
52 "\n %% npts -- %d"
53 "\n %% tausmall -- %e"
54 "\n %% taubig -- %e"
55 "\n",
56 argv[0], msglvl, argv[2], argv[3], npts, tausmall, taubig) ;
57 fflush(msgFile) ;
58 /*
59 --------------------------
60 read in the InpMtx object
61 --------------------------
62 */
63 if ( strcmp(argv[3], "none") == 0 ) {
64 fprintf(msgFile, "\n no file to read from") ;
65 exit(0) ;
66 }
67 inpmtx = InpMtx_new() ;
68 rc = InpMtx_readFromFile(inpmtx, argv[3]) ;
69 fprintf(msgFile,
70 "\n %% return value %d from InpMtx_readFromFile(%p,%s)",
71 rc, inpmtx, argv[3]) ;
72 if ( rc != 1 ) {
73 exit(-1) ;
74 }
75 fprintf(msgFile, "\n\n %d entries", inpmtx->nent) ;
76 /*
77 ---------------
78 get the profile
79 ---------------
80 */
81 xDV = DV_new() ;
82 yDV = DV_new() ;
83 InpMtx_log10profile(inpmtx, npts, xDV, yDV, tausmall, taubig,
84 &nzero, &nsmall, &nbig) ;
85 fprintf(msgFile,
86 "\n %% %8d zero entries "
87 "\n %% %8d entries smaller than %20.12e in magnitude"
88 "\n %% %8d entries larger than %20.12e in magnitude",
89 nzero, nsmall, tausmall, nbig, taubig) ;
90 DV_sizeAndEntries(xDV, &size, &xvec) ;
91 DV_sizeAndEntries(yDV, &size, &yvec) ;
92 fprintf(msgFile, "\n data = [ ...") ;
93 for ( ii = 0 ; ii < size ; ii++ ) {
94 fprintf(msgFile, "\n %20.12e %20.12e", xvec[ii], yvec[ii]) ;
95 }
96 fprintf(msgFile, " ] ; ") ;
97 /*
98 ------------------------
99 free the working storage
100 ------------------------
101 */
102 DV_free(xDV) ;
103 DV_free(yDV) ;
104 InpMtx_free(inpmtx) ;
105
106 fprintf(msgFile, "\n") ;
107 fclose(msgFile) ;
108
109 return(1) ; }
110
111 /*--------------------------------------------------------------------*/
112