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.02
/
map.c
< prev
next >
Wrap
C/C++ Source or Header
|
1999-11-10
|
19KB
|
664 lines
/* SeisView alone/client Copyright (C) 1992,1998 K.Koketsu
<history>
98-11-04 Remote auxiliary files.
98-11-03 Include panel definitions and remove CR.
98-10-06 Some global variables are replaced by constants.
98-02-25 Abandon DOS, but take Windows 95/NT.
96-06-22 version 2.02
93-12-07 version 2.01 */
#include <stdlib.h>
#include <string.h>
#include <ctype.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 char z$[11], w$[81]; /* work string */
/***************************** variables for menu ****************************/
extern char em$[51]; /* error message on menu */
extern char mc$[42][9], md$[65]; /* field strings */
extern short isr; /* initial cursor position */
extern short kd[13]; /* function key definitions*/
/**************************** variables for retrieval ***********************/
extern char f2$[6];
extern char dst$[11];
extern char so1$[4], som1$[3], so2$[4], som2$[3];
extern char sa1$[3], sam1$[3], sa2$[3], sam2$[3];
extern char sew1$[2], sew2$[2], sns1$[2], sns2$[2];
/**************************** parameters for map ****************************/
int kx0, kx1, ky0, ky1;
int cdp[7], icd[7];
double cmg[8], rmg[8];
int ndp, nmg;
double ro, ru;
int dmap(), epicenters();
char est$[11], mps$[9], yns$[2], ync$[4];
char to1$[4], tom1$[3], to2$[4], tom2$[3];
char ta1$[3], tam1$[3], ta2$[3], tam2$[3];
char tew1$[2], tew2$[2], tns1$[2], tns2$[2];
double yln[181], dln[180]; /* some values for map projection */
double a1,a2, b1,b2; /* latitude, longitude */
double c1, c2;
double xm, ym, rrx, rry;
short ynmap; /* flag wether a map is actually drawn */
short wrap; /* flag of wrap-around */
int map1(), map2();
int map()
{
double tte, yko;
int i, np, nplot;
short tom1, tom2, tam1, tam2;
if(itot == 0) return( 3 );
strcpy(est$,dst$);
strcpy(to1$,so1$); strcpy(tom1$,som1$); strcpy(tew1$,sew1$);
strcpy(to2$,so2$); strcpy(tom2$,som2$); strcpy(tew2$,sew2$);
strcpy(ta1$,sa1$); strcpy(tam1$,sam1$); strcpy(tns1$,sns1$);
strcpy(ta2$,sa2$); strcpy(tam2$,sam2$); strcpy(tns2$,sns2$);
strcpy(yns$,"N");
j10:
strcpy(mc$[ 0],mps$); strcpy(md$,est$);
strcpy(mc$[ 2],to1$); strcpy(mc$[ 3],tom1$); strcpy(mc$[ 4],tew1$);
strcpy(mc$[ 5],to2$); strcpy(mc$[ 6],tom2$); strcpy(mc$[ 7],tew2$);
strcpy(mc$[ 8],ta1$); strcpy(mc$[ 9],tam1$); strcpy(mc$[10],tns1$);
strcpy(mc$[11],ta2$); strcpy(mc$[12],tam2$); strcpy(mc$[13],tns2$);
strcpy(mc$[14],yns$); strcpy(mc$[15],ync$);
if(*mps$ != 0) isr = 0;
else if(*est$ != 0) isr = 1;
else isr = 2;
j31:
np = panel(MAP);
if(np==3 || np==6) return( 0 );
strxcpy(mps$, mc$[0]);
strxcpy(est$, md$);
strcpy(to1$,mc$[ 2]); strcpy(tom1$,mc$[ 3]); strcpy(tew1$,mc$[ 4]);
strcpy(to2$,mc$[ 5]); strcpy(tom2$,mc$[ 6]); strcpy(tew2$,mc$[ 7]);
strcpy(ta1$,mc$[ 8]); strcpy(tam1$,mc$[ 9]); strcpy(tns1$,mc$[10]);
strcpy(ta2$,mc$[11]); strcpy(tam2$,mc$[12]); strcpy(tns2$,mc$[13]);
strcpy(yns$,mc$[14]); strcpy(ync$ ,mc$[15]);
if( *est$ ) {
if(! dist(est$,1)) {
isr = 1;
strcpy(em$, "Invalid region name!");
goto j31;
}
}
tom1 = atoi(tom1$); tom2 = atoi(tom2$);
tam1 = atoi(tam1$); tam2 = atoi(tam2$);
if(tom1 > 59) isr = 3;
if(tom2 > 59) isr = 6;
if(tam1 > 59) isr = 9;
if(tam2 > 59) isr = 12;
if(isr > 2) {
strcpy(em$, "Minute values should be less than 60!");
goto j31;
}
b1 = atoi(to1$) + tom1/60.;
b2 = atoi(to2$) + tom2/60.;
a1 = atoi(ta1$) + tam1/60.;
a2 = atoi(ta2$) + tam2/60.;
if(*tew1$ == 'W') b1 = - b1;
if(*tew2$ == 'W') b2 = - b2;
if(*tns1$ == 'S') a1 = - a1;
if(*tns2$ == 'S') a2 = - a2;
if(a1 > a2) {
strcpy(em$,"The second latitude should be in the north of the first!");
goto j31;
}
if(b1 >= b2) { wrap = 1; b2 = b2 + 360.; }
else wrap = 0;
if(!strcmp(yns$,"Y")) { /* Change plotting parameters. */
switch( map1() ) {
case 3: return( 0 );
case 6: goto j10;
}
}
for(i=0; i<nmg; i++) {
if(i == 0) rmg[i] = ro;
else rmg[i] = rmg[i-1]*ru;
}
clear( 0 );
c1 = fnyy(a1); c2 = fnyy(a2);
xm = b2 - b1; ym = c2 - c1;
ky1 = YPixels-1;
tte = ky1;
yko = tte * xm/ym;
if(yko > 490.) {
yko = 490.; tte = yko * ym/xm;
}
kx0 = (int)(245 - yko/2); kx1 = (int)(kx0 + yko);
ky0 = (int)(ky1/2 - tte/2); ky1 = (int)(ky0 + tte);
rrx = (kx1-kx0) / xm; rry = (ky1-ky0) / ym;
j40:
ynmap = 1;
if(! dmap(mps$,0)) {
gviewport(0, 0, 639, YPixels-1);
goto j31;
}
nplot = epicenters();
gviewport(0, 0, 639, YPixels-1);
if(atoi(ync$) > 0) nplot = - atoi( ync$ );
legend(mps$, nplot);
np = fgkey(1, 1);
if(np == F1) goto j40;
if(np == F8) np = map2();
if(np == F3) return( 0 );
else { if(np != F6) beep(); goto j10; }
}
int map1()
{
int i, k;
for(i=0; i<7; i++) {
if(i < ndp) {
itoa(cdp[i], mc$[i*2 ], 10);
itoa(icd[i], mc$[i*2+1], 10);
}
else {
strcpy(mc$[i*2 ], " ");
strcpy(mc$[i*2+1], " ");
}
}
for(i=0; i<8; i++) {
if(i < nmg) hcvt(cmg[i], mc$[14+i]);
else strcpy(mc$[14+i], " ");
}
hcvt(ro, mc$[22]);
hcvt(ru, mc$[23]);
if(k = panel(MAP1)) return( k );
for(i=0; i<7; i++) {
if(!strcmp(mc$[i*2]," ")) break;
cdp[i] = atoi( mc$[i*2 ] );
icd[i] = atoi( mc$[i*2+1] );
}
ndp = i;
for(i=0; i<8; i++) {
if(!strcmp(mc$[14+i]," ")) break;
cmg[i] = atof( mc$[14+i] );
}
nmg = i;
ro = atof( mc$[22] );
ru = atof( mc$[23] );
}
/*** subfunction selection (map2) ***/
int map2()
{
int i, isf;
char isf$[2];
strcpy(isf$, "1");
j50:
strcpy(md$,est$);
strcpy(mc$[ 1],to1$); strcpy(mc$[ 2],tom1$); strcpy(mc$[ 3],tew1$);
strcpy(mc$[ 4],to2$); strcpy(mc$[ 5],tom2$); strcpy(mc$[ 6],tew2$);
strcpy(mc$[ 7],ta1$); strcpy(mc$[ 8],tam1$); strcpy(mc$[ 9],tns1$);
strcpy(mc$[10],ta2$); strcpy(mc$[11],tam2$); strcpy(mc$[12],tns2$);
j52:
strcpy(mc$[13],isf$); strcpy(mc$[14],"N");
isr = 13;
kd[6] = 6;
i = panel( MAP2 );
if(i < 0) i = 6;
if(i==3 || i==6) return(i + F1 - 1);
strcpy(isf$,mc$[13]); isf = atoi( isf$ );
if(!strcmp(mc$[14],"Y") || isf>=5) ynmap = 1; else ynmap = 0;
if(isf>0 && isf<7) {
switch( isf ) {
case 1: i = map_find(); break;
case 2: i = map_select(); break;
case 3: i = map_cross_section(); break;
case 4: i = map_space_time(); break;
case 5: i = map_active_faults(); break;
case 6: i = map_stations(); break;
}
if(i== F3) return( i );
else goto j50;
}
else {
strcpy(em$, "Invalid subfunction number!");
goto j52;
}
}
int dmap(map$, flag, ifc)
char *map$;
int flag, ifc[];
{
char *iwseg;
char f$[13], a$[5], c, d[2];
unsigned short na;
short i, n, mp, lx, ly, ic, lxo, kx2;
long bb[4], b3, am1, am2, bm1, lonoff, mp360;
long xxm, xo, xp, c2ry;
double yym, yo, yp, rrxm;
if(*map$ == 0) {
if(b1>=90. && b2<=180. && a1>=0. && a2<=90.) strcpy(f$,"NWPAC");
else if(rrx < 4.0) strcpy(f$,"EARTH");
else strcpy(f$,"WORLD");
}
else strcpy(f$, map$);
strlwr( f$ );
if(flag == 0) strcat(f$, ".m");
else strcat(f$, ".f");
c2ry = (long)(c2 * rry);
_setcolor( 7 );
_setbkcolor( 0 );
gbox(0, kx0, ky0, kx1, ky1);
gviewport(kx0+1, ky0+1, kx1-1, ky1-1);
kx2 = kx1 - kx0 -2;
if(flag==0 && !ynmap) return( 1 );
pspen(1, -1);
iwseg = iseg[nseg-1];
a$[4] = 0;
if(! rbload(iwseg, 0, f$)) return( 0 );
na = 0;
c = peek(na,iwseg);
lonoff = (short)qeek(na+1,iwseg);
if(c == 'F') mp = 1000; else mp = 100;
bm1 = (long)((b1-lonoff) * mp);
b3 = (long)(b2*mp - bm1);
am1 = (long)(a1 * mp);
am2 = (long)(a2 * mp);
rrxm = rrx / mp;
mp360 = (long)mp * 360;
na += 3;
j20:
c = peek(na++,iwseg);
d[0] = peek(na++,iwseg);
if(c == 'X') { pspen(2, 0); return( 1 ); }
if(c == 'Z') {
if(*d != '2') f$[strlen(f$)-1] = 0;
d[1] = 0; strcat(f$, d);
if(! rbload(iwseg, 0, f$)) return( 0 );
na = 0;
goto j20;
}
if(*d == '2') { n = qeek(na,iwseg); na += 2; }
else n = peek(na++,iwseg);
for(i=0; i<4; i++) {
if(mp == 1000) bb[i] = qeek(na,iwseg);
else bb[i] = (short)qeek(na,iwseg);
na += 2;
if(i > 1) {
bb[i] = bb[i] - bm1;
if(wrap && bb[i]<0) bb[i] = bb[i] + mp360;
}
}
if(bb[2] > bb[3]) {
xo = bb[3];
bb[3] = bb[2];
bb[2] = xo;
}
if(bb[0]>am2 || bb[1]<am1 || bb[2]>b3 || bb[3]<0) {
na = na + 4*n; goto j20;
}
pspen(-1, 0);
switch( c ) {
case 'B': ic = 1; pspen(-1, 1); break;
case 'F': ic = ifc[0]; break;
case 'G': ic = ifc[1]; break;
case 'H': ic = ifc[2]; break;
case 'I': ic = ifc[3]; break;
default : ic = 3;
}
_setcolor( ic );
for(i=0; i<n; i++) {
if(mp == 1000) {
yym = qeek(na ,iwseg);
xxm = qeek(na+2,iwseg);
}
else {
yym = (short)qeek(na ,iwseg);
xxm = (short)qeek(na+2,iwseg);
}
na += 4;
xxm = xxm - bm1;
if(wrap && xxm<0) xxm = xxm + mp360;
yym = lat( yym/mp );
lx = (short)(xxm * rrxm);
ly = (short)(c2ry - yym*rry);
if(i == 0) gmoveto(lx, ly);
else {
if((lxo<10 && lx>kx2-10) || (lxo>kx2-10 && lx<10)) {
if(lxo < 10) xp = 0;
else xp = b3;
yp = (xp-xo)*(yym-yo)/(xxm-xo) + yo;
lx = (short)(xp * rrxm);
ly = (short)(c2ry - yp*rry);
glineto(lx, ly);
if(lxo < 10) xp = b3;
else xp = 0;
lx = (short)(xp * rrxm);
gmoveto(lx, ly);
}
lx = (short)(xxm * rrxm);
ly = (short)(c2ry - yym*rry);
glineto(lx, ly);
}
lxo = lx;
xo = xxm;
yo = yym;
}
goto j20;
}
/******************* EPICENTERS ****************** (Plot epicenters.) */
int epicenters()
{
int i, ic, im, lx, ly, n;
double xx, yy, hh, rm;
n = 0;
for(i=0; i<itot; i++) {
eqparm(i, &xx, &yy, &hh, &rm, 0);
if(wrap && xx<b2-360.) xx = xx + 360.;
if(xx>b1 && xx<b2 && yy>a1 && yy<a2) {
for(ic=ndp-1; ic>0; ic--) if(hh >= cdp[ic]) break;
for(im=nmg-1; im>0; im--) if(rm >= cmg[im]) break;
im = (int)rmg[im];
lx = (int)((xx-b1) * rrx);
ly = (int)((c2-lat(yy)) * rry);
_setcolor( icd[ic] );
gsymbol(lx, ly, im, icd[ic]);
n++;
}
}
return( n );
}
/********* LEGEND ************ (Write legends for basic map.) */
void legend(mps$, nplot)
char *mps$;
int nplot;
{
char *c;
int i, ja, j, ic, im, lx, ly;
double xx, yy, hh, rm;
if(nplot >=0) {
gprint(63, 1, "MAP", 4);
pfromto(-2, nplot);
gprint(63, 9, "depth ", 2);
for(i=0; i<=ndp; i++) {
j = (int)((i+8.5) * RowPixels) + 1;
if(i == ndp) {
_setcolor( icd[0] );
strcpy(w$, "unknown");
}
else {
_setcolor( icd[i] );
itoa(cdp[i], w$, 10);
if(c = strchr(w$,'.')) *c = 0;
strcat(w$, " -");
}
gsymbol(554, j, 5, icd[i]);
gprint(72, i+9, w$, 7);
}
mag_legend();
}
else {
pspen(1, 0);
_setcolor( 7 );
gbox(0, kx1+5, ky0+1, kx1+95, ky1-1);
gbox(0, kx0+1, ky1+5, kx1-1, ky1+95);
gsmall_font();
gfprint(kx1+ 3, ky1+ 1, "0", 7);
gfprint(kx1+80, ky1+ 1, ync$, 7);
gfprint(kx1+ 3, ky1+85, ync$, 7);
gnormal_font();
pspen(2, 0);
for(i=0; i<itot; i++) {
eqparm(i, &xx, &yy, &hh, &rm, 0);
if(xx>b1 && xx<b2 && yy>a1 && yy<a2 && hh<=-nplot) {
for(ic=ndp-1; ic>0; ic--) if(hh >= cdp[ic]) break;
for(im=nmg-1; im>0; im--) if(rm >= cmg[im]) break;
im = (int)rmg[im];
lx = (int)((xx-b1) * rrx);
ly = (int)((c2-lat(yy)) * rry);
ja = (int)(hh * 90 / (-nplot));
_setcolor( icd[ic] );
gsymbol(ja+kx1+5, ly+ky0+1, im, icd[ic]);
gsymbol(lx+kx0+1, ja+ky1+5, im, icd[ic]);
}
}
}
}
void mag_legend()
{
int ia, ja, j, k;
gprint(63, 17, "magnitude ", 2);
ja = 1;
for(ia=0; ia<nmg; ia+=ja) {
j = (int)((ia/ja+17.5) * RowPixels);
if(ia == 8) { k = (int)rmg[0]; strcpy(w$, "unknown"); }
else {
k = (int)rmg[ia];
hcvt(cmg[ia], w$);
strcat(w$, " -");
}
gprint(72, ia/ja+18, w$, 7);
gcircle(0, 554, j, k);
}
}
void map_init()
{
short i;
double ri;
for(i=0; i<=180; i++) {
ri = i - 90;
yln[i] = fnyy(ri);
}
for(i=0; i<=179; i++) dln[i] = yln[i+1] - yln[i];
}
void dpmg_init()
{
int i;
ndp = 7;
cdp[0] = 0; cdp[1] = 20; cdp[2] = 40; cdp[3] = 60;
cdp[4] = 80; cdp[5] =200; cdp[6] =600;
icd[0] = 4; icd[1] = 5; icd[2] = 6; icd[3] = 2;
icd[4] = 3; icd[5] = 1; icd[6] = 7;
nmg = 8;
for(i=0; i<nmg; i++) cmg[i] = i;
ro = 1.50; ru = 1.25;
strcpy(ync$, "000");
}
double fnyy( pp )
double pp;
{
/* Mercator */
/* return( log(tan((pp/2.+45.)/57.2958))*57.2958 ); */
/* Miller */
return( 1.25*log(tan((pp*0.4+45.)/57.2958))*57.2958 );
}
double lat( yy )
double yy;
{
int lnn;
if(yy < -90) lnn = 0;
else lnn = (int)yy + 90;
return( yln[lnn] + dln[lnn]*(yy+90-lnn) );
}
void eqparm(ia, xx, yy, hh, rm, iss)
int ia, iss;
double *xx, *yy, *hh, *rm;
{
int ipag, mr;
unsigned na;
char *is;
ipag = ia / 4095;
is = iseg[iss+ipag];
na = (ia-ipag*4095)*16 + 4;
*xx = bin2deg(na+ 7, is);
*yy = bin2deg(na+10, is);
*hh = (short)qeek(na+13,is)/10.;
if(peek(na,is) == 255) *hh = 0.;
mr = peek(na+15,is);
if(mr == 0) *rm = -9999.;
else if(mr & 0x80) *rm = - (mr&0x7f)/10.;
else *rm = mr / 10.;
}
double bin2deg(off, is)
unsigned off;
char *is;
{
short min;
double v;
min = peek(off+1,is);
if(min & 0x80)
v = - (peek(off,is) + (min & 0x7f)/60. + peek(off+2,is)/3600.);
else v = peek(off,is) + min/60. + peek(off+2,is)/3600.;
return( v );
}
/************************ Panel Definitions **********************/
char map_pan[] = "\
Request : MAP \
Change parameters in () as you like and press Enter. \
1. Map Dataset ( ) \
2. Region ( ) \
or Longitude -deg,min- ( )( ) ( ) --> ( )( ) ( ) \
Latitude -deg,min- ( )( ) ( ) --> ( )( ) ( ) \
3. Do you like to change symbol assignments? < Y/N > ( ) \
4. Maximum depth for associated cross-section charts -km- ( ) \
|If you give 0km, no associated charts will be drawn. Even if drawn,| \
|one of them will appear incomplete, but complete in a PostScript copy.| \
\
26, 2, 8 \
26, 3, 10 \
26, 4, 3 \
33, 4, 2 \
40, 4, 1 \
50, 4, 3 \
57, 4, 2 \
64, 4, 1 \
26, 5, 2 \
32, 5, 2 \
39, 5, 1 \
50, 5, 2 \
56, 5, 2 \
63, 5, 1 \
61, 6, 1 \
61, 7, 3 ";
char map1_pan[] = "\
Request : MAP \
Change color and size of symbols and their corresponding depth \
and magnitude ranges in () as you like and press Enter. \
Depth class range color | \
DEP0 ( ) - ( ) | 1 : Blue (Cross) \
DEP1 ( ) - ( ) | 2 : Green (Triangle) \
DEP2 ( ) - ( ) | 3 : Cyan (Rv.Triangle)\
DEP3 ( ) - ( ) | 4 : Red (Circle) \
DEP4 ( ) - ( ) | 5 : Magenta (Square) \
DEP5 ( ) - ( ) | 6 : Yellow (Diamond) \
DEP6 ( ) - ( ) | 7 : White (Plus) \
unknown DEP0 \
Magnitude class range \
MAG0 ( ) - Classes below a class with \
MAG1 ( ) - a blank range will not work. \
MAG2 ( ) - \
MAG3 ( ) - \
MAG4 ( ) - \
MAG5 ( ) - \
MAG6 ( ) - \
MAG7 ( ) - \
unknown MAG0 \
Size base size <MAG0> : ( )pixels factor : ( ) \
29, 4, 3 \
44, 4, 1 \
29, 5, 3 \
44, 5, 1 \
29, 6, 3 \
44, 6, 1 \
29, 7, 3 \
44, 7, 1 \
29, 8, 3 \
44, 8, 1 \
29, 9, 3 \
44, 9, 1 \
29, 10, 3 \
44, 10, 1 \
31, 13, 4 \
31, 14, 4 \
31, 15, 4 \
31, 16, 4 \
31, 17, 4 \
31, 18, 4 \
31, 19, 4 \
31, 20, 4 \
38, 22, 4 \
64, 22, 4 ";
char map2_pan[] = "\
Request : MAP SUBFUNCTIONS \
Mapping Area: \
Region < > \
or Longitude -deg,min- < >< > < > --> < >< > < > \
Latitude -deg,min- < >< > < > --> < >< > < > \
\
Specify a subfunction number and press Enter. \
( ) 1 : Find 4 : Space-Time \
2 : Select 5 : Active Faults \
3 : Cross-Section 6 : Stations \
\
Do you need epicenters to be overlaid with the map? < Y/N > ( ) \
(For active faults or stations the map will be always overlaid.) \
\
26, 2,-10 \
26, 3, -3 \
33, 3, -2 \
40, 3, -1 \
50, 3, -3 \
57, 3, -2 \
64, 3, -1 \
26, 4, -2 \
32, 4, -2 \
39, 4, -1 \
50, 4, -2 \
56, 4, -2 \
63, 4, -1 \
27, 7, 1 \
67, 11, 1 ";