Re: how to change dimension name

From: 朱学明 <557xiaozhu_at_nyahnyahspammersnyahnyah>
Date: Mon Dec 16 2013 - 09:26:45 MST

Hi Mary,
   I have tested it. It works for me now.
   But I found that I can not create and use a new variable like as follow, or it will get an error.
My orginal nc file like this,
$ ncdump.exe -h ecs_new_zeta_climatology.nc
netcdf ecs_new_zeta_climatology {
dimensions:
        one = 1 ;
        xi_rho = 564 ;
        eta_rho = 565 ;
variables:
        float zeta_avg(eta_rho, xi_rho) ;
                zeta_avg:long_name = "climtology free-surface" ;
                zeta_avg:units = "meter" ;
                zeta_avg:coordinates = "lat_rho lon_rho" ;
                zeta_avg:field = "free-surface, scalar, series" ;
                zeta_avg:_FillValue = 1.e+37f ;
}

Once I run the coomands as follow,

ncl 7> a=addfile("ecs_new_zeta_climatology.nc","w")
ncl 8> tt=a->zeta_avg
ncl 9> tt!0="eta_rhoqq"
ncl 10> tt!1="xi_rhosss"
ncl 11> a->zeta_avg=tt
warning:Dimension names of left hand side and right hand side do not match, overwriting dimension (eta_rho), use (/ .. /) if this is not the desired result
ncdimrename: ncid 131072: NetCDF: String match to name in use
fatal:Could not change dimension (2) to (eta_rhoqq) for file (ecs_new_zeta_climatology)
warning:Dimension names of left hand side and right hand side do not match, overwriting dimension (xi_rho), use (/ .. /) if this is not the desired result
ncdimrename: ncid 131072: NetCDF: String match to name in use
fatal:Could not change dimension (1) to (xi_rhosss) for file (ecs_new_zeta_climatology)

The new file will be as follow,

$ ncdump.exe -h ecs_new_zeta_climatology.nc
netcdf ecs_new_zeta_climatology {
dimensions:
        one = 1 ;
        xi_rho = 564 ;
        eta_rho = 565 ;
        eta_rhoqq = 565 ;
        xi_rhosss = 564 ;
variables:
        float zeta_avg(eta_rho, xi_rho) ;
                zeta_avg:long_name = "climtology free-surface" ;
                zeta_avg:units = "meter" ;
                zeta_avg:coordinates = "lat_rho lon_rho" ;
                zeta_avg:field = "free-surface, scalar, series" ;
                zeta_avg:_FillValue = 1.e+37f ;
}

It looks like that we could not use any new variable. Do you know the reason? Thanks.

2013-12-17



Xueming Zhu 朱学明
Key Laboratory of Research on Marine Hazards Forecasting (LoMF), SOA
National Marine Environmental Forecasting Center (NMEFC)
No.8, Dahuisi Road, Haidian District, Beijing, 100081
People's Republic of China
Tel:+86-10-82481923



发件人:Mary Haley <haley@ucar.edu>
发送时间:2013-12-16 23:32
主题:Re: Re: [ncl-talk] how to change dimension name
收件人:"朱学明"<557xiaozhu@163.com>
抄送:"ncl-talk@ucar.edu USERS"<ncl-talk@ucar.edu>


You can operate on the variable file directly, by using the "w" option to addfile:

a = addfile("example.nc","w")
a->T!0 = "time"
a->T!1 = "lat"
etcetera

When you do this, it will operate on the file directly, and you can't undo the changes, so be very careful about this.
This will also cause all other variables on that file with the same named dimensions to be changed.

You should make a copy of your file before you do this kind of change.

You may also want to consider using a separate package for this kind of thing, if you need to do this for a lot of files.
See the "ncrename" utility that comes with the NetCDF operators:

http://nco.sourceforge.net/nco.html#ncrename-netCDF-Renamer


--Mary



On Dec 14, 2013, at 9:28 PM, 朱学明 <557xiaozhu@163.com> wrote:

> Hello Mary,
> Thanks for your reply.
> I know that "!" symbol just can change the variable's dimension name.
> But I want to change the dimension's name in the nc file. So what you mentioned may not make sense to me.
>
> Do you have any other suggestion still? Thanks.
>
> 2013-12-15
> Xueming Zhu 朱学明
> Key Laboratory of Research on Marine Hazards Forecasting (LoMF), SOA
> National Marine Environmental Forecasting Center (NMEFC)
> No.8, Dahuisi Road, Haidian District, Beijing, 100081
> People's Republic of China
> Tel:+86-10-82481923
> 发件人:Mary Haley <haley@ucar.edu>
> 发送时间:2013-12-14 00:49
> 主题:Re: [ncl-talk] how to change dimension name
> 收件人:"朱学明"<557xiaozhu@163.com>
> 抄送:"ncl-talk@ucar.edu USERS"<ncl-talk@ucar.edu>
>
>
> On Dec 12, 2013, at 1:03 PM, 朱学明 <557xiaozhu@163.com> wrote:
>
> > Hello all,
> > Anyone knows how can I change a nc file's dimension name?
>
> Use the "!" symbol.
>
> For example, if you read variable "T" off a NetCDF (or HDF, GRIB) file, and it has dimension names "TIME", "LATITUDE", and "LONGITUDE" (in that order), you can change them with:
>
> T!0 = "time"
> T!1 = "lat"
> T!2 = "lon"
>
> For more information, see the NCL Reference Manual:
>
> http://www.ncl.ucar.edu/Document/Manuals/Ref_Manual/NclVariables.shtml#Dimensions
>
> --Mary
>
> >
> > Thanks.
> >
> > 2013-12-13
> > Xueming Zhu 朱学明
> > Key Laboratory of Research on Marine Hazards Forecasting (LoMF), SOA
> > National Marine Environmental Forecasting Center (NMEFC)
> > No.8, Dahuisi Road, Haidian District, Beijing, 100081
> > People's Republic of China
> > Tel:+86-10-82481923
> > _______________________________________________
> > ncl-talk mailing list
> > List instructions, subscriber options, unsubscribe:
> > http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Dec 16 09:27:11 2013

This archive was generated by hypermail 2.1.8 : Wed Dec 18 2013 - 14:29:51 MST