1
/* @(#)luttbl.c 19.1 (ES0-DMD) 02/25/03 14:01:07 */
2
/*===========================================================================
3
Copyright (C) 1995 European Southern Observatory (ESO)
5
This program is free software; you can redistribute it and/or
6
modify it under the terms of the GNU General Public License as
7
published by the Free Software Foundation; either version 2 of
8
the License, or (at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public
16
License along with this program; if not, write to the Free
17
Software Foundation, Inc., 675 Massachusetss Ave, Cambridge,
20
Corresponding concerning ESO-MIDAS should be addressed as follows:
21
Internet e-mail: midas@eso.org
22
Postal address: European Southern Observatory
23
Data Management Division
24
Karl-Schwarzschild-Strasse 2
25
D 85748 Garching bei Muenchen
27
===========================================================================*/
29
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
30
.COPYRIGHT: Copyright (c) 1994 European Southern Observatory,
32
.IDENTIFIER module LUTTBL
34
.AUTHOR K. Banse ESO - IPG, Garching
35
.KEYWORDS LUT/ITT tables
36
.PURPOSE use table interfaces
37
.CONTAINS OPNTBL, CRELUT & CREITT
39
#include <midas_def.h> Prototypes for MIDAS interfaces
41
.VERSIONS 1.00 940704 F77 -> C, from TABSUBS.FOR R.M.van Hees
42
.VERSIONS 1.10 941109 cleanup + fix it
43
------------------------------------------------------------*/
45
/* Define _POSIX_SOURCE to indicate that this is a POSIX program */
47
#define _POSIX_SOURCE 1
50
#include <midas_def.h>
58
/*++++++++++++++++++++++++++++++
60
.PURPOSE open LUT or ITT tables
62
call as OPNTBL( table, tid, ncols, nrows )
64
char *table : table name
66
int *tid : id of table
67
int *ncols : number of columns
68
int *nrows : number of rows
71
--------------------------------*/
73
void OPNTBL( table, tid, ncols, nrows )
75
int *tid, *ncols, *nrows;
78
int allcol, allrow, ec, el, ed, nsort, stat;
81
static int con_alw = 1, log_no = 0, dis_no = 0; /* variables for SCECNT */
84
/* first look for table in current directory,
85
then for table in MID_WORK, finally look for system table */
87
(void) SCECNT( "GET", &ec, &el, &ed );
88
(void) SCECNT( "PUT", &con_alw, &log_no, &dis_no );
89
stat = TCTOPN( table, F_I_MODE, tid );
91
nsort = 0; /* use as indicator of SCECNT */
92
if (stat != ERR_NORMAL)
94
(void) sprintf( file, "MID_WORK:%-s", table );
95
stat = TCTOPN( file, F_I_MODE, tid );
98
(void) sprintf( file, "MID_SYSTAB:%-s", table );
99
(void) SCECNT( "PUT", &ec, &el, &ed );
101
stat = TCTOPN( file, F_I_MODE, tid );
105
/* get info about table */
107
if (nsort == 0) (void) SCECNT( "PUT", &ec, &el, &ed );
108
(void) TCIGET( *tid, ncols, nrows, &nsort, &allcol, &allrow );
114
/*++++++++++++++++++++++++++++++
116
.PURPOSE create + fill LUT tables for Image Display
118
call as CRELUT( table, rlut )
120
char *table: table name
121
float *rlut: LUT table (red, green, blue)
123
int format: format = 0 for Midas table, 9 for ASCII file
124
int *range: low, high range (0,1 or 0,255 supported)
127
--------------------------------*/
129
void CRELUT (table,rlut,lutlen,format,range)
132
int lutlen, format, *range;
136
register float *pntrR, *pntrG, *pntrB;
138
int idx, tid, tcolnm[3], idata[3];
142
int IndxR, IndxG, IndxB;
143
static char *tbllab[3] = { "RED", "GREEN", "BLUE" };
145
idx = CGN_INDEXC(table,' ');
146
if (idx < 0) idx = strlen(table);
148
SCETER(111,"CRELUT: input table name > 56 chars....");
152
IndxB = lutlen + lutlen;
153
pntrR = rlut + IndxR;
154
pntrG = rlut + IndxG;
155
pntrB = rlut + IndxB;
158
/* check for table or ASCII file option */
160
if (format == 9) /* write to ASCII file */
164
fp = osaopen(table,1); /* open for writing */
166
SCETER(123,"Could not open output file...");
170
for (nn=1; nn<=lutlen; nn++)
175
sprintf(mytab," %8.5f %8.5f %8.5f",data[0],data[1],data[2]);
176
osawrite(fp,mytab,strlen(mytab));
183
rm = (float) (MYLUTSZ - 1);
184
for (nn=1; nn<=lutlen; nn++)
187
idata[0] = CGN_NINT(data[0]*rm);
189
idata[1] = CGN_NINT(data[1]*rm);
191
idata[2] = CGN_NINT(data[2]*rm);
192
sprintf(mytab," %d %d %d",idata[0],idata[1],idata[2]);
193
osawrite(fp,mytab,strlen(mytab));
199
else /* write to Midas table */
201
(void) strncpy(mytab,table,idx);
202
(void) strcpy(&mytab[idx],".lut");
204
(void) TCTINI( mytab, 0, F_O_MODE, 8, MYLUTSZ, &tid );
206
for (nn=0; nn<3; nn++)
207
(void) TCCINI( tid, D_R4_FORMAT, 1, "e12.5", " ", tbllab[nn], tcolnm+nn );
209
for (nn=1; nn<=lutlen; nn++)
214
(void) TCRWRR( tid, nn, 3, tcolnm, data );
217
(void) TCSINI( tid ); /* release table file properly */
218
(void) TCTCLO( tid );
225
/*++++++++++++++++++++++++++++++
227
.PURPOSE create + fill ITT tables for Image Display
229
call as CREITT( table, rlut )
231
char *table : table name
233
float *ritt : ITT table
236
--------------------------------*/
238
void CREITT ( table, ritt )
245
int idx, tid, tcolnm;
248
static char *tbllab = "ITT";
250
idx = CGN_INDEXC(table,' ');
251
if (idx < 0) idx = strlen(table);
253
SCETER(111,"CREITT: input table name > 56 chars....");
255
(void) strncpy(mytab,table,idx);
256
(void) strcpy(&mytab[idx],".itt");
258
(void) TCTINI( mytab, 0, F_O_MODE, 4, MYLUTSZ, &tid );
259
(void) TCCINI( tid, D_R4_FORMAT, 1, "e12.5", " ", tbllab, &tcolnm );
261
for (nn=1; nn<=MYLUTSZ; nn++)
262
(void) TCEWRR( tid, nn, tcolnm, ritt++ );
264
(void) TCSINI( tid ); /* release table file properly */
265
(void) TCTCLO( tid );