00001
00002
00003
00004
00005
00006 #include <stdio.h>
00007 #include <math.h>
00008 #include <stdlib.h>
00009 #include <time.h>
00010 #include <sys/time.h>
00011 #include <sys/resource.h>
00012 #include "jsoc_main.h"
00013 #include "drms_dsdsapi.h"
00014 #include "errlog.h"
00015
00016 #define ARRLENGTH(ARR) (sizeof(ARR)/sizeof(ARR[0]))
00017
00018 #define kNOTSPECIFIED "not specified"
00019 #define QUAL_NODATA (0x80000000)
00020 #define QUAL_MIXEDCALVER (0x00000001)
00021
00022 #define MODES(L) ((((L)+1)*(L))/2)
00023 #define MINIMUM(X,Y) (((X)<(Y))?(X):(Y))
00024 #define MAXIMUM(X,Y) (((X)>(Y))?(X):(Y))
00025
00026 char *module_name = "jretile";
00027 char *cvsinfo_jretile = "cvsinfo: $Header: /home/cvsuser/cvsroot/JSOC/proj/globalhs/apps/jretile.c,v 1.12 2014/06/06 13:04:19 tplarson Exp $";
00028
00029 ModuleArgs_t module_args[] =
00030 {
00031 {ARG_STRING, "in", NULL, "input data records"},
00032 {ARG_STRING, "out", NULL, "output data series"},
00033 {ARG_STRING, "segin", kNOTSPECIFIED, "input data segment"},
00034 {ARG_STRING, "segout", kNOTSPECIFIED, "output data segment"},
00035 {ARG_STRING, "histlink", "HISTORY", "name of link to ancillary dataseries for processing metadata"},
00036 {ARG_INT, "MEMUSE", "3", "set to 0 to minimize use of file descriptors and memory, set to 1 to read slices and write whole files, 2 to read whole files and write slices, 3 to read whole files and write whole files."},
00037 {ARG_INT, "PERM", "1", "set to 0 for transient records, nonzero for permanent records"},
00038 {ARG_INT, "VERB", "1", "option for level of verbosity: 0=only error and warning messages; >0=print messages outside of loop; >1=print messages inside loop; >2=debugging output", NULL},
00039 {ARG_INT, "CALVERKEY","2", "short integer bit mask determining which 4-bit fields of CALVER64 are permitted to change on input. set the bit to disallow change of the corresponding nybble."},
00040 {ARG_INT, "LMIN" , "0", "minimum l in output", NULL},
00041 {ARG_INT, "LMAX" , "0", "maximum l in output", NULL},
00042 {ARG_INT, "LCHUNK", "0", "size of output chunk in l", NULL},
00043 {ARG_TIME, "TSTART", NULL, "start time of first output record"},
00044 {ARG_STRING, "TTOTAL", NULL, "total length of time in output"},
00045 {ARG_STRING, "TCHUNK", kNOTSPECIFIED, "length of output timeseries"},
00046 {ARG_END}
00047 };
00048
00049 #include "saveparm.c"
00050 #include "timing.c"
00051 #include "set_history.c"
00052 #include "calversfunctions.c"
00053
00054 #include "jretile_manytofew.c"
00055 #include "jretile_fewtomany.c"
00056 #include "jretile_maxmem.c"
00057
00058 int DoIt(void)
00059 {
00060
00061 int status=0;
00062 char *inrecquery = NULL, *outseries = NULL;
00063 int lmin,lmax,lchunksize,lchunkfirst,lchunklast,nlchunks,ntimechunks,nrecsin,nrecsout;
00064 double nseconds,chunksecs;
00065 char *ttotal, *tchunk;
00066 DRMS_Record_t *tempoutrec = NULL;
00067
00068 int verbflag, memflag;
00069
00070 inrecquery = (char *)cmdparams_get_str(&cmdparams, "in", &status);
00071 outseries = (char *)cmdparams_get_str(&cmdparams, "out", &status);
00072 lmin=cmdparams_get_int(&cmdparams, "LMIN", &status);
00073 lmax=cmdparams_get_int(&cmdparams, "LMAX", &status);
00074 lchunksize=cmdparams_get_int(&cmdparams, "LCHUNK", &status);
00075 if (lchunksize == 0)
00076 lchunksize=lmax+1;
00077 verbflag = cmdparams_get_int(&cmdparams, "VERB", &status);
00078 memflag = cmdparams_get_int(&cmdparams, "MEMUSE", &status);
00079
00080 ttotal=(char *)cmdparams_get_str(&cmdparams, "TTOTAL", &status);
00081 status=drms_names_parseduration(&ttotal, &nseconds, 1);
00082 tchunk=(char *)cmdparams_get_str(&cmdparams, "TCHUNK", &status);
00083 if (strcmp(kNOTSPECIFIED, tchunk))
00084 {
00085 status=drms_names_parseduration(&tchunk, &chunksecs, 1);
00086 }
00087 else
00088 chunksecs=0;
00089
00090 tempoutrec = drms_create_record(drms_env, outseries, DRMS_TRANSIENT, &status);
00091 if (status != DRMS_SUCCESS)
00092 {
00093 fprintf(stderr,"ERROR: couldn't open a record in output dataseries %s, status = %d\n", outseries, status);
00094 return 1;
00095 }
00096
00097 char *outchecklist[] = {"T_START", "QUALITY", "LMIN", "LMAX", "NDT"};
00098 DRMS_Keyword_t *outkeytest;
00099 int itest;
00100 for (itest=0; itest < ARRLENGTH(outchecklist); itest++)
00101 {
00102 outkeytest = hcon_lookup_lower(&tempoutrec->keywords, outchecklist[itest]);
00103 if (outkeytest == NULL || outkeytest->info->islink || outkeytest->info->recscope == 1)
00104 {
00105 fprintf(stderr, "ERROR: output keyword %s is either missing, constant, or a link\n", outchecklist[itest]);
00106 drms_close_record(tempoutrec, DRMS_FREE_RECORD);
00107 return 1;
00108 }
00109 }
00110
00111 if (chunksecs == 0.0)
00112 chunksecs = drms_getkey_float(tempoutrec, "T_START_step", &status);
00113 drms_close_record(tempoutrec, DRMS_FREE_RECORD);
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125 nrecsin = drms_count_records(drms_env, inrecquery, &status);
00126 if (status != DRMS_SUCCESS)
00127 {
00128 fprintf(stderr, "ERROR: problem counting input records: status = %d, nrecs = %d\n", status, nrecsin);
00129 return 1;
00130 }
00131
00132 ntimechunks=nseconds/chunksecs;
00133 lchunkfirst = lmin/lchunksize;
00134 lchunklast = lmax/lchunksize;
00135 nlchunks = (lchunklast - lchunkfirst) + 1;
00136 nrecsout = nlchunks*ntimechunks;
00137
00138 if (verbflag)
00139 printf("nrecsin = %d, nrecsout = %d, ", nrecsin, nrecsout);
00140
00141 if (memflag==0)
00142 {
00143 if (nrecsin > nrecsout)
00144 {
00145 if (verbflag)
00146 printf("using jretile_manytofew()\n");
00147 status=jretile_manytofew();
00148 }
00149 else
00150 {
00151 if (verbflag)
00152 printf("using jretile_fewtomany()\n");
00153 status=jretile_fewtomany();
00154 }
00155 }
00156 else if (memflag==1)
00157 {
00158 if (verbflag)
00159 printf("forced use of jretile_fewtomany()\n");
00160 status=jretile_fewtomany();
00161 }
00162 else if (memflag==2)
00163 {
00164 if (verbflag)
00165 printf("forced use of jretile_manytofew()\n");
00166 status=jretile_manytofew();
00167 }
00168 else if (memflag==3)
00169 {
00170 if (verbflag)
00171 printf("using jretile_maxmem()\n");
00172 status=jretile_maxmem();
00173 }
00174
00175 return status;
00176
00177 }