Debian Codegraph @

gui/XEchelle/src/splib.c

raw
1 /*===========================================================================
2 Copyright (C) 1991 - 2009 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 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
29 .IDENT libsp.c
30 .MODULE subroutines -- spcallin.exe, spcalib.exe
31 .LANGUAGE C
32 .AUTHOR Cristian Levin - ESO La Silla
33 .PURPOSE Functions for reading the line catalog table.
34 .KEYWORDS calibration
35 .VERSION 1.0 1-Mar-1991 Implementation
36
37 090825 last modif
38 ------------------------------------------------------------*/
39
40 #include <stdio.h>
41 #include <midas_def.h>
42
43 #include <gl_defs.h>
44 #include <spec_defs.h>
45
46 extern float *fvector();
47
48 extern int *ivector();
49
50 extern char **cmatrix();
51
52 extern void free_fvector(), free_cmatrix(), free_ivector();
53
54
55
56 /*
57 * read_catalog_table(): reads catalog table named by 'lincat' and
58 * stores the values in the 'lc' structure. Values should have the
59 * following conditions:
60 * wrang[0] <= wave <= wrang[1]
61 * intens >= imin
62 */
63 int read_catalog_table( lc, lincat, wrang, imin )
64 LCTAB *lc;
65 char *lincat;
66 int wrang[2];
67 float imin;
68 {
69 int inull;
70 float rnull;
71 double dnull;
72 int nulval, sortcol, aw, ar, ncols;
73 int nrows = 0;
74 float intens;
75 float wave;
76 int col_wave, col_intens, col_ion;
77 int i, id;
78 char str[MAXLINE];
79
80 strcpy( lc->name, lincat );
81
82 TCMNUL( &inull, &rnull, &dnull ); /* obtain NULL values */
83 if ( TCTOPN( lc->name, F_I_MODE, &id ) != 0 ) {
84 sprintf( str, "Table %s couldn't be opened.", lc->name );
85 SCTPUT( str );
86 return FALSE;
87 }
88 TCIGET( id, &ncols, &lc->nrows, &sortcol, &aw, &ar );
89
90 TCCSER( id, COL_WAVE, &col_wave );
91 if ( col_wave == -1 ) {
92 sprintf( str, "*** column %s missing ***", COL_WAVE );
93 SCTPUT( str );
94 return FALSE;
95 }
96 TCCSER( id, COL_INTENSITY, &col_intens );
97 if ( col_intens == -1 )
98 TCCSER( id, COL_STRENGTH, &col_intens );
99
100 TCCSER( id, COL_ION, &col_ion );
101 if ( col_ion == -1 ) {
102 sprintf( str, "*** column %s missing ***", COL_ION );
103 SCTPUT( str );
104 return FALSE;
105 }
106
107 /* allocate space for data */
108 lc->row = ivector( 0, lc->nrows - 1 );
109 lc->wave = fvector( 0, lc->nrows - 1 );
110 lc->intens = fvector( 0, lc->nrows - 1 );
111 lc->ion = cmatrix( 0, lc->nrows - 1, 0, MAXION - 1 );
112
113 for ( i = 0; i < lc->nrows; i++ ) {
114 lc->intens[nrows] = 0;
115 lc->ion[nrows][0] = '\0';
116 TCERDR( id, i+1, col_wave, &wave, &nulval );
117 if ( wave > wrang[1] || wave < wrang[0] ) /* Wavelength range */
118 continue;
119 if ( col_intens != -1 ) {
120 TCERDR( id, i+1, col_intens, &intens, &nulval );
121 if ( intens != rnull && intens < imin ) /* Strength limit */
122 continue;
123 if ( intens != rnull )
124 lc->intens[nrows] = intens;
125 }
126 if ( col_ion != -1 )
127 TCERDC( id, i+1, col_ion, lc->ion[nrows], &nulval );
128 lc->wave[nrows] = wave;
129 lc->row[nrows] = i+1;
130 nrows++;
131 }
132 lc->nrows = nrows; /* no. of effective rows */
133 TCTCLO( id );
134
135 return TRUE;
136 }
137
138 void free_catalog_table( lc )
139 LCTAB *lc;
140 {
141 free_ivector(lc->row, 0, lc->nrows - 1);
142 free_fvector(lc->wave, 0, lc->nrows - 1);
143 free_fvector(lc->intens, 0, lc->nrows - 1);
144 free_cmatrix(lc->ion, 0, lc->nrows - 1, 0, MAXION - 1);
145
146 osmmfree((char *)lc);
147 }
148
149 void nrerror( msg ) /* for management of math local routine errors */
150 char *msg;
151 {
152 fprintf(stderr, "* %s *\r\n", msg);
153 }