function [newStr,newFormat]=buildTextOutputString(curStr,curFormat,txtElement,txtElementParameter)
% Builds the output string and format for the text output file
% Input: the current string (if it exists)
%        the current format string (if it exists)
%        the text element to build for (e.g., latitude,longitude,brightness temperature)
% Optional Input: text element parameter tells how many of a certain variable there is 
%                    (e.g. radiance for infrared bands will contain 16 fields
% Output: updated string and format string
% Kevin Baggett
% Fri Mar  1 00:08:58 UTC 2002

if ~strcmp(curStr,'')
    %append a comma to Format string, semicolon to variable string
    curStr=sprintf('%s;',curStr);
    curFormat=sprintf('%s,',curFormat);
end
pctChar=char(37); % percent character for sprintf of format statements

switch txtElement
case 'LatLon'
    newStr=sprintf('%slat(i);lon(i)',curStr);
    newFormat=sprintf('%s%s7.3f,%s7.3f',curFormat,pctChar,pctChar);
case 'Cloud Mask'
    newStr=sprintf('%sdata.mask(i)',curStr);
    newFormat=sprintf('%s%si',curFormat,pctChar);
case 'Cloud Top Pressure'
    newStr=sprintf('%sfloor(data.ctPressureData1km(i))',curStr);
    newFormat=sprintf('%s%si',curFormat,pctChar);
case 'Cloud Top Temperature'
    newStr=sprintf('%sdata.ctTempData1km(i)',curStr);
    newFormat=sprintf('%s%s7.3f',curFormat,pctChar);
case 'Cloud Phase'
    newStr=sprintf('%sdata.phaseData1km(i)',curStr);
    newFormat=sprintf('%s%si',curFormat,pctChar);
case 'Effective Cloud Emissivity'
    newStr=sprintf('%sdata.effEmissivity1km(i)',curStr);
    newFormat=sprintf('%s%s4.2f',curFormat,pctChar);
case 'Brightness Temperature'
    for j=1:txtElementParameter
        curStr=sprintf('%sdata.bt(%i,i)'';',curStr,j);
        curFormat=sprintf('%s%s7.3f,',curFormat,pctChar);
    end
    curStrlen=length(curStr);
    curFormatLen=length(curFormat);
    newStr=curStr(1:curStrlen-1); %chop off comma or semicolon on the end
    newFormat=curFormat(1:curFormatLen-1);
case 'Radiance'
    for j=1:txtElementParameter
        curStr=sprintf('%sdata.radiance(%i,i)'';',curStr,j);
        curFormat=sprintf('%s%s7.3f,',curFormat,pctChar);
    end
    curStrlen=length(curStr);
    curFormatLen=length(curFormat);
    newStr=curStr(1:curStrlen-1); %chop off comma or semicolon on the end
    newFormat=curFormat(1:curFormatLen-1);
case 'Reflectance'
    for j=1:txtElementParameter
        curStr=sprintf('%sdata.reflectance(%i,i)'';',curStr,j);
        curFormat=sprintf('%s%s7.3f,',curFormat,pctChar);
    end
    curStrlen=length(curStr);
    curFormatLen=length(curFormat);
    newStr=curStr(1:curStrlen-1); %chop off comma or semicolon on the end
    newFormat=curFormat(1:curFormatLen-1);
end
