From: Jean-Philippe ARGAUD Date: Tue, 21 Apr 2015 21:16:51 +0000 (+0200) Subject: Documentation and source minor corrections and improvements X-Git-Tag: V7_6_0~17 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b4f6ca68c45cb48121412758248e4c9ab843d54f;p=modules%2Fadao.git Documentation and source minor corrections and improvements --- diff --git a/bin/AdaoCatalogGenerator.py b/bin/AdaoCatalogGenerator.py index 55a322c..6e1b056 100644 --- a/bin/AdaoCatalogGenerator.py +++ b/bin/AdaoCatalogGenerator.py @@ -61,7 +61,9 @@ begin_catalog_file = """#-*-coding:iso-8859-1-*- # Generated by AdaoCatalogGenerator on ${date} # -------------------------------------------------------- +import os, re import Accas +from Accas.A_VALIDATOR import FileExtVal, FunctionVal from Accas import * JdC = JDC_CATA ( @@ -70,30 +72,60 @@ JdC = JDC_CATA ( regles = ( AU_MOINS_UN ('ASSIMILATION_STUDY','CHECKING_STUDY'), AU_PLUS_UN ('ASSIMILATION_STUDY','CHECKING_STUDY')), ) VERSION_CATALOGUE='%s' + +def NoCheckInNS(filename): + return 1 +NoCheckInNS.info = "" +def DirectOperatorInNS(filename): + if os.path.exists(filename): + fc = open(filename, 'r').readlines() + cr = re.compile("^DirectOperator[\s]*=") + for ln in fc: + if cr.match(ln): return 1 + return 0 +DirectOperatorInNS.info = u"The Python file has to contain explicitly a \\"DirectOperator\\" variable." +def TangentOperatorInNS(filename): + if os.path.exists(filename): + fc = open(filename, 'r').readlines() + cr = re.compile("^TangentOperator[\s]*=") + for ln in fc: + if cr.match(ln): return 1 + return 0 +TangentOperatorInNS.info = u"The Python file has to contain explicitly a \\"TangentOperator\\" variable." +def AdjointOperatorInNS(filename): + if os.path.exists(filename): + fc = open(filename, 'r').readlines() + cr = re.compile("^AdjointOperator[\s]*=") + for ln in fc: + if cr.match(ln): return 1 + return 0 +AdjointOperatorInNS.info = u"The Python file has to contain explicitly a \\"AdjointOperator\\" variable." """%(module_version.name,module_version.version) +# 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) +# validators=[OnlyStr(), FileExtVal('py'), FunctionVal(fv)] data_method = """ -def F_${data_name}(statut) : return FACT( +def F_${data_name}(statut, fv=NoCheckInNS) : return FACT( statut = statut, FROM = SIMP(statut = "o", typ = "TXM", into=(${data_into}), defaut=${data_default}), SCRIPT_DATA = BLOC ( condition = " FROM in ( 'Script', ) ", - SCRIPT_FILE = SIMP(statut = "o", typ = "FichierNoAbs", validators=(OnlyStr()), 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"), + 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"), ), STRING_DATA = BLOC ( condition = " FROM in ( 'String', ) ", 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"), ), SCRIPTWITHFUNCTIONS_DATA = BLOC ( condition = " FROM in ( 'ScriptWithFunctions', ) ", - SCRIPTWITHFUNCTIONS_FILE = SIMP(statut = "o", typ = "FichierNoAbs", validators=(OnlyStr()), 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"), + 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"), ), SCRIPTWITHONEFUNCTION_DATA = BLOC ( condition = " FROM in ( 'ScriptWithOneFunction', ) ", - SCRIPTWITHONEFUNCTION_FILE = SIMP(statut = "o", typ = "FichierNoAbs", validators=(OnlyStr()), 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"), + 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"), 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"), 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"), 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"), 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"), ), SCRIPTWITHSWITCH_DATA = BLOC ( condition = " FROM in ( 'ScriptWithSwitch', ) ", - SCRIPTWITHSWITCH_FILE = SIMP(statut = "o", typ = "FichierNoAbs", validators=(OnlyStr()), 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"), + 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"), ), TEMPLATE_DATA = BLOC (condition = " FROM in ( 'Template', ) ", Template = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "AnalysisPrinter", into=("AnalysisPrinter", "AnalysisSaver", "AnalysisPrinterAndSaver")), @@ -123,13 +155,21 @@ def F_InitChoice() : return ("Background", ) def F_Init(statut) : return FACT(statut = statut, - INIT_FILE = SIMP(statut = "o", typ = "FichierNoAbs", validators=(OnlyStr())), + INIT_FILE = SIMP(statut = "o", typ = "FichierNoAbs", validators=[OnlyStr(), FileExtVal('py')]), TARGET_LIST = SIMP(statut = "o", typ = "TXM", min=1, max="**", into=F_InitChoice(), validators=(VerifExiste(2))), ) """ assim_data_method = """ -def F_${assim_name}(statut) : return FACT( +def ${assim_name}InNS(filename): + if os.path.exists(filename): + fc = open(filename, 'r').readlines() + cr = re.compile("^${assim_name}[\s]*=") + for ln in fc: + if cr.match(ln): return 1 + return 0 +${assim_name}InNS.info = u"The Python file has to contain explicitly a \\"${assim_name}\\" variable." +def F_${assim_name}(statut, fv=NoCheckInNS) : return FACT( statut=statut, ${storage} INPUT_TYPE = SIMP(statut="o", typ = "TXM", into=(${choices}), defaut=${default_choice}),${decl_choices} @@ -138,7 +178,7 @@ ${storage} assim_data_choice = """ ${choice_name} = BLOC ( condition = " INPUT_TYPE in ( '${choice_name}', ) ", - data = F_${choice_name}("o"), + data = F_${choice_name}("o", fv), ),""" observers_choice = """ @@ -151,7 +191,7 @@ observers_choice = """ Value = SIMP(statut = "o", typ = "TXM") ), UserFile = BLOC (condition = " NodeType == 'Script' ", - Value = SIMP(statut = "o", typ = "FichierNoAbs", validators=(OnlyStr())) + Value = SIMP(statut = "o", typ = "FichierNoAbs", validators=[OnlyStr(), FileExtVal('py')]) ), ObserverTemplate = F_ObserverTemplate(), ), @@ -193,13 +233,21 @@ def F_Observers(statut) : return FACT( """ algo_choices = """ -def F_AlgorithmParameters(statut,algos_names) : return FACT( +def AlgorithmParametersInNS(filename): + if os.path.exists(filename): + fc = open(filename, 'r').readlines() + cr = re.compile("^AlgorithmParameters[\s]*=") + for ln in fc: + if cr.match(ln): return 1 + return 0 +AlgorithmParametersInNS.info = u"The Python file has to contain explicitly a \\"AlgorithmParameters\\" variable." +def F_AlgorithmParameters(statut, algos_names, fv=NoCheckInNS) : return FACT( statut = statut, Algorithm = SIMP(statut="o", typ = "TXM", into = algos_names ), Parameters = SIMP(statut="f", typ = "TXM", into=("Defaults", "Dict") ), Dict = BLOC ( condition = " Parameters == 'Dict' ", statut="f", - data = F_Dict("o"), + data = F_Dict("o", fv), ),${all_algo_defaults} ) """ @@ -209,7 +257,6 @@ one_algo_choices = """ ${algo_parameters} ),""" assim_study = """ - def F_variables(statut) : return FACT( statut=statut, regles = ( MEME_NOMBRE ('NAMES', 'SIZES')), @@ -223,14 +270,14 @@ ASSIMILATION_STUDY = PROC(nom="ASSIMILATION_STUDY", StudyName = SIMP(statut="o", typ = "TXM", defaut="ADAO Calculation Case"), StudyRepertory = SIMP(statut="f", typ = "Repertoire", min=1, max=1), Debug = SIMP(statut="f", typ = "I", into=(0, 1), defaut=0), - AlgorithmParameters = F_AlgorithmParameters("o",(${algos_names})), - Background = F_Background("o"), - BackgroundError = F_BackgroundError("o"), - Observation = F_Observation("o"), - ObservationError = F_ObservationError("o"), + AlgorithmParameters = F_AlgorithmParameters("o",(${algos_names}), AlgorithmParametersInNS), + Background = F_Background("o", BackgroundInNS), + BackgroundError = F_BackgroundError("o", BackgroundErrorInNS), + Observation = F_Observation("o", ObservationInNS), + ObservationError = F_ObservationError("o", ObservationErrorInNS), ObservationOperator = F_ObservationOperator("o"), EvolutionModel = F_EvolutionModel("f"), - EvolutionError = F_EvolutionError("f"), + EvolutionError = F_EvolutionError("f", EvolutionErrorInNS), ControlInput = F_ControlInput("f"), UserDataInit = F_Init("f"), UserPostAnalysis = F_UserPostAnalysis("o"), @@ -245,11 +292,11 @@ CHECKING_STUDY = PROC(nom="CHECKING_STUDY", StudyName = SIMP(statut="o", typ = "TXM", defaut="ADAO Checking Case"), StudyRepertory = SIMP(statut="f", typ = "Repertoire", min=1, max=1), Debug = SIMP(statut="f", typ = "I", into=(0, 1), defaut=0), - AlgorithmParameters = F_AlgorithmParameters("o",(${check_names})), - CheckingPoint = F_CheckingPoint("o"), - BackgroundError = F_BackgroundError("f"), - Observation = F_Observation("f"), - ObservationError = F_ObservationError("f"), + AlgorithmParameters = F_AlgorithmParameters("o", (${check_names}), AlgorithmParametersInNS), + CheckingPoint = F_CheckingPoint("o", CheckingPointInNS), + BackgroundError = F_BackgroundError("f", BackgroundErrorInNS), + Observation = F_Observation("f", ObservationInNS), + ObservationError = F_ObservationError("f", ObservationErrorInNS), ObservationOperator = F_ObservationOperator("o"), UserDataInit = F_Init("f"), Observers = F_Observers("f") diff --git a/src/daEficas/Makefile.am b/src/daEficas/Makefile.am index 7f70e93..6535581 100644 --- a/src/daEficas/Makefile.am +++ b/src/daEficas/Makefile.am @@ -32,6 +32,7 @@ mypkgpython_PYTHON = \ __init__.py \ prefs_ADAO.py \ prefs.py \ + traduitADAOsansToV7_6_0.py \ traduitADAOV7_4_0ToV7_6_0.py \ traduitADAOV7_5_0ToV7_6_0.py \ traduitADAOV7_5_1ToV7_6_0.py diff --git a/src/daEficas/traduitADAOsansToV7_6_0.py b/src/daEficas/traduitADAOsansToV7_6_0.py new file mode 100644 index 0000000..aab742e --- /dev/null +++ b/src/daEficas/traduitADAOsansToV7_6_0.py @@ -0,0 +1,122 @@ +#-*-coding:iso-8859-1-*- +# +# Copyright (C) 2008-2015 EDF R&D +# +# This file is part of SALOME ADAO module +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D + +import log +import optparse +import sys +import re + +from load import getJDC, getJDCFromTexte +from mocles import parseKeywords +from removemocle import * +from renamemocle import * +from renamemocle import * +from inseremocle import * +from changeValeur import * +from movemocle import * +from dictErreurs import * +from regles import pasDeRegle + +version_out = "V7_6_0" + +usage="""Usage: python %prog [options] + +Typical use is: + python %prog --infile=xxxx.comm --outfile=yyyy.comm""" + +atraiter = ( + "ASSIMILATION_STUDY", + "CHECKING_STUDY", + ) + +dict_erreurs = { + "ASSIMILATION_STUDY":"Changements dans l'arbre et dans les noms", + "CHECKING_STUDY":"Changements dans l'arbre et dans les noms", + } + +sys.dict_erreurs=dict_erreurs + +def traduc(infile=None,outfile=None,texte=None,flog=None): + hdlr = log.initialise(flog) + if infile is not None: + jdc = getJDC(infile,atraiter) + elif texte is not None: + jdc = getJDCFromTexte(texte,atraiter) + else: + raise ValueError("Traduction du JDC impossible") + + #Parse les mocles des commandes + parseKeywords(jdc.root) + GenereErreurPourCommande(jdc,('Algorithm','AlgorithmParameters','FunctionDict')) + # ========================================================================== + + for command in atraiter: + # Insere le MC s'il n'existe pas + chercheOperInsereFacteurSiRegle(jdc, command, "AlgorithmParameters",((("AlgorithmParameters",),"nexistepasMCFParmi"),)) + # Deplace le MC + moveMotClefInOperToFact(jdc, command, "Algorithm", "AlgorithmParameters") + # Renomme le MC + renameMotCleInFact(jdc, command, "AlgorithmParameters", "INPUT_TYPE", "Parameters") + # Renomme le MC + renameMotCle(jdc, command, "Study_name", "StudyName") + renameMotCle(jdc, command, "Study_repertory", "StudyRepertory") + + # ========================================================================== + fsrc = jdc.getSource() + fsrc = re.sub( "FunctionDict", "ScriptWithSwitch", fsrc ) + fsrc = re.sub( "FUNCTIONDICT_FILE", "SCRIPTWITHSWITCH_FILE", fsrc ) + fsrc = re.sub( "#VERSION_CATALOGUE:.*:FIN VERSION_CATALOGUE", "#VERSION_CATALOGUE:%s:FIN VERSION_CATALOGUE"%version_out, fsrc) + fsrc = re.sub( "#CHECKSUM.*FIN CHECKSUM", "", fsrc ) + # + log.ferme(hdlr) + if outfile is not None: + f=open(outfile,'w') + f.write( fsrc ) + f.close() + else: + return fsrc + +class MonTraducteur: + def __init__(self,texte): + self.__texte = str(texte) + def traduit(self): + return traduc(infile=None,outfile=None,texte=self.__texte,flog=None) + +def main(): + parser = optparse.OptionParser(usage=usage) + + parser.add_option('-i','--infile', dest="infile", + help="Le fichier COMM en entree, a traduire") + parser.add_option('-o','--outfile', dest="outfile", default='out.comm', + help="Le fichier COMM en sortie, traduit") + + options, args = parser.parse_args() + if len(options.infile) == 0: + print + parser.print_help() + print + sys.exit(1) + + traduc(options.infile,options.outfile) + +if __name__ == '__main__': + main()