ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/JSOC/proj/flatfield/apps/write_dark.c
Revision: 1.1
Committed: Tue Jun 8 00:08:07 2010 UTC (13 years, 3 months ago) by richard
Content type: text/plain
Branch: MAIN
CVS Tags: Ver_6-0, Ver_6-1, Ver_6-2, Ver_6-3, Ver_6-4, Ver_9-1, Ver_5-14, Ver_5-13, Ver_5-12, Ver_5-11, Ver_5-10, Ver_LATEST, Ver_9-3, Ver_9-41, Ver_9-2, Ver_8-8, Ver_8-2, Ver_8-3, Ver_8-0, Ver_8-1, Ver_8-6, Ver_8-7, Ver_8-4, Ver_8-5, Ver_7-1, Ver_7-0, Ver_9-5, Ver_9-4, Ver_8-10, Ver_8-11, Ver_8-12, Ver_9-0, HEAD
Log Message:
module: write dark
Writes records of dark images for AIA or HMI
Example:

write_dark_test instrument="HMI"\
file_dark="/scr20/richard/hmi/dark_side_4555561.bin"\
series_dark="su_production.dark" camera=1\
t_obs="2010.04.29_17:28:43.00_UTC"\
fsn_list_dark=4555562,4555582,4555602,4555622,4555642\
nx=4096 ny=4096

File Contents

