| 1 | #Basic python script to verify that changed workspace comments took effect |
|---|
| 2 | |
|---|
| 3 | import sys,os |
|---|
| 4 | #Import Mantid computatinal modules |
|---|
| 5 | sys.path.append(os.environ['MANTIDPATH']) |
|---|
| 6 | from mantid.simpleapi import * |
|---|
| 7 | |
|---|
| 8 | #Change path and file to point appropriately to the MD workspace you want to load |
|---|
| 9 | path='C:\Users\mid\Documents\Mantid\Powder\CalcProj\\' #will read input and save output to this directory |
|---|
| 10 | file='zrh_1000_PCalcProj.nxs' |
|---|
| 11 | print "*** Loading in Workspace: ",path+file |
|---|
| 12 | ws=LoadMD(path+file) |
|---|
| 13 | comment_orig=ws.getComment() |
|---|
| 14 | print " Original comment: ",comment_orig |
|---|
| 15 | #change comment |
|---|
| 16 | comment_new=comment_orig+' this is a new comment' |
|---|
| 17 | print " Comment to be added to workspace: ",comment_new |
|---|
| 18 | ws.setComment(comment_new) |
|---|
| 19 | #print new comment |
|---|
| 20 | comment_current=ws.getComment() |
|---|
| 21 | print " Comment set in workspace: ",comment_current |
|---|
| 22 | |
|---|
| 23 | if comment_current == comment_orig: |
|---|
| 24 | print "Setting workspace comment did not take" |
|---|
| 25 | elif 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 |
|---|
| 42 | else: |
|---|
| 43 | print "Problem: comment mismatch between original and that set" |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | |
|---|