Home > atmlab > sensors > airs_l12_swath_file.m

airs_l12_swath_file

PURPOSE ^

function buffer = airs_l12_swath_file(filename,content_flag,content_list,swathname)

SYNOPSIS ^

function buffer = airs_l12_swath_file(filename,content_flag,content_list,swathname)

DESCRIPTION ^

   function buffer = airs_l12_swath_file(filename,content_flag,content_list,swathname)

 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 1 or 2 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 1B/2 EOS-HDF swath 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 swath(s) in that file.
                1: The name and values of the swath's dimension parameters.
                2: The name and values of the swath's attribute parameters.
                3: The name and values of the swath'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.
 swathname    - A text expression for the data swath within the granule file that is to be
                examined. This function will only process one data swath at a time. In the
                (typical) case that there is only ONE data swath 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_l12_swath_file.m

SOURCE CODE ^

0001 function buffer = airs_l12_swath_file(filename,content_flag,content_list,swathname)
0002 
0003 %   function buffer = airs_l12_swath_file(filename,content_flag,content_list,swathname)
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 1 or 2 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 1B/2 EOS-HDF swath 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 swath(s) in that file.
0021 %                1: The name and values of the swath's dimension parameters.
0022 %                2: The name and values of the swath's attribute parameters.
0023 %                3: The name and values of the swath'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 % swathname    - A text expression for the data swath within the granule file that is to be
0030 %                examined. This function will only process one data swath at a time. In the
0031 %                (typical) case that there is only ONE data swath 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_L12_swath_file';
0046 
0047    buffer = [];
0048 
0049    if ~exist('swathname','var')
0050       swathname = [];
0051    end
0052 
0053    if ~exist('content_list','var')
0054       content_list = {};
0055    end
0056 
0057    if ischar(content_list)
0058       tmp = content_list;
0059       content_list = {tmp};
0060       clear tmp
0061    end
0062 
0063 % Abort the program if no data file has been provided.
0064    if isempty(filename)
0065       disp([prog_name ': ERROR - No input filename was specified.'])
0066       return
0067    end
0068 
0069 % Abort the program if no data type has been specified.
0070    if isempty(content_flag)
0071       disp([prog_name ': ERROR - No content code (type) was provided.'])
0072       return
0073    end
0074 
0075 % Set up a set of names (labels) for the different types of data queries.
0076    type_list = {'swath','dimension','attribute','field'};
0077 
0078 % Get a file id value.
0079    fid   = hdfsw('open',filename,'read');
0080 
0081 % Abort the program if the file does not exist or cannot be read.
0082    if fid == -1
0083       disp([prog_name ': ERROR - ' filename ' could not be opened.'])
0084       status = hdfsw('close', fid);
0085       return
0086    end
0087 
0088 % Get the number of data swaths in the file (normally just 1)
0089    [nswath, swathlist] = hdfsw('inqswath',filename);
0090 
0091 % Abort the program if no data swath(s) is/are found.
0092    if nswath == 0 | isempty(swathlist)
0093       disp([prog_name ': ERROR - ' filename ' has no data swath.'])
0094       status = hdfsw('close', fid);
0095       return;
0096    end
0097 
0098 % If only the swath list is requested, return that text string and end the program.
0099    if content_flag == 0
0100       buffer = swathlist;
0101       status = hdfsw('close', fid);
0102       return;
0103    end
0104 
0105 % Accept a user-specified data swath name or the first (and only) available swath within the file.
0106 % Only continue processing if the data set is confined to a single swath.
0107    if ~isempty(swathname)
0108       swathname = swathname;
0109    else
0110       swathname = swathlist;
0111    end
0112 
0113 % Abort the program if more than one data swath can be extracted from 'swathname'.
0114    if ~isempty(findstr(swathname,','))
0115       disp([prog_name ': ERROR - This file contains multiple data swaths - Choose just one.'])
0116       disp([prog_name ': Swath List = ' swathname])
0117       status = hdfsw('close', fid);
0118       return;
0119    end
0120 
0121 % Attach an ID to this swath.
0122    swath_id = hdfsw('attach', fid, swathname);
0123    if (swath_id == -1)
0124       disp([prog_name ': ERROR - Unable to open swath ' swathname])
0125       status = hdfsw('detach',swath_id);
0126       status = hdfsw('close', fid);
0127       return;
0128    end
0129 
0130 % Select the content list (i.e., set of parameter names) from the swath itself
0131 % unless these names are specified directly by the user.
0132    var_list1 = [];
0133    var_list2 = [];
0134    list1     = {};
0135    list2     = {};
0136    if isempty(content_list)
0137       switch content_flag
0138          case {1}
0139             [ndims,var_list1,dims] = hdfsw('inqdims',swath_id);
0140          case {2}
0141             [nattrib,var_list1]  = hdfsw('inqattrs', swath_id);
0142          case {3}
0143             [ngeo_fields,var_list1,rank,ntype] = hdfsw('inqgeofields',swath_id);
0144             [ndata_fields,var_list2,rank,type] = hdfsw('inqdatafields',swath_id);
0145          otherwise
0146             disp([prog_name ': ERROR - No content list (based on content flag) was generated.'])
0147             status = hdfsw('detach',swath_id);
0148             status = hdfsw('close', fid);
0149             return;
0150       end
0151    end
0152 
0153 % Now convert one or both comma-delimited text strings (var_list1 and/or var_list2)
0154 % into a cell array of parameter names.
0155    if isempty(content_list)
0156       if ~isempty(var_list1)
0157          list1 = {};
0158          rem   = var_list1;
0159          while ~isempty(rem)
0160             [part_name,rem] = strtok(rem,',');
0161             list1 = cat(2,list1,{part_name});
0162          end
0163       end
0164       if ~isempty(var_list2)
0165          list2 = {};
0166          rem   = var_list2;
0167          while ~isempty(rem)
0168             [part_name,rem] = strtok(rem,',');
0169             list2 = cat(2,list2,{part_name});
0170          end
0171       end
0172       content_list = union(list1,list2);
0173    end
0174    
0175 % Abort the program if the content list is just a single blank string entry.
0176    if length(content_list) == 1 & length(content_list{1}) == 0
0177       disp([prog_name ': ERROR - No set of ' type_list{content_flag} ' parameter names was specified.'])
0178       status = hdfsw('detach',swath_id);
0179       status = hdfsw('close', fid);
0180       return
0181    end
0182 
0183 % Abort the program if the content list is still undefined.
0184    if isempty(content_list)
0185       disp([prog_name ': ERROR - No set of ' type_list{content_flag} ' parameter names was specified.'])
0186       status = hdfsw('detach',swath_id);
0187       status = hdfsw('close', fid);
0188       return
0189    end
0190 
0191    buffer = [];
0192 
0193    for i = 1:length(content_list)
0194 
0195       item_name = content_list{i};
0196 
0197 % Discard any parameter names that have a '=' sign in the name.
0198 % NOTE: This is an optional feature based on experience with these data files.
0199       if ~isempty(findstr(item_name,'=')) 
0200          continue;
0201       end
0202 
0203 % Extract the data value based on the parameter name and data type.
0204       switch content_flag
0205          case {1}
0206             [item_val     ] = hdfsw('diminfo',swath_id,item_name);
0207          case {2}
0208             [item_val,fail] = hdfsw('readattr',swath_id,item_name);
0209          case {3}
0210             [item_val,fail] = hdfsw('readfield',swath_id,item_name,[],[],[]);
0211          otherwise
0212             disp([prog_name ': ERROR - No valid content flag was specified.'])
0213             status = hdfsw('detach',swath_id);
0214             status = hdfsw('close', fid);
0215             return;
0216       end
0217 
0218       if ~isempty(item_val) 
0219 
0220 % Now replace any '.' characters in the parameter name with '_'.
0221          if ~isempty(findstr(item_name,'.'))
0222             new_name  = strrep(item_name,'.','_');
0223             item_name = new_name;
0224          end
0225 
0226 % Now add that parameter data set as a field to the buffer structure.
0227          if ~isfield(buffer,item_name)
0228             eval(['buffer.' item_name ' = item_val;'])
0229          end
0230 
0231       end
0232 
0233    end
0234 
0235 % Close out the swath and file.
0236    status = hdfsw('detach',swath_id);
0237    status = hdfsw('close', fid);
0238

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