# Content
1
2 // write out flatfields
3
4
5 #include <stdlib.h>
6 #include <stdio.h>
7 #include <math.h>
8 #include <jsoc_main.h>
9 #include <string.h>
10 #include <time.h>
11
12
13
14 char *module_name = "write_dark"; //name of the module
15
16 //arguments of the module
17 ModuleArgs_t module_args[] =
18 {
19 {ARG_STRING, "instrument"}, //HMI or AIA
20 {ARG_STRING, "series_dark", ""}, //series name dark
21 {ARG_STRING, "file_dark"}, //file name of dark image (binary file of floats)
22 {ARG_INT, "camera", "0"}, //camera for HMI (1 or 2)
23 {ARG_STRING, "wave_str", "dd"}, //wave string for AIA
24 {ARG_TIME, "t_obs"}, //T_OBS
25 {ARG_INTS, "fsn_list_dark", "-1,-1"}, //comma separated list of FSNs
26 {ARG_INT, "nx", "4096"}, //x dim of image
27 {ARG_INT, "ny", "4096"}, //y dim of image
28 {ARG_END}
29 };
30
31
32
33 /////////////////////////////////////////////////////////////////////////////////
34
35
36
37 /*-------------------------------------------------------------*/
38 /* */
39 /* DoIt is the entry point of the module */
40 /* the name MUST be DoIt for a DRMS module */
41 /* */
42 /*-------------------------------------------------------------*/
43
44 int DoIt(void)
45 {
46
47 int i,j,k;
48 int status = DRMS_SUCCESS;
49
50 const char *input_dark;
51 input_dark = cmdparams_get_str(&cmdparams, "file_dark", NULL);
52
53 const char *instrument;
54 instrument=cmdparams_get_str(&cmdparams, "instrument", &status);
55
56 if (strcmp(instrument,"HMI") != 0 && strcmp(instrument,"AIA") != 0){printf("Instrument invalid\n"); exit(EXIT_FAILURE);}
57
58 int inst_hmi=!strcmp(instrument,"HMI");
59 int inst_aia=!strcmp(instrument,"AIA");
60
61
62
63 const char *wavelength;
64 int vvd=0, vvv=-1;
65 short aia_cam[23]={1,1,1,1,1,1,2,2,2,2,2,2,3,3,3,3,3,4,4,4,4,4,4};
66
67 if (inst_aia)
68 {
69 wavelength=cmdparams_get_str(&cmdparams, "wave_str", &status);
70 char **wavestrs=(char **)(malloc(23*sizeof(char *)));
71
72
73 wavestrs[0]="131_THIN";
74 wavestrs[1]="131_THICK";
75 wavestrs[2]="131_OPEN";
76 wavestrs[3]="335_THIN";
77 {char *wv="335_THICK"; wavestrs[4]=wv;}
78 {char *wv="335_OPEN"; wavestrs[5]=wv;}
79 {char *wv="193_THIN"; wavestrs[6]=wv;}
80 {char *wv="193_THICK"; wavestrs[7]=wv;}
81 {char *wv="193_OPEN"; wavestrs[8]=wv;}
82 {char *wv="211_THIN"; wavestrs[9]=wv;}
83 {char *wv="211_THICK"; wavestrs[10]=wv;}
84 {char *wv="211_OPEN"; wavestrs[11]=wv;}
85 {char *wv="171_THIN"; wavestrs[12]=wv;}
86 {char *wv="171_THICK"; wavestrs[13]=wv;}
87 {char *wv="1600"; wavestrs[14]=wv;}
88 {char *wv="1700"; wavestrs[15]=wv;}
89 {char *wv="4500"; wavestrs[16]=wv;}
90 {char *wv="94_THIN"; wavestrs[17]=wv;}
91 {char *wv="94_THICK"; wavestrs[18]=wv;}
92 {char *wv="94_OPEN"; wavestrs[19]=wv;}
93 {char *wv="304_THIN"; wavestrs[20]=wv;}
94 {char *wv="304_THICK"; wavestrs[21]=wv;}
95 {char *wv="304_OPEN"; wavestrs[22]=wv;}
96
97
98
99
100
101 for (i=0; i<23; ++i){vvd += !strcmp(wavestrs[i], wavelength); if (!strcmp(wavestrs[i], wavelength)) vvv=i;}
102 if (vvd == 0){printf("nonexisting wavelength id\n"); exit(EXIT_FAILURE);} else {printf("wavelength number %d\n", vvv);}
103 }
104
105
106
107
108 int cam_id=cmdparams_get_int(&cmdparams, "camera", NULL);
109
110 char *camera_string;
111
112 if (inst_hmi){
113 if (cam_id == 1) camera_string="HMI_SIDE1";
114 if (cam_id == 2) camera_string="HMI_FRONT2";
115 if (cam_id < 1 || cam_id > 2){printf("wrong camera id for HMI\n"); exit(EXIT_FAILURE);}
116 }
117
118 if (inst_aia){
119 if (aia_cam[vvv] == 1) camera_string="AIA_ATA1";
120 if (aia_cam[vvv] == 2) camera_string="AIA_ATA2";
121 if (aia_cam[vvv] == 3) camera_string="AIA_ATA3";
122 if (aia_cam[vvv] == 4) camera_string="AIA_ATA4";
123
124 }
125 TIME t_dark=cmdparams_get_time(&cmdparams, "t_obs", NULL);
126
127
128 int *fsn_list_dark;
129 fsn_list_dark=(int *)(malloc(sizeof(int)*256));
130 int ndark=cmdparams_get_intarr(&cmdparams, "fsn_list_dark", &fsn_list_dark, NULL);
131
132 if (ndark <1){ printf("wrong number of dark frames\n"); exit(EXIT_FAILURE);}
133 if (ndark > 256){ printf("too many dark frames\n"); exit(EXIT_FAILURE);}
134 char fsn_string_dark[13*256]={""};
135 for (k=0; k<ndark; ++k)
136 {
137 char ffnumb[12]={""};
138 sprintf(ffnumb, "%12d", fsn_list_dark[k]);
139 strcat(fsn_string_dark, ffnumb);
140 if (k<(ndark-1)) strcat(fsn_string_dark, ",");
141 }
142
143
144 int fsn_first_dark=fsn_list_dark[0];
145 int fsn_last_dark=fsn_list_dark[ndark-1];
146
147
148
149
150 const char *series_name_dark;
151 series_name_dark=cmdparams_get_str(&cmdparams, "series_dark", NULL);
152
153
154 int stat = DRMS_SUCCESS;
155 int error = 0;
156
157
158 DRMS_RecordSet_t *dataout, *dataout_dark;
159
160 DRMS_Record_t *recout = NULL;
161 DRMS_Segment_t *segout = NULL;
162 DRMS_Array_t *arrout_dark;
163 long long recnum_dark;
164 DRMS_Type_t type = DRMS_TYPE_FLOAT;
165 DRMS_Type_t type_time = DRMS_TYPE_TIME;
166 size_t bytes_read;
167 FILE *fgram;
168 float *gout1;
169
170
171 int nx=cmdparams_get_int(&cmdparams, "nx", NULL);
172 int ny=cmdparams_get_int(&cmdparams, "ny", NULL);
173
174 int axisin[2]; //size of input arrays
175 int axisout[2]={nx,ny};
176
177
178 //KEYWORDS ***********************************************************************/
179
180 const char *primekey1 = "CAMERA";
181 const char *primekey2 = "T_OBS"; //1st prime key of output data
182
183
184 const char *key1 = "FSN_FIRST"; // output keyword //copy
185 const char *key2 = "FSN_LAST"; // output keyword //copy
186 const char *key3 = "FSN_INPUT"; // output keyword //copy
187
188 const char *key6="INSTRUME";
189
190 const char *key1aia="WAVE_STR";
191
192
193 printf("START!\n");
194
195
196 //*****************************************************************************/
197 //Dark data series /
198 //*****************************************************************************/
199
200 drms_series_exists(drms_env, series_name_dark, &status);
201 if (status == DRMS_ERROR_UNKNOWNSERIES)
202 {
203 printf("Dark series %s doesn't exist\n",series_name_dark); //if the output series does not exit
204 exit(EXIT_FAILURE); //we exit the program
205 }
206 if (status == DRMS_SUCCESS)
207 {
208 printf("Dark series %s exists.\n",series_name_dark);
209 }
210
211 //read dark image
212
213 float *f_dark;
214 fgram=fopen(input_dark, "rb");
215 if (fgram==NULL){fputs("File error", stderr); printf("Could not read file\n"); exit(EXIT_FAILURE);}
216 f_dark=(float *)(malloc(nx*ny*sizeof(float)));
217 bytes_read=fread(f_dark,sizeof(float),nx*ny,fgram);
218 fclose(fgram);
219
220
221 arrout_dark = drms_array_create(type,2,axisout,NULL,&status);
222 if (status != 0 || arrout_dark == NULL){printf("could not create array\n"); exit(EXIT_FAILURE);}
223
224 gout1=arrout_dark->data;
225
226 dataout_dark = drms_create_records(drms_env,1,(char *)series_name_dark, DRMS_PERMANENT, &stat);
227 if (stat !=0 || dataout_dark == NULL){printf("could not create dark\n"); exit(EXIT_FAILURE);}
228
229
230 for (j=0; j<ny; ++j) for (i=0; i<nx; ++i) gout1[j*nx+i]=f_dark[j*nx+i];
231
232 if (stat != DRMS_SUCCESS)
233 {
234 printf("Could not create a record for the series %s\n", series_name_dark);
235 exit(EXIT_FAILURE);
236 }
237
238 if (stat == DRMS_SUCCESS)
239 {
240 printf("Writing a record on the DRMS for the series %s\n", series_name_dark);
241
242 recout = dataout_dark->records[0];
243 recnum_dark=recout->recnum;
244
245 status=0;
246 status += drms_setkey_time(recout, primekey2, t_dark);
247
248 if (inst_hmi) status += drms_setkey_int(recout, primekey1,cam_id);
249
250 status += drms_setkey_int(recout,key1,fsn_first_dark);
251 status += drms_setkey_int(recout,key2,fsn_last_dark);
252 status += drms_setkey_string(recout, key3, fsn_string_dark);
253 status += drms_setkey_string(recout, key6, camera_string);
254
255
256 if (inst_aia) status += drms_setkey_string(recout, key1aia, wavelength);
257
258
259 if (status != 0){printf("error setting keywords"); exit(EXIT_FAILURE);}
260 drms_keyword_setdate(recout);
261
262 segout=drms_segment_lookup(recout, "dark");
263 if (segout == NULL){printf("could not find segment\n"); exit(EXIT_FAILURE);}
264
265 status=drms_segment_write(segout, arrout_dark, 0);
266 if (status != 0){printf("could not write segment\n"); exit(EXIT_FAILURE);}
267 }
268
269 drms_close_records(dataout_dark, DRMS_INSERT_RECORD);
270 drms_free_array(arrout_dark);
271 printf("done\n");
272
273
274
275 printf("COMPLETED!\n");
276
277
278
279
280
281 return 0;
282
283
284
285 }
286
287
288