Index: /issm/trunk-jpl/test/NightlyRun/runme.py
===================================================================
--- /issm/trunk-jpl/test/NightlyRun/runme.py	(revision 12638)
+++ /issm/trunk-jpl/test/NightlyRun/runme.py	(revision 12639)
@@ -34,5 +34,7 @@
 import socket
 import numpy
+import h5py
 import sys
+from parallelrange import parallelrange
 from IdToName import IdToName
 
@@ -73,16 +75,11 @@
 
 	#GET ids  {{{1
-#	flist=os.listdir('.')     #use dir, as it seems to act OS independent
-	flist=glob.glob('test*.m')    #File name must start with 'test' and must end by '.m'
-	list_ids=[] 
-	for file in flist:
-#		if file[:4] == 'test' and \    #File name must start with 'test'
-#		   file[-2:] == '.m' and \    #File name must end by '.m'
-#		   not file == 'test.m':    #File name must be different than 'test.m'
-		if not file == 'test.m':    #File name must be different than 'test.m'
-			list_ids.append(int(file[4:-2]))    #Keep test id only (skip 'test' and '.m')
-#	[i1,i2]=parallelrange(rank,numprocs,length(list_ids));               #Get tests for this cpu only
-#	list_ids=list_ids(i1:i2);
+	flist=glob.glob('test*.py')    #File name must start with 'test' and must end by '.py' and must be different than 'test.py'
+	list_ids=[int(file[4:-3]) for file in flist if not file == 'test.py']    #Keep test id only (skip 'test' and '.py')
 	print 'list_ids =',list_ids
+
+	i1,i2=parallelrange(rank,numprocs,len(list_ids))    #Get tests for this cpu only
+	list_ids=list_ids[i1:i2+1]
+	print 'list_ids after parallelrange =',list_ids
 
 	if id:
@@ -94,5 +91,5 @@
 	else:
 		test_ids=set(list_ids)
-	print 'test_ids after list =',test_ids
+#	print 'test_ids after list =',test_ids
 	# }}}
 
@@ -104,5 +101,5 @@
 			exclude_ids=[exclude]
 		test_ids=test_ids.difference(set(exclude_ids))
-	print 'test_ids after exclude =',test_ids
+#	print 'test_ids after exclude =',test_ids
 	# }}}
 
@@ -122,5 +119,5 @@
 	elif benchmark.lower() == 'tranforcing':
 		test_ids=test_ids.intersection(set(range(1501,1503)))
-	print 'test_ids after benchmark =',test_ids
+#	print 'test_ids after benchmark =',test_ids
 	test_ids=list(test_ids)
 	test_ids.sort()
@@ -136,5 +133,5 @@
 			os.chdir(root)
 			id_string=IdToName(id)
-			execfile('test'+str(id)+'.py')
+			execfile('test'+str(id)+'.py',globals())
 
 			#UPDATE ARCHIVE?
@@ -143,16 +140,21 @@
 
 				if not socket.gethostname().lower().split('.')[0] == 'larsen':
-					raise RuntimeError('Nightly run archives must be saved on "larsen" (hostname is "'+socket.gethostname()+'")')
+#					raise RuntimeError("Nightly run archives must be saved on 'larsen' (hostname is '"+socket.gethostname()+"').")
+					print "Nightly run archives must be saved on 'larsen' (hostname is '"+socket.gethostname()+"')."
+				f = h5py.File(os.path.join('..','Archives',archive_name+'.hdf5'),'w')
 				for k,fieldname in enumerate(field_names):
-					field=field_values[k]
-					exec(archive_name+'_field'+str(k)+' =  field')
-#				eval(['save ../Archives/' archive_name ' ' archive_name '_field*']);
-				print 'File ./../Archives/'+archive_name+' saved\n'
+					field=numpy.array(field_values[k],dtype=float)
+					f.create_dataset(archive_name+'_field'+str(k),data=field)
+				f.close()
+				print "File '%s' saved.\n" % os.path.join('..','Archives',archive_name+'.hdf5')
 
 			#ELSE: CHECK TEST
 			else:
 
-#				#load archive
-#				load(['../Archives/' archive_name ]);
+				#load archive
+				if os.path.exists(os.path.join('..','Archives',archive_name+'.hdf5')):
+					f = h5py.File(os.path.join('..','Archives',archive_name+'.hdf5'),'r')
+				else:
+					raise IOError("Archive file '"+os.path.join('..','Archives',archive_name+'.hdf5')+"' does not exist.")
 
 				for k,fieldname in enumerate(field_names):
@@ -161,9 +163,17 @@
 						#Get field and tolerance
 						field=numpy.array(field_values[k],dtype=float)
+#						print 'field =',field
 						tolerance=field_tolerances[k]
+#						print 'tolerance =',tolerance
 
 						#compare to archive
-						exec('archive=numpy.array('+archive_name+'_field'+str(k)+',dtype=float)')
-						error_diff=max(abs(archive-field))/(max(abs(archive))+sys.float_info.epsilon)
+						if archive_name+'_field'+str(k) in f:
+							archive=f[archive_name+'_field'+str(k)][...]
+						else:
+							raise NameError("Field name '"+archive_name+'_field'+str(k)+"' does not exist in archive file.")
+#						print 'archive =',archive
+						error_diff=numpy.amax(numpy.abs(archive-field),axis=1)/ \
+								   (numpy.amax(numpy.abs(archive),axis=1)+sys.float_info.epsilon)
+#						print 'error_diff =',error_diff
 
 						#disp test result
@@ -181,5 +191,5 @@
 						message=me2
 						if   output.lower() == 'nightly':
-							fid=open(ISSM_DIR+'/nightlylog/matlaberror.log', 'a')
+							fid=open(os.path.join(ISSM_DIR,'nightlylog','matlaberror.log'), 'a')
 							fid.write('%s' % message)
 							fid.write('\n------------------------------------------------------------------\n')
@@ -187,5 +197,5 @@
 							print 'FAILURE difference: N/A test id: %i test name: %s field: %s' % (id,id_string,fieldname)
 						elif output.lower() == 'daily':
-							fid=open(ISSM_DIR+'/dailylog/matlaberror.log', 'a')
+							fid=open(os.path.join(ISSM_DIR,'dailylog','matlaberror.log'), 'a')
 							fid.write('%s' % message)
 							fid.write('\n------------------------------------------------------------------\n')
@@ -196,4 +206,6 @@
 							raise RuntimeError(me2)
 
+				f.close()
+
 		except Exception as me:
 
@@ -202,5 +214,5 @@
 			message=me
 			if   output.lower() == 'nightly':
-				fid=open(ISSM_DIR+'/nightlylog/matlaberror.log', 'a')
+				fid=open(os.path.join(ISSM_DIR+'nightlylog','matlaberror.log'), 'a')
 				fid.write('%s' % message)
 				fid.write('\n------------------------------------------------------------------\n')
@@ -208,5 +220,5 @@
 				print 'FAILURE difference: N/A test id: %i test name: %s field: %s' % (id,id_string,'N/A')
 			elif output.lower() == 'daily':
-				fid=open(ISSM_DIR+'/dailylog/matlaberror.log', 'a')
+				fid=open(os.path.join(ISSM_DIR+'dailylog','matlaberror.log'), 'a')
 				fid.write('%s' % message)
 				fid.write('\n------------------------------------------------------------------\n')
