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

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

Hi Erik,

Do you have access to NCO (the netCDF Operators)? If so, you can
easily split files along the record dimension using the ncks
operator. As an example,

% ncks -d time,0,729 hgt.2006.nc hgt.2006-01.nc
% ncks -d time,730,1459 hgt.2006.nc hgt.2006-02.nc

I highly recommend NCO for easy manipulation of netcdf files... it
works great in tandem with NCL.

See here for more info:
http://nco.sourceforge.net/

Sincerely,
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:24:08 MDT

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