IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 12, 2015, 6:18:23 PM (11 years ago)
Author:
eugene
Message:

merge changes from EAM dev branch ohana.20150429

Location:
trunk/Ohana
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana

  • trunk/Ohana/src/opihi/cmd.data

  • trunk/Ohana/src/opihi/cmd.data/read_vectors.c

    r38062 r38441  
    11# include "data.h"
     2int dump_raw_table (FTable *table, char *message);
     3int dump_cmp_table (FTable *table, char *message);
    24
    35FILE *f = (FILE *) NULL;
     
    412414  table.header = &header;
    413415
    414   /* load appropriate extension (if extname is a number, use count) */
     416  /**** find the appropriate extension and read header (if extname is a number, use count) ****/
    415417  if (Nextend > -1) {
    416418    // first extension is PHU, cannot be a table.
     
    429431    }
    430432    if (!gfits_load_header (f, &header)) ESCAPE ("error reading header for extension %d\n", Nextend);
    431 
    432     if (getSizes) {
    433       read_table_sizes (&header);
    434       if (CCDKeyword != NULL) free (CCDKeyword);
    435       gfits_free_header (&header);
    436       return TRUE;
    437     }
    438 
    439     if (Nrows == -1) {
    440       Nrows = header.Naxis[1] - start;
    441     }
    442     if (start < 0) ESCAPE ("invalid range: start < 0\n");
    443     if (start >= header.Naxis[1]) ESCAPE ("invalid range: start >= Ny (%d)\n", header.Naxis[1]);
    444     if (Nrows < 0) ESCAPE ("invalid range: Nrows < 0\n");
    445 
    446     // just a warning:
    447     if (start + Nrows > header.Naxis[1]) {
    448       if (VERBOSE) gprint (GP_ERR, "NOTE: reading last block will return only %d rows\n", header.Naxis[1] - start);
    449     }
    450 
    451     // Ny = 100, start = 0, Nrows = -1 -> Nrows => 100
    452     // Ny = 100, start = 10, Nrows = 90
    453 
    454     if (!gfits_fread_ftable_range (f, padIfShort, &table, start, Nrows)) ESCAPE ("error reading table for extension %d\n", Nextend);
    455433  } else {
    456434    if (CCDKeyword == NULL) {
     
    460438      CCDKeyword = strcreate ("EXTNAME");
    461439    }
    462 
    463440    while (1) {
    464441      if (!gfits_load_header (f, &header)) {
     
    469446        return (TRUE); 
    470447      }
    471 
    472448      Nbytes = gfits_data_size (&header);
    473449
     
    482458        continue;
    483459      }
    484 
    485       if (getSizes) {
    486         read_table_sizes (&header);
    487         if (CCDKeyword != NULL) free (CCDKeyword);
    488         gfits_free_header (&header);
    489         return TRUE;
    490       }
    491 
    492       if (Nrows == -1) {
    493         Nrows = header.Naxis[1] - start;
    494       }
    495       if (start < 0) ESCAPE ("invalid range: start < 0\n");
    496       if (start >= header.Naxis[1]) ESCAPE ("invalid range: start >= Ny (%d)\n", header.Naxis[1]);
    497       if (Nrows < 0) ESCAPE ("invalid range: Nrows < 0\n");
    498 
    499       // just a warning:
    500       if (start + Nrows > header.Naxis[1]) {
    501         if (VERBOSE) gprint (GP_ERR, "NOTE: reading last block will return only %d rows\n", header.Naxis[1] - start);
    502       }
    503 
    504       if (!gfits_fread_ftable_range (f, padIfShort, &table, start, Nrows)) ESCAPE ("error reading table for extension %d\n", Nextend);
    505 
    506       // if (!gfits_fread_ftable_data (f, &table, padIfShort)) ESCAPE ("error reading table for extension\n");
    507 
    508460      break;
    509461    }
     462  }
     463
     464  int IsCompressed = gfits_extension_is_compressed_table (&header);
     465
     466  if (getSizes && !IsCompressed) {
     467    read_table_sizes (&header);
     468    if (CCDKeyword != NULL) free (CCDKeyword);
     469    gfits_free_header (&header);
     470    return TRUE;
     471  }
     472  if (IsCompressed) {
     473    if (getSizes) {
     474      gprint (GP_ERR, "%s[%s] is compressed: -sizes is invalid\n", filename, extname);
     475      gfits_free_header (&header);
     476      return FALSE;
     477    }
     478    if ((start > 0) || (Nrows > -1)) {
     479      gprint (GP_ERR, "%s[%s] is compressed: must read entire table\n", filename, extname);
     480      gfits_free_header (&header);
     481      return FALSE;
     482    }
     483  }
     484
     485  if (Nrows == -1) {
     486    Nrows = header.Naxis[1] - start;
     487  }
     488  if (start < 0) ESCAPE ("invalid range: start < 0\n");
     489  if (start >= header.Naxis[1]) ESCAPE ("invalid range: start >= Ny ("OFF_T_FMT")\n", header.Naxis[1]);
     490  if (Nrows < 0) ESCAPE ("invalid range: Nrows < 0\n");
     491
     492  // just a warning:
     493  if (start + Nrows > header.Naxis[1]) {
     494    if (VERBOSE) gprint (GP_ERR, "NOTE: reading last block will return only "OFF_T_FMT" rows\n", header.Naxis[1] - start);
     495  }
     496
     497  // Ny = 100, start = 0, Nrows = -1 -> Nrows => 100
     498  // Ny = 100, start = 10, Nrows = 90
     499
     500  if (IsCompressed) {
     501    if (!gfits_fread_ftable_data (f, &table, padIfShort)) ESCAPE ("error reading table for extension %d\n", Nextend);
     502  } else {
     503    if (!gfits_fread_ftable_range (f, padIfShort, &table, start, Nrows)) ESCAPE ("error reading table for extension %d\n", Nextend);
    510504  }
    511505
     
    518512  Binary = !strcmp (type, "BINTABLE");
    519513  Ny = header.Naxis[1];
     514
     515  Header *outheader = &header;
     516  FTable *outtable  = &table;
     517
     518  Header rawheader;
     519  FTable rawtable;
     520  if (IsCompressed) {
     521    rawtable.header = &rawheader;
     522
     523    dump_cmp_table (&table, "rd cmp");
     524
     525    int Nfields;
     526    if (!gfits_scan (&header, "TFIELDS", "%d", 1, &Nfields)) ESCAPE ("cannot find TFIELDS in header\n");
     527    for (i = 0; i < Nfields; i++) {
     528      gfits_byteswap_varlength_column (&table, i+1);
     529    }
     530    if (!gfits_uncompress_table (&table, &rawtable)) ESCAPE ("failed to uncompress table\n");
     531    dump_raw_table (&rawtable, "rd raw");
     532
     533    outheader = &rawheader;
     534    outtable  = &rawtable;
     535    gfits_free_header (&header);
     536    gfits_free_table (&table);
     537    Ny = rawheader.Naxis[1];
     538  }
    520539
    521540  /* find columns which match requested vectors */
     
    527546    Nval = 0;
    528547    if (Binary) {
    529       if (!gfits_get_bintable_column_type (&header, argv[i], type, &Nval)) ESCAPE ("requested field not found");
    530       if (!gfits_get_bintable_column (&header, &table, argv[i], &data)) ESCAPE ("error reading data from specified field");
     548      if (!gfits_get_bintable_column_type (outheader, argv[i], type, &Nval)) ESCAPE ("requested field not found\n");
     549      if (!gfits_get_bintable_column_raw (outheader, outtable, argv[i], &data, IsCompressed)) ESCAPE ("error reading data from specified field\n");
    531550    } else {
    532       if (!gfits_get_table_column_type (&header, argv[i], type)) ESCAPE ("requested field not found");
    533       if (!gfits_get_table_column (&header, &table, argv[i], &data)) ESCAPE ("error reading data from specified field");
    534     }
    535     if (Nval == 0) ESCAPE ("no data for field in table");
     551      if (!gfits_get_table_column_type (outheader, argv[i], type)) ESCAPE ("requested field not found\n");
     552      if (!gfits_get_table_column (outheader, outtable, argv[i], &data)) ESCAPE ("error reading data from specified field\n");
     553    }
     554    if (Nval == 0) ESCAPE ("no data for field in table\n");
    536555   
    537556    vecType = OPIHI_INT;
    538     if (!strcmp (type, "double") || !strcmp (type, "float")) {
     557    if (!strcmp (type, "double") || !strcmp (type, "float") || !strcmp (type, "int64_t")) {
    539558      vecType = OPIHI_FLT;
    540559    }
     
    570589        else
    571590          sprintf (name, "%s:%d", argv[i], j);
    572         if ((vec[j] = SelectVector (name, ANYVECTOR, TRUE)) == NULL) ESCAPE ("bad vector name");
     591        if ((vec[j] = SelectVector (name, ANYVECTOR, TRUE)) == NULL) ESCAPE ("bad vector name\n");
    573592        ResetVector (vec[j], vecType, Ny);
    574593      }
    575594
    576       if (!VectorAssignData (vec, type, data, Ny, Nval)) ESCAPE ("bad column type %s", type);
     595      if (!VectorAssignData (vec, type, data, Ny, Nval)) ESCAPE ("bad column type %s\n", type);
    577596
    578597    } else {
     
    584603        else
    585604          sprintf (name, "%s:%d", argv[i], j);
    586         if ((vec[j] = SelectVector (name, ANYVECTOR, TRUE)) == NULL) ESCAPE ("bad vector name");
     605        if ((vec[j] = SelectVector (name, ANYVECTOR, TRUE)) == NULL) ESCAPE ("bad vector name\n");
    587606        ResetVector (vec[j], vecType, Nval);
    588607      }
    589608
    590       if (!VectorAssignDataTranspose (vec, type, data, Ny, Nval)) ESCAPE ("bad column type %s", type);
     609      if (!VectorAssignDataTranspose (vec, type, data, Ny, Nval)) ESCAPE ("bad column type %s\n", type);
    591610    }
    592611    free (data);
     
    594613  }
    595614  if (CCDKeyword != NULL) free (CCDKeyword);
    596   gfits_free_table (&table);
    597   gfits_free_header (&header);
     615  gfits_free_table (outtable);
     616  gfits_free_header (outheader);
    598617  return (TRUE);
    599618}
Note: See TracChangeset for help on using the changeset viewer.