(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.12, Fri Jun 6 12:04:19 2014 UTC (4 years, 4 months ago) by tplarson
Branch: MAIN
CVS Tags: globalhs_version_9, globalhs_version_8, globalhs_version_7, globalhs_version_6, globalhs_version_5, globalhs_version_4, globalhs_version_19, globalhs_version_18, globalhs_version_17, globalhs_version_16, globalhs_version_15, globalhs_version_14, globalhs_version_13, globalhs_version_12, globalhs_version_11, globalhs_version_10, Ver_LATEST, Ver_9-2, Ver_9-1, Ver_9-0, Ver_8-8, Ver_8-7, Ver_8-6, Ver_8-5, Ver_8-12, Ver_8-11, Ver_8-10, HEAD
Changes since 1.11: +31 -7 lines
add option to force use of particular retile routine, default to jretile_maxmem()

/* 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.12 2014/06/06 13:04:19 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,    "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."},  
   {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"},
   {ARG_END}
};

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

#include "jretile_manytofew.c"
#include "jretile_fewtomany.c"
#include "jretile_maxmem.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, memflag;

  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)
    lchunksize=lmax+1;
  verbflag = cmdparams_get_int(&cmdparams, "VERB", &status);
  memflag = cmdparams_get_int(&cmdparams, "MEMUSE", &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);
  }
  else
    chunksecs=0;

  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;
  }

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

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

  if (memflag==0)
  {
    if (nrecsin > nrecsout)
    {
      if (verbflag)
        printf("using jretile_manytofew()\n");
      status=jretile_manytofew();
    }
    else
    {
      if (verbflag)
        printf("using jretile_fewtomany()\n");
      status=jretile_fewtomany();
    }
  }
  else if (memflag==1)
  {
    if (verbflag)
      printf("forced use of jretile_fewtomany()\n");
    status=jretile_fewtomany();
  }
  else if (memflag==2)
  {
    if (verbflag)
      printf("forced use of jretile_manytofew()\n");
    status=jretile_manytofew();
  }
  else if (memflag==3)
  {
    if (verbflag)
      printf("using jretile_maxmem()\n");
    status=jretile_maxmem();
  }

  return status;

}

Karen Tian
Powered by
ViewCVS 0.9.4