//////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// // // Class: NetCDFFileIO // // Filename: ReadL1BNetCDF.cpp // // Header Files: NetCDFFileIO.h // // Description: This class is designed to provide a series // of utilities to read the Level 1B // routine NetCDF files that the GUVI DP POC // is producing. These are as follows: // GUVI Imaging Disk Level 1B data product // GUVI Imaging Limb Level 1B data product // GUVI Static Imaging Level 1B data product // // Author: M. Weiss // // Date: April, 1999 // // Change History: // --------------- // Oct. 99 MW modified to match new data file definitions. // Added usage of GUVIBaseTypes.h. // Nov. 99 MW Added check so that negative errors aren't // scaled // Jan. 02 MW Added calls to nc_close in ReadL1BImagingDisk, // ReadL1BImagingLimb and ReadL1BStaticImaging // methods. Changed SecsOfDay to MsecsOfDay. // Utilization of Vector from standard template // library to store a full orbits worth of data. // Changed processing and output parameter to // return a full orbits worth of data. // Feb. 02 MW Changed array index names from per* to Num*. // Removed color index from Pierce point lat/lon. // Moved Array indices from ImagingDisk1BPixelData, // ImagingLimb1BPixelData and StaticImaging1BPixelData // to individual fields in record of PixelData. // Feb. 02 BW DQI for the L1B data files got moved from the / scan // basis to the per pixel basis. /// //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// // include files #include #include#include "NetCDFFileIO.h" #include "LogUtil.h" //////////////////////////////////////////////////////////// // // Method: ReadLevel1BImagingDisk // // Description: This method reads the GUVI level 1B imaging // disk data from a netcdf file. This method // returns a single orbits worth of imaging // data for every call // // Inputs: // Name Description // ---- ----------- // inFileName file name of data to be read // orbitIData a pointer to the data to be read // // Return: // Name Description // ---- ----------- // n/a true = successful read // false = unsuccessful read // bool NetCDFFileIO::ReadLevel1BImagingDisk( string inFileName, OrbitOfImagingDisk1B& orbitIData ) { // to store a single scans worth of imaging data into ImagingDisk1BFormat imagingData; // indicates which scan number we're currently on int scanNum; size_t numScans; int status; int ncid; // netcdf file id // the following are used for the netcdf variable // ids int scanDim; int xtrkDim; int alongTrkDim; int colorDim; int dcDim; int bcDim; // netcdf variables defined in file int timeID; int detectorID; int slitID; int dcID; int bcID; int dqID; int pptLatID; int pptLonID; int radianceID; int calErrorID; int CountErrorID; short tempError; // holding value for scaled error // open the file specified by inFileName status = nc_open(inFileName.c_str(), NC_NOWRITE, &ncid); // check if the file open was successful if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingDisk: Can't open netcdf file, name\n", inFileName.c_str()); return false; } // get the netcdf dimension ids status = nc_inq_dimid(ncid, "NumScans", &scanDim); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingDisk: Can't find scan dim\n"); nc_close(ncid); return false; } status = nc_inq_dimid(ncid, "NumAcrossTrackPixels", &xtrkDim); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingDisk: Can't find xtrk dim\n"); nc_close(ncid); return false; } status = nc_inq_dimid(ncid, "NumAlongTrackPixels", &alongTrkDim); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingDisk: Can't find along track dim\n"); nc_close(ncid); return false; } status = nc_inq_dimid(ncid, "NumColors", &colorDim); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingDisk: Can't find color dim\n"); nc_close(ncid); return false; } status = nc_inq_dimid(ncid, "NumDarkCountPixels", &dcDim); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingDisk: Can't find dark count pixels dim\n"); nc_close(ncid); return false; } status = nc_inq_dimid(ncid, "NumBackgroundCountPixels", &bcDim); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingDisk: Can't find background count pixels dim\n"); nc_close(ncid); return false; } // get all of the variable ids. doing it here since it's not dependent // upon which indices you're looking at in a dimensional field status = nc_inq_varid(ncid, "Time", &timeID); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingDisk: Can't find time\n"); nc_close(ncid); return false; } status = nc_inq_varid(ncid, "Detector", &detectorID); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingDisk: Can't find Detector\n"); nc_close(ncid); return false; } status = nc_inq_varid(ncid, "Slit", &slitID); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingDisk: Can't find slit\n"); nc_close(ncid); return false; } size_t countdc[] = {1, NUM_DARK_COUNT_PIXELS}; status = nc_inq_varid(ncid, "DarkCountPixels", &dcID); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingDisk: Can't find variable dark counts\n"); nc_close(ncid); return false; } size_t countbc[] = {1, NUM_X_BACKGROUND_PIXELS * NUM_Y_BACKGROUND_PIXELS}; status = nc_inq_varid(ncid, "BackgroundPixels", &bcID); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingDisk: Can't find variable backgrund counts\n"); nc_close(ncid); return false; } status = nc_inq_varid(ncid, "PiercePointLatitude", &pptLatID); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingDisk: Can't find pierce pt lat\n"); nc_close(ncid); return false; } status = nc_inq_varid(ncid, "PiercePointLongitude", &pptLonID); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingDisk: Can't find pierce pt lon\n"); nc_close(ncid); return false; } status = nc_inq_varid(ncid, "RadianceData", &radianceID); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingDisk: Can't find variable radiance data\n"); nc_close(ncid); return false; } status = nc_inq_varid(ncid, "CalibrationError", &calErrorID); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingDisk: Can't find variable cal error\n"); nc_close(ncid); return false; } status = nc_inq_varid(ncid, "CountError", &CountErrorID); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingDisk: Can't find variable count error\n"); nc_close(ncid); return false; } status = nc_inq_varid(ncid, "DQI", &dqID); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingDisk: Can't find data quality\n"); nc_close(ncid); return false; } // find out how many scans are in the file so that they can all be // processed status = nc_inq_dimlen(ncid, scanDim, &numScans); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingDisk: Can't get num of dimensions for perScan\n"); nc_close(ncid); return false; } // now get data from the data product file for all scans for (scanNum = 0; scanNum numScans; scanNum++) { // first get the data that appears on a scan basis but // to do that have to first find out what variable // corresponds with the approrpriate variable id and // then issue a netcdf to get the associated data size_t startscan[1] = {scanNum}; status = nc_get_var1_long(ncid, timeID, startscan, &imagingData.ScanData.MsecsOfDay); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingDisk: Can't read time\n"); nc_close(ncid); return false; } status = nc_get_var1_uchar(ncid, detectorID, startscan, &imagingData.ScanData.DetectorNum); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingDisk: Can't read detector num\n"); nc_close(ncid); return false; } status = nc_get_var1_uchar(ncid, slitID, startscan, &imagingData.ScanData.SlitPosition); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingDisk: Can't read slit position\n"); nc_close(ncid); return false; } size_t startdc[2] = {scanNum, 0}; status = nc_get_vara_short(ncid, dcID, startdc, countdc, imagingData.ScanData.DarkCountPixel); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingDisk: Can't read dark count pixels\n"); nc_close(ncid); return false; } size_t startbc[2] = {scanNum, 0}; status = nc_get_vara_short(ncid, bcID, startbc, countbc, imagingData.ScanData.BackgroundCountPixel); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingDisk: Can't read background count pixels\n"); nc_close(ncid); return false; } // now add the imaging pixel data that has already // been uncompressed and the other imaging data that // appears on a cross track basis. // Dim 3 has scan num, across track, and along track as // dimensions size_t dim3[3] = {scanNum, 0, 0}; // Dim 4 has scan num, across track, along track and color // as dimensions size_t dim4[4] = {scanNum, 0, 0, 0}; // need to go through the imaging data record for all // crosstracks because netcdf has a problem with mixing // record fields with arrays for (int i = 0; i NUM_DISK_CROSS_TRACK_PIXELS; i++) { dim3[1] = i; dim4[1] = i; // need to go through the imaging data record also // for all along track pixels and all imaging colors // also due to a netcdf bug/quirk for (int j = 0; j NUM_ALONG_TRACK_PIXELS; j++) { dim3[2] = j; dim4[2] = j; status = nc_get_var1_float(ncid, pptLatID, dim3, &imagingData.PixelData.PiercePoint[i][j].Latitude); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingDisk: Can't read pierce pt lat\n"); nc_close(ncid); return false; } status = nc_get_var1_float(ncid, pptLonID, dim3, &imagingData.PixelData.PiercePoint[i][j].Longitude); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingDisk: Can't read pierce pt lon\n"); nc_close(ncid); return false; } // and all colors for (int k = 0; k NUM_IMAGING_COLORS; k++) { // set the array position for the appropriate cross track // pixel index dim4[3] = k; status = nc_get_var1_float(ncid, radianceID, dim4, &imagingData.PixelData.Radiance[i][j][k]); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingDisk: Can't read pixel data\n"); nc_close(ncid); return false; } status = nc_get_var1_short(ncid, calErrorID, dim4, &tempError); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingDisk: Can't read cal error\n"); nc_close(ncid); return false; } // a negative value for error indicates that the data // is totally invalid so don't scale that imagingData.PixelData.CalibrationError[i][j][k] = (Float)tempError; if (tempError> 0) imagingData.PixelData.CalibrationError[i][j][k] /= (Float)UNCERTAINTY_SCALE_FACTOR; status = nc_get_var1_short(ncid, CountErrorID, dim4, &tempError); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingDisk: Can't read count error\n"); nc_close(ncid); return false; } // a negative value for error indicates that the data // is totally invalid so don't scale that imagingData.PixelData.CountError[i][j][k] = (Float)tempError; if (tempError > 0) imagingData.PixelData.CountError[i][j][k] /= (Float)UNCERTAINTY_SCALE_FACTOR; status = nc_get_var1_float(ncid, dqID, dim4, &imagingData.PixelData.DQI[i][j][k]); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingDisk: Can't read data quality\n"); nc_close(ncid); return false; } } // of for colors } // of for all all along track pixels } // of for all cross track pixels orbitIData.push_back(imagingData); } // for all scans // close the netcdf file nc_close(ncid); return true; } //////////////////////////////////////////////////////////// // // Method: ReadLevel1BImagingLimb // // Description: This method reads the GUVI level 1B imaging // limb data from a netcdf file. This method // returns a single orbits worth of imaging // data for every call // // Inputs: // Name Description // ---- ----------- // inFileName file name of data to be read // orbitIData a pointer to the data to be read // // Return: // Name Description // ---- ----------- // n/a true = successful read // false = unsuccessful read // bool NetCDFFileIO::ReadLevel1BImagingLimb( string inFileName, OrbitOfImagingLimb1B& orbitIData ) { // a single scans worth of data ImagingLimb1BFormat imagingData; // indicates which scan number we're currently on int scanNum; size_t numScans; int status; int ncid; // netcdf file id // the following are used for the netcdf variable // ids int scanDim; int xtrkDim; int alongTrkDim; int colorDim; int dcDim; int bcDim; // netcdf variables defined in file int timeID; int detectorID; int slitID; int dcID; int bcID; int dqID; int radianceID; int calErrorID; int CountErrorID; int zaID; int raID; int decID; int tanptLatID; int tanptLonID; int tanptAltID; int bkgdStarID; short tempError; // holding value for scaled error // open the file specified by inFileName status = nc_open(inFileName.c_str(), NC_NOWRITE, &ncid); // check if the file open was successful if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingLimb: Can't open netcdf file, name\n", inFileName.c_str() ); return false; } // get the netcdf dimension ids status = nc_inq_dimid(ncid, "NumScans", &scanDim); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingLimb: Can't find scan dim\n"); nc_close(ncid); return false; } status = nc_inq_dimid(ncid, "NumCrossTrackPixels", &xtrkDim); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingLimb: Can't find xtrk dim\n"); nc_close(ncid); return false; } status = nc_inq_dimid(ncid, "NumAlongTrackPixels", &alongTrkDim); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingLimb: Can't find along track dim\n"); nc_close(ncid); return false; } status = nc_inq_dimid(ncid, "NumColors", &colorDim); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingLimb: Can't find color dim\n"); nc_close(ncid); return false; } status = nc_inq_dimid(ncid, "NumDarkCountPixels", &dcDim); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingLimb: Can't find dark count pixels dim\n"); nc_close(ncid); return false; } status = nc_inq_dimid(ncid, "NumBackgroundCountPixels", &bcDim); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingLimb: Can't find background count pixels dim\n"); nc_close(ncid); return false; } // get all of the variable ids. doing it here since it's not dependent // upon which indices you're looking at in a dimensional field status = nc_inq_varid(ncid, "Time", &timeID); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingLimb: Can't find time\n"); nc_close(ncid); return false; } status = nc_inq_varid(ncid, "Detector", &detectorID); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingLimb: Can't find Detector\n"); nc_close(ncid); return false; } status = nc_inq_varid(ncid, "Slit", &slitID); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingLimb: Can't find slit\n"); nc_close(ncid); return false; } size_t countdc[] = {1, NUM_DARK_COUNT_PIXELS}; status = nc_inq_varid(ncid, "DarkCountPixels", &dcID); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingLimb: Can't find variable dark counts\n"); nc_close(ncid); return false; } size_t countbc[] = {1, NUM_X_BACKGROUND_PIXELS * NUM_Y_BACKGROUND_PIXELS}; status = nc_inq_varid(ncid, "BackgroundPixels", &bcID); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingLimb: Can't find variable backgrund counts\n"); nc_close(ncid); return false; } status = nc_inq_varid(ncid, "BackgroundStarAtPixel", &bkgdStarID); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingLimb: Can't find variable background star\n"); nc_close(ncid); return false; } status = nc_inq_varid(ncid, "ZenithAngle", &zaID); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingLimb: Can't find zenith angle\n"); nc_close(ncid); return false; } status = nc_inq_varid(ncid, "RA", &raID); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingLimb: Can't find variable ra\n"); nc_close(ncid); return false; } status = nc_inq_varid(ncid, "DEC", &decID); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingLimb: Can't find variable dec\n"); nc_close(ncid); return false; } status = nc_inq_varid(ncid, "TangentPointLatitude", &tanptLatID); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingLimb: Can't find variable tan pt lat\n"); nc_close(ncid); return false; } status = nc_inq_varid(ncid, "TangentPointLongitude", &tanptLonID); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingLimb: Can't find variable tan pt lon\n"); nc_close(ncid); return false; } status = nc_inq_varid(ncid, "TangentPointAltitude", &tanptAltID); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingLimb: Can't find variable tan pt alt\n"); nc_close(ncid); return false; } status = nc_inq_varid(ncid, "RadianceData", &radianceID); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingLimb: Can't find variable radiance data\n"); nc_close(ncid); return false; } status = nc_inq_varid(ncid, "CalibrationError", &calErrorID); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingLimb: Can't find variable cal error\n"); nc_close(ncid); return false; } status = nc_inq_varid(ncid, "CountError", &CountErrorID); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingLimb: Can't find variable count error\n"); nc_close(ncid); return false; } status = nc_inq_varid(ncid, "DQI", &dqID); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingLimb: Can't find data quality\n"); nc_close(ncid); return false; } // find out how many scans are in the file so that they can all be // processed status = nc_inq_dimlen(ncid, scanDim, &numScans); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingLimb: Can't get num of dimensions for perScan\n"); nc_close(ncid); return false; } // now get data from the data product file for all scans for (scanNum = 0; scanNum numScans; scanNum++) { // first get the data that appears on a scan basis but // to do that have to first find out what variable // corresponds with the approrpriate variable id and // then issue a netcdf to get the associated data size_t startscan[1] = {scanNum}; status = nc_get_var1_long(ncid, timeID, startscan, &imagingData.ScanData.MsecsOfDay); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingLimb: Can't read time\n"); nc_close(ncid); return false; } status = nc_get_var1_uchar(ncid, detectorID, startscan, &imagingData.ScanData.DetectorNum); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingLimb: Can't read detector num\n"); nc_close(ncid); return false; } status = nc_get_var1_uchar(ncid, slitID, startscan, &imagingData.ScanData.SlitPosition); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingLimb: Can't read slit position\n"); nc_close(ncid); return false; } size_t startdc[2] = {scanNum, 0}; status = nc_get_vara_short(ncid, dcID, startdc, countdc, imagingData.ScanData.DarkCountPixel); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingLimb: Can't read dark count pixels\n"); nc_close(ncid); return false; } size_t startbc[2] = {scanNum, 0}; status = nc_get_vara_short(ncid, bcID, startbc, countbc, imagingData.ScanData.BackgroundCountPixel); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingLimb: Can't read background count pixels\n"); nc_close(ncid); return false; } // now add the imaging pixel data that has already // been uncompressed and the other imaging data that // appears on a cross track basis size_t dim3[3] = {scanNum, 0, 0}; size_t dim4[4] = {scanNum, 0, 0, 0}; // need to go through the imaging data record for all // crosstracks because netcdf has a problem with mixing // record fields with arrays for (int i = 0; i NUM_LIMB_CROSS_TRACK_PIXELS; i++) { dim3[1] = i; dim4[1] = i; // need to go through the imaging data record also // for all along track pixels and all imaging colors // also due to a netcdf bug/quirk for (int j = 0; j NUM_ALONG_TRACK_PIXELS; j++) { dim3[2] = j; dim4[2] = j; status = nc_get_var1_uchar(ncid, bkgdStarID, dim3, &imagingData.PixelData. BackgroundStarAtPixel[i][j]); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingLimb: Can't read background star\n"); nc_close(ncid); return false; } status = nc_get_var1_float(ncid, tanptLatID, dim3, &imagingData.PixelData. TangentPoint[i][j].Latitude); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingLimb: Can't read tan pt lat\n"); nc_close(ncid); return false; } status = nc_get_var1_float(ncid, tanptLonID, dim3, &imagingData.PixelData. TangentPoint[i][j].Longitude); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingLimb: Can't read tan pt lon\n"); nc_close(ncid); return false; } status = nc_get_var1_float(ncid, tanptAltID, dim3, &imagingData.PixelData. TangentPoint[i][j].Altitude); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingLimb: Can't read tan pt alt\n"); nc_close(ncid); return false; } status = nc_get_var1_float(ncid, zaID, dim3, &imagingData.PixelData.ZenithAngle[i][j]); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingLimb: Can't read zenith angle\n"); nc_close(ncid); return false; } status = nc_get_var1_float(ncid, raID, dim3, &imagingData.PixelData.RA[i][j]); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingLimb: Can't read RA\n"); nc_close(ncid); return false; } status = nc_get_var1_float(ncid, decID, dim3, &imagingData.PixelData.DEC[i][j]); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingLimb: Can't read DEC\n"); nc_close(ncid); return false; } // and all colors for (int k = 0; k NUM_IMAGING_COLORS; k++) { // set the array position for the appropriate cross track // pixel index dim4[3] = k; status = nc_get_var1_float(ncid, radianceID, dim4, &imagingData.PixelData.Radiance[i][j][k]); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingLimb: Can't read pixel data\n"); nc_close(ncid); return false; } status = nc_get_var1_short(ncid, calErrorID, dim4, &tempError); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingLimb: Can't read cal error\n"); nc_close(ncid); return false; } // a negative value for error indicates that the data // is totally invalid so don't scale that imagingData.PixelData.CalibrationError[i][j][k] = (Float)tempError; if (tempError > 0) imagingData.PixelData.CalibrationError[i][j][k] /= (Float)UNCERTAINTY_SCALE_FACTOR; status = nc_get_var1_short(ncid, CountErrorID, dim4, &tempError); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingLimb: Can't read count error\n"); nc_close(ncid); return false; } // a negative value for error indicates that the data // is totally invalid so don't scale that imagingData.PixelData.CountError[i][j][k] = (Float)tempError; if (tempError > 0) imagingData.PixelData.CountError[i][j][k] /= (Float)UNCERTAINTY_SCALE_FACTOR; status = nc_get_var1_float(ncid, dqID, dim4, &imagingData.PixelData.DQI[i][j][k]); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BImagingLimb: Can't read data quality\n"); nc_close(ncid); return false; } } // of for colors } // of for all all along track pixels } // of for all cross track pixels orbitIData.push_back(imagingData); } // for all scans nc_close(ncid); return true; } //////////////////////////////////////////////////////////// // // Method: ReadLevel1BStaticImaging // // Description: This method reads the GUVI level 1B static // imaging data from a netcdf file. This method // returns a single orbits worth of static // imaging data for every call // // Inputs: // Name Description // ---- ----------- // inFileName file name of data to be read // orbitSiData a pointer to the data to be read // // Return: // Name Description // ---- ----------- // n/a true = successful read // false = unsucessful read // bool NetCDFFileIO::ReadLevel1BStaticImaging( string inFileName, OrbitOfStaticImaging1B& orbitSiData ) { // to store a single scans worth of data StaticImaging1BFormat siData; // indicates which scan number we're currently on Integer scanNum; size_t numScans; Integer status; Integer ncid; // netcdf file id // the following are used for the netcdf variable // ids Integer scanDim; Integer xtrkDim; Integer alongTrkDim; Integer colorDim; Integer dcDim; Integer bcDim; // netcdf variables defined in file Integer timeID; Integer fineTimeID; Integer detectorID; Integer slitID; Integer dcID; Integer bcID; Integer dqID; Integer radianceID; Integer calErrorID; Integer CountErrorID; Integer raID; Integer decID; Integer tanptLatID; Integer tanptLonID; Integer tanptAltID; Integer bkgdStarID; Short tempError; // holding value for scaled error // open the file specified by inFileName status = nc_open(inFileName.c_str(), NC_NOWRITE, &ncid); // check if the file open was successful if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BStaticImaging: Can't open netcdf file, name\n", inFileName.c_str() ); return false; } // get the netcdf dimension ids status = nc_inq_dimid(ncid, "NumScans", &scanDim); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BStaticImaging: Can't find scan dim\n"); nc_close(ncid); return false; } status = nc_inq_dimid(ncid, "NumAcrossTrackPixels", &xtrkDim); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BStaticImaging: Can't find xtrk dim\n"); nc_close(ncid); return false; } status = nc_inq_dimid(ncid, "NumAlongTrackPixels", &alongTrkDim); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BStaticImaging: Can't find along track dim\n"); nc_close(ncid); return false; } status = nc_inq_dimid(ncid, "NumColors", &colorDim); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BStaticImaging: Can't find color dim\n"); nc_close(ncid); return false; } status = nc_inq_dimid(ncid, "NumDarkCountPixels", &dcDim); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BStaticImaging: Can't find dark count pixels dim\n"); nc_close(ncid); return false; } status = nc_inq_dimid(ncid, "NumBackgroundCountPixels", &bcDim); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BStaticImaging: Can't find background count pixels dim\n"); nc_close(ncid); return false; } // get all of the variable ids. doing it here since it's // not dependent upon which indices you're looking at in a // dimensional field status = nc_inq_varid(ncid, "Time", &timeID); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BStaticImaging: Can't find time\n"); nc_close(ncid); return false; } status = nc_inq_varid(ncid, "FineTime", &fineTimeID); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BStaticImaging: Can't find fine time\n"); nc_close(ncid); return false; } status = nc_inq_varid(ncid, "Detector", &detectorID); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BStaticImaging: Can't find Detector\n"); nc_close(ncid); return false; } status = nc_inq_varid(ncid, "Slit", &slitID); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BStaticImaging: Can't find slit\n"); nc_close(ncid); return false; } size_t countdc[] = {1, NUM_DARK_COUNT_PIXELS}; status = nc_inq_varid(ncid, "DarkCountPixels", &dcID); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BStaticImaging: Can't find variable dark counts\n"); nc_close(ncid); return false; } size_t countbc[] = {1, NUM_X_BACKGROUND_PIXELS * NUM_Y_BACKGROUND_PIXELS}; status = nc_inq_varid(ncid, "BackgroundPixels", &bcID); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BStaticImaging: Can't find variable backgrund counts\n"); nc_close(ncid); return false; } status = nc_inq_varid(ncid, "DataQualityIndicator", &dqID); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BStaticImaging: Can't find data quality\n"); nc_close(ncid); return false; } status = nc_inq_varid(ncid, "BackgroundStarAtPixel", &bkgdStarID); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BStaticImaging: Can't find variable background star\n"); nc_close(ncid); return false; } status = nc_inq_varid(ncid, "TangentPointLatitude", &tanptLatID); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BStaticImaging: Can't find variable tan pt lat\n"); nc_close(ncid); return false; } status = nc_inq_varid(ncid, "TangentPointLongitude", &tanptLonID); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BStaticImaging: Can't find variable tan pt lon\n"); nc_close(ncid); return false; } status = nc_inq_varid(ncid, "TangentPointAltitude", &tanptAltID); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BStaticImaging: Can't find variable tan pt alt\n"); nc_close(ncid); return false; } status = nc_inq_varid(ncid, "RA", &raID); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BStaticImaging: Can't find variable RA\n"); nc_close(ncid); return false; } status = nc_inq_varid(ncid, "DEC", &decID); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BStaticImaging: Can't find variable DEC\n"); nc_close(ncid); return false; } status = nc_inq_varid(ncid, "RadianceData", &radianceID); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BStaticImaging: Can't find variable radiance data\n"); nc_close(ncid); return false; } status = nc_inq_varid(ncid, "CalibrationError", &calErrorID); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BStaticImaging: Can't find variable cal error\n"); nc_close(ncid); return false; } status = nc_inq_varid(ncid, "CountError", &CountErrorID); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BStaticImaging: Can't find variable count error\n"); nc_close(ncid); return false; } // find out how many scans are in the file so that they can all be // processed status = nc_inq_dimlen(ncid, scanDim, &numScans); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BStaticImaging: Can't get num of dimensions for perScan\n"); nc_close(ncid); return false; } // now get data from the data product file for all scans for (scanNum = 0; scanNum numScans; scanNum++) { // first get the data that appears on a scan basis but // to do that have to first find out what variable // corresponds with the approrpriate variable id and // then issue a netcdf to get the associated data size_t startscan[1] = {scanNum}; status = nc_get_var1_long(ncid, timeID, startscan, &siData.ScanData.MsecsOfDay); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BStaticImaging: Can't read time\n"); nc_close(ncid); return false; } status = nc_get_var1_uchar(ncid, detectorID, startscan, &siData.ScanData.DetectorNum); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BStaticImaging: Can't read detector num\n"); nc_close(ncid); return false; } status = nc_get_var1_uchar(ncid, slitID, startscan, &siData.ScanData.SlitPosition); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BStaticImaging: Can't read slit position\n"); nc_close(ncid); return false; } size_t startdc[2] = {scanNum, 0}; status = nc_get_vara_short(ncid, dcID, startdc, countdc, siData.ScanData.DarkCountPixel); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BStaticImaging: Can't read dark count pixels\n"); nc_close(ncid); return false; } size_t startbc[2] = {scanNum, 0}; status = nc_get_vara_short(ncid, bcID, startbc, countbc, siData.ScanData.BackgroundCountPixel); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BStaticImaging: Can't read background count pixels\n"); nc_close(ncid); return false; } // now add the static imaging pixel data that has already // been uncompressed and the other imaging data that // appears on a cross track basis size_t dim2[2] = {scanNum, 0}; size_t dim3[3] = {scanNum, 0, 0}; size_t dim4[4] = {scanNum, 0, 0, 0}; // need to go through the static imaging data record for // all crosstracks because netcdf has a problem with mixing // record fields with arrays for (Integer i = 0; i TOTAL_CROSS_TRACK_PIXELS; i++) { dim2[1] = i; dim3[1] = i; dim4[1] = i; status = nc_get_var1_float(ncid, fineTimeID, dim2, &siData.PixelData.FineTime[i]); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BStaticImaging: Can't read fine time\n"); nc_close(ncid); return false; } // need to go through the static imaging data record // for all along track indices and also for all // imaging colors also due to a netcdf bug/quirk for (Integer j = 0; j NUM_ALONG_TRACK_PIXELS; j++) { dim3[2] = j; dim4[2] = j; status = nc_get_var1_uchar(ncid, bkgdStarID, dim3, &siData.PixelData. BackgroundStarAtPixel[i][j]); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BStaticImaging: Can't read background star\n"); nc_close(ncid); return false; } status = nc_get_var1_float(ncid, raID, dim3, &siData.PixelData.RA[i][j]); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BStaticImaging: Can't read RA\n"); nc_close(ncid); return false; } status = nc_get_var1_float(ncid, decID, dim3, &siData.PixelData.DEC[i][j]); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BStaticImaging: Can't read DEC\n"); nc_close(ncid); return false; } status = nc_get_var1_float(ncid, tanptLatID, dim3, &siData.PixelData.TangentPoint[i][j]. Latitude); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BStaticImaging: Can't read tan pt lat\n"); nc_close(ncid); return false; } status = nc_get_var1_float(ncid, tanptLonID, dim3, &siData.PixelData.TangentPoint[i][j]. Longitude); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BStaticImaging: Can't read tan pt lon\n"); nc_close(ncid); return false; } status = nc_get_var1_float(ncid, tanptAltID, dim3, &siData.PixelData.TangentPoint[i][j]. Altitude); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BStaticImaging: Can't read tan pt alt\n"); nc_close(ncid); return false; } for (Integer k = 0; k NUM_IMAGING_COLORS; k++) { dim4[3] = k; status = nc_get_var1_float(ncid, radianceID, dim4, &siData.PixelData.Radiance[i][j][k]); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BStaticImaging: Can't read pixel data\n"); nc_close(ncid); return false; } status = nc_get_var1_short(ncid, calErrorID, dim4, &tempError); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BStaticImaging: Can't read cal error\n"); nc_close(ncid); return false; } // a negative value for error indicates that the data // is totally invalid so don't scale that siData.PixelData.CalibrationError[i][j][k] = (Float)tempError; if (tempError > 0) siData.PixelData.CalibrationError[i][j][k] /= (Float)UNCERTAINTY_SCALE_FACTOR; status = nc_get_var1_short(ncid, CountErrorID, dim4, &tempError); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BStaticImaging: Can't read count error\n"); nc_close(ncid); return false; } // a negative value for error indicates that the data // is totally invalid so don't scale that siData.PixelData.CountError[i][j][k] = (Float)tempError; if (tempError > 0) siData.PixelData.CountError[i][j][k] /= (Float)UNCERTAINTY_SCALE_FACTOR; status = nc_get_var1_float(ncid, dqID, dim4, &siData.PixelData.DQI[i][j][k]); if (status != NC_NOERR) { LogMessage(LOG_ERROR, "NetCDFFileIO.ReadLevel1BStaticImaging: Can't read data quality\n"); nc_close(ncid); return false; } } // of for all colors } // of for all along track pixels } // of for all cross track pixels orbitSiData.push_back(siData); } // for all scans nc_close(ncid); return true; } // End of file