Re: [netcdfgroup] what is the correct shape of this 3-D variable?

 On 11/1/10 1:08 PM, Michael Rawlins wrote:

I'm trying to understand the data in the "air" variable in this file:

ftp://ftp.cdc.noaa.gov/Datasets/NARR/Dailies/monolevel/air.2m.1980.nc

The header shows this:
It's temperature, packed with scale and offset as short integers. The order of the dimensions returned by ncdump is the C-order, in fortran they will be reversed.

-Jeff

    short air(time, y, x) ;
        air:units = "K" ;
        air:long_name = "Daily Air Temperature at 2 m" ;
        air:unpacked_valid_range = 151.f, 400.f ;
        air:precision = 0.003799786f ;
        air:actual_range = 224.0775f, 313.0685f ;
        air:missing_value = 32767s ;
        air:valid_range = -32765s, 32765s ;
        air:_FillValue = -32767s ;
        air:GRIB_name = "TMP" ;
        air:GRIB_id = 11 ;
        air:var_desc = "Air temperature" ;
        air:standard_name = "air_temperature" ;
        air:level_desc = "2 m" ;
        air:dataset = "NARR Daily Averages" ;
        air:statistic = "Mean" ;
        air:parent_stat = "Individual Obs" ;
        air:grid_mapping = "Lambert_Conformal" ;
        air:coordinates = "lat lon" ;
        air:add_offset = 275.5f ;
        air:scale_factor = 0.003799786f ;
        air:cell_methods = "time: mean (of 8 3-hourly values in one day)
" ;

An ncdump -v air gives this for the first 349 values:

 air =
  6392, 6396, 6396, 6386, 6392, 6369, 6345, 6353, 6320, 6339, 6306, 6330,
6310, 6263, 6291, 6269, 6269, 6246, 6217, 6217, 6172, 6176, 6115, 6135, 6098, 6039, 6065, 6022, 6022, 5956, 5874, 5880, 5855, 5855, 5820, 5753, 5753, 5689, 5705, 5720, 5699, 5730, 5712, 5724, 5740, 5689, 5701, 5720, 5701, 5699, 5685, 5685, 5720, 5753, 5753, 5827, 5788, 5788, 5792, 5825, 5800, 5903, 5954, 5925, 5985, 6168, 6146, 6086, 6151, 6102, 6133, 6263, 6150, 6238, 6281, 6279, 6308, 6314, 6287, 6326, 6355, 6330, 6353, 6390, 6365, 6411, 6404, 6367, 6398, 6388, 6374, 6374, 6357, 6337, 6337, 6324, 6308, 6308, 6298, 6287, 6287, 6277, 6273, 6273, 6269, 6275, 6275, 6273, 6263, 6263, 6267, 6265, 6265, 6265, 6267, 6267, 6273, 6273, 6256, 6281, 6285, 6259, 6283, 6289, 6265, 6277, 6271, 6250, 6277, 6279, 6250, 6240, 6258, 6234, 6228, 6252, 6226, 6221, 6242, 6215, 6205, 6197, 6197, 6207, 6197, 6197, 6209, 6221, 6221, 6230, 6203, 6230, 6273, 6252, 6291, 6330, 6314, 6316, 6322, 6322, 6314, 6306, 6306, 6271, 6236, 6230, 6211, 6201, 6191, 6191, 6180, 6187, 6176, 6176, 6184, 6195, 6195, 6197, 6221, 6199, 6224, 6217, 6234, 6256, 6250, 6240, 6248, 6248, 6257, 6277, 6267, 6292, 6283, 6304, 6312, 6322, 6339, 6345, 6345, 6366, 6374, 6371, 6372, 6384, 6388, 6388, 6388, 6390, 6388, 6382, 6374, 6380, 6372, 6376, 6374, 6372, 6372, 6374, 6380, 6392, 6398, 6415, 6429, 6429, 6454, 6460, 6464, 6456, 6458, 6450, 6437, 6437, 6423, 6425, 6415, 6413, 6405, 6386, 6386, 6367, 6363, 6351, 6341, 6339, 6333, 6333, 6330, 6341, 6335, 6339, 6339, 6341, 6341, 6347, 6349, 6357, 6361, 6365, 6368, 6368, 6380, 6382, 6384, 6392, 6398, 6394, 6394, 6363, 6365, 6318, 6329, 6269, 6193, 6207, 6145, 6125, 6092, 6063, 5985, 5985, 5936, 5933, 5897, 5817, 5771, 5765, 5765, 5619, 5492, 5469, 5346, 5321, 5321, 5311, 5276, 5325, 5346, 5272, 5331, 5331, 5335, 5364, 5319, 5084, 5228, 5228, 4202, 3020, 3730, 3886, 2763, 2763, 3590, 5732, 5817, 5849, 2356, 2356, 2013, 4305, 5590, 6351, 6540, 6540, 6402, 6540, 6520, 6524, 6462, 6462, 6147, 6141, 6102, 6063, 5989, 5989,
    6172, 6162, 6158, 5664, 6199, 6199, 6662, 32767, 32767, 32767, 32767,
    32767, 32767,


Below is the simple FORTRAN program I wrote to read the data. The third dimension (X) has 349 elements. If I write out the 349 elements of third dimension of air [eg. air(1,1,1:349)], I do not get the above 349 values in the file. But if I write out the first 349 elements of the first dimension [eg. air(1:349,1,1)], I get the first 349 elements in the file (shown above). But the first dimension in the file holds time, which the header suggests has 366 elements. How is this 3-D data oriented when read with NF_GET_VAR_INT2? I'm a relative novice with netCDF. I seem to recall it is the last dimension of an array that varies first in a read variable. That is X in this case.



  program readNARR

  INCLUDE  '/usr/include/netcdf.inc'
  INTEGER NCID, STATUS, IDVAR
  parameter (NY=277,NX=349,Ntime=366,NDIMS=2)
  integer :: x_dimid, y_dimid, dimids(NDIMS),itairdims(2)
  integer*2 :: air(Ntime,NY,NX)
  real x(NX),y(NY),air_degC(Ntime,NY,NX)

! gfortran -fbounds-check read_NARR_Test.f90 get_season_NARR.f90 -I/usr/include -lnetcdf -lnetcdff

  PRINT *, 'Using NetCDF version: ', NF_INQ_LIBVERS()

  STATUS = NF_OPEN('air.2m.1980.nc',0,NCID)
  if (status .ne. 0) then
     print*, NF_STRERROR(STATUS)
     stop 'Error reading .nc file'
  endif

  STATUS = NF_INQ_VARID (NCID, 'air', ID_air)
  IF (STATUS .NE. 0) stop 'Error getting air varID'
  print*, 'ID for air ', ID_air
  STATUS = NF_GET_VAR_INT2 (NCID, ID_air, air)
  IF (STATUS .NE. 0) stop 'Error getting air data'
  print*, 'Get Var completed'

! Write all of the array values of the third dimension. These should be the ! first 349 values in the ncdump. The file header says third dimension, 'X', ! has 349 elements. The following write does not show the first 349 values
!  in the ncdump.
  write(*,'(349i6)') air(1,1,1:349)

! But if we write the first 349 values of the first dimension (time), we get
!  the first 349 values shown in the ncdump of the .nc file.
  write(*,*)  '*******************************************'
  write(*,*)  '*******************************************'
  write(*,'(349i6)') air(1:349,1,1)

3  stop
end program readNARR


_______________________________________________
netcdfgroup mailing list
netcdfgroup@xxxxxxxxxxxxxxxx
For list information or to unsubscribe, visit: http://www.unidata.ucar.edu/mailing_lists/



  • 2010 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdfgroup archives: