1 |
#ident "$Header: /home/cvsuser/cvsroot/JSOC/proj/lev0/apps/get_image_location.c,v 1.6 2010/12/06 23:03:06 jps Exp $" |
2 |
/* GET IMAGE LOCATION to be merged into Jim's Lev1 code */ |
3 |
/* NOTE1:Jim:Jim's code needs to free Image_Location after calling get_location_information. */ |
4 |
/* NOTE2:Jim:Example main file used to test at:/home3/carl/cvs/JSOC/proj/lev1/apps/gif_main.c*/ |
5 |
/******************** defines ***********************************************/ |
6 |
/* use by Jim's pre-productions test-> #define GMP_MASTER_POINTING_SERIES "su_carl.master_pointing" */ |
7 |
/* use by Carl to test ->#define GMP_MASTER_POINTING_SERIES "su_carl.test99_master_pointing"*/ |
8 |
/* use for production after launch ->#define GMP_MASTER_POINTING_SERIES "sdo._master_pointing"*/ |
9 |
#define GMP_MASTER_POINTING_SERIES "sdo.master_pointing" |
10 |
#define GMP_DRMS_OPEN_FAILED 1 |
11 |
#define GMP_MAX_DSNAME_STR 100 |
12 |
#define GMP_MAX_KEYWORD_NAME_STR 100 |
13 |
#define GMP_MAX_QUERY_STR 200 |
14 |
#define GMP_MAX_MPO_REC_SIZE 200 |
15 |
#define GMP_MAX_TELESCOPE_STR 10 |
16 |
#define GMP_MALLOC_FAILED 2 |
17 |
#define GMP_PACKET_TIME_STR 50 |
18 |
#define GMP_PASSED_STATUS 0 |
19 |
#define GMP_TOBS_NOT_SORTED_FAILED 3 |
20 |
|
21 |
/******************** structures ********************************************/ |
22 |
typedef struct Image_Location_struct { |
23 |
//******* |
24 |
// Inputs |
25 |
//******* |
26 |
// Obs time |
27 |
TIME tobs; |
28 |
|
29 |
// For AIA:1,2,3,4. For HMI:1 or 2 |
30 |
int camera; |
31 |
|
32 |
// For AIA:SDO/AIA. For HMI:SDO/HMI |
33 |
char telescope[GMP_MAX_TELESCOPE_STR]; |
34 |
|
35 |
//wavelength |
36 |
int wavelength; |
37 |
|
38 |
//******************************************* |
39 |
// Returned values from get_image_location() |
40 |
//******************************************* |
41 |
float x; |
42 |
float y; |
43 |
float instrot; |
44 |
float imscale; |
45 |
float yinrtb; //value in mp is SC_Y_INRT_BIAS; |
46 |
float zinrtb; // value in mp is SC_Z_INRT_BIAS; |
47 |
// MPO_REC, "Master Pointing series record pointer" |
48 |
char mpo_rec[GMP_MAX_MPO_REC_SIZE]; |
49 |
|
50 |
} Image_Location; |
51 |
|
52 |
typedef struct TIME_MP_struct { |
53 |
TIME tstart; |
54 |
TIME tstop; |
55 |
} TIME_MP; |
56 |
|
57 |
/******************** functions *********************************************/ |
58 |
int find_mp_record(TIME_MP *time_mp, int nrec, TIME tobs); |
59 |
|
60 |
/****************************************************************************/ |
61 |
/************* get_image_location function *********************************/ |
62 |
/****************************************************************************/ |
63 |
int get_image_location(DRMS_Env_t *drms_env, int ncnt, Image_Location **ptr_imageloc) |
64 |
{ |
65 |
|
66 |
/* drms record create variables */ |
67 |
DRMS_RecordSet_t *rs; |
68 |
DRMS_RecordSet_t *rset; |
69 |
DRMS_Record_t *rec; |
70 |
/* local variables */ |
71 |
Image_Location *tptr; |
72 |
TIME tstart_range,tend_range; |
73 |
TIME_MP *time_mp; |
74 |
char dsname[GMP_MAX_DSNAME_STR]; |
75 |
char nquery[GMP_MAX_QUERY_STR]; |
76 |
int i,j,idx; |
77 |
int nrec; |
78 |
int status; |
79 |
|
80 |
/* initialize variables */ |
81 |
tptr= *ptr_imageloc; |
82 |
|
83 |
/*get master pointing series name */ |
84 |
strcpy(dsname, GMP_MASTER_POINTING_SERIES); |
85 |
|
86 |
/* set tstart and tend range */ |
87 |
tstart_range= (tptr)->tobs; |
88 |
tend_range= (tptr+(ncnt-1))->tobs ; |
89 |
|
90 |
/* check for not sort list of tobs */ |
91 |
if (tstart_range > tend_range) |
92 |
{ |
93 |
printkerr("ERROR at %s, line %d: Failed because TOBS list is not sorted. " |
94 |
"Returning error. Not setting return values.\n",__FILE__,__LINE__); |
95 |
return (GMP_TOBS_NOT_SORTED_FAILED); |
96 |
} |
97 |
|
98 |
/* create query statement */ |
99 |
sprintf(nquery,"%s[? T_START < %.0f AND T_STOP > %.0f ?]",dsname,tend_range,tstart_range); |
100 |
//printf("test:get_location_information:<%s>\n",nquery); |
101 |
|
102 |
/* open records with query */ |
103 |
rset = drms_open_records(drms_env, nquery, &status); |
104 |
if(!rset || !rset->n || status) |
105 |
{ |
106 |
/* return error PT_DRMS_OPEN_FAILED if cannot open */ |
107 |
printkerr("ERROR at %s, line %d: Failed to open master pointing series:<%s>. " |
108 |
"Check envirionment GMP_MASTER_POINTING_SERIES variable is set " |
109 |
"correctly. Or check time range in master pointing series is available.\n", |
110 |
__FILE__,__LINE__, dsname); |
111 |
return (GMP_DRMS_OPEN_FAILED); |
112 |
} |
113 |
nrec= rset->n; |
114 |
|
115 |
/*allocate space for time records found in query */ |
116 |
time_mp= (TIME_MP *) malloc(nrec*sizeof(TIME_MP)); |
117 |
if(!time_mp) return (GMP_MALLOC_FAILED); |
118 |
|
119 |
/*put time records in allocated time records */ |
120 |
for(i=0; i<nrec;i++) |
121 |
{ |
122 |
(time_mp+i)->tstart=drms_getkey_time(rset->records[i],"T_START",&status); |
123 |
(time_mp+i)->tstop=drms_getkey_time(rset->records[i],"T_STOP",&status); |
124 |
} |
125 |
|
126 |
/* loop thru array of structures and fill in values including tobs value */ |
127 |
for(i=0; i < ncnt; i++) |
128 |
{ |
129 |
/* find_mp_record where tobs values is between T_START and T_STOP values of record */ |
130 |
idx=find_mp_record(time_mp, nrec, (tptr+i)->tobs); |
131 |
if (idx == -1) |
132 |
{ |
133 |
printkerr("WARNING at %s, line %d: Setting return values to DRMS_MISSING_FLOAT " |
134 |
"because could not find record. TOBS time passed " |
135 |
"is <%f>.\n", __FILE__,__LINE__,(tptr+i)->tobs); |
136 |
(tptr+i)->x= DRMS_MISSING_FLOAT; |
137 |
(tptr+i)->y= DRMS_MISSING_FLOAT; |
138 |
(tptr+i)->instrot=DRMS_MISSING_FLOAT; |
139 |
(tptr+i)->imscale=DRMS_MISSING_FLOAT; |
140 |
(tptr+i)->zinrtb=DRMS_MISSING_FLOAT; |
141 |
(tptr+i)->yinrtb=DRMS_MISSING_FLOAT; |
142 |
continue; |
143 |
} |
144 |
|
145 |
/* get record found where found tobs value is between T_START and T_STOP values in mp */ |
146 |
rec=rset->records[idx]; |
147 |
|
148 |
/* set spacecraft z inrt and y inrt bias value */ |
149 |
(tptr+i)->zinrtb =drms_getkey_float(rec, "SC_Z_INRT_BIAS", &status); |
150 |
if(status == -10006) |
151 |
{ |
152 |
(tptr+i)->zinrtb=DRMS_MISSING_FLOAT; |
153 |
printkerr("WARNING at %s, line %d: Setting zinrtb failed because of error code DRMS_ERROR_UNKNOWNKEYWORD. " |
154 |
"Status returned from drms_getkey_float was %d\n", __FILE__,__LINE__, status); |
155 |
} |
156 |
|
157 |
(tptr+i)->yinrtb=drms_getkey_float(rec, "SC_Y_INRT_BIAS", &status); |
158 |
if(status == -10006) |
159 |
{ |
160 |
(tptr+i)->yinrtb=DRMS_MISSING_FLOAT; |
161 |
printkerr("WARNING at %s, line %d: Setting yinrtb failed because of error code DRMS_ERROR_UNKNOWNKEYWORD. " |
162 |
"Status returned from drms_getkey_float was %d\n",__FILE__,__LINE__, status); |
163 |
} |
164 |
|
165 |
|
166 |
/* load parameters in structure using values from this mp record */ |
167 |
if(!strcmp((tptr+i)->telescope, "SDO/HMI")) |
168 |
{ |
169 |
if((tptr+i)->camera == 1) |
170 |
{ |
171 |
(tptr+i)->x =drms_getkey_float(rec, "H_CAM1_X0", &status); |
172 |
(tptr+i)->y=drms_getkey_float(rec, "H_CAM1_Y0", &status); |
173 |
(tptr+i)->instrot=drms_getkey_float(rec, "H_CAM1_INSTROT", &status); |
174 |
(tptr+i)->imscale=drms_getkey_float(rec, "H_CAM1_IMSCALE", &status); |
175 |
sprintf((tptr+i)->mpo_rec, "%s[:#%lld]", GMP_MASTER_POINTING_SERIES, rec->recnum); |
176 |
} |
177 |
else if((tptr+i)->camera == 2) |
178 |
{ |
179 |
(tptr+i)->x=drms_getkey_float(rec, "H_CAM2_X0", &status); |
180 |
(tptr+i)->y=drms_getkey_float(rec, "H_CAM2_Y0", &status); |
181 |
(tptr+i)->instrot=drms_getkey_float(rec, "H_CAM2_INSTROT", &status); |
182 |
(tptr+i)->imscale=drms_getkey_float(rec, "H_CAM2_IMSCALE", &status); |
183 |
sprintf((tptr+i)->mpo_rec, "%s[:#%lld]", GMP_MASTER_POINTING_SERIES, rec->recnum); |
184 |
} |
185 |
else |
186 |
{ |
187 |
printkerr("WARNING at %s, line %d: Setting returns values set to DRMS_MISSING_FLOAT " |
188 |
"because could not find camera value for hmi. Camera value passed " |
189 |
"is <%d>.\n", __FILE__,__LINE__,(tptr+i)->camera); |
190 |
(tptr+i)->x= DRMS_MISSING_FLOAT; |
191 |
(tptr+i)->y=DRMS_MISSING_FLOAT; |
192 |
(tptr+i)->instrot=DRMS_MISSING_FLOAT; |
193 |
(tptr+i)->imscale=DRMS_MISSING_FLOAT; |
194 |
} |
195 |
}/*end if HMI data to retrieve and set */ |
196 |
else if(!strcmp((tptr+i)->telescope, "SDO/AIA")) |
197 |
{ |
198 |
if ( (tptr+i)->wavelength == 94) |
199 |
{ |
200 |
(tptr+i)->x=drms_getkey_float(rec, "A_094_X0", &status); |
201 |
(tptr+i)->y=drms_getkey_float(rec, "A_094_Y0", &status); |
202 |
(tptr+i)->instrot=drms_getkey_float(rec, "A_094_INSTROT", &status); |
203 |
(tptr+i)->imscale=drms_getkey_float(rec, "A_094_IMSCALE", &status); |
204 |
sprintf((tptr+i)->mpo_rec, "%s[:#%lld]", GMP_MASTER_POINTING_SERIES, rec->recnum); |
205 |
} |
206 |
else if ( (tptr+i)->wavelength == 131) |
207 |
{ |
208 |
(tptr+i)->x=drms_getkey_float(rec, "A_131_X0", &status); |
209 |
(tptr+i)->y=drms_getkey_float(rec, "A_131_Y0", &status); |
210 |
(tptr+i)->instrot=drms_getkey_float(rec, "A_131_INSTROT", &status); |
211 |
(tptr+i)->imscale=drms_getkey_float(rec, "A_131_IMSCALE", &status); |
212 |
sprintf((tptr+i)->mpo_rec, "%s[:#%lld]", GMP_MASTER_POINTING_SERIES, rec->recnum); |
213 |
} |
214 |
else if ( (tptr+i)->wavelength == 171) |
215 |
{ |
216 |
(tptr+i)->x=drms_getkey_float(rec, "A_171_X0", &status); |
217 |
(tptr+i)->y=drms_getkey_float(rec, "A_171_Y0", &status); |
218 |
(tptr+i)->instrot=drms_getkey_float(rec, "A_171_INSTROT", &status); |
219 |
(tptr+i)->imscale=drms_getkey_float(rec, "A_171_IMSCALE", &status); |
220 |
sprintf((tptr+i)->mpo_rec, "%s[:#%lld]", GMP_MASTER_POINTING_SERIES, rec->recnum); |
221 |
} |
222 |
//added after ok from jps to treat 193 and 195 identical |
223 |
else if (((tptr+i)->wavelength == 193) || ((tptr+i)->wavelength == 195)) |
224 |
{ |
225 |
(tptr+i)->x=drms_getkey_float(rec, "A_193_X0", &status); |
226 |
(tptr+i)->y=drms_getkey_float(rec, "A_193_Y0", &status); |
227 |
(tptr+i)->instrot=drms_getkey_float(rec, "A_193_INSTROT", &status); |
228 |
(tptr+i)->imscale=drms_getkey_float(rec, "A_193_IMSCALE", &status); |
229 |
sprintf((tptr+i)->mpo_rec, "%s[:#%lld]", GMP_MASTER_POINTING_SERIES, rec->recnum); |
230 |
} |
231 |
else if ( (tptr+i)->wavelength == 211) |
232 |
{ |
233 |
(tptr+i)->x=drms_getkey_float(rec, "A_211_X0", &status); |
234 |
(tptr+i)->y=drms_getkey_float(rec, "A_211_Y0", &status); |
235 |
(tptr+i)->instrot=drms_getkey_float(rec, "A_211_INSTROT", &status); |
236 |
(tptr+i)->imscale=drms_getkey_float(rec, "A_211_IMSCALE", &status); |
237 |
sprintf((tptr+i)->mpo_rec, "%s[:#%lld]", GMP_MASTER_POINTING_SERIES, rec->recnum); |
238 |
} |
239 |
else if ( (tptr+i)->wavelength == 304) |
240 |
{ |
241 |
(tptr+i)->x=drms_getkey_float(rec, "A_304_X0", &status); |
242 |
(tptr+i)->y=drms_getkey_float(rec, "A_304_Y0", &status); |
243 |
(tptr+i)->instrot=drms_getkey_float(rec, "A_304_INSTROT", &status); |
244 |
(tptr+i)->imscale=drms_getkey_float(rec, "A_304_IMSCALE", &status); |
245 |
sprintf((tptr+i)->mpo_rec, "%s[:#%lld]", GMP_MASTER_POINTING_SERIES, rec->recnum); |
246 |
} |
247 |
else if ( (tptr+i)->wavelength == 335) |
248 |
{ |
249 |
(tptr+i)->x=drms_getkey_float(rec, "A_335_X0", &status); |
250 |
(tptr+i)->y=drms_getkey_float(rec, "A_335_Y0", &status); |
251 |
(tptr+i)->instrot=drms_getkey_float(rec, "A_335_INSTROT", &status); |
252 |
(tptr+i)->imscale=drms_getkey_float(rec, "A_335_IMSCALE", &status); |
253 |
sprintf((tptr+i)->mpo_rec, "%s[:#%lld]", GMP_MASTER_POINTING_SERIES, rec->recnum); |
254 |
} |
255 |
else if ( (tptr+i)->wavelength == 1600) |
256 |
{ |
257 |
(tptr+i)->x=drms_getkey_float(rec, "A_1600_X0", &status); |
258 |
(tptr+i)->y=drms_getkey_float(rec, "A_1600_Y0", &status); |
259 |
(tptr+i)->instrot=drms_getkey_float(rec, "A_1600_INSTROT", &status); |
260 |
(tptr+i)->imscale=drms_getkey_float(rec, "A_1600_IMSCALE", &status); |
261 |
sprintf((tptr+i)->mpo_rec, "%s[:#%lld]", GMP_MASTER_POINTING_SERIES, rec->recnum); |
262 |
} |
263 |
else if ( (tptr+i)->wavelength == 1700) |
264 |
{ |
265 |
(tptr+i)->x=drms_getkey_float(rec, "A_1700_X0", &status); |
266 |
(tptr+i)->y=drms_getkey_float(rec, "A_1700_Y0", &status); |
267 |
(tptr+i)->instrot=drms_getkey_float(rec, "A_1700_INSTROT", &status); |
268 |
(tptr+i)->imscale=drms_getkey_float(rec, "A_1700_IMSCALE", &status); |
269 |
sprintf((tptr+i)->mpo_rec, "%s[:#%lld]", GMP_MASTER_POINTING_SERIES, rec->recnum); |
270 |
} |
271 |
else if ( (tptr+i)->wavelength == 4500) |
272 |
{ |
273 |
(tptr+i)->x=drms_getkey_float(rec, "A_4500_X0", &status); |
274 |
(tptr+i)->y=drms_getkey_float(rec, "A_4500_Y0", &status); |
275 |
(tptr+i)->instrot=drms_getkey_float(rec, "A_4500_INSTROT", &status); |
276 |
(tptr+i)->imscale=drms_getkey_float(rec, "A_4500_IMSCALE", &status); |
277 |
sprintf((tptr+i)->mpo_rec, "%s[:#%lld]", GMP_MASTER_POINTING_SERIES, rec->recnum); |
278 |
} |
279 |
else |
280 |
{ |
281 |
printkerr("WARNING at %s, line %d: Setting return values to DRMS_MISSING_FLOAT " |
282 |
"because could not find wavelength value for aia. Wavelength value passed " |
283 |
"is <%d>.\n", __FILE__,__LINE__,(tptr+i)->wavelength); |
284 |
(tptr+i)->x= DRMS_MISSING_FLOAT; |
285 |
(tptr+i)->y= DRMS_MISSING_FLOAT; |
286 |
(tptr+i)->instrot=DRMS_MISSING_FLOAT; |
287 |
(tptr+i)->imscale=DRMS_MISSING_FLOAT; |
288 |
} |
289 |
}/*end else if AIA data to retrieve and set */ |
290 |
}/*for loop thru tobs values passed */ |
291 |
|
292 |
/* close drms record */ |
293 |
drms_close_records(rset, DRMS_FREE_RECORD); |
294 |
|
295 |
/*free MP_TIME structure */ |
296 |
free(time_mp); |
297 |
return(GMP_PASSED_STATUS); |
298 |
} |
299 |
|
300 |
/****************************************************************************/ |
301 |
/************* find_mp_record function *************************************/ |
302 |
/****************************************************************************/ |
303 |
int find_mp_record(TIME_MP *time_mp, int nrec, TIME tobs) |
304 |
{ |
305 |
int i; |
306 |
int index=-1; |
307 |
|
308 |
/* check if tobs time + or - range factor is between master pointing record T_START/T_STOP */ |
309 |
for(i=0; i<nrec; i++) |
310 |
{ |
311 |
if( (fabs((time_mp + i)->tstart) < fabs(tobs) ) && |
312 |
(fabs((time_mp + i)->tstop) > fabs(tobs) ) ) |
313 |
{ |
314 |
index=i; |
315 |
return index; |
316 |
} |
317 |
} |
318 |
/* never found match- return index= -1 */ |
319 |
return index; |
320 |
} |
321 |
|