Skip to main content

Example

The example provided in this recipe uses NASA Ocean Biogeochemical Data (NOBM) Monthly Assimilated Total Chlorophyll data for the month of May 2003, with these coordinates:  -66.0937, 49.336, -46.4062, 64.1016, which covers much of the Labrador Sea north of Newfoundland, Canada. 

The data are acquired from the Giovanni data analysis system, and is in the output format NetCDF. An image of the partial output results is shown in Figure 1.

Estimated Completion Time

1.5 hours for initial setup, 15-20 minutes for individual data files once set-up has been completed.

Image
Image Caption

Figure 1: Sample image of the partial output result in ASCII format

NOTE: NetCDF4Excel is not authored by or supported by NASA. Use of this software is at the discretion of the user and the user undertakes any risks inherent with downloading or operating the software on their own computer system(s).

It is probably a good idea to read these instructions all the way through before getting started.

Prerequisites

Tested with Software: Excel 2007 running on Microsoft Windows operating system.

This recipe requires the use of a downloadable Microsoft Excel spreadsheet, NetCDF4Excel.  This spreadsheet imports a NetCDF data file and transforms it to ASCII text with three arrays on separate sheets:  latitude, longitude, and data values.  A macro written at the GES DISC can then be run to transform the arrays to a single list of lat, lon, and data value triplets.  Microsoft Excel must be available on the computing platform.

Best When: This recipe is best applied when users require data value output for single maps.  The method cannot be easily adapted to the processing of a large number of data files.

 

Procedure

1. Plot map in Giovanni and download data in NetCDF format

Create a map with NASA Ocean Biogeochemical Data (NOBM) Monthly Assimilated Total Chlorophyll data for the month of May 2003 in the Labrador Sea with these coordinates:  -66.0937, 49.336, -46.4062, 64.1016.  Search with keyword “NOBM_MON” and then choose the Assimilated Chlorophyll Monthly data product. Select May 2003 for the Beginning and End Dates (Figure 2). 

Or Click on the following URL, and all these criteria will be entered. Then click “Plot Data”.

https://giovanni.gsfc.nasa.gov/giovanni/#service=TmAvMp&starttime=2003-05-01T00:00:00Z&endtime=2003-05-31T23:59:59Z&bbox=-66.0937,49.336,-46.4062,64.1016&data=NOBM_MON_R2014_tot

 

Image
Image Caption

Figure 2: A sample of Giovanni interface and location of the study area

Once the map is generated, you can save it as a PNG (Note: The image is plotted on a log scale and the minimum value is set to 0.0799). Here is what the map looks like both unsmoothed and smoothed, using the default color palette (red indicates high chlorophyll concentrations – this is the Davis Strait and northern Labrador Sea in May, with Greenland at upper right) (Figure 3):

Image
Image Caption

Figure 3: Giovanni generated map in unsmoothed (left) and smoothed (right) option.

On the right side of the map, click on “Downloads”. The NetCDF file (.nc suffix) is available for download on that page, as shown below (Figure 4). Click on the file and download it to your system. Note the location. The file can be renamed, but don’t delete the .nc suffix.

Image
Image Caption

Figure 4: Sample Giovanni “Download” page.

2. Download NetCDF4Excel and installation

Below are different locations where it can be acquired:

netcdf4excel Google Code Archive

NetCDF4Excel Github Repository

netcdf4excel at Sourceforge

The instructions for NetCDF4Excel installation are duplicated below:

The NetCDF add-in

This add-in is written in VBA 6.0 (so it won't work with Office 2010 64 bits) and is designed for Excel 2007 running with the Microsoft Windows operating system.

It allows to open NetCDF data (classical format, versions 3.x) with Excel for read / write access. Nevertheless, please remind that you will always be limited by Excel's own memory limitations, i.e. trying to open huge data files may result in crashing Excel.

Supported Structures and Types

Supported data structures: 

  • Values 
  • Vectors with dimension length up to 1,048,576 
  • Numerical Matrices with up to N dimensions : at least dimension N (or N-1) should be less than 16,384 AND the product of the other dimensions should be less than 1,048,576 divided by dimension N (or N-1) 
  • Character Matrices with up to 4 dimensions (the last one has to be the - constant - number of characters of the strings)

Supported data types: 

  • NC_BYTE (the equivalent of the C type « signed char ») 
  • NC_SHORT 
  • NC_INT 
  • NC_FLOAT 
  • NC_DOUBLE 
  • NC_CHAR (be careful : NetCDF character strings are stored in fixed length vectors)

Supported platforms: 

  • Windows XP 32 bits 
  • Windows Vista 32 bits 
  • Windows Seven 32 and 64 bits 
  • Windows 8 32 and 64 bits

Installing the software

Just download the add-in, execute the installer, accept the license agreement and that's all. You should then have a short-cut on your desktop allowing you to launch an empty Excel workbook including the add-in.

Image
Image Caption

Figure 5: Here is what the NetCDF4Excel icon looks like installed on the Desktop. (This has only been tested on a Windows OS machine.)

Reading an entire NetCDF file

In the NetCDF menu, select « Open File » , then browse to the desired nc file. DON'T TRY TO USE THE NATIVE EXCEL "OPEN FILE" MENU, IT JUST WON'T WORK!

 

Reading a specific variable or a slice of variable in a NetCDF file

In the NetCDF menu, select « Read Variable » , browse to the desired nc file and select the variable you want to read. It is possible to select a slice of data to be read.

 

Writing a NetCDF file

Important notice : if you make changes to the data in Excel, you should be careful to strictly respect the structure of the Excel workbook, as described in the "NC_Info" tab.

In the NetCDF menu, select « Save File » , then browse to the desired location.

 

Known limitations and problems

Rounding errors may occur with data stored as floating point values.

Character strings : in Excel, strings are written in the cells of the spreadsheet with double quotes and are of a fixed length (strings are completed with blanks if necessary).

 

3. Import NetCDF data into Excel

Open the NetCDF4Excel spreadsheet (Figure 6). If you see a Security Warning, click the “Enable Content” button. Click on “Add-Ins”, which will display the NetCDF4Excel add-in frame at left.

Image
Image Caption

Figure 6: Sample of NetCDF4Excel_2007 spreadsheet

Click on “NetCDF”, then “Open File”, and navigate to the data file downloaded from Giovanni-4 in step 1. Click on the file to open it. This will open a new workbook, Book 1. There are four sheets in the workbook, entitled “NC_Info”, “lat”, “lon”, and the name of the data product. (The data product name in this case is “NOBM_MON_R2014_tot”).

   NC_Info contains the metadata for the data file.

   lat contains the latitude values for the data file. For this example, it is a column of 22 values.

   lon contains the longitude values for the data file. For this example, it is a column of 15 values.

NOBM_MON_R2014_tot is the data values. For this example, this sheet has a data value array that is 15 x 22. The array is shown below.  “-9999” represents no data (Figure 7):

Image
Image Caption

Figure 7: Sample of imported data.

4. Transform the data into the desired ASCII text output

4.1 This step is to create the macro that will transform the data into the desired ASCII text output format.

The text of the macro “ReOrganizeSub” is given below. The important text (that will need to be edited) is in bold font. The instructions for installation follow.  (You may wish to copy this into a text file before copying it into the Excel workbook.)

ReOrganizeSub
Sub ReorganizeSub()
     
    Dim MatrixAry(1 To 50, 1 To 100, 1 To 3) As String
    Dim i As Integer
    Dim j As Integer
    Dim RowIvb As Integer
    Const LatNdx As Integer = 1
    Const LongNdx As Integer = 2
    Const ValueNdx As Integer = 3
    For j = 1 To final
      For i = 1 To final
         MatrixAry(i, j, LatNdx) = Worksheets("lat").Range("A" & i + 1).Value
         MatrixAry(i, j, LongNdx) = Worksheets("lon").Range("A" & j + 1).Value
         MatrixAry(i, j, ValueNdx) = Worksheets("data set name").Range(NumToLtr(j + 1) & i + 2).Value
      Next i
    Next j
    For j = 1 To final
    For i = 1 To final
      RowIvb = RowIvb + 1
      Worksheets("Results").Range("A" & RowIvb).Value = MatrixAry(i, j, LatNdx)
      Worksheets("Results").Range("B" & RowIvb).Value = MatrixAry(i, j, LongNdx)
      Worksheets("Results").Range("C" & RowIvb).Value = MatrixAry(i, j, ValueNdx)
    Next i
  Next j
End Sub
Function NumToLtr(ColNumIvb) As String
    Dim ColLtrCde1Ivb As Long 'Column Letter Code of 1st character:ascii code
    Dim ColLtrCde2Ivb As Long 'Column Letter Code of 2nd character: ascii code
    If ColNumIvb <= 26 Then 'if a single letter
       'Returns the letter for the ASCII character code, where "A" is 65 (1+64)
       NumToLtr = Chr(ColNumIvb + 64)
    Else 'if 2 characters (max 2 characters "IV" last column on Excel page
       '1st character is the number of 26's without the remainder
       ColLtrCde1Ivb = (ColNumIvb - ((ColNumIvb - 1) Mod 26)) / 26
       '2nd is the remainder
       ColLtrCde2Ivb = ColNumIvb - (ColLtrCde1Ivb * 26)
       NumToLtr = Chr(ColLtrCde1Ivb + 64) & Chr(ColLtrCde2Ivb + 64)
    End If
End Function

Macro Installation Instructions

Go to File Options

Activate the Developer tab and close Options

Go to Developer tab

Go to the Visual Basic icon (at left)

Image
Image Caption

Figure 8: Here is what the Visual Basic icon looks like.

Go to "Insert", drop down to "Module", click on "Module".

At this point, there will be an empty space. Copy the text of ReorganizeSub into this space.

Image
Image Caption

Figure 9: Sample interface of Visual Basic model.

The macro will retain the name ReorganizeSub, but once it has been imported, the module can be named to save the workbook for future use with the module installed. We named the module “LatLonConverter”. Now save this workbook! (Rename it from the originally downloaded NetCDF4Excel workbook.)

4.2 To adapt the macro to the data array, the final values will be entered for the array size, and the data set name will be entered from the data value sheet. 

In this case, the number of latitude values, i, is 22, so in both occurrences of “For i = 1 To final”, change final to 22.   The number of longitude values is 15, so in both occurrences of “For j = 1 to final”, change final to 15. (These values are for the example;  for other array sizes, they will be changed as appropriate for the number of lat and lon values in the array).

Then change data set name to “NOBM_MON_R2014_tot”.

Image
Image Caption

Figure 10: sample section of macro that needs to be modified.

4.3 Now go back to the workbook with the spreadsheets by clicking on the small Excel icon (green X) at top left, under File. 

Next to the tabs on the bottom for the four sheets, there is a “+” sign in a circle.  Click on that, and a new sheet tab will be available, “Sheet5”.  Right click on the tab, click Rename, and Rename the sheet “Results”. 

Image
Image Caption

Figure 11: Sample workbook for running macro.

4.4 Now you’re ready to run the macro. 

Click on the Macro icon, and you will see a list of macros (Figure 12). Most of them are for the NetCDF import function of the NetCDF4Excel spreadsheet.

  • Locate “ReorganizeSub”, click on it, and it will appear in the top bar. Then click Run.
Image
Image Caption

Figure 12: Sample Macro window.

The reorganized array will be written to the Results spreadsheet. The top of the reorganized array looks like what is shown in figure 13: remember that this array has 15 x 22 (=330) data values.

Image
Image Caption

Figure 13: Sample Results spreadsheet.

4.5 Now save “Book1” to save your results (you will likely wish to rename it).

Note that you can choose to save it as an Excel workbook (.xlsx), or a macro-enabled workbook (.xlsm).   One of the quirks of this process is that this saved workbook will not have the NetCDF import add-in. So for each file to be processed, start with the workbook created with the installed ReorganizeSub macro at the end of Step 4.1. 

Additional Info

The reorganized data array can now be used to identify data values for specific latitude-longitude points. The file can be saved as an Excel workbook, and it can also be saved as a Comma Separated Values (.csv) file. To do this, click on “Save As” under “File”, choose a destination directory, and then select “CSV (Comma-Delimited)” as the format. The .csv file can then be imported into other applications as text.

 

Related Resources

Documentation for NetCDF4Excel
UCAR NetCDF Software Page

Details

Last Updated

Dec. 2, 2026

Published

Dec. 1, 2020

Data Archive

Goddard Earth Sciences Data and Information Services Center (GES DISC)