Knowledge Base

How do I convert an HDF/HDF-EOS file into binary format?

To convert HDF or HDF-EOS files into binary format you can use the hdp utility, which is part of the HDF4 distribution available from the HDF Group. How you install HDF4 depends on your operating system. Full instructions for installing and using hdp on Mac/Unix and Windows are provided below.

Installing HDF4 and using hdp on Mac/UNIX

  1. Download the ‘hdf-4.2.15-osx1013_64-clang.tar.gz’ from:
    https://portal.hdfgroup.org/display/support/HDF+4.2.15#HDF4.2.15-mac13

  2. Move the downloaded file to where you would like to run the program from. Untar the file and this will produce a folder called ‘hdf’.

  3. Open a terminal and navigate to the ‘hdf’ folder and run the ‘HDF-4.2.15-Darwin.sh’ and follow the prompts.

  4. Once installed, the hdp utility can be found in the ‘HDF-4.2.15-Darwin/HDF_Group/HDF/4.2.15/bin/’ folder. Navigate to this folder and type the ‘pwd’ command to get the full directory of this folder. You can either you use this to run the command from wherever your HDF5 file is or you can add it to your $PATH in your .zshrc or .bash_profile file in your home directory.

  5. In a terminal navigate to the folder where the HDF/HDF-EOS file is that you want to convert. To dump the header information in the HDF/HDF-EOS file into a text file you can use the following command:

    hdp dumpsds –h –o <output_file> <input_HDF_file>


    For example, to output the header information from 'MOD10C1A2018131.006.2018133040434.hdf' into a text file called ‘output.txt’:

    hdp dumpsds –h –o output.txt MOD10C1A2018131.006.2018133040434.hdf

  6. The output text file will include the variable names in the file, so you can identify which variables you want to output in binary format. To dump a variable from a HDF/HDF-EOS file into a binary file you can use the following command:

    hdp dumpsds -n <variable> -o <output_binary_file> -b <input_HDF_file>

    For example, to dump the variable 'Day_CMG_Snow_Cover' in 'MOD10C1A2018131.006.2018133040434.hdf' into an output file called ‘MOD_Snow_Cover.out’:
     
    hdp dumpsds -n Day_CMG_Snow_Cover -o MOD_Snow_Cover.out -b MOD10C1A2018131.006.2018133040434.hdf

Installing HDF4 and using hdp on Windows

  1. Download the ‘hdf-4.2.15-win10_64-vs15-Intel.zip’, or the relevant version for your system, from:
    https://portal.hdfgroup.org/display/support/HDF+4.2.15

  2. Unzip the downloaded file. Then in the ‘hdf’ folder double click on the HDF5-1.12.0-win64 installer. This will start a wizard installer and follow the instructions for installation.

  3. Once the installation has finished, check that HDF4 has been added to your path by opening a command prompt and typing 'PATH'. The 'C:\Program Files\HDF_Group\HDF\4.2.15\bin\' should be included in the list that appears.

  4. In the command prompt navigate to the folder where the HDF file you want to convert is.

  5. To dump the header information in the HDF/HDF-EOS file into a text file use the following command:

    hdp dumpsds –h –o <output_file> <input_HDF_file>


    For example, to output the header information from 'MOD10C1A2018131.006.2018133040434.hdf' into a text file called ‘output.txt’:

    hdp dumpsds –h –o output.txt MOD10C1A2018131.006.2018133040434.hdf 

  6. The output text file will include the variables in the file, so you can identify which variables you want to output in binary format. To dump a variable from a HDF/HDF-EOS file into a binary file use the following command:

    hdp dumpsds -n <variable> -o <output_binary_file> -b <input_HDF_file> 

    For example, to dump the variable 'Day_CMG_Snow_Cover' in 'MOD10C1A2018131.006.2018133040434.hdf' into an output file called ‘MOD_Snow_Cover.out’:
     
    hdp dumpsds -n Day_CMG_Snow_Cover -o MOD_Snow_Cover.out -b MOD10C1A2018131.006.2018133040434.hdf