ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/JSOC/proj/util/apps/aia_fixCROTA2.c
Revision: 1.1
Committed: Sat Sep 29 20:28:31 2012 UTC (10 years, 11 months ago) by jps
Content type: text/plain
Branch: MAIN
CVS Tags: Ver_8-8, Ver_8-11, Ver_8-2, Ver_8-10, Ver_8-0, Ver_8-1, Ver_8-6, Ver_LATEST, Ver_8-4, Ver_9-41, Ver_8-3, Ver_8-5, Ver_8-12, Ver_8-7, Ver_9-5, Ver_9-4, Ver_9-3, Ver_9-2, Ver_9-1, Ver_9-0, HEAD
Log Message:
Module to update CROTA2, EPERDN, and related keywords for aia.lev1

File Contents

# Content
1 #include "jsoc.h"
2 #include "jsoc_main.h"
3
4 char *module_name = "aia_fixCROTA2";
5
6 /*
7 * This program updates CROTA2 based on results of the 2012 transit of Venus.
8 * CROTA2 is corrected by adding CCDx_DELTA
9 * If INST_ROT is present it will be updated.
10 * DATE is updated.
11 * A HISTORY line is added.
12 *
13 * call with aia_fixCROTA2 ds=<recordset_query>
14 *
15 */
16
17 #define DIE(msg) {fflush(stdout);fprintf(stderr,"%s, status=%d\n",msg,status); return(status);}
18
19 #define NOTSPECIFIED "Not Specified"
20 #define MP_SERIES "sdo.master_pointing"
21 #define GMP_MAX_MPO_REC_SIZE 200
22
23 ModuleArgs_t module_args[] =
24 {
25 {ARG_STRING, "ds", NOTSPECIFIED, "data series to process."},
26 {ARG_END}
27 };
28
29 static char mp_query[512], respq[512];
30
31 int DoIt(void)
32 {
33 int status = DRMS_SUCCESS;
34 DRMS_Record_t *rmp, *rresp;
35 DRMS_RecordSet_t *inRS, *outRS, *rsmp=NULL, *rs_resp=NULL;;
36 int irec, nrecs, nresp;
37 const char *dsSeries = params_get_str(&cmdparams, "ds");
38 TIME t_obs, mpt_end=0.0;
39
40 inRS = drms_open_records(drms_env, dsSeries, &status);
41 nrecs = inRS->n;
42 if (status || nrecs == 0)
43 {
44 fprintf(stdout, " status=%d, no records found, skip this block\n",status);
45 fflush(stdout);
46 return (DRMS_SUCCESS);
47 }
48
49 outRS = drms_clone_records_nosums(inRS, DRMS_PERMANENT, DRMS_SHARE_SEGMENTS, &status);
50 nrecs = outRS->n;
51 if (status || nrecs == 0)
52 DIE("No records cloned");
53 drms_close_records(inRS, DRMS_FREE_RECORD);
54
55 for (irec=0; irec<nrecs; irec++)
56 {
57 DRMS_Record_t *rec = outRS->records[irec];
58 float arot[10], ascl[10];
59 float crota2, sat_rot;
60 int i, quality, instrot_status, wl;
61 char mpo_rec[GMP_MAX_MPO_REC_SIZE];
62 char *rotkeys[] = { "A_094_INSTROT", "A_131_INSTROT", "A_171_INSTROT",
63 "A_193_INSTROT", "A_211_INSTROT", "A_304_INSTROT", "A_335_INSTROT",
64 "A_1600_INSTROT", "A_1700_INSTROT", "A_4500_INSTROT"};
65 char *sclkeys[] = { "A_094_IMSCALE", "A_131_IMSCALE", "A_171_IMSCALE",
66 "A_193_IMSCALE", "A_211_IMSCALE", "A_304_IMSCALE", "A_335_IMSCALE",
67 "A_1600_IMSCALE", "A_1700_IMSCALE", "A_4500_IMSCALE"};
68 char *dsresp = "aia.response";
69 char *wavstr = drms_getkey_string(rec, "WAVE_STR", &status);
70
71 quality = drms_getkey_int(rec, "QUALITY", &status);
72 if (!status && quality < 0)
73 continue;
74
75 t_obs = drms_getkey_time(rec, "T_OBS", &status);
76 sat_rot = drms_getkey_float(rec, "SAT_ROT", NULL);
77 if (drms_ismissing_float(sat_rot)) sat_rot = 0.0;
78 wl = drms_getkey_int(rec, "WAVELNTH", NULL);
79
80 // The action is all between here and the end of the irec loop
81 if (t_obs > mpt_end) {
82 int iw, nrmp;
83 sprintf(mp_query, "%s[? T_START <= %f and %f < T_STOP ?]",
84 MP_SERIES, t_obs, t_obs);
85 rsmp = drms_open_records(drms_env, mp_query, &status);
86 nrmp = rsmp->n;
87 if (status || nrmp != 1) DIE("No Master Pointing Record");
88 rmp = rsmp->records[0];
89 sprintf(mpo_rec, "%s[:#%lld]", MP_SERIES, rmp->recnum);
90 mpt_end = drms_getkey_time(rmp, "T_STOP", &status);
91 if (status) DIE("No T_STOP for Master Pointing Record");
92 for (iw=0; iw<10; iw++) {
93 arot[iw] = drms_getkey_float(rmp, rotkeys[iw], &instrot_status);
94 if (instrot_status) DIE("Value for inst rotation not found");
95 ascl[iw] = drms_getkey_float(rmp, sclkeys[iw], &status);
96 if (status) DIE("Value for inst scale not found");
97 }
98 drms_close_records(rsmp, DRMS_FREE_RECORD);
99 }
100 switch (wl) {
101 case 94: i = 0; break;
102 case 131: i = 1; break;
103 case 171: i = 2; break;
104 case 193: i = 4; break;
105 case 211: i = 4; break;
106 case 304: i = 5; break;
107 case 335: i = 6; break;
108 case 1600: i = 7; break;
109 case 1700: i = 8; break;
110 case 4500: i = 9; break;
111 default: DIE("Bad wavelength in AIA level 1 record");
112 }
113 drms_setkey_float(rec, "INST_ROT", arot[i]);
114 drms_setkey_float(rec, "CDELT1", ascl[i]);
115 drms_setkey_float(rec, "CDELT2", ascl[i]);
116 drms_setkey_float(rec, "IMSCL_MP", ascl[i]);
117 crota2 = sat_rot + arot[i];
118 drms_setkey_float(rec, "CROTA2", crota2);
119 drms_setkey_time(rec, "DATE", CURRENT_SYSTEM_TIME);
120 drms_setkey_string(rec, "MPO_REC", mpo_rec);
121 sprintf(respq, "%s[][%s][? t_start <= %10.5f and t_stop > %10.5f ?]",
122 dsresp, wavstr, t_obs, t_obs);
123 rresp = NULL;
124 rs_resp = drms_open_records(drms_env, respq, &status);
125 if (status) { DIE("Can not open aia.response series.\n");
126 } else {
127 nresp = rs_resp->n;
128 if (nresp>0) rresp = rs_resp->records[0];
129 }
130 if(rresp) {
131 float eperdn = drms_getkey_float(rresp, "EPERDN", &status);
132 drms_setkey_float(rec, "DN_GAIN", eperdn);
133 float dnperpht = drms_getkey_float(rresp, "DNPERPHT", &status);
134 drms_setkey_float(rec, "DNPERPHT", dnperpht);
135 float eff_wl = drms_getkey_float(rresp, "EFF_WVLN", &status);
136 drms_setkey_float(rec, "EFF_WVLN", eff_wl);
137 float p1 = drms_getkey_float(rresp, "EFFA_P1", &status);
138 float p2 = drms_getkey_float(rresp, "EFFA_P2", &status);
139 float p3 = drms_getkey_float(rresp, "EFFA_P3", &status);
140 TIME t_start = drms_getkey_float(rresp, "T_START", &status);
141 float dt = (float) (t_obs - t_start)/86400.0;
142 float factor = ((p3*dt + p2)*dt + p1)*dt + 1.0;
143 float eff_area = drms_getkey_float(rresp, "EFF_AREA", &status);
144 eff_area = eff_area*factor;
145 drms_setkey_float(rec, "EFF_AREA", eff_area);
146 int ver_num = drms_getkey_int(rresp, "VER_NUM", &status);
147 drms_setkey_int(rec, "DN_GN_V", ver_num);
148 drms_setkey_int(rec, "EFF_AR_V", ver_num);
149 }
150 } //end of "irec" loop
151 if (drms_close_records(outRS, DRMS_INSERT_RECORD))
152 fprintf(stderr, "drms_close_records failure for %s\n", dsSeries);
153
154 fprintf(stdout, "%s CROTA2 fixed\n", dsSeries);
155 fflush(stdout);
156
157 return (DRMS_SUCCESS);
158 } // end of DoIt