Index: trunk/libIGCM/libIGCM_post/xios_parser.py
===================================================================
--- trunk/libIGCM/libIGCM_post/xios_parser.py	(revision 1467)
+++ trunk/libIGCM/libIGCM_post/xios_parser.py	(revision 1535)
@@ -176,7 +176,56 @@
         print '\n'
    
+def modifydr2xmlIPSL(args):
+    """Recursively find tree element with file tag and change the path prefix of the name attribute."""
+
+    # Loop over file_def files
+    for inputFile in args.file:
+        # Read the file_def_xml
+        if args.verbosity >= 1: print '\nReading dr2xml_def_xml=',inputFile
+        try:
+            tree = ET.parse(inputFile)
+        except:
+            print "Parse error. Please fix so that it can be parsed."
+            traceback.print_exc(file=sys.stdout)
+            return
+        root=tree.getroot()
+        if args.verbosity >= 3: print root.tag, root.attrib, '\n'
+
+        # Change file name prefix to point where we want
+        for elem in tree.iter(tag='file'):
+            if not elem.attrib.get('mode') == 'read':
+                name=elem.attrib.get('name')
+                if args.JobName is not None:
+                    name = name.replace('JobName', args.JobName[0]).replace('ModelName', args.ModelName[0])
+                    elem.set('name', os.path.normpath(args.newPath[0]) + '/' + os.path.normpath(name))
+                else:
+                    elem.set('name', os.path.normpath(args.newPath[0]) + '/' + os.path.normpath(name))
+                if args.verbosity >= 2: print elem.tag, elem.attrib
+                if args.splitLastDate is not None: elem.set('split_last_date', args.splitLastDate[0] + ' 00:00:00')
+                if args.ModelVersion is not None:
+                    for childElem in elem.iter(tag='variable'):
+                        if args.verbosity >= 2: print childElem.tag, childElem.attrib
+                        if childElem.attrib.get('name') is not None:
+                            if childElem.attrib.get('name') == 'model_version':
+                               childElem.text = args.ModelVersion[0]
+                if args.ModelName is not None:
+                    for childElem in elem.iter(tag='variable'):
+                        if args.verbosity >= 2: print childElem.tag, childElem.attrib
+                        if childElem.attrib.get('name') is not None:
+                            if childElem.attrib.get('name') == 'source_id':
+                               childElem.text = args.ModelName[0]
+
+
+        # Write out the results
+        if args.verbosity >= 1: print '\nWriting dr2xml_def_xml=','modified.' + inputFile
+        try:
+            tree.write ('modified.' + inputFile)
+        except:
+            print "Write error. Please fix so that it can be parsed."
+            traceback.print_exc(file=sys.stdout)
+            return
+
 def modifyPath(args):
     """Recursively find tree element with file tag and change the path prefix of the name attribute."""
-
     # Loop over file_def files
     for inputFile in args.file:
@@ -191,5 +240,4 @@
         root=tree.getroot()
         if args.verbosity >= 3: print root.tag, root.attrib, '\n'
-
         # Change file name prefix to point where we want
         for elem in tree.iter(tag='file'):
@@ -201,5 +249,5 @@
                     elem.set('name', os.path.normpath(args.newPath[0]) + '/' + os.path.normpath(name))
                 if args.verbosity >= 2: print elem.tag, elem.attrib
-                    
+                   
         # Write out the results
         if args.verbosity >= 1: print '\nWriting dr2xml_def_xml=','modified.' + inputFile
@@ -303,5 +351,5 @@
         parser_check.add_argument('--file', nargs='+', required=True, help='XIOS xml file_def type')
         parser_check.set_defaults(func=check, correction=False)
-        
+
         # create the parser for the "modify" command
         parser_check = subparsers.add_parser('modify', help='Will make sure field_def is a superset of file_def')
@@ -309,4 +357,14 @@
         parser_check.add_argument('--file', nargs='+', required=True, help='XIOS xml file_def type')
         parser_check.set_defaults(func=check, correction=True)
+        
+        # create the parser for the "modifydr2xmlIPSL" command
+        parser_check = subparsers.add_parser('modifydr2xmlIPSL', help='Adapt dr2xml_file to produce output files according to IPSL requirements')
+        parser_check.add_argument('--newPath', nargs=1, required=True, help='Directory output for file produced from dr2xml_file type')
+        parser_check.add_argument('--JobName', nargs=1, required=False, help='Name of the simulation to be added in the name of file produced from dr2xml_file type')
+        parser_check.add_argument('--ModelName', nargs=1, required=False, help='Name of the model to be added in the name of file produced from dr2xml_file type')
+        parser_check.add_argument('--ModelVersion', nargs=1, required=False, help='Model version to be added in global attributes of files produced from dr2xml_file type')
+        parser_check.add_argument('--file', nargs='+', required=True, help='XIOS xml dr2xml_file type')
+        parser_check.add_argument('--splitLastDate', nargs=1, required=False, help='Date to be used as split_last_date')
+        parser_check.set_defaults(func=modifydr2xmlIPSL)
 
         # create the parser for the "modifyPath" command
