# [ncl-talk] set_dimension_query

Kunal Bali kunal.bali9 at gmail.com
Sat Sep 30 13:25:51 MDT 2017

```Thank You so much, Rick Sir for providing all these valuable information.
It's little complex to me but I am trying to understand.

However, I am trying to convert this hdf file into netcdf by incorporating
your code. But file did not convert with Geo2D. please check the code below
if you have time.

begin
a =
var  = short2flt(a->Optical_Depth_055(:,:))

x = fspan(-3450000.+500., -2250000.-500., 1200)
y = fspan(1600000.-500., 400000.+500., 1200)

x := conform_dims((/1200, 1200/), x, 1)
y := conform_dims((/1200, 1200/), y, 0)

src = "+proj=aea +lat_0=23.0 +lat_1=21d03m +lat_2=41 +lon_0=102
+ellps=clrk66"
dst = "+proj=latlon +ellps=sphere"
x := flt2dble(ndtooned(x))
y := flt2dble(ndtooned(y))
z = x   ; A quick-n-dirty way to get an empty Z array of same
dimensions/type
z = 0.   ;
transform_coordinate(src, dst, x, y, z)

; convert back to curvilinear coord arrays
lon = onedtond(x, (/1200, 1200/))
lat = onedtond(y, (/1200, 1200/))

lat at units = "degrees_north"
lat!0 = "lat"
;    lat&lat = lat
lon at units = "degrees_east"
lon!0 = "lon"
;    lon&lon = lon

var!0 = "lat"    ; you can name these dimensions whatever you want..
var!1 = "lon"
;        var&lat = lat     ; but make sure you refer to the correct named
dimensions
;        var&lon = lon

;     system("/bin/rm -f simple1.nc")
ncdf = addfile("simple3.nc" ,"c")  ; open output netCDF file

;===================================================================
; create global attributes of the file (optional)
;===================================================================
fAtt               = True            ; assign file attributes
fAtt at title         = "NCL Simple Approach to netCDF Creation"
fAtt at source_file   =  "original-file.nc"
fAtt at Conventions   = "None"
fAtt at creation_date = systemfunc ("date")
fileattdef( ncdf, fAtt )            ; copy file attributes

;===================================================================
; make time an UNLIMITED dimension; recommended  for most applications
;===================================================================

ncdf->var = var

end

Kunal Bali

On Sat, Sep 30, 2017 at 10:15 PM, Rick Brownrigg <brownrig at ucar.edu> wrote:

> Hi,
>
> This file is an interesting and challenging one to geo-reference. Without
> proper documentation on how the file is constructed/encoded, all of what
> follows is speculation. But I'm fairly confident it is sound.
>
> In the group GRID_1, there are these parameters:
>
>   GridName="grid1km"
>   XDim=1200
>   YDim=1200
>   UpperLeftPointMtrs=(-3450000.000000,1600000.000000)
>   LowerRightMtrs=(-2250000.000000,400000.000000)
>   Projection=GCTP_ALBERS
>   ProjParams=(0,0,21030000,41000000,102000000,23000000,0,0,0,0,0,0,0)
>   SphereCode=12
>   GridOrigin=HDFE_GD_UL
>   GROUP=Dimension
>   END_GROUP=Dimension
>
> The name suggests a 1KM grid, and as such, by its resolution, it should
> span 1200KM. Indeed, from the corner points:
>
> In X:  (-3450000 - -2250000) = a span of 1200000meters; divided by
> xres=1200, yields 1000meter grid cells
> In Y:  (1600000 - 400000) = 1200000meters; div by yres=1200 yields
> 1000meter grid cells
>
> So everything is consistent so far. The GCTP_ALBERS suggest the grid was
> constructed based upon an ALBERS projection, using the GCTP library. The
> ProjParams give further details:
>
>   ProjParams=(0,0,21030000,41000000,102000000,23000000,0,0,0,0,0,0,0)
>
> Again, without documentation, this is speculation, but looking at
> pg13/appendexD in:
>
>    https://www.ngs.noaa.gov/PUBS_LIB/GeneralCartographicTransformat
> ionPackage_v2_TR_NOS124_CGS9.pdf
>
> for the Albers projection, the first 2 values appear to be semimajor axis
> of ellipsoid, and eccentricity. Both are zero, implying defaults of
> Clarke's 1866 ellipsoid and spherical earth (which seems to be an oymoron?
>
> The next 6 values might be:
>
>   lat of 1st standard parallel
>   lat of 2nd standard parallel
>   lon of central meridian
>   lat of projection's origin
>   false easting (zero in this case)
>   false northing (zero)
>
> the remaining zeros don't seem to apply.
>
> NCL does not have an public interface to GCTP, but there is an
> undocumented interface to the well-known proj4 library. The trick here is
> to use it to convert from meters-on-the ground units into lat/lon.  The
> first step is to construct arrays representing the grid's position in
> meters. In the X direction, if we did
>
>   x = fspan(-3450000., -2250000, 1200)
>
> we get an array of 1201, which is wrong. I speculate that for a grid of
> 1200, those values represent the total *spatial extent* of the grid, but
> that the data are based upon cell centers, not corners. Thus something like:
>
>   x = fspan(-3450000.+500., -2250000.-500., 1200)
>   y = fspan(1600000.-500., 400000.+500., 1200)
>
> A 1km grid cannot obviously be constant spacing in longitude, so
> ultimately, your coordinate arrays are going to be curvilinear:
>
>   x := conform_dims((/1200, 1200/), x, 1)
>   y := conform_dims((/1200, 1200/), y, 0)
>
> NOTE: THIS ASSUMES THE GRID IS ROW MAJOR, WEST-->EAST, NORTH-->SOUTH
>
> The undocumented NCL function "transform_coordinates" takes a proj4
> source-porjection string, dest-proj string, x, y, z 1D arrays of type
> double, and returns the results in the x,y,z arrays. I won't go into the
> details of the proj-strings. We want something like:
>
> src = "+proj=aea +lat_0=23.0 +lat_1=21d03m +lat_2=41 +lon_0=102
> +ellps=clrk66"
> dst = "+proj=latlon +ellps=sphere"
> x := flt2dble(ndtooned(x))
> y := flt2dble(ndtooned(y))
> z = x   ; A quick-n-dirty way to get an empty Z array of same
> dimensions/type
> z = 0.  ;
> transform_coordinate(src, dst, x, y, z)
>
> ; convert back to curvilinear coord arrays
> lon = onedtond(x, (/1200, 1200/))
> lat = onedtond(y, (/1200, 1200/))
>
>
> From here, you have to associate the lat/lon coordinate arrays with the
> variables you want to plot, as Adam and other previously described.
>
> Attached is a script and example plot of the resultant grid. Please let
> the group know if this appears to be the correct area-of-interest.
>
> Rick
>
>
>
> On Fri, Sep 29, 2017 at 11:45 AM, Rick Brownrigg <brownrig at ucar.edu>
> wrote:
>
>> Hi,
>>
>> I do not know for certain without examining the file, but it looks like
>> those values are map-projection parameters, from which curvilinear grid was
>> generated as equal-area grid cells in lat/lon spac.
>>
>> Rick
>>
>> On Fri, Sep 29, 2017 at 10:16 AM, Kunal Bali <kunal.bali9 at gmail.com>
>> wrote:
>>
>>> Thanks for all the suggestions and help Adam Sir. Now the data is
>>> showing over the Indian region.
>>> but one thing I need to confirm here.
>>>
>>> Some values in the form of UpperLeftPointMtrs and LowerRightMtrs are
>>> given in the file ((in the original hdf file) ) description along with X
>>> YDim.
>>>
>>> So, does these value interfer while creating the lat lon dimensions
>>> during conversion netcdf from hdf?
>>>
>>> Sould these values be consider or we can ignore these values?
>>>
>>>
>>> group: latlon {
>>>     variables:
>>>       short _HDFEOS_CRS;
>>>         :Projection = "GCTP_ALBERS";
>>>         :*UpperLeftPointMtrs* = -3450000.0, 1600000.0; // double
>>>         *:LowerRightMtrs* = -2250000.0, 400000.0; // double
>>>         :ProjParams = 0.0, 0.0, 2.103E7, 4.1E7, 1.02E8, 2.3E7, 0.0, 0.0,
>>> 0.0, 0.0, 0.0, 0.0, 0.0; // double
>>>         :SphereCode = "12";
>>>
>>>     group: Data_Fields {
>>>       dimensions:
>>>         YDim = 1200;
>>>         XDim = 1200;
>>>       variables:
>>>         float lat(YDim=1200, XDim=1200);
>>>
>>>         float lon(YDim=1200, XDim=1200);
>>>
>>>
>>>
>>>
>>>
>>>
>>> Regards
>>> Kunal Bali
>>>
>>>
>>>
>>>
>>> On Thu, Sep 28, 2017 at 9:27 PM, Adam Phillips <asphilli at ucar.edu>
>>> wrote:
>>>
>>>> Hi Kunal,
>>>> As the documentation states, latGlobeFo (lonGlobeFo) generates
>>>> latitudes (longitudes) and associated metadata for a *global* fixed
>>>> offset grid.
>>>> https://www.ncl.ucar.edu/Document/Functions/Contributed/latG
>>>> lobeFo.shtml
>>>> https://www.ncl.ucar.edu/Document/Functions/Contributed/lonG
>>>> lobeFo.shtml
>>>> If you need to create coordinates for a regional grid, then you will
>>>> have to do it by hand. For example, if you know your data are equally
>>>> spaced in the both the latitude and longitude direction from 0:40N, 60:100E
>>>> (for example), you can set up your coordinates like this:
>>>>
>>>> lat = fspan(0,40,1200)
>>>> lon = fspan(60,100,1200)
>>>> print(lat)   ; check that these are the correct coordinates
>>>> print(lon)   ; check that these are the correct coordinates
>>>> lat at units = "degrees_north"
>>>> lat!0 = "lat"
>>>> lat&lat = lat
>>>> lon at units = "degrees_east"
>>>> lon!0 = "lon"
>>>> lon&lon = lon
>>>> var!0 = "lat"    ; you can name these dimensions whatever you want..
>>>> var!1 = "lon"
>>>> var&lat = lat     ; but make sure you refer to the correct named
>>>> dimensions
>>>> var&lon = lon
>>>>
>>>> The above is similar to what latGlobeFo/lonGlobeFo do for global grids.
>>>> Hope that helps. If you have further questions please respond to ncl-talk.
>>>>
>>>> On Tue, Sep 26, 2017 at 10:26 AM, Kunal Bali <kunal.bali9 at gmail.com>
>>>> wrote:
>>>>
>>>>> Thanks for all the suggestions Dennis sir.
>>>>> But now I have come to know that the dimensions
>>>>>
>>>>> nlat=1200
>>>>> nlon=1200
>>>>>
>>>>> are belongs to only of Indian region.
>>>>>
>>>>> And the code I am using below is not displaying the data over Indian
>>>>> region.
>>>>>
>>>>>  lat = latGlobeFo(nlat, "lat", "latitude", "degrees_north")
>>>>>  lon = lonGlobeFo(nlon, "lon", "longitude", "degrees_east")
>>>>> lat = lat(::-1)
>>>>> lon = (/ lon - 180. /)  ; subtract 180 from all values
>>>>> lon&lon = lon
>>>>>
>>>>>
>>>>> regards
>>>>> Kunal Bali
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> On Tue, Sep 19, 2017 at 10:36 PM, Dennis Shea <shea at ucar.edu> wrote:
>>>>>
>>>>>> Ditto what Marston posted.
>>>>>>
>>>>>> ===
>>>>>> Please look at NCL's FAQ.
>>>>>>
>>>>>> [1] Click "Support" at top of page
>>>>>> [2] Click FAQ
>>>>>>
>>>>>> I think it would be instructive to look at all of the topics.
>>>>>>
>>>>>> For example:
>>>>>>
>>>>>> *Error messages and other issues*
>>>>>> Look at #7
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Tue, Sep 19, 2017 at 3:03 AM, Marston Johnston <shejo284 at gmail.com
>>>>>> > wrote:
>>>>>>
>>>>>>> It tells you in the warning message, exactly what to do to remove
>>>>>>> the warning.
>>>>>>>
>>>>>>> If you want to improve you coding skills, it would better to
>>>>>>> understand why the warning is occurring in the first place: dimension 0 and
>>>>>>> 1 of the variable you are passing has no names or the names do not match
>>>>>>> the variable on the lhs.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> /M
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>>>>>>
>>>>>>> Marston S. Ward, PhD
>>>>>>>
>>>>>>> Department of Earth Sciences
>>>>>>>
>>>>>>> University of Gothenburg, Sweden
>>>>>>>
>>>>>>> Email: marston.johnston at gu.se
>>>>>>>
>>>>>>> SkypeID: marston.johnston
>>>>>>>
>>>>>>> Phone: +46-31-7864901 <+46%2031%20786%2049%2001>
>>>>>>>
>>>>>>> Only the fruitful thing is true!
>>>>>>>
>>>>>>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> *From: *ncl-talk <ncl-talk-bounces at ucar.edu> on behalf of Kunal
>>>>>>> Bali <kunal.bali9 at gmail.com>
>>>>>>> *Date: *Tuesday, 19 September 2017 at 10:50
>>>>>>> *Cc: *"ncl-talk at ucar.edu" <ncl-talk at ucar.edu>
>>>>>>> *Subject: *Re: [ncl-talk] set_dimension_query
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> Thank you for providing this information.
>>>>>>>
>>>>>>> It's working. The script given below is now able to convert multiple
>>>>>>> files into .netcdf with the desired file name.
>>>>>>> However, on the same time, it also shows some warnings. But noted
>>>>>>> that, I am successfully creating the multiple files into the netcdf. I just
>>>>>>> need to know that how can I remove these warnings?
>>>>>>>
>>>>>>> warning:VarVarWrite: Dimension names for dimension number (0) don't
>>>>>>> match, assigning name of rhs dimension to lhs and overwriting coordinate
>>>>>>> variable, use "(/../)" if this change is not desired
>>>>>>> warning:VarVarWrite: Dimension names for dimension number (1) don't
>>>>>>> match, assigning name of rhs dimension to lhs and overwriting coordinate
>>>>>>> variable, use "(/../)" if this change is not desired
>>>>>>> warning:["Execute.c":8640]:Execute: Error occurred at or near line
>>>>>>> 22 in file netcdf2.ncl
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> ;-----------------------------------------------------------
>>>>>>> -----------
>>>>>>>
>>>>>>>
>>>>>>> begin
>>>>>>>
>>>>>>>         diri = "/Users/Pushp/Desktop/test/"   ; input directory
>>>>>>>         fili  = systemfunc("cd "+diri+" ; ls MAIACTAOT.h00v02*hdf")
>>>>>>>         nfili = dimsizes(fili)
>>>>>>>         print("nfili="+nfili)
>>>>>>>
>>>>>>>
>>>>>>>         dirnc = "/Users/Pushp/Desktop/test/"   ; output (netCDF)
>>>>>>> directory
>>>>>>>
>>>>>>>         do nf=0,nfili-1
>>>>>>>         pthi = diri+fili(nf)
>>>>>>>
>>>>>>>         var  = short2flt(f->Optical_Depth_055(:,:))
>>>>>>>
>>>>>>>         nlat = 1200
>>>>>>>         nlon = 1200
>>>>>>>         lat  = latGlobeFo(nlat, "lat", "latitude", "degrees_north")
>>>>>>>         lon  = lonGlobeFo(nlon, "lon", "longitude",
>>>>>>> "degrees_east")
>>>>>>>     ;    lat  = lat(::-1)
>>>>>>>         lon  = (/ lon - 180. /)  ; subtract 180 from all values
>>>>>>>         lon&lon = lon           ; update coordinates
>>>>>>>
>>>>>>>         var!0 = "lat"    ; you can name these dimensions whatever
>>>>>>> you want..
>>>>>>>         var!1 = "lon"
>>>>>>>         var&lat = lat     ; but make sure you refer to the correct
>>>>>>> named dimensions
>>>>>>>         var&lon = lon
>>>>>>>
>>>>>>>
>>>>>>>      filroot = str_get_cols(fili(nf), 0, 27)  ; eg:
>>>>>>> "MAIACTAOT.h00v02.20000570505"
>>>>>>>      filnc    = filroot+".nc"
>>>>>>>      pthnc  = dirnc + filnc
>>>>>>>
>>>>>>>      system("/bin/rm -f "+pthnc)
>>>>>>>      ncdf = addfile(pthnc,"c")  ; open new netCDF file
>>>>>>>
>>>>>>>
>>>>>>>      end do    ; end 'nf' loop
>>>>>>>
>>>>>>>    ;     system("/bin/rm -f simple2.nc")
>>>>>>>    ;     ncdf = addfile("simple2.nc" ,"c")  ; open output netCDF
>>>>>>> file
>>>>>>>
>>>>>>>     ;===========================================================
>>>>>>> ========
>>>>>>>     ; create global attributes of the file (optional)
>>>>>>>     ;===========================================================
>>>>>>> ========
>>>>>>>        fAtt               = True            ; assign file attributes
>>>>>>>        fAtt at title         = "NCL Simple Approach to netCDF Creation"
>>>>>>>        fAtt at source_file   =  "original-file.nc"
>>>>>>>        fAtt at Conventions   = "None"
>>>>>>>        fAtt at creation_date = systemfunc ("date")
>>>>>>>        fileattdef( ncdf, fAtt )            ; copy file attributes
>>>>>>>
>>>>>>>     ;===========================================================
>>>>>>> ========
>>>>>>>     ; make time an UNLIMITED dimension; recommended  for most
>>>>>>> applications
>>>>>>>     ;===========================================================
>>>>>>> ========
>>>>>>>        filedimdef(ncdf,"time",-1,True)
>>>>>>>
>>>>>>> ;       ncdf->var&lat = lat
>>>>>>> ;       ncdf->var&lon = lon
>>>>>>>        ncdf->var = var
>>>>>>>
>>>>>>> end
>>>>>>>
>>>>>>>
>>>>>>> Kunal Bali
>>>>>>>
>>>>>>> Research Scholar
>>>>>>>
>>>>>>> Radio & Atmospheric Science Division
>>>>>>>
>>>>>>> CSIR - National Physical Laboratory
>>>>>>>
>>>>>>> New Delhi - 110012
>>>>>>>
>>>>>>> India
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On Mon, Sep 18, 2017 at 9:04 PM, Dennis Shea <shea at ucar.edu> wrote:
>>>>>>>
>>>>>>> Loop over the files ...
>>>>>>>
>>>>>>>
>>>>>>>  diri = "/media/Local Disk/NPL/MODIS_FPC/"   ; input directory
>>>>>>>
>>>>>>>  fili  = systemfunc("cd "+diri +; ls MAIACTAOT.h00v02*hdf")
>>>>>>>
>>>>>>>  nfili = dimsizes(fili)
>>>>>>>
>>>>>>>  print("nfili="+nfili)
>>>>>>>
>>>>>>>  dirnc = "/media/Local Disk/NPL/MODIS_FPC/"   ; output (netCDF)
>>>>>>> directory
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>  do nf=0,nfili-1
>>>>>>>
>>>>>>>       pthi = diri+fili(nf)
>>>>>>>
>>>>>>>
>>>>>>>       ....
>>>>>>>
>>>>>>>      filroot = *str_get_cols*(fili(nf), 0, 27)  ; eg:
>>>>>>> "MAIACTAOT.h00v02.20000570505"
>>>>>>>
>>>>>>>      filnc    = filroot+".nc"
>>>>>>>
>>>>>>>      pthnc  = dirnc + filnc
>>>>>>>
>>>>>>>      system("/bin/rm -f "+pthnc)
>>>>>>>      ncdf = addfile(pthnc,"c")  ; open new netCDF file
>>>>>>>
>>>>>>>      ....
>>>>>>>
>>>>>>> end do    ; end 'nf' loop
>>>>>>>
>>>>>>>
>>>>>>> =====
>>>>>>>
>>>>>>> If there is something you do not understand use some print
>>>>>>> statements.
>>>>>>>
>>>>>>> Become familiar with the 'string' category. Look at all the
>>>>>>> functions.
>>>>>>>
>>>>>>>    https://www.ncl.ucar.edu/Document/Functions/string.shtml
>>>>>>>
>>>>>>>
>>>>>>>    https://www.ncl.ucar.edu/Document/Functions/Built-in/str_get
>>>>>>> _cols.shtml
>>>>>>>
>>>>>>> Good Luck
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On Mon, Sep 18, 2017 at 6:11 AM, Kunal Bali <kunal.bali9 at gmail.com>
>>>>>>> wrote:
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> that will change the name of only one file. isn't it. but what about
>>>>>>> the other files
>>>>>>>
>>>>>>> I have 365 files in one directory and I need to change all the file
>>>>>>> name one by one.
>>>>>>>
>>>>>>>
>>>>>>> Kunal Bali
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On Mon, Sep 18, 2017 at 5:14 PM, Dennis Shea <shea at ucar.edu> wrote:
>>>>>>>
>>>>>>> Really?
>>>>>>>
>>>>>>> Change:
>>>>>>>       system("/bin/rm -f simple.nc")
>>>>>>>
>>>>>>> To:
>>>>>>>       system("/bin/rm -f MAIACTAOT.h00v02.20000570505.nc
>>>>>>> <http://simple.nc>")
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On Mon, Sep 18, 2017 at 12:37 AM, Kunal Bali <kunal.bali9 at gmail.com>
>>>>>>> wrote:
>>>>>>>
>>>>>>> Thanks, it worked.
>>>>>>>
>>>>>>> one more question is that.
>>>>>>>
>>>>>>> I used the code (given below). So it gives simple.nc name as an
>>>>>>> output file.
>>>>>>>
>>>>>>>
>>>>>>> If I want to keep the original file name with the output file name
>>>>>>> then what should I do?
>>>>>>>
>>>>>>> I mean the original file name is MAIACTAOT.h00v02.20003660700.hdf
>>>>>>>
>>>>>>> Now I want to create my netcdf file name  as
>>>>>>> MAIACTAOT.h00v02.20003660700.nc NOT simple.nc.
>>>>>>>
>>>>>>> I can not simply write simple.nc file name because I have many
>>>>>>> files.
>>>>>>>
>>>>>>> e.g I have one directory having 365 .hdf file. So I need to convert
>>>>>>> all the hdf file to netcdf file at once with the same name of original file
>>>>>>> names.
>>>>>>>
>>>>>>> I hope you have got my query.
>>>>>>>
>>>>>>> please let me know that too.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> Thank You
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> Kunal Bali
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On Thu, Sep 14, 2017 at 9:09 PM, Adam Phillips <asphilli at ucar.edu>
>>>>>>> wrote:
>>>>>>>
>>>>>>> Hi Kunal,
>>>>>>>
>>>>>>> It looks to me like your latitudes are flipped. You are setting up
>>>>>>> and assigning your coordinate lat/lon variables in this coding:
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> nlat = 1200
>>>>>>> nlon = 1200
>>>>>>> lat = latGlobeFo(nlat, "lat", "latitude", "degrees_north")
>>>>>>>
>>>>>>> lon = lonGlobeFo(nlon, "lon", "longitude", "degrees_east")
>>>>>>> lat = lat(::-1)
>>>>>>> lon = (/ lon - 180. /)  ; subtract 180 from all values
>>>>>>>
>>>>>>> lon&lon = lon           ; update coordinates
>>>>>>>
>>>>>>> var!0 = "lat"    ; you can name these dimensions whatever you want..
>>>>>>> var!1 = "lon"
>>>>>>> var&lat = lat     ; but make sure you refer to the correct named
>>>>>>> dimensions
>>>>>>> var&lon = lon
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> Assuming I'm right on your latitudes being the issue, one of the
>>>>>>> following two modifications should work:
>>>>>>>
>>>>>>> Delete this line:
>>>>>>>
>>>>>>> lat = lat(::-1)
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> If the above doesn't fix it, try this:
>>>>>>>
>>>>>>> Change this:
>>>>>>>
>>>>>>> lat = lat(::-1)
>>>>>>>
>>>>>>> to this:
>>>>>>>
>>>>>>> lat = lat(::-1)
>>>>>>>
>>>>>>> lat&lat = lat
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> If you continue to have issues please respond to ncl-talk.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On Wed, Sep 13, 2017 at 12:35 PM, Kunal Bali <kunal.bali9 at gmail.com>
>>>>>>> wrote:
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> For direct output as a netcdf format, I used the script given below.
>>>>>>> It produced the netcdf file easily. But the netcdf file and original hdf
>>>>>>> file both showing the different results. The data pattern is shifted. I
>>>>>>> mean it may be related to the lat lon position. please see the attached
>>>>>>> file, you will understand.  And please let me know which one is correct.
>>>>>>>
>>>>>>> ;-----------------------------------------------------------
>>>>>>> -----------
>>>>>>>
>>>>>>>
>>>>>>> begin
>>>>>>> 00v02.20000570505.hdf","r")
>>>>>>>         var  = short2flt(a->Optical_Depth_055(:,:))
>>>>>>>             ;          short2flt(a[:]->noxfire)
>>>>>>>         nlat = 1200
>>>>>>>         nlon = 1200
>>>>>>>         lat = latGlobeFo(nlat, "lat", "latitude", "degrees_north")
>>>>>>>         lon = lonGlobeFo(nlon, "lon", "longitude", "degrees_east")
>>>>>>>         lat = lat(::-1)
>>>>>>>         lon = (/ lon - 180. /)  ; subtract 180 from all values
>>>>>>>         lon&lon = lon           ; update coordinates
>>>>>>>
>>>>>>>         var!0 = "lat"    ; you can name these dimensions whatever
>>>>>>> you want..
>>>>>>>         var!1 = "lon"
>>>>>>>         var&lat = lat     ; but make sure you refer to the correct
>>>>>>> named dimensions
>>>>>>>         var&lon = lon
>>>>>>>
>>>>>>>                  system("/bin/rm -f simple.nc")
>>>>>>>              ncdf = addfile("simple.nc" ,"c")  ; open output netCDF
>>>>>>> file
>>>>>>>
>>>>>>>     ;===========================================================
>>>>>>> ========
>>>>>>>     ; create global attributes of the file (optional)
>>>>>>>     ;===========================================================
>>>>>>> ========
>>>>>>>        fAtt               = True            ; assign file attributes
>>>>>>>        fAtt at title         = "NCL Simple Approach to netCDF Creation"
>>>>>>>        fAtt at source_file   =  "original-file.nc"
>>>>>>>        fAtt at Conventions   = "None"
>>>>>>>        fAtt at creation_date = systemfunc ("date")
>>>>>>>        fileattdef( ncdf, fAtt )            ; copy file attributes
>>>>>>>
>>>>>>>     ;===========================================================
>>>>>>> ========
>>>>>>>     ; make time an UNLIMITED dimension; recommended  for most
>>>>>>> applications
>>>>>>>     ;===========================================================
>>>>>>> ========
>>>>>>>        filedimdef(ncdf,"time",-1,True)
>>>>>>>        ncdf->var = var
>>>>>>>
>>>>>>> end
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> Kunal Bali
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On Wed, Sep 13, 2017 at 11:27 PM, Kunal Bali <kunal.bali9 at gmail.com>
>>>>>>> wrote:
>>>>>>>
>>>>>>> No problem, I sorted out.
>>>>>>>
>>>>>>> Just changed short to float.
>>>>>>>
>>>>>>>
>>>>>>> Kunal Bali
>>>>>>>
>>>>>>> Research Scholar
>>>>>>>
>>>>>>> Radio & Atmospheric Science Division
>>>>>>>
>>>>>>> CSIR - National Physical Laboratory
>>>>>>>
>>>>>>> New Delhi - 110012
>>>>>>>
>>>>>>> India
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On Wed, Sep 13, 2017 at 11:24 PM, Kunal Bali <kunal.bali9 at gmail.com>
>>>>>>> wrote:
>>>>>>>
>>>>>>> Thanks for providing this information.
>>>>>>>
>>>>>>> Also, I would like to mention that when I plot this data. The values
>>>>>>> are not in the domain. I mean the real values lie in-between 0 to 1 but
>>>>>>> here it is reaching to 400.
>>>>>>>
>>>>>>> So, how to correct the values?
>>>>>>>
>>>>>>> Description of the variable is
>>>>>>>
>>>>>>> short Optical_Depth_055(YDim=1200, XDim=1200);
>>>>>>>   :long_name = "AOT at 0.55 micron";
>>>>>>>   :scale_factor = 0.001; // double
>>>>>>>   :add_offset = 0.0; // double
>>>>>>>   :unit = "None";
>>>>>>>   :_FillValue = -28672S; // short
>>>>>>>   :valid_range = -100S, 5000S; // short
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> Kunal Bali
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On Wed, Sep 13, 2017 at 10:28 PM, Adam Phillips <asphilli at ucar.edu>
>>>>>>> wrote:
>>>>>>>
>>>>>>> Hi Kunal,
>>>>>>>
>>>>>>> Yes, clicking on the output netCDF link from the Applications page:
>>>>>>>
>>>>>>> http://www.ncl.ucar.edu/Applications/o-netcdf.shtml
>>>>>>>
>>>>>>> I would recommend following the inefficient method #1. Unless you
>>>>>>> are writing a file with many large variables, the inefficient method works
>>>>>>> just fine.
>>>>>>>
>>>>>>> http://www.ncl.ucar.edu/Applications/method_1.shtml
>>>>>>>
>>>>>>> Good luck,
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On Wed, Sep 13, 2017 at 10:25 AM, Kunal Bali <kunal.bali9 at gmail.com>
>>>>>>> wrote:
>>>>>>>
>>>>>>> Thank you so much, it worked
>>>>>>>
>>>>>>> I want to know one more thing.
>>>>>>> After rearranging the dimensions can we now convert (or write) this
>>>>>>> arranged file into netcdf format?
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> Kunal Bali
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On Wed, Sep 13, 2017 at 8:55 PM, Adam Phillips <asphilli at ucar.edu>
>>>>>>> wrote:
>>>>>>>
>>>>>>> Hi Kunal,
>>>>>>>
>>>>>>> I think you just need to rearrange the order of your lines and tweak
>>>>>>> a couple of lines. As the error message states, lat is not defined in your
>>>>>>> 3rd line and you are referring to it as if it is.Try this:
>>>>>>>
>>>>>>> 00v02.20000570505.hdf","r")
>>>>>>> var  = a->Optical_Depth_055(:,:)
>>>>>>> nlat = 1200
>>>>>>> nlon = 1200
>>>>>>> lat = latGlobeFo(nlat, "lat", "latitude", "degrees_north")
>>>>>>>
>>>>>>> lon = lonGlobeFo(nlon, "lon", "longitude", "degrees_east")
>>>>>>> lat = lat(::-1)
>>>>>>> lon = (/ lon - 180. /)  ; subtract 180 from all values
>>>>>>> lon&lon = lon           ; update coordinates
>>>>>>>
>>>>>>> var!0 = "lat"    ; you can name these dimensions whatever you want..
>>>>>>> var!1 = "lon"
>>>>>>>
>>>>>>> var&lat = lat     ; but make sure you refer to the correct named
>>>>>>> dimensions
>>>>>>>
>>>>>>> var&lat = lon
>>>>>>>
>>>>>>> ;var&XDim_grid1km = lat
>>>>>>> ;var&YDim_grid1km = lon
>>>>>>>
>>>>>>>
>>>>>>> If you have any further questions please respond to the ncl-talk
>>>>>>> email list.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On Wed, Sep 13, 2017 at 8:38 AM, Kunal Bali <kunal.bali9 at gmail.com>
>>>>>>> wrote:
>>>>>>>
>>>>>>> Dear NCL
>>>>>>>
>>>>>>> I have a file with the variable summary. The dimensions are in 2D.
>>>>>>>
>>>>>>> ncl 2>  printVarSummary(var)
>>>>>>>
>>>>>>> Variable: var
>>>>>>> Type: short
>>>>>>> Total Size: 2880000 bytes
>>>>>>>             1440000 values
>>>>>>> Number of Dimensions: 2
>>>>>>> Dimensions and sizes:    [*YDim_grid1km | 1200] x [XDim_grid1km |
>>>>>>> 1200]*
>>>>>>> Coordinates:
>>>>>>> Number Of Attributes: 7
>>>>>>>   long_name :    AOT at 0.55 micron
>>>>>>>   scale_factor :    0.001
>>>>>>>   unit :    None
>>>>>>>   _FillValue :    -28672
>>>>>>>   valid_range :    ( -100, 5000 )
>>>>>>>   hdf_name :    Optical_Depth_055
>>>>>>>
>>>>>>> I am trying to read the dimensions of this file as
>>>>>>>
>>>>>>> begin
>>>>>>> 00v02.20000570505.hdf","r")
>>>>>>>
>>>>>>>             var  = a->Optical_Depth_055(:,:)
>>>>>>>
>>>>>>>          var&XDim_grid1km = lat
>>>>>>>          var&YDim_grid1km = lon
>>>>>>>
>>>>>>>         nlat = 1200
>>>>>>>          nlon = 1200
>>>>>>>             lat = latGlobeFo(nlat, "lat", "latitude",
>>>>>>> "degrees_north")
>>>>>>>         lon = lonGlobeFo(nlon, "lon", "longitude", "degrees_east")
>>>>>>>             lat = lat(::-1)
>>>>>>>             lon = (/ lon - 180. /)  ; subtract 180 from all values
>>>>>>>             lon&lon = lon           ; update coordinates
>>>>>>>
>>>>>>>
>>>>>>>         var!0 = "lat"
>>>>>>>         var!1 = "lon"
>>>>>>>
>>>>>>>
>>>>>>> But the error appeared as
>>>>>>> *fatal:Variable (lat) is undefined*
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> So, could anyone please let me know that how to read dimension of
>>>>>>> this file.
>>>>>>>
>>>>>>> Thank You
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> Regards
>>>>>>>
>>>>>>> Kunal Bali
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> _______________________________________________
>>>>>>> ncl-talk mailing list
>>>>>>> ncl-talk at ucar.edu
>>>>>>> List instructions, subscriber options, unsubscribe:
>>>>>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>>
>>>>>>>
>>>>>>> Associate Scientist,  Climate and Global Dynamics Laboratory, NCAR
>>>>>>>
>>>>>>> www.cgd.ucar.edu/staff/asphilli/   303-497-1726
>>>>>>> <%28303%29%20497-1726>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> _______________________________________________
>>>>>>> ncl-talk mailing list
>>>>>>> ncl-talk at ucar.edu
>>>>>>> List instructions, subscriber options, unsubscribe:
>>>>>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>>
>>>>>>>
>>>>>>> Associate Scientist,  Climate and Global Dynamics Laboratory, NCAR
>>>>>>>
>>>>>>> www.cgd.ucar.edu/staff/asphilli/   303-497-1726
>>>>>>> <%28303%29%20497-1726>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> _______________________________________________
>>>>>>> ncl-talk mailing list
>>>>>>> ncl-talk at ucar.edu
>>>>>>> List instructions, subscriber options, unsubscribe:
>>>>>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>>
>>>>>>>
>>>>>>> Associate Scientist,  Climate and Global Dynamics Laboratory, NCAR
>>>>>>>
>>>>>>> www.cgd.ucar.edu/staff/asphilli/   303-497-1726
>>>>>>> <%28303%29%20497-1726>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> _______________________________________________
>>>>>>> ncl-talk mailing list
>>>>>>> ncl-talk at ucar.edu
>>>>>>> List instructions, subscriber options, unsubscribe:
>>>>>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> _______________________________________________
>>>>>>> ncl-talk mailing list
>>>>>>> ncl-talk at ucar.edu
>>>>>>> List instructions, subscriber options, unsubscribe:
>>>>>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> _______________________________________________ ncl-talk mailing
>>>>>>> list ncl-talk at ucar.edu List instructions, subscriber options,
>>>>>>> unsubscribe: http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>>>>>
>>>>>>> _______________________________________________
>>>>>>> ncl-talk mailing list
>>>>>>> ncl-talk at ucar.edu
>>>>>>> List instructions, subscriber options, unsubscribe:
>>>>>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>>>>>
>>>>>>>
>>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> ncl-talk mailing list
>>>>> ncl-talk at ucar.edu
>>>>> List instructions, subscriber options, unsubscribe:
>>>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>>>
>>>>>
>>>>
>>>>
>>>> --
>>>> Associate Scientist,  Climate and Global Dynamics Laboratory, NCAR
>>>> www.cgd.ucar.edu/staff/asphilli/   303-497-1726 <%28303%29%20497-1726>
>>>>
>>>> <http://www.cgd.ucar.edu/staff/asphilli>
>>>>
>>>
>>>
>>> _______________________________________________
>>> ncl-talk mailing list
>>> ncl-talk at ucar.edu
>>> List instructions, subscriber options, unsubscribe:
>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20171001/a595f504/attachment.html>
```