gt:                         long[] l = ((long[])val);
context: /*
     Originally based on code from neuroConstruct: https://github.com/NeuralEnsemble/neuroConstruct
  
     @ Author: p.gleeson 
  */
  
  package org.neuroml.model.util.hdf5;
  
  
  import ncsa.hdf.object.*;
  import ncsa.hdf.object.h5.*;
  import java.io.*;
  import java.util.*;
  
  import java.util.ArrayList;
  
  import ncsa.hdf.hdf5lib.HDF5Constants;
  
  import ncsa.hdf.utils.SetNatives;
  
  public class Hdf5Utils
  {
  
      static boolean verbose = false;
      
      public Hdf5Utils()
      {
          super();
      }
      
      public static void setVerbose(boolean v)
      {
          verbose = v;
      }
      
      private static void printv(String msg)
      {
          String pre = "HDF5 U >> ";
          if (verbose) 
              System.out.println(pre+msg.replaceAll("\n", "\n"+pre));
      }
      
      /*
       * Helper function to throw error if no H5 classes found
       */
      private static void testH5classes() throws Hdf5Exception
      {
          try
          {
              ClassLoader cl  = ClassLoader.getSystemClassLoader();
              cl.loadClass("ncsa.hdf.object.FileFormat");
          }
          catch(Exception ex)
          {
              throw new Hdf5Exception("Problem finding HDF5 classes in classpath. Please ensure jars and libraries are installed correctly.\n", ex);
          }
      }
      
      public static Attribute getSimpleAttr(String name, String value, H5File h5File) throws Exception
      {
          Datatype dtype = h5File.createDatatype(Datatype.CLASS_STRING, value.length()+1, Datatype.NATIVE, Datatype.NATIVE);
  
          long[] attrDims = {1}; 
  
          Attribute attr = new Attribute(name, dtype, attrDims);
          String[] info = new String[]{value };
  
          attr.setValue(info); 
          
          return attr;
      }
      
      public static void addStringAttribute(Group group, String name, String value, H5File h5File) throws Exception
      {
          if (value==null)
              return;
          
          Datatype dtype = h5File.createDatatype(Datatype.CLASS_STRING, value.length()+1, Datatype.NATIVE, Datatype.NATIVE);
          
          String[] info = new String[]{value };
          Attribute attr = new Attribute(name, dtype, new long[]{1}, info);
          
          group.writeMetadata(attr);
      }
  
      public static H5File createH5file(File file) throws Hdf5Exception
      {
          testH5classes();
          
          FileFormat fileFormat = FileFormat.getFileFormat(FileFormat.FILE_TYPE_HDF5);
  
          if (fileFormat == null)
          {
              throw new Hdf5Exception("Cannot find HDF5 FileFormat.");
          }
  
          try
          {
              H5File h5File = (H5File) fileFormat.create(file.getAbsolutePath());
  
              if (h5File == null)
              {
                  throw new Hdf5Exception("Failed to create file:"+file);
              }
  
              return h5File;
          }
          catch (Exception ex)
          {
              throw new Hdf5Exception("Error creating file: " + file + ".", ex);
          }
      }
  
      public static H5File openH5file(File file) throws Hdf5Exception
      {
          testH5classes();
          
          FileFormat fileFormat = FileFormat.getFileFormat(FileFormat.FILE_TYPE_HDF5);
  
          if (fileFormat == null)
          {
              throw new Hdf5Exception("Cannot find HDF5 FileFormat.");
          }
  
          try
          {
              H5File h5File = (H5File)fileFormat.open(file.getAbsolutePath(), FileFormat.READ);
  
              if (h5File == null)
              {
                  throw new Hdf5Exception("Failed to open file:"+file);
              }
              
              
              open(h5File);
  
              return h5File;
          }
          catch (Exception ex)
          {
              throw new Hdf5Exception("Error creating file: " + file + ".", ex);
          }
      }
  
      public static void open(H5File h5File) throws Hdf5Exception
      {
          testH5classes();
          try
          {
              h5File.open();
          }
          catch (Exception ex)
          {
              throw new Hdf5Exception("Failed to open HDF5 file", ex);
          }
  
      }
  
      public static H5File openForRead(File f) throws Hdf5Exception
      {
          try
          {
              H5File h5file = new H5File(f.getAbsolutePath(), HDF5Constants.H5F_ACC_RDONLY);
              
              h5file.open();
              
              return h5file;
          }
          catch (Exception ex)
          {
              throw new Hdf5Exception("Failed to open HDF5 file", ex);
          }
  
      }
  
      public static void close(H5File h5File) throws Hdf5Exception
      {
          try
          {
              h5File.close();
          }
          catch (Exception ex)
          {
              throw new Hdf5Exception("Failed to close HDF5 file", ex);
          }
  
      }
      
      
      public static String getFirstStringValAttr(ArrayList<Attribute> attrs, String attrName)
      {
          for (Attribute attribute : attrs) 
          {
              if (attribute.getName().equals(attrName))
              {
                  printv("Attribute: "+attribute+"; val: "+attribute.getValue()+
                                 "; class: "+attribute.getValue().getClass()+"; dim: "+attribute.getDataDims().length+
                                 "; desc: "+attribute.getType().getDatatypeDescription()
                                 +"; dt class "+attribute.getType().getDatatypeClass()
                                 +"; dt order "+attribute.getType().getDatatypeOrder()
                                 +"; dt sign "+attribute.getType().getDatatypeSign()
                                 +"; dt size "+attribute.getType().getDatatypeSize()
                                 +"; dt nat "+attribute.getType().toNative());
              
                  if (attribute.getValue() instanceof Object[])
                  {
                      Object[] vals = (Object[])attribute.getValue();
                      printv(" Array of length: "+vals.length+"; first: ["+vals[0]+"], "+vals[0].getClass().getCanonicalName());
  
                      return vals[0].toString();
                  }
                  if (attribute.getValue() instanceof Object)
                  {
                      Object val = attribute.getValue();
  
                      printv(" Value: ["+val+"], "+val.getClass().getCanonicalName());
                      
                      if (val instanceof long[])
                      {
  