-"""
-Creates MED file with scalar field associated with the mesh of the calculation case.
-The scalar value associated with the mesh node is the Strickler coefficient of the land cover containing the node.
-case_name: calculation case name in the study
-med_file_name: path to input MED file with mesh on nodes
-output_file_name: path to output MED file with
-med_field_name: field name
-"""
-def assignStrickler(case_name, med_file_name, output_file_name, med_field_name='FRICTION'):
- # Check calculation case
- doc = HYDROPy.HYDROData_Document.Document( theStudyId )
- case = doc.FindObjectByName(case_name)
- if case is None:
- raise BadParamsError("Calculation case '%s' not found" % case_name)
-
- # Check input MED file
- if not os.path.exists(med_file_name):
- raise BadParamsError("Input file '%s' not exists" % med_file_name)
-
- # Copy input file to the output path, if the output path is empty - use the input path for the output
- file_path = med_file_name
- if output_file_name and (output_file_name != file_path):
- shutil.copyfile(med_file_name, output_file_name)
- file_path = output_file_name
-
- # Open input MED file
- fid = medfile.MEDfileOpen(file_path, medenum.MED_ACC_RDEXT)
-
- # Get mesh info
- mesh_name, sdim, mdim, meshtype, desc, dtunit, sort, nstep, repere, axisname, axisunit = medmesh.MEDmeshInfo(fid, 1)
-
- nb_nodes, chgt, trsf = medmesh.MEDmeshnEntity(fid, mesh_name, medenum.MED_NO_DT, medenum.MED_NO_IT,
- medenum.MED_NODE, medenum.MED_NONE,
- medenum.MED_COORDINATE, medenum.MED_NO_CMODE)
-
-
- # Create field
- if nb_nodes > 0:
- # Get node coordinates
- coords = medfile.MEDFLOAT(nb_nodes*sdim)
- medmesh.MEDmeshNodeCoordinateRd(fid, mesh_name, medenum.MED_NO_DT, medenum.MED_NO_IT,
- medenum.MED_FULL_INTERLACE, coords)
-
- # Get list of Strickler coefficient values for the nodes
- values = []
- x_coords = coords[0::sdim]
- y_coords = coords[1::sdim]
+
+def assignStrickler(nomCas, input_file_name, output_file_name="", med_field_name='BOTTOM FRICTION', verbose=False):
+ """
+ assignStrickler creates the scalar field associated with the mesh of the calculation case that
+ represents the Strickler coefficient of the land cover.
+
+ In:
+ nomCas: Calculation Case Name in module HYDRO
+ input_file_name: med file name corresponding to the HYDRO case
+ output_file_name: med file name with the Strickler coefficient; default is the same as fichierMaillage
+ med_field_name: name of the field of the Strickler coefficient
+ default value is 'BOTTOM FRICTION'.
+ Out:
+ """
+ erreur = 0
+ message = ""
+
+ while not erreur:
+
+ if verbose:
+ print "nomCas:", nomCas
+ print "input_file_name:", input_file_name
+ print "output_file_name:", output_file_name
+ print "med_field_name:", med_field_name
+
+# 1. Controls
+# 1.1. Check calculation case
+ doc = HYDROPy.HYDROData_Document.Document(theStudyId)
+ case = doc.FindObjectByName(nomCas)
+ if case is None:
+ raise BadParamsError("Calculation case '%s' not found" % nomCas)
+
+# 1.2. Check input MED file
+ if not os.path.exists(input_file_name):
+ raise BadParamsError("Input file '%s' not exists" % input_file_name)
+
+# 2. The output file
+# 2.1. If output MED file is not defined, it is equal to the input file
+ if not output_file_name:
+ output_file_name = input_file_name
+
+# 2.2. Copy input file to the output path, if the output path is different from the input path
+ if output_file_name != input_file_name:
+ import shutil
+ shutil.copyfile(input_file_name, output_file_name)
+#
+# 3. Reads the mesh
+#
+ meshMEDFileRead = ml.MEDFileMesh.New(output_file_name)
+#
+# 4. Gets the information about the nodes
+#
+ nbnodes = meshMEDFileRead.getNumberOfNodes()
+ if verbose:
+ print "Number of nodes: %d" % nbnodes
+#
+ coords = meshMEDFileRead.getCoords()
+ #print "coords =\n", coords
+#
+# 5. Calculation of the Strickler coefficient
+ values = list()
+ x_coords = coords[:, 0]
+ y_coords = coords[:, 1]
+ #print "x_coords =\n", x_coords
+ #print "y_coords =\n", y_coords