Debian Codegraph @

gui/XIdent/src/splib.c

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