Re: Changing the name of a dimension in a variable

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Mon Apr 21 2014 - 20:43:24 MDT

Tabish,

I misunderstood about what kind of output you wanted.

The "addfiles" function only handles the leftmost dimension one of two ways: it either creates a new dimension that represents the number of files you are reading in (the "join" method), or it keeps the same number of dimension, but "grows" the leftmost dimension (usually "time") by the number of time steps in each file ("cat" method). The "cat" method is the default, so simply comment out the line:

> ListSetType (f, "join") ; concatenate (=default)

and I think you should be set. The leftmost dimension should also have the correct name, and, if was a properly defined coordinate array, it should have a new coordinate array.

--Mary

On Apr 20, 2014, at 6:26 AM, Tabish Ansari <tabishumaransari@gmail.com> wrote:

> Dear Mary
>
> Thank you very much for your mail.
>
> The above script works for me but there is a small issue.
> I wish to merge files having variables like (time|1, lev|1, lat|109, lon|99) to get new variables still with 4 dimensions wherein the time dimension increases to the no. of files. However, the above script outputs variables with 5 dimensions (ncl_join, time, lev, lat, lon).
>
> Now that I used a subset operation over that variable like:
>
> newvar= outputvar(:,0,:,:,:)
>
> newvar is now like (ncl_join, lev, lat, lon)
>
> Now my only aim is to rename the leftmost dimension "ncl_join" as "Time" and my purpose will be soved.
>
> Please suggest me a method to do that.
>
> Thanks
>
>
>
>
> On 19 April 2014 05:02, Mary Haley <haley@ucar.edu> wrote:
> Tabish,
>
> I believe you can simply use "addfiles" to open file1 through file10, read the the variables of interest, and then write them back out.
>
> Here's how it might look for one variable called "T".
> UNTESTED:
>
> ;---Get list of files and open them with one call
> filenames =systemfunc("ls -1 file*.nc" )
> f = addfiles(filenames,"r")
> ListSetType (f, "join") ; concatenate (=default)
>
> T = f[:]->T ; Read T off all files
> printVarSummary(T)
>
> ;---Open output file and write new variable
> system("rm -rf output.nc")
> fout = addfile("output.nc","c")
> fout->T = T
>
> This is just a rough script, and it writes the variable using the "inefficient" method. If you are going to be doing lots of variables, or really large variables, then you may want to write the file using the "efficient" method. See:
>
> http://www.ncl.ucar.edu/Applications/o-netcdf.shtml
>
> --Mary
>
> On Apr 17, 2014, at 1:56 PM, Tabish Ansari <tabishumaransari@gmail.com> wrote:
>
>> Hello
>>
>> I have a netcdf files (say file1 to file10) with some 3d array variables of the form varname(z,x,y).
>>
>> Now I want to create a new netcdf file (say newfile) with 4d arrays that will contain all the variables corresponding to file1 to file10. This will be of the form:
>>
>> varname(time,z,x,y)
>>
>> where varname(0,z,x,y) comes from file 1 varname(z,x,y)
>> varname(1,z,x,y) comes from file 2 varname(z,x,y)
>> varname(2,z,x,y) comes from file 3 varname(z,x,y)
>>
>> and so on...
>>
>>
>> ​For this I want to first declare a 4d array of the form:
>>
>> varname = new((/10,5,100,100/),float)
>>
>> but how do I assign this array to the newfile?​
>>
>> --
>> Thanks & Regards
>> Tabish Umar Ansari
>> MS Research Scholar
>> Environmental & Water Resources Engineering Division
>> Department of Civil Engineering
>> IIT Madras
>> _______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
>
>
> --
> Thanks & Regards
> Tabish Umar Ansari
> MS Research Scholar
> Environmental & Water Resources Engineering Division
> Department of Civil Engineering
> IIT Madras
> _______________________________________________
> 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 Apr 21 20:43:36 2014

This archive was generated by hypermail 2.1.8 : Tue Apr 29 2014 - 09:04:20 MDT