/[ascend]/trunk/ascend/compiler/test/yacasgen.py
ViewVC logotype

Diff of /trunk/ascend/compiler/test/yacasgen.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3320 by jpye, Tue Jan 9 23:07:20 2018 UTC revision 3321 by jpye, Thu Jan 11 04:04:39 2018 UTC
# Line 18  Line 18 
18  # This script generates a YACAS file that includes all the symbolic derivs  # This script generates a YACAS file that includes all the symbolic derivs
19  # and operating points which is later parsed by YACAS  # and operating points which is later parsed by YACAS
20    
21  try:  # NOTE that in YACAS, [stmt;...] is a *statement block*, while
22      print "Generating files for input to Yacas"  # {a,b,...} is a *list*.
23      varsf = open('Vars.txt','r')  
24      yacasprepf1st = open('yacas-prep-1st.txt','r')  print "\nGenerating files for input to Yacas\n"
25      yacasoutf1st = open('yacas-input-1st.txt','w')  varsf = open('varnames.txt','r')
26      yacasprepf2nd = open('yacas-prep-2nd.txt','r')  yacasprepf1st = open('yacas-prep-1st.txt','r')
27      yacasoutf2nd = open('yacas-input-2nd.txt','w')  yacasoutf1st = open('yacas-input-1st.txt','w')
28    yacasprepf2nd = open('yacas-prep-2nd.txt','r')
29    yacasoutf2nd = open('yacas-input-2nd.txt','w')
30    
31  #ToStdout() [Echo(N( Eval(D(%s) %s),17))]  #ToStdout() [Echo(N( Eval(D(%s) %s),17))]
32    
33  # ToStdout() [Echo(N( Eval(D(%s) D(%s) %s),17))];  # ToStdout() [Echo(N( Eval(D(%s) D(%s) %s),17))];
34    
35      i=0 # counter for number of variables in each relation  i=0 # counter for number of variables in each relation
36      for line in varsf:  varlist = []
37          if line.strip().startswith('@ Relation'):  for line in varsf:
38              print "i=%d: %s"%(i,line.strip())        if line.strip().startswith('@ Relation'):
39              j = (i)*(i) # i^2-- there will be this many second derivatives          where = " Where " + (" And ".join(varlist))
40              yacasoutf2nd.write('ToStdout() [Echo("' + line.strip() + '");];\n')          print "i=%d: %s"%(i,line.strip())  
41              while j>0:          j = (i)*(i) # i^2-- there will be this many second derivatives
42                  yacasoutf2nd.write("ToStdout() [Echo({N(Eval(%s),17)});];\n"%(yacasprepf2nd.readline().strip(),))          yacasoutf2nd.write('Echo("' + line.strip() + '");\n')
43                  j = j-1          while j>0:
44                s = "(%s) %s"%(yacasprepf2nd.readline().strip(),where)
45              yacasoutf1st.write('ToStdout() [Echo("' + line.strip() + '");];\n')              yacasoutf2nd.write("Echo(N(%s,17));\n"%(s,))
46              while i>0:              j = j-1
47                  yacasoutf1st.write("ToStdout() [Echo({N(Eval(%s),17)});];\n"%(yacasprepf1st.readline().strip(),))  
48                  i = i-1          yacasoutf1st.write('Echo("' + line.strip() + '");\n')
49              # back to i=0 again          while i>0:
50          else:              s = "(%s) %s"%(yacasprepf1st.readline().strip(),where)
51              # Vars.txt contains a variable value declaration              yacasoutf1st.write("Echo(N(%s,17));\n"%(s,))
52              i = i+1 # increase the number of variables              i = i-1
53              yacasoutf2nd.write(line.strip()+';\n')          # back to i=0 again
54              yacasoutf1st.write(line.strip()+';\n')          varlist = []
55      varsf.close()      else:
56      yacasprepf2nd.close()          # Vars.txt contains a variable value declaration
57      yacasoutf2nd.close()          i = i+1 # increase the number of variables
58      yacasprepf1st.close()          varlist.append(line.strip())
59      yacasoutf1st.close()          print "varlist =",varlist
60  except IOError, e:  #           yacasoutf2nd.write(line.strip()+';\n')
61      print "Error managing streams" ,e  #           yacasoutf1st.write(line.strip()+';\n')
62    varsf.close()
63    yacasprepf2nd.close()
64    yacasoutf2nd.close()
65    yacasprepf1st.close()
66    yacasoutf1st.close()
67    

Legend:
Removed from v.3320  
changed lines
  Added in v.3321

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22