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 / mapsub.c < prev    next >
C/C++ Source or Header  |  2000-04-23  |  27KB  |  978 lines

  1. /*  SeisView alone/client    Copyright (C) 1992,2000  K.Koketsu
  2.          <history>
  3.          00-04-25  Remove unwanted debugging statements.
  4.          98-11-05  Remote auxiliary files.
  5.          98-11-03  Include panel definitions and remove CR.
  6.                    Fix bugs for a region traversing the date line.
  7.          98-10-06  Some global variables are replaced by constants.
  8.                    _setbkcolor(0) in the initialization.
  9.          98-02-25  Abandon DOS, but take Windows 95/NT.
  10.          93-06-02  version 2.00                    */
  11.  
  12. #include <math.h>
  13. #include "ctlname.h"
  14. #include "seis.h"
  15.  
  16. #ifdef WIN32
  17. extern HWND hwnd;
  18. #endif
  19. extern char     *iseg[10];            /* work segments for  selected events  */
  20. extern unsigned nseg;                 /* number of working segments          */
  21. extern short    nmax, nmax2;          /* maximum numbers of selected events  */
  22. extern int    itot;                               /* total # selected events */
  23. extern char   z$[11], w$[81];                     /* work string             */
  24.  
  25. /***************************** variables for menu ****************************/
  26. extern char   em$[51];                            /* error message on menu   */
  27. extern char   mc$[42][9];                         /* field strings           */
  28. extern short  isr;                                /* initial cursor position */
  29. extern short  kd[13];                             /* function key definitions*/
  30.  
  31. /******************** parameters for retrieving kernel **********************/
  32. extern long     lo1,lo2;            /* longitude            */
  33. extern short    lom1,lom2, la1,lam1,la2,lam2;    /* lonmin, lat,latmin        */
  34.  
  35. /**************************** variables for retrieval ************************/
  36. extern char   f2$[6];
  37. extern char   y1$[5], m1$[3], d1$[3], h1$[3], n1$[3], s1$[5];
  38. extern char   y2$[5], m2$[3], d2$[3], h2$[3], n2$[3], s2$[5];
  39. extern char   dst$[9];
  40. extern char   dp1$[6], dp2$[6], mg1$[5], mg2$[5];
  41. extern char   ynh$[2], ynm$[2];
  42.  
  43. /**************************** parameters for map ****************************/
  44. extern int    kx0, kx1, ky0, ky1;
  45. extern char   mps$[9], ync$[4];
  46. extern double yln[181], dln[180];    /* some values for map projection   */
  47. extern double a1,a2, b1,b2;            /* latitude,  longitude        */
  48. extern double c1, c2;
  49. extern double xm, ym, rrx, rry;
  50. extern int    cdp[7], icd[7];
  51. extern double cmg[8], rmg[8];
  52. extern int    ndp, nmg;
  53. extern short  wrap;                /* flag of wrap-around        */
  54.  
  55. /**************************** variables for TIME *****************************/
  56. extern int    kyy1, km1, kd1, kh1, kn1;
  57. extern int    kyy2, km2, kd2, kh2, kn2;
  58.  
  59. /**************************** variables for taxis ****************************/
  60. extern double st0, rt0, ut;
  61.  
  62. /********************* parameters for cross-section **************************/
  63. long   lo[5];
  64. short  lom[5], la[5], lam[5];
  65.  
  66. void   map_retrv(), press_prompt(), map_sub_prep(), legend2(), ital(),
  67.        otparm();
  68. int    project_area();
  69. double rtal(), delta();
  70.  
  71. /*** map subfunction-1 (find) ***/
  72. int map_find()
  73. {
  74.     int     ip, iq, ic, id, ie, icy, p[2], q[2];
  75.     int     i, itof, ly, printing;
  76.     double  f;
  77.  
  78.     ly = 21;
  79.     printing = 0;
  80.     clear( 0 );
  81. j10:
  82.     dmap(mps$, 0);
  83.     epicenters();
  84.     gviewport(0, 0, 639, YPixels-1);
  85.  
  86.     if(! printing) {
  87.     gprint(63, ly  , "Move the cross     ", 4);
  88.     gprint(63, ly+1, "to area center     ", 4);
  89.     press_prompt(1, ly+2);
  90.     ip = (kx1+kx0)/2;  iq = (ky1+ky0)/2;
  91.     gcursor(kx0, ky0, kx1, ky1, &ip, &iq, 1);
  92.     if(ip == -1)  goto j10;
  93.     
  94.     gprint(63, ly+1, "on circumference   ", 4);
  95.     ie = ip + 3;  id = (int)(iq - 2);
  96.     gcursor(kx0, ky0, kx1, ky1, &ie, &id, 0);
  97.     if(ie == -1)  goto j10;
  98.     }
  99.  
  100.     f = (ie-ip)*(ie-ip) + (id-iq)*(id-iq);
  101.     ic  = (int)sqrt( f );
  102.     icy =  ic;
  103.     _setcolor( 2 );  gcircle(0, ip, iq, ic);
  104.     press_prompt(2, ly);
  105.     gprint(63, ly+1, "a function key     ", 4);
  106.     gprint(63, ly+2, "on the toolbar.    ", 4);
  107.  
  108.     i = fgkey(0, 0);
  109.     printing = 0;
  110.     if(i == -1)  goto j10;
  111.     if(i == F1) { printing = 1; goto j10; }
  112.     if(i != cr)  return(i);
  113.  
  114. /* retrieve */
  115.     p[0] = ip - ic;  q[0] = iq + icy;
  116.     p[1] = ip + ic;  q[1] = iq - icy;
  117.     map_sub_prep(p, q, 2);
  118.     clear( 0 );
  119.     _setcolor( 4 );    /* Paint the area. */
  120.     gcircle(1, ip, iq, ic);
  121.     map_retrv( &itof );
  122.  
  123.     if(itof == 0) {
  124.     strcpy(em$, "No event was found.");
  125.     return(6 + F1 + 1);
  126.     }
  127.     return( table(1, itof) );
  128. }
  129.  
  130. /*** map subfunction-2 (select) ***/
  131. int map_select()
  132. {
  133.     int     p[4], q[4];
  134.     short   i, j, ly, printing;
  135.     unsigned iw;
  136.     char    *zseg;
  137.  
  138.     ly = 21;
  139.     printing = 0;
  140.     clear( 0 );
  141. j10:
  142.     dmap(mps$, 0);
  143.     epicenters();
  144.     gviewport(0, 0, 639, YPixels-1);
  145.  
  146. /* specify four corners of the area */
  147.     for(i=0; i<4; i++) {
  148.     if(i == 0) {
  149.         if(! printing) {
  150.         gprint(63, ly  , "Move the cross     ", 4);
  151.         gprint(63, ly+1, "to 1st area corner ", 4);
  152.         press_prompt(1, ly+2);
  153.         p[0] = (kx1+kx0)/2;  q[0] = (ky1+ky0)/2;
  154.         gcursor(kx0, ky0, kx1, ky1, &p[i], &q[i], 1);
  155.         if(p[i] == -1)  goto j10;
  156.         }
  157.     }
  158.     else {
  159.         if(! printing) {
  160.         switch( i ) {
  161.             case 1: gprint(63, ly+1, "to 2nd area corner ", 4); break;
  162.             case 2: gprint(63, ly+1, "to 3rd area corner ", 4); break;
  163.             case 3: gprint(63, ly+1, "to 4th area corner ", 4); break;
  164.         }
  165.         p[i] = p[i-1] + 3;
  166.         q[i] = q[i-1] - 2;
  167.         gcursor(kx0, ky0, kx1, ky1, &p[i], &q[i], 0);
  168.         if(p[i] == -1)  goto j10;
  169.         }
  170.         _setcolor( 2 );
  171.         gmoveto(p[i-1], q[i-1]);
  172.         glineto(p[i  ], q[i  ]);
  173.     }
  174.     }
  175.     glineto(p[0], q[0]);
  176.  
  177.     map_sub_prep(p, q, 4);
  178.  
  179.     press_prompt(2, ly);
  180.     gprint(63, ly+1, "a function key     ", 4);
  181.     gprint(63, ly+2, "on the toolbar.    ", 4);
  182.     i = fgkey(0, 0);
  183.     printing = 0;
  184.     if(i == -1)  goto j10;
  185.     if(i == F1) { printing = 1; goto j10; }
  186.     if(i != cr)  return( i );
  187.  
  188. /* confirmation */
  189.     strcpy(mc$[24],dp1$);  strcpy(mc$[25],dp2$);  strcpy(mc$[26],ynh$);
  190.     strcpy(mc$[27],mg1$);  strcpy(mc$[28],mg2$);  strcpy(mc$[29],ynm$);
  191.     strcpy(mc$[30],"Y");
  192.     isr = 30;
  193.     i = panel( MAPS2 );
  194.     if(i==3 || i==6)  return(i + F1 - 1);
  195.     if(!strcmp(mc$[30],"N"))  return(6 + F1 - 1);
  196.  
  197. /* select */
  198.     clear( 0 );
  199.     _setcolor( 4 );    /* Paint the area. */
  200.     gfillpolygon(p, q, 4);
  201.     map_retrv( &itot );
  202.  
  203.     iw = nmax/4095;
  204.     j = itot / 4095;  if(itot%4095 != 0) j++;
  205.     for(i=0; i<j; i++) {
  206.     zseg = iseg[i];
  207.     iseg[i] = iseg[iw+i];
  208.     iseg[iw+i] = zseg;
  209.     }
  210.  
  211.     strcpy(em$, "Memory contents were replaced.");
  212.     return(6 + F1 - 1);
  213. }
  214.  
  215. /**** map subfunction-3 (cross-section) ****/
  216. map_cross_section()
  217. {
  218.     int     p[4], q[4];
  219.     int     i, j, k, ds, rx1, rx2, itof; 
  220.     int     rv1, rv2, ir, vlen, vorg;
  221.     int     ixa, ixb, ixu, ixr, ixn;
  222.     int     iwo, ic, im;
  223.     double  uv, rva, ux, rc, rw;
  224.     double  f, xx, yy, hh, rm;
  225.  
  226.     i = project_area(p, q, &ds, &rw);
  227.     if(i != cr)  return( i );
  228.  
  229.     map_sub_prep(p, q, 4);
  230.  
  231. /* confirmation */
  232.     strcpy(mc$[18], "   0");  strcpy(mc$[19], jtoa(ds,w$,4));
  233.     strcpy(mc$[20], "   0");  strcpy(mc$[21], " 300");
  234.     isr = 18;
  235.     kd[6] = 6;
  236.     i = panel( MAPS3 );
  237.     if(i==3 || i==6)  return(i + F1 - 1);
  238.     rx1 = atoi(mc$[18]);  rx2 = atoi(mc$[19]);
  239.     rv1 = atoi(mc$[20]);  rv2 = atoi(mc$[21]);
  240.  
  241. /* retrieve */
  242.     clear( 0 );
  243.     _setcolor( 4 );    /* Paint the area. */
  244.     gfillpolygon(p, q, 4);
  245.     map_retrv( &itof );
  246.     clear( 0 );
  247.     _setbkcolor( 0 );
  248.  
  249. j10: /* legend */
  250.     gprint(27, 1, "Distance (km)", 2);
  251.     vprint(8, "Depth ^kmv");
  252.     gprint(63, 1, "CROSS-", 4);
  253.     gprint(63, 2, "SECTION", 4);
  254.     gprint(63,10, "leftmost", 2);
  255.     gprint(63,12, "rightmost", 2);
  256.     legend2(ds, itof);
  257.  
  258. /* draw cross-section */
  259.     _setcolor( 7 );
  260.     vorg = (int)(RowPixels * 2.5);
  261.     vlen = YPixels - (int)(RowPixels*3.5);
  262.     gbox(0, 40, vorg, 490, vlen+vorg-RowPixels);
  263.     vaxis(3, rv1, rv2, &ir, &uv, &rva);
  264.     scale(rx1, rx2, &ixa, &ixb, &ixu);
  265.     ixr = ixb - ixa;
  266.     ixn = ixr / ixu;
  267.     ux  = 418. / ixr;
  268.     _setcolor( 7 );
  269.     for(i=1; i<=ixn; i++) {
  270.     itoa(i*ixu+ixa, w$, 10);
  271.     j = 57 + (int)(i*ixu*ux);
  272.     k = _gettextextent( w$ ) / 2;
  273.     gmoveto(j, vorg-RowPixels/2);  glineto(j, vorg);
  274.     if(ixn<9 || i%2==0)  gfprint(j-k, RowPixels, w$, 7);
  275.     }
  276.     _setcolor( 3 );
  277.     j = 57 + (int)((rx1-ixa)*ux);
  278.     gmoveto(j, vorg-RowPixels/2);  glineto(j, vorg);
  279.     j = 57 + (int)((rx2-ixa)*ux);
  280.     gmoveto(j, vorg-RowPixels/2);  glineto(j, vorg);
  281.  
  282.     rc = q[0] - p[0]*rw;
  283.     iwo = nmax / 4095;
  284.     for(i=0; i<itof; i++) {
  285.     eqparm(i, &xx, &yy, &hh, &rm, iwo);
  286.     if(hh>=rv1 && hh<=rv2) {
  287.         f = rtal(xx, yy, rw, rc, p, q);
  288.         if(f>=rx1 && f<=rx2) {
  289.         j = 57 + (int)((f-ixa)*ux);
  290.         k = ir - (int)((hh-rva)*uv);
  291.         for(ic=ndp-1; ic>0; ic--)  if(hh >= cdp[ic]) break;
  292.         for(im=nmg-1; im>0; im--)  if(rm >= cmg[im]) break;
  293.         im = (int)rmg[im];
  294.         _setcolor( icd[ic] );
  295.         gcircle(0, j, k, im);
  296.         }
  297.     }
  298.     }
  299.  
  300.     i = fgkey(0, 1);
  301.     if(i==-1 || i==F1)  goto j10;
  302.     return( i );
  303. }
  304.  
  305. /**** map subfunction-4 (space-time) ****/
  306. int map_space_time()
  307. {
  308.     int    p[4], q[4];
  309.     int    i, j, k, ds, itof; 
  310.     int    rv1, rv2, ir, vlen, vorg;
  311.     int    jtm;
  312.     double st1, st2;
  313.     int    iwo, ic, im;
  314.     int    jy, jm, jd, jh, jn;
  315.     double uv, rva, rc, rw, f;
  316.     double xx, yy, hh, rm, rjt;
  317.  
  318.     i = project_area(p, q, &ds, &rw);
  319.     if(i != cr)  return( i );
  320.  
  321.     map_sub_prep(p, q, 4);
  322.  
  323. /* confirmation */
  324.     strcpy(mc$[18],y1$);  strcpy(mc$[19],m1$);  strcpy(mc$[20],d1$);
  325.     strcpy(mc$[21],h1$);  strcpy(mc$[22],n1$);  strcpy(mc$[23],s1$);
  326.     strcpy(mc$[24],y2$);  strcpy(mc$[25],m2$);  strcpy(mc$[26],d2$);
  327.     strcpy(mc$[27],h2$);  strcpy(mc$[28],n2$);  strcpy(mc$[29],s2$);
  328.     strcpy(mc$[30],"Y");
  329.     strcpy(mc$[31], "   0");  strcpy(mc$[32], jtoa(ds,w$,4));
  330.     isr = 18;
  331.     i = panel( MAPS4 );
  332.     if(i==3 || i==6)  return(i + F1 - 1);
  333.     kyy1 = atoi(mc$[18]);  kyy2 = atoi(mc$[24]);
  334.     km1  = atoi(mc$[19]);  km2  = atoi(mc$[25]);
  335.     kd1  = atoi(mc$[20]);  kd2  = atoi(mc$[26]);
  336.     kh1  = atoi(mc$[21]);  kh2  = atoi(mc$[27]);
  337.     if(!strcmp(mc$[30],"H"))  jtm = 3;
  338.     else if(!strcmp(mc$[30],"D"))  jtm = 2;
  339.     else if(!strcmp(mc$[30],"M"))  jtm = 1;
  340.     else  jtm = 0;
  341.     rv1 = atoi(mc$[31]);  rv2 = atoi(mc$[32]);
  342.  
  343. /* retrieve */
  344.     clear( 0 );
  345.     _setcolor( 4 );    /* Paint the area. */
  346.     gfillpolygon(p, q, 4);
  347.     map_retrv( &itof );
  348.     clear( 0 );
  349.     _setbkcolor( 0 );
  350.  
  351. j10: /* lengend */
  352.     i = 24;
  353.     vprint(8, "Distance ^kmv");
  354.     gprint(63, 1, "SPACE-", 4);
  355.     gprint(63, 2, "TIME", 4);
  356.     gprint(63,10, "bottom", 2);
  357.     gprint(63,12, "top", 2);
  358.     legend2(ds, itof);
  359.  
  360. /* draw space-time chart */
  361.     _setcolor( 7 );
  362.     vorg = 0;
  363.     vlen = YPixels - (int)(RowPixels*3.5);
  364.     gbox(0, 40, vorg, 490, vorg+vlen);
  365.     vaxis(1, rv1, rv2, &ir, &uv, &rva);
  366.     st1 = fncal(kyy1,km1,kd1);  st2 = fncal(kyy2,km2,kd2);
  367.     taxis(1, jtm, st1, st2);
  368.  
  369.     rc = q[0] - p[0]*rw;
  370.     iwo = nmax / 4095;
  371.     for(i=0; i<itof; i++) {
  372.     eqparm(i, &xx, &yy, &hh, &rm, iwo);
  373.     otparm(i, &jy, &jm, &jd, &jh, &jn, iwo);
  374.     f = rtal(xx, yy, rw, rc, p, q);
  375.     if(f>=rv1 && f<=rv2) {
  376.         rjt = fncal(jy,jm,jd);
  377.         if(rjt>=st1 && rjt<=st2) {
  378.         if(jtm == 3) {
  379.             if(rjt==st1 && jh<kh1)  goto j135;
  380.             if(rjt==st2 && jh>kh2)  goto j135;
  381.             j = 57 + (int)(((rjt-st1)*24.+jh+jn/60.-kh1)*ut);
  382.         }
  383.         else  j = 57 + (int)(((rjt-st1+(jh+jn/60.)/24.)*ut));
  384.         k = ir - (int)((f-rva)*uv);
  385.         for(ic=ndp-1; ic>0; ic--)  if(hh >= cdp[ic]) break;
  386.         for(im=nmg-1; im>0; im--)  if(rm >= cmg[im]) break;
  387.         im = (int)rmg[im];
  388.         _setcolor( icd[ic] );
  389.         gsymbol(j, k, im, icd[ic]);
  390.         }
  391.     }
  392. j135:   continue;
  393.     }
  394.  
  395.     i = fgkey(0, 1);
  396.     if(i==-1 || i==F1)  goto j10;
  397.     return( i );
  398. }
  399.  
  400. /*** map subfunction-5 (active faults) ***/
  401. int map_active_faults()
  402. {
  403.     int  ifc[4], i, nplot;
  404.     char fname[9];
  405.  
  406.     if(b1>123 && b2<150 && a1>23 && a2<50)  strcpy(mc$[0],"JAPAN   ");
  407.     else  strcpy(mc$[0],"        ");
  408.     strcpy(mc$[1],"5");  strcpy(mc$[2],"2");
  409.     strcpy(mc$[3],"3");  strcpy(mc$[4],"3");
  410.     isr = 0;
  411. j31:
  412.     i = panel( MAPS5 );
  413.     if(i==3 || i==6)  return(i + F1 - 1);
  414.     if(strcmp(mc$[0],"        ") == 0) {
  415.     strcpy(em$, "Invalid dataset name!");
  416.     goto j31;
  417.     }
  418.     strxcpy(fname, mc$[0]);
  419.     for(i=0; i<4; i++)  ifc[i] = atoi(mc$[i+1]);
  420.  
  421.     clear( 0 );
  422. j10:
  423.     i = dmap(fname, 1, ifc);
  424.     gviewport(0, 0, 639, YPixels-1);
  425.     if(! i)  goto j31;
  426.     dmap(mps$, 0);
  427.     nplot = epicenters();
  428.     gviewport(0, 0, 639, YPixels-1);
  429.     if(atoi(ync$) > 0)  nplot = - atoi( ync$ );
  430.     legend(mps$, nplot);
  431.  
  432.     i = fgkey(0, 1);
  433.     if(i==-1 || i==F1)  goto j10;
  434.     return(i);
  435. }
  436.  
  437. /*** map subfunction-6 (stations) ***/
  438. int map_stations()
  439. {
  440.     int    i, na, lx, ly, nplot;
  441.     char   *iwseg, f$[13], a$[5];
  442.     double xx, yy;
  443.  
  444.     strcpy(mc$[0], f2$);  strcpy(mc$[1], "N");
  445.     isr = 0;
  446. j31:
  447.     i = panel( MAPS6 );
  448.     if(i==3 || i==6)  return(i + F1 - 1);
  449.     if(strcmp(mc$[0],"        ") == 0) {
  450.     strcpy(em$, "Invalid dataset name!");
  451.     goto j31;
  452.     }
  453.     iwseg = iseg[nseg-1];
  454.     strxcpy(f$, mc$[0]);  strlwr( f$ );  strcat(f$, ".s");
  455.     if(! rbload(iwseg, 0, f$))  goto j31;
  456.  
  457.     clear( 0 );
  458. j10:
  459.     dmap(mps$, 0);
  460.     nplot = epicenters();
  461.     rbload(iwseg, 0, f$);
  462.     pspen(5, 0);
  463.     _setcolor( 4 );
  464.     gsmall_font();
  465.  
  466.     for(na=0; ; na+=16) {
  467.     for(i=0; i<4; i++)  a$[i] = peek(na+i+6,iwseg);
  468.     if(a$[3] == ' ') a$[3] = 0; else a$[4] = 0;
  469.     xx = bin2deg(na+10, iwseg);
  470.     yy = bin2deg(na+13, iwseg);
  471.     if(fabs(xx) > 254.)  break;
  472.     if(wrap && xx<0.)  xx = xx + 360.; /* wrap! */
  473.     if(xx>b1 && xx<b2 && yy>a1 && yy<a2) {
  474.         lx = (int)((xx-b1) * rrx);
  475.         ly = (int)((c2-lat(yy)) * rry);
  476.         gsymbol(lx, ly, 3, 7);
  477.         if(*mc$[1] == 'Y')  gfprint(lx+4, ly, a$, 4);
  478.     }
  479.     }
  480.     pspen(2, 0);
  481.     gviewport(0, 0, 639, YPixels-1);
  482.     if(atoi(ync$) > 0)  nplot = - atoi( ync$ );
  483.     legend(mps$, nplot);
  484.  
  485.     i = fgkey(0, 1);
  486.     if(i==-1 || i==F1)  goto j10;
  487.     return(i);
  488. }
  489.  
  490. void map_retrv( itt )
  491. int  *itt;
  492. {
  493.     short    lx, ly;
  494.     unsigned ra, is, iw, na;
  495.     double   xf, yf;
  496.     int    jy, jm, jd, jh, jn;
  497.  
  498.     *itt = 0;  ra = 0;  na = 4;
  499.     is = 0;  iw = nmax/4095;
  500.     /* `wrap' happens only if the region traverses the date line, and so 
  501.        360 degrees must be added to a western longitude in case of wrap = 1.*/
  502.     if( wrap ) {
  503.     if(lo1 < 0)  lo1 = lo1 + 360*256;
  504.     if(lo2 < 0)  lo2 = lo2 + 360*256;
  505.     }
  506.     _getimage();
  507.  
  508.     for(;;) {
  509.     ra = retrv(ra, *itt, is, iw);
  510.     if(ra == 0xffff)  break;
  511.     if(ra >  0x7fff) {
  512.         is++;  ra = 0;  na = 4;
  513.     }
  514.     else {
  515.         xf = bin2deg(na+ 7, iseg[iw]);
  516.         yf = bin2deg(na+10, iseg[iw]);
  517.         if(wrap && xf<0.)  xf = xf + 360.; /* wrap! */
  518.         yf = lat(yf);
  519.         lx = (int)((xf-b1)*rrx) + kx0+1;
  520.         ly = (int)((c2-yf)*rry) + ky0+1;
  521.         otparm(*itt, &jy, &jm, &jd, &jh, &jn, iw);
  522.         if(_getpixel(lx,ly)) { (*itt)++;  na += 16; }
  523.         if((*itt) == nmax2) {
  524.         poke(0xff, 0xfff4, iseg[iw]);
  525.         poke(0xff, 0xfff5, iseg[iw]);
  526.         break;
  527.         }
  528.         if((*itt)>0 && (*itt)%4095==0) {
  529.         poke(0xfe, 0xfff4, iseg[iw]);
  530.         poke(0xff, 0xfff5, iseg[iw]);
  531.         iw++;  na = 4;
  532.         }
  533.         ra++;
  534.     }
  535.     }
  536. }
  537.  
  538. project_area(p, q, ds, rw)
  539. int    p[], q[], *ds;
  540. double *rw;
  541. {
  542.     int      i, ly, printing;
  543.     double   rb, rc, rd, re;
  544.  
  545.     ly = 21;
  546.     printing = 0;
  547.     clear( 0 );
  548. j10:
  549.     dmap(mps$, 0);
  550.     epicenters();
  551.     gviewport(0, 0, 639, YPixels-1);
  552.  
  553. /* specify two ends of the axis and a width point */
  554.     for(i=0; i<3; i++) {
  555.     if(i == 0) {
  556.         if(! printing) {
  557.         gprint(63, ly  , "Move the cross     ", 4);
  558.         gprint(63, ly+1, "to 1st axis end    ", 4);
  559.         press_prompt(1, ly+2);
  560.         p[0] = (kx1+kx0)/2;  q[0] = (ky1+ky0)/2;
  561.         gcursor(kx0, ky0, kx1, ky1, &p[i], &q[i], 1);
  562.         if(p[i] == -1)  goto j10;
  563.         }
  564.     }
  565.     else {
  566.         if(! printing) {
  567.         switch( i ) {
  568.             case 1: gprint(63, ly+1, "to 2nd axis end    ", 4); break;
  569.             case 2: gprint(63, ly+1, "to width point     ", 4); break;
  570.         }
  571.         p[i] = p[i-1] + 3;
  572.         q[i] = q[i-1] - 2;
  573.         gcursor(kx0, ky0, kx1, ky1, &p[i], &q[i], 0);
  574.         if(p[i] == -1)  goto j10;
  575.         }
  576.         if(i == 1) {
  577.         _setcolor( 2 );
  578.         gmoveto(p[0], q[0]);
  579.         glineto(p[i], q[i]);
  580.         }
  581.     }
  582.     ital(p[i], q[i], &lo[i], &lom[i], &la[i], &lam[i]);
  583.     }
  584.  
  585. /* calculate distance */
  586.     *ds = (int)delta(lo[1]+lom[1]/60., la[1]+lam[1]/60.);
  587.  
  588. /* y1=w*x1+f : y2=w*x2+f: yr=w*xr+c */
  589. /* y2=-x2/w+d: y1=-x1/w+e           */
  590.     if(p[1] == p[0]) {
  591.     p[3] = p[2];
  592.     q[2] = q[1];
  593.     q[3] = q[0];
  594.     *rw = -1.;
  595.     }
  596.     else if(q[1] == q[0]) {
  597.     q[3] = q[2];
  598.     p[2] = p[1];
  599.     p[3] = p[0];
  600.     *rw = -2.;
  601.     }
  602.     else {
  603.     *rw = q[1] - q[0];
  604.     *rw = (*rw) / (p[1]-p[0]);
  605.     rc = q[2] - (*rw)*p[2];
  606.     rd = q[1] + p[1]/(*rw);
  607.     re = q[0] + p[0]/(*rw);
  608.     rb = (*rw) + 1./(*rw);
  609.     rd = (rd-rc) / rb;
  610.     p[2] = (int)rd;
  611.     q[2] = (int)((*rw)*rd + rc);
  612.     rd = (re-rc) / rb;
  613.     p[3] = (int)rd;
  614.     q[3] = (int)((*rw)*rd + rc);
  615.     }
  616.  
  617. /* plot the 3rd and 4th points */
  618.     _setcolor( 2 );
  619.     for(i=2; i<4; i++) {
  620.     gmoveto(p[i-1], q[i-1]);
  621.     glineto(p[i  ], q[i  ]);
  622.     ital(p[i], q[i], &lo[i+1], &lom[i+1], &la[i+1], &lam[i+1]);
  623.     }
  624.     glineto(p[0], q[0]);
  625.  
  626.     press_prompt(2, ly);
  627.     gprint(63, ly+1, "a function key     ", 4);
  628.     gprint(63, ly+2, "on the toolbar.    ", 4);
  629.  
  630.     i = fgkey(0, 0);
  631.     printing = 0;
  632.     if(i == -1)  goto j10;
  633.     if(i == F1) { printing = 1; goto j10; }
  634.     return( i );
  635. }
  636.  
  637. void map_sub_prep(p, q, max)
  638. int  p[], q[], max;
  639. {
  640.     int    pp, qq;
  641.     long   lo;
  642.     short  lom, la, lam, p1, p2, i;
  643.  
  644.     for(i=0; i<max; i++) {
  645.     ital(p[i], q[i], &lo, &lom, &la, &lam);
  646.     strcpy(mc$[i*6+0], jtoa(abs((int)lo),w$,-3));
  647.     strcpy(mc$[i*6+1], jtoa(lom,w$,-2));
  648.     if(lo < 0)  strcpy(mc$[i*6+2], "W");
  649.     else  strcpy(mc$[i*6+2], "E");
  650.     strcpy(mc$[i*6+3], jtoa(abs(la),w$,-2));
  651.     strcpy(mc$[i*6+4], jtoa(lam,w$,-2));
  652.     if(la < 0)  strcpy(mc$[i*6+5], "S");
  653.     else  strcpy(mc$[i*6+5], "N");
  654.  
  655.     pp = p[i];  qq = q[i];
  656.     if(pp < kx0) pp = kx0;
  657.     if(pp > kx1) pp = kx1;
  658.     if(qq < ky0) qq = ky0;
  659.     if(qq > ky1) qq = ky1;
  660.     ital(pp, qq, &lo, &lom, &la, &lam);
  661.     lo = lo*256 + lom;
  662.     la = la*256 + lam;
  663.     if(i == 0) {
  664.         p1 = pp;  p2 = pp;
  665.         lo1 = lo;  lo2 = lo;  la1 = la;  la2 = la;
  666.     }
  667.     else {
  668.         if(pp < p1) { p1 = pp;  lo1 = lo; }
  669.         if(pp > p2) { p2 = pp;  lo2 = lo; }
  670.         if(la < la1) la1 = la;  if(la > la2) la2 = la;
  671.     }
  672.     }
  673. }
  674.  
  675. void ital(lx, ly, lo, lom, la, lam)
  676. int   lx, ly;
  677. long  *lo;
  678. short *la, *lom, *lam;
  679. {
  680.     short  i;
  681.     double xxx, yyy;
  682.  
  683.     xxx = (lx-kx0)/rrx + b1;
  684.     if(xxx > 180.)  xxx = xxx - 360.;
  685.     *lo = (long)xxx;
  686.     if(xxx >= 0.)  *lom = (short)((xxx-*lo) * 60.);
  687.     else  *lom = (short)((*lo-xxx) * 60.);
  688.     yyy =  ym+c1 - (ly-ky0)/rry;
  689.     for(i=0; i<=180; i++)  if(yyy < yln[i])  break;
  690.     if(i > 90) {
  691.     *la = i - 91;
  692.     *lam = (short)((yyy-yln[i-1]) / dln[i-1] * 60.);
  693.     }
  694.     else {
  695.     *la = i - 90;
  696.     *lam = (short)((yln[i]-yyy) / dln[i-1] * 60.);
  697.     }
  698. }
  699.  
  700. double delta(bo, ba)
  701. double bo, ba;
  702. {
  703.     double  ao, aa, co, ca, dp, da, pi, rr; 
  704.     double  coa, soa, cob, sob, caa, saa, cab, sab;
  705.  
  706.     pi = 3.14159;
  707.     ao = lo[0] + lom[0]/60.;  aa = la[0] + lam[0]/60.;
  708.     co = ao/180.*pi;  ca = aa/180.*pi;  dp = bo/180.*pi;  da = ba/180.*pi;
  709.     coa = cos(co);  soa = sin(co);  cob = cos(dp);  sob = sin(dp);
  710.     caa = cos(ca);  saa = sin(ca);  cab = cos(da);  sab = sin(da);
  711.     co = caa*coa - cab*cob;
  712.     ca = caa*soa - cab*sob;
  713.     dp = saa - sab;
  714.     rr = co*co + ca*ca + dp*dp;
  715.     return(6369. * 2.*asin(0.5*sqrt(rr)));
  716. }
  717.  
  718. /* legend for cross-section & space-time */
  719. void legend2(ds, nplot)
  720. int  ds, nplot;
  721. {
  722.     short  i, j;
  723.     char   s[4];
  724.  
  725.     pfromto(-3, nplot);
  726.     for(i=0; i<2; i++) {
  727.     j = 11 + i*2;
  728.     jtoa(abs((int)lo[i]), w$, -3);
  729.     strcat(w$, " ");  strcat(w$, jtoa(lom[i],s,-2));
  730.     if(lo[i] < 0)  strcat(w$, "W-");
  731.     else  strcat(w$, "E-");
  732.  
  733.     strcat(w$, jtoa(abs((int)la[i]),s,-2));
  734.     strcat(w$, " ");  strcat(w$, jtoa(lam[i],s,-2));
  735.     if(la[i] < 0)  strcat(w$, "S");
  736.     else  strcat(w$, "N");
  737.     gprint(63, j, w$, 7);
  738.     }
  739.     gprint(63, 14, "length", 2);
  740.     itoa(ds, w$, 10);  strcat(w$, "km");
  741.     gprint(66, 15, w$, 7);
  742.  
  743.     mag_legend();
  744. }
  745.  
  746. double rtal(xx, yy, rw, rc, p, q)
  747. double xx, yy, rw, rc;
  748. int    p[], q[];
  749. {
  750.     double yyy, rd, rtx, rty, rlo, rla;
  751.     short  i;
  752.  
  753.     yyy = lat(yy);
  754.     if(wrap && xx<0.)  xx = xx + 360.;
  755.     rtx = (xx-b1)*rrx + kx0;
  756.     rty = (ym-yyy+c1)*rry + ky0;
  757.     if(rw == -1.)  rtx = p[0];
  758.     else if(rw == -2.)  rty = q[0];
  759.     else {
  760.     rd  = rty + rtx/rw;
  761.     rtx = (rd-rc) / (rw+1./rw);
  762.     rty = rw*rtx + rc;
  763.     }
  764.  
  765.     rlo = (rtx-kx0)/rrx + b1;
  766.     yyy =  ym+c1 - (rty-ky0)/rry;
  767.     for(i=0; i<=180; i++)  if(yyy < yln[i])  break;
  768.     if(i > 90)  rla = i - 91 + (yyy-yln[i-1])/dln[i-1];
  769.     else  rla = i - 90 + (yln[i]-yyy)/dln[i-1];
  770.     return( delta(rlo, rla) );
  771. }
  772.  
  773. void otparm(ia, jy, jm, jd, jh, jn, iss)
  774. int  ia, iss;
  775. int  *jy, *jm, *jd, *jh, *jn;
  776. {
  777.     char     *is;
  778.     int      ipag;
  779.     unsigned na;
  780.  
  781.     ipag = ia / 4095;
  782.     is   = iseg[iss+ipag];
  783.     na   = (ia-ipag*4095)*16 + 4;
  784.     *jy = fnyear(na,is);
  785.     *jm = peek(na+1,is);
  786.     *jd = peek(na+2,is);
  787.     *jh = peek(na+3,is);
  788.     *jn = peek(na+4,is);
  789. }
  790.  
  791. char *jtoa(i, s, n)
  792. int   i, n;
  793. char *s;
  794. {
  795.     unsigned j, nn;
  796.     char     t[31];
  797.  
  798.     nn = abs(n);
  799.     itoa(i, s, 10);
  800.     j = 0;
  801.     if(strlen(s) < nn)  for(; j<nn-strlen(s); j++) {
  802.     if(n < 0) t[j] = '0';  else t[j] = ' ';
  803.     }
  804.     t[j] = 0;
  805.     strcat(t, s);
  806.     strcpy(s, t);
  807.     return( s );
  808. }
  809.  
  810. void press_prompt(i, y)
  811. int  i, y;
  812. {
  813.     switch( i ) {
  814.     case 1: gprint(63, y, "and press a button.", 4); break;
  815.     case 2: gprint(63, y, "Press Enter or     ", 4); break;
  816.     }
  817. }
  818.  
  819. char maps2_pan[] ="\
  820.     Request : MAP SELECT                                                     \
  821.     Type Y or N and press Enter.                                             \
  822.     Points    Longitude-deg,min-   Latitude-deg,min-                         \
  823.        1st    <     ><    ><   >   <    ><    ><   >                         \
  824.        2nd    <     ><    ><   >   <    ><    ><   >                         \
  825.        3rd    <     ><    ><   >   <    ><    ><   >                         \
  826.        4th    <     ><    ><   >   <    ><    ><   >  Undetermined?          \
  827.     Depth -km-     <       >    -->     <       >        <   >               \
  828.     Magnitude      <      >     -->     <      >         <   >               \
  829.                                                                              \
  830.     Are these all right? <Y/N>  (   )                                        \
  831.                                                                              \
  832. 16,  3, -3 \
  833. 23,  3, -2 \
  834. 29,  3, -1 \
  835. 37,  3, -3 \
  836. 43,  3, -2 \
  837. 49,  3, -1 \
  838. 16,  4, -3 \
  839. 23,  4, -2 \
  840. 29,  4, -1 \
  841. 37,  4, -3 \
  842. 43,  4, -2 \
  843. 49,  4, -1 \
  844. 16,  5, -3 \
  845. 23,  5, -2 \
  846. 29,  5, -1 \
  847. 37,  5, -3 \
  848. 43,  5, -2 \
  849. 49,  5, -1 \
  850. 16,  6, -3 \
  851. 23,  6, -2 \
  852. 29,  6, -1 \
  853. 37,  6, -3 \
  854. 43,  6, -2 \
  855. 49,  6, -1 \
  856. 21,  7, -5 \
  857. 42,  7, -5 \
  858. 59,  7, -1 \
  859. 21,  8, -4 \
  860. 42,  8, -4 \
  861. 59,  8, -1 \
  862. 34, 10,  1 ";
  863.  
  864. char maps3_pan[] ="\
  865.     Request : MAP CROSS-SECTION                                              \
  866.     Change parameters in () as you like and press Enter.                     \
  867.                    Points    Longitude-deg,min-   Latitude-deg,min-          \
  868.     Projection Axis   1st    <     ><    ><   >   <    ><    ><   >          \
  869.                       2nd    <     ><    ><   >   <    ><    ><   >          \
  870.     Width/Direction          <     ><    ><   >   <    ><    ><   >          \
  871.                                                                              \
  872.     Drawing Range:                                                           \
  873.        X-axis <distance>  : X1 (      )                                      \
  874.                             X2 (      )                                      \
  875.        Y-axis <depth>     : Y1 (      )   Events with unknown depths will    \
  876.                             Y2 (      )   be plotted at 0km.                 \
  877.                                                                              \
  878. 31,  3, -3 \
  879. 38,  3, -2 \
  880. 44,  3, -1 \
  881. 52,  3, -3 \
  882. 58,  3, -2 \
  883. 64,  3, -1 \
  884. 31,  4, -3 \
  885. 38,  4, -2 \
  886. 44,  4, -1 \
  887. 52,  4, -3 \
  888. 58,  4, -2 \
  889. 64,  4, -1 \
  890. 31,  5, -3 \
  891. 38,  5, -2 \
  892. 44,  5, -1 \
  893. 52,  5, -3 \
  894. 58,  5, -2 \
  895. 64,  5, -1 \
  896. 33,  8,  4 \
  897. 33,  9,  4 \
  898. 33, 10,  4 \
  899. 33, 11,  4 ";
  900.  
  901. char maps4_pan[] ="\
  902.     Request : MAP SPACE-TIME                                                 \
  903.     Change parameters in () as you like and press Enter.                     \
  904.                    Points    Longitude-deg,min-   Latitude-deg,min-          \
  905.     Projection Axis   1st    <     ><    ><   >   <    ><    ><   >          \
  906.                       2nd    <     ><    ><   >   <    ><    ><   >          \
  907.     Width/Direction          <     ><    ><   >   <    ><    ><   >          \
  908.                                                                              \
  909.     Drawing Range:                                                           \
  910.        X-axis <time>   :  From (       /    /    ) (    :    :      )        \
  911.                           To   (       /    /    ) (    :    :      )        \
  912.                      Tick Unit (   )  <---Y/M/D/H <year/month/day/hour>      \
  913.        Y-axis <distance> : Y1  (      )                                      \
  914.                            Y2  (      )                                      \
  915.                                                                              \
  916. 31,  3, -3 \
  917. 38,  3, -2 \
  918. 44,  3, -1 \
  919. 52,  3, -3 \
  920. 58,  3, -2 \
  921. 64,  3, -1 \
  922. 31,  4, -3 \
  923. 38,  4, -2 \
  924. 44,  4, -1 \
  925. 52,  4, -3 \
  926. 58,  4, -2 \
  927. 64,  4, -1 \
  928. 31,  5, -3 \
  929. 38,  5, -2 \
  930. 44,  5, -1 \
  931. 52,  5, -3 \
  932. 58,  5, -2 \
  933. 64,  5, -1 \
  934. 33,  8,  4 \
  935. 41,  8,  2 \
  936. 46,  8,  2 \
  937. 53,  8,  2 \
  938. 58,  8,  2 \
  939. 63,  8,  4 \
  940. 33,  9,  4 \
  941. 41,  9,  2 \
  942. 46,  9,  2 \
  943. 53,  9,  2 \
  944. 58,  9,  2 \
  945. 63,  9,  4 \
  946. 33, 10,  1 \
  947. 33, 11,  4 \
  948. 33, 12,  4 ";
  949.  
  950. char maps5_pan[] ="\
  951.     Request : MAP ACTIVE-FAULTS                                              \
  952.     Give the name of a fault dataset, specify colors corresponding           \
  953.     to the activeness of fauls, and press Enter.                             \
  954.             Fault Dataset  (          )                                      \
  955.             Activeness     color      |                                      \
  956.              A             (   )      |  1 : Blue                            \
  957.              B and A-B     (   )      |  2 : Green                           \
  958.              C and B-C     (   )      |  3 : Cyan                            \
  959.              unknown       (   )      |  4 : Red                             \
  960.                                       |  5 : Magenta                         \
  961.                                       |  6 : Yellow                          \
  962.                                       |  7 : White                           \
  963. 29,  3,  8 \
  964. 29,  5,  1 \
  965. 29,  6,  1 \
  966. 29,  7,  1 \
  967. 29,  8,  1 ";
  968.  
  969. char maps6_pan[] ="\
  970.     Request : MAP STATIONS                                                   \
  971.     Give the name of a station dataset and press Enter.                      \
  972.                                                                              \
  973.     Station Dataset    (          )                                          \
  974.     Do you like to get station codes to be printed? < Y/N >  (   )           \
  975.                                                                              \
  976. 25,  3,  8 \
  977. 63,  4,  1 ";
  978.