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
/
sort.c
< prev
next >
Wrap
C/C++ Source or Header
|
1999-11-10
|
7KB
|
172 lines
/* SeisView alone/client Copyright (C) 1992,1998 K.Koketsu
<history>
98-11-03 Include panel definitions and remove CR.
98-10-01 Fix the misdeclaration of `isr'.
93-12-07 Original version. */
#include "seis.h"
extern char *iseg[10]; /* work segments for selected events */
extern unsigned nseg; /* number of working segments */
extern short nmax, nmax2; /* maximum numbers of selected events */
extern int itot; /* total # selected events */
extern short isort; /* flag for sorting */
/***************************** variables for menu ****************************/
extern char em$[51]; /* error message on menu */
extern char mc$[42][9]; /* field strings */
extern short isr; /* initial cursor position */
/*************************** SORT ****************** (Sort selected events.) */
int ll[2048], lr[2048];
void swap();
int fnitem();
int sort()
{
int ip, iq, ir;
int i, j, k, l, m, n;
double tt, tu;
if(itot == 0) return( 3 );
if(itot > nmax2) return( 4 );
isr = 0;
strcpy(mc$[0], "MAG "); strcpy(mc$[1], "D");
strcpy(mc$[2], " "); strcpy(mc$[3], " ");
j40:
if(panel(SORT) == 3) return( 0 );
if(!strcmp(mc$[0],"TIME") && isort==0) {
if(*mc$[1] == 'D') {
isort = 1;
for(i=0; i<itot/2; i++) swap(i, itot-1-i);
}
goto j60;
}
if((ip=fnitem(mc$[0])) > 10) {
strcpy(em$, "The first item is invalid!");
goto j40;
}
wblink(); /* 1st sorting (quick sort) */
move(11, 6);
printw("Be patient. Now sorting to %s ...", mc$[0]);
if(*mc$[1] == 'D') iq = 2; else iq = 1;
if(!strcmp(mc$[0],"TIME") && iq==1) isort = 0; else isort = 1;
k = 1; l = 1; m = itot;
j160: i = l; j = m; n = (l+m)/2;
tt = fnarg(n, ip);
j170: if(iq == 2) goto j182;
j172: if(fnarg(i,ip) < tt) { i++; goto j172; }
j174: if(fnarg(j,ip) > tt) { j--; goto j174; }
goto j200;
j182: if(fnarg(i,ip) > tt) { i++; goto j182; }
j184: if(fnarg(j,ip) < tt) { j--; goto j184; }
j200: if(i >= j) goto j210;
swap(i-1, j-1);
i++; j--; goto j170;
j210: if(i == j) { i++; j--; }
if(l >= j) goto j240;
if(i < m) { ll[k] = l; lr[k] = j; k++; l=i; goto j160; }
m = j; goto j160;
j240: if(i < m) { l = i; goto j160; }
k--;
if(k >= 0) { l = ll[k]; m = lr[k]; goto j160; }
j60: if(!strcmp(mc$[2]," ")) goto j50;
if((ir=fnitem(mc$[2])) > 10) {
strcpy(em$, "The second item is invalid!");
goto j40;
}
wblink(); /* 2nd sorting (bubble sort) */
move(11, 6);
printw("Be patient. Now sorting to %s ...", mc$[2]);
if(*mc$[3] == 'D') iq = 2; else iq = 1;
isort = 1;
i = 1; tt = fnarg(i,ip);
j290: j = i+1; if(j >= itot) goto j50;
j300: tu = fnarg(j,ip);
if(tu == tt) { if(++j < itot) goto j300; }
if(j == i+1) goto j310;
if(j == itot) j++;
for(k=j-1; k>=i+1; k--) {
for(l=i+1; l<=k; l++) {
if((iq==1 && fnarg(l-1,ir)>fnarg(l,ir)) ||
(iq==2 && fnarg(l-1,ir)<fnarg(l,ir))) swap(l-2, l-1);
}
}
j310: i = j; tt = tu; goto j290;
j50: standend();
return( 0 );
}
int fnitem( a$ )
char *a$;
{
if( strstr(a$,"TIME") ) return( 0 );
else if( strstr(a$,"LON") ) return( 1 );
else if( strstr(a$,"LAT") ) return( 2 );
else if( strstr(a$,"DEP") ) return( 3 );
else if( strstr(a$,"MAG") ) return( 4 );
return( 99 );
}
void swap(P, Q)
unsigned P, Q;
{
unsigned TP, SP, TQ, SQ;
char IBF[16];
SP = P/4095; TP = P - SP*4095;
SQ = Q/4095; TQ = Q - SQ*4095;
memcpy(IBF, iseg[SP]+TP*16+4, 16);
memcpy(iseg[SP]+TP*16+4, iseg[SQ]+TQ*16+4, 16);
memcpy(iseg[SQ]+TQ*16+4, IBF, 16);
}
/************************ Panel Definitions **********************/
char sort_pan[] = "\
Request : SORT \
Specify items and sorting order in () as you like and press Enter. \
\
Item Order Sortable items Valid order \
1st ( ) ( ) | TIME LON LAT A:Ascending \
2nd ( ) ( ) | DEP MAG D:Descending \
\
Keep the second item blank if you do not need it. \
(The second sorting will be done by means of bubble sort, \
and so that should take a long time.) \
\
23, 4, 4 \
32, 4, 1 \
23, 5, 4 \
32, 5, 1 ";
char help_pan[] = "\
'Region' always has higher priority than 'Latitude' and 'Longitude'. \
If you like to specify an area by coordinates, 'Region' should be made blank.\
\
<Regions> (See the file 'regions'. You may edit this.) \
Geographical Area: WORLD,PACIFIC,ATLANTIC,INDIAN,NWPAC(NW Pacific),AUSTRALIA,\
AFRICA,NAMERICA,CAMERICA,SAMERICA,USSR,CHINA,ASEAN,INDIA,ARAB,EUROPE,JAPAN\
Japanese district: \
HOKKAIDO,TOHOKU,KANTO,IZU,TOKAI,CHUBU,KINKI,NANKAI,CHUGOKU,SHIKOKU,KYUSHU \
\
<Data Sources> ISC,ISCNE: International Seismological Centre \
PDE : USGS (Preliminary Determination of Earthquakes) \
JMA : Japan Meteorological Agency \
UTSU : Dr Utsu's Catalog \
RIKA : Rika Nenpyo \
JPN : JMA + UTSU + RIKA \
JUNEC : Japanese National Universities \
\
<Map Data> EARTH: World with plate boundaries \
WORLD: fine World by ISC \
NWPAC: North-western Pacific by Dr Yoshii \
JAPAN: fine Japan by Ms Kotake ";