Home > atmlab > sensors > airs_l3_grid_file.m

airs_l3_grid_file

PURPOSE ^

function buffer = airs_l3_grid_file(filename,content_flag,content_list,gridname)

SYNOPSIS ^

function buffer = airs_l3_grid_file(filename,content_flag,content_list,gridname)

DESCRIPTION ^

   function buffer = airs_l3_grid_file(filename,content_flag,content_list,gridname)

 Created by Stephen Licata on 03-17-2005.

 DESCRIPTION:
 This function reads a Level 1 or 2 granule data file in the HDF-EOS format
 and extracts one of the following information types into a data buffer:

 DESCRIPTION:
 This function reads a Level 3 granule data file in the HDF-EOS format
 and extracts one of the following information types into a data buffer:

 INPUT ARGUMENTS (REQUIRED)

 filename  - The fully qualified path to a Level 3 EOS-HDF grid format granule file.

 content_flag - An integer (0-3) that specifies the type of data to be extracted, as follows:
                0: A text string showing the name of the grid(s) in that file.
                1: The name and values of the grid's dimension parameters.
                2: The name and values of the grid's attribute parameters.
                3: The name and values of the grid's data field parameters.

 INPUT ARGUMENTS [OPTIONAL]:

 content_list - An array of names for the content items to be returned. If left unspecified,
                the function will return ALL the parameters in that content category.
 gridname     - A text expression for the data grid within the granule file that is to be
                examined. This function will only process one data grid at a time. In the
                (typical) case that there is only ONE data grid in the granule file, this
                argument can be left unspecified.

 RETURN VALUES:

 buffer       - IDL data structure with fields of parameter name/parameter value.
                Type "help,buffer,/struct" at the IDL command line for details.
                The buffer parameter will be empty ([]) if the function fails.

 SIDE EFFECTS:

              Parameter names in the input file containing with a period character will be saved
              in the output data structure buffer) with an underscore in place of the period.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

airs_l3_grid_file.m

SOURCE CODE ^

