root/trunk/twtgo.c

Revision 389, 3.8 kB (checked in by heitor.barbieri, 3 weeks ago)

essage first commit

Line 
1
2/* ------------------------------ twtgo.c ----------------------------------- */
3
4#include <stdio.h>
5#include <math.h>
6#include <string.h>
7
8#if 1
9#include "cisis.h"   /* CISIS Interface header file */
10#include "cirun.h"   /* CISIS Interface runtime declarations */
11#else
12#include "\cisis\include\cisis.h"   /* CISIS Interface header file */
13#include "\cisis\include\cirun.h"   /* CISIS Interface runtime declarations */
14#endif
15
16/* cisis/update working area */
17UBYTE buffup[MAXMFRL+BUFSIZ];
18
19void main(argc,argv)
20int argc;
21char *argv[];
22{
23    RECSTRU *recp;          /* mandatory for defines REC RDB MF0 MFR DIR, FIELDP */
24    LONGX irec;
25    LONGX upcrec;
26    LONGX mfn;
27    UBYTE *batchp,*p;
28    int xfd;
29
30    UBYTE *dbnamep,*dbnoutp;
31    LONGX parmtell;
32    LONGX parmfrom,parmto,parmloop,parmcount;
33    LONGX count=0L;
34
35    LONGX v999;
36    LONGX v99;
37
38    int argnext=1;
39
40    if (argc < 3) {
41        printf("%s",cicopyr("Utility TWTGO"));
42        printf("\n");
43        printf("twtgo <dbname> [create=]<dbnout> \n");
44        printf("\n");
45        printf(" <dbname> input master file \n");
46        printf(" <dbnout> output master file for results \n");
47        printf("\n");
48        exit(1);
49    }
50
51    dbnamep=argv[argnext++];
52    dbnoutp=argv[argnext++];
53
54    parmtell=0;
55    parmfrom=1; parmto=0; parmloop=1; parmcount=LONGX_MAX;
56
57    for (; argnext < argc; argnext++) {
58        p=argv[argnext];
59
60        if (strncmp(p,"tell=",5) == 0) {
61            if (sscanf(p+5,"%"_LD_,&parmtell) != 1)
62                fatal(p);
63            continue;
64        }
65
66        if (strncmp(p,"from=",5) == 0) {
67            if (sscanf(p+5,"%"_LD_,&parmfrom) != 1)
68                fatal(p);
69            continue;
70        }
71        if (strncmp(p,"to=",3) == 0) {
72            if (sscanf(p+3,"%"_LD_,&parmto) != 1)
73                fatal(p);
74            continue;
75        }
76        if (strncmp(p,"loop=",5) == 0) {
77            if (sscanf(p+5,"%"_LD_,&parmloop) != 1)
78                fatal(p);
79            continue;
80        }
81        if (strncmp(p,"count=",6) == 0) {
82            if (sscanf(p+6,"%"_LD_,&parmcount) != 1)
83                fatal(p);
84            continue;
85        }
86
87        fatal(p);
88    }
89    if (parmtell) fprintf(stderr,"+++ input data base:  %s\n",dbnamep);
90    if (parmtell) fprintf(stderr,"+++ output data base: %s\n",dbnoutp);
91
92    /* init */
93    if (strncmp(dbnoutp,"create=",7) == 0) {
94      recisis0((dbnoutp+=7));
95    }
96    else {
97          if (strncmp(dbnoutp,"append=",7) == 0) dbnoutp+=7;
98          dbxopt_fatal=0;
99          if ((xfd=dbxopen("",dbnoutp,mx1extp)) <= 0) {
100            recisis0(dbnoutp);
101        }
102        else
103            CLOSE(xfd);
104    }
105
106    RECORD((upcrec=nrecs),dbnoutp,0L);
107
108    /*
109        main loop
110    */
111    for (irec=nrecs, mfn=parmfrom; ; mfn+=parmloop) {
112
113        if (parmto) if (mfn > parmto) break;
114        if (parmcount) if (count >= parmcount) break;
115
116        RECORD(irec,dbnamep,mfn);
117        if (RECrc == RCEOF) break;
118        count++;
119        if (RECrc != RCNORMAL) continue;
120
121        recfield(buffup, irec, 999, 1, "0"); v999=atol(buffup);
122        recfield(buffup, irec,  99, 1, "0");  v99=atol(buffup);
123
124        if (v99>0) {
125            double num = (double)v999;
126            double den = (double)v99;
127            float x,w,w5,w6,w7;
128
129            x  = (float)v999/(float)v99;
130            w5 = (float)log(1+(1/den));
131            w6 = (float)(1/den);
132            w7 = w5 / w6;                                             
133            w  = w7 * x;
134
135            sprintf(batchp=buffup,"A3|%9.7f| A4|%9.7f| A5|%9.7f| A6|%9.7f| A7|%9.7f|",w,x,w5,w6,w7);
136
137            batchp+=strlen(batchp); *batchp='\0';
138            if ((p=fldupdat(irec,buffup)) != NULL) fatal(p);
139            recupdat(upcrec,irec);
140        }
141
142        if (parmtell) if (!(count % parmtell)) fprintf(stderr,"+++ %"_LD_" recs\n",count);
143    }
144
145    if (parmtell) fprintf(stderr,"twtgo: %"_LD_" recs\n",count);
146    exit(0);
147}
148
149
150
Note: See TracBrowser for help on using the browser.