| 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 |
.LANGUAGE C |
| 30 |
.IDENT optplate |
| 31 |
.AUTHOR Preben Grosbol (ESO-IPG) |
| 32 |
.KEYWORDS OPTOPUS, Star plates, drill |
| 33 |
.ENVIRON ESO-MIDAS |
| 34 |
.COMMENTS Uses 'osa' for writing ASCII command file |
| 35 |
.PURPOSE Convert a MIDAS table of OPTOPUS object positions |
| 36 |
into a ASCII command file for drilling the star |
| 37 |
plate. |
| 38 |
.VERSION 1.0 1991-Sep-03 : Creation, PJG |
| 39 |
.VERSION 1.1 1991-Nov-29 : Exchange '.' with ',' in numbers, PJG |
| 40 |
.VERSION 1.2 1994-Feb-11 : Update to new SC-routines, PJG |
| 41 |
|
| 42 |
090903 last modif |
| 43 |
------------------------------------------------------------------------*/ |
| 44 |
|
| 45 |
#include <osparms.h> /* MIDAS OS definitions */ |
| 46 |
#include <midas_def.h> /* MIDAS definitions */ |
| 47 |
#include <optdef.h> /* Definition of templete commands */ |
| 48 |
|
| 49 |
#include <stdio.h> |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
#define MXNAME 60 /* Max. char. in file names */ |
| 55 |
#define MXOBJ 512 /* Max. objects in table file */ |
| 56 |
#define DFEXT ".dat" /* Default extension of ASCII file */ |
| 57 |
|
| 58 |
#define X_LABEL "X" |
| 59 |
#define Y_LABEL "Y" |
| 60 |
#define Z_LABEL "Z" |
| 61 |
#define T_LABEL "TYPE" |
| 62 |
|
| 63 |
int main() |
| 64 |
{ |
| 65 |
char dname[MXNAME], tname[MXNAME], line[80]; |
| 66 |
char *pc, obj_type[MXOBJ]; |
| 67 |
char *strrchr(); |
| 68 |
int err, no_obj, i, bguide; |
| 69 |
int tid, fid, iva, inull, sflag; |
| 70 |
int col, row, nsort, acol, arow; |
| 71 |
int col_no_xpos, col_no_ypos, col_no_zval, col_no_type; |
| 72 |
double xpos[MXOBJ], ypos[MXOBJ], zval[MXOBJ]; |
| 73 |
CMDLINE *pcmd, **ptmpl; |
| 74 |
|
| 75 |
SCSPRO("OPTPLATE"); /* initiate MIDAS environment */ |
| 76 |
|
| 77 |
/* read name of TABLE, open it and find columns */ |
| 78 |
|
| 79 |
err = SCKGETC("IN_A", 1, MXNAME, &iva, tname); |
| 80 |
pc = tname; |
| 81 |
while (*pc && *pc!=' ') pc++; |
| 82 |
*pc = '\0'; |
| 83 |
err = TCTOPN(tname, F_I_MODE, &tid); |
| 84 |
err = TCIGET(tid, &col, &row, &nsort, &acol, &arow); |
| 85 |
|
| 86 |
err = TCLSER(tid, X_LABEL, &col_no_xpos); |
| 87 |
err = TCLSER(tid, Y_LABEL, &col_no_ypos); |
| 88 |
err = TCLSER(tid, Z_LABEL, &col_no_zval); |
| 89 |
err = TCLSER(tid, T_LABEL, &col_no_type); |
| 90 |
|
| 91 |
no_obj = 0; |
| 92 |
for (i=1; i<=row; i++) { /* read table into arrays */ |
| 93 |
err = TCSGET(tid, i, &sflag); |
| 94 |
if (!sflag) continue; |
| 95 |
iva = 0; |
| 96 |
err = TCERDD(tid, i, col_no_xpos, &xpos[no_obj], &inull); |
| 97 |
iva |= inull; |
| 98 |
err = TCERDD(tid, i, col_no_ypos, &ypos[no_obj], &inull); |
| 99 |
iva |= inull; |
| 100 |
err = TCERDD(tid, i, col_no_zval, &zval[no_obj], &inull); |
| 101 |
iva |= inull; |
| 102 |
err = TCERDC(tid, i, col_no_type, line, &inull); |
| 103 |
iva |= inull; |
| 104 |
if (iva) continue; |
| 105 |
if (MXOBJ <= no_obj) { /* too many table rows */ |
| 106 |
SCTPUT("Warning: too many rows in table - truncation done!"); |
| 107 |
no_obj++; break; |
| 108 |
} |
| 109 |
xpos[no_obj] /= 1000.0; |
| 110 |
ypos[no_obj] /= 1000.0; |
| 111 |
zval[no_obj] /= 1000.0; |
| 112 |
obj_type[no_obj++] = *line; |
| 113 |
} |
| 114 |
sprintf(line,"%5d objects read from table >%s<",no_obj,tname); |
| 115 |
SCTPUT(line); |
| 116 |
TCTCLO(tid); /* close table file */ |
| 117 |
|
| 118 |
/* read name of ASCII file and open it */ |
| 119 |
|
| 120 |
err = SCKGETC("OUT_A", 1, MXNAME, &iva, dname); |
| 121 |
pc = dname; |
| 122 |
while (*pc && *pc!=' ') pc++; |
| 123 |
*pc = '\0'; |
| 124 |
|
| 125 |
if (*dname == '*') { /* create default file name */ |
| 126 |
strcpy(dname,tname); |
| 127 |
if ((pc=strrchr(dname,'.'))) strcpy(pc,DFEXT); |
| 128 |
} |
| 129 |
if (!strrchr(dname,'.')) strcat(dname,DFEXT); |
| 130 |
|
| 131 |
if ((fid=osaopen(dname,WRITE)) == -1) { /* open ASCII command file */ |
| 132 |
SCETER(1, "Error: cannot open ASCII output file"); |
| 133 |
} |
| 134 |
|
| 135 |
/* write ASCII command file */ |
| 136 |
|
| 137 |
ptmpl = tmpl; |
| 138 |
do { |
| 139 |
pcmd = *ptmpl; |
| 140 |
if (pcmd->type) |
| 141 |
for (i=0; i<no_obj; i++) { |
| 142 |
bguide = (obj_type[i]=='B' || obj_type[i]=='b'); |
| 143 |
while ((pc=pcmd->line)) { |
| 144 |
if ((!bguide && (pcmd->type & 0x10)) || |
| 145 |
(bguide && (pcmd->type & 0x20))) { |
| 146 |
if (pcmd->type & 0x3) { /* check format */ |
| 147 |
if (pcmd->type & 0x01) |
| 148 |
sprintf(line,pc,xpos[i],ypos[i]); |
| 149 |
else if (pcmd->type & 0x02) sprintf(line,pc,zval[i]); |
| 150 |
pc = line; |
| 151 |
while (*pc) { /* change . with , */ |
| 152 |
if (*pc=='.') *pc = ','; |
| 153 |
pc++; |
| 154 |
} |
| 155 |
osawrite(fid,line,strlen(line)); |
| 156 |
} |
| 157 |
else osawrite(fid,pc,strlen(pc)); |
| 158 |
} |
| 159 |
pcmd++; |
| 160 |
} |
| 161 |
pcmd = *ptmpl; |
| 162 |
} |
| 163 |
else while ((pc=(pcmd++)->line)) osawrite(fid,pc,strlen(pc)); |
| 164 |
ptmpl++; |
| 165 |
} while (*ptmpl); |
| 166 |
|
| 167 |
/* close files and exit */ |
| 168 |
|
| 169 |
osaclose(fid); |
| 170 |
sprintf(line,"ASCII drill command file >%s< written",dname); |
| 171 |
SCTPUT(line); |
| 172 |
|
| 173 |
SCSEPI(); |
| 174 |
|
| 175 |
return 0; |
| 176 |
} |