Ticket #10544: chk_WriteComments.py

File chk_WriteComments.py, 1.9 KB (added by Steve Miller, 6 years ago)
Line 
1#Basic python script to verify that changed workspace comments took effect
2
3import sys,os
4#Import Mantid computatinal modules
5sys.path.append(os.environ['MANTIDPATH'])
6from mantid.simpleapi import *     
7
8#Change path and file to point appropriately to the MD workspace you want to load
9path='C:\Users\mid\Documents\Mantid\Powder\CalcProj\\'  #will read input and save output to this directory
10file='zrh_1000_PCalcProj.nxs'
11print "*** Loading in Workspace: ",path+file
12ws=LoadMD(path+file)
13comment_orig=ws.getComment()
14print "  Original comment: ",comment_orig
15#change comment
16comment_new=comment_orig+' this is a new comment'
17print "  Comment to be added to workspace: ",comment_new
18ws.setComment(comment_new)
19#print new comment
20comment_current=ws.getComment()
21print "  Comment set in workspace: ",comment_current
22
23if comment_current == comment_orig:
24    print "Setting workspace comment did not take"
25elif comment_current == comment_new:
26    print "The new comment was set properly in the workspace"
27    #in this case, save the workspace, then re-load it to see if the new comment is still there
28    file='zrh_1000_PCalcProj_newComment.nxs'
29    print "*** Saving workspace: ",path+file
30    SaveMD(ws,path+file)
31    print "*** Loading workspace: ",path+file
32    wsReload=Load(path+file)
33    comment_reload=wsReload.getComment()
34    if comment_reload == comment_new:
35        print "--> The new comment was saved and recalled properly!"
36        print "  Comment to be saved: ",comment_new
37        print "  Comment from reloaded workspace: "
38    else:
39        print "--> Comment mismatch between the workspace to be saved and the reloaded workspace...unlucky..."
40        print "  Comment to be saved: ",comment_new
41        print "  Comment from reloaded workspace: ",comment_reload
42else:
43    print "Problem: comment mismatch between original and that set"
44   
45
46