/*Translated by FOR_C, v3.4.2 (-), on 07/09/115 at 08:33:14 */ /*FOR_C Options SET: ftn=u io=c no=p op=aimnv pf=,p_gsortp s=dbov str=l x=f - prototypes */ #include #include "fcrt.h" #include #include #include "p_gsortp.h" /*>> 1995-05-28 DRGSORTP Krogh Converted SFTRAN to Fortran *>> 1988-11-22 DRGSORTP Snyder Initial code. * * Test driver for GSORTP. * * Construct an array of 1000 random numbers using SRANUA. * Sort it using GSORTP. * Check whether it is in order. * */ /* COMMON translations */ struct t_rcom { float r[1000-(1)+1]; } rcom; /* end of COMMON translations */ int main( ) { LOGICAL32 ok; long int i, p[1000-(1)+1]; /* Generate 1000 random numbers */ sranua( rcom.r, 1000 ); /* Sort them using GSORTP. */ ok = TRUE; gsortp( compar, 1000, p ); /* Check the order. */ for (i = 2; i <= 1000; i++) { if (rcom.r[p[i-(1)]-(1)] < rcom.r[p[i - 1-(1)]-(1)]) ok = FALSE; } /* Print the results. */ if (ok) { printf("GSORTP succeeded\n"); } else { printf("GSORTP failed\n"); } exit(0); } /* end of function */ long /*FUNCTION*/ compar( long i, long j) { long int compar_v; /* Determine the relative order of R(I) and R(J), where R is in * the common block /RCOM/. Return -1 if R(I) should preceed R(J) * in the sorted order, +1 if R(I) should follow R(J), and 0 * otherwise. * */ switch (SARITHIF(rcom.r[i-(1)] - rcom.r[j-(1)])) { case -1: goto L_10; case 0: goto L_20; case 1: goto L_30; } L_10: compar_v = -1; return( compar_v ); L_20: compar_v = 0; return( compar_v ); L_30: compar_v = 1; return( compar_v ); } /* end of function */