Miguel Rocha avatar Miguel Rocha committed e97cfd4

Fixed a couple of bugs in gadget_hdf5_to_irate(): "msg" was being used before being defined and "snapnum" was not being converted to int at the beginning

Comments (0)

Files changed (1)

     omegaM = inhead.attrs['Omega0']
     omegaL = inhead.attrs['OmegaLambda']
     hubble = inhead.attrs['HubbleParam']
+    
+    try:
+        snapnum = int(snapnum)
+    except ValueError:
+        raise ValueError("The number used for the snapshot is not an integer.")
 
-    
     if os.path.isfile(outname):
         irate = h5py.File(outname,'a')
         print "Opening {0} to add data to it.".format(outname)
     nbulge = nfile[3]
     nstar = nfile[4]
     nbndry = nfile[5]
-        
+    
     try:
-        snap = irate.create_group("Snapshot"+str(snapnum))
-        print "Created new group for Snapshot "+str(snapnum)
+        snap = irate.create_group("Snapshot{0:05}".format(snapnum))
+        print "Created new group for Snapshot{0:05}".format(snapnum)
     except ValueError:
-        snap = irate['Snapshot'+str(snapnum)]
-        print "Adding data to existing group Snapshot"+str(snapnum)
-
+        snap = irate["Snapshot{0:05}".format(snapnum)]
+        print "Adding data to existing group Snapshot{0:05}".format(snapnum)
+    
     capbet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
     try:
         pdata = snap.create_group('ParticleData')
             pdata.attrs['Velocityunitcgs'] = vunits
             pdata.attrs['Massunitname'] = mname
             pdata.attrs['Massunitcgs'] = munits
-    
+
     exitflag = False
+    msg = "\n"
     if ngas > 0:
         if t0_name[0] not in capbet:  t0_name = t0_name.capitalize()
         try:
         except ValueError:
             msg = msg + "The group /Snapshot{0:05}/ParticleData/{1} already exists. Please specify a different location to save gas data.\n".format(snapnum,t0_name)
             exitflag = True
-        
+    
     if nhalo > 0:
         if t1_name[0] not in capbet:  t1_name = t1_name.capitalize()
         try:
         except ValueError:
             msg = msg + "The group /Snapshot{0:05}/ParticleData/{1} already exists. Please specify a different location to save halo data.\n".format(snapnum,t1_name)
             exitflag = True
-        
+    
     if ndisk > 0:
         if t2_name[0] not in capbet:  t2_name = t2_name.capitalize()
         try:
         except ValueError:
             msg = msg + "The group /Snapshot{0:05}/ParticleData/{1} already exists. Please specify a different location to save boundary data.\n".format(snapnum,t5_name)
             exitflag = True
-        
+    
     if exitflag:
         raise ValueError(msg)   
-            
+    
     if ngas > 0:
         path = fin['PartType0']
         for block in path.keys():
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.