| 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 |
#include <stdio.h> |
| 29 |
#include <gl_defs.h> |
| 30 |
#include <xm_defs.h> |
| 31 |
#include <midas_def.h> |
| 32 |
|
| 33 |
#define MAXROWS 300 |
| 34 |
#define MAXIMAGE 80 |
| 35 |
#define MAXAIRM 20 |
| 36 |
#define DEFAULT_AIRM 1 |
| 37 |
#define NAMELEN 20 |
| 38 |
#define IDENTLEN 40 |
| 39 |
|
| 40 |
|
| 41 |
extern void GetNameInputCatalog(), DropTrailingBlanks(); |
| 42 |
extern int file_exists(), AppendDialogText(); |
| 43 |
|
| 44 |
void UpdateAirmass(); |
| 45 |
int ExistDescriptor(), ExistAirmass(); |
| 46 |
|
| 47 |
|
| 48 |
static Widget NameForm, ValueForm; |
| 49 |
static int ItemsForm; |
| 50 |
|
| 51 |
/************************************************************************** |
| 52 |
FillAirmassForm(): fill the text form with : |
| 53 |
- name & ident of each image of the input catalog in one text widget |
| 54 |
(read/only). |
| 55 |
- airmass value in the other text widget (read/write). |
| 56 |
If the input catalog is invalid, returns FALSE, else TRUE. |
| 57 |
*/ |
| 58 |
int FillAirmassForm( w_name, w_value) |
| 59 |
Widget w_name, w_value; |
| 60 |
{ |
| 61 |
char incat[MAXLINE]; |
| 62 |
char *image_list, *airmass_list; |
| 63 |
char name[MAXLINE], ident[MAXLINE]; |
| 64 |
char line[MAXLINE]; |
| 65 |
float airmass; |
| 66 |
FILE *fp; |
| 67 |
extern char *XmTextFieldGetString(); |
| 68 |
|
| 69 |
NameForm = w_name; |
| 70 |
ValueForm = w_value; |
| 71 |
ItemsForm = 0; |
| 72 |
|
| 73 |
GetNameInputCatalog(incat); |
| 74 |
|
| 75 |
if ( !file_exists(incat, ".cat") ) |
| 76 |
return FALSE; |
| 77 |
|
| 78 |
airmass_list = XtMalloc((unsigned) MAXIMAGE * MAXROWS); |
| 79 |
image_list = XtMalloc((unsigned) MAXAIRM * MAXROWS); |
| 80 |
airmass_list[0] = image_list[0] = '\0'; |
| 81 |
|
| 82 |
/* Unfortunately this routine doesn't work. It opens the catalog only once. |
| 83 |
If the catalog is modified before the next call, it doesn't take care of |
| 84 |
it and still gets the old entries. We'll read the catalog by hand. |
| 85 |
SCCGET(incat, 1, name, ident, &entry); |
| 86 |
*/ |
| 87 |
|
| 88 |
if ( strstr(incat, ".cat") == NULL ) |
| 89 |
strcat(incat, ".cat"); |
| 90 |
|
| 91 |
fp = fopen(incat, "r"); |
| 92 |
fgets(line, MAXLINE, fp); /* read comments line */ |
| 93 |
while ( fgets(line, MAXLINE, fp) != NULL ) { |
| 94 |
strncpy(name, line, NAMELEN); |
| 95 |
name[NAMELEN] = '\0'; |
| 96 |
strncpy(ident, line+NAMELEN, IDENTLEN); |
| 97 |
ident[IDENTLEN] = '\0'; |
| 98 |
DropTrailingBlanks(name); |
| 99 |
sprintf(image_list, "%s%s %s\n", image_list, name, ident); |
| 100 |
if ( ExistAirmass(name, &airmass) ) |
| 101 |
sprintf(airmass_list, "%s%.6f\n", airmass_list, airmass); |
| 102 |
else |
| 103 |
sprintf(airmass_list, "%s%d\n", airmass_list, DEFAULT_AIRM); |
| 104 |
ItemsForm++; |
| 105 |
} |
| 106 |
fclose(fp); |
| 107 |
|
| 108 |
XmTextSetString(w_name, image_list); |
| 109 |
XmTextSetString(w_value, airmass_list); |
| 110 |
|
| 111 |
XtFree(airmass_list); |
| 112 |
XtFree(image_list); |
| 113 |
|
| 114 |
return TRUE; |
| 115 |
} |
| 116 |
|
| 117 |
void UpdateAirmassValues() |
| 118 |
{ |
| 119 |
char *name_index, *value_index; |
| 120 |
char *name_list, *value_list; |
| 121 |
char name[MAXLINE], ident[MAXLINE], value[MAXLINE]; |
| 122 |
int i; |
| 123 |
float fval; |
| 124 |
|
| 125 |
name_list = XmTextGetString(NameForm); |
| 126 |
value_list = XmTextGetString(ValueForm); |
| 127 |
|
| 128 |
name_index = name_list; |
| 129 |
value_index = value_list; |
| 130 |
for ( i = 0; i < ItemsForm; i++ ) { |
| 131 |
sscanf(name_index, "%s%[^\n]", name, ident); |
| 132 |
sscanf(value_index, "%[^\n]", value); |
| 133 |
sscanf(value, "%f", &fval); |
| 134 |
UpdateAirmass(name, fval); |
| 135 |
name_index += strlen(name) + strlen(ident) + 1; |
| 136 |
value_index += strlen(value) + 1; |
| 137 |
} |
| 138 |
|
| 139 |
XtFree(name_list); |
| 140 |
XtFree(value_list); |
| 141 |
} |
| 142 |
|
| 143 |
/************************************************************************* |
| 144 |
MissingAirmassInCatalog(): check if the images of the input catalog have |
| 145 |
the airmass descriptor. Return TRUE if any of them don't have it. |
| 146 |
*/ |
| 147 |
int MissingAirmassInCatalog() |
| 148 |
{ |
| 149 |
char incat[MAXLINE], name[MAXLINE], line[MAXLINE]; |
| 150 |
float airmass; |
| 151 |
FILE *fp; |
| 152 |
|
| 153 |
GetNameInputCatalog(incat); |
| 154 |
|
| 155 |
if ( !file_exists(incat, ".cat") ) |
| 156 |
return TRUE; |
| 157 |
|
| 158 |
if ( strstr(incat, ".cat") == NULL ) |
| 159 |
strcat(incat, ".cat"); |
| 160 |
|
| 161 |
fp = fopen(incat, "r"); |
| 162 |
fgets(line, MAXLINE, fp); /* read comments line */ |
| 163 |
while ( fgets(line, MAXLINE, fp) != NULL ) { |
| 164 |
strncpy(name, line, NAMELEN); |
| 165 |
name[NAMELEN] = '\0'; |
| 166 |
DropTrailingBlanks(name); |
| 167 |
if ( !ExistAirmass(name, &airmass) ) |
| 168 |
return TRUE; |
| 169 |
} |
| 170 |
fclose(fp); |
| 171 |
|
| 172 |
return FALSE; |
| 173 |
} |
| 174 |
|
| 175 |
/**************************************************************** |
| 176 |
ReadAirmassValues(): read the airmass values of the image names |
| 177 |
*/ |
| 178 |
void ReadAirmassValues() |
| 179 |
{ |
| 180 |
} |
| 181 |
|
| 182 |
void UpdateAirmass( image, airmass ) |
| 183 |
char *image; |
| 184 |
float airmass; |
| 185 |
{ |
| 186 |
char command[MAXLINE]; |
| 187 |
float local_airm; |
| 188 |
int unit, id; |
| 189 |
|
| 190 |
if ( !file_exists(image, ".bdf") ) |
| 191 |
return; |
| 192 |
|
| 193 |
if ( !ExistDescriptor(image, "O_AIRM") ) { |
| 194 |
sprintf(command, "write/desc %s o_airm/r/1/1 %f", image, airmass); |
| 195 |
AppendDialogText(command); |
| 196 |
return; |
| 197 |
} |
| 198 |
SCFOPN(image, D_R4_FORMAT, 0, F_IMA_TYPE, &id); |
| 199 |
local_airm = airmass; |
| 200 |
SCDWRR(id, "O_AIRM", &local_airm, 1, 1, &unit); |
| 201 |
SCFCLO(id); |
| 202 |
} |
| 203 |
|
| 204 |
/****************************************************************************** |
| 205 |
ExistAirmass(): checks if the descriptor O_AIRM or AIRMASS exists in 'image'. |
| 206 |
if it exists, returns the value in the variable 'airmass'. |
| 207 |
*/ |
| 208 |
|
| 209 |
int ExistAirmass( image, airmass ) |
| 210 |
char *image; |
| 211 |
float *airmass; |
| 212 |
{ |
| 213 |
int retval, nulval; /* useless */ |
| 214 |
char descnam[10]; |
| 215 |
int unit, id; |
| 216 |
|
| 217 |
if ( ExistDescriptor(image, "O_AIRM") ) |
| 218 |
strcpy(descnam, "O_AIRM"); |
| 219 |
else if ( ExistDescriptor(image, "AIRMASS") ) |
| 220 |
strcpy(descnam, "AIRMASS"); |
| 221 |
else |
| 222 |
return FALSE; |
| 223 |
|
| 224 |
SCFOPN(image, D_R4_FORMAT, 0, F_IMA_TYPE, &id); |
| 225 |
SCDRDR(id, descnam, 1, 1, &retval, airmass, &unit, &nulval); |
| 226 |
SCFCLO(id); |
| 227 |
|
| 228 |
return TRUE; |
| 229 |
} |
| 230 |
|
| 231 |
/**************************************************************************** |
| 232 |
ExistDescriptor(): checks if the descriptor 'desc' exists in 'image'. |
| 233 |
*/ |
| 234 |
int ExistDescriptor( image, desc ) |
| 235 |
char *image; /* name of the image */ |
| 236 |
char *desc; /* descriptor name */ |
| 237 |
{ |
| 238 |
int retval, nulval, id; |
| 239 |
char type; |
| 240 |
|
| 241 |
if ( file_exists( image, ".bdf" ) ) { |
| 242 |
SCFOPN( image, D_R4_FORMAT, 0, F_IMA_TYPE, &id ); |
| 243 |
SCDFND( id, desc, &type, &retval, &nulval ); |
| 244 |
if ( type != ' ' ) { |
| 245 |
SCFCLO(id); |
| 246 |
return(TRUE); |
| 247 |
} |
| 248 |
SCFCLO(id); |
| 249 |
} |
| 250 |
return(FALSE); |
| 251 |
} |