00001
00002
00003
00004
00005 #include <stdlib.h>
00006 #include <stdio.h>
00007 #include <math.h>
00008 #include <jsoc_main.h>
00009 #include <string.h>
00010 #include <time.h>
00011
00012
00013
00014 char *module_name = "write_badpix";
00015
00016
00017 ModuleArgs_t module_args[] =
00018 {
00019 {ARG_STRING, "instrument"},
00020 {ARG_STRING, "series_badpix", ""},
00021 {ARG_STRING, "file_badpix"},
00022 {ARG_INT, "camera", "0"},
00023 {ARG_STRING, "wave_str", "dd"},
00024 {ARG_TIME, "t_obs"},
00025 {ARG_INT, "nbad", "0", "0-16777216"},
00026 {ARG_END}
00027 };
00028
00029
00030
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 int DoIt(void)
00043 {
00044
00045 int status=DRMS_SUCCESS;
00046 int i,j,k;
00047
00048
00049 const char *input_badpix;
00050 input_badpix = cmdparams_get_str(&cmdparams, "file_badpix", NULL);
00051
00052 const char *instrument;
00053 instrument=cmdparams_get_str(&cmdparams, "instrument", &status);
00054
00055 if (strcmp(instrument,"HMI") != 0 && strcmp(instrument,"AIA") != 0){printf("Instrument invalid\n"); exit(EXIT_FAILURE);}
00056
00057 int inst_hmi=!strcmp(instrument,"HMI");
00058 int inst_aia=!strcmp(instrument,"AIA");
00059
00060 const char *wavelength;
00061 int vvd=0, vvv=-1;
00062 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};
00063
00064 if (inst_aia)
00065 {
00066 wavelength=cmdparams_get_str(&cmdparams, "wave_str", &status);
00067 char **wavestrs=(char **)(malloc(23*sizeof(char *)));
00068
00069
00070 wavestrs[0]="131_THIN";
00071 wavestrs[1]="131_THICK";
00072 wavestrs[2]="131_OPEN";
00073 wavestrs[3]="335_THIN";
00074 {char *wv="335_THICK"; wavestrs[4]=wv;}
00075 {char *wv="335_OPEN"; wavestrs[5]=wv;}
00076 {char *wv="193_THIN"; wavestrs[6]=wv;}
00077 {char *wv="193_THICK"; wavestrs[7]=wv;}
00078 {char *wv="193_OPEN"; wavestrs[8]=wv;}
00079 {char *wv="211_THIN"; wavestrs[9]=wv;}
00080 {char *wv="211_THICK"; wavestrs[10]=wv;}
00081 {char *wv="211_OPEN"; wavestrs[11]=wv;}
00082 {char *wv="171_THIN"; wavestrs[12]=wv;}
00083 {char *wv="171_THICK"; wavestrs[13]=wv;}
00084 {char *wv="1600"; wavestrs[14]=wv;}
00085 {char *wv="1700"; wavestrs[15]=wv;}
00086 {char *wv="4500"; wavestrs[16]=wv;}
00087 {char *wv="94_THIN"; wavestrs[17]=wv;}
00088 {char *wv="94_THICK"; wavestrs[18]=wv;}
00089 {char *wv="94_OPEN"; wavestrs[19]=wv;}
00090 {char *wv="304_THIN"; wavestrs[20]=wv;}
00091 {char *wv="304_THICK"; wavestrs[21]=wv;}
00092 {char *wv="304_OPEN"; wavestrs[22]=wv;}
00093
00094
00095
00096
00097
00098 for (i=0; i<23; ++i){vvd += !strcmp(wavestrs[i], wavelength); if (!strcmp(wavestrs[i], wavelength)) vvv=i;}
00099 if (vvd == 0){printf("nonexisting wavelength id\n"); exit(EXIT_FAILURE);} else {printf("number %d\n", vvv);}
00100 }
00101
00102 int cam_id;
00103 cam_id=cmdparams_get_int(&cmdparams, "camera", NULL);
00104
00105 const char *camera_string;
00106 if (inst_hmi)
00107 {
00108
00109 if (cam_id == 1) camera_string="HMI_SIDE1";
00110 if (cam_id == 2) camera_string="HMI_FRONT2";
00111 if (cam_id < 1 || cam_id > 2){printf("wrong camera id for HMI\n"); exit(EXIT_FAILURE);}
00112 }
00113
00114 if (inst_aia){
00115 if (aia_cam[vvv] == 1) camera_string="AIA_ATA1";
00116 if (aia_cam[vvv] == 2) camera_string="AIA_ATA2";
00117 if (aia_cam[vvv] == 3) camera_string="AIA_ATA3";
00118 if (aia_cam[vvv] == 4) camera_string="AIA_ATA4";
00119 }
00120
00121
00122 TIME t_start=cmdparams_get_time(&cmdparams, "t_obs", NULL);
00123 TIME t_offpoint=t_start;
00124
00125 int nbad=cmdparams_get_int(&cmdparams, "nbad", NULL);
00126
00127 const char *series_name_bad;
00128 series_name_bad=cmdparams_get_str(&cmdparams, "series_badpix", NULL);
00129
00130
00131
00132
00133 int stat = DRMS_SUCCESS;
00134
00135
00136 DRMS_RecordSet_t *dataout, *dataout_bad;
00137
00138 DRMS_Record_t *recout = NULL;
00139 DRMS_Segment_t *segout = NULL;
00140 DRMS_Array_t *arrout, *arrout_bad;
00141 long long recnum_bad;
00142 DRMS_Type_t type;
00143 DRMS_Type_t type_time = DRMS_TYPE_TIME;
00144 size_t bytes_read;
00145 FILE *fgram;
00146 float *gout1;
00147 int *gout_bad;
00148
00149
00150
00151
00152
00153 const char *primekey1 = "CAMERA";
00154 const char *primekey2 = "T_OBS";
00155
00156 const char *key6="INSTRUME";
00157
00158 const char *key1aia="WAVE_STR";
00159
00160
00161 printf("START!\n");
00162
00163
00164
00165
00166
00167
00168
00169
00170 drms_series_exists(drms_env, series_name_bad, &status);
00171 if (status == DRMS_ERROR_UNKNOWNSERIES)
00172 {
00173 printf("Series %s doesn't exist\n",series_name_bad);
00174 exit(EXIT_FAILURE);
00175 }
00176 if (status == DRMS_SUCCESS)
00177 {
00178 printf("Series %s exists.\n",series_name_bad);
00179 }
00180
00181 int *f_bad;
00182 fgram=fopen(input_badpix, "rb");
00183 if (fgram==NULL){fputs("File error", stderr); printf("could not read file\n"); exit(EXIT_FAILURE);}
00184 f_bad=(int *)(malloc(nbad*sizeof(int)));
00185 bytes_read=fread(f_bad,sizeof(int),nbad,fgram);
00186 fclose(fgram);
00187
00188 int axisout_bad[1];
00189 axisout_bad[0]=nbad;
00190 type = DRMS_TYPE_INT;
00191
00192 arrout_bad = drms_array_create(type,1,axisout_bad,NULL,&status);
00193 if (status !=0 || arrout_bad == NULL){printf("could not create array\n"); exit(EXIT_FAILURE);}
00194
00195 gout_bad = arrout_bad->data;
00196
00197 for (j=0; j<nbad; ++j) gout_bad[j]=f_bad[j];
00198 dataout_bad = drms_create_records(drms_env,1,(char *)series_name_bad,DRMS_PERMANENT,&stat);
00199
00200 if (stat != DRMS_SUCCESS)
00201 {
00202 printf("Could not create a record for the series %s\n", series_name_bad);
00203 exit(EXIT_FAILURE);
00204 }
00205 if (stat == DRMS_SUCCESS)
00206 {
00207 printf("Writing a record on the DRMS for the series %s\n",series_name_bad);
00208 recout = dataout_bad->records[0];
00209 recnum_bad=recout->recnum;
00210
00211 status=0;
00212 status += drms_setkey_time(recout, primekey2, t_start);
00213
00214 if (inst_hmi) status += drms_setkey_int(recout, primekey1,cam_id);
00215
00216 if (inst_aia) status += drms_setkey_string(recout, key1aia, wavelength);
00217
00218 status += drms_setkey_string(recout, key6, camera_string);
00219
00220
00221 if (status != 0){printf("error setting keywords"); exit(EXIT_FAILURE);}
00222 drms_keyword_setdate(recout);
00223
00224 segout = drms_segment_lookup(recout, "bad_pixel_list");
00225 if (segout == NULL){printf("could not find segment\n"); exit(EXIT_FAILURE);}
00226
00227 status=drms_segment_write(segout, arrout_bad, 0);
00228 if (status != 0){printf("could not write segment\n"); exit(EXIT_FAILURE);}
00229
00230 }
00231
00232 drms_close_records(dataout_bad, DRMS_INSERT_RECORD);;
00233 drms_free_array(arrout_bad);
00234 printf("done\n");
00235
00236 printf("COMPLETED!\n");
00237
00238
00239
00240
00241
00242 return 0;
00243
00244
00245
00246 }
00247
00249
00250
00251
00252