IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 33207


Ignore:
Timestamp:
Feb 7, 2012, 11:48:36 AM (14 years ago)
Author:
eugene
Message:

working on dvodist

Location:
branches/eam_branches/ipp-20111122/Ohana/src/photdbc
Files:
4 added
4 edited
1 moved

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20111122/Ohana/src/photdbc/src/AssignSkyToHost.c

    r33206 r33207  
    2929    }
    3030
    31 
    32 
    3331    // assign all regions to one of the Nhost hosts
    3432    int N = MAX(table->Nhosts - 1, table->Nhosts * drand48());
  • branches/eam_branches/ipp-20111122/Ohana/src/photdbc/src/CopyToHostLocation.c

    r33206 r33207  
    11# include "photdbc.h"
    2 # include <md5.h>
    3 # include <unistd.h> // needed?
    42
    53# define DEBUG 1
    6 # define NBUFFER 512
    7 # define NDIGEST  16
    8 
    9 # define DATA_ON_TGT       0x4000
    10 # define DATA_COPY_FAILURE 0x8000
    11 # define DATA_HOST_ID      0x3fff
    124
    135int CostToHostLocation (SkyList *skylist, HostTable *table) {
     
    8577       
    8678      // need to re-open and re-read tgtname to check md5sum
     79      md5_byte_t tgtDigest[NDIGEST];
    8780      get_md5_with_copy (tgtname, NULL, tgtDigest);
    8881
     
    141134*/
    142135
    143 // read a file, get the md5 sum, optionally write to 'output'
    144 int get_md5_with_copy (char *input, char *output, md5_byte_t *digest) {
    145 
    146   // open the src file
    147   FILE *fInput = fopen (input, "r");
    148   int fdInput = fileno (fInput);
    149        
    150   // open the tgt file
    151   FILE *fOutput = NULL;
    152   int fdOutput = 0;
    153   if (output) {
    154     fOutput = fopen (tgtname, "w");
    155     fdOutput = fileno (fOutput);
    156   }
    157 
    158   int nbytes;
    159   md5_state_t state;
    160   md5_byte_t buffer[NBUFFER];
    161 
    162   md5_init (&state);
    163   while ((nbytes = read (fdInput, buffer, NBUFFER)) > 0) {
    164     md5_append (&state, buffer, nbytes);
    165     if (output) {
    166       nbytes = write (fdOutput, buffer, NBUFFER);
    167       // XXX check that we actually write out all nbytes...
    168     }
    169   }
    170   md5_finish(&state, digest);
    171        
    172   fclose (fInput);
    173   flush (fInput);
    174 
    175   if (output) {
    176     fclose (fOutput);
    177     flush (fOutput);
    178   }
    179   return TRUE;
    180 }
    181 
    182136/* need to think a bit about behavior in the context of SPLIT vs MEF:
    183137
  • branches/eam_branches/ipp-20111122/Ohana/src/photdbc/src/HostTableLoad.c

    r33204 r33207  
    11# include "photdbc.h"
    22# define DEBUG 1
    3 
    4 typedef struct {
    5   char *hostname;
    6   char *pathname;
    7   int hostID;
    8 } HostInfo
    9 
    10 typedef struct {
    11     int Nhosts;
    12   HostInfo *hosts;
    13 } HostTable
    143
    154void InitHosts (HostInfo *hosts, int Nhosts, int NHOSTS) {
     
    3423}
    3524
    36 HostTable *HostTableLoad () {
     25HostTable *HostTableLoad (char *catdir) {
     26
     27  char *filename = NULL;
     28
     29  ALLOCATE (filename, char, strlen(catdir) + strlen("/HostTable.dat") + 1);
     30  sprintf (filename, "%s/HostTable.dat", catdir);
    3731
    3832  FILE *f = fopen (filename, "r");
  • branches/eam_branches/ipp-20111122/Ohana/src/photdbc/src/dvodist.c

    r33206 r33207  
    1 # include "photdbc.h"
     1# include "dvodist.h"
    22
    33int main (int argc, char **argv) {
     
    88
    99  /* get configuration info, args, lockfile */
    10   initialize_dvodist (argc, argv);
     10  initialize (argc, argv);
     11  char *catdir = strcreate (argv[1]);
     12
     13  LockDatabase (catdir);
    1114
    1215  // dvodist (-out | -in)
    1316  // dvodist -out : host table represents new target locations
    1417 
    15   hosts = HostTableLoad ();
     18  HostTable *hosts = HostTableLoad (catdir);
     19  if (NULL) {
     20    Shutdown ("failed to load Host Table for %s\n", catdir);
     21  }
    1622
    17   // the output catalog needs to inherit the SKY_DEPTH of the input catalog
    18   sky = SkyTableLoadOptimal (CATDIR, NULL, GSCFILE, TRUE, SKY_DEPTH_HST, VERBOSE);
    19   SkyTableSetFilenames (sky, CATDIR, "cpt");
    20   skylist = SkyListByPatch (sky, -1, &REGION);
     23  // load the current SkyTable. If SkyTable does not exist, we must fail
     24  sky = SkyTableLoadOptimal (catdir, NULL, NULL, TRUE, SKY_DEPTH_HST, VERBOSE);
     25  SkyTableSetFilenames (sky, catdir, "cpt");
     26  skylist = SkyListByPatch (sky, -1, &UserPatch);
    2127
    22   AssignSkyToHost (skylist, hosts);
     28  switch (MODE) {
     29    case MODE_OUT:
     30      AssignSkyToHost (skylist, hosts);
     31      CopyToHostLocation (skylist, hosts);
     32      break;
     33    case MODE_IN:
     34      CopyFromHostLocation (skylist, hosts);
     35      break;
     36    default:
     37      fprintf (stderr, "impossible!");
     38      abort();
     39  }
    2340
    24   CopyToHostLocation (skylist, hosts);
    25 
     41  // XXX probably need to make this a skyregion_io.c function
     42  // char *SkyTableFilename (char *catdir);
    2643  char *skyfile;
    2744  ALLOCATE (skyfile, char, strlen(catdir) + strlen("/SkyTable.fits") + 1);
     
    3148  exit (0);
    3249}
     50
     51/* things still missing AFAIK :
     52
     53 * switch based on MODE
     54 * add header keyword to SkyTable to note existence of hostID
     55 * code for CopyFromHostLocation
     56 
     57 */
  • branches/eam_branches/ipp-20111122/Ohana/src/photdbc/src/initialize_dvodist.c

    r33206 r33207  
    1 # include "photdbc.h"
     1# include "dvodist.h"
    22
    3 void initialize_dvodist (int argc, char **argv) {
     3void initialize (int argc, char **argv) {
    44
    55  /* are these set correctly? */
    6   if (get_argument (argc, argv, "-h")) usage_dvodist();
    7   if (get_argument (argc, argv, "--h")) usage_dvodist();
    8   if (get_argument (argc, argv, "-help")) usage_dvodist();
    9   if (get_argument (argc, argv, "--help")) usage_dvodist();
     6  if (get_argument (argc, argv, "-h")) usage();
     7  if (get_argument (argc, argv, "--h")) usage();
     8  if (get_argument (argc, argv, "-help")) usage();
     9  if (get_argument (argc, argv, "--help")) usage();
    1010
    1111  // XXX anything? ConfigInit (&argc, argv);
     
    1313}
    1414
    15 void usage_dvodist() {
     15void usage() {
    1616
    1717  fprintf (stderr, "USAGE: dvodist (-out | -in) (catdir)\n\n");
     
    3636
    3737  /* specify portion of the sky */
    38   REGION.Rmin = 0;
    39   REGION.Rmax = 360;
    40   REGION.Dmin = -90;
    41   REGION.Dmax = +90;
     38  UserPatch.Rmin = 0;
     39  UserPatch.Rmax = 360;
     40  UserPatch.Dmin = -90;
     41  UserPatch.Dmax = +90;
    4242  if ((N = get_argument (argc, argv, "-region"))) {
    4343    remove_argument (N, &argc, argv);
    44     REGION.Rmin = atof (argv[N]);
     44    UserPatch.Rmin = atof (argv[N]);
    4545    remove_argument (N, &argc, argv);
    46     REGION.Rmax = atof (argv[N]);
     46    UserPatch.Rmax = atof (argv[N]);
    4747    remove_argument (N, &argc, argv);
    48     REGION.Dmin = atof (argv[N]);
     48    UserPatch.Dmin = atof (argv[N]);
    4949    remove_argument (N, &argc, argv);
    50     REGION.Dmax = atof (argv[N]);
     50    UserPatch.Dmax = atof (argv[N]);
    5151    remove_argument (N, &argc, argv);
    5252
    53     if (REGION.Rmin == REGION.Rmax) {
     53    if (UserPatch.Rmin == UserPatch.Rmax) {
    5454      fprintf (stderr, "ERROR: selected region is ill-defined: Rmin == Rmax\n");
    5555      exit (2);
    5656    }
    57     if (REGION.Dmin == REGION.Dmax) {
     57    if (UserPatch.Dmin == UserPatch.Dmax) {
    5858      fprintf (stderr, "ERROR: selected region is ill-defined: Dmin == Dmax\n");
    5959      exit (2);
     
    6161  }
    6262
    63   MODE = 0;
     63  MODE = MODE_NONE;
    6464  if ((N = get_argument (argc, argv, "-in"))) {
    65     MODE = COPY_IN;
     65    MODE = MODE_IN;
    6666    remove_argument (N, &argc, argv);
    6767  }
     
    6969    if (!MODE) {
    7070      fprintf (stderr, "ERROR: cannot use both -in and -out options!\n");
    71       usage_dvodist();
     71      usage();
    7272    }
    73     MODE = COPY_OUT;
     73    MODE = MODE_OUT;
    7474    remove_argument (N, &argc, argv);
    7575  }
     76  if (!MODE) usage();
    7677
    7778  if (argc != 2) usage();
Note: See TracChangeset for help on using the changeset viewer.