Home > utilities > do_volume_change.m

do_volume_change

PURPOSE ^

DO_VOLUME_CHANGE Calculate volume of water which experiences a change in

SYNOPSIS ^

function [totalVolume] = do_volume_change(plotOPTS,FVCOM)

DESCRIPTION ^

 DO_VOLUME_CHANGE Calculate volume of water which experiences a change in
   pH beyond some defined threshold.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [totalVolume] = do_volume_change(plotOPTS,FVCOM)
0002 % DO_VOLUME_CHANGE Calculate volume of water which experiences a change in
0003 %   pH beyond some defined threshold.
0004 
0005 % Make a 3D array of the volumes to get to total volume which experiences
0006 % the change in pH.
0007 [nx,nz,ttot]=size(FVCOM.(plotOPTS.var_plot));
0008 
0009 % Get the time step (in seconds)
0010 dt=round((plotOPTS.Time_record(2)-plotOPTS.Time_record(1))*24*60*60);
0011 % Make sure we're actually able to sample at the rate requested.
0012 if plotOPTS.change_type~=0 && dt/(60*60)>plotOPTS.change_type
0013     error('Output file sampling frequency is coarser than specified time sampling.')
0014 end
0015 
0016 % Sigma layer fraction (nz*nz)
0017 sigThickness=roundn(abs(diff(FVCOM.siglev,1,2)),-5); % roundn to even values out.
0018 % Total depth (nz*ttot)
0019 totalDepth=repmat(FVCOM.h,1,size(FVCOM.zeta,2))+FVCOM.zeta;
0020 % Volume for every element for each time step
0021 cellVolume=nan(nx,nz,ttot);
0022 for ii=1:nz
0023     for jj=1:ttot
0024         cellVolume(:,ii,jj)=totalDepth(:,jj).*sigThickness(:,ii).*FVCOM.art1.*dt;
0025     end
0026 end
0027 
0028 if plotOPTS.change_type==0 || plotOPTS.change_type==dt/(60*60)
0029     % Instantaneous change (i.e. a change between outputs beyond a given value.
0030     phChange=diff(FVCOM.DYE,1,3);
0031     
0032     % Find the elements with the change beyond the threshold.
0033     idx=phChange<plotOPTS.threshold_change;
0034 
0035     % Using those indices, find the volume which is affected.
0036     totalVolume=sum(cellVolume(idx));
0037 else
0038     % The more complicated n-hour change.
0039     
0040     % Use the time period over which we're interested in to get an index
0041     % jump value.
0042     dtJump=(plotOPTS.change_type*60*60)/dt;
0043     if dtJump-round(dtJump)~=0
0044         error('Output sampling is not compatible with time period of change.')
0045     end
0046 
0047     phChange=nan(nx,nz,ttot-dtJump);
0048     for tt=1:length(plotOPTS.Time_record)
0049         if tt<=length(plotOPTS.Time_record)-dtJump
0050             phChange(:,:,tt)=(FVCOM.DYE(:,:,tt+dtJump)-FVCOM.DYE(:,:,tt));
0051         end
0052     end
0053     
0054     % Find the change values that happen for at least n-hours.
0055     % Probably best to look away now if you're interested in clean quick
0056     % code.
0057     totalVolume=0;
0058     for ii=1:nx
0059         for jj=1:nz
0060             totalVolumeCurrent=get_runs(plotOPTS,squeeze(phChange(ii,jj,:)),squeeze(cellVolume(ii,jj,:)),plotOPTS.change_type,plotOPTS.threshold_change);
0061             totalVolume=totalVolume+totalVolumeCurrent;
0062         end
0063     end
0064     
0065 end
0066 
0067 
0068 end

Generated on Thu 19-Mar-2015 12:20:56 by m2html © 2005