Commits

Britton Smith committed be6e382

Fixed data reading routine for new format files where the grid
parameters are attributes instead of separate datasets.

Comments (0)

Files changed (1)

src/clib/initialize_cloudy_data.C

 
   fprintf(stderr,"Initializing Cloudy cooling.\n");
   fprintf(stderr,"cloudy_table_file: %s.\n",my_chemistry.cloudy_table_file);
-  fprintf(stderr,"include_metalheating: %"ISYM".\n",my_chemistry.include_metal_heating);
+  fprintf(stderr,"include_metal_heating: %"ISYM".\n",my_chemistry.include_metal_heating);
   fprintf(stderr,"cmb_temperature_floor: %"ISYM".\n",my_chemistry.cmb_temperature_floor);
 
   /* Get conversion units. */
   }
   delete [] temp_int_arr;
 
+  // Grid parameters.
+  for (q = 0;q < my_chemistry.CloudyCoolingGridRank;q++) {
+
+    if (q < my_chemistry.CloudyCoolingGridRank - 1) {
+      sprintf(parameter_name,"Parameter%"ISYM,(q+1));
+    }
+    else {
+      sprintf(parameter_name,"Temperature");
+    }
+
+    temp_data = new float64[my_chemistry.CloudyCoolingGridDimension[q]];
+
+    attr_id = H5Aopen_name(dset_id, parameter_name);
+    if (attr_id == h5_error) {
+      fprintf(stderr,"Failed to open %s attribute in Cooling dataset.\n", 
+              parameter_name);
+      return FAIL;
+    }
+    status = H5Aread(attr_id, HDF5_R8, temp_data);
+    if (attr_id == h5_error) {
+      fprintf(stderr,"Failed to read %s attribute in Cooling dataset.\n",
+              parameter_name);
+      return FAIL;
+    }
+
+    my_chemistry.CloudyCoolingGridParameters[q] = 
+      new gr_float[my_chemistry.CloudyCoolingGridDimension[q]];
+    for (w = 0;w < my_chemistry.CloudyCoolingGridDimension[q];w++) {
+      if (q < my_chemistry.CloudyCoolingGridRank - 1) {
+	my_chemistry.CloudyCoolingGridParameters[q][w] = (float) temp_data[w];
+      }
+      else {
+	// convert temeperature to log
+	my_chemistry.CloudyCoolingGridParameters[q][w] = (float) log10(temp_data[w]);
+      }
+
+    }
+    fprintf(stderr,"%s: %"GSYM" to %"GSYM" (%"ISYM" steps).\n",parameter_name,
+            my_chemistry.CloudyCoolingGridParameters[q][0],
+            my_chemistry.CloudyCoolingGridParameters[q][my_chemistry.CloudyCoolingGridDimension[q]-1],
+            my_chemistry.CloudyCoolingGridDimension[q]);
+    status = H5Aclose(attr_id);
+    if (attr_id == h5_error) {
+      fprintf(stderr,"Failed to close %s attribute in Cooling dataset.\n",
+              parameter_name);
+      return FAIL;
+    }
+    delete [] temp_data;
+
+  }
+
   // Read Cooling data.
   my_chemistry.CloudyDataSize = 1;
   for (q = 0;q < my_chemistry.CloudyCoolingGridRank;q++) {
     }
   }
 
-  // Read in grid parameters.
-  for (q = 0;q < my_chemistry.CloudyCoolingGridRank;q++) {
-
-    if (q < my_chemistry.CloudyCoolingGridRank - 1) {
-      sprintf(parameter_name,"/Parameter%"ISYM,(q+1));
-    }
-    else {
-      sprintf(parameter_name,"/Temperature");
-    }
-
-    temp_data = new float64[my_chemistry.CloudyCoolingGridDimension[q]];
-
-    dset_id =  H5Dopen(file_id, parameter_name);
-    if (dset_id == h5_error) {
-      fprintf(stderr,"Can't open %s in %s.\n",parameter_name,my_chemistry.cloudy_table_file);
-      return FAIL;
-    }
-
-    status = H5Dread(dset_id, HDF5_R8, H5S_ALL, H5S_ALL, H5P_DEFAULT, temp_data);
-    fprintf(stderr,"Reading Cloudy %s dataset.\n",parameter_name);
-    if (status == h5_error) {
-      fprintf(stderr,"Failed to read %s dataset.\n",parameter_name);
-      return FAIL;
-    }
-
-    my_chemistry.CloudyCoolingGridParameters[q] = new gr_float[my_chemistry.CloudyCoolingGridDimension[q]];
-    for (w = 0;w < my_chemistry.CloudyCoolingGridDimension[q];w++) {
-      if (q < my_chemistry.CloudyCoolingGridRank - 1) {
-	my_chemistry.CloudyCoolingGridParameters[q][w] = (float) temp_data[w];
-      }
-      else {
-	// convert temeperature to log
-	my_chemistry.CloudyCoolingGridParameters[q][w] = (float) log10(temp_data[w]);
-      }
-    }
-    delete [] temp_data;
-
-    status = H5Dclose(dset_id);
-    if (status == h5_error) {
-      fprintf(stderr,"Failed to close %s dataset.\n",parameter_name);
-      return FAIL;
-    }
-
-    fprintf(stderr,"%s: %"GSYM" to %"GSYM" (%"ISYM" steps).\n",parameter_name,
-		       my_chemistry.CloudyCoolingGridParameters[q][0],
-		       my_chemistry.CloudyCoolingGridParameters[q][my_chemistry.CloudyCoolingGridDimension[q]-1],
-		       my_chemistry.CloudyCoolingGridDimension[q]);
-
-  } // for (q = 0;q < my_chemistry.CloudyCoolingGridRank;q++)
-
   status = H5Fclose (file_id);
 
   if (my_chemistry.CloudyCoolingGridRank > CLOUDY_COOLING_MAX_DIMENSION) {