00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <drms_keyword.h>
00016 #include "packets.h"
00017 #include "printk.h"
00018
00019 extern int INVALtime;
00020
00021 static int HK_getkey_int(HK_Keyword_t *isp, char *key)
00022 {
00023 while (isp)
00024 {
00025 if (strcmp(key,isp->fitsname)==0)
00026 return((int)isp->raw_value);
00027 isp = isp->next;
00028 }
00029 return(DRMS_MISSING_INT);
00030 }
00031
00032 static TIME SDO_to_DRMS_time(int sdo_s, int sdo_ss)
00033 {
00034 static int firstcall = 1;
00035 static TIME sdo_epoch;
00036 if (firstcall)
00037 {
00038 firstcall = 0;
00039 sdo_epoch = sscan_time("1958.01.01_00:00:00_TAI");
00040 }
00041
00042 return(sdo_epoch + (TIME)sdo_s + (TIME)(sdo_ss & 0xFFFF)/65536.0);
00043 }
00044
00045 static void sprint_time_ISO (char *tstring, TIME t)
00046 {
00047 sprint_time(tstring,t,"UTC",0);
00048 tstring[4] = tstring[7] = '-';
00049 tstring[10] = 'T';
00050 tstring[19] = '\0';
00051 }
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 static int nrollct(int cmdt, int clt)
00067 {
00068 if (cmdt < 50332) return 0;
00069 int nr = (cmdt - 16777)/67109;
00070 int rem = cmdt%67109;
00071 if ((rem < 16777) || (rem > 50332)) return nr + (clt > 0x800000 ? 0 : 1);
00072 return nr;
00073 }
00074
00075 void HMI_compute_exposure_times(DRMS_Record_t *rec, HK_Keyword_t *isp, int flg)
00076 {
00077 static int waveltab[10] = { 335, 131, 211, 193, 1600, 1700, 4500, 171, 304, 94 };
00078
00079 static char date_obs[100];
00080
00081 TIME t_obs,MJD_epoch = -3727641600.000;
00082 double exptime, expsdev;
00083 float int_time;
00084
00085 if (flg) {
00086 char *aia_instru[] = { "AIA_1", "AIA_2", "AIA_3", "AIA_4" };
00087 int aimgshce = HK_getkey_int(isp, "AIMGSHCE");
00088 int aimgots = HK_getkey_int(isp, "AIMGOTS");
00089 if((aimgots == 0) && (aimgshce != 0)) INVALtime = 1;
00090 else INVALtime = 0;
00091 int aimgotss = HK_getkey_int(isp, "AIMGOTSS");
00092 int aimshcbc = HK_getkey_int(isp, "AIMSHCBC");
00093 aimshcbc += 0x1000000*nrollct(aimgshce, aimshcbc);
00094 int aimshcbe = HK_getkey_int(isp, "AIMSHCBE");
00095 aimshcbe += 0x1000000*nrollct(aimgshce, aimshcbe);
00096 int aimshctc = HK_getkey_int(isp, "AIMSHCTC");
00097 aimshctc += 0x1000000*nrollct(aimgshce, aimshctc);
00098 int aimshcte = HK_getkey_int(isp, "AIMSHCTE");
00099 aimshcte += 0x1000000*nrollct(aimgshce, aimshcte);
00100 int aimshobc = HK_getkey_int(isp, "AIMSHOBC");
00101 int aimshobe = HK_getkey_int(isp, "AIMSHOBE");
00102 int aimshotc = HK_getkey_int(isp, "AIMSHOTC");
00103 int aimshote = HK_getkey_int(isp, "AIMSHOTE");
00104 int aicfgdl3 = HK_getkey_int(isp, "AICFGDL3");
00105 int aicfgdl4 = HK_getkey_int(isp, "AICFGDL4");
00106 int aiagp9 = HK_getkey_int(isp, "AIAGP9");
00107 int aiagp10 = HK_getkey_int(isp, "AIAGP10");
00108
00109 if ((aicfgdl3 == DRMS_MISSING_SHORT) || (aicfgdl4 == DRMS_MISSING_SHORT)) {
00110 int_time = DRMS_MISSING_FLOAT;
00111 } else if (aiagp9 && aiagp10) {
00112 int_time = (float)(aiagp10 - aiagp9)/128.0;
00113 } else {
00114 int nroll = 256*(int)((aimgshce + 273)/2000);
00115 int_time = ((float)(aicfgdl4 - aicfgdl3 + nroll)*1000.0)/128.0;
00116 if((int)int_time < aimgshce) int_time = int_time + 2000.0;
00117 int_time = int_time/1000.0;
00118 }
00119 drms_setkey_float(rec, "INT_TIME", int_time);
00120
00121 double shebc = (aimshcbc - aimshobc)*4.0e-6;
00122 double shebe = (aimshcbe - aimshobe)*4.0e-6;
00123 double shetc = (aimshctc - aimshotc)*4.0e-6;
00124 double shete = (aimshcte - aimshote)*4.0e-6;
00125 double offset = ( aimshobc + aimshcbc + aimshobe + aimshcbe +
00126 aimshotc + aimshctc + aimshote + aimshcte )/8.0e6;
00127 if(aimgshce == 0) {
00128 drms_setkey_string(rec, "IMG_TYPE", "DARK");
00129 int axsec = HK_getkey_int(isp, "ATCSISP");
00130 int axssec = HK_getkey_int(isp, "ATCSSISP");
00131 if((axsec == DRMS_MISSING_INT) || (axssec == DRMS_MISSING_INT)) {
00132 axsec = HK_getkey_int(isp, "ATCS211");
00133 axssec = HK_getkey_int(isp, "ATCSS211");
00134 }
00135 if((axsec == DRMS_MISSING_INT) || (axssec == DRMS_MISSING_INT)) {
00136 axsec = HK_getkey_int(isp, "ATCS239");
00137 axssec = HK_getkey_int(isp, "ATCSS239");
00138 }
00139 if((axsec != DRMS_MISSING_INT) && (axssec != DRMS_MISSING_INT)) {
00140 axssec = axssec >> 16;
00141 t_obs = SDO_to_DRMS_time(axsec, axssec);
00142 }
00143 }
00144 else {
00145 drms_setkey_string(rec, "IMG_TYPE", "LIGHT");
00146 t_obs = SDO_to_DRMS_time(aimgots, aimgotss) + offset;
00147 }
00148 exptime = (shebc + shebe + shetc + shete)/4.0;
00149 if (aimgshce < 73) exptime = exptime*7.0/20.0;
00150 expsdev = sqrt((shebc*shebc + shebe*shebe + shetc*shetc +
00151 shete*shete)/4.0 - exptime*exptime);
00152 int asqhdr = HK_getkey_int(isp, "ASQHDR");
00153 if (DRMS_MISSING_INT == asqhdr) asqhdr = HK_getkey_int(isp, "A827A");
00154 int ahtelid = (asqhdr >> 30) & 0x3;
00155 int ahtlfsn = asqhdr & 0x3FFFFFF;
00156 int asqtnum = HK_getkey_int(isp, "ASQTNUM");
00157 drms_setkey_string(rec, "INSTRUME", aia_instru[ahtelid]);
00158
00159
00160 int wavel = HK_getkey_int(isp, "AIAWVLEN");
00161 if (wavel == DRMS_MISSING_INT) wavel = HK_getkey_int(isp, "A856C");
00162 if (wavel != DRMS_MISSING_INT) {
00163 if (wavel < 10) drms_setkey_int(rec, "WAVELNTH", waveltab[wavel]);
00164 else drms_setkey_int(rec, "WAVELNTH", DRMS_MISSING_INT);
00165 }
00166
00167 int aecmode = HK_getkey_int(isp, "AECMODE");
00168 if (aecmode == DRMS_MISSING_INT) aecmode = HK_getkey_int(isp, "A8328");
00169 if (aecmode == DRMS_MISSING_INT) aecmode = HK_getkey_int(isp, "A8215-00");
00170 if (aecmode != DRMS_MISSING_INT) {
00171 if (aecmode) drms_setkey_string(rec, "A8215_00", "On");
00172 else drms_setkey_string(rec, "A8215_00", "Off");
00173 }
00174 } else {
00175 int hshiexp = HK_getkey_int(isp, "HSHIEXP");
00176 int hobitsec = HK_getkey_int(isp, "HOBITSEC");
00177 if((hobitsec == 0) && (hshiexp != 0)) INVALtime = 1;
00178 else INVALtime = 0;
00179 int hobitss = HK_getkey_int(isp, "HOBITSS");
00180 int hshmiclb = HK_getkey_int(isp, "HSHMICLB");
00181 int hshmiclm = HK_getkey_int(isp, "HSHMICLM");
00182 int hshmiclt = HK_getkey_int(isp, "HSHMICLT");
00183 int hshmiopb = HK_getkey_int(isp, "HSHMIOPB");
00184 int hshmiopm = HK_getkey_int(isp, "HSHMIOPM");
00185 int hshmiopt = HK_getkey_int(isp, "HSHMIOPT");
00186 double sheb = (hshmiclb - hshmiopb)*1.0e-6;
00187 double shem = (hshmiclm - hshmiopm)*1.0e-6;
00188 double shet = (hshmiclt - hshmiopt)*1.0e-6;
00189 double offset = ( hshmiclb + hshmiopb + hshmiclm + hshmiopm + hshmiclt + hshmiopt )/6.0e6;
00190
00191 if(hshiexp == 0) {
00192 drms_setkey_string(rec, "IMG_TYPE", "DARK");
00193 int hxsec = HK_getkey_int(isp, "HTCSISP");
00194 int hxssec = HK_getkey_int(isp, "HTCSSISP");
00195 if((hxsec == DRMS_MISSING_INT) || (hxssec == DRMS_MISSING_INT)) {
00196 hxsec = HK_getkey_int(isp, "HTCS1BD");
00197 hxssec = HK_getkey_int(isp, "HTCSS1BD");
00198 }
00199 if((hxsec == DRMS_MISSING_INT) || (hxssec == DRMS_MISSING_INT)) {
00200 hxsec = HK_getkey_int(isp, "HTCS1DB");
00201 hxssec = HK_getkey_int(isp, "HTCSS1DB");
00202 }
00203 if((hxsec != DRMS_MISSING_INT) && (hxssec != DRMS_MISSING_INT)) {
00204 hxssec = hxssec >> 16;
00205 hxsec = hxsec + 1;
00206 t_obs = SDO_to_DRMS_time(hxsec, hxssec);
00207 }
00208 }
00209 else {
00210 drms_setkey_string(rec, "IMG_TYPE", "LIGHT");
00211 t_obs = SDO_to_DRMS_time(hobitsec,hobitss) + offset;
00212 }
00213 exptime = (sheb + shem + shet)/3.0;
00214 expsdev = sqrt((sheb*sheb + shem*shem + shet*shet)/3.0 - exptime*exptime);
00215
00216 int camid = HK_getkey_int(isp, "HCAMID");
00217 camid = camid & 0x01;
00218 camid++;
00219 drms_setkey_int(rec, "CAMERA", camid);
00220 if(camid == 1) drms_setkey_string(rec, "INSTRUME", "HMI_SIDE1");
00221 else drms_setkey_string(rec, "INSTRUME", "HMI_FRONT2");
00222 }
00223
00224
00225 TIME date__obs = t_obs - exptime/2.0;
00226 TIME mjd = date__obs - MJD_epoch;
00227 double mjd_day = floor(mjd / 86400.0);
00228 double mjd_time = mjd - 86400.0 * mjd_day;
00229
00230
00231
00232 drms_setkey_double(rec, "T_OBS", t_obs);
00233 drms_setkey_double(rec, "EXPTIME", exptime);
00234 drms_setkey_float(rec, "EXPSDEV", expsdev);
00235
00236 drms_setkey_double(rec, "DATE__OBS", date__obs);
00237 drms_setkey_double(rec, "MJD", mjd_day);
00238 drms_setkey_double(rec, "TIME", mjd_time);
00239
00240
00241
00242 }
00243