[MITgcm-support] How to join two nc files?

Baylor Fox-Kemper baylor at MIT.EDU
Tue Jun 6 09:25:01 EDT 2006


Hi there,
   Here is a little matlab script that reads state files.  It doesn't  
do anything fancy (e.g., cubed sphere), but it does allow to to see  
all tiles at one time snapshot.  You just decide what variable as var  
(e.g., 'U', 'V', etc)  and what time (in days).  It returns the  
variable as well as the day found and the location in space of the  
variable (xfound,yfound,zfound).
   Cheers,
   -Baylor

function [varout,dayfound,xfound,yfound,zfound]=tileopen(getday,var);

sdir=dir('state.*.nc');
t1dir=dir('state.*.t001.nc');
lg=1:(length(sdir)/length(t1dir));

% Time location
for getlength=1:(length(t1dir))
f=netcdf(t1dir(getlength).name);
if isempty(f), error([' ## Bad Netcdf File: ',t1dir 
(getlength).name]), end
daynow=f{'model_time',1}(:)/86400;
if length(daynow)==0
    daynow=f{'T',1}(:)/86400;
end
for ii=1:length(daynow)
    day(getlength,ii)=daynow(ii);
end
if (length(day(1,:))>length(daynow))
    day(getlength,(length(daynow)+1):end)=nan;
end
close(f)
end

[val,indx]=min(abs(day'-getday));
[dayfound,filenum]=min(val);
indx=indx(filenum);
dayfound=day(filenum,indx);

%Space Location

X=[];
Y=[];
varout=[];

for tile=lg
f=netcdf(sdir((filenum-1)*max(lg)+tile).name);

Varin=f{var}(indx,:,:,:);
thedims=dim(f{var});

Xin=f{name(thedims{4})}(:);
Yin=f{name(thedims{3})}(:);
zfound=f{name(thedims{2})}(:);

if length(find(X==Xin(end)))==0
   if length(find(X==Xin(1)))==0
    X=[X;Xin];
   else
    X=[X;Xin(2:end)];
   end
end
Xbeg=find(X==Xin(1));
Xend=find(X==Xin(end));

if length(find(Y==Yin(end)))==0
   if length(find(Y==Yin(1)))==0
    Y=[Y;Yin];
   else
    Y=[Y;Yin(2:end)];
   end
end
Ybeg=find(Y==Yin(1));
Yend=find(Y==Yin(end));

varout(1:length(zfound),Ybeg:Yend,Xbeg:Xend)=Varin;

close(f);
end

xfound=X;
yfound=Y;

% End function




On Jun 6, 2006, at 3:34 AM, Brainf wrote:

>
> Hi mitgcm,
>    One time have two nc files, like state.0000000000.t001.nc and  
> state.0000000000.t002.nc,
> useing ferret can see only one file, it is  difficult to use.
> How to join this two nc file to one file?
>
> I found a util 'joinds' in MITgcm\utils\scripts,
> Maybe it can do this work,
> so I type:
> $ ./joinds ./t1/state.0000000000.t001.nc ./t1/state.0000000000.t002.nc
>
> but it doesn't work and said " No dataset found.   "......
>
> How can I do?
>
> Best regards.
>
> Brainf
> brainf at 163.com
> 2006-06-06
>
>
> _______________________________________________
> MITgcm-support mailing list
> MITgcm-support at mitgcm.org
> http://mitgcm.org/mailman/listinfo/mitgcm-support




More information about the MITgcm-support mailing list