1 #-*-coding:iso-8859-1-*-
3 # Copyright (C) 2008-2015 EDF R&D
5 # This file is part of SALOME ADAO module
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 # Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D
33 logging.basicConfig(level=logging.WARNING)
35 #----------- Templates Part ---------------#
36 begin_catalog_file = """#-*-coding:iso-8859-1-*-
38 # Copyright (C) 2008-2015 EDF R&D
40 # This file is part of SALOME ADAO module
42 # This library is free software; you can redistribute it and/or
43 # modify it under the terms of the GNU Lesser General Public
44 # License as published by the Free Software Foundation; either
45 # version 2.1 of the License.
47 # This library is distributed in the hope that it will be useful,
48 # but WITHOUT ANY WARRANTY; without even the implied warranty of
49 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
50 # Lesser General Public License for more details.
52 # You should have received a copy of the GNU Lesser General Public
53 # License along with this library; if not, write to the Free Software
54 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
56 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
58 # Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D
60 # --------------------------------------------------------
61 # Generated by AdaoCatalogGenerator on ${date}
62 # --------------------------------------------------------
71 regles = ( AU_MOINS_UN ('ASSIMILATION_STUDY','CHECKING_STUDY'), AU_PLUS_UN ('ASSIMILATION_STUDY','CHECKING_STUDY')),
73 VERSION_CATALOGUE='%s'
75 def NoCheckInNS(filename):
78 def DirectOperatorInNS(filename):
79 if os.path.exists(filename):
80 fc = open(filename, 'r').readlines()
81 cr = re.compile("^def[\s]*DirectOperator[\s]*\(")
83 if cr.match(ln): return 1
85 DirectOperatorInNS.info = u"The Python file has to contain explicitly a \\"DirectOperator\\" function definition with only one vector as argument."
86 def TangentOperatorInNS(filename):
87 if os.path.exists(filename):
88 fc = open(filename, 'r').readlines()
89 cr = re.compile("^def[\s]*TangentOperator[\s]*\(")
91 if cr.match(ln): return 1
93 TangentOperatorInNS.info = u"The Python file has to contain explicitly a \\"TangentOperator\\" function definition with only one pair of vectors as argument."
94 def AdjointOperatorInNS(filename):
95 if os.path.exists(filename):
96 fc = open(filename, 'r').readlines()
97 cr = re.compile("^def[\s]*AdjointOperator[\s]*\(")
99 if cr.match(ln): return 1
101 AdjointOperatorInNS.info = u"The Python file has to contain explicitly an \\"AdjointOperator\\" function definition with only one pair of vectors as argument."
102 """%(module_version.name,module_version.version)
104 # Important : validators=[...] pour que les conditions soient traitées simultanément, en "ET", et pas en "OU" (choisi dans le cas du tuple à la place de la liste)
105 # validators=[OnlyStr(), FileExtVal('py'), FunctionVal(fv)]
107 def F_${data_name}(statut, fv=NoCheckInNS) : return FACT(
109 FROM = SIMP(statut = "o", typ = "TXM", into=(${data_into}), defaut=${data_default}),
110 SCRIPT_DATA = BLOC ( condition = " FROM in ( 'Script', ) ",
111 SCRIPT_FILE = SIMP(statut = "o", typ = "FichierNoAbs", validators=[OnlyStr(), FileExtVal('py'), FunctionVal(fv)], fr="En attente d'un nom de fichier script, avec ou sans le chemin complet pour le trouver, contenant si nécessaire la définition d'une variable interne de même nom que le concept parent", ang="Waiting for a script file name, with or without the full path to find it, containing if necessary the definition of an internal variable of the same name as the parent concept"),
113 STRING_DATA = BLOC ( condition = " FROM in ( 'String', ) ",
114 STRING = SIMP(statut = "o", typ = "TXM",${ms_default} fr="En attente d'une chaine de caractères entre guillements. Pour construire un vecteur ou une matrice, ce doit être une suite de nombres, utilisant un espace ou une virgule pour séparer deux éléments et un point-virgule pour séparer deux lignes", ang="Waiting for a string in quotes. To build a vector or a matrix, it has to be a float serie, using a space or comma to separate two elements in a line, a semi-colon to separate rows"),
116 SCRIPTWITHFUNCTIONS_DATA = BLOC ( condition = " FROM in ( 'ScriptWithFunctions', ) ",
117 SCRIPTWITHFUNCTIONS_FILE = SIMP(statut = "o", typ = "FichierNoAbs", validators=[OnlyStr(), FileExtVal('py'), FunctionVal(DirectOperatorInNS), FunctionVal(TangentOperatorInNS), FunctionVal(AdjointOperatorInNS)], fr="En attente d'un nom de fichier script, avec ou sans le chemin complet pour le trouver, contenant en variables internes trois fonctions de calcul nommées DirectOperator, TangentOperator et AdjointOperator", ang="Waiting for a script file name, with or without the full path to find it, containing as internal variables three computation functions named DirectOperator, TangentOperator and AdjointOperator"),
119 SCRIPTWITHONEFUNCTION_DATA = BLOC ( condition = " FROM in ( 'ScriptWithOneFunction', ) ",
120 SCRIPTWITHONEFUNCTION_FILE = SIMP(statut = "o", typ = "FichierNoAbs", validators=[OnlyStr(), FileExtVal('py'), FunctionVal(DirectOperatorInNS)], fr="En attente d'un nom de fichier script, avec ou sans le chemin complet pour le trouver, contenant en variable interne une seule fonction de calcul nommée DirectOperator", ang="Waiting for a script file name, with or without the full path to find it, containing as internal variable only one function named DirectOperator"),
121 DifferentialIncrement = SIMP(statut="o", typ = "R", val_min=0, val_max=1, defaut=0.01, fr="Incrément de la perturbation dX pour calculer la dérivée, construite en multipliant X par l'incrément en évitant les valeurs nulles", ang="Increment of dX perturbation to calculate the derivative, build multiplying X by the increment avoiding null values"),
122 CenteredFiniteDifference = SIMP(statut="o", typ = "I", into=(0, 1), defaut=0, fr="Formulation centrée (1) ou décentrée (0) pour la méthode des différences finies", ang="Centered (1) or uncentered (0) formulation for the finite differences method"),
123 EnableMultiProcessing = SIMP(statut="f", typ = "I", into=(0, 1), defaut=0, fr="Calculs élémentaires effectués en séquentiel (0) ou en parallèle (1) dans la méthode des différences finies", ang="Elementary calculations done sequentially (0) or in parallel (1) in the finite differences method"),
124 NumberOfProcesses = SIMP(statut="f", typ = "I", val_min=0, defaut=0, fr="Nombre de processus parallèles, 0 pour un contrôle automatique", ang="Number of parallel processes, 0 for automatic control"),
126 SCRIPTWITHSWITCH_DATA = BLOC ( condition = " FROM in ( 'ScriptWithSwitch', ) ",
127 SCRIPTWITHSWITCH_FILE = SIMP(statut = "o", typ = "FichierNoAbs", validators=[OnlyStr(), FileExtVal('py')], fr="En attente d'un nom de fichier script, avec ou sans le chemin complet pour le trouver, contenant un switch pour les calculs direct, tangent et adjoint", ang="Waiting for a script file name, with or without the full path to find it, containing a switch for direct, tangent and adjoint computations"),
129 TEMPLATE_DATA = BLOC (condition = " FROM in ( 'Template', ) ",
130 Template = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "AnalysisPrinter", into=("AnalysisPrinter", "AnalysisSaver", "AnalysisPrinterAndSaver")),
131 AnalysisPrinter = BLOC (condition = " Template == 'AnalysisPrinter' ",
132 ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import numpy\\nxa=numpy.ravel(ADD.get('Analysis')[-1])\\nprint 'Analysis:',xa" ),
134 AnalysisSaver = BLOC (condition = " Template == 'AnalysisSaver' ",
135 ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import numpy\\nxa=numpy.ravel(ADD.get('Analysis')[-1])\\nf='/tmp/analysis.txt'\\nprint 'Analysis saved in \\"%s\\"'%f\\nnumpy.savetxt(f,xa)" ),
137 AnalysisPrinterAndSaver = BLOC (condition = " Template == 'AnalysisPrinterAndSaver' ",
138 ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import numpy\\nxa=numpy.ravel(ADD.get('Analysis')[-1])\\nprint 'Analysis:',xa\\nf='/tmp/analysis.txt'\\nprint 'Analysis saved in \\"%s\\"'%f\\nnumpy.savetxt(f,xa)" ),
145 def F_InitChoice() : return ("Background",
149 "ObservationOperator",
152 "AlgorithmParameters",
156 def F_Init(statut) : return FACT(statut = statut,
157 INIT_FILE = SIMP(statut = "o", typ = "FichierNoAbs", validators=[OnlyStr(), FileExtVal('py')]),
158 TARGET_LIST = SIMP(statut = "o", typ = "TXM", min=1, max="**", into=F_InitChoice(), validators=(VerifExiste(2))),
162 assim_data_method = """
163 def ${assim_name}InNS(filename):
164 if os.path.exists(filename):
165 fc = open(filename, 'r').readlines()
166 cr = re.compile("^${assim_name}[\s]*=")
168 if cr.match(ln): return 1
170 ${assim_name}InNS.info = u"The Python file has to contain explicitly a \\"${assim_name}\\" variable."
171 def F_${assim_name}(statut, fv=NoCheckInNS) : return FACT(
174 INPUT_TYPE = SIMP(statut="o", typ = "TXM", into=(${choices}), defaut=${default_choice}),${decl_choices}
178 assim_data_choice = """
179 ${choice_name} = BLOC ( condition = " INPUT_TYPE in ( '${choice_name}', ) ",
180 data = F_${choice_name}("o", fv),
183 observers_choice = """
184 ${var_name} = BLOC (condition=" '${var_name}' in set(SELECTION) ",
185 ${var_name}_data = FACT(statut = "o",
186 Scheduler = SIMP(statut = "f", typ = "TXM"),
187 Info = SIMP(statut = "o", typ = "TXM", defaut = "${var_name}"),
188 NodeType = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "Template", into=("String", "Script", "Template")),
189 PythonScript = BLOC (condition = " NodeType == 'String' ",
190 Value = SIMP(statut = "o", typ = "TXM")
192 UserFile = BLOC (condition = " NodeType == 'Script' ",
193 Value = SIMP(statut = "o", typ = "FichierNoAbs", validators=[OnlyStr(), FileExtVal('py')])
195 ObserverTemplate = F_ObserverTemplate(),
199 observers_method = """
200 def F_ObserverTemplate() : return BLOC(condition = " NodeType == 'Template' ",
201 Template = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "ValuePrinter", into=("ValuePrinter", "ValueSeriePrinter", "ValueSaver", "ValueSerieSaver", "ValuePrinterAndSaver", "ValueSeriePrinterAndSaver", "ValueGnuPlotter", "ValueSerieGnuPlotter")),
202 ValuePrinter = BLOC (condition = " Template == 'ValuePrinter' ",
203 ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "print info,var[-1]" ),
205 ValueSeriePrinter = BLOC (condition = " Template == 'ValueSeriePrinter' ",
206 ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "print info,var[:]" ),
208 ValueSaver = BLOC (condition = " Template == 'ValueSaver' ",
209 ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import numpy,re\\nv=numpy.array((var[-1]))\\nglobal istep\\ntry:\\n istep += 1\\nexcept:\\n istep = 0\\nf='/tmp/value_%s_%05i.txt'%(info,istep)\\nf=re.sub('\s','_',f)\\nprint 'Value saved in \\"%s\\"'%f\\nnumpy.savetxt(f,v)" ),
211 ValueSerieSaver = BLOC (condition = " Template == 'ValueSerieSaver' ",
212 ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import numpy,re\\nv=numpy.array((var[:])) \\nglobal istep\\ntry:\\n istep += 1\\nexcept:\\n istep = 0\\nf='/tmp/value_%s_%05i.txt'%(info,istep)\\nf=re.sub('\s','_',f)\\nprint 'Value saved in \\"%s\\"'%f\\nnumpy.savetxt(f,v)" ),
214 ValuePrinterAndSaver = BLOC (condition = " Template == 'ValuePrinterAndSaver' ",
215 ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import numpy,re\\nv=numpy.array((var[-1]))\\nprint info,v\\nglobal istep\\ntry:\\n istep += 1\\nexcept:\\n istep = 0\\nf='/tmp/value_%s_%05i.txt'%(info,istep)\\nf=re.sub('\s','_',f)\\nprint 'Value saved in \\"%s\\"'%f\\nnumpy.savetxt(f,v)" ),
217 ValueSeriePrinterAndSaver = BLOC (condition = " Template == 'ValueSeriePrinterAndSaver' ",
218 ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import numpy,re\\nv=numpy.array((var[:])) \\nprint info,v\\nglobal istep\\ntry:\\n istep += 1\\nexcept:\\n istep = 0\\nf='/tmp/value_%s_%05i.txt'%(info,istep)\\nf=re.sub('\s','_',f)\\nprint 'Value saved in \\"%s\\"'%f\\nnumpy.savetxt(f,v)" ),
220 ValueGnuPlotter = BLOC (condition = " Template == 'ValueGnuPlotter' ",
221 ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import Gnuplot\\nglobal ifig,gp\\ntry:\\n ifig += 1\\n gp('set style data lines')\\nexcept:\\n ifig = 0\\n gp = Gnuplot.Gnuplot(persist=1)\\n gp('set style data lines')\\ngp('set title \\"%s (Figure %i)\\"'%(info,ifig))\\ngp.plot( Gnuplot.Data( var[-1], with_='lines lw 2' ) )" ),
223 ValueSerieGnuPlotter = BLOC (condition = " Template == 'ValueSerieGnuPlotter' ",
224 ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import Gnuplot\\nglobal ifig,gp\\ntry:\\n ifig += 1\\n gp('set style data lines')\\nexcept:\\n ifig = 0\\n gp = Gnuplot.Gnuplot(persist=1)\\n gp('set style data lines')\\ngp('set title \\"%s (Figure %i)\\"'%(info,ifig))\\ngp.plot( Gnuplot.Data( var[:], with_='lines lw 2' ) )" ),
228 def F_Observers(statut) : return FACT(
230 SELECTION = SIMP(statut="o", defaut=[], typ="TXM", min=0, max="**", validators=NoRepeat(), into=(${choices})),${decl_choices}
235 def AlgorithmParametersInNS(filename):
236 if os.path.exists(filename):
237 fc = open(filename, 'r').readlines()
238 cr = re.compile("^AlgorithmParameters[\s]*=")
240 if cr.match(ln): return 1
242 AlgorithmParametersInNS.info = u"The Python file has to contain explicitly an \\"AlgorithmParameters\\" variable."
243 def F_AlgorithmParameters(statut, algos_names, fv=NoCheckInNS) : return FACT(
245 Algorithm = SIMP(statut="o", typ = "TXM", into = algos_names ),
246 Parameters = SIMP(statut="f", typ = "TXM", into=("Defaults", "Dict") ),
247 Dict = BLOC ( condition = " Parameters == 'Dict' ",
249 data = F_Dict("o", fv),
250 ),${all_algo_defaults}
253 one_algo_choices = """
254 Parameters${algo_name} = BLOC (condition = " (Parameters == 'Defaults') and (Algorithm == '${algo_name}') ",
256 ${algo_parameters} ),"""
259 def F_variables(statut) : return FACT(
261 regles = ( MEME_NOMBRE ('NAMES', 'SIZES')),
262 NAMES = SIMP(statut="o", typ="TXM", max="**", validators=NoRepeat()),
263 SIZES = SIMP(statut="o", typ="I", val_min=1, max="**")
266 os.chdir(os.path.abspath(dirname))
268 ChDir.info = u"This has to be a regular directory path."
270 ASSIMILATION_STUDY = PROC(nom="ASSIMILATION_STUDY",
273 StudyName = SIMP(statut="o", typ = "TXM", defaut="ADAO Calculation Case"),
274 StudyRepertory = SIMP(statut="f", typ = "Repertoire", validators=FunctionVal(ChDir), min=1, max=1),
275 Debug = SIMP(statut="f", typ = "I", into=(0, 1), defaut=0),
276 AlgorithmParameters = F_AlgorithmParameters("o",(${algos_names}), AlgorithmParametersInNS),
277 Background = F_Background("o", BackgroundInNS),
278 BackgroundError = F_BackgroundError("o", BackgroundErrorInNS),
279 Observation = F_Observation("o", ObservationInNS),
280 ObservationError = F_ObservationError("o", ObservationErrorInNS),
281 ObservationOperator = F_ObservationOperator("o"),
282 EvolutionModel = F_EvolutionModel("f"),
283 EvolutionError = F_EvolutionError("f", EvolutionErrorInNS),
284 ControlInput = F_ControlInput("f"),
285 UserDataInit = F_Init("f"),
286 UserPostAnalysis = F_UserPostAnalysis("o"),
287 InputVariables = F_variables("f"),
288 OutputVariables = F_variables("f"),
289 Observers = F_Observers("f")
292 CHECKING_STUDY = PROC(nom="CHECKING_STUDY",
295 StudyName = SIMP(statut="o", typ = "TXM", defaut="ADAO Checking Case"),
296 StudyRepertory = SIMP(statut="f", typ = "Repertoire", validators=FunctionVal(ChDir), min=1, max=1),
297 Debug = SIMP(statut="f", typ = "I", into=(0, 1), defaut=0),
298 AlgorithmParameters = F_AlgorithmParameters("o", (${check_names}), AlgorithmParametersInNS),
299 CheckingPoint = F_CheckingPoint("o", CheckingPointInNS),
300 BackgroundError = F_BackgroundError("f", BackgroundErrorInNS),
301 Observation = F_Observation("f", ObservationInNS),
302 ObservationError = F_ObservationError("f", ObservationErrorInNS),
303 ObservationOperator = F_ObservationOperator("o"),
304 UserDataInit = F_Init("f"),
305 Observers = F_Observers("f")
309 begin_catalog_file = string.Template(begin_catalog_file)
310 data_method = string.Template(data_method)
311 assim_data_method = string.Template(assim_data_method)
312 assim_data_choice = string.Template(assim_data_choice)
313 assim_study = string.Template(assim_study)
314 observers_method = string.Template(observers_method)
315 observers_choice = string.Template(observers_choice)
316 algo_choices = string.Template(algo_choices)
317 one_algo_choices = string.Template(one_algo_choices)
319 #----------- End of Templates Part ---------------#
323 #----------- Begin generation script -----------#
324 print "-- Starting AdaoCalatogGenerator.py --"
328 import daYacsSchemaCreator
329 import daCore.AssimilationStudy
330 import daYacsSchemaCreator.infos_daComposant as infos
332 logging.fatal("Import of ADAO python modules failed !" +
333 "\n add ADAO python installation directory in your PYTHONPATH")
334 traceback.print_exc()
337 def check_args(args):
338 logging.debug("Arguments are :" + str(args))
340 logging.fatal("Bad number of arguments: you have to provide two arguments (%d given)" % (len(args)))
344 from optparse import OptionParser
345 usage = "usage: %prog [options] catalog_path catalog_name"
347 my_parser = OptionParser(usage=usage, version=version)
348 (options, args) = my_parser.parse_args()
351 catalog_path = args[0]
352 catalog_name = args[1]
354 # Generates into a string
355 mem_file = StringIO.StringIO()
358 from time import strftime
359 mem_file.write(begin_catalog_file.substitute(date=strftime("%Y-%m-%d %H:%M:%S")))
361 # Step initial: on obtient la liste des algos
365 assim_study_object = daCore.AssimilationStudy.AssimilationStudy()
366 algos_list = assim_study_object.get_available_algorithms()
367 del assim_study_object
368 for algo_name in algos_list:
369 if algo_name in infos.AssimAlgos:
370 logging.debug("An assimilation algorithm is found: " + algo_name)
371 algos_names += "\"" + algo_name + "\", "
372 elif algo_name in infos.CheckAlgos:
373 logging.debug("A checking algorithm is found: " + algo_name)
374 check_names += "\"" + algo_name + "\", "
376 logging.debug("This algorithm is not considered: " + algo_name)
378 # Step 1: A partir des infos, on cree les fonctions qui vont permettre
379 # d'entrer les donnees utilisateur
380 for data_input_name in infos.DataTypeDict.keys():
381 logging.debug('A data input Type is found: ' + data_input_name)
382 data_name = data_input_name
387 # On recupere les differentes facon d'entrer les donnees
388 for basic_type in infos.DataTypeDict[data_input_name]:
389 data_into += "\"" + basic_type + "\", "
391 # On choisit le default
392 data_default = "\"" + infos.DataTypeDefaultDict[data_input_name] + "\""
393 if infos.DataSValueDefaultDict.has_key(data_input_name):
394 ms_default = " defaut=\"" + infos.DataSValueDefaultDict[data_input_name] + "\","
396 mem_file.write(data_method.substitute(data_name = data_name,
397 data_into = data_into,
398 data_default = data_default,
399 ms_default = ms_default,
400 algos_names = algos_names+check_names))
402 # Step 2: On cree les fonctions qui permettent de rentrer les donnees des algorithmes
403 for assim_data_input_name in infos.AssimDataDict.keys():
404 logging.debug("An input function data input is found: " + assim_data_input_name)
405 # assim_name = assim_data_input_name
411 if infos.AssimDataDefaultDict[assim_data_input_name] in infos.StoredAssimData:
412 storage = " Stored = SIMP(statut=\"o\", typ = \"I\", into=(0, 1), defaut=0, fr=\"Choix de stockage interne ou non du concept parent\", ang=\"Choice of the storage or not of the parent concept\"),"
413 for choice in infos.AssimDataDict[assim_data_input_name]:
414 choices += "\"" + choice + "\", "
415 decl_choices += assim_data_choice.substitute(choice_name = choice)
416 if choice in infos.StoredAssimData:
417 storage = " Stored = SIMP(statut=\"o\", typ = \"I\", into=(0, 1), defaut=0, fr=\"Choix de stockage interne ou non du concept parent\", ang=\"Choice of the storage or not of the parent concept\"),"
418 default_choice = "\"" + infos.AssimDataDefaultDict[assim_data_input_name] + "\""
420 mem_file.write(assim_data_method.substitute(assim_name = assim_data_input_name,
423 decl_choices = decl_choices,
424 default_choice = default_choice))
426 # Step 3: On ajoute les fonctions representant les options possibles
427 for opt_name in infos.OptDict.keys():
428 logging.debug("An optional node is found: " + opt_name)
434 for choice in infos.OptDict[opt_name]:
435 data_into += "\"" + choice + "\", "
437 # On choisit le default
438 data_default = "\"" + infos.OptDefaultDict[opt_name] + "\""
439 if infos.DataSValueDefaultDict.has_key(opt_name):
440 ms_default = " defaut=\"" + infos.DataSValueDefaultDict[opt_name] + "\","
442 mem_file.write(data_method.substitute(data_name = data_name,
443 data_into = data_into,
444 data_default = data_default,
445 ms_default = ms_default,
446 algos_names = algos_names+check_names))
448 # Step 4: On ajoute la methode optionnelle init
449 # TODO uniformiser avec le step 3
450 mem_file.write(init_method)
452 # Step 5: Add observers
454 for obs_var in infos.ObserversList:
455 decl_choices += observers_choice.substitute(var_name=obs_var)
456 mem_file.write(observers_method.substitute(choices = infos.ObserversList,
457 decl_choices = decl_choices))
459 # Step 5: Add algorithmic choices
461 all_names = eval((algos_names+check_names))
462 all_algo_defaults = ""
463 for algo in all_names:
464 assim_study_object = daCore.AssimilationStudy.AssimilationStudy()
465 assim_study_object.setAlgorithm(choice=algo)
466 par_dict = assim_study_object.getAlgorithmParameters(False)
467 par_keys = par_dict.keys()
471 if pn in ("StoreInternalVariables",): continue # Cles a supprimer
472 pt = par_dict[pn]["typecast"]
473 pd = par_dict[pn]["default"]
474 pm = par_dict[pn]["message"]
475 if par_dict[pn].has_key("minval") and par_dict[pn]["minval"] is not None:
476 vi = ", val_min=%s"%par_dict[pn]["minval"]
479 if par_dict[pn].has_key("minval") and par_dict[pn]["maxval"] is not None:
480 vs = ", val_max=%s"%par_dict[pn]["maxval"]
484 algo_parameters += """ %s = SIMP(statut="f", typ="I"%s%s, min=1, max=1, defaut=%s, fr="%s"),\n"""%(pn,vi,vs,int(pd),pm)
486 algo_parameters += """ %s = SIMP(statut="f", typ="R"%s%s, min=1, max=1, defaut=%s, fr="%s"),\n"""%(pn,vi,vs,float(pd),pm)
488 algo_parameters += """ %s = SIMP(statut="f", typ="I", min=1, max=1, defaut=%s, fr="%s"),\n"""%(pn,int(pd),pm)
489 elif pt is str and par_dict[pn].has_key("listval"):
490 algo_parameters += """ %s = SIMP(statut="f", typ="TXM", min=1, max=1, defaut="%s", into=%s, fr="%s"),\n"""%(pn,str(pd),par_dict[pn]["listval"],pm)
491 elif pt is tuple and par_dict[pn].has_key("listval"):
492 algo_parameters += """ %s = SIMP(statut="f", typ="TXM", max="**", into=%s, fr="%s"),\n"""%(pn,par_dict[pn]["listval"],pm)
494 algo_parameters += """ %s = SIMP(statut="f", typ="TXM", fr="%s"),\n"""%(pn,pm)
495 del assim_study_object
496 if algo_parameters != "":
497 all_algo_defaults += one_algo_choices.substitute(
499 algo_parameters=algo_parameters,
502 mem_file.write(algo_choices.substitute(all_algo_defaults=all_algo_defaults))
504 # Final step: Add algorithm and assim_study
505 mem_file.write(assim_study.substitute(algos_names=algos_names,
506 check_names=check_names,
507 decl_algos=decl_algos))
509 final_file = open(catalog_path + "/" + catalog_name, "wr")
510 final_file.write(mem_file.getvalue())