00001 #include <drms_keyword.h>
00002 #include "packets.h"
00003 #include "printk.h"
00004
00005 extern int INVALtime;
00006
00007
00008
00009 static int HK_getkey_int(HK_Keyword_t *isp, char *key)
00010 {
00011 while (isp)
00012 {
00013 if (strcmp(key,isp->fitsname)==0)
00014 return((int)isp->raw_value);
00015 isp = isp->next;
00016 }
00017 return(DRMS_MISSING_INT);
00018 }
00019
00020 static TIME SDO_to_DRMS_time(int sdo_s, int sdo_ss)
00021 {
00022 static int firstcall = 1;
00023 static TIME sdo_epoch;
00024 if (firstcall)
00025 {
00026 firstcall = 0;
00027 sdo_epoch = sscan_time("1958.01.01_00:00:00_TAI");
00028 }
00029 return(sdo_epoch + (TIME)sdo_s + (TIME)(sdo_ss & 0xFFFF)/65536.0);
00030 }
00031
00032 static void sprint_time_ISO (char *tstring, TIME t)
00033 {
00034 sprint_time(tstring,t,"UTC",0);
00035 tstring[4] = tstring[7] = '-';
00036 tstring[10] = 'T';
00037 tstring[19] = '\0';
00038 }
00039
00040 void HMI_compute_exposure_times(DRMS_Record_t *rec, HK_Keyword_t *isp, int flg)
00041 {
00042 static char date_obs[100];
00043 TIME t_obs,MJD_epoch = -3727641600.000;
00044 double exptime=0.0, expdev=0.0, expoff=0.0;
00045 double she[6];
00046 float int_time;
00047 int frmtyp;
00048 int i, iimgots, iimgotss, iris_camera[3] = {1, 2, 2}, status;
00049 int ifuvot[6], inuvot[5], isjiot[5], ifuvct[6], inuvct[5], isjict[5];
00050 char *iris_instru[] = { "FUV", "NUV", "SJI" };
00051 char *fuvotkw[] = { "IFUVAOT", "IFUVBOT", "IFUVCOT", "IFUVDOT", "IFUVEOT",
00052 "IFUVFOT" };
00053 char *nuvotkw[] = { "INUVAOT", "INUVBOT", "INUVCOT", "INUVDOT", "INUVEOT" };
00054 char *sjiotkw[] = { "ISJIAOT", "ISJIBOT", "ISJICOT", "ISJIDOT", "ISJIEOT" };
00055 char *fuvctkw[] = { "IFUVACT", "IFUVBCT", "IFUVCCT", "IFUVDCT", "IFUVECT",
00056 "IFUVFCT" };
00057 char *nuvctkw[] = { "INUVACT", "INUVBCT", "INUVCCT", "INUVDCT", "INUVECT" };
00058 char *sjictkw[] = { "ISJIACT", "ISJIBCT", "ISJICCT", "ISJIDCT", "ISJIECT" };
00059
00060 int isqisysn = HK_getkey_int(isp, "ISQISYSN");
00061 int iimgcfd1 = HK_getkey_int(isp, "IIMGCFD1");
00062 int iimgcfd2 = HK_getkey_int(isp, "IIMGCFD2");
00063 int iimgcfd3 = HK_getkey_int(isp, "IIMGCFD3");
00064 int iimgcfd4 = HK_getkey_int(isp, "IIMGCFD4");
00065 int iimgshce = HK_getkey_int(isp, "IIMGSHCE");
00066
00067
00068
00069 int use_pktim;
00070
00071 for (i=0; i<6; i++) {
00072 ifuvot[i] = HK_getkey_int(isp, fuvotkw[i]);
00073 ifuvct[i] = HK_getkey_int(isp, fuvctkw[i]);
00074 if(i<5) {
00075 inuvot[i] = HK_getkey_int(isp, nuvotkw[i]);
00076 inuvct[i] = HK_getkey_int(isp, nuvctkw[i]);
00077 isjiot[i] = HK_getkey_int(isp, sjiotkw[i]);
00078 isjict[i] = HK_getkey_int(isp, sjictkw[i]);
00079 }
00080 }
00081
00082 switch (isqisysn) {
00083 case 0:
00084 if (ifuvot[0] < ifuvot[1]) {
00085 while (ifuvct[0] < ifuvct[2]) ifuvct[0] += 16777216;
00086 ifuvct[0] -= 16777216;
00087 while (ifuvct[1] < ifuvct[0]) ifuvct[1] += 16777216;
00088 while (ifuvct[3] < ifuvct[2]) ifuvct[3] += 16777216;
00089 while (ifuvct[4] < ifuvct[2]) ifuvct[4] += 16777216;
00090 while (ifuvct[5] < ifuvct[2]) ifuvct[5] += 16777216;
00091 } else {
00092 ifuvct[5] += 16777216;
00093 while (ifuvct[5] < ifuvct[2]) ifuvct[5] += 16777216;
00094 ifuvct[5] -= 16777216;
00095 while (ifuvct[4] < ifuvct[5]) ifuvct[4] += 16777216;
00096 while (ifuvct[3] < ifuvct[4]) ifuvct[3] += 16777216;
00097 while (ifuvct[1] < ifuvct[2]) ifuvct[1] += 16777216;
00098 while (ifuvct[0] < ifuvct[2]) ifuvct[0] += 16777216;
00099 }
00100 for (i=0; i<6; i++) {
00101 expoff += (ifuvct[i] + ifuvot[i])*4.0e-6/6.0;
00102 she[i] = (ifuvct[i] - ifuvot[i])*4.0e-6;
00103 exptime += she[i];
00104 expdev += she[i]*she[i];
00105 }
00106 exptime /= 6.0;
00107 expdev = sqrt(expdev/6.0 - exptime*exptime);
00108 iimgots = HK_getkey_int(isp, "IIMGOTS1");
00109 iimgotss = HK_getkey_int(isp, "IMGOTSS1");
00110 break;
00111 case 1:
00112 if (inuvot[0] < inuvot[1]) {
00113 while (inuvct[0] < inuvct[2]) inuvct[0] += 65536;
00114 inuvct[0] -= 65536;
00115 while (inuvct[1] < inuvct[0]) inuvct[1] += 65536;
00116 while (inuvct[3] < inuvct[2]) inuvct[3] += 65536;
00117 while (inuvct[4] < inuvct[2]) inuvct[4] += 65536;
00118 } else {
00119 inuvct[4] += 65536;
00120 while (inuvct[4] < inuvct[2]) inuvct[4] += 65536;
00121 inuvct[4] -= 65536;
00122 while (inuvct[3] < inuvct[4]) inuvct[3] += 65536;
00123 while (inuvct[1] < inuvct[2]) inuvct[1] += 65536;
00124 while (inuvct[0] < inuvct[2]) inuvct[0] += 65536;
00125 }
00126 for (i=0; i<5; i++) {
00127 expoff += (inuvct[i] + inuvot[i])*4.0e-6/5.0;
00128 she[i] = (inuvct[i] - inuvot[i])*4.0e-6;
00129 exptime += she[i];
00130 expdev += she[i]*she[i];
00131 }
00132 exptime /= 5.0;
00133 expdev = sqrt(expdev/5.0 - exptime*exptime);
00134 iimgots = HK_getkey_int(isp, "IIMGOTS2");
00135 iimgotss = HK_getkey_int(isp, "IMGOTSS2");
00136 break;
00137 case 2:
00138 if (isjiot[0] < isjiot[1]) {
00139 while (isjict[0] < isjict[2]) isjict[0] += 65536;
00140 isjict[0] -= 65536;
00141 while (isjict[1] < isjict[0]) isjict[1] += 65536;
00142 while (isjict[3] < isjict[2]) isjict[3] += 65536;
00143 while (isjict[4] < isjict[2]) isjict[4] += 65536;
00144 } else {
00145 isjict[4] += 65536;
00146 while (isjict[4] < isjict[2]) isjict[4] += 65536;
00147 isjict[4] -= 65536;
00148 while (isjict[3] < isjict[4]) isjict[3] += 65536;
00149 while (isjict[1] < isjict[2]) isjict[1] += 65536;
00150 while (isjict[0] < isjict[2]) isjict[0] += 65536;
00151 }
00152 for (i=0; i<5; i++) {
00153 expoff += (isjict[i] + isjiot[i])*4.0e-6/5.0;
00154 she[i] = (isjict[i] - isjiot[i])*4.0e-6;
00155 exptime += she[i];
00156 expdev += she[i]*she[i];
00157 }
00158 exptime /= 5.0;
00159 expdev = sqrt(expdev/5.0 - exptime*exptime);
00160 iimgots = HK_getkey_int(isp, "IIMGOTS3");
00161 iimgotss = HK_getkey_int(isp, "IMGOTSS3");
00162 break;
00163 }
00164 if((iimgots == 0) && (iimgshce != 0)) INVALtime = 1;
00165 else INVALtime = 0;
00166
00167
00168
00169
00170
00171
00172 use_pktim = 0;
00173 frmtyp = HK_getkey_int(isp, "IIFRMTYP");
00174 switch (frmtyp) {
00175 case 0:
00176 drms_setkey_string(rec, "IMG_TYPE", "CURRENT");
00177 break;
00178 case 1:
00179 drms_setkey_string(rec, "IMG_TYPE", "LIGHT");
00180 break;
00181 case 2:
00182 drms_setkey_string(rec, "IMG_TYPE", "DARK");
00183 use_pktim = 1;
00184 break;
00185 case 3:
00186 drms_setkey_string(rec, "IMG_TYPE", "LED");
00187 break;
00188 case 4:
00189 drms_setkey_string(rec, "IMG_TYPE", "LTC");
00190 break;
00191 case 5:
00192 drms_setkey_string(rec, "IMG_TYPE", "SPAT");
00193 use_pktim = 1;
00194 break;
00195 case 6:
00196 drms_setkey_string(rec, "IMG_TYPE", "VPAT");
00197 use_pktim = 1;
00198 break;
00199 default:
00200 drms_setkey_string(rec, "IMG_TYPE", "UNKNOWN");
00201 break;
00202 }
00203
00204 drms_setkey_double(rec, "EXPTIME", exptime);
00205 drms_setkey_double(rec, "EXPSDEV", expdev);
00206 if ((iimgcfd1 == DRMS_MISSING_SHORT) || (iimgcfd4 == DRMS_MISSING_SHORT)) {
00207 int_time = DRMS_MISSING_FLOAT;
00208 } else {
00209 int_time = (iimgcfd4 - iimgcfd1)*0.0078125;
00210 }
00211 drms_setkey_float(rec, "INT_TIME", int_time);
00212 drms_setkey_string(rec, "INSTRUME", iris_instru[isqisysn]);
00213
00214
00215 if(use_pktim) {
00216 iimgots = HK_getkey_int(isp, "ITCS56");
00217 iimgotss = HK_getkey_int(isp, "ITCSS56");
00218 iimgotss = iimgotss >> 16;
00219 }
00220
00221 t_obs = SDO_to_DRMS_time(iimgots, iimgotss) - exptime/2.0;
00222 drms_setkey_double(rec, "T_OBS", t_obs);
00223
00224 TIME date__obs = t_obs - exptime/2.0;
00225 drms_setkey_double(rec, "DATE__OBS", date__obs);
00226 drms_setkey_int(rec, "CAMERA", iris_camera[isqisysn]);
00227 int aecmode = HK_getkey_int(isp, "AECMODE");
00228
00229
00230 int iicrsid = HK_getkey_int(isp, "IICRSID");
00231 int ifwpos = HK_getkey_int(isp, "IFWPOS");
00232
00233
00234
00235
00236 printk("iicrsid = %d\n", iicrsid);
00237 printk("ifwpos = %d\n", ifwpos);
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249 switch (isqisysn) {
00250 case 0:
00251
00252 drms_setkey_string(rec, "IMG_PATH", "FUV");
00253 break;
00254 case 1:
00255
00256 if (iicrsid < 4) drms_setkey_string(rec, "IMG_PATH", "NUV-SJI");
00257 else drms_setkey_string(rec, "IMG_PATH", "NUV");
00258 break;
00259 case 2:
00260
00261 if (iicrsid < 4) { drms_setkey_string(rec, "IMG_PATH", "NUV-SJI"); }
00262 else {
00263 switch (ifwpos) {
00264 case 1:
00265 case 2:
00266 drms_setkey_string(rec, "IMG_PATH", "SJI_5000W");
00267 break;
00268 case 31:
00269 case 32:
00270 drms_setkey_string(rec, "IMG_PATH", "SJI_1330");
00271 break;
00272 case 61:
00273 case 62:
00274 drms_setkey_string(rec, "IMG_PATH", "SJI_2796");
00275 break;
00276 case 91:
00277 case 92:
00278 drms_setkey_string(rec, "IMG_PATH", "SJI_1400");
00279 break;
00280 case 121:
00281 case 122:
00282 drms_setkey_string(rec, "IMG_PATH", "SJI_2832");
00283 break;
00284 case 151:
00285 case 152:
00286 drms_setkey_string(rec, "IMG_PATH", "SJI_1600W");
00287 break;
00288 default:
00289 drms_setkey_string(rec, "IMG_PATH", "SJI_UNKNOWN");
00290 break;
00291 }
00292 }
00293 break;
00294 }
00295 }