0001 function buffer = airs_l3_grid_file(filename,content_flag,content_list,gridname)
0002 
0003 %   function buffer = airs_l3_grid_file(filename,content_flag,content_list,gridname)
0004 %
0005 % Created by Stephen Licata on 03-17-2005.
0006 %
0007 % DESCRIPTION:
0008 % This function reads a Level 1 or 2 granule data file in the HDF-EOS format
0009 % and extracts one of the following information types into a data buffer:
0010 %
0011 % DESCRIPTION:
0012 % This function reads a Level 3 granule data file in the HDF-EOS format
0013 % and extracts one of the following information types into a data buffer:
0014 %
0015 % INPUT ARGUMENTS (REQUIRED)
0016 %
0017 % filename  - The fully qualified path to a Level 3 EOS-HDF grid format granule file.
0018 %
0019 % content_flag - An integer (0-3) that specifies the type of data to be extracted, as follows:
0020 %                0: A text string showing the name of the grid(s) in that file.
0021 %                1: The name and values of the grid's dimension parameters.
0022 %                2: The name and values of the grid's attribute parameters.
0023 %                3: The name and values of the grid's data field parameters.
0024 %
0025 % INPUT ARGUMENTS [OPTIONAL]:
0026 %
0027 % content_list - An array of names for the content items to be returned. If left unspecified,
0028 %                the function will return ALL the parameters in that content category.
0029 % gridname     - A text expression for the data grid within the granule file that is to be
0030 %                examined. This function will only process one data grid at a time. In the
0031 %                (typical) case that there is only ONE data grid in the granule file, this
0032 %                argument can be left unspecified.
0033 %
0034 % RETURN VALUES:
0035 %
0036 % buffer       - IDL data structure with fields of parameter name/parameter value.
0037 %                Type "help,buffer,/struct" at the IDL command line for details.
0038 %                The buffer parameter will be empty ([]) if the function fails.
0039 %
0040 % SIDE EFFECTS:
0041 %
0042 %              Parameter names in the input file containing with a period character will be saved
0043 %              in the output data structure buffer) with an underscore in place of the period.
0044 
0045    prog_name = 'read_L3_grid_file';
0046 
0047    buffer = [];
0048 
0049    if ~exist('gridname','var')
0050       gridname = [];
0051    end
0052 
0053 
0054    if ~exist('content_list','var')
0055       content_list = {};
0056    end
0057 
0058    if ischar(content_list)
0059       tmp = content_list;
0060       content_list = {tmp};
0061       clear tmp
0062    end
0063 
0064 % Abort the program if no data file has been provided.
0065    if isempty(filename)
0066       disp([prog_name ': ERROR - No input filename was specified.'])
0067       return
0068    end
0069 
0070 % Abort the program if no data type has been specified.
0071    if isempty(content_flag)
0072       disp([prog_name ': ERROR - No content code (type) was provided.'])
0073       return
0074    end
0075 
0076 % Set up a set of names (labels) for the different types of data queries.
0077    type_list = {'grid','dimension','attribute','field'};
0078 
0079 % Get a file id value.
0080    fid   = hdfgd('open',filename,'read');
0081 
0082 % Abort the program if the file does not exist or cannot be read.
0083    if fid == -1
0084       disp([prog_name ': ERROR - ' filename ' could not be opened.'])
0085       status = hdfgd('close', fid);
0086       return
0087    end
0088 
0089 % Get the number of data grids in the file (normally just 1)
0090    [ngrid,gridlist] = hdfgd('inqgrid',filename);
0091 
0092 % Abort the program if no data grid(s) is/are found.
0093    if ngrid == 0 | isempty(gridlist)
0094       disp([prog_name ': ERROR - ' filename ' has no data grid.'])
0095       status = hdfgd('close', fid);
0096       return;
0097    end
0098 
0099 % If only the grid list is requested, return that text string and end the program.
0100    if content_flag == 0
0101       buffer = gridlist;
0102       status = hdfgd('close', fid);
0103       return;
0104    end
0105 
0106 % Accept a user-specified data grid name or the first (and only) available grid within the file.
0107 % Only continue processing if the data set is confined to a single grid.
0108    if ~isempty(gridname)
0109       gridname = gridname;
0110    else
0111       gridname = gridlist;
0112    end
0113 
0114 % Abort the program if more than one data grid can be extracted from 'gridname'.
0115    if ~isempty(findstr(gridname,','))
0116       disp([prog_name ': ERROR - This file contains multiple data grids - Choose just one.'])
0117       disp([prog_name ': Swath List = ' gridname])
0118       status = hdfgd('close', fid);
0119       return;
0120    end
0121 
0122 % Attach an ID to this grid.
0123    grid_id = hdfgd('attach', fid, gridname);
0124    if (grid_id == -1)
0125       disp([prog_name ': ERROR - Unable to open grid ' gridname])
0126       status = hdfgd('detach',grid_id);
0127       status = hdfgd('close', fid);
0128       return;
0129    end
0130 
0131 % Select the content list (i.e., set of parameter names) from the grid itself
0132 % unless these names are specified directly by the user.
0133    var_list1 = [];
0134    list1     = {};
0135    if isempty(content_list)
0136       switch content_flag
0137          case {1}
0138             [ndims,var_list1,dims] = hdfgd('inqdims',grid_id);
0139             if ndims == 0
0140                disp([prog_name ': ERROR - No data dimensions were located.'])
0141                status = hdfgd('detach',grid_id);
0142                status = hdfgd('close', fid);
0143             end
0144          case {2}
0145             [nattrib,var_list1]    = hdfgd('inqattrs',grid_id);
0146             if nattrib == 0
0147                disp([prog_name ': ERROR - No data attributes were located.'])
0148                status = hdfgd('detach',grid_id);
0149                status = hdfgd('close', fid);
0150             end
0151          case {3}
0152             [nfields,var_list1,rank,ntype] = hdfgd('inqfields',grid_id);
0153             if nfields == 0
0154                disp([prog_name ': ERROR - No data fields were located.'])
0155                status = hdfgd('detach',grid_id);
0156                status = hdfgd('close', fid);
0157             end
0158          otherwise
0159             disp([prog_name ': ERROR - No content list (based on content flag) was generated.'])
0160             status = hdfgd('detach',grid_id);
0161             status = hdfgd('close', fid);
0162             return;
0163       end
0164    end
0165 
0166 % Now convert one or both comma-delimited text strings (var_list1 and/or var_list2)
0167 % into a cell array of parameter names.
0168    if isempty(content_list)
0169       if ~isempty(var_list1)
0170          list1 = {};
0171          rem   = var_list1;
0172          while ~isempty(rem)
0173             [part_name,rem] = strtok(rem,',');
0174             list1 = cat(2,list1,{part_name});
0175          end
0176       end
0177       content_list = list1;
0178    end
0179    
0180 % Abort the program if the content list is just a single blank string entry.
0181    if length(content_list) == 1 & length(content_list{1}) == 0
0182       disp([prog_name ': ERROR - No set of ' type_list{content_flag} ' parameter names was specified.'])
0183       status = hdfgd('detach',grid_id);
0184       status = hdfgd('close', fid);
0185       return
0186    end
0187 
0188 % Abort the program if the content list is still undefined.
0189    if isempty(content_list)
0190       disp([prog_name ': ERROR - No set of ' type_list{content_flag} ' parameter names was specified.'])
0191       status = hdfgd('detach',grid_id);
0192       status = hdfgd('close', fid);
0193       return
0194    end
0195 
0196    buffer = [];
0197 
0198    for i = 1:length(content_list)
0199 
0200       item_name = content_list{i};
0201 
0202 % Discard any parameter names that have a '=' sign in the name.
0203 % NOTE: This is an optional feature based on experience with these data files.
0204       if ~isempty(findstr(item_name,'=')) 
0205          continue;
0206       end
0207 
0208 % Extract the data value based on the parameter name and data type.
0209       switch content_flag
0210          case {1}
0211             [item_val     ] = hdfgd('diminfo',grid_id,item_name);
0212          case {2}
0213             [item_val,fail] = hdfgd('readattr',grid_id,item_name);
0214          case {3}
0215             [item_val,fail] = hdfgd('readfield',grid_id,item_name,[],[],[]);
0216          otherwise
0217             disp([prog_name ': ERROR - No valid content flag was specified.'])
0218             status = hdfgd('detach',grid_id);
0219             status = hdfgd('close', fid);
0220             return;
0221       end
0222 
0223       if ~isempty(item_val) 
0224 
0225 % Now replace any '.' characters in the parameter name with '_'.
0226          if ~isempty(findstr(item_name,'.'))
0227             new_name  = strrep(item_name,'.','_');
0228             item_name = new_name;
0229          end
0230 
0231 % Now add that parameter data set as a field to the buffer structure.
0232          if ~isfield(buffer,item_name)
0233             eval(['buffer.' item_name ' = item_val;'])
0234          end
0235 
0236       end
0237 
0238    end
0239 
0240    status = hdfgd('detach',grid_id);
0241    status = hdfgd('close', fid);
0242

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005