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 / select.c < prev    next >
C/C++ Source or Header  |  1999-11-10  |  19KB  |  661 lines

  1. /*  SeisView alone/client    Copyright (C) 1992,1999  K.Koketsu
  2.              <history>
  3.          99-11-09  Y2K issue for filename convention.
  4.          99-01-08  Check the success of gethostbyname().
  5.          98-11-05  Remote auxiliary files and fix a bug in retrv_server().
  6.          98-11-03  Include panel definitions and remove CR.
  7.          98-11-02  Measure the elapse time of retrieval (optional).
  8.          98-10-16  retrv() is again separated from `select.c'.
  9.          98-10-13  Fix in 2.02 patchlevel a appears again.
  10.          98-02-25  Abandon DOS, but take Windows 95/NT.
  11.          96-10-08  Fix the bug in retrv_server() (2.02 patchlevel a).
  12.          96-05-28  Fix the bug in making filenames after b10.
  13.          94-01-10  bcopy --> memcpy.                */
  14.  
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <string.h>
  18. #include <fcntl.h>
  19. #include <sys/timeb.h>
  20. #include <time.h>
  21. #include "seis.h"
  22.  
  23. #ifdef WIN32
  24. extern HWND hwnd;
  25. #endif
  26. extern char     *iseg[10];            /* work segments for  selected events  */
  27. extern unsigned nseg;                 /* number of working segments          */
  28. extern short    nmax, nmax2;          /* maximum numbers of selected events  */
  29. extern char     fc$[11];              /* string typed by user                */
  30. extern int   itot;                                /* total # selected events */
  31. extern short isort;                               /* flag for sorting        */
  32. extern char  z$[11], w$[81];                      /* work string             */
  33. extern char  drv$[65], drvo$[65];                 /* parameters for disk,prn */
  34.  
  35. /***************************** variables for menu ****************************/
  36. extern char   em$[51];                            /* error message on menu   */
  37. extern char   mc$[42][9], md$[65];                /* field strings           */
  38. extern short  isr;                                /* initial cursor position */
  39.  
  40. /**************************** variables for retrieval ************************/
  41. char   myhost[101];
  42. char   f2$[6];
  43. char   y1$[5], m1$[3], d1$[3], h1$[3], n1$[3], s1$[5];
  44. char   y2$[5], m2$[3], d2$[3], h2$[3], n2$[3], s2$[5];
  45. char   dst$[11];
  46. char   so1$[4], som1$[3], so2$[4], som2$[3];
  47. char   sa1$[3], sam1$[3], sa2$[3], sam2$[3];
  48. char   sew1$[2], sew2$[2], sns1$[2], sns2$[2];
  49. char   dp1$[6], dp2$[6], mg1$[5], mg2$[5];
  50. char   ynh$[2], ynm$[2];
  51. extern char  to1$[4], tom1$[3], to2$[4], tom2$[3];
  52. extern char  ta1$[3], tam1$[3], ta2$[3], tam2$[3];
  53. extern char  tew1$[2], tew2$[2], tns1$[2], tns2$[2];
  54.  
  55. /******************** parameters for retrieving kernel **********************/
  56. unsigned imd1,ihm1,isc1, imd2,ihm2,isc2;    /* month+day, hour+min, sec */
  57. long     lo1, lo2;                /* longitude            */
  58. long     b180 = 180*256L, b360 = 360*256L;
  59. short    lom1,lom2, la1,lam1,la2,lam2;        /* lonmin, lat,latmin        */
  60. unsigned ih1, ih2;                /* depth            */
  61. int      m1, m2;                /* magnitude            */
  62.  
  63. unsigned iyy1,im1,id1, iyy2,im2,id2;        /* years from and to        */
  64. unsigned jh1,jm1, jh2,jm2;            /* times from and to        */
  65. double   hh1,hh2, rm1,rm2;            /* depth, magnitude        */
  66.  
  67. int getn_server();
  68.  
  69. /*************************** SELECT ********************** (Select events.) */
  70. int select_seis()  /* Avoid conflict with the standard UNIX select(). */
  71. {
  72.     int      i, rc;
  73.     unsigned iy, ra;
  74.     char     g$[24];
  75.     int      jyy1, jyy2;
  76. #ifdef SPEED
  77.     char    *timeline;
  78.     struct timeb timebuffer;
  79. #ifdef WIN32
  80.     char    tl0[80], tl1[80];
  81. #endif
  82. #endif
  83.  
  84.     strcpy(mc$[ 0],f2$);
  85.     strcpy(mc$[ 1],y1$);  strcpy(mc$[ 2],m1$);  strcpy(mc$[ 3],d1$);
  86.     strcpy(mc$[ 4],h1$);  strcpy(mc$[ 5],n1$);  strcpy(mc$[ 6],s1$);
  87.     strcpy(mc$[ 7],y2$);  strcpy(mc$[ 8],m2$);  strcpy(mc$[ 9],d2$);
  88.     strcpy(mc$[10],h2$);  strcpy(mc$[11],n2$);  strcpy(mc$[12],s2$);
  89.     strcpy(md$,dst$);
  90.     strcpy(mc$[14],so1$);  strcpy(mc$[15],som1$);  strcpy(mc$[16],sew1$);
  91.     strcpy(mc$[17],so2$);  strcpy(mc$[18],som2$);  strcpy(mc$[19],sew2$);
  92.     strcpy(mc$[20],sa1$);  strcpy(mc$[21],sam1$);  strcpy(mc$[22],sns1$);
  93.     strcpy(mc$[23],sa2$);  strcpy(mc$[24],sam2$);  strcpy(mc$[25],sns2$);
  94.     strcpy(mc$[26],dp1$);  strcpy(mc$[27],dp2$);
  95.     strcpy(mc$[28],mg1$);  strcpy(mc$[29],mg2$);
  96.     strcpy(mc$[30],ynh$);  strcpy(mc$[31],ynm$);
  97.     isr = 0;
  98.  
  99. j31:
  100.     standend();
  101.     rc = panel( SELECT );
  102.     if(rc==3 || rc==6)  return( 0 );
  103.  
  104.     isr = 0;
  105.     strcpy(f2$,mc$[0]);
  106.     strcpy(y1$,mc$[1]); strcpy(y2$,mc$[ 7]);
  107.     strcpy(m1$,mc$[2]); strcpy(m2$,mc$[ 8]);
  108.     strcpy(d1$,mc$[3]); strcpy(d2$,mc$[ 9]);
  109.     strcpy(h1$,mc$[4]); strcpy(h2$,mc$[10]);
  110.     strcpy(n1$,mc$[5]); strcpy(n2$,mc$[11]);
  111.     strcpy(s1$,mc$[6]); strcpy(s2$,mc$[12]);
  112.     strxcpy(dst$,md$);
  113.     strcpy(so1$,mc$[14]); strcpy(som1$,mc$[15]);  strcpy(sew1$,mc$[16]);
  114.     strcpy(so2$,mc$[17]); strcpy(som2$,mc$[18]);  strcpy(sew2$,mc$[19]);
  115.     strcpy(sa1$,mc$[20]); strcpy(sam1$,mc$[21]);  strcpy(sns1$,mc$[22]);
  116.     strcpy(sa2$,mc$[23]); strcpy(sam2$,mc$[24]);  strcpy(sns2$,mc$[25]);
  117.     strcpy(dp1$,mc$[26]); strcpy(dp2$ ,mc$[27]);
  118.     strcpy(mg1$,mc$[28]); strcpy(mg2$ ,mc$[29]);
  119.     strcpy(ynh$,mc$[30]); strcpy(ynm$ ,mc$[31]);
  120.  
  121.     if(strchr(f2$,' '))  *(strchr(f2$,' ')) = 0;
  122.     iyy1 = atoi(y1$);    iyy2 = atoi(y2$);
  123.     if(iyy1>iyy2 || (strstr(f2$,"ISC") && iyy1<1964)) {
  124.     isr =  1;
  125.     strcpy(em$, "Invalid date!");
  126.     goto j31;
  127.     }
  128.     im1 = atoi(m1$); im2 = atoi(m2$);
  129.     id1 = atoi(d1$); id2 = atoi(d2$);
  130.     jh1 = atoi(h1$); jh2 = atoi(h2$);
  131.     jm1 = atoi(n1$); jm2 = atoi(n2$);
  132.     isc1 = (unsigned)(atof(s1$)*10.);
  133.     isc2 = (unsigned)(atof(s2$)*10.);
  134.     imd1 = im1*256 + id1;  imd2 = im2*256 + id2;
  135.     ihm1 = jh1*256 + jm1;  ihm2 = jh2*256 + jm2;
  136.     if( *dst$ ) {
  137.     if(! dist(dst$,0)) { isr = 13;  goto j31; }
  138.     }
  139.     lo1  = atoi(so1$ );  lo2  = atoi(so2$ );
  140.     la1  = atoi(sa1$ );  la2  = atoi(sa2$ );
  141.     lom1 = atoi(som1$);  lom2 = atoi(som2$);
  142.     lam1 = atoi(sam1$);  lam2 = atoi(sam2$);
  143.     jtoa((int)lo1,so1$,-3);  jtoa((int)lo2,so2$,-3);
  144.     jtoa(la1 ,sa1$ ,-2);  jtoa(la2 ,sa2$ ,-2);
  145.     jtoa(lom1,som1$,-2);  jtoa(lom2,som2$,-2);
  146.     jtoa(lam1,sam1$,-2);  jtoa(lam2,sam2$,-2);
  147.     if(lom1 > 59)  isr = 17;
  148.     if(lom2 > 59)  isr = 20;
  149.     if(lam1 > 59)  isr = 23;
  150.     if(lam2 > 59)  isr = 26;
  151.     if(isr > 1) {
  152.     strcpy(em$, "Minute values should be less than 60!");
  153.     goto j31;
  154.     }
  155.  
  156.     _normal_font(); wreverse();
  157.     move(14, 5);  clrtoeol();
  158.     addstr(" Now retrieving ...");
  159.     itot = 0;  isort = 0;
  160.  
  161.     lo1 = lo1*256 + lom1;
  162.     lo2 = lo2*256 + lom2;
  163.     la1 = la1*256 + lam1;
  164.     la2 = la2*256 + lam2;
  165.     if(*sew1$ == 'W')  lo1 = - lo1;
  166.     if(*sew2$ == 'W')  lo2 = - lo2;
  167.     if(*sns1$ == 'S')  la1 = - la1;
  168.     if(*sns2$ == 'S')  la2 = - la2;
  169.     if(la1 > la2) {
  170.     strcpy(em$,"The second latitude should be in the north of the first!");
  171.     goto j31;
  172.     }
  173.     if(lo1 >= lo2)  lo2 = lo2 + b360;
  174.  
  175.     hh1 = atof(dp1$);  hh2 = atof(dp2$);
  176.     ih1 = (unsigned)(hh1*10 + 0.01);
  177.     ih2 = (unsigned)(hh2*10 + 0.01);
  178.     rm1 = atof(mg1$);  rm2 = atof(mg2$);
  179.     if(rm1 >= 0.)   m1 = (int)(rm1*10 + 0.01);
  180.     else  m1 = (int)(rm1*10 - 0.01);
  181.     if(rm2 >= 0.)   m2 = (int)(rm2*10 + 0.01);
  182.     else  m2 = (int)(rm2*10 - 0.01);
  183.  
  184.     if(*drv$ != '@')  goto  jALONE;
  185.  
  186.     if(! open_server(drv$+1)) {
  187.     sprintf(em$, "`%s' cannot be accessed to!", drv$+1);
  188.     goto j31;
  189.     }
  190.  
  191.     if(!strcmp(f2$,"RIKA") || !strcmp(f2$,"UTSU")) {
  192.     if(! retrv_server(f2$,&itot,0))  goto j46;
  193.     close_server();
  194.     }
  195.     else {
  196.     if(! strcmp(f2$,"JPN")) {
  197.         jyy1 = iyy1;  jyy2 = iyy2;
  198.         if(iyy1 < 1885) {
  199.         if(! retrv_server("RIKA",&itot,0))  goto j46;
  200.         else { close_server(); open_server(drv$+1); }
  201.         }
  202.         if(iyy1 < 1926) {
  203.         if(iyy2 > 1925)  iyy2 = 1925;
  204.         if(! retrv_server("UTSU",&itot,0))  goto j46;
  205.         else { close_server(); open_server(drv$+1); }
  206.         iyy2 = jyy2;
  207.         }
  208.         if(iyy2 > 1925) { if(iyy1 < 1926)  iyy1 = 1926; }
  209.         else  goto j56;
  210.     }
  211.  
  212.     for(iy=iyy1; iy<=iyy2; iy++) {
  213.         if(iy > iyy1)  open_server(drv$ + 1);
  214.         if(! strcmp(f2$,"JPN"))  strcpy(g$, "JMA");
  215.         else  strcpy(g$, f2$);
  216.         if(! (i = retrv_server(g$, &itot, iy)))  goto j46;
  217.         close_server();
  218.         if(i < 0)  break;
  219.     }
  220.     }
  221. j56:
  222.     if(! strcmp(f2$,"JPN")) { iyy1 = jyy1;  iyy2 = jyy2; }
  223.     goto j41;
  224.  
  225. j46:
  226.     close_server();
  227.     goto  j31;
  228.  
  229. jALONE:
  230.  
  231.     if(!strcmp(f2$,"RIKA")) {
  232.     if(! rvrika())  goto j31;
  233.     }
  234.     else if(!strcmp(f2$,"UTSU")) {
  235.     if(! rvutsu(0))  goto j31;
  236.     }
  237.     else {
  238.     if(!strcmp(f2$,"JPN")) {
  239.         if(iyy1 < 1885) {
  240.         if(! rvrika())  goto j31;
  241.         sprintf(w$, "RIKA         -- %5d", itot);
  242.         mvaddstr(14, 25, w$);
  243.         xflush();
  244.         }
  245.         if(iyy1 < 1926) { /* Note RIKA+UTSU < 2000. */
  246.         if(iyy2 < 1926) i = 0;  else i = 1;
  247.         if(! rvutsu(i))  goto j31;
  248.         sprintf(w$, "UTSU         -- %5d", itot);
  249.         mvaddstr(14, 25, w$);
  250.         xflush();
  251.         }
  252.     }
  253.     if(iyy1 < 1926)  iyy1 = 1926;
  254. #ifdef SPEED
  255.     ftime( &timebuffer );
  256.     timeline = ctime( &(timebuffer.time) );
  257. #ifdef WIN32
  258.     sprintf(tl0, "%.19s.%hu %s", timeline, timebuffer.millitm,
  259.         &timeline[20]);
  260. #else
  261.     printf("%.19s.%hu %s", timeline, timebuffer.millitm, &timeline[20]);
  262. #endif
  263. #endif
  264.     for(iy=iyy1; iy<=iyy2; iy++) {
  265.         if(!strcmp(f2$,"JPN")) strcpy(g$, "JMA");  else strcpy(g$, f2$);
  266.         sprintf(w$, "%-5.5s (%4d) -- %5d", g$, iy, itot);
  267.         mvaddstr(14, 25, w$);
  268.         xflush();
  269.         /* Y2K for file name convention */
  270.         /*sprintf(g$+strlen(g$), "-%d.B", iy-1900);*/
  271.         if     (iy < 2000) sprintf(g$+strlen(g$), "-%d.B", iy-1900);
  272.         else if(iy < 2010) sprintf(g$+strlen(g$),"00%d.B", iy-2000);
  273.         else               sprintf(g$+strlen(g$), "0%d.B", iy-2000);
  274. j29:        if(! bload(iseg[nseg-1],0,g$))  goto j31;
  275.  
  276.         ra = 0;
  277.         for(;;) {
  278.         ra = retrv(ra, itot, nseg-1, 0);
  279.         if(ra == 0xffff)  break;
  280.         else if(ra == 0xfffe) {
  281.             itoa(2, g$+strlen(g$), 10);
  282.             goto j29;
  283.         }
  284.         else if(ra > 0x7fff) {
  285.          /* itoa(0xffff-ra+1, g$+strlen(g$)-1, 10); 96-05-28 */
  286.             itoa(0xffff-ra+1, strchr(g$,'.')+2, 10);
  287.             goto j29;
  288.         }
  289.         else {
  290.             if(++itot == nmax) break;
  291.             ra++;
  292.         }
  293.         }
  294.         if(itot == nmax) break;
  295.     }
  296. #ifdef SPEED
  297.     ftime( &timebuffer );
  298.     timeline = ctime( &(timebuffer.time) );
  299. #ifdef WIN32
  300.     sprintf(tl1, "%.19s.%hu %s", timeline, timebuffer.millitm,
  301.         &timeline[20]);
  302.     strcat(tl0, tl1);
  303.     MessageBox(hwnd, tl0, "debug", MB_OK);
  304. #else
  305.     printf("%.19s.%hu %s", timeline, timebuffer.millitm, &timeline[20]);
  306. #endif
  307. #endif
  308.     }
  309. j41:
  310.     standend();
  311.     if(itot == nmax)  return( 2 );
  312.     else              return( 0 );
  313. }
  314.  
  315.  
  316. /********* DIST ************ (Translate a district name to lat/lon.) */
  317. dist(a$, flg)
  318. char *a$;  int flg;
  319. {
  320.     char  *iwseg;
  321.     unsigned  rcod, off;
  322.     char  s[11], ew1[2], ew2[2], ns1[2], ns2[2];
  323.     char  do1[4], do2[4], da1[3], da2[3];
  324.  
  325.     iwseg = iseg[nseg-1];  off = 0;
  326.  
  327.     if(!(rcod = rbload(iwseg, off, "regions"))) return( 0 );
  328.  
  329.     while(sscanf(iwseg+off, "%10s %s %s %s %s %s %s %s %s",
  330.          s, do1, ew1, do2, ew2, da1, ns1, da2, ns2) == 9) {
  331.     if( strstr(a$,s) )  goto jdist;
  332.     if((off = (unsigned)strchr(iwseg+off,'\n')) == 0) break;
  333.     if((off = off + 1 - (unsigned)iwseg) > rcod) break;
  334.     }
  335.     strcpy(em$, "Invalid region name!");
  336.     return( 0 );
  337.  
  338. jdist:
  339.     if(flg  == 0) {
  340.     strcpy(so1$,  do1);  strcpy(so2$,  do2);
  341.     strcpy(sa1$,  da1);  strcpy(sa2$,  da2);
  342.     strcpy(som1$,"00");  strcpy(som2$,"00");
  343.     strcpy(sam1$,"00");  strcpy(sam2$,"00");
  344.     strcpy(sew1$, ew1);  strcpy(sew2$, ew2);
  345.     strcpy(sns1$, ns1);  strcpy(sns2$, ns2);
  346.     }
  347.     else {
  348.     strcpy(to1$,  do1);  strcpy(to2$,  do2);
  349.     strcpy(ta1$,  da1);  strcpy(ta2$,  da2);
  350.     strcpy(tom1$,"00");  strcpy(tom2$,"00");
  351.     strcpy(tam1$,"00");  strcpy(tam2$,"00");
  352.     strcpy(tew1$, ew1);  strcpy(tew2$, ew2);
  353.     strcpy(tns1$, ns1);  strcpy(tns2$, ns2);
  354.     }
  355.     return( 1 );
  356. }
  357.  
  358. rvutsu( flg )
  359. int  flg;
  360. {
  361.     unsigned  ra;
  362.  
  363.     if(! bload(iseg[nseg-1],0,"UTSU.B"))  return( 0 );
  364. j29:
  365.     ra = 0;
  366.     for(;;) {
  367.     ra = retrv(ra, itot, nseg-1, 0);
  368.     if(ra == 0xffff)  return( 1 );
  369.     else if(ra > 0x7fff) {
  370.         if(flg == 1)  return( 1 );
  371.         if(! bload(iseg[nseg-1],0,"UTSU.B2"))  return( 0 );
  372.         goto j29;
  373.     }
  374.     else {
  375.         if(++itot == nmax)  return( 2 );
  376.         ra++;
  377.     }
  378.     }
  379. }
  380.  
  381. rvrika()
  382. {
  383.     unsigned  ra;
  384.  
  385.     if(! bload(iseg[nseg-1],0,"RIKA.B"))  return( 0 );
  386.     ra = 0;
  387.     for(;;) {
  388.     ra = retrv(ra, itot, nseg-1, 0);
  389.     if(ra == 0xffff)  return( 1 );
  390.     else { itot++; ra++; }
  391.     }
  392. }
  393.  
  394. /* common retrieving kernel */
  395. #include "retrv.c"
  396.  
  397. int rbload(sg, off, fname) /* extended bload() */
  398. char *sg, *fname;
  399. unsigned  off;
  400. {
  401.     char     t[17];
  402.     unsigned rcod, nn;
  403.  
  404.     if(*drvo$ == '@') {
  405.     if(! open_server(drvo$+1)) {
  406.         sprintf(em$, "`%s' cannot be accessed to!", drvo$+1);
  407.         return( 0 );
  408.     }
  409.     gethostname(myhost, 100);
  410.     send_server( myhost );
  411.     send_server( ":" );  send_server( fname );
  412.     getn_server(t, 16);
  413.     if(! *t) {
  414.         sprintf(em$, "File `%s' does not exist on `%s'!", t+1, drvo$+1);
  415.         return( 0 );
  416.     }
  417.     rcod = 0;
  418.     for(;;) {
  419.         getn_server(t, 6);
  420.         sscanf(t, "%d", &nn);
  421.         if(nn == 0)  break;
  422.         getn_server(sg+off+rcod, nn);
  423.         rcod += nn;
  424.     }
  425.     }
  426.     else {
  427.     if(!(rcod = bload(sg,off,fname)))  return( 0 );
  428.     }
  429.     return( rcod );
  430. }
  431.  
  432. #define  SEISD  (516 + 5000)
  433.  
  434. #ifdef WIN32
  435. #include <io.h>
  436. #include <winsock.h>
  437. SOCKET       sock;
  438. const char   on = 1;
  439. #else
  440. #include <sys/types.h>
  441. #include <sys/socket.h>
  442. #include <netinet/in.h>
  443. #include <netdb.h>
  444. int     sock;
  445. int     on = 1;
  446. #endif
  447.  
  448.  
  449. open_server( hname )
  450. char  *hname;
  451. {
  452.     struct  hostent  *addr;
  453.     struct  sockaddr_in  server;
  454.  
  455.     /* listen connection */
  456.     server.sin_family = AF_INET;
  457.     server.sin_port = htons( SEISD );
  458.     addr = gethostbyname( hname );
  459.     if(addr == NULL)  return( 0 ); /* 1999-01-08 */
  460.     memcpy(&server.sin_addr, addr->h_addr, addr->h_length);
  461.  
  462.     if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0)  return( 0 );
  463.     if (connect(sock, &server, sizeof(server)) < 0) {
  464.     close( sock );
  465.     return( 0 );
  466.     }
  467.  
  468.     setsockopt(sock, SOL_SOCKET, SO_LINGER, &on, on);
  469.     return( 1 );
  470. }
  471.  
  472. void close_server() { close( sock ); }
  473.  
  474. int getn_server(s, n)
  475. char *s;  int n;
  476. {
  477. #ifdef WIN32
  478.     return( recv(sock, s, n, 0) );
  479. #else
  480.     return( read(sock, s, n) );
  481. #endif
  482. }
  483.  
  484. void putn_server(s, n)
  485. char *s;  int n;
  486. {
  487. #ifdef WIN32
  488.     send(sock, s, n, 0);
  489. #else
  490.     write(sock, s, n);
  491. #endif
  492. }
  493.  
  494. void send_server( t )
  495. char *t;
  496. {
  497.     char  s[16];
  498.     int   i, n;
  499.  
  500.     n = strlen( t );
  501.     for(i=0; i<16; i++) {
  502.     if(i >= n)  s[i] = ' ';
  503.     else  s[i] = t[i];
  504.     }
  505.     putn_server(s, 16);
  506. }
  507.  
  508. unsigned short
  509. read_server( s )
  510. unsigned char  *s;
  511. {
  512.     getn_server(s, 16);
  513.     return(s[0] + (s[1]<<8));
  514. }
  515.  
  516. void submit_server(s, iy)
  517. char  *s;
  518. int   iy;
  519. {
  520.     char  t[5];
  521.  
  522.     gethostname(myhost, 100);
  523.     send_server( myhost );
  524.     send_server( s );
  525.     sprintf(t, "%4d", iy);  send_server( t );
  526.     send_server( itoa(iyy1,w$,10) );
  527.     send_server(m1$);  send_server(d1$);
  528.     send_server(h1$);  send_server(n1$);  send_server(s1$);
  529.     send_server( itoa(iyy2,w$,10) );
  530.     send_server(m2$);  send_server(d2$);
  531.     send_server(h2$);  send_server(n2$);  send_server(s2$);
  532.     send_server(so1$);  strcpy(w$, som1$);
  533.     if(*sew1$ == 'W') strcat(w$, sew1$);  send_server(w$);
  534.     send_server(so2$);  strcpy(w$, som2$);
  535.     if(*sew2$ == 'W') strcat(w$, sew2$);  send_server(w$);
  536.     send_server(sa1$);  strcpy(w$, sam1$);
  537.     if(*sns1$ == 'S') strcat(w$, sns1$);  send_server(w$);
  538.     send_server(sa2$);  strcpy(w$, sam2$);
  539.     if(*sns2$ == 'S') strcat(w$, sns2$);  send_server(w$);
  540.     send_server(dp1$);  send_server(dp2$);
  541.     send_server(mg1$);  send_server(mg2$);
  542.     send_server(ynh$);  send_server(ynm$);
  543. }
  544.  
  545. retrv_server(s, itot, iy)
  546. char  *s;
  547. int   *itot, iy;
  548. {    /* <return code>
  549.        1: OK, 0: network error, -1: over nmax */
  550.     char  t[17];
  551.     int   n, ismany;
  552.     unsigned pag, nn, m, of, num, eof;
  553.  
  554.     if(iy == 0)  sprintf(w$, "%-5.5s        -- %5d", s, *itot);
  555.     else  sprintf(w$, "%-5.5s (%4d) -- %5d", s, iy, *itot);
  556.     mvaddstr(14, 25, w$);  xflush();
  557.     submit_server(s, iy);
  558.  
  559.     eof    = 0;
  560.     ismany = 0;
  561.     while(eof != 0xffff) {
  562.     getn_server(t, 16);
  563.     if(! *t) {
  564.         sprintf(em$, "File `%s' does not exist on `%s'!", t+1, drv$+1);
  565.         return( 0 );
  566.     }
  567.     else  send_server( "1" );
  568.     getn_server(t, 5);
  569.     t[5] = 0;
  570.     n = atoi( t );
  571.  
  572.     of = 0;
  573.     nn = (unsigned)n * 16 + 2;
  574.     while(nn > 0) {
  575.         m = (unsigned)getn_server(iseg[nseg-1]+of, nn);
  576.         if(m > 0) { nn -= m; of += m; }
  577.     }
  578.     eof = (unsigned char)iseg[nseg-1][of+nn-1];
  579.     eof = (eof << 8) + (unsigned char)iseg[nseg-1][of+nn-2];
  580.  
  581.     if(*itot+n > nmax) {
  582.         n = nmax - *itot;
  583.         ismany = 1;
  584.     }
  585.     if(n > 0) {
  586.         pag = (*itot) / 4095;
  587.         num = (*itot) % 4095;
  588.         nn = n * 16;
  589.         if(num+n > 4095) {
  590.         of = num*16 + 4;
  591.         m  = (4095-num) * 16;
  592.         memcpy(iseg[pag]+of, iseg[nseg-1], m);
  593.            /* These are wrong! (1998-11-05)
  594.         *(iseg[pag]+of+nn  ) = (unsigned char)0xfe;
  595.         *(iseg[pag]+of+nn+1) = (unsigned char)0xff; */
  596.         iseg[pag][0xfff4] = (unsigned char)0xfe;
  597.         iseg[pag][0xfff5] = (unsigned char)0xff;
  598.         pag++;
  599.         num = 0;
  600.         nn -= m;
  601.         }
  602.         else  m = 0;
  603.         of = num*16 + 4;
  604.         memcpy(iseg[pag]+of, iseg[nseg-1]+m, nn);
  605.         *itot += n;
  606.         *(iseg[pag]+of+nn  ) = (unsigned char)0xff;
  607.         *(iseg[pag]+of+nn+1) = (unsigned char)0xff;
  608.     }
  609.     }
  610.     if( ismany )  return( -1 );
  611.     return( 1 );
  612. }
  613.  
  614. char select_pan[] = "\
  615.     Request : SELECT                                                         \
  616.     Change parameters in () as you like and press Enter.                     \
  617.  0. Data Source         (       )                                            \
  618.  1. Date/Time     From  ( +      /    /    )     (    :    :      )          \
  619.                   To    ( +      /    /    )     (    :    :      )          \
  620.  2. Region              (            )                                       \
  621.  or Longitude -deg,min- (     )(    )(   ) --> (     )(    )(   )            \
  622.     Latitude  -deg,min- (    )(    )(   )  --> (    )(    )(   )             \
  623.    |Longitudes are measured eastward.|                                       \
  624.  3. Depth     -km-      (       )          --> (       )                     \
  625.  4. Magnitude           (      )           --> (      )                      \
  626.  5. You like to include events whose following item is undetermined? < Y/N > \
  627.              Depth      (   )                                                \
  628.              Magnitude  (   )                                                \
  629. 26,  2,  5 \
  630. 28,  3,  4 \
  631. 35,  3,  2 \
  632. 40,  3,  2 \
  633. 51,  3,  2 \
  634. 56,  3,  2 \
  635. 61,  3,  4 \
  636. 28,  4,  4 \
  637. 35,  4,  2 \
  638. 40,  4,  2 \
  639. 51,  4,  2 \
  640. 56,  4,  2 \
  641. 61,  4,  4 \
  642. 26,  5, 10 \
  643. 26,  6,  3 \
  644. 33,  6,  2 \
  645. 39,  6,  1 \
  646. 49,  6,  3 \
  647. 56,  6,  2 \
  648. 62,  6,  1 \
  649. 26,  7,  2 \
  650. 32,  7,  2 \
  651. 38,  7,  1 \
  652. 49,  7,  2 \
  653. 55,  7,  2 \
  654. 61,  7,  1 \
  655. 26,  9,  5 \
  656. 49,  9,  5 \
  657. 26, 10,  4 \
  658. 49, 10,  4 \
  659. 26, 12,  1 \
  660. 26, 13,  1 ";
  661.