Changeset 40881
- Timestamp:
- Sep 3, 2019, 11:38:21 AM (7 years ago)
- Location:
- branches/eam_branches/ohana.20190329/src/addstar
- Files:
-
- 5 edited
-
include/ukirt_uhs.h (modified) (3 diffs)
-
src/args_loadukirt_uhs.c (modified) (1 diff)
-
src/loadukirt_uhs.c (modified) (1 diff)
-
src/loadukirt_uhs_readstars.c (modified) (9 diffs)
-
src/loadukirt_uhs_table.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ohana.20190329/src/addstar/include/ukirt_uhs.h
r40833 r40881 1 2 # define BUFFER_SIZE 0x100000 3 // # define BUFFER_SIZE 900 1 4 2 5 // measure[1] = J … … 17 20 // AddstarClientOptions args_loadukirt_uhs_client (int *argc, char **argv, AddstarClientOptions options); 18 21 19 int loadukirt_uhs_table ( int Nstart, int Nend, SkyList *skylistInput, HostTable *hosts, char **filename, AddstarClientOptions *options);22 int loadukirt_uhs_table (SkyList *skylistInput, char *filename, AddstarClientOptions *options); 20 23 21 24 UKIRT_UHS_Stars *loadukirt_uhs_make_subset (UKIRT_UHS_Stars *stars, int Nstars, int start, SkyRegion *region, int *nsubset); … … 39 42 // UKIRT_UHS_Stars *loadukirt_uhs_load_stars (char *filename, int *nstars); 40 43 41 UKIRT_UHS_Stars *loadukirt_uhs_readstars ( char *filename, UKIRT_UHS_Stars *stars, int *nstars, AddstarClientOptions *options);44 UKIRT_UHS_Stars *loadukirt_uhs_readstars (FILE *f, char *buffer, int *nstart, AddstarClientOptions *options, int *nstars); 42 45 43 46 int loadukirt_uhs_sortStars (UKIRT_UHS_Stars *stars, int Nstars); -
branches/eam_branches/ohana.20190329/src/addstar/src/args_loadukirt_uhs.c
r40832 r40881 116 116 DUMP = NULL; 117 117 118 if (*argc <2) {119 fprintf (stderr, "USAGE: loadukirt_uhs [options] (fitsfile) [..more files]\n");118 if (*argc != 2) { 119 fprintf (stderr, "USAGE: loadukirt_uhs [options] (fitsfile)\n"); 120 120 exit (2); 121 121 } -
branches/eam_branches/ohana.20190329/src/addstar/src/loadukirt_uhs.c
r40832 r40881 27 27 skylist = SkyListByPatch (sky, -1, &UserPatch); 28 28 29 int Nstart = 1; 30 int Nend = argc; 31 while (Nstart < Nend) { 32 Nstart = loadukirt_uhs_table (Nstart, Nend, skylist, NULL, argv, &options); 33 } 29 loadukirt_uhs_table (skylist, argv[1], &options); 34 30 35 31 SkyTableFree (sky); -
branches/eam_branches/ohana.20190329/src/addstar/src/loadukirt_uhs_readstars.c
r40880 r40881 1 1 # include "addstar.h" 2 2 # include "ukirt_uhs.h" 3 # define NSTARS_MAX 10000000 4 // # define NSTARS_MAX 10 3 5 4 6 /* this function reads the values of interest from the UKIRT UHS CSV files: … … 73 75 lineStatus &= readStatus; FIELD[Nelem] = dvalue; } 74 76 75 UKIRT_UHS_Stars *loadukirt_uhs_readstars (char *filename, UKIRT_UHS_Stars *stars, int *nstars, AddstarClientOptions *options) { 77 static int Nline_read = 0; // track number of lines read so far (use to skip lines as well) 78 static int Nskip = 1; // UKIRT UHS CSV files have a single header row (and no special character to mark) 79 80 UKIRT_UHS_Stars *loadukirt_uhs_readstars (FILE *f, char *buffer, int *nstart, AddstarClientOptions *options, int *nstars) { 76 81 77 82 int codeJ = GetPhotcodeCodebyName ("UKIRT_UHS_J"); if (!codeJ) Shutdown ("missing photcode UKIRT_UHS_J"); … … 80 85 // time_t UKIRT_UHS_EPOCH = ohana_date_to_sec ("2016/01/01,00:00:00"); 81 86 // fprintf (stderr, "WARNING: using an invalid UKIRT_UHS_EPOCH (see loadukirt_uhs_readstars.c:60)\n"); 82 83 // read in the full FITS files84 FILE *f = fopen (filename, "r");85 if (f == NULL) Shutdown ("can't read ukirt_uhs file: %s", filename);86 87 int Nskip = 1; // UKIRT UHS CSV files have a single header row (and no special character to mark)88 87 89 88 int Nelem = 0; // number of valid rows read (vector elements) … … 110 109 ALLOCATE_PTR (jSeqNum, int, NELEM); 111 110 112 // we allocate one extra byte into which we never read so there will always be a NULL terminating the string113 ALLOCATE_PTR (buffer, char, 0x10001);114 bzero (buffer, 0x10001);115 116 int Nline_read = 0; // track number of lines read so far (use to skip lines as well)117 118 111 // we have a working buffer read from the file. we parse the lines in the working buffer 119 112 // until we reach the last chunk without an EOL char. at that point, we shift the start … … 122 115 // we treat \n\r pair as a single EOL char to handle mac files: 123 116 124 int Nstart = 0; // location of the last valid byte in the buffer (start filling here)117 int Nstart = *nstart; // location of the last valid byte in the buffer (start filling here) 125 118 int EndOfFile = FALSE; 126 while (!EndOfFile ) {127 int Nbytes = 0x10000- Nstart;119 while (!EndOfFile && (Nelem < NSTARS_MAX)) { 120 int Nbytes = BUFFER_SIZE - Nstart; 128 121 // we have allocated one extra byte into which we never read so there will always be a NULL terminating the string 129 122 bzero (&buffer[Nstart], Nbytes + 1); … … 133 126 break; 134 127 } 128 135 129 // we still need to parse the rest of the buffer, but there might not be an EOL on the last line 136 130 if (Nread == 0) { … … 187 181 188 182 // the start of the line is the 1st element (fields are 1-counting) 189 jPARSE ( 1, 0, sourceID, "sourceID");183 jPARSE ( 1, 1, sourceID, "sourceID"); 190 184 iPARSE ( 3, 1, frameSetID, "frameSetID"); 191 185 dPARSE ( 4, 3, ra, "ra"); … … 255 249 int NSTARS = Nstars + 0.1*NstarsIn; 256 250 257 if (!stars) { 258 ALLOCATE (stars, UKIRT_UHS_Stars, NSTARS); 259 } else { 260 REALLOCATE (stars, UKIRT_UHS_Stars, NSTARS); 261 } 251 ALLOCATE_PTR (stars, UKIRT_UHS_Stars, NSTARS); 262 252 263 253 for (int i = 0; i < NstarsIn; i++) { … … 336 326 FREE (jSeqNum); 337 327 338 free (buffer);339 340 328 *nstars = Nstars; 329 *nstart = Nstart; 341 330 return (stars); 342 331 } -
branches/eam_branches/ohana.20190329/src/addstar/src/loadukirt_uhs_table.c
r40832 r40881 1 1 # include "addstar.h" 2 2 # include "ukirt_uhs.h" 3 # define NSTARS_MAX 10000004 3 5 int loadukirt_uhs_table (int Nstart, int Nend, SkyList *skylistInput, HostTable *hosts, char **filename, AddstarClientOptions *options) { 6 OHANA_UNUSED_PARAM(hosts); 4 // one pass reads a single file at a time 5 int loadukirt_uhs_table (SkyList *skylistInput, char *filename, AddstarClientOptions *options) { 7 6 8 int i; 7 // open the input file here and pass the pointer below 8 FILE *f = fopen (filename, "r"); 9 if (f == NULL) Shutdown ("can't read ukirt_uhs file: %s", filename); 9 10 10 int Nstars = 0; 11 UKIRT_UHS_Stars *stars = NULL; 12 for (i = Nstart; (Nstars < NSTARS_MAX) && (i < Nend); i++) { 13 // read the next file and append to the current set of stars 14 fprintf (stderr, "loading %s\n", filename[i]); 15 stars = loadukirt_uhs_readstars (filename[i], stars, &Nstars, options); 16 } 17 Nstart = i; // we pass back the entry for the next file to be read 18 if (!stars) return Nstart; 11 // we allocate one extra byte into which we never read so there will always be a NULL terminating the string 12 ALLOCATE_PTR (buffer, char, BUFFER_SIZE + 1); 13 bzero (buffer, BUFFER_SIZE + 1); 19 14 20 fprintf (stderr, "writing %d stars to dvo\n", Nstars); 15 // starting point of valid data in buffer; this is updated on each pass to readstars 16 int Nstart = 0; 21 17 22 // sort the stars by RA 23 loadukirt_uhs_sortStars (stars, Nstars); 18 while (1) { 24 19 25 // scan through the stars, loading the containing catalogs 26 // skip through table for unsaved stars 27 for (i = 0; i < Nstars; i++) { 28 if (stars[i].flag) continue; 20 // read the chunk from the file 21 fprintf (stderr, "loading %s\n", filename); 29 22 30 // scan forward until we read the UserPatch 31 if (stars[i].average.R < UserPatch.Rmin) continue; 32 if (stars[i].average.R > UserPatch.Rmax) break; 33 if (stars[i].average.D < UserPatch.Dmin) continue; 34 if (stars[i].average.D > UserPatch.Dmax) continue; 23 // on each pass, we read a new chunk of data and receive Nstars 35 24 36 // identify the relevant catalog 37 SkyList *skylist = SkyRegionByPoint_List (skylistInput, -1, stars[i].average.R, stars[i].average.D); 38 if (skylist[0].Nregions == 0) { 25 int Nstars = 0; 26 UKIRT_UHS_Stars *stars = loadukirt_uhs_readstars (f, buffer, &Nstart, options, &Nstars); 27 if (!Nstars) { 28 fclose (f); 29 free (buffer); 30 return TRUE; // end of file reached 31 } 32 33 fprintf (stderr, "writing %d stars to dvo\n", Nstars); 34 35 // sort the stars by RA 36 loadukirt_uhs_sortStars (stars, Nstars); 37 38 // scan through the stars, loading the containing catalogs 39 // skip through table for unsaved stars 40 for (int i = 0; i < Nstars; i++) { 41 if (stars[i].flag) continue; 42 43 // scan forward until we read the UserPatch 44 if (stars[i].average.R < UserPatch.Rmin) continue; 45 if (stars[i].average.R > UserPatch.Rmax) break; 46 if (stars[i].average.D < UserPatch.Dmin) continue; 47 if (stars[i].average.D > UserPatch.Dmax) continue; 48 49 // identify the relevant catalog 50 SkyList *skylist = SkyRegionByPoint_List (skylistInput, -1, stars[i].average.R, stars[i].average.D); 51 if (skylist[0].Nregions == 0) { 52 SkyListFree (skylist); 53 continue; 54 } 55 SkyRegion *region = skylist[0].regions[0]; 56 57 // select stars matching this region 58 int Nsubset; 59 UKIRT_UHS_Stars *subset = loadukirt_uhs_make_subset (stars, Nstars, i, region, &Nsubset); 60 61 // In parallel mode, write out the subset to a disk file. Block until a remote host 62 // is available. In serial mode, just match against the appropriate region and save 63 // NOTE: disable parallel mode for now: 64 // loadukirt_uhs_save_remote (subset, Nsubset, hosts, region, skylist[0].filename[0], options); 65 loadukirt_uhs_catalog (subset, Nsubset, region, skylist[0].filename[0], options); 66 free (subset); 39 67 SkyListFree (skylist); 40 continue;41 68 } 42 SkyRegion *region = skylist[0].regions[0]; 43 44 // select stars matching this region 45 int Nsubset; 46 UKIRT_UHS_Stars *subset = loadukirt_uhs_make_subset (stars, Nstars, i, region, &Nsubset); 47 48 // In parallel mode, write out the subset to a disk file. Block until a remote host 49 // is available. In serial mode, just match against the appropriate region and save 50 // NOTE: disable parallel mode for now: 51 // loadukirt_uhs_save_remote (subset, Nsubset, hosts, region, skylist[0].filename[0], options); 52 loadukirt_uhs_catalog (subset, Nsubset, region, skylist[0].filename[0], options); 53 free (subset); 54 SkyListFree (skylist); 69 free (stars); 55 70 } 56 71 … … 59 74 // harvest_all (); 60 75 61 free (stars);62 return Nstart;76 // we should not actually reach this point 77 return FALSE; 63 78 } 64 79 80 /* modifying to read in smaller blocks of the input file at a time 81 82 each pass on readstars needs to ... 83 84 */ 85
Note:
See TracChangeset
for help on using the changeset viewer.
