(file) Return to jretile.c CVS log (file) (dir) Up to [Development] / JSOC / proj / globalhs / apps

File: [Development] / JSOC / proj / globalhs / apps / jretile.c (download)
Revision: 1.11, Sun Apr 28 07:05:21 2013 UTC (10 years, 4 months ago) by tplarson
Branch: MAIN
CVS Tags: globalhs_version_3, globalhs_version_2, globalhs_version_1, globalhs_version_0, Ver_8-4, Ver_8-3, Ver_8-2, Ver_8-1
Changes since 1.10: +1 -0 lines
changed how cvs versions are tracked.

/* this module does the same thing as the SOI module retile, though not quite an exact port
 * translated by tim larson
 * future upgrade: keep track of missing inputs rather than initializing entire array to 0.

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#include <sys/resource.h>
#include "jsoc_main.h"
#include "drms_dsdsapi.h"
#include "errlog.h"

#define ARRLENGTH(ARR)  (sizeof(ARR)/sizeof(ARR[0]))

#define kNOTSPECIFIED "not specified"
#define QUAL_NODATA	 (0x80000000)
#define QUAL_MIXEDCALVER (0x00000001)

#define MODES(L)        ((((L)+1)*(L))/2)
#define MINIMUM(X,Y)    (((X)<(Y))?(X):(Y))
#define MAXIMUM(X,Y)    (((X)>(Y))?(X):(Y))

char *module_name = "jretile";
char *cvsinfo_jretile = "cvsinfo: $Header: /home/cvsuser/cvsroot/JSOC/proj/globalhs/apps/jretile.c,v 1.11 2013/04/28 08:05:21 tplarson Exp $";

ModuleArgs_t module_args[] = 
   {ARG_STRING, "in",       NULL,          "input data records"},
   {ARG_STRING, "out",      NULL,          "output data series"},
   {ARG_STRING, "segin",    kNOTSPECIFIED, "input data segment"},
   {ARG_STRING, "segout",   kNOTSPECIFIED, "output data segment"},
   {ARG_STRING, "histlink", "HISTORY",     "name of link to ancillary dataseries for processing metadata"},
   {ARG_INT,    "PERM",     "1",           "set to 0 for transient records, nonzero for permanent records"},
   {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},
   {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."},
   {ARG_INT,    "LMIN" ,    "0",           "minimum l in output", NULL},
   {ARG_INT,    "LMAX" ,    "0",           "maximum l in output", NULL},   /* if 0, default is LMAX of in_sds */
   {ARG_INT,    "LCHUNK",   "0",           "size of output chunk in l", NULL},/* if 0, is LMAX+1 */ 
   {ARG_TIME,   "TSTART",   NULL,          "start time of first output record"},
   {ARG_STRING, "TTOTAL",   NULL,          "total length of time in output"},
   {ARG_STRING, "TCHUNK",   kNOTSPECIFIED, "length of output timeseries"},

#include "saveparm.c"
#include "timing.c"
#include "set_history.c"
#include "calversfunctions.c"

#include "jretile_manytofew.c"
#include "jretile_fewtomany.c"

int DoIt(void)

  int status=0;
  char *inrecquery = NULL, *outseries = NULL;
  int lmin,lmax,lchunksize,lchunkfirst,lchunklast,nlchunks,ntimechunks,nrecsin,nrecsout;
  double nseconds,chunksecs;
  char *ttotal, *tchunk;
  DRMS_Record_t *tempoutrec = NULL;
//  DRMS_RecordSet_t *inrecset = NULL;
  int verbflag;

  inrecquery = (char *)cmdparams_get_str(&cmdparams, "in", &status);
  outseries = (char *)cmdparams_get_str(&cmdparams, "out", &status);
  lmin=cmdparams_get_int(&cmdparams, "LMIN", &status);
  lmax=cmdparams_get_int(&cmdparams, "LMAX", &status);
  lchunksize=cmdparams_get_int(&cmdparams, "LCHUNK", &status);
  if (lchunksize == 0)
  verbflag = cmdparams_get_int(&cmdparams, "VERB", &status);

  ttotal=(char *)cmdparams_get_str(&cmdparams, "TTOTAL", &status);
  status=drms_names_parseduration(&ttotal, &nseconds, 1);
  tchunk=(char *)cmdparams_get_str(&cmdparams, "TCHUNK", &status);
  if (strcmp(kNOTSPECIFIED, tchunk))
    status=drms_names_parseduration(&tchunk, &chunksecs, 1);

  tempoutrec = drms_create_record(drms_env, outseries, DRMS_TRANSIENT, &status);
  if (status != DRMS_SUCCESS) 
   fprintf(stderr,"ERROR: couldn't open a record in output dataseries %s, status = %d\n", outseries, status);
   return 1;

  char *outchecklist[] = {"T_START", "QUALITY", "LMIN", "LMAX", "NDT"};
  DRMS_Keyword_t *outkeytest;
  int itest;
  for (itest=0; itest < ARRLENGTH(outchecklist); itest++)
    outkeytest = hcon_lookup_lower(&tempoutrec->keywords, outchecklist[itest]);
    if (outkeytest == NULL || outkeytest->info->islink || outkeytest->info->recscope == 1)
      fprintf(stderr, "ERROR: output keyword %s is either missing, constant, or a link\n", outchecklist[itest]);
      drms_close_record(tempoutrec, DRMS_FREE_RECORD);
      return 1;

  if (chunksecs == 0.0)
    chunksecs = drms_getkey_float(tempoutrec, "T_START_step", &status);
  drms_close_record(tempoutrec, DRMS_FREE_RECORD);

  inrecset = drms_open_recordset(drms_env, inrecquery, &status);
  if (status != DRMS_SUCCESS || inrecset == NULL)
    fprintf(stderr, "ERROR: problem opening input recordset: status = %d\n", status);
    return 1;
  nrecsin = inrecset->n;
  drms_close_records(inrecset, DRMS_FREE_RECORD);
  nrecsin = drms_count_records(drms_env, inrecquery, &status);
  if (status != DRMS_SUCCESS)
    fprintf(stderr, "ERROR: problem counting input records: status = %d, nrecs = %d\n", status, nrecsin);
    return 1;

  lchunkfirst = lmin/lchunksize;
  lchunklast = lmax/lchunksize;
  nlchunks = (lchunklast - lchunkfirst) + 1;
  nrecsout = nlchunks*ntimechunks;

  if (verbflag)
    printf("nrecsin = %d, nrecsout = %d, ", nrecsin, nrecsout);

  if (nrecsin > nrecsout)
    if (verbflag)
      printf("using jretile_manytofew()\n");
    if (verbflag)
      printf("using jretile_fewtomany()\n");

  return status;


Karen Tian
Powered by
ViewCVS 0.9.4