简体   繁体   中英

xml libxml2 parsing

In the code below, my problem is that it's writing output to all folders based on only one input file. Can some one give me a hint and check if my code is looping properly?

import libxml2
import os.path
from numpy import *
from cfs_utils import *

np=[1,2,3,4,5,6,7,8]
n=[20,30,40,60,80,100,130]
solver=["CG_iluk", "CG_saamg", "CG_ssor", "BiCGSTABL_iluk",   "BiCGSTABL_saamg", "BiCGSTABL_ssor", "cholmod", "ilu" ]
file_list=["eval_CG_iluk_default","eval_CG_saamg_default", "eval_CG_ssor_default", "eval_BiCGSTABL_iluk", "eval_BiCGSTABL_saamg", "eval_BiCGSTABL_ssor","simp_cholmod_solver_3D_evaluate ", "simp_ilu_solver_3D_evaluate" ]

for sol in solver:
    i=0
    for cnt_np in np:

        #open write_file= "Graphs/" +  "Np"+ cnt_np + "/CG_iluk.dat"
        #"Graphs/Np1/CG_iluk.dat"


        write_file = open("Graphs/"+ "Np"+ str(cnt_np) + "/" + sol + ".dat", "w")

        #loop through different unknowns
        for cnt_n in n:

            #open file "cfs_calculations_" + cnt_n +"np"+ cnt_np+ "/" +  file_list(i) + "_default.info.xml"

            read_file = "cfs_calculations_" +str(cnt_n) +"np"+ str(cnt_np) + "/" +  file_list[i] + ".info.xml"

            #read wall and cpu time and write

            if os.path.exists(read_file):
                doc = libxml2.parseFile(read_file)
                xml = doc.xpathNewContext()
                walltime = xpath(xml, "//cfsInfo/sequenceStep/OLAS/mechanic/solver/summary/setup/timer/@wall")
                cputime = xpath(xml, "//cfsInfo/sequenceStep/OLAS/mechanic/solver/summary/setup/timer/@cpu")
                unknowns = 3*cnt_n*cnt_n*cnt_n
                write_file.write(str(unknowns) + "\t" +  walltime + "\t" +  cputime + "\n")
                doc.freeDoc()
        write_file.close()
    i=i+1

问题解决了,I = o,不在循环之内

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM