| 1 |
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 2 |
.IDENT applic.c |
| 3 |
.MODULE subroutines -- gmidas.exe |
| 4 |
.LANGUAGE C |
| 5 |
.AUTHOR M.Peron- ESO |
| 6 |
.PURPOSE |
| 7 |
.KEYWORDS application routines, Midas related routines. |
| 8 |
.VERSION 1.0 1-Mar-1994 Implementation |
| 9 |
|
| 10 |
090825 last modif |
| 11 |
------------------------------------------------------------*/ |
| 12 |
|
| 13 |
#include <stdio.h> |
| 14 |
#include <math.h> |
| 15 |
|
| 16 |
#include <do.h> |
| 17 |
#include "UxLib.h" |
| 18 |
#include <midas_def.h> |
| 19 |
#include <str.h> |
| 20 |
#include <tbldef.h> |
| 21 |
#include <osparms.h> |
| 22 |
|
| 23 |
#include <Xm/List.h> |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
extern int file_exists(), read_ident(), stsnum(); |
| 28 |
|
| 29 |
extern void free_cmatrix(), free_ivector(); |
| 30 |
|
| 31 |
char *mode[] = {"IMAGING (RED)","IMAGING (BLUE)", "IMAGING (SUSI)", |
| 32 |
"GRISM SPECTROSCOPY","GRATING SPECTROSCOPY (RED)", |
| 33 |
"GRATING SPECTROSCOPY (BLUE)", |
| 34 |
"ECHELLE SPECTROSCOPY"}; |
| 35 |
char *all[] = {"EXPTIME","RA","DEC","DATE","EXPTYPE","OPATH"}; |
| 36 |
char *imar[] = {"R_FILTER_ID"}; |
| 37 |
char *imab[] = {"B_FILTER_ID"}; |
| 38 |
char *ech[] = {"R_FILTER_ID","GRISM_ID","R_GRATING_ID","R_GRATING_WLEN"}; |
| 39 |
char *gr[] = {"R_FILTER_ID","GRISM_ID"}; |
| 40 |
char *gtr[] = {"R_FILTER_ID","R_GRATING_ID","R_GRATING_WLEN"}; |
| 41 |
char *gtb[] = {"B_FILTER_ID","B_GRATING_ID","B_GRATING_WLEN"}; |
| 42 |
char *susi[] = {"S_FILTER_ID"}; |
| 43 |
char *osmmget(); |
| 44 |
|
| 45 |
/******************* |
| 46 |
Local variables |
| 47 |
*******************/ |
| 48 |
static LCTAB *Lc = NULL; /* Line catalog table */ |
| 49 |
static LCCOL *Lcc = NULL; |
| 50 |
static char * List[10240]; |
| 51 |
static int OstAllocated = FALSE; |
| 52 |
static int oldcbs; |
| 53 |
/********************************** |
| 54 |
application external variables |
| 55 |
**********************************/ |
| 56 |
extern char ostchoice[60]; /* OST table*/ |
| 57 |
extern char claschoice[60]; /* Clas table*/ |
| 58 |
extern char *rowtext[256]; /*Text Widget*/ |
| 59 |
extern Widget sb; |
| 60 |
|
| 61 |
int size; |
| 62 |
double atof(); |
| 63 |
float *fvector(); |
| 64 |
int *ivector(); |
| 65 |
char **cmatrix(); |
| 66 |
char *cvector(); |
| 67 |
extern int tidost,tidclas,colno,fno; |
| 68 |
extern char *colchoice; |
| 69 |
extern char *filechoice; |
| 70 |
void free_ost(); |
| 71 |
int read_ost_table() |
| 72 |
{ |
| 73 |
if ( ! file_exists( ostchoice, ".tbl" ) ) { |
| 74 |
SCTPUT( "*** OST table doesn't exist ***" ); |
| 75 |
return(FALSE); |
| 76 |
} |
| 77 |
|
| 78 |
if ( Lc != NULL ) { /* deallocate space */ |
| 79 |
free_cmatrix(Lc->ident, 0, Lc->nrows - 1, 0, MAXION - 1); |
| 80 |
free_ivector(Lc->row,0,Lc->nrows-1); |
| 81 |
osmmfree((char *)Lc); |
| 82 |
} |
| 83 |
Lc = (LCTAB *)osmmget( sizeof(LCTAB) ); |
| 84 |
|
| 85 |
/* call to a library routine */ |
| 86 |
if( !read_ident( Lc,ostchoice) ) { |
| 87 |
Lc = NULL; |
| 88 |
return FALSE; |
| 89 |
} |
| 90 |
return TRUE; |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
void display_ident_table( wlist ) |
| 95 |
Widget wlist; |
| 96 |
{ |
| 97 |
int i; |
| 98 |
XmStringTable str_list; |
| 99 |
|
| 100 |
if ( OstAllocated ) |
| 101 |
free_ost(); |
| 102 |
OstAllocated = TRUE; |
| 103 |
for ( i = 0; i < Lc->nrows; i++ ) |
| 104 |
List[i] = (char *)osmmget( 80 ); |
| 105 |
List[Lc->nrows] = NULL; |
| 106 |
|
| 107 |
for ( i = 0; i < Lc->nrows; i++ ) |
| 108 |
strcpy( List[i], Lc->ident[i]); |
| 109 |
|
| 110 |
str_list = (XmStringTable)XtMalloc(Lc->nrows * sizeof(XmString *)); |
| 111 |
for ( i = 0; i < Lc->nrows; i++ ) { |
| 112 |
str_list[i] = XmStringCreateSimple(List[i]); |
| 113 |
} |
| 114 |
XmListSetPos(wlist, 1); |
| 115 |
XmListDeleteAllItems(wlist); |
| 116 |
XmListAddItems(wlist, str_list, Lc->nrows, 1); |
| 117 |
|
| 118 |
for ( i = 0; i <Lc->nrows; i++ ) |
| 119 |
XmStringFree(str_list[i]); |
| 120 |
XtFree((char*)str_list); |
| 121 |
|
| 122 |
|
| 123 |
} |
| 124 |
|
| 125 |
|
| 126 |
void display_col_table( wlist ) |
| 127 |
Widget wlist; |
| 128 |
{ |
| 129 |
extern swidget myerror; |
| 130 |
int i,j,k,dummy,mycol[256],len,mylen,nulls[256],pos; |
| 131 |
int top,visible; |
| 132 |
char form[TBL_FORLEN+1]; |
| 133 |
char title[500],mylabel[TBL_LABLEN+1],mymess[60]; |
| 134 |
XmStringTable str_list; |
| 135 |
Position x1,x2,y; |
| 136 |
|
| 137 |
if (Lcc != NULL ) { |
| 138 |
free_cmatrix(Lcc->value,0,Lcc->nrows-1,0,MAXVAL-1); |
| 139 |
osmmfree((char *)Lcc); |
| 140 |
Lcc = (LCCOL *)0; |
| 141 |
} |
| 142 |
for (i=0; i<500; i++) title[i] = '\0'; |
| 143 |
mylen = 1; |
| 144 |
k = 0; |
| 145 |
/* sprintf(mymess,"WRITE/OUT %s",colchoice); |
| 146 |
AppendDialogText(mymess);*/ |
| 147 |
for (i=0; i<colno; i++) { |
| 148 |
TCLSER(tidost,colchoice + i*(TBL_LABLEN+1),&mycol[i]); |
| 149 |
if (mycol[i] == -1) { |
| 150 |
XmListDeleteAllItems(UxGetWidget(UxFindSwidget("readtable"))); |
| 151 |
XmTextSetString(UxGetWidget(UxFindSwidget("scrollabel")),""); |
| 152 |
sprintf(mymess,"Column %s missing",colchoice+i*(TBL_LABLEN+1)); |
| 153 |
UxPutMessageString(UxFindSwidget("errorDialog1"),mymess); |
| 154 |
UxPopupInterface(myerror,no_grab); |
| 155 |
return ; |
| 156 |
} |
| 157 |
|
| 158 |
strncpy(mylabel,colchoice + i*(TBL_LABLEN+1),1+TBL_LABLEN); |
| 159 |
TCFGET(tidost,mycol[i],form,&len,&dummy); |
| 160 |
title[k++] = ' '; |
| 161 |
for (j=0; mylabel[j] && (j<len); j++) title[k++] = mylabel[j] ; |
| 162 |
for (; j < len; j++) title[k++] = ' '; |
| 163 |
mylen += len; |
| 164 |
mylen++; |
| 165 |
} |
| 166 |
Lcc = (LCCOL *)osmmget(sizeof(LCCOL)) ; |
| 167 |
TCIGET( tidost, &dummy, &Lcc->nrows, &dummy, &dummy, &dummy ); |
| 168 |
Lcc->value = cmatrix(0,Lcc->nrows-1,0,mylen); |
| 169 |
str_list = (XmStringTable)XtMalloc(Lcc->nrows *sizeof(XmString *)); |
| 170 |
for (i=0; i< Lcc->nrows; i++) { |
| 171 |
TCRRDC(tidost,i+1,colno,mycol,Lcc->value[i],nulls); |
| 172 |
str_list[i] = XmStringCreateSimple(Lcc->value[i]); |
| 173 |
} |
| 174 |
XmListSetPos(wlist, 1); |
| 175 |
XmListDeleteAllItems(wlist); |
| 176 |
XmListAddItems(wlist, str_list, Lcc->nrows, 1); |
| 177 |
XtVaGetValues(UxGetWidget(UxFindSwidget("identlist")), |
| 178 |
XmNtopItemPosition,&top, |
| 179 |
XmNvisibleItemCount,&visible, |
| 180 |
NULL); |
| 181 |
XmListSetBottomPos(wlist,top+visible-1); |
| 182 |
for ( i = 0; i <Lcc->nrows; i++ ) |
| 183 |
XmStringFree(str_list[i]); |
| 184 |
XtFree((char *)str_list); |
| 185 |
XmTextSetString(UxGetWidget(UxFindSwidget("scrollabel")),title); |
| 186 |
XmTextShowPosition(UxGetWidget(UxFindSwidget("scrollabel")),(XmTextPosition) 0); |
| 187 |
pos = XmTextGetTopCharacter(UxGetWidget(UxFindSwidget("scrollabel"))); |
| 188 |
XmTextPosToXY(UxGetWidget(UxFindSwidget("scrollabel")),pos,&x1,&y); |
| 189 |
pos = pos+1; |
| 190 |
XmTextPosToXY(UxGetWidget(UxFindSwidget("scrollabel")),pos,&x2,&y); |
| 191 |
size = x2-x1; |
| 192 |
oldcbs = 0; |
| 193 |
} |
| 194 |
void free_ost() |
| 195 |
{ |
| 196 |
int i; |
| 197 |
|
| 198 |
for ( i = 0; i < Lc->nrows; i++ ) |
| 199 |
osmmfree( List[i] ); |
| 200 |
} |
| 201 |
|
| 202 |
|
| 203 |
void myscrollv(scrollbar,client_data,cbs) |
| 204 |
Widget scrollbar; |
| 205 |
XtPointer client_data; |
| 206 |
XmScrollBarCallbackStruct *cbs; |
| 207 |
{ |
| 208 |
|
| 209 |
XmListSetPos(UxGetWidget(UxFindSwidget("readtable")),cbs->value+1); |
| 210 |
XmListSetPos(UxGetWidget(UxFindSwidget("identlist")),cbs->value+1); |
| 211 |
} |
| 212 |
|
| 213 |
void myscrollh(scrollbar,client_data,cbs) |
| 214 |
Widget scrollbar; |
| 215 |
XtPointer client_data; |
| 216 |
XmScrollBarCallbackStruct *cbs; |
| 217 |
{ |
| 218 |
XmTextPosition pos; |
| 219 |
short int column; |
| 220 |
XtVaGetValues(UxGetWidget(UxFindSwidget("scrollabel")),XmNcolumns,&column,NULL); |
| 221 |
pos = cbs->value /size; |
| 222 |
if (cbs->value > oldcbs) { |
| 223 |
XmTextShowPosition(UxGetWidget(UxFindSwidget("scrollabel")),(XmTextPosition) (pos+column)); |
| 224 |
} |
| 225 |
else { |
| 226 |
XmTextShowPosition(UxGetWidget(UxFindSwidget("scrollabel")),(XmTextPosition) (pos)); |
| 227 |
} |
| 228 |
oldcbs = cbs->value; |
| 229 |
} |
| 230 |
void myscrollh2(scrollbar,client_data,cbs) |
| 231 |
Widget scrollbar; |
| 232 |
XtPointer client_data; |
| 233 |
XmScrollBarCallbackStruct *cbs; |
| 234 |
{ |
| 235 |
/*XmListSetPos(UxGetWidget(UxFindSwidget("sl2")),cbs->pixel); */ |
| 236 |
} |
| 237 |
|
| 238 |
void my_select(list_w,client_data,cbs) |
| 239 |
Widget list_w; |
| 240 |
XtPointer client_data; |
| 241 |
XmListCallbackStruct *cbs; |
| 242 |
{ |
| 243 |
int i, nbytes; |
| 244 |
char *choice ; |
| 245 |
if (filechoice) osmmfree(filechoice); |
| 246 |
nbytes = 200 * cbs->selected_item_count; |
| 247 |
fno = cbs->selected_item_count; |
| 248 |
filechoice = osmmget(nbytes); |
| 249 |
for (i=0; i<cbs->selected_item_count ;i++) { |
| 250 |
XmStringGetLtoR(cbs->selected_items[i],XmSTRING_DEFAULT_CHARSET,&choice); |
| 251 |
strcat(filechoice,choice); |
| 252 |
filechoice[strlen(filechoice)] = ','; |
| 253 |
filechoice[strlen(filechoice)+1] = '\0'; |
| 254 |
} |
| 255 |
XtFree(choice); |
| 256 |
} |
| 257 |
|
| 258 |
void myrow(widget,client_data,cbs) |
| 259 |
Widget widget; |
| 260 |
XtPointer client_data; |
| 261 |
XmRowColumnCallbackStruct *cbs; |
| 262 |
{ |
| 263 |
} |
| 264 |
|
| 265 |
void never_called(text_w,i) |
| 266 |
Widget text_w; |
| 267 |
int i; |
| 268 |
{ |
| 269 |
rowtext[i-1] = XmTextGetString(text_w); |
| 270 |
} |
| 271 |
void read_descr(mytext) |
| 272 |
Widget mytext; |
| 273 |
{ |
| 274 |
int indx,status,lbuf,numbuf,comma,item_no,i; |
| 275 |
XmString *str; |
| 276 |
char buf[32]; |
| 277 |
char *descr[200]; |
| 278 |
lbuf = 32; |
| 279 |
item_no = 0; |
| 280 |
indx = 1; |
| 281 |
while (!(status = SCDINF(tidost,indx,4,buf,lbuf,&numbuf))){ |
| 282 |
if (buf[0] == ' ' ) break; |
| 283 |
comma = stuindex(buf,","); |
| 284 |
if (buf[comma+1] == 'C' && strncmp(buf,"TLABL",5) !=0 && strncmp(buf,"TSELT",5) !=0 && strncmp(buf,"HISTORY",7) !=0 ) { |
| 285 |
descr[item_no] = osmmget(16); |
| 286 |
strncpy(descr[item_no],buf,comma-1); |
| 287 |
comma = stuindex(descr[item_no]," ") ; |
| 288 |
if (*(descr[item_no]+comma)) *(descr[item_no]+comma) = '\0'; |
| 289 |
item_no++; |
| 290 |
} |
| 291 |
indx++; |
| 292 |
} |
| 293 |
str = (XmString *)XtMalloc(item_no * sizeof(XmString)); |
| 294 |
for (i=0; i<item_no; i++) |
| 295 |
str[i] = XmStringCreateSimple(descr[i]); |
| 296 |
|
| 297 |
XtVaSetValues(mytext, |
| 298 |
XmNlistItems,str, |
| 299 |
XmNlistItemCount,item_no, |
| 300 |
NULL); |
| 301 |
} |
| 302 |
|
| 303 |
int redecomp(descr) |
| 304 |
char descr[257]; |
| 305 |
{ |
| 306 |
extern Widget rowrule[256][2]; |
| 307 |
extern swidget myerror; |
| 308 |
extern int tidost; |
| 309 |
int i,col,len,fin,colnew,ncol,dummy,index; |
| 310 |
char label[TBL_LABLEN+1],op[3],crit[256]; |
| 311 |
char mymess[60]; |
| 312 |
index = strscans(descr,":#"); |
| 313 |
if (!descr[index]) { |
| 314 |
sprintf(mymess,"This is probably not a classification rule"); |
| 315 |
UxPutMessageString(UxFindSwidget("errorDialog1"),mymess); |
| 316 |
UxPopupInterface(myerror,no_grab); |
| 317 |
return(-1); |
| 318 |
} |
| 319 |
TCIGET(tidost,&ncol,&dummy,&dummy,&dummy,&dummy); |
| 320 |
for (i=0; i<ncol; i++) XmTextSetString(rowrule[i][1],""); |
| 321 |
oscfill(label,TBL_LABLEN+1,'\0'); |
| 322 |
len = strlen(descr); |
| 323 |
i = stuindex(descr,"."); |
| 324 |
strncpy(label,descr,i); |
| 325 |
TCLSER(tidost,label+1,&colnew); |
| 326 |
descr = descr + i+1; |
| 327 |
while (*descr) { |
| 328 |
oscfill(crit,256,'\0'); |
| 329 |
fin = 1; |
| 330 |
col = colnew; |
| 331 |
while (fin) { |
| 332 |
if (*descr == ':') { |
| 333 |
i = stuindex(descr,"."); |
| 334 |
oscfill(label,TBL_LABLEN+1,'\0'); |
| 335 |
strncpy(label,descr,i); |
| 336 |
TCLSER(tidost,label+1,&col); |
| 337 |
descr = descr + i+1; |
| 338 |
} |
| 339 |
else if (*descr == 'O' || *descr == 'A') { |
| 340 |
if (*descr == 'O') { |
| 341 |
strcat(crit,"|"); |
| 342 |
descr = descr+3; |
| 343 |
i = stuindex(descr,"."); |
| 344 |
descr = descr+i+1; |
| 345 |
} |
| 346 |
else { |
| 347 |
descr = descr +4; |
| 348 |
i = stuindex(descr,"."); |
| 349 |
oscfill(label,17,'\0'); |
| 350 |
strncpy(label,descr,i); |
| 351 |
TCLSER(tidost,label+1,&colnew); |
| 352 |
descr = descr + i+1; |
| 353 |
if (col ==colnew) strcat(crit,"&"); |
| 354 |
else fin = 0; |
| 355 |
} |
| 356 |
} |
| 357 |
else if (stucomp(descr,"NULL") == 0) { |
| 358 |
descr+= 4; |
| 359 |
} |
| 360 |
else { |
| 361 |
if (strncmp(descr,"E",1) == 0) strcpy(op,"="); |
| 362 |
else if (strncmp(descr,"N",1) == 0) strcpy(op,"!="); |
| 363 |
else if (strncmp(descr,"LE",2) == 0) strcpy(op,"<="); |
| 364 |
else if (strncmp(descr,"LT",2) == 0) strcpy(op,"<"); |
| 365 |
else if (strncmp(descr,"GE",2) == 0) strcpy(op,">="); |
| 366 |
else if (strncmp(descr,"GT",2) == 0) strcpy(op,">"); |
| 367 |
else { |
| 368 |
while (*descr == ' ') descr++ ; |
| 369 |
fin = 0; |
| 370 |
continue; |
| 371 |
} |
| 372 |
strcat(crit,op); |
| 373 |
descr = descr + 3; |
| 374 |
if (*descr == '"') { |
| 375 |
descr++; |
| 376 |
if (*descr == '"') descr +=2; |
| 377 |
else { |
| 378 |
i = strloc(descr,'"'); |
| 379 |
strncat(crit,descr,i); |
| 380 |
descr = descr+i+2; |
| 381 |
} |
| 382 |
if (!*descr) fin = 0; |
| 383 |
} |
| 384 |
else { |
| 385 |
i = stsnum(descr); |
| 386 |
strncat(crit,descr,i); |
| 387 |
descr = descr+i; |
| 388 |
if (!*descr) fin=0; |
| 389 |
else if (*descr == '.') descr++; |
| 390 |
} |
| 391 |
} |
| 392 |
} |
| 393 |
/* UxPutText(UxWidgetToSwidget(row[col-1]),crit); */ |
| 394 |
XmTextSetString(rowrule[col-1][1],crit); |
| 395 |
} |
| 396 |
descr = descr-len; |
| 397 |
return 0; |
| 398 |
} |
| 399 |
|
| 400 |
|
| 401 |
int read_clas_table() |
| 402 |
{ |
| 403 |
extern Widget row1[40],row2[40],row3[40]; |
| 404 |
extern swidget myerror; |
| 405 |
extern int rowno; |
| 406 |
int cold,colo,cols,nrow,dummy,i,null; |
| 407 |
char mytext[8],descr[TBL_LABLEN+1],mystring[80]; |
| 408 |
if (tidclas !=-1) TCTCLO(tidclas); |
| 409 |
TCTOPN(claschoice,F_I_MODE,&tidclas); |
| 410 |
UxPutText(UxFindSwidget("sclas_t1"),claschoice); |
| 411 |
TCLSER(tidclas,"DESCR",&cold); |
| 412 |
if (cold == -1) { |
| 413 |
UxPutMessageString(UxFindSwidget("errorDialog1"),"Column DESCR missing"); |
| 414 |
UxPopupInterface(myerror,no_grab); |
| 415 |
return -1; |
| 416 |
} |
| 417 |
TCLSER(tidclas,"OUTCOL",&colo); |
| 418 |
if (colo == -1) { |
| 419 |
UxPutMessageString(UxFindSwidget("errorDialog1"),"Column OUTCOL missing"); |
| 420 |
UxPopupInterface(myerror,no_grab); |
| 421 |
return -1; |
| 422 |
} |
| 423 |
TCLSER(tidclas,"OUTCHAR",&cols); |
| 424 |
if (cols == -1) { |
| 425 |
UxPutMessageString(UxFindSwidget("errorDialog1"),"Column OUTCHAR missing"); |
| 426 |
UxPopupInterface(myerror,no_grab); |
| 427 |
return -1; |
| 428 |
} |
| 429 |
TCIGET(tidclas,&dummy,&nrow,&dummy,&dummy,&dummy); |
| 430 |
if (row1[0]) for (i=0; i<rowno; i++) { |
| 431 |
XmTextSetString(row1[i],""); |
| 432 |
XmTextSetString(row2[i],""); |
| 433 |
XmTextSetString(row3[i],""); |
| 434 |
} |
| 435 |
if (nrow>5 && nrow > rowno ) XtVaSetValues(UxGetWidget(UxFindSwidget("rowproc")),XmNnumColumns,nrow,NULL); |
| 436 |
for (i=0; i<nrow; i++) { |
| 437 |
if (!row1[i]) { |
| 438 |
sprintf(mytext,"text1_%d",i); |
| 439 |
row1[i] = XtVaCreateManagedWidget(mytext, xmTextWidgetClass,UxGetWidget( UxFindSwidget("rowproc")),NULL); |
| 440 |
sprintf(mytext,"text2_%d",i); |
| 441 |
row2[i] = XtVaCreateManagedWidget(mytext, xmTextWidgetClass,UxGetWidget( UxFindSwidget("rowproc")),NULL); |
| 442 |
sprintf(mytext,"text3_%d",i); |
| 443 |
row3[i] = XtVaCreateManagedWidget(mytext, xmTextWidgetClass,UxGetWidget( UxFindSwidget("rowproc")),NULL); |
| 444 |
} |
| 445 |
} |
| 446 |
if(nrow>5 && nrow > rowno) rowno=nrow; |
| 447 |
for (i=0; i<nrow; i++) { |
| 448 |
TCERDC(tidclas,i+1,cold,descr,&null); |
| 449 |
XmTextSetString(row1[i],descr); |
| 450 |
TCERDC(tidclas,i+1,colo,descr,&null); |
| 451 |
XmTextSetString(row2[i],descr); |
| 452 |
TCERDC(tidclas,i+1,cols,mystring,&null); |
| 453 |
XmTextSetString(row3[i],mystring); |
| 454 |
} |
| 455 |
return 0; |
| 456 |
|
| 457 |
} |
| 458 |
int read_asso_table() |
| 459 |
{ |
| 460 |
extern Widget arow1[20],arow2[20],arow3[20],arow4[20]; |
| 461 |
extern swidget myerror; |
| 462 |
extern int arowno,tidasso; |
| 463 |
extern char assochoice[60]; |
| 464 |
int colf,colr1,colr2,colw,nrow,dummy,i,null; |
| 465 |
char mytext[8],function[100],range1[20],range2[20],weight[10]; |
| 466 |
if (tidasso !=-1) TCTCLO(tidasso); |
| 467 |
TCTOPN(assochoice,F_IO_MODE,&tidasso); |
| 468 |
TCLSER(tidasso,"FUNCTION",&colf); |
| 469 |
if (colf == -1) { |
| 470 |
UxPutMessageString(UxFindSwidget("errorDialog1"),"Column FUNCTION missing"); |
| 471 |
UxPopupInterface(myerror,no_grab); |
| 472 |
return -1; |
| 473 |
} |
| 474 |
TCLSER(tidasso,"RANGE_1",&colr1); |
| 475 |
if (colr1 == -1) { |
| 476 |
UxPutMessageString(UxFindSwidget("errorDialog1"),"Column RANGE_1 missing"); |
| 477 |
UxPopupInterface(myerror,no_grab); |
| 478 |
return -1; |
| 479 |
} |
| 480 |
TCLSER(tidasso,"RANGE_2",&colr2); |
| 481 |
if (colr2 == -1) { |
| 482 |
UxPutMessageString(UxFindSwidget("errorDialog1"),"Column RANGE_2 missing"); |
| 483 |
UxPopupInterface(myerror,no_grab); |
| 484 |
return -1; |
| 485 |
} |
| 486 |
TCLSER(tidasso,"WEIGHT",&colw); |
| 487 |
if (colw == -1) { |
| 488 |
UxPutMessageString(UxFindSwidget("errorDialog1"),"Column WEIGHT missing"); |
| 489 |
UxPopupInterface(myerror,no_grab); |
| 490 |
return -1; |
| 491 |
} |
| 492 |
TCIGET(tidasso,&dummy,&nrow,&dummy,&dummy,&dummy); |
| 493 |
if (nrow>5 && nrow > arowno) XtVaSetValues(UxGetWidget(UxFindSwidget("rowasso")),XmNnumColumns,nrow,NULL); |
| 494 |
if (arow1[0]) for (i=0; i<arowno; i++) { |
| 495 |
XmTextSetString(arow1[i],""); |
| 496 |
XmTextSetString(arow2[i],""); |
| 497 |
XmTextSetString(arow3[i],""); |
| 498 |
XmTextSetString(arow4[i],""); |
| 499 |
} |
| 500 |
for (i=0; i<nrow; i++) { |
| 501 |
if (!arow1[i]) { |
| 502 |
sprintf(mytext,"a1_%d",i); |
| 503 |
arow1[i] = XtVaCreateManagedWidget(mytext, xmTextWidgetClass,UxGetWidget( UxFindSwidget("rowasso")),NULL); |
| 504 |
sprintf(mytext,"a2_%d",i); |
| 505 |
arow2[i] = XtVaCreateManagedWidget(mytext, xmTextWidgetClass,UxGetWidget( UxFindSwidget("rowasso")),NULL); |
| 506 |
sprintf(mytext,"a3_%d",i); |
| 507 |
arow3[i] = XtVaCreateManagedWidget(mytext, xmTextWidgetClass,UxGetWidget( UxFindSwidget("rowasso")),NULL); |
| 508 |
|
| 509 |
sprintf(mytext,"a4_%d",i); |
| 510 |
arow3[i] = XtVaCreateManagedWidget(mytext, xmTextWidgetClass,UxGetWidget( UxFindSwidget("rowasso")),NULL); |
| 511 |
} |
| 512 |
} |
| 513 |
if(nrow>5 && nrow > arowno) arowno=nrow; |
| 514 |
for (i=0; i<nrow; i++) { |
| 515 |
TCERDC(tidasso,i+1,colf,function,&null); |
| 516 |
XmTextSetString(arow1[i],function); |
| 517 |
TCERDC(tidasso,i+1,colr1,range1,&null); |
| 518 |
XmTextSetString(arow2[i],range1); |
| 519 |
TCERDC(tidasso,i+1,colr2,range2,&null); |
| 520 |
XmTextSetString(arow3[i],range2); |
| 521 |
TCERDC(tidasso,i+1,colw,weight,&null); |
| 522 |
XmTextSetString(arow4[i],weight); |
| 523 |
} |
| 524 |
UxPutText(UxFindSwidget("arule_name"),assochoice); |
| 525 |
return 0; |
| 526 |
} |
| 527 |
|
| 528 |
|
| 529 |
int save_clas_table(table) |
| 530 |
char *table; |
| 531 |
{ |
| 532 |
extern Widget row1[40],row2[40],row3[40]; |
| 533 |
extern int rowno; |
| 534 |
int tid,cold,colo,cols,i,index; |
| 535 |
char *mytext,lab1[TBL_LABLEN+1],lab2[80]; |
| 536 |
|
| 537 |
TCTINI(table,F_TRANS,F_O_MODE,3,rowno,&tid); |
| 538 |
TCCINI(tid,D_C_FORMAT,16,"A10"," ","DESCR",&cold); |
| 539 |
TCCINI(tid,D_C_FORMAT,16,"A10"," ","OUTCOL",&colo); |
| 540 |
TCCINI(tid,D_C_FORMAT,80,"A20"," ","OUTCHAR",&cols); |
| 541 |
for (i=0; i<rowno;i++) { |
| 542 |
mytext = XmTextGetString(row1[i]); |
| 543 |
index = strskip(mytext,' '); |
| 544 |
strcpy(lab1,mytext+index); |
| 545 |
XtFree(mytext); |
| 546 |
if (lab1[0] == '\0') continue; |
| 547 |
index = strbskip(lab1,' '); |
| 548 |
if (lab1[index+1] !='\0' ) lab1[index+1] = '\0'; |
| 549 |
TCEWRC(tid,i+1,cold,lab1); |
| 550 |
mytext = XmTextGetString(row2[i]); |
| 551 |
index = strskip(mytext,' '); |
| 552 |
strcpy(lab1,mytext+index); |
| 553 |
XtFree(mytext); |
| 554 |
index = strbskip(lab1,' '); |
| 555 |
if (lab1[index+1] !='\0' ) lab1[index+1] = '\0'; |
| 556 |
TCEWRC(tid,i+1,colo,lab1); |
| 557 |
mytext = XmTextGetString(row3[i]); |
| 558 |
index = strskip(mytext,' '); |
| 559 |
strcpy(lab2,mytext+index); |
| 560 |
XtFree(mytext); |
| 561 |
index = strbskip(lab2,' '); |
| 562 |
if (lab2[index+1] !='\0' ) lab2[index+1] = '\0'; |
| 563 |
TCEWRC(tid,i+1,cols,lab2); |
| 564 |
} |
| 565 |
TCTCLO(tid); |
| 566 |
return 0; |
| 567 |
} |
| 568 |
|
| 569 |
int save_asso_table(table) |
| 570 |
char *table; |
| 571 |
{ |
| 572 |
extern Widget arow1[20],arow2[20],arow3[20],arow4[20]; |
| 573 |
extern int arowno; |
| 574 |
int tid,colf,colr1,colr2,colw,i,index; |
| 575 |
char *mytext,lab1[100],lab2[20]; |
| 576 |
double weight; |
| 577 |
TCTINI(table,F_TRANS,F_O_MODE,4,arowno,&tid); |
| 578 |
TCCINI(tid,D_C_FORMAT,100,"A50"," ","FUNCTION",&colf); |
| 579 |
TCCINI(tid,D_C_FORMAT,20,"A20"," ","RANGE_1",&colr1); |
| 580 |
TCCINI(tid,D_C_FORMAT,20,"A20"," ","RANGE_2",&colr2); |
| 581 |
TCCINI(tid,D_R4_FORMAT,1,"F5.2"," ","WEIGHT",&colw); |
| 582 |
for (i=0; i<arowno;i++) { |
| 583 |
mytext= XmTextGetString(arow1[i]); |
| 584 |
if (mytext[0] == '\0') continue; |
| 585 |
index = strskip(mytext,' '); |
| 586 |
strcpy(lab1,mytext+index); |
| 587 |
XtFree(mytext); |
| 588 |
index = strbskip(lab1,' '); |
| 589 |
if (lab1[index+1] !='\0') lab1[index+1] = '\0'; |
| 590 |
TCEWRC(tid,i+1,colf,lab1); |
| 591 |
mytext = XmTextGetString(arow2[i]); |
| 592 |
index = strskip(mytext,' '); |
| 593 |
strcpy(lab2,mytext+index); |
| 594 |
XtFree(mytext); |
| 595 |
index = strbskip(lab2,' '); |
| 596 |
if (lab2[index+1] !='\0') lab2[index+1] = '\0'; |
| 597 |
TCEWRC(tid,i+1,colr1,lab2); |
| 598 |
mytext = XmTextGetString(arow3[i]); |
| 599 |
index = strskip(mytext,' '); |
| 600 |
strcpy(lab2,mytext+index); |
| 601 |
XtFree(mytext); |
| 602 |
index = strbskip(lab2,' '); |
| 603 |
if (lab2[index+1] !='\0') lab2[index+1] = '\0'; |
| 604 |
TCEWRC(tid,i+1,colr2,lab2); |
| 605 |
mytext = XmTextGetString(arow4[i]); |
| 606 |
weight = atof(mytext); |
| 607 |
XtFree(mytext); |
| 608 |
TCEWRD(tid,i+1,colw,&weight); |
| 609 |
} |
| 610 |
TCTCLO(tid); |
| 611 |
return 0; |
| 612 |
} |
| 613 |
|
| 614 |
void add_ident_table(wlist) |
| 615 |
Widget wlist; |
| 616 |
{ |
| 617 |
extern int tidost; |
| 618 |
int dummy,nrow,col_ident,nul,upper,visible,top,item_no; |
| 619 |
char mident[MAXION]; |
| 620 |
XmString item; |
| 621 |
XtVaGetValues(wlist,XmNitemCount,&upper, |
| 622 |
XmNvisibleItemCount,&visible, |
| 623 |
XmNtopItemPosition,&top, |
| 624 |
NULL); |
| 625 |
TCIGET( tidost, &dummy, &nrow, &dummy, &dummy, &dummy ); |
| 626 |
if (nrow > upper) { |
| 627 |
TCLSER(tidost,"IDENT",&col_ident); |
| 628 |
TCERDC(tidost,nrow,col_ident,mident,&nul); |
| 629 |
item = XmStringCreateSimple(mident); |
| 630 |
XmListAddItemUnselected(wlist,item,0); |
| 631 |
item_no = upper+1; |
| 632 |
if (item_no >=top+visible) XmListSetBottomPos(wlist,item_no); |
| 633 |
XmStringFree(item); |
| 634 |
} |
| 635 |
} |
| 636 |
|
| 637 |
|
| 638 |
void add_col_table(wlist) |
| 639 |
Widget wlist; |
| 640 |
{ |
| 641 |
int mylen,mycol[256],nulls[256],i,nrow, len,dummy,upper; |
| 642 |
int top,visible,item_no; |
| 643 |
char *myvalue,form[TBL_FORLEN+1]; |
| 644 |
XmString item; |
| 645 |
mylen = 0; |
| 646 |
|
| 647 |
XtVaGetValues(wlist,XmNitemCount,&upper, |
| 648 |
XmNvisibleItemCount,&visible, |
| 649 |
XmNtopItemPosition,&top, |
| 650 |
NULL); |
| 651 |
for (i=0; i<colno; i++) { |
| 652 |
TCLSER(tidost,colchoice + i*(TBL_LABLEN+1),&mycol[i]); |
| 653 |
TCFGET(tidost,mycol[i],form,&len,&dummy); |
| 654 |
mylen += len; |
| 655 |
mylen++; |
| 656 |
} |
| 657 |
TCIGET( tidost, &dummy, &nrow, &dummy, &dummy, &dummy ); |
| 658 |
if (nrow > upper) { |
| 659 |
myvalue = osmmget(mylen+1); |
| 660 |
TCRRDC(tidost,nrow,colno,mycol,myvalue,nulls); |
| 661 |
item = XmStringCreateSimple(myvalue); |
| 662 |
XmListAddItemUnselected(wlist,item,0); |
| 663 |
item_no = upper+1; |
| 664 |
if (item_no >=top+visible) XmListSetBottomPos(wlist,item_no); |
| 665 |
XmStringFree(item); |
| 666 |
osmmfree(myvalue); |
| 667 |
} |
| 668 |
} |
| 669 |
int initmytable() |
| 670 |
{ |
| 671 |
extern int tidcomm; |
| 672 |
int col,pid,val; |
| 673 |
char cval[2]; |
| 674 |
TCTINI("TAB_COMM",F_TRANS,F_O_MODE,3,1,&tidcomm); |
| 675 |
TCCINI(tidcomm,D_I4_FORMAT,1,"I6"," ","PID",&col); |
| 676 |
TCCINI(tidcomm,D_C_FORMAT,60,"A20"," ","OST",&col); |
| 677 |
TCCINI(tidcomm,D_C_FORMAT,60,"A20"," ","DESCR",&col); |
| 678 |
TCCINI(tidcomm,D_I4_FORMAT,1,"I6"," ","OPFLAG",&col); |
| 679 |
pid = oshpid(); |
| 680 |
TCEWRI(tidcomm,1,1,&pid); |
| 681 |
strcpy(cval,"?"); |
| 682 |
TCEWRC(tidcomm,1,2,cval); |
| 683 |
val = 1; |
| 684 |
TCEWRI(tidcomm,1,4,&val); |
| 685 |
TCTCLO(tidcomm); |
| 686 |
return 0; |
| 687 |
} |
| 688 |
|
| 689 |
int populate(wlist) |
| 690 |
Widget wlist; |
| 691 |
{ |
| 692 |
XmStringTable str_list; |
| 693 |
int i, item_no; |
| 694 |
|
| 695 |
item_no = 7; |
| 696 |
str_list = (XmStringTable)XtMalloc(item_no * sizeof(XmString)); |
| 697 |
for (i=0; i<item_no; i++) { |
| 698 |
str_list[i] = XmStringCreateSimple(mode[i]); |
| 699 |
} |
| 700 |
XmListSetPos(wlist,1); |
| 701 |
XmListDeleteAllItems(wlist); |
| 702 |
XmListAddItems(wlist, str_list, item_no, 1); |
| 703 |
|
| 704 |
for ( i = 0; i <item_no; i++ ) |
| 705 |
XmStringFree(str_list[i]); |
| 706 |
XtFree((char *)str_list); |
| 707 |
|
| 708 |
return 0; |
| 709 |
} |
| 710 |
|
| 711 |
int selectlist(mymode,wlist) |
| 712 |
char *mymode; |
| 713 |
Widget wlist; |
| 714 |
{ |
| 715 |
int item_no,i; |
| 716 |
XmString str; |
| 717 |
XtVaSetValues(wlist,XmNselectionPolicy,XmMULTIPLE_SELECT,NULL); |
| 718 |
XmListDeselectAllItems(wlist); |
| 719 |
if (stucomp(mymode,"COPY") == 0) { |
| 720 |
for (i=0; i<colno; i++) { |
| 721 |
str= XmStringCreateSimple(colchoice+i*(TBL_LABLEN+1)); |
| 722 |
XmListSelectItem(wlist,str,False); |
| 723 |
XmStringFree(str); |
| 724 |
} |
| 725 |
XtVaSetValues(wlist,XmNselectionPolicy,XmEXTENDED_SELECT,NULL); |
| 726 |
return(0); |
| 727 |
} |
| 728 |
item_no = 6; |
| 729 |
for (i=0; i<item_no; i++) { |
| 730 |
str= XmStringCreateSimple(all[i]); |
| 731 |
XmListSelectItem(wlist,str,False); |
| 732 |
XmStringFree(str); |
| 733 |
} |
| 734 |
|
| 735 |
if (stucomp(mymode,"GRISM SPECTROSCOPY") == 0) { |
| 736 |
item_no = 2; |
| 737 |
for (i=0; i<item_no; i++) { |
| 738 |
str= XmStringCreateSimple(gr[i]); |
| 739 |
XmListSelectItem(wlist,str,False); |
| 740 |
XmStringFree(str); |
| 741 |
} |
| 742 |
} |
| 743 |
else if (stucomp(mymode,"GRATING SPECTROSCOPY (RED)") == 0) { |
| 744 |
item_no = 3; |
| 745 |
for (i=0; i<item_no; i++) { |
| 746 |
str= XmStringCreateSimple(gtr[i]); |
| 747 |
XmListSelectItem(wlist,str,False); |
| 748 |
XmStringFree(str); |
| 749 |
} |
| 750 |
} |
| 751 |
else if (stucomp(mymode,"GRATING SPECTROSCOPY (BLUE)") == 0) { |
| 752 |
item_no = 3; |
| 753 |
for (i=0; i<item_no; i++) { |
| 754 |
str= XmStringCreateSimple(gtb[i]); |
| 755 |
XmListSelectItem(wlist,str,False); |
| 756 |
XmStringFree(str); |
| 757 |
} |
| 758 |
} |
| 759 |
else if (stucomp(mymode,"ECHELLE SPECTROSCOPY") == 0) { |
| 760 |
item_no = 4; |
| 761 |
for (i=0; i<item_no; i++) { |
| 762 |
str= XmStringCreateSimple(ech[i]); |
| 763 |
XmListSelectItem(wlist,str,False); |
| 764 |
XmStringFree(str); |
| 765 |
} |
| 766 |
} |
| 767 |
else if (stucomp(mymode,"IMAGING (RED)") == 0) { |
| 768 |
item_no = 1; |
| 769 |
for (i=0; i<item_no; i++) { |
| 770 |
str= XmStringCreateSimple(imar[i]); |
| 771 |
XmListSelectItem(wlist,str,False); |
| 772 |
XmStringFree(str); |
| 773 |
} |
| 774 |
} |
| 775 |
else if (stucomp(mymode,"IMAGING (BLUE)") == 0) { |
| 776 |
item_no = 1; |
| 777 |
for (i=0; i<item_no; i++) { |
| 778 |
str= XmStringCreateSimple(imab[i]); |
| 779 |
XmListSelectItem(wlist,str,False); |
| 780 |
XmStringFree(str); |
| 781 |
} |
| 782 |
} |
| 783 |
else if (stucomp(mymode,"IMAGING (SUSI)") == 0) { |
| 784 |
item_no = 1; |
| 785 |
for (i=0; i<item_no; i++) { |
| 786 |
str= XmStringCreateSimple(imab[i]); |
| 787 |
XmListSelectItem(wlist,str,False); |
| 788 |
XmStringFree(str); |
| 789 |
} |
| 790 |
} |
| 791 |
XtVaSetValues(wlist,XmNselectionPolicy,XmEXTENDED_SELECT,NULL); |
| 792 |
return 0; |
| 793 |
} |
| 794 |
|
| 795 |
|
| 796 |
int getselectlist(wlist) |
| 797 |
Widget wlist; |
| 798 |
{ |
| 799 |
XmString *str_list; |
| 800 |
int pos_cnt,i; |
| 801 |
char *choice; |
| 802 |
colno = 0; |
| 803 |
XtVaGetValues(wlist,XmNselectedItemCount,&pos_cnt, |
| 804 |
XmNselectedItems,&str_list, |
| 805 |
NULL); |
| 806 |
for (i=0; i<pos_cnt; i++ ) { |
| 807 |
XmStringGetLtoR(str_list[i],XmSTRING_DEFAULT_CHARSET,&choice); |
| 808 |
strcpy(colchoice+(TBL_LABLEN+1)*colno,choice); |
| 809 |
XtFree(choice); |
| 810 |
colno++; |
| 811 |
} |
| 812 |
return 0; |
| 813 |
} |
| 814 |
|
| 815 |
void display_help(wtext,file) |
| 816 |
swidget wtext; |
| 817 |
char file[20]; |
| 818 |
|
| 819 |
{ |
| 820 |
extern swidget help; |
| 821 |
int fid,nobytes,mm; |
| 822 |
char *pbuf,cfile[160]; |
| 823 |
|
| 824 |
OSY_TRNLOG("XDO_HELP",cfile,120,&mm); |
| 825 |
cfile[mm] = '/'; |
| 826 |
strcpy(&cfile[mm+1],file); |
| 827 |
fid = osaopen(cfile,F_I_MODE); |
| 828 |
nobytes = 100000; |
| 829 |
pbuf = (char *)osmmget(nobytes); |
| 830 |
osdread(fid,pbuf,nobytes); |
| 831 |
XmTextSetString(UxGetWidget(UxFindSwidget("scrolledText1")),pbuf); |
| 832 |
osaclose(fid); |
| 833 |
UxPopupInterface(help,no_grab); |
| 834 |
osmmfree(pbuf); |
| 835 |
} |
| 836 |
|
| 837 |
void checkdigit(text_w,unused,cbs) |
| 838 |
Widget text_w; |
| 839 |
XtPointer unused; |
| 840 |
XmTextVerifyCallbackStruct *cbs; |
| 841 |
{ |
| 842 |
int len; |
| 843 |
if (cbs->text->ptr == NULL) |
| 844 |
return; |
| 845 |
for (len=0; len<cbs->text->length; len++) { |
| 846 |
if (isalpha(cbs->text->ptr[len])) { |
| 847 |
int i; |
| 848 |
for (i=len; (i+1) <cbs->text->length; i++) |
| 849 |
cbs->text->ptr[i] = cbs->text->ptr[i+1]; |
| 850 |
cbs->text->length--; |
| 851 |
len--; |
| 852 |
} |
| 853 |
} |
| 854 |
} |
| 855 |
void checkchar(text_w,unused,cbs) |
| 856 |
Widget text_w; |
| 857 |
XtPointer unused; |
| 858 |
XmTextVerifyCallbackStruct *cbs; |
| 859 |
{ |
| 860 |
int len; |
| 861 |
if (cbs->text->ptr == NULL) |
| 862 |
return; |
| 863 |
for (len=0; len<cbs->text->length; len++) { |
| 864 |
if (cbs->text->ptr[len] == '<' || cbs->text->ptr[len] == '>' ) { |
| 865 |
int i; |
| 866 |
for (i=len; (i+1) <cbs->text->length; i++) |
| 867 |
cbs->text->ptr[i] = cbs->text->ptr[i+1]; |
| 868 |
cbs->text->length--; |
| 869 |
len--; |
| 870 |
} |
| 871 |
} |
| 872 |
} |