00001 #ident "$Header: /home/cvsuser/cvsroot/JSOC/proj/lev0/apps/get_image_location.c,v 1.7 2011/04/08 19:51:34 carl Exp $"
00002
00003
00004
00005
00006
00007
00008
00009 #define GMP_MASTER_POINTING_SERIES "sdo.master_pointing"
00010 #define GMP_DRMS_OPEN_FAILED 1
00011 #define GMP_MAX_DSNAME_STR 100
00012 #define GMP_MAX_KEYWORD_NAME_STR 100
00013 #define GMP_MAX_QUERY_STR 200
00014 #define GMP_MAX_MPO_REC_SIZE 200
00015 #define GMP_MAX_TELESCOPE_STR 10
00016 #define GMP_MALLOC_FAILED 2
00017 #define GMP_PACKET_TIME_STR 50
00018 #define GMP_PASSED_STATUS 0
00019 #define GMP_TOBS_NOT_SORTED_FAILED 3
00020
00021
00022 typedef struct Image_Location_struct {
00023
00024
00025
00026
00027 TIME tobs;
00028
00029
00030 int camera;
00031
00032
00033 char telescope[GMP_MAX_TELESCOPE_STR];
00034
00035
00036 int wavelength;
00037
00038
00039
00040
00041 float x;
00042 float y;
00043 float instrot;
00044 float imscale;
00045 float yinrtb;
00046 float zinrtb;
00047
00048 char mpo_rec[GMP_MAX_MPO_REC_SIZE];
00049
00050 } Image_Location;
00051
00052 typedef struct TIME_MP_struct {
00053 TIME tstart;
00054 TIME tstop;
00055 } TIME_MP;
00056
00057
00058 int find_mp_record(TIME_MP *time_mp, int nrec, TIME tobs);
00059
00060
00061
00062
00063 int get_image_location(DRMS_Env_t *drms_env, int ncnt, Image_Location **ptr_imageloc)
00064 {
00065
00066
00067 DRMS_RecordSet_t *rs;
00068 DRMS_RecordSet_t *rset;
00069 DRMS_Record_t *rec;
00070
00071 Image_Location *tptr;
00072 TIME tstart_range,tend_range;
00073 TIME_MP *time_mp;
00074 char dsname[GMP_MAX_DSNAME_STR];
00075 char nquery[GMP_MAX_QUERY_STR];
00076 int i,j,idx;
00077 int nrec;
00078 int status;
00079
00080
00081 tptr= *ptr_imageloc;
00082
00083
00084 strcpy(dsname, GMP_MASTER_POINTING_SERIES);
00085
00086
00087 tstart_range= (tptr)->tobs;
00088 tend_range= (tptr+(ncnt-1))->tobs ;
00089
00090
00091 if (tstart_range > tend_range)
00092 {
00093 printkerr("ERROR at %s, line %d: Failed because TOBS list is not sorted. "
00094 "Returning error. Not setting return values.\n",__FILE__,__LINE__);
00095 return (GMP_TOBS_NOT_SORTED_FAILED);
00096 }
00097
00098
00099 sprintf(nquery,"%s[? T_START < %.0f AND T_STOP > %.0f ?]",dsname,tend_range,tstart_range);
00100
00101
00102
00103 rset = drms_open_records(drms_env, nquery, &status);
00104 if(!rset || !rset->n || status)
00105 {
00106
00107 printkerr("ERROR at %s, line %d: Failed to open master pointing series:<%s>. "
00108 "Check envirionment GMP_MASTER_POINTING_SERIES variable is set "
00109 "correctly. Or check time range in master pointing series is available.\n",
00110 __FILE__,__LINE__, dsname);
00111 return (GMP_DRMS_OPEN_FAILED);
00112 }
00113 nrec= rset->n;
00114
00115
00116 time_mp= (TIME_MP *) malloc(nrec*sizeof(TIME_MP));
00117 if(!time_mp) return (GMP_MALLOC_FAILED);
00118
00119
00120 for(i=0; i<nrec;i++)
00121 {
00122 (time_mp+i)->tstart=drms_getkey_time(rset->records[i],"T_START",&status);
00123 (time_mp+i)->tstop=drms_getkey_time(rset->records[i],"T_STOP",&status);
00124 }
00125
00126
00127 for(i=0; i < ncnt; i++)
00128 {
00129
00130 idx=find_mp_record(time_mp, nrec, (tptr+i)->tobs);
00131 if (idx == -1)
00132 {
00133 printkerr("WARNING at %s, line %d: Setting return values to DRMS_MISSING_FLOAT "
00134 "because could not find record. TOBS time passed "
00135 "is <%f>.\n", __FILE__,__LINE__,(tptr+i)->tobs);
00136 (tptr+i)->x= DRMS_MISSING_FLOAT;
00137 (tptr+i)->y= DRMS_MISSING_FLOAT;
00138 (tptr+i)->instrot=DRMS_MISSING_FLOAT;
00139 (tptr+i)->imscale=DRMS_MISSING_FLOAT;
00140 (tptr+i)->zinrtb=DRMS_MISSING_FLOAT;
00141 (tptr+i)->yinrtb=DRMS_MISSING_FLOAT;
00142 continue;
00143 }
00144
00145
00146 rec=rset->records[idx];
00147
00148
00149 (tptr+i)->zinrtb =drms_getkey_float(rec, "SC_Z_INRT_BIAS", &status);
00150 if(status == -10006)
00151 {
00152 (tptr+i)->zinrtb=DRMS_MISSING_FLOAT;
00153 printkerr("WARNING at %s, line %d: Setting zinrtb failed because of error code DRMS_ERROR_UNKNOWNKEYWORD. "
00154 "Status returned from drms_getkey_float was %d\n", __FILE__,__LINE__, status);
00155 }
00156
00157 (tptr+i)->yinrtb=drms_getkey_float(rec, "SC_Y_INRT_BIAS", &status);
00158 if(status == -10006)
00159 {
00160 (tptr+i)->yinrtb=DRMS_MISSING_FLOAT;
00161 printkerr("WARNING at %s, line %d: Setting yinrtb failed because of error code DRMS_ERROR_UNKNOWNKEYWORD. "
00162 "Status returned from drms_getkey_float was %d\n",__FILE__,__LINE__, status);
00163 }
00164
00165
00166
00167 if(!strcmp((tptr+i)->telescope, "SDO/HMI"))
00168 {
00169 if((tptr+i)->camera == 1)
00170 {
00171 (tptr+i)->x =drms_getkey_float(rec, "H_CAM1_X0", &status);
00172 (tptr+i)->y=drms_getkey_float(rec, "H_CAM1_Y0", &status);
00173 (tptr+i)->instrot=drms_getkey_float(rec, "H_CAM1_INSTROT", &status);
00174 (tptr+i)->imscale=drms_getkey_float(rec, "H_CAM1_IMSCALE", &status);
00175 sprintf((tptr+i)->mpo_rec, "%s[:#%lld]", GMP_MASTER_POINTING_SERIES, rec->recnum);
00176 }
00177 else if((tptr+i)->camera == 2)
00178 {
00179 (tptr+i)->x=drms_getkey_float(rec, "H_CAM2_X0", &status);
00180 (tptr+i)->y=drms_getkey_float(rec, "H_CAM2_Y0", &status);
00181 (tptr+i)->instrot=drms_getkey_float(rec, "H_CAM2_INSTROT", &status);
00182 (tptr+i)->imscale=drms_getkey_float(rec, "H_CAM2_IMSCALE", &status);
00183 sprintf((tptr+i)->mpo_rec, "%s[:#%lld]", GMP_MASTER_POINTING_SERIES, rec->recnum);
00184 }
00185 else
00186 {
00187 printkerr("WARNING at %s, line %d: Setting returns values set to DRMS_MISSING_FLOAT "
00188 "because could not find camera value for hmi. Camera value passed "
00189 "is <%d>.\n", __FILE__,__LINE__,(tptr+i)->camera);
00190 (tptr+i)->x= DRMS_MISSING_FLOAT;
00191 (tptr+i)->y=DRMS_MISSING_FLOAT;
00192 (tptr+i)->instrot=DRMS_MISSING_FLOAT;
00193 (tptr+i)->imscale=DRMS_MISSING_FLOAT;
00194 }
00195 }
00196 else if(!strcmp((tptr+i)->telescope, "SDO/AIA"))
00197 {
00198 if ( (tptr+i)->wavelength == 94)
00199 {
00200 (tptr+i)->x=drms_getkey_float(rec, "A_094_X0", &status);
00201 (tptr+i)->y=drms_getkey_float(rec, "A_094_Y0", &status);
00202 (tptr+i)->instrot=drms_getkey_float(rec, "A_094_INSTROT", &status);
00203 (tptr+i)->imscale=drms_getkey_float(rec, "A_094_IMSCALE", &status);
00204 sprintf((tptr+i)->mpo_rec, "%s[:#%lld]", GMP_MASTER_POINTING_SERIES, rec->recnum);
00205 }
00206 else if ( (tptr+i)->wavelength == 131)
00207 {
00208 (tptr+i)->x=drms_getkey_float(rec, "A_131_X0", &status);
00209 (tptr+i)->y=drms_getkey_float(rec, "A_131_Y0", &status);
00210 (tptr+i)->instrot=drms_getkey_float(rec, "A_131_INSTROT", &status);
00211 (tptr+i)->imscale=drms_getkey_float(rec, "A_131_IMSCALE", &status);
00212 sprintf((tptr+i)->mpo_rec, "%s[:#%lld]", GMP_MASTER_POINTING_SERIES, rec->recnum);
00213 }
00214 else if ( (tptr+i)->wavelength == 171)
00215 {
00216 (tptr+i)->x=drms_getkey_float(rec, "A_171_X0", &status);
00217 (tptr+i)->y=drms_getkey_float(rec, "A_171_Y0", &status);
00218 (tptr+i)->instrot=drms_getkey_float(rec, "A_171_INSTROT", &status);
00219 (tptr+i)->imscale=drms_getkey_float(rec, "A_171_IMSCALE", &status);
00220 sprintf((tptr+i)->mpo_rec, "%s[:#%lld]", GMP_MASTER_POINTING_SERIES, rec->recnum);
00221 }
00222
00223 else if (((tptr+i)->wavelength == 193) || ((tptr+i)->wavelength == 195))
00224 {
00225 (tptr+i)->x=drms_getkey_float(rec, "A_193_X0", &status);
00226 (tptr+i)->y=drms_getkey_float(rec, "A_193_Y0", &status);
00227 (tptr+i)->instrot=drms_getkey_float(rec, "A_193_INSTROT", &status);
00228 (tptr+i)->imscale=drms_getkey_float(rec, "A_193_IMSCALE", &status);
00229 sprintf((tptr+i)->mpo_rec, "%s[:#%lld]", GMP_MASTER_POINTING_SERIES, rec->recnum);
00230 }
00231 else if ( (tptr+i)->wavelength == 211)
00232 {
00233 (tptr+i)->x=drms_getkey_float(rec, "A_211_X0", &status);
00234 (tptr+i)->y=drms_getkey_float(rec, "A_211_Y0", &status);
00235 (tptr+i)->instrot=drms_getkey_float(rec, "A_211_INSTROT", &status);
00236 (tptr+i)->imscale=drms_getkey_float(rec, "A_211_IMSCALE", &status);
00237 sprintf((tptr+i)->mpo_rec, "%s[:#%lld]", GMP_MASTER_POINTING_SERIES, rec->recnum);
00238 }
00239 else if ( (tptr+i)->wavelength == 304)
00240 {
00241 (tptr+i)->x=drms_getkey_float(rec, "A_304_X0", &status);
00242 (tptr+i)->y=drms_getkey_float(rec, "A_304_Y0", &status);
00243 (tptr+i)->instrot=drms_getkey_float(rec, "A_304_INSTROT", &status);
00244 (tptr+i)->imscale=drms_getkey_float(rec, "A_304_IMSCALE", &status);
00245 sprintf((tptr+i)->mpo_rec, "%s[:#%lld]", GMP_MASTER_POINTING_SERIES, rec->recnum);
00246 }
00247 else if ( (tptr+i)->wavelength == 335)
00248 {
00249 (tptr+i)->x=drms_getkey_float(rec, "A_335_X0", &status);
00250 (tptr+i)->y=drms_getkey_float(rec, "A_335_Y0", &status);
00251 (tptr+i)->instrot=drms_getkey_float(rec, "A_335_INSTROT", &status);
00252 (tptr+i)->imscale=drms_getkey_float(rec, "A_335_IMSCALE", &status);
00253 sprintf((tptr+i)->mpo_rec, "%s[:#%lld]", GMP_MASTER_POINTING_SERIES, rec->recnum);
00254 }
00255 else if ( (tptr+i)->wavelength == 1600)
00256 {
00257 (tptr+i)->x=drms_getkey_float(rec, "A_1600_X0", &status);
00258 (tptr+i)->y=drms_getkey_float(rec, "A_1600_Y0", &status);
00259 (tptr+i)->instrot=drms_getkey_float(rec, "A_1600_INSTROT", &status);
00260 (tptr+i)->imscale=drms_getkey_float(rec, "A_1600_IMSCALE", &status);
00261 sprintf((tptr+i)->mpo_rec, "%s[:#%lld]", GMP_MASTER_POINTING_SERIES, rec->recnum);
00262 }
00263 else if ( (tptr+i)->wavelength == 1700)
00264 {
00265 (tptr+i)->x=drms_getkey_float(rec, "A_1700_X0", &status);
00266 (tptr+i)->y=drms_getkey_float(rec, "A_1700_Y0", &status);
00267 (tptr+i)->instrot=drms_getkey_float(rec, "A_1700_INSTROT", &status);
00268 (tptr+i)->imscale=drms_getkey_float(rec, "A_1700_IMSCALE", &status);
00269 sprintf((tptr+i)->mpo_rec, "%s[:#%lld]", GMP_MASTER_POINTING_SERIES, rec->recnum);
00270 }
00271 else if ( (tptr+i)->wavelength == 4500)
00272 {
00273 (tptr+i)->x=drms_getkey_float(rec, "A_4500_X0", &status);
00274 (tptr+i)->y=drms_getkey_float(rec, "A_4500_Y0", &status);
00275 (tptr+i)->instrot=drms_getkey_float(rec, "A_4500_INSTROT", &status);
00276 (tptr+i)->imscale=drms_getkey_float(rec, "A_4500_IMSCALE", &status);
00277 sprintf((tptr+i)->mpo_rec, "%s[:#%lld]", GMP_MASTER_POINTING_SERIES, rec->recnum);
00278 }
00279 else
00280 {
00281 printkerr("WARNING at %s, line %d: Setting return values to DRMS_MISSING_FLOAT "
00282 "because could not find wavelength value for aia. Wavelength value passed "
00283 "is <%d>.\n", __FILE__,__LINE__,(tptr+i)->wavelength);
00284 (tptr+i)->x= DRMS_MISSING_FLOAT;
00285 (tptr+i)->y= DRMS_MISSING_FLOAT;
00286 (tptr+i)->instrot=DRMS_MISSING_FLOAT;
00287 (tptr+i)->imscale=DRMS_MISSING_FLOAT;
00288 }
00289 }
00290 }
00291
00292
00293 drms_close_records(rset, DRMS_FREE_RECORD);
00294
00295
00296 free(time_mp);
00297 return(GMP_PASSED_STATUS);
00298 }
00299
00300
00301
00302
00303 int find_mp_record(TIME_MP *time_mp, int nrec, TIME tobs)
00304 {
00305 int i;
00306 int index=-1;
00307
00308
00309 for(i=0; i<nrec; i++)
00310 {
00311 if( (fabs((time_mp + i)->tstart) < fabs(tobs) ) &&
00312 (fabs((time_mp + i)->tstop) > fabs(tobs) ) )
00313 {
00314 index=i;
00315 return index;
00316 }
00317 }
00318
00319 return index;
00320 }
00321