Re: Assign array to a new file: merging several 3d arrays into a 4d array

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Fri Apr 18 2014 - 17:32:30 MDT

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

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Fri Apr 18 17:32:40 2014

This archive was generated by hypermail 2.1.8 : Fri Apr 18 2014 - 17:37:58 MDT