home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.eri.u-tokyo.ac.jp
/
2014.03.ftp.eri.u-tokyo.ac.jp.zip
/
ftp.eri.u-tokyo.ac.jp
/
pub
/
seisv
/
src
/
3.02a
/
time.c
< prev
Wrap
C/C++ Source or Header
|
2000-04-23
|
18KB
|
626 lines
/* SeisView alone/client Copyright (C) 1992,1998 K.Koketsu
<history>
98-11-03 Include panel definitions and remove CR.
98-10-06 Some global variables are replaced by constants.
98-10-01 _setbkcolor(0) in the initialization.
98-02-25 Abandon DOS, but take Windows 95/NT.
96-01-04 fix the bug in timebar(). */
#include <stdlib.h>
#include <math.h>
#include "ctlname.h"
#include "seis.h"
extern char *iseg[10]; /* work segments for selected events */
extern unsigned nseg; /* number of working segments */
extern int itot; /* total # selected events */
extern short isort; /* flag for sorting */
extern char z$[11], w$[81]; /* work string */
/***************************** variables for menu ****************************/
extern char em$[51]; /* error message on menu */
extern char mc$[42][9]; /* field strings */
extern short isr; /* initial cursor position */
/**************************** variables for retrieval ************************/
extern char y1$[5], m1$[3], d1$[3], h1$[3], n1$[3], s1$[6];
extern char y2$[5], m2$[3], d2$[3], h2$[3], n2$[3], s2$[6];
/**************************** variables for TIME *****************************/
int kyy1, km1, kd1, kh1, kn1;
int kyy2, km2, kd2, kh2, kn2;
int lmt[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
/**************************** variables for taxis ****************************/
double st0, rt0, ut;
void tlplot(), timbar(), itos();
int fnuruu(), nnleng();
/******************* TIME (Draw time-frequency diagram) ************/
int time_seisv()
{
int i, k, jvj, jvk, jvl, jhl, jtm;
int rv1, rv2, ir, vlen;
int ipag, na, ly, lm, ld, lh, iu, iw;
int ldh, kdh1, kdh2, ln;
int nn, iv, ip, iy, im, id, ih;
char *is;
double st1, st2, sym, sym1, sym2;
double sc1, sc2, uv, rva, rm, sc, ru;
double rly, f;
if(itot == 0) return( 3 );
isr = 0;
strcpy(mc$[ 0],"LNR");
strcpy(mc$[ 1],y1$); strcpy(mc$[ 2],m1$); strcpy(mc$[ 3],d1$);
strcpy(mc$[ 4],h1$); strcpy(mc$[ 5],n1$); strcpy(mc$[ 6],s1$);
strcpy(mc$[ 7],y2$); strcpy(mc$[ 8],m2$); strcpy(mc$[ 9],d2$);
strcpy(mc$[10],h2$); strcpy(mc$[11],n2$); strcpy(mc$[12],s2$);
strcpy(mc$[13],"Y"); strcpy(mc$[14],"FRQ"); strcpy(mc$[15],"LNR");
strcpy(mc$[16]," 0");
scale(0, itot, &i, &k, &ir); itos(k, w$, 5);
strcpy(mc$[17], w$);
j100:
if(panel(TIME) == 3) return( 0 );
kyy1 = atoi(mc$[ 1]); kyy2 = atoi(mc$[ 7]);
km1 = atoi(mc$[ 2]); km2 = atoi(mc$[ 8]);
kd1 = atoi(mc$[ 3]); kd2 = atoi(mc$[ 9]);
kh1 = atoi(mc$[ 4]); kh2 = atoi(mc$[10]);
kn1 = atoi(mc$[ 5]); kn2 = atoi(mc$[11]);
sc1 = atof(mc$[ 6]); sc2 = atof(mc$[12]);
if(!strcmp(mc$[13],"H")) jtm = 3;
else if(!strcmp(mc$[13],"D")) jtm = 2;
else if(!strcmp(mc$[13],"M")) jtm = 1;
else jtm = 0;
rv1 = atoi(mc$[16]); rv2 = atoi(mc$[17]);
if(!strcmp(mc$[ 0],"LOG")) jhl = 2; else jhl = 1;
if(!strcmp(mc$[14],"MAG")) jvk = 2; else jvk = 1;
if(!strcmp(mc$[14],"ACM")) jvj = 1; else jvj = 0;
if(!strcmp(mc$[15],"LOG")) jvl = 2; else jvl = 1;
if(jvk==2 && jhl==2 && jtm!=3) {
jtm = 2; strcpy(mc$[13],"D");
}
if(jvl==2 && rv1 <0) { rv1 = 0; strcpy(mc$[16]," 0"); }
if(jvk==1 && isort>0) {
strcpy(em$,"Frequency diagram cannot be made for data in special order.");
goto j100;
}
clear( 0 );
_setbkcolor( 0 );
j200: /* legend */
i = 24;
if(jvj == 1) { i = 1; strcpy(w$,"Accumulated "); strcpy(z$,"(ACM "); }
else { i = 4; *w$ = 0; strcpy(z$,"("); }
if(jvk == 1) { strcat(w$,"Frequency"); strcat(z$,"FRQ)"); }
else { strcat(w$,"Magnitude"); strcat(z$,"MAG)"); }
vprint(i, w$);
gprint(63, 1, "Time", 4);
gprint(68, 1, z$, 4);
legend3();
_setcolor( 7 );
/* axes */
vaxis(jvl, rv1, rv2, &ir, &uv, &rva);
vlen = (int)(YPixels - RowPixels*3.5);
if(jvk ==2) gfprint(0, vlen+1, "unknown", 5);
st1 = fncal(kyy1, km1, kd1);
st2 = fncal(kyy2, km2, kd2);
taxis(jhl, jtm, st1, st2);
/* Draw bars */
if(jvk == 2) { /* MAG */
_setcolor( 4 );
sym1 = kyy1*100.+ km1; sym2 = kyy2*100.+ km2;
kdh1 = kd1*100 + kh1; kdh2 = kd2*100 + kh2;
for(i=0; i<itot; i++) {
ipag = i / 4095;
is = iseg[ipag];
na = (i-ipag*4095)*16 + 4;
ly = fnyear(na,is); lm = peek(na+1,is);
ld = peek(na+2,is); lh = peek(na+3,is);
sym = ly*100. + lm; ldh = ld*100 + lh;
if(sym>sym2 || (sym==sym2 && ldh>kdh2)) break;
if(sym>sym1 || (sym==sym1 && ldh>=kdh1)) {
rm = peek(na+15,is) / 10.;
if(jvl == 2) {
if(rm == 0.) f = -1.;
else f = log10(rm);
}
if((jvl==1 && rm>=rva) || (jvl==2 && f>=rva)) {
ln = peek(na+4,is);
sc = qeek(na+5,is)/10.;
if(jtm == 3)
ru = (fncal(ly,lm,ld)-st0)*24.+lh+ln/60.+sc/3600.-rt0;
else ru = fncal(ly,lm,ld)-st0+lh/24.+ln/1440.;
if(jhl == 2) iu = (int)(log10(ru+1)*ut);
else iu = (int)(ru*ut);
if(rm == 0.) iw = - RowPixels/2;
else {
if(jvl == 2) iw = (int)((log10(rm)-rva)*uv);
else iw = (int)((rm-rva)*uv);
}
gmoveto(57+iu, vlen); glineto(57+iu, vlen-iw);
}
}
}
}
else { /* FRQ */
nn = 0; iv = 0; ip = 0;
ly = kyy1; lm = km1; ld = kd1; lh = kh1;
if(jtm == 0) {
f = fncal(kyy2,km2,kd2+1);
for(i=0; i<itot; i++) {
ipag = i / 4095;
is = iseg[ipag];
na = (i-ipag*4095)*16 + 4;
iy = fnyear(na,is);
if(iy >= kyy1) {
if(ly == iy) {
nn++;
if(i != itot-1) goto j215;
else ip = 1;
}
j211: iw = nnleng(nn, jvl, rva, uv);
if(jhl == 2) {
ru = ly - kyy1 + 1;
tlplot(ru, ut, iw, vlen);
}
else {
if(jvj == 0) {
iu = (int)((fncal(ly,1,1)-st0) * ut);
if((rly=fncal(ly,12,32)) > f) rly = f;
}
else {
iu = iv;
if( ip ) rly = f;
else if((rly=fncal(iy,1,1)) > f) rly = f;
}
iv = (int)((rly-st0) * ut);
timbar(jhl, iu, iv, iw, vlen);
}
ly = iy;
if(jvj == 0) nn = 1; else nn++;
if(i==itot-1 && ip==0) { ip = 1; goto j211; }
if(ly > kyy2) break;
}
j215: continue;
}
}
if(jtm == 1) {
f = fncal(kyy2,km2,kd2+1);
for(i=0; i<itot; i++) {
ipag = i / 4095;
is = iseg[ipag];
na = (i-ipag*4095)*16 + 4;
iy = fnyear(na,is);
im = peek(na+1,is);
if(iy>kyy1 || (iy==kyy1 && im>=km1)) {
if(ly==iy && lm==im) {
nn++;
if(i != itot-1) goto j225; else ip = 1;
}
j221: iw = nnleng(nn, jvl, rva, uv);
if(jhl == 2) {
ru = (ly-kyy1)*12+lm-km1+1;
tlplot(ru, ut, iw, vlen);
}
else {
if(jvj == 0) {
iu = (int)((fncal(ly,lm,1)-st0) * ut);
if((rly=fncal(ly,lm,lmt[lm-1]+1)) > f) rly = f;
}
else {
iu = iv;
if( ip ) rly = f;
else if((rly=fncal(iy,im,1)) > f) rly = f;
}
iv = (int)((rly-st0) * ut);
timbar(jhl, iu, iv, iw, vlen);
}
ly = iy; lm = im;
if(jvj == 0) nn = 1; else nn++;
if(i==itot-1 && ip==0) { ip = 1; goto j221; }
if(fncal(ly,lm,1) > fncal(kyy2,km2,1)) break;
}
j225: continue;
}
}
if(jtm == 2) {
f = fncal(kyy2,km2,kd2+1);
for(i=0; i<itot; i++) {
ipag = i / 4095;
is = iseg[ipag];
na = (i-ipag*4095)*16 + 4;
iy = fnyear(na,is);
im = peek(na+1,is);
id = peek(na+2,is);
if(iy>kyy1 || (iy==kyy1 && im>=km1) ||
(iy==kyy1 && im==km1 && id>=kd1)) {
if(ly==iy && lm==im && ld==id) {
nn++;
if(i < itot-1) goto j235; else ip = 1;
}
j231: iw = nnleng(nn, jvl, rva, uv);
if(jhl == 2) {
ru = fncal(ly,lm,ld) - st0+1;
tlplot(ru, ut, iw, vlen);
}
else {
if(jvj == 0) {
iu = (int)((fncal(ly,lm,ld)-st0) * ut);
if((rly=fncal(ly,lm,ld+1)) > f) rly = f;
}
else {
iu = iv;
if( ip ) rly = f;
else if((rly=fncal(iy,im,id)) > f) rly = f;
}
iv = (int)((rly-st0) * ut);
timbar(jhl, iu, iv, iw, vlen);
}
ly = iy; lm = im; ld = id;
if(jvj == 0) nn = 1; else nn++;
if(i==itot-1 && ip==0) { ip = 1; goto j231; }
if(fncal(ly,lm,ld) > fncal(kyy2,km2,kd2)) break;
}
j235: continue;
}
}
if(jtm == 3) {
f = (fncal(kyy2,km2,kd2)-st0)*24+kh2+1;
for(i=0; i<itot; i++) {
ipag = i / 4095;
is = iseg[ipag];
na = (i-ipag*4095)*16 + 4;
iy = fnyear(na,is);
im = peek(na+1,is);
id = peek(na+2,is);
ih = peek(na+3,is);
if(iy>kyy1 || (iy==kyy1 && im>=km1) ||
(iy==kyy1 && im==km1 && id>=kd1) ||
(iy==kyy1 && im==km1 && id==kd1 && ih>=kh1)) {
if(ly==iy && lm==im && ld==id && lh==ih) {
nn++;
if(i < itot-1) goto j245; else ip = 1;
}
j241: iw = nnleng(nn, jvl, rva, uv);
if(jhl == 2) {
ru = (fncal(ly,lm,ld)-st0)*24+lh-rt0 + 1;
tlplot(ru, ut, iw, vlen);
}
else {
if(jvj == 0) {
iu = (int)(((fncal(ly,lm,ld)-st0)*24+lh-rt0) * ut);
if((rly=(fncal(ly,lm,ld)-st0)*24+lh+1)>f) rly = f;
}
else {
iu = iv;
if( ip ) rly = f;
else if((rly=(fncal(iy,im,id)-st0)*24+ih)>f) rly=f;
}
iv = (int)((rly-rt0)*ut);
timbar(jhl, iu, iv, iw, vlen);
}
ly = iy; lm = im; ld = id; lh = ih;
if(jvj == 0) nn = 1; else nn++;
if(i==itot-1 && ip==0) { ip = 1; goto j241; }
if(fncal(ly,lm,ld)*24+lh>fncal(kyy2,km2,kd2)*24+kh2) break;
}
j245: continue;
}
}
}
k = fgkey(0, 1);
if(k==-1 || k==F1) goto j200;
else if(k == F3) return( 0 );
else goto j100;
}
int nnleng(nn, jvl, rva, uv)
int nn, jvl;
double rva, uv;
{
double f;
if(nn == 0) return( 0 );
if(jvl == 2) {
f = nn;
return( (int)((log10(f)-rva)*uv) );
}
else return( (int)((nn-rva)*uv) );
}
void tlplot(ru, ut, iw, vlen) /* log time plot */
double ru, ut;
int iw, vlen;
{
int iv;
iv = (int)(log10(ru) * ut);
gmoveto(57+iv-6, vlen-iw); glineto(57+iv+6, vlen-iw);
gmoveto(57+iv, vlen-iw-6); glineto(57+iv, vlen-iw+6);
}
void timbar(jhl, iu, iv, iw, vlen)
int jhl, iu, iv, iw, vlen;
{
if(jhl == 2) {
gmoveto(57+iu, vlen); glineto(57+iv, vlen-iw);
}
else {
/* gbox(0, 57+iu, vlen, 57+iv, vlen-iw); (94-01-04) */
gbox(0, 57+iu, vlen-iw, 57+iv, vlen);
}
}
double fncal(i, j, k)
int i, j, k;
{
int icy, icm, isy;
double rcc;
if(i < 1900) { rcc = 0.; isy = 700; }
else { rcc = 438300.; isy = 1900; }
for(icy=isy; icy<i; icy++) {
if(fnuruu(icy)) rcc = rcc + 366; else rcc = rcc + 365;
}
rcc = rcc + k;
if(j < 2) return( rcc );
for(icm=1; icm<j; icm++) {
rcc = rcc + lmt[icm-1];
if(icm==2 && fnuruu(i)) rcc = rcc + 1;
}
return( rcc );
}
void fnlac(days, icy, icm, icd)
double days;
int *icy, *icm, *icd;
{
int i, kcp, icb;
for(i=700; i<=2000; i++) {
if(fnuruu(i)) kcp = 366; else kcp = 365;
if((days-=kcp) <= 0.) break;
}
*icy = i;
icb = (int)(days + kcp);
for(i=1; i<=12; i++) {
kcp = lmt[i-1];
if(i==2 && fnuruu(*icy)) kcp++;
if((icb-=kcp) <= 0.) break;
}
*icm = i;
*icd = icb + kcp;
}
int fnuruu( i )
int i;
{
if(i% 4 != 0) return( 0 );
if(i%400 != 0) return( 1 );
if(i%100 != 0) return( 0 );
return( 1 );
}
void taxis(iz, jtm, st1, st2)
int iz, jtm;
double st1, st2;
{
int itn, iun, ib, vlen, vle2, xorg, svn;
int lyy, lmm, ldd, lhh, lyz, lmz, ldz;
int i, j, k, ihr, iday, rsb;
double stn, rtb;
double f, days, rt1, rt2;
_setcolor( 7 );
vlen = (int)(YPixels - RowPixels*3.5);
xorg = 41;
gmoveto(xorg, vlen);
glineto( 490, vlen);
xorg += RowPixels;
vle2 = (int)(vlen + RowPixels*0.5);
if(iz == 1) { /* LNR */
if(jtm == 0) {
itn = kyy2+1 - kyy1;
if((iun=itn/8) < 1) iun = 1;
st0 = fncal(kyy1,1,1);
ut = 418./(st2+1-st0);
for(i=0; i<=itn; i+=iun) {
ib = (int)(xorg + (fncal(kyy1+i,1,1)-st0)*ut);
gmoveto(ib, vlen); glineto(ib, vle2);
itoa(kyy1+i, w$, 10);
k = _gettextextent( w$ ) / 2;
gfprint(ib-k, vle2+2, w$, 7);
}
}
else if(jtm == 1) {
stn = (kyy2-kyy1)*12. + km2+1. - km1;
if((svn=(int)(stn/8.)) < 1) svn = 1;
st0 = fncal(kyy1,km1,1);
ut = 418/(st2+1-st0);
lyy = kyy1; lmm = km1; lyz = -1;
for(f=0.; f<=stn; f+=svn) {
ib = (int)(xorg + (fncal(lyy,lmm,1)-st0)*ut);
gmoveto(ib, vlen); glineto(ib, vle2);
itoa(lmm, w$, 10);
k = _gettextextent( w$ ) / 2;
gfprint(ib-k, vle2+2, w$, 7);
if(lyy != lyz) {
itoa(lyy, w$, 10);
gfprint(ib-k, vle2+RowPixels, w$, 7);
}
lyz = lyy;
lmm = lmm + svn;
while(lmm > 12) { lmm -= 12; lyy++; }
}
}
else if(jtm == 2) {
stn = fncal(kyy2,km2,kd2)-fncal(kyy1,km1,kd1)+1;
if((svn=(int)(stn/8.)) < 1) svn = 1;
st0 = fncal(kyy1,km1,kd1);
ut = 418/(st2+1-st0);
lyy = kyy1; lmm = km1; ldd = kd1; lyz = -1; lmz = -1;
for(f=0.; f<=stn; f+=svn) {
ib = (int)(xorg + (fncal(lyy,lmm,ldd)-st0)*ut);
if(lmm == lmz) goto j1337;
if(lyy == lyz) goto j1410;
strcat(itoa(lyy,w$,10), "/");
strcat(w$, itoa(lmm,z$,10));
k = _gettextextent( w$ ) / 2;
gfprint(ib-k, vle2+RowPixels, w$, 7);
lyz = lyy;
goto j1337;
j1410: itoa(lmm, w$, 10);
k = _gettextextent( w$ ) / 2;
gfprint(ib-k, vle2+RowPixels, w$, 7);
j1337: gmoveto(ib, vlen); glineto(ib, vle2);
itoa(ldd, w$, 10);
k = _gettextextent( w$ ) / 2;
gfprint(ib-k, vle2, w$, 7);
lmz = lmm;
days = st0 + f;
fnlac(days, &lyy, &lmm, &ldd);
}
}
else {
stn = (fncal(kyy2,km2,kd2)-fncal(kyy1,km1,kd1))*24 + kh2+1-kh1;
if((svn=(int)(stn/8.)) < 1) svn = 1;
rt0 = kh1;
rt1 = kh1 + kn1/60.;
rt2 = kh2 + kn2/60.;
st0 = fncal(kyy1,km1,kd1);
ut = 418/((st2-st0)*24.+rt2+1-rt0);
lmm = km1; ldd = kd1; lhh = kh1; lmz = -1; ldz = -1;
for(f=0.; f<=stn; f+=svn) {
ib = 57 + (int)(((fncal(kyy1,lmm,ldd)-st0)*24.+lhh-rt0)*ut);
if(ldd == ldz) goto j1347;
if(lmm == lmz) goto j1420;
strcat(itoa(lmm,w$,10), "/");
strcat(w$, itoa(ldd,z$,10));
k = _gettextextent( w$ ) / 2;
gfprint(ib-k, vle2+RowPixels, w$, 7);
lmz = lmm; goto j1347;
j1420: itoa(ldd, w$, 10);
k = _gettextextent( w$ ) / 2;
gfprint(ib-k, vle2+RowPixels, w$, 7);
j1347: gmoveto(ib, vlen); glineto(ib, vle2);
itoa(lhh, w$, 10);
k = _gettextextent( w$ ) / 2;
gfprint(ib-k, vle2, w$, 7);
ldz = ldd;
iday = (int)(f / 24.);
ihr = (int)(f - iday*24);
lhh = kh1 + ihr;
if(lhh > 23) { iday++; lhh -= 24; }
days = st0 + iday;
fnlac(days, &lyy, &lmm, &ldd);
}
}
_setcolor( 3 );
if(jtm == 3) ib = 57 + (int)(((st1-st0)*24.+rt1-rt0)*ut);
else ib = 57 + (int)((st1-st0)*ut);
gmoveto(ib, vlen); glineto(ib, vle2);
if(jtm == 3) ib = 57 + (int)(((st2-st0)*24.+rt2+1-rt0)*ut);
else ib = 57 + (int)((st2+1-st0)*ut);
gmoveto(ib, vlen); glineto(ib, vle2);
}
else { /* LOG */
st1 = 1;
switch( jtm ) {
case 0: st0 = fncal(kyy1,1,1);
st2 = kyy2-kyy1+1;
break;
case 1: st0 = fncal(kyy1,km1,1);
st2 = (kyy2-kyy1)*12+km2+1-km1;
break;
case 2: st0 = fncal(kyy1,km1,kd1);
st2 = fncal(kyy2,km2,kd2)-fncal(kyy1,km1,kd1)+1;
break;
case 3: st0 = fncal(kyy1,km1,kd1); rt0 = kh1;
st2 = (fncal(kyy2,km2,kd2)-
fncal(kyy1,km1,kd1))*24 + kh2+1-kh1;
break;
}
i = (int)st1; j = (int)st2;
scale(i, j, &i, &rsb, &j);
f = rsb;
rtb = log10(f); ut = 418/rtb;
_setcolor( 7 );
j = 1;
for(i=0; i<5; i++) {
if(i > rsb) break;
ib = 57 + (int)(i*ut);
gmoveto(ib, vlen); glineto(ib, vle2);
itoa(j, w$, 10);
k = _gettextextent( w$ ) / 2;
gfprint(ib-k, vle2, w$, 7);
j = j * 10;
}
_setcolor( 3 );
gmoveto(57, vlen); glineto(57, vle2);
ib = 57 + (int)(log10(st2)*ut);
gmoveto(ib, vlen); glineto(ib, vle2);
i = (int)st2; itoa(i, w$, 10);
k = _gettextextent( w$ ) / 2;
gfprint(ib-k, vle2, w$, 3);
}
}
void itos(i, s, len)
int i, len;
char *s;
{
int j; char t[11];
itoa(i, t, 10);
if((int)strlen(t) < len) {
for(j=0; j<len-(int)strlen(t); j++) s[j] = ' ';
s[j] = 0;
}
else *s = 0;
strcat(s, t);
}
/************************ Panel Definitions **********************/
char time_pan[] = "\
Request : TIME \
Specify attributes of the coordinates in () as you like and press Enter. \
X-Axis : Item < TIME > \
Scaling ( ) <--- LNR/LOG(Linear/Logarithmic) \
From ( / / ) ( : : ) \
To ( / / ) ( : : ) \
Tick Unit ( ) <--- Y/M/D/H(Year/Month/Day/Hour) \
Y-Axis : Item ( ) <--- FRQ/ACM/MAG \
(Frequency/Accumulated/Magnitude) \
Scaling ( ) <--- LNR/LOG(Linear/Logarithmic) \
Y1 ( ) \
Y2 ( ) \
\
33, 3, 3 \
33, 4, 4 \
40, 4, 2 \
45, 4, 2 \
52, 4, 2 \
57, 4, 2 \
62, 4, 5 \
33, 5, 4 \
40, 5, 2 \
45, 5, 2 \
52, 5, 2 \
57, 5, 2 \
62, 5, 5 \
33, 6, 1 \
33, 7, 3 \
33, 9, 3 \
33, 10, 5 \
33, 11, 5 ";