00001 #define HAVE_LONGLONG
00002
00003
00004 #include <jsoc_main.h>
00005 #include <drms_fortran.h>
00006 #include <fitsio.h>
00007 #include <string.h>
00008 #include <dirent.h>
00009
00010 static char * formatObsDateTime(char *, char * , char *);
00011 static int replace_str( char *, char, char );
00012 int gong2drms_set_keywords (char *, int, char *);
00013
00014 int gong2drms_set_keywords (char *rec_hdl, int headlen, char *header) {
00015 DRMS_Record_t * record = (DRMS_Record_t *) _convert_handle(rec_hdl);
00016 int status=0;
00017 int i;
00018
00019 int key_len=0;
00020
00021 char *ghist=(char *) NULL;
00022 char card[FLEN_CARD], svalue[FLEN_CARD];
00023 char date_part[250], obs_datetime[250];
00024 long ivalue;
00025 float fvalue;
00026 const char *p;
00027
00028
00029 char keyname[FLEN_KEYWORD], value[FLEN_VALUE], comm[FLEN_COMMENT];
00030
00031
00032 p=header;
00033
00034 for (i=0; i<headlen; i+=80, p+=80) {
00035 status=0;
00036 strncpy(card, p, 80);
00037 card[80]='\0';
00038 ffgknm(card, keyname, &key_len, &status);
00039
00040 if (keyname[0] == '\0') break;
00041
00042 ffpsvc(card, value, comm, &status);
00043
00044
00045
00046
00047
00048 for (i = (strlen(value) - 2); i >= 0 && value[i] == ' '; i--) {
00049 value[i+1] = '\0'; value[i]='\'';
00050 }
00051
00052
00053 if ( !strcmp(keyname, "BSCALE") ) {
00054 ffc2rr(value, &fvalue, &status);
00055 drms_setkey_float(record, "BSCALE", fvalue);
00056 }
00057 if ( !strcmp(keyname, "BZERO") ) {
00058 ffc2s(value,svalue,&status);
00059 drms_setkey_string(record, "BZERO", svalue);
00060 }
00061 if ( !strcmp(keyname, "OBJECT") ) {
00062 ffc2s(value,svalue,&status);
00063 drms_setkey_string(record, "OBJECT", svalue);
00064 }
00065 if ( !strcmp(keyname, "ORIGIN") ) {
00066 ffc2s(value,svalue,&status);
00067 drms_setkey_string(record, "ORIGIN", svalue);
00068 }
00069 if ( !strcmp(keyname, "DATE") ) {
00070 ffc2rr(value, &fvalue, &status);
00071 drms_setkey_float(record, "DATE", fvalue);
00072 }
00073 if ( !strcmp(keyname, "IRAFNAME") ) {
00074 ffc2s(value,svalue,&status);
00075 drms_setkey_string(record, "IRAFNAME", svalue);
00076 }
00077 if ( !strcmp(keyname, "IRAF-MAX") ) {
00078 ffc2rr(value, &fvalue, &status);
00079 drms_setkey_float(record, "IRAF__MAX", fvalue);
00080 }
00081 if ( !strcmp(keyname, "IRAF-MIN") ) {
00082 ffc2rr(value, &fvalue, &status);
00083 drms_setkey_float(record, "IRAF__MIN", fvalue);
00084 }
00085 if ( !strcmp(keyname, "IRAF-BPX") ) {
00086 ffc2ii(value, &ivalue, &status);
00087 drms_setkey_int(record, "IRAF__BPX", ivalue);
00088 }
00089 if ( !strcmp(keyname, "IRAFTYPE") ) {
00090 ffc2s(value,svalue,&status);
00091 drms_setkey_string(record, "IRAFTYPE", svalue);
00092 }
00093 if ( !strcmp(keyname, "ORIGIN") ) {
00094 ffc2s(value,svalue,&status);
00095 drms_setkey_string(record, "ORIGIN", svalue);
00096 }
00097
00098 if ( !strcmp(keyname, "MAP_TYPE") ) {
00099 ffc2s(value,svalue,&status);
00100 drms_setkey_string(record, "MAP_TYPE", svalue);
00101 }
00102 if ( !strcmp(keyname, "ITIME") ) {
00103 ffc2rr(value, &fvalue, &status);
00104 drms_setkey_float(record, "ITIME", fvalue);
00105 }
00106
00107 if ( !strcmp(keyname, "DATE-OBS") ) {
00108 ffc2s(value, svalue, &status);
00109 strcpy(date_part,svalue);
00110 }
00111
00112 if ( !strcmp(keyname, "TIME-OBS") ) {
00113 ffc2s(value, svalue, &status);
00114 drms_setkey_string(record, "DATETIME__OBS", formatObsDateTime(obs_datetime, date_part, svalue));
00115 }
00116
00117 if ( !strcmp(keyname, "SITENAME") ) {
00118 ffc2s(value,svalue,&status);
00119 drms_setkey_string(record, "SITENAME", svalue);
00120 }
00121
00122 if ( !strcmp(keyname, "SITE") ) {
00123 ffc2s(value,svalue,&status);
00124 drms_setkey_string(record, "SITE", svalue);
00125 }
00126
00127 if ( !strncmp(keyname, "GHIST", sizeof(char) * 5) ) {
00128 if ( !strcmp(keyname, "GHISTSEQ") ) {
00129 ffc2ii(value,&ivalue,&status);
00130
00131 ghist=malloc((size_t) sizeof(char)*80*(ivalue));
00132 memset(ghist,'\0',(size_t) sizeof(char)*80*(ivalue));
00133 } else {
00134 ffc2s(value,svalue,&status);
00135
00136 strcpy(ghist+ sizeof(char) * strlen(ghist),svalue);
00137
00138 drms_setkey_string(record, "GHIST", ghist);
00139 }
00140 }
00141
00142 if ( !strcmp(keyname, "TYPE") ) {
00143 ffc2ii(value, &ivalue, &status);
00144 drms_setkey_int(record, "TYPE", ivalue);
00145 }
00146
00147 if ( !strcmp(keyname, "DTYPE") ) {
00148 ffc2s(value,svalue,&status);
00149 drms_setkey_string(record, "DTYPE", svalue);
00150 }
00151
00152 if ( !strcmp(keyname, "VELSCALE") ) {
00153 ffc2rr(value, &fvalue, &status);
00154 drms_setkey_float(record, "VELSCALE", fvalue);
00155 }
00156
00157 if ( !strcmp(keyname, "VEL_BIAS") ) {
00158 ffc2rr(value, &fvalue, &status);
00159 drms_setkey_float(record, "VEL_BIAS", fvalue);
00160 }
00161
00162 if ( !strcmp(keyname, "VCOR1") ) {
00163 ffc2rr(value, &fvalue, &status);
00164 drms_setkey_float(record, "VCOR1", fvalue);
00165 }
00166 if ( !strcmp(keyname, "OFFSET") ) {
00167 ffc2rr(value, &fvalue, &status);
00168 drms_setkey_float(record, "GOFFSET", fvalue);
00169 }
00170 if ( !strcmp(keyname, "FNDLMBXC") ) {
00171 ffc2rr(value, &fvalue, &status);
00172 drms_setkey_float(record, "FNDLMBXC", fvalue);
00173 }
00174 if ( !strcmp(keyname, "FNDLMBYC") ) {
00175 ffc2rr(value, &fvalue, &status);
00176 drms_setkey_float(record, "FNDLMBYC", fvalue);
00177 }
00178 if ( !strcmp(keyname, "FNDLMBMA") ) {
00179 ffc2rr(value, &fvalue, &status);
00180 drms_setkey_float(record, "FNDLMBMA", fvalue);
00181 }
00182 if ( !strcmp(keyname, "FNDLMBMI") ) {
00183 ffc2rr(value, &fvalue, &status);
00184 drms_setkey_float(record, "FNDLMBMI", fvalue);
00185 }
00186 if ( !strcmp(keyname, "FNDLMBAN") ) {
00187 ffc2rr(value, &fvalue, &status);
00188 drms_setkey_float(record, "FNDLMBAN", fvalue);
00189 }
00190 if ( !strcmp(keyname, "C_MA") ) {
00191 ffc2rr(value, &fvalue, &status);
00192 drms_setkey_float(record, "C_MA", fvalue);
00193 }
00194 if ( !strcmp(keyname, "C_MI") ) {
00195 ffc2rr(value, &fvalue, &status);
00196 drms_setkey_float(record, "C_MI", fvalue);
00197 }
00198 if ( !strcmp(keyname, "PIXLENX") ) {
00199 ffc2rr(value, &fvalue, &status);
00200 drms_setkey_float(record, "PIXLENX", fvalue);
00201 }
00202 if ( !strcmp(keyname, "PIXLENY") ) {
00203 ffc2rr(value, &fvalue, &status);
00204 drms_setkey_float(record, "PIXLENY", fvalue);
00205 }
00206 if ( !strcmp(keyname, "B0") ) {
00207 ffc2rr(value, &fvalue, &status);
00208 drms_setkey_float(record, "B0", fvalue);
00209 }
00210 if ( !strcmp(keyname, "L0") ) {
00211 ffc2rr(value, &fvalue, &status);
00212 drms_setkey_float(record, "L0", fvalue);
00213 }
00214 if ( !strcmp(keyname, "P_ANGLE") ) {
00215 ffc2rr(value, &fvalue, &status);
00216 drms_setkey_float(record, "P_ANGLE", fvalue);
00217 }
00218 if ( !strcmp(keyname, "SEMIDIAM") ) {
00219 ffc2rr(value, &fvalue, &status);
00220 drms_setkey_float(record, "SEMIDIAM", fvalue);
00221 }
00222 if ( !strcmp(keyname, "DELTA_L0") ) {
00223 ffc2rr(value, &fvalue, &status);
00224 drms_setkey_float(record, "DELTA_L0", fvalue);
00225 }
00226 if ( !strcmp(keyname, "N_IMGMRG") ) {
00227 ffc2ii(value, &ivalue, &status);
00228 drms_setkey_int(record, "N_IMGMRG", ivalue);
00229 }
00230 if ( !strcmp(keyname, "MRG_IM01") ) {
00231 ffc2s(value,svalue,&status);
00232 drms_setkey_string(record, "MRG_IM01", svalue);
00233 }
00234 if ( !strcmp(keyname, "MRG_IM02") ) {
00235 ffc2s(value,svalue,&status);
00236 drms_setkey_string(record, "MRG_IM02", svalue);
00237 }
00238 if ( !strcmp(keyname, "MRG_IM03") ) {
00239 ffc2s(value,svalue,&status);
00240 drms_setkey_string(record, "MRG_IM03", svalue);
00241 }
00242 if ( !strcmp(keyname, "MRG_IM04") ) {
00243 ffc2s(value,svalue,&status);
00244 drms_setkey_string(record, "MRG_IM04", svalue);
00245 }
00246 if ( !strcmp(keyname, "MRG_IM05") ) {
00247 ffc2s(value,svalue,&status);
00248 drms_setkey_string(record, "MRG_IM05", svalue);
00249 }
00250 if ( !strcmp(keyname, "MRG_IM06") ) {
00251 ffc2s(value,svalue,&status);
00252 drms_setkey_string(record, "MRG_IM06", svalue);
00253 }
00254 if ( !strcmp(keyname, "MRG_IM07") ) {
00255 ffc2s(value,svalue,&status);
00256 drms_setkey_string(record, "MRG_IM07", svalue);
00257 }
00258 if ( !strcmp(keyname, "INORM") ) {
00259 ffc2s(value,svalue,&status);
00260 drms_setkey_string(record, "INORM", svalue);
00261 }
00262 }
00263
00264 if (ghist != (char * ) NULL) {
00265 free(ghist);
00266 }
00267
00268 return 0;
00269 }
00270
00271 FCALLSCFUN3(INT, gong2drms_set_keywords, F_GONG2DRMS_SET_KEYWORDS, f_gong2drms_set_keywords, STRING, INT, STRING)
00272
00273 char * formatObsDateTime(char * obs_datetime, char * date_part, char * time_part) {
00274
00275 char date[250];
00276
00277 sprintf(date, "%s %s", date_part, time_part);
00278
00279 if (!strcmp(date,"UTC")) {
00280 strcpy(obs_datetime, date);
00281 } else {
00282 sprintf(obs_datetime, "%s UTC", date);
00283 }
00284
00285 replace_str(obs_datetime, '/', '.');
00286 replace_str(obs_datetime, ' ', '_');
00287
00288 return obs_datetime;
00289 }
00290
00291 int replace_str( char * p, char c_from, char c_to) {
00292 char *r_chr;
00293 int count=0;
00294 while((r_chr=strrchr(p,c_from))!= (char *) NULL) {
00295 *r_chr = c_to;
00296 count++;
00297 }
00298 return count;
00299 }