00001 #include "jsoc_main.h"
00002 #include "drms_types.h"
00003
00004 char *module_name = "DRMS_QUERY_FL_TEST";
00005
00006 typedef enum
00007 {
00008 kDQFLErr_Success = 0,
00009 kDQFLErr_Error = 1
00010 } DQFLError_t;
00011
00012 #define kRecSetIn "recsin"
00013
00014 ModuleArgs_t module_args[] =
00015 {
00016 {ARG_STRING, kRecSetIn, "", "Input data series."},
00017 {ARG_END}
00018 };
00019
00020 int DoIt(void)
00021 {
00022 int status = DRMS_SUCCESS;
00023 const char *rsin = cmdparams_get_str(&cmdparams, kRecSetIn, NULL);
00024 int ncols;
00025 int nrows;
00026 int icol;
00027 int irow;
00028 DRMS_Record_t *template = NULL;
00029 char *keyBuf = NULL;
00030 size_t szKeyBuf;
00031 DRMS_Array_t *data = NULL;
00032 DQFLError_t rv = kDQFLErr_Success;
00033
00034 char *allvers = NULL;
00035
00036
00037 char **sets = NULL;
00038 DRMS_RecordSetType_t *settypes = NULL;
00039 char **snames = NULL;
00040 char **filts = NULL;
00041 int nsets = 0;
00042 DRMS_RecQueryInfo_t rsinfo;
00043
00044 if (drms_record_parserecsetspec(rsin, &allvers, &sets, &settypes, &snames, &filts, &nsets, &rsinfo) != DRMS_SUCCESS)
00045 {
00046 rv = kDQFLErr_Error;
00047 }
00048 else
00049 {
00050
00051 template = drms_template_record(drms_env, snames[0], &status);
00052
00053 drms_record_freerecsetspecarr(&allvers, &sets, &settypes, &snames, &filts, nsets);
00054
00055 if (!template || status != DRMS_SUCCESS)
00056 {
00057 rv = kDQFLErr_Error;
00058 }
00059 else
00060 {
00061
00062
00063 HIterator_t *last = NULL;
00064 DRMS_Keyword_t *key = NULL;
00065
00066 szKeyBuf = 1024;
00067 keyBuf = calloc(1, szKeyBuf);
00068 XASSERT(keyBuf);
00069
00070
00071 int start = ceil(hcon_size(&template->keywords) * 0.15);
00072 int skip = 2;
00073 int nKeys;
00074 int skipCount;
00075
00076 if (start + skip * 3 > hcon_size(&template->keywords))
00077 {
00078 start = hcon_size(&template->keywords);
00079 skip = 0;
00080 nKeys = 1;
00081 }
00082 else
00083 {
00084 nKeys = 3;
00085 }
00086
00087 skipCount = 0;
00088 while (((key = drms_record_nextkey(template, &last, 0)) != NULL) && nKeys > 0)
00089 {
00090 if (start > 1)
00091 {
00092 start--;
00093 }
00094 else
00095 {
00096 if (skipCount == 0)
00097 {
00098
00099 if (!drms_keyword_isconstant(key))
00100 {
00101 keyBuf = base_strcatalloc(keyBuf, key->info->name, &szKeyBuf); XASSERT(keyBuf);
00102
00103 if (nKeys > 1)
00104 {
00105 keyBuf = base_strcatalloc(keyBuf, ", ", &szKeyBuf); XASSERT(keyBuf);
00106 }
00107 }
00108
00109 nKeys--;
00110
00111 skipCount = skip;
00112 }
00113 else
00114 {
00115 skipCount--;
00116 }
00117 }
00118 }
00119
00120 if (last)
00121 {
00122 hiter_destroy(&last);
00123 }
00124
00125
00126 data = drms_record_getvector(drms_env, rsin, keyBuf, DRMS_TYPE_STRING, 1, &status);
00127
00128 if (data && status == DRMS_SUCCESS)
00129 {
00130 ncols = data->axis[0];
00131 nrows = data->axis[1];
00132
00133
00134 for (irow = 0; irow < nrows; irow++)
00135 {
00136 for (icol = 0; icol < ncols; icol++)
00137 {
00138 printf("%s ", ((char **)data->data)[icol * nrows + irow]);
00139 }
00140
00141 printf("\n");
00142 }
00143 }
00144 else
00145 {
00146 rv = kDQFLErr_Error;
00147 }
00148 }
00149 }
00150
00151 return rv;
00152 }