From a4f45b528c10c2d4f6dcf947c398ba0db594e1ad Mon Sep 17 00:00:00 2001
From: Federico Felici <federico.felici@epfl.ch>
Date: Tue, 28 May 2019 17:10:51 +0200
Subject: [PATCH] Print including MARTe2 config headers

---
 code/classes/SCDclass_expcode.m         |  4 ----
 code/classes/SCDclass_mdsobjcontainer.m | 26 ++++++++++++++++++++++---
 code/classes/SCDclass_mdspar.m          |  5 ++++-
 code/classes/SCDclass_mdsparvector.m    |  1 -
 4 files changed, 27 insertions(+), 9 deletions(-)

diff --git a/code/classes/SCDclass_expcode.m b/code/classes/SCDclass_expcode.m
index c9a6f86..a13f581 100644
--- a/code/classes/SCDclass_expcode.m
+++ b/code/classes/SCDclass_expcode.m
@@ -521,11 +521,7 @@ classdef SCDclass_expcode
             end
             
             
-            fprintf("+MDSParameters = {\n");
-            fprintf("   Class = MDSParameters\n");
-            fprintf("   Shot = %d\n",shot);
             obj.mdscontainer.printMARTe2parconfig(shot);
-            fprintf("}\n");
             
             fprintf("+MDSWavegens = {\n");
             fprintf("   Class = MDSWavegens\n");
diff --git a/code/classes/SCDclass_mdsobjcontainer.m b/code/classes/SCDclass_mdsobjcontainer.m
index 3e08ccb..f9d9fed 100644
--- a/code/classes/SCDclass_mdsobjcontainer.m
+++ b/code/classes/SCDclass_mdsobjcontainer.m
@@ -247,11 +247,31 @@ classdef SCDclass_mdsobjcontainer
           switch obj.modeltogenerate
             case 'all'
               iorder = getParamsServerTreeOrder(obj);  % order entries following mdsserver, mdstree order
-               for ii=1:obj.numparams
-                jj = iorder(ii);
-                str = obj.mdsparams(jj).genMARTe2entry(shot);
+              prevServer = ''; % init 
+              
+              % Header for MDS for loader
+              loaderStr = sprintf('\n\n+MDSLoader = {\n Class=SPCMDSLoader \n Shot=%d\n',shot);
+              fprintf("%s",loaderStr);
+              
+              for ii=1:obj.numparams
+                mymdsparam = obj.mdsparams(iorder(ii));
+
+                currentServer = mymdsparam.getMDSserver;
+
+                % generate header for MDSsource if necessary
+                if ~strcmp(currentServer,prevServer) %if a new server needs to be opened
+                  if ii~=1, fprintf('  }\n'), end 
+                  % print new source header
+                  fprintf("%s\n",mymdsparam.genMARTe2MDSsourcestr); 
+                end
+                prevServer = currentServer;
+                
+                % generate data source entry
+                str = mymdsparam.genMARTe2entry(shot);
                 fprintf("   %s\n",str);
               end
+              fprintf("}\n\n");
+
             otherwise
               for ii=1:obj.numparams
                 if(strcmp(obj.modeltogenerate,obj.mdsparams(ii).getmodelname))
diff --git a/code/classes/SCDclass_mdspar.m b/code/classes/SCDclass_mdspar.m
index 0c36c55..f7b27e2 100644
--- a/code/classes/SCDclass_mdspar.m
+++ b/code/classes/SCDclass_mdspar.m
@@ -186,7 +186,10 @@ classdef SCDclass_mdspar < matlab.mixin.Heterogeneous
 %            entrystring = ['+' obj.modeltargetpar ' = { Class=' obj.classname ' Path=' obj.tdiexprused ' Server=' obj.mdsserver, ' Tree=' obj.mdstree];   
             entrystring = sprintf('+%-25s = { Class=%-30s Path=%-35s Server=%-25s Tree=%-25s',obj.modeltargetpar,obj.classname,obj.tdiexprused,obj.mdsserver,obj.mdstree);
         end
-        
+
+        function str = genMARTe2MDSsourcestr(obj)
+          str = sprintf(' +MDSSource = {\n  Class=SPCMDSSource\n  Server=%s\n  Tree=%s',obj.mdsserver,obj.mdstree);
+        end
     end
     
     
diff --git a/code/classes/SCDclass_mdsparvector.m b/code/classes/SCDclass_mdsparvector.m
index 22673b6..c0f6f70 100644
--- a/code/classes/SCDclass_mdsparvector.m
+++ b/code/classes/SCDclass_mdsparvector.m
@@ -33,7 +33,6 @@ classdef SCDclass_mdsparvector < SCDclass_mdspar
             entrystring=obj.genMARTe2entrycommon(shot);
             entrystring=[entrystring ' }'];
         end
-
         
     end
 end
-- 
GitLab