Code covered by the BSD License  

Highlights from
MODTRAN-compatible SRF (e.g. gauss) Generator

image thumbnail
from MODTRAN-compatible SRF (e.g. gauss) Generator by Jason Brazile
Generate MODTRAN-compatible spectral response functions (e.g. gaussian).

srf_modtran(infname, outfname, shape, n, yedge)
function [chans, centers, fwhms] = srf_modtran(infname, outfname, shape, n, yedge)
% SRF_MODTRAN Generate a MODTRAN-compatible response filter file based on
%    a MODO-style sensor response file
%
% Modtran expects something like this:
%
%  Nanometer data for AVIRIS sensor (assumes Gaussian with max response of 1)
%  CENTER:  373.40NM   FWHM:  9.90NM
%  357.7735  .0010000  27950.64
%  [... 64 more data points deleted ...]
%  CENTER:  382.94NM   FWHM:  9.82NM
%  367.4398  .0010000  27215.34
%  [... 64 more data points deleted ...]
%
% Modo uses a format like this:
%
%  ch#          wvl[nm]     fwhm[nm]
%  1.00000      374.370      15.4500
%  2.00000      384.460      11.5300
%  [... other data points delete ...]
%
% The latest version should be available via:
%wget \
%'http://apex-esa.cvs.sourceforge.net/viewvc/*checkout*/apex-esa/tools/srf_modtran.m'
%
    if nargin < 5 yedge = .001; end
    if nargin < 4 n = 65; end
    if nargin < 3 shape = 'gauss'; end
    if nargin < 2 error('Must give at least infname anf outfname'); end


    [fid,msg] = fopen(infname);
    if fid == -1 error(['fopen failed: ''' infname ''' ' msg]); end
    line =  fgetl(fid);
    if exist('textscan')			% octave doesn't have textscan
      rinfo = textscan(fid, '%f %f %f %*[^\n]');
      [chans, centers, fwhms] = rinfo{:};
    else
      rinfo = fscanf(fid, '%f %f %f', [3,inf])';
      chans = rinfo(:,1); centers = rinfo(:,2); fwhms = rinfo(:,3);
    end
    if fclose(fid) == -1 error(['fclose failed: ''' infname '''']); end

    [fid,msg] = fopen(outfname, 'w');
    if fid == -1 error(['fopen failed: ''' outfname ''' ' msg]); end
    fprintf(fid, 'Nanometer data ''%s'' (''%s'' with max response of 1)\n', ...
	infname, shape);

    for i=1:length(chans)
        [wl, y, wn] = srf_generate(centers(i), fwhms(i), shape, n, yedge);
        fprintf(fid, 'CENTER: %7.2fNM   FWHM: %5.2fNM\n', centers(i), fwhms(i));
        fprintf(fid, '%10.4f %9.7f %9.2f\n', [wl y wn]');
    end
    if fclose(fid) == -1 error(['fclose failed: ''' outfname '''']); end
end

Contact us at files@mathworks.com