Re: how do I split one .nc file into two

From: Ryan L. Sriver <rsriver_at_nyahnyahspammersnyahnyah>
Date: Tue, 31 Jul 2007 22:40:09 -0400

Hi again Erik,

To answer your question using ncl, you could do something like the
following:

a=addfile("./hgt.2006.nc","r")
hgt=a->hgt
time=a->time

ntimes=dimsizes(time)
split=dimsizes(time)/2

hgt_1=hgt(0:split-1,:,:,:)
hgt_2=hgt(split:ntimes-1,:,:,:)

ncdf_out_1=addfile("hgt.2006-1.nc","c")
ncdf_out_2=addfile("hgt.2006-2.nc","c")

ncdf_out_1->hgt_1=hgt_1
ncdf_out_2->hgt_1=hgt_2

Hope that helps,
Ryan Sriver

On Jul 31, 2007, at 9:53 PM, Erik Noble wrote:

> Hi.
> Simple question:
> How do I split in half a necdf file with one varible and write out 2
> separate files?
> The variable has 1460 time steps
> time = UNLIMITED ; // (1460 currently)
> hgt(time, level, lat, lon)
>
> What do I need to change here? Is this too much? :
>
> begin
> ;***********************************************
> ;read in netcdf file
> ;***********************************************
> a = addfile("./hgt.2006.nc","r")
> ncdf_out = addfile("hgt.2006-1.nc" ,"c") ; create output
> netCDF file
> ncdf_out2 = addfile("hgt.2006-2.nc" ,"c") ; create 2nd output
> netCDF file
> names = getfilevarnames(a)
>
> time = getvarnames(time)
> ntimes = dimsizes(time)
> Split = (ntimes-1)/2
>
> do i=0. Split
> ncdf_out->$names(i)$ = a->$names(i)$
> end do
>
> do i=Split, ntimes-1
> ncdf_out2->$names(i)$ = a->$names(i)$
> end do
> end
>
> Thank you ahead of time.
> Sincerely,
> Erik
> _______________________________________________
> ncl-talk mailing list
> ncl-talk_at_ucar.edu
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

Ryan Sriver
Ph.D. Candidate
Department of Earth and Atmospheric Sciences
Purdue University
http://web.ics.purdue.edu/~rsriver

_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Tue Jul 31 2007 - 20:40:09 MDT

This archive was generated by hypermail 2.2.0 : Mon Aug 06 2007 - 08:08:45 MDT