Debian Codegraph @

applic/general/src/sortrow.c

raw
1 /*===========================================================================
2 Copyright (C) 1991-2005 European Southern Observatory (ESO)
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 2 of
7 the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public
15 License along with this program; if not, write to the Free
16 Software Foundation, Inc., 675 Massachusetts Ave, Cambridge,
17 MA 02139, USA.
18
19 Correspondence concerning ESO-MIDAS should be addressed as follows:
20 Internet e-mail: [email protected]
21 Postal address: European Southern Observatory
22 Data Management Division
23 Karl-Schwarzschild-Strasse 2
24 D 85748 Garching bei Muenchen
25 GERMANY
26 ===========================================================================*/
27
28 /* Program : sortrow.c */
29 /* Author : P. Ballester ESO - Garching */
30 /* Date : 29.04.91 */
31
32 /* 090710 last modif */
33
34 #include <midas_def.h>
35
36 #include <stdio.h>
37 #include <mutil.h>
38
39 #define ipos(col, row,siz) row * siz + col
40
41 int main()
42 {
43
44 char inpframe[TEXT_LEN+1], outframe[TEXT_LEN+1];
45 char ident[TEXT_LEN+1], cunit[16*2 + 1];
46 char text[TEXT_LEN+1], time[TEXT_LEN+1];
47
48 float *pntr_inp, *pntr_out;
49 float ratio, thres=20.;
50
51 double start[2], step[2];
52
53 int naxis, npix[2], actvals, imno_inp, imno_out;
54 int nbrow, nbcol, row, pos, posmin, posmax;
55
56 SCSPRO("sortrow");
57
58 SCKGETC("IN_A", 1, 80, &actvals, inpframe);
59 SCKGETC("IN_B", 1, 80, &actvals, outframe);
60
61 SCIGET (inpframe, D_R4_FORMAT, F_I_MODE, F_IMA_TYPE, 2,
62 &naxis, npix, start, step, ident, cunit, (char **)&pntr_inp,
63 &imno_inp);
64
65
66 SCIPUT (outframe, D_R4_FORMAT, F_IO_MODE, F_IMA_TYPE, naxis,
67 npix, start, step, ident, cunit, (char **)&pntr_out, &imno_out);
68
69 nbrow = npix[1];
70 nbcol = npix[0];
71
72 for (row=0; row<nbrow; row++) {
73
74 ratio = 100. * (row+1) / nbrow;
75 if (ratio >= thres) {
76 OSY_ASCTIM(time);
77 sprintf (text," %d%% done ...",(int) thres);
78 strcat (time,text);
79 SCTPUT(time);
80 thres += 20.;
81 }
82
83 /* Copy column into output frame */
84 posmin = ipos(0,row,nbcol);
85 posmax = ipos(nbcol, row, nbcol);
86
87 for (pos=posmin; pos<posmax; pos++)
88 pntr_out[pos] = pntr_inp[pos];
89
90 /* sort(nbcol,&pntr_out[posmin-1]); */
91 quick_sort(nbcol, &pntr_out[posmin]);
92
93 }
94 SCSEPI();
95 return 0;
96 }
97
98