% Delivered to the Government in Accordance with Contract FA8650-10-C-7080
% 
%  (c) 2011 United Technologies Corp.
% Developed with the sponsorship of the Defense Advanced Research Projects Agency (DARPA).
%  
% Permission is hereby granted, free of charge, to any person obtaining a copy of this data, including any software or models in source or binary form, as well as any drawings, specifications, and documentation (collectively "the Data"), to deal in the Data without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Data, and to permit persons to whom the Data is furnished to do so, subject to the following conditions:
%  
% The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Data.
%  
% THE DATA IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS, SPONSORS, DEVELOPERS, CONTRIBUTORS, OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE DATA OR THE USE OR OTHER DEALINGS IN THE DATA.
% 


function TMSExport(SYS, name)

for i = 1:length(SYS)
    try SYS{i}.Opt.MaxEqConstrRes=max(SYS{i}.Opt.EqConstr); catch dum = 'dum'; end
end

ParamList = {  'Opt.ExitFlag'              '-'  
               'Opt.MaxEqConstrRes'        '-'
               'Opt.Model'                 '-'
               'MFTV.Outlet{2}.Temp'       'F'
               'ABPump.Pars.Power'         'hp'
               'ABPump.Pars.Eta'           '-'
               'MFPump.Pars.Power'         'hp'
               'MFPump.Pars.Eta'           '-'
               'ActPump.Pars.Power'        'hp'
               'ActPump.Pars.Eta'          '-'
               'RTTCooler.Pars.Q'          'kw'};

filename = [name,'.csv'];
ExportCSV(SYS,ParamList,filename);

StationList = {'FuelTank.Outlet'      'PTM'
               'ECS.Outlet'           'T'
               'Hyd.Outlet'           'T'
               'Gen.Outlet'           'T'
               'MFPump.Inlet'         'PTM'
               'MFPump.Outlet'        'PT'
               'ABPump.Inlet'         'PTM'
               'ABPump.Outlet'        'PT'
               'Merge2.Outlet'        'TM'
               'ActPump.Inlet'        'PTM'
               'ActPump.Outlet'       'PT'
               'EngAct.Inlet'         'PTM'
               'EngAct.Outlet'        'PT'
               'EngOil.Inlet'         'TM'
               'EngOil.Outlet'        'T'
               'MFTV.Outlet{2}'       'TM'
               'RTTCooler.Inlet'      'TM'
               'RTTCooler.Outlet'     'PT'};
           
FStationList = MakeStationList(StationList);
SPfilename = [name,'SP.csv'];
ExportCSV(SYS,FStationList,SPfilename);
end

function FullStationList = MakeStationList(StationList)
    np = size(StationList,1);
    j = 1;
    for i = 1:np
        switch StationList{i,2}
        case 'T'
            FullStationList{j,1} = [StationList{i,1},'.Temp'];
            FullStationList{j,2} = ['F'];
            j = j + 1;
        case 'PT'
            FullStationList{j,1} = [StationList{i,1},'.Press'];
            FullStationList{j,2} = ['psia'];
            j = j + 1;
            FullStationList{j,1} = [StationList{i,1},'.Temp'];
            FullStationList{j,2} = ['F'];
            j = j + 1;
        case 'TM'
            FullStationList{j,1}     = [StationList{i,1},'.Temp'];
            FullStationList{j,2}     = ['F'];
            j = j + 1;
            FullStationList{j,1} = [StationList{i,1},'.Mdot'];
            FullStationList{j,2} = ['pps'];
            j = j + 1;
        case 'PTM'
            FullStationList{j,1} = [StationList{i,1},'.Press'];
            FullStationList{j,2} = ['psia'];
            j = j + 1;
            FullStationList{j,1} = [StationList{i,1},'.Temp'];
            FullStationList{j,2} = ['F'];
            j = j + 1;
            FullStationList{j,1} = [StationList{i,1},'.Mdot'];
            FullStationList{j,2} = ['pps'];
            j = j + 1;
        end
    end
end
            
% function FullStationList = MakeStationList(StationList)
%     np = size(StationList,1);
%     j = 1;
%     for i = 1:np
%         sc = StationList(i,2);
%         nc = size(sc,2);
%         switch sc(1)
%         case 'P'
%             FullStationList{j,1}     = [StationList{i,1},'.Press'];
%             FullStationList{j,2}     = ['psia'];
%             j = j + 1;
%             if nc > 2
%                 scl = sc(3:nc-3);
%             else
%                 scl = ' ';
%             end
%         end
%         FullStationList{j,1}     = [StationList{i,1},'.Temp'];
%         FullStationList{j,2}     = ['F'];
%         j = j + 1;
%         if nc > 1
%             scl = sc(2:nc-2);
%         else
%             scl = ' ';
%         end
%         switch scl
%         case 'H'
%             FullStationList{j,1} = [StationList{i,1},'.Fluid.HumRatio'];
%             FullStationList{j,2} = ['gr/lb'];
%             j = j + 1;
%         case 'M'
%             FullStationList{j,1} = [StationList{i,1},'.Mdot'];
%             FullStationList{j,2} = ['pps'];
%             j = j + 1;
%         case 'HM'
%             FullStationList{j,1} = [StationList{i,1},'.Fluid.HumRatio'];
%             FullStationList{j,2} = ['gr/lb'];
%             j = j + 1;
%             FullStationList{j,1} = [StationList{i,1},'.Mdot'];
%             FullStationList{j,2} = ['pps'];
%             j = j + 1;
%         end
%     end
% end
%*********************************************************************
% CVS Version Control Log Data. DO NOT EDIT BELOW THIS LINE!
% $Log: ArchATMSExport.m,v $
% Revision 1.4  2004/11/22 20:29:06  ReeveHM
% Added FSU parameters
%
% Revision 1.3  2004/11/22 13:12:10  ReeveHM
% Cleaned up.
%
% Revision 1.2  2004/11/18 18:27:27  ReeveHM
% no message
%
% Revision 1.1  2004/11/15 22:21:08  ReeveHM
% As recieved from Razvan Florea.  This is the state of the reference aircraft
% TMS model as of 11/15/04.
%

