00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <stdio.h>
00022 #include <stdlib.h>
00023 #include <time.h>
00024 #include <sys/time.h>
00025 #include <math.h>
00026 #include <string.h>
00027 #include "jsoc_main.h"
00028
00029 #define DIE(msg) {fflush(stdout); fprintf(stderr,"%s, status=%d\n", msg, status); return(status);}
00030 #define SHOW(msg) {printf("%s", msg); fflush(stdout);}
00031
00032
00033 char *module_name = "fix_lorentz";
00034
00035 ModuleArgs_t module_args[] =
00036 {
00037 {ARG_STRING, "in", NULL, "Input/output lorentz series"},
00038 {ARG_END}
00039 };
00040
00041 int DoIt(void)
00042 {
00043
00044 char *cvsinfo = strdup("$Id: fix_lorentz.c,v 1.1 2014/05/17 01:28:49 xudong Exp $");
00045
00046 int status = DRMS_SUCCESS;
00047
00048 char *inQuery = (char *) params_get_str(&cmdparams, "in");
00049
00050
00051
00052 DRMS_RecordSet_t *inRS = drms_open_records(drms_env, inQuery, &status);
00053 int nrecs = inRS->n;
00054
00055 if (status || (nrecs == 0)) DIE("Error open data series");
00056
00057
00058
00059 DRMS_RecordSet_t *outRS = drms_clone_records(inRS, DRMS_PERMANENT, DRMS_SHARE_SEGMENTS, &status);
00060 if (status) DIE("Error cloning data series");
00061
00062
00063
00064 drms_close_records(inRS, DRMS_FREE_RECORD);
00065
00066
00067
00068 int iGood = 0;
00069
00070 for (int irec = 0; irec < nrecs; irec++) {
00071
00072
00073
00074 DRMS_Record_t *outRec = outRS->records[irec];
00075
00076 TIME t_rec = drms_getkey_time(outRec, "T_REC", &status);
00077 char t_rec_str[100];
00078 sprint_time(t_rec_str, t_rec, "TAI", 0);
00079
00080 printf("Record #%d of %d, T_REC=%s...\n", irec + 1, nrecs, t_rec_str);
00081
00082
00083
00084 DRMS_Record_t *sharpRec = drms_link_follow(outRec, "SHARP", &status);
00085 if (status) {
00086 SHOW("Error retrieving sharp record, skipped\n");
00087 continue;
00088 }
00089
00090
00091
00092 drms_copykey(outRec, sharpRec, "NOAA_AR");
00093 drms_copykey(outRec, sharpRec, "NOAA_NUM");
00094 drms_copykey(outRec, sharpRec, "NOAA_ARS");
00095 drms_copykey(outRec, sharpRec, "AMBPATCH");
00096
00097 char timebuf[512], histbuf[2014];
00098 double val;
00099 sprint_time(timebuf, (double)time(NULL) + UNIX_EPOCH, "ISO", 0);
00100 drms_setkey_string(outRec, "DATE", timebuf);
00101
00102 sprintf(histbuf, "NOAA keywords fixed with %s", cvsinfo);
00103 drms_setkey_string(outRec, "HISTORY", histbuf);
00104
00105
00106
00107 drms_close_record(sharpRec, DRMS_FREE_RECORD);
00108 iGood++;
00109
00110 }
00111
00112
00113
00114 drms_close_records(outRS, DRMS_INSERT_RECORD);
00115
00116 printf("%d of %d records fixed.\n", iGood, nrecs);
00117
00118 return DRMS_SUCCESS;
00119
00120 }