IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 39478


Ignore:
Timestamp:
Mar 23, 2016, 12:34:01 PM (10 years ago)
Author:
eugene
Message:

free memory; elevate the sky, skylist loads out of relphot_objects and load_images

Location:
trunk/Ohana/src/relphot
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/relphot/Makefile

    r38062 r39478  
    9292$(SRC)/initialize.$(ARCH).o      \
    9393$(SRC)/syncfile.$(ARCH).o        \
     94$(SRC)/select_images.$(ARCH).o   \
     95$(SRC)/load_images.$(ARCH).o     \
    9496$(SRC)/load_catalogs.$(ARCH).o   \
    9597$(SRC)/reload_catalogs.$(ARCH).o \
  • trunk/Ohana/src/relphot/include/relphot.h

    r39464 r39478  
    418418Catalog      *load_catalogs_parallel PROTO((SkyList *sky, int *Ncatalog, char *syncfile));
    419419
    420 SkyList      *load_images         PROTO((FITS_DB *db, char *regionName, SkyRegion *region));
     420SkyList      *load_images         PROTO((FITS_DB *db, SkyTable *sky, char *regionName, SkyRegion *region));
    421421Image        *select_images       PROTO((SkyList *skylist, Image *timage, off_t Ntimage, char *inSubset, off_t **LineNumber, off_t *Nimage, SkyRegion *region));
    422422
     
    475475void          wimages             PROTO((void));
    476476void          write_coords        PROTO((Header *header, Coords *coords));
    477 int relphot_objects (int hostID, char *hostpath);
     477int relphot_objects (SkyTable *sky, SkyList *skylist, int hostID, char *hostpath);
    478478int relphot_images (void);
    479479
     
    597597int getMosaicFlags (off_t meas, int cat);
    598598
     599void relphot_free (SkyTable *sky, SkyList *skylist);
     600void freeImages ();
     601void relphot_client_free (SkyTable *sky, SkyList *skylist);
     602void BrightCatalogFree (BrightCatalog *bcatalog);
     603
     604void free_astrom_table ();
  • trunk/Ohana/src/relphot/src/BrightCatalog.c

    r39262 r39478  
    547547}
    548548
     549void BrightCatalogFree (BrightCatalog *bcatalog) {
     550  if (!bcatalog) return;
     551  FREE (bcatalog[0].average);
     552  FREE (bcatalog[0].measure);
     553  FREE (bcatalog[0].secfilt);
     554  FREE (bcatalog);
     555  return;
     556}
     557
    549558// distribute a bright catalog across separate catalogs
    550559CatalogSplitter *BrightCatalogSplitInit (int Nsecfilt) {
  • trunk/Ohana/src/relphot/src/ConfigInit.c

    r34749 r39478  
    7373  SetZeroPoint (ZERO_POINT);
    7474
     75  FreeConfigFile();
    7576  free (config);
    7677  free (file);
  • trunk/Ohana/src/relphot/src/ImageOps.c

    r39457 r39478  
    265265    free (N_ONIMAGE);
    266266  }
     267}
     268
     269void freeImages () {
     270
     271  FREE (image);
     272  FREE (LineNumber);
     273
     274  FREE (imageIDs);
     275  FREE (imageIdx);
     276
     277  FREE (tessID);
     278  FREE (projectID);
     279  FREE (skycellID);
     280
     281  free_astrom_table();
    267282}
    268283
  • trunk/Ohana/src/relphot/src/ImageSubset.c

    r37037 r39478  
    4343  if (!gfits_load_header (f, &theader)) {
    4444    fclose (f);
     45    gfits_free_header (&header);
     46    gfits_free_matrix (&matrix);
    4547    return NULL;
    4648  }
     
    4951  if (!gfits_fread_ftable_data (f, &ftable, FALSE)) {
    5052    fclose (f);
     53    gfits_free_header (&theader);
     54    gfits_free_header (&header);
     55    gfits_free_matrix (&matrix);
    5156    return (NULL);
    5257  }
     
    100105  free (ucdist);
    101106
     107  gfits_free_header (&header);
     108  gfits_free_matrix (&matrix);
     109  gfits_free_header (&theader);
     110  gfits_free_table  (&ftable);
     111
    102112  *nimage = Nrow;
    103113  return image;
  • trunk/Ohana/src/relphot/src/MosaicOps.c

    r39457 r39478  
    313313  fprintf (stderr, "matched %d images to %d mosaics, %d simple chips not matched to mosaics\n", (int) (Nsubset - Nsimple), (int) Nmosaic, (int) Nsimple);
    314314  return;
     315}
     316
     317void freeMosaics () {
    315318}
    316319
  • trunk/Ohana/src/relphot/src/StarOps.c

    r39464 r39478  
    302302
    303303  SetMrelInfoFree (&results);
     304  SetMrelInfoFree (&summary);
    304305
    305306  return (TRUE);
     
    324325
    325326  SetMrelInfoFree (&results);
     327  SetMrelInfoFree (&summary);
    326328  return (TRUE);
    327329}
     
    387389             threadinfo[i].summary.Nsys);
    388390    SetMrelInfoAccum (&summary, &threadinfo[i].summary);
     391    SetMrelInfoFree (&threadinfo[i].summary);
    389392  }
    390393  if (VERBOSE2) fprintf (stderr, "total : %d stars with no data in photcode, %d stars marked having too few measurements (Nbad: %d, Ncal: %d, Nmos: %d, Ngrid: %d, Nsys: %d)\n", summary.Ncode, summary.Nfew, summary.Nbad, summary.Ncal, summary.Nmos, summary.Ngrid, summary.Nsys);
    391394  free (threadinfo);
    392395
     396  SetMrelInfoFree (&summary);
    393397  return TRUE;
    394398}
     
    407411    if (i == -1) {
    408412      threadinfo->state = THREAD_DONE;
     413      SetMrelInfoFree (&results);
    409414      return NULL;
    410415    }
  • trunk/Ohana/src/relphot/src/args.c

    r39345 r39478  
    441441  }
    442442
     443  PhotcodeList = NULL;
     444  photcodes = NULL;
    443445  switch (mode) {
    444446    case SYNTH_PHOT:
     
    450452    case PARALLEL_IMAGES:
    451453    case PARALLEL_REGIONS:
     454    case APPLY_OFFSETS:
    452455      PhotcodeList = strcreate (argv[1]);
    453456      photcodes = ParsePhotcodeList (PhotcodeList, &Nphotcodes, TRUE); // require SEC photcodes
     
    465468}
    466469
     470// XXX need to free sky
     471void relphot_free (SkyTable *sky, SkyList *skylist) {
     472  FREE (UserCatalog);
     473  FREE (OUTROOT);
     474  FREE (UPDATE_CATFORMAT);
     475
     476  FREE (BOUNDARY_TREE);
     477  FREE (REGION_FILE);
     478  FREE (SYNTH_ZERO_POINTS);
     479  FREE (IMAGE_TABLE);
     480  FREE (CATDIR);
     481
     482  FREE (PhotcodeList);
     483  FREE (photcodes);
     484 
     485  SkyTableFree (sky);
     486  SkyListFree(skylist);
     487  FreePhotcodeTable();
     488 
     489  ohana_memcheck (VERBOSE);
     490  ohana_memdump (VERBOSE);
     491}
     492
    467493int args_client (int argc, char **argv) {
    468494
     
    470496  double trange;
    471497
    472   // by definition, the client is not parallel
     498 // by definition, the client is not parallel
    473499  PARALLEL = FALSE;
    474500  PARALLEL_MANUAL = FALSE;
     
    722748}
    723749
     750// XXX need to free sky
     751void relphot_client_free (SkyTable *sky, SkyList *skylist) {
     752  FREE (HOSTDIR);
     753  FREE (BCATALOG);
     754  FREE (IMAGES);
     755
     756  FREE (SYNTH_ZERO_POINTS);
     757  FREE (BOUNDARY_TREE);
     758  FREE (UPDATE_CATFORMAT);
     759
     760  FREE (CATDIR);
     761  FREE (PhotcodeList);
     762  FREE (photcodes);
     763 
     764  SkyTableFree (sky);
     765  SkyListFree(skylist);
     766  FreePhotcodeTable();
     767 
     768  ohana_memcheck (VERBOSE);
     769  ohana_memdump (VERBOSE);
     770}
     771
     772
  • trunk/Ohana/src/relphot/src/bcatalog.c

    r39341 r39478  
    239239  }
    240240
     241  free (Nvalid)
     242
    241243  return (TRUE);
    242244}
  • trunk/Ohana/src/relphot/src/client_logger.c

    r36630 r39478  
    2727int client_logger_message (char *format,...) {
    2828
     29  if (!logfile) return FALSE;
     30
    2931  va_list argp;
    3032
  • trunk/Ohana/src/relphot/src/initialize.c

    r39377 r39478  
    9292
    9393  // XXX need to determine which globals can affect relphot_client in either mode and pass appropriately
     94  PhotcodeList = NULL;
     95  photcodes = NULL;
    9496
    9597  relphot_client_help (argc, argv);
  • trunk/Ohana/src/relphot/src/load_catalogs.c

    r38986 r39478  
    176176    fprintf (stderr, "command: %s\n", command);
    177177
    178     if (PARALLEL_MANUAL) continue;
     178    if (PARALLEL_MANUAL) {
     179      free (command);
     180      continue;
     181    }
    179182
    180183    if (PARALLEL_SERIAL) {
     
    194197      table->hosts[i].pid = pid; // save for future reference
    195198    }
     199    free (command);
    196200  }
    197201
     
    254258  *Ncatalog = catalogs->Ncatalog;
    255259
     260  // need to free the place-holder catalogs:
     261  for (i = catalogs->Ncatalog; i < catalogs->NCATALOG; i++) {
     262    free (catalogs->catalog[i].averageT);
     263    free (catalogs->catalog[i].measureT);
     264    free (catalogs->catalog[i].secfilt);
     265  }
     266
    256267  int Nmeasure = 0;
    257268  int Naverage = 0;
     
    265276
    266277  BrightCatalogSplitFree (catalogs);
     278  FreeHostTable (table);
    267279
    268280  return (catalog);
  • trunk/Ohana/src/relphot/src/load_images.c

    r38986 r39478  
    11# include "relphot.h"
     2
     3static AstromOffsetTable *table = NULL;
    24
    35// This function generates a subset of the images based on selections.  Input db has already
    46// been loaded with the raw fits table data
    5 SkyList *load_images (FITS_DB *db, char *regionName, SkyRegion *region) {
     7SkyList *load_images (FITS_DB *db, SkyTable *sky, char *regionName, SkyRegion *region) {
    68
    79  Image     *image, *subset;
     
    1012  char *inSubset;
    1113
    12   SkyTable *sky = NULL;
    1314  SkyList *skylist = NULL;
    1415
    1516  INITTIME;
    1617
    17   // load the current sky table (layout of all SkyRegions)
    18   sky = SkyTableLoadOptimal (CATDIR, SKY_TABLE, GSCFILE, TRUE, SKY_DEPTH, VERBOSE);
    19   SkyTableSetFilenames (sky, CATDIR, "cpt");
    20  
    2118  // convert database table to internal structure (binary to Image)
    2219  // 'image' points to the same memory as db->ftable->buffer
     
    3532  char mapfile[DVO_MAX_PATH];
    3633  snprintf (mapfile, DVO_MAX_PATH, "%s/AstroMap.fits", CATDIR);
    37   AstromOffsetTable *table = AstromOffsetMapLoad (mapfile, 100000, VERBOSE);
     34  table = AstromOffsetMapLoad (mapfile, 100000, VERBOSE);
    3835
    3936  // assign images.coords.offsetMap -> table->map[i]
     
    117114  initMosaics (subset, Nsubset, image, inSubset, Nimage);
    118115  MARKTIME("init mosaics: %f sec\n", dtime);
     116  free (inSubset);
    119117 
    120118  // save the subset of images in the static reference in ImageOps, set up indexes
     
    142140  return (TRUE);
    143141}
     142
     143void free_astrom_table () {
     144  if (!table) return;
     145  AstromOffsetTableFree (table);
     146  free (table);
     147}
  • trunk/Ohana/src/relphot/src/reload_catalogs.c

    r38986 r39478  
    152152    }
    153153    free (image);
    154   } else {
    155     // load the current sky table (layout of all SkyRegions)
    156     SkyTable *skytable = SkyTableLoadOptimal (CATDIR, SKY_TABLE, GSCFILE, TRUE, SKY_DEPTH, VERBOSE);
    157     // XXX kind of hackish...
    158     ALLOCATE (sky, SkyList, 1);
    159     strcpy (sky->hosts, skytable->hosts);
     154//  } else {
     155//    // load the current sky table (layout of all SkyRegions)
     156//    SkyTable *skytable = SkyTableLoadOptimal (CATDIR, SKY_TABLE, GSCFILE, TRUE, SKY_DEPTH, VERBOSE);
     157//    // XXX kind of hackish...
     158//    ALLOCATE (sky, SkyList, 1);
     159//    strcpy (sky->hosts, skytable->hosts);
     160//    SkyTableFree (skytable);
    160161  }
    161162
     
    189190    reload_catalog_parallel_group (&groups[i], sky, imageFile);
    190191  }
     192
     193  for (i = 0; i < Ngroups; i++) {
     194    free (groups[i].hosts);
     195  }
     196  free (groups);
     197  FreeHostTable (table);
     198
    191199  return TRUE;
    192200}
     
    264272    fprintf (stderr, "command: %s\n", command);
    265273
    266     if (PARALLEL_MANUAL) continue;
     274    if (PARALLEL_MANUAL) {
     275      free (command);
     276      continue;
     277    }
    267278
    268279    if (PARALLEL_SERIAL) {
     
    282293      group->hosts[i][0].pid = pid; // save for future reference
    283294    }
     295    free (command);
    284296  }
    285297
  • trunk/Ohana/src/relphot/src/relphot.c

    r38986 r39478  
    22
    33int main (int argc, char **argv) {
     4
     5  SkyTable *sky = NULL;
     6  SkyList *skylist = NULL;
    47
    58  // get configuration info, args
     
    1720      // take the current set of detections and set the mean magnitudes
    1821      // DOES NOT LOAD THE IMAGE TABLE
    19       relphot_objects (0, NULL);
     22      sky = SkyTableLoadOptimal (CATDIR, NULL, NULL, TRUE, -1, VERBOSE);
     23      if (!sky) {
     24        fprintf (stderr, "ERROR running loading sky table from %s\n", CATDIR);
     25        exit (2);
     26      }
     27      SkyTableSetFilenames (sky, CATDIR, "cpt");
     28     
     29      skylist = SkyListByPatch (sky, -1, &UserPatch);
     30      if (!skylist) {
     31        fprintf (stderr, "ERROR setting up skylist for %s\n", CATDIR);
     32        exit (2);
     33      }
     34      relphot_objects (sky, skylist, 0, NULL);
     35      relphot_free (sky, skylist);
    2036      exit (0);
    2137
     
    2339      // set the mean magnitudes ONLY for SYNPHOT objects
    2440      relphot_synthphot (0, NULL);
     41      relphot_free (NULL, NULL);
    2542      exit (0);
    2643
     
    2845      // run image updates in parallel across multiple remote machines
    2946      relphot_parallel_regions ();
     47      relphot_free (NULL, NULL);
    3048      exit (0);
    3149
     
    3351      // operation on the remote machines in the PARALLEL_REGION mode
    3452      relphot_parallel_images ();
     53      relphot_free (NULL, NULL);
    3554      exit (0);
    3655
     
    4160        exit (2);
    4261      }
    43       reload_catalogs (NULL, NULL, 0, NULL);
     62
     63      sky = SkyTableLoadOptimal (CATDIR, NULL, NULL, TRUE, -1, VERBOSE);
     64      if (!sky) {
     65        fprintf (stderr, "ERROR running loading sky table from %s\n", CATDIR);
     66        exit (2);
     67      }
     68      SkyTableSetFilenames (sky, CATDIR, "cpt");
     69     
     70      skylist = SkyListByPatch (sky, -1, &UserPatch);
     71      if (!skylist) {
     72        fprintf (stderr, "ERROR setting up skylist for %s\n", CATDIR);
     73        exit (2);
     74      }
     75
     76      reload_catalogs (skylist, NULL, 0, NULL);
     77      relphot_free (sky, skylist);
    4478      exit (0);
    4579
  • trunk/Ohana/src/relphot/src/relphot_client.c

    r39289 r39478  
    2222  client_logger_init (HOSTDIR);
    2323
    24   // load the current sky table (layout of all SkyRegions)
     24  // load the current sky table (layout of all SkyRegions) if needed
    2525  SkyTable *sky = SkyTableLoadOptimal (CATDIR, NULL, NULL, TRUE, -1, VERBOSE);
    2626  if (!sky) {
    27       fprintf (stderr, "ERROR running loading sky table from %s\n", CATDIR);
    28       exit (2);
     27    fprintf (stderr, "ERROR running loading sky table from %s\n", CATDIR);
     28    exit (2);
    2929  }
    3030  SkyTableSetFilenames (sky, CATDIR, "cpt");
    31 
     31     
    3232  SkyList *skylist = SkyListByPatch (sky, -1, &UserPatch);
    3333  if (!skylist) {
    34       fprintf (stderr, "ERROR setting up skylist for %s\n", CATDIR);
    35       exit (2);
     34    fprintf (stderr, "ERROR setting up skylist for %s\n", CATDIR);
     35    exit (2);
    3636  }
    3737  client_logger_message ("loaded sky table and defined patch\n");
     
    5454          exit (2);
    5555      }
     56
     57      // free memory associated with the catalogs
     58      for (int i = 0; i < Ncatalog; i++) {
     59        free_tiny_values (&catalog[i]);
     60        dvo_catalog_free (&catalog[i]);
     61      }
     62      free (catalog);
     63      BrightCatalogFree (bcatalog);
    5664      client_logger_message ("generated subset table\n");
     65      relphot_client_free (sky, skylist);
    5766      break;
    5867    }
     
    7281
    7382      // load the flat-field correction table from CATDIR
    74 # if (0)
    75       char flatcorrFile[1024];
    76       snprintf (flatcorrFile, 1024, "%s/flatcorr.fits", CATDIR);
    77       FlatCorrectionTable *flatcorr = FlatCorrectionLoad (flatcorrFile, VERBOSE);
    78       client_logger_message ("loaded flat-field correction data\n");
    79 # endif
    8083      FlatCorrectionTable *flatcorr = NULL;
    8184      reload_catalogs (skylist, flatcorr, HOST_ID, HOSTDIR);
     85      freeImages ();
     86      free (image);
    8287      client_logger_message ("updated catalogs\n");
     88      relphot_client_free (sky, skylist);
    8389      break;
    8490    }
    8591
    8692    case MODE_UPDATE_OBJECTS: {
    87       relphot_objects (HOST_ID, HOSTDIR);
     93      relphot_objects (sky, skylist, HOST_ID, HOSTDIR);
     94      relphot_client_free (sky, skylist);
    8895      client_logger_message ("updated objects\n");
    8996      break;
     
    101108  }
    102109  client_logger_message ("done with relphot_client\n");
    103 
    104110  exit (0);
    105111}
  • trunk/Ohana/src/relphot/src/relphot_images.c

    r39377 r39478  
    1212  Catalog *catalog = NULL;
    1313  FITS_DB db;
    14   SkyList *skylist = NULL;
    1514
    1615  INITTIME;
     16
     17  // load the current sky table (layout of all SkyRegions)
     18  SkyTable *sky = SkyTableLoadOptimal (CATDIR, SKY_TABLE, GSCFILE, TRUE, SKY_DEPTH, VERBOSE);
     19  SkyTableSetFilenames (sky, CATDIR, "cpt");
    1720
    1821  /* register database handle with shutdown procedure */
     
    4043
    4144  /* load regions and images based on specified sky patch and/or catalog */
    42   skylist = load_images (&db, UserCatalog, &UserPatch);
     45  SkyList *skylist = load_images (&db, sky, UserCatalog, &UserPatch);
    4346  MARKTIME("-- load images: %f sec\n", dtime);
    4447
     
    219222      dvo_image_save (&dbX, VERBOSE);
    220223      dvo_image_unlock (&dbX);
     224      gfits_db_free (&dbX);
    221225      MARKTIME("-- save Image.dat.bck: %f sec\n", dtime);
    222226    }
     
    228232      dvo_catalog_free (&catalog[i]);
    229233    }
     234    free (catalog);
    230235    freeImageBins (Ncatalog, TRUE);
    231236    freeMosaicBins (Ncatalog, TRUE);
     
    259264  }
    260265  dvo_image_unlock (&db);
    261 
     266  gfits_db_free (&db);
     267  freeImages();
     268
     269  relphot_free (sky, skylist);
    262270  exit (0);
    263271}
  • trunk/Ohana/src/relphot/src/relphot_objects.c

    r39464 r39478  
    88int relphot_objects_parallel (SkyList *sky);
    99
    10 int relphot_objects (int hostID, char *hostpath) {
     10int relphot_objects (SkyTable *sky, SkyList *skylist, int hostID, char *hostpath) {
    1111
    1212  off_t i, j, k;
    1313  int Nsecfilt;
    1414
    15   SkyTable *sky = NULL;
    16   SkyList *skylist = NULL;
    1715  Catalog catalog;
    18 
    19   // load the current sky table (layout of all SkyRegions)
    20   sky = SkyTableLoadOptimal (CATDIR, SKY_TABLE, GSCFILE, TRUE, SKY_DEPTH, VERBOSE);
    21   SkyTableSetFilenames (sky, CATDIR, "cpt");
    22  
    23   // determine the populated SkyRegions overlapping the requested area (default depth)
    24   skylist = SkyListByPatch (sky, -1, &UserPatch);
    2516
    2617  // XXX need to decide how to determine PARALLEL mode...
     
    112103    dvo_catalog_free (&catalog);
    113104  }
    114  
    115105  return (TRUE);
    116106}
     
    169159    fprintf (stderr, "command: %s\n", command);
    170160
    171     if (PARALLEL_MANUAL) continue;
     161    if (PARALLEL_MANUAL) {
     162      free (command);
     163      continue;
     164    }
    172165
    173166    if (PARALLEL_SERIAL) {
     
    187180      table->hosts[i].pid = pid; // save for future reference
    188181    }
     182    free (command);
    189183  }
    190184
     
    197191  }
    198192
     193  FreeHostTable (table);
    199194  return TRUE;
    200195}     
  • trunk/Ohana/src/relphot/src/select_images.c

    r37807 r39478  
    269269  REALLOCATE (line_number, off_t, MAX (nimage, 1));
    270270
     271  FREE (RmaxBand);
     272  FREE (RminBand);
     273
    271274  if (!USE_BASIC_CHECK) {
    272275    free (skycoords);
Note: See TracChangeset for help on using the changeset viewer.