import re
import argparse
from argparse import RawTextHelpFormatter

if __name__ == "__main__":
    parser = argparse.ArgumentParser(formatter_class=RawTextHelpFormatter)
    parser.add_argument('--model_file', type=str, default="dnn_model", help="<name of your model file with layer specs>")
    parser.add_argument('--dataflow', type=str, default="os", help='dataflow choices: dla, os, ws, rs')
    parser.add_argument('--outfile', type=str, default="out.m", help='output file name')
    opt = parser.parse_args()
    print('Begin processing')
    dsconv = 0
    with open(opt.dataflow + ".m" ,"r") as fd:
        with open("util/dpt.m" , "r") as fdpt:
            with open("out/" + opt.outfile, "w") as fo:
                with open("out/" + opt.model_file + ".m", "r") as fm:
                    for line in fm:
                        if(re.search("DSCONV",line)):
                            dsconv = 1
                        write_pos = re.match("Dimensions" ,line)
                        if(write_pos):
                            fo.write(line)
                            if(dsconv):
                                fdpt.seek(0)
                                fo.write(fdpt.read())
                            else:
                                fd.seek(0)
                                fo.write(fd.read())
                            dsconv=0
                        else:
                            fo.write(line)

print("DFSL file created")

                        
                    

@@ -19,16 +19,31 @@
 rgparse%0A
+import os.path%0A
 from arg
@@ -569,16 +569,74 @@
 onv = 0%0A
+    if os.path.exists(%22out/%22 + opt.model_file +%22.m%22):%0A    
     with
@@ -674,32 +674,36 @@
  as fd:%0A        
+ 
+   
 with open(%22util/
@@ -729,32 +729,36 @@
 pt:%0A            
+   
+ 
 with open(%22out/%22
@@ -785,16 +785,20 @@
  as fo:%0A
+    
         
@@ -879,16 +879,20 @@
         
+    
 for line
@@ -895,24 +895,28 @@
 line in fm:%0A
+    
             
@@ -981,24 +981,28 @@
             
+    
 dsconv = 1%0A 
@@ -1000,16 +1000,20 @@
 onv = 1%0A
+    
         
@@ -1093,16 +1093,20 @@
         
+    
 if(write
@@ -1132,32 +1132,36 @@
                 
+ 
+   
 fo.write(line)%0A 
@@ -1155,24 +1155,28 @@
 write(line)%0A
+    
             
@@ -1235,16 +1235,20 @@
         
+    
 fdpt.see
@@ -1276,32 +1276,36 @@
                 
+ 
+   
 fo.write(fdpt.re
@@ -1302,32 +1302,36 @@
 te(fdpt.read())%0A
+    
                 
@@ -1380,16 +1380,20 @@
         
+    
 fd.seek(
@@ -1419,32 +1419,36 @@
                 
+  
+  
 fo.write(fd.read
@@ -1443,32 +1443,36 @@
 rite(fd.read())%0A
+    
                 
@@ -1508,32 +1508,36 @@
                 
+    
 else:%0A          
@@ -1546,32 +1546,36 @@
                 
+   
+ 
 fo.write(line)%0A%0A
@@ -1574,16 +1574,24 @@
 (line)%0A%0A
+        
 print(%22D
@@ -1608,16 +1608,84 @@
 reated%22)
+%0A    else:%0A        print(%22Model file not found, please provide one%22)
 %0A%0A      

update to modelfile_to DFSL script