How do I access the add_offset and scale_factor in an .nc file?

When I give

Import["H:\\g15e\\nc_ecmwf\\era5\\ec_2006010904z_25_PV_T_u_v.nc", \
"Attributes"] [file name works - loses underscores in post]

among the responses are

"/u" -> <|"_FillValue" -> -32767, "add_offset" -> 30.6164, 
  "long_name" -> "U component of wind", "missing_value" -> -32767, 
  "scale_factor" -> 0.00198886, "standard_name" -> "eastward_wind", 
  "units" -> "m s**-1"|>,

How do I access add_offset and scale_factor for subsequent calculations and where is this written up in the online documentation?​

Look up the documentation for Association.

Eric, DId so and thanks.

Going on, why does the following Do line on a 2-d array, array1

 array1 = {{11, 12, 13, 14}, {21, 22, 23, 24}}

  Do[Part[array1, 1, index3], {index3, {1, 2}}]

give an error message to the effect that

  Do::nliter: Non-list iterator index3 at position 2 does not evaluate to a real numeric value.  It seems like a normal Do loop in MM syntax.

Joel

I don’t get that message running that code. I get that message if I provide a symbol as the Do iterator and the symbol doesn’t evaluate to a number. Is this the exact code, or did you try to simplify the example? I would need to more about what happened in your session. Have you tried quitting the kernel and trying again?

FWIW, you shouldn’t expect that code to actually resolve to any value. Well, more accurately it should evaluate to Null.

Eric,

I started with a clean fresh notebook and tried with and without initializing the index variable. What is attached is the complete notebook, test05.nb.

Joel

test05.nb (5.74 KB)

Ah. The problem is that you’re using an invalid variable name. The underscore character in Mathematica is used as a shortcut for Pattern. When you did this:

index_a = 0

you actually created a replacement rule for expressions that have a as their head. That doesn’t really have anything to do with the iteration variable in Do, because Do will localize that automatically. Still, Do expects a symbol as the iteration variable, not a Pattern expression.

To fix both of these issues, choose a variable name that doesn’t include reserved characters.

Having said that, I notice that these error messages are different than what you reported before, so we still haven’t figured out what was going wrong before.

Thanks, and have made progress.

Joel