function makencWaves_ec_R5()

addpath /hpc/home/hpcops/Matlab/Toolbox/mexcdfnew/mexcdf/mexnc
addpath /hpc/home/hpcops/Matlab/Toolbox/mexcdfnew/mexcdf/snctools
addpath /hpc/home/hpcops/Matlab/Toolbox/mexcdf/netcdf_toolbox/netcdf/ncutility
addpath /hpc/home/hpcops/Matlab/Toolbox/mexcdf/netcdf_toolbox/netcdf/nctype
addpath /hpc/home/hpcops/Matlab/Toolbox/mexcdf/netcdf_toolbox/netcdf

addpath /hpc/home/hpcops/Matlab_Tools/nctoolbox/cdm/utilities
addpath /hpc/home/hpcops/Matlab_Tools/nctoolbox/cdm/utilities/graphics
addpath /hpc/home/hpcops/Matlab_Tools/nctoolbox/cdm/utilities/interp
addpath /hpc/home/hpcops/Matlab_Tools/nctoolbox/cdm/utilities/misc
addpath /hpc/home/hpcops/Matlab_Tools/nctoolbox/cdm/utilities/njcompatability
addpath /hpc/home/hpcops/Matlab_Tools/nctoolbox/cdm/utilities/search
addpath /hpc/home/hpcops/Matlab_Tools/nctoolbox/cdm/utilities/slicing
addpath /hpc/home/hpcops/Matlab_Tools/nctoolbox/cdm/utilities/sura_catalog
addpath /hpc/home/hpcops/Matlab_Tools/nctoolbox/cdm/utilities/units
addpath /hpc/home/hpcops/Matlab_Tools/nctoolbox/cdm/utilities/vis
addpath /hpc/home/hpcops/Matlab_Tools/nctoolbox/cdm
addpath /hpc/home/hpcops/Matlab_Tools/nctoolbox/java
addpath /hpc/home/hpcops/Matlab_Tools/nctoolbox
addpath /hpc/home/hpcops/Matlab/wavepackets
addpath /hpc/home/hpcops/Matlab/wavepackets/Inpaint_nans
addpath /hpc/home/hpcops/Matlab/read_grib.r3
addpath /hpc/home/hpcops/Matlab_Tools/nctoolbox

%Run this command to initialize nctools Toolbox - this was the fix 2/09/2012
setup_nctoolbox

Rollback =0;
%Find day of year
V = date;
datefix = '01-Jan-1970';
Nbase = datenum(datefix);
N = datenum(V) - Rollback;
Nhours = (N - Nbase)*24;

Day1 = datevec(datenum(date)-Rollback) %Find Day1's date 
%if month is 1-9 then add a leading 0 to string
Ayear = num2str(Day1(1));
if Day1(2)<10 
    Amonth=strcat('0',num2str(Day1(2)));
else
    Amonth=num2str(Day1(2));
end
%if day is 1-9 then add a leading 0 to string
if Day1(3)<10
    Aday=strcat('0',num2str(Day1(3)));
else
    Aday=num2str(Day1(3));
end

%loadwpa = '/export/lnx351/bdaniels/Matlab/Matfiles/WPAtest.mat';
%eval (['load ' loadwpa]);
%fileout = strcat('/export/lnx351/bdaniels/playprogs/MikeB/netcdf/Waves_',Ayear,Amonth,Aday,'f096.nc');

loadlat = '/hpc/home/hpcops/Matlab/Matfiles/latwpak.mat';
eval (['load ' loadlat]);

loadlon = '/hpc/home/hpcops/Matlab/Matfiles/lonwpak360.mat';
eval (['load ' loadlon]);
%clear;

%Forecast Loop
for F = 1:15
    forecast = (F-1)*12;
    fcast = num2str(forecast); 
if forecast < 10
	fileout = strcat('/hpc/home/hpcops/bodner/waves/packets/matlab/netcdf/Waves_EC_',Ayear,Amonth,Aday,'00f00',fcast,'.nc');
    u_file = strcat('/hpc/home/hpcops/bodner/waves/packets/matlab/grib/ecmwf_hr/ecmwf_hr_300_u_',Ayear,Amonth,Aday,'00f00',fcast,'.grib');
    v_file = strcat('/hpc/home/hpcops/bodner/waves/packets/matlab/grib/ecmwf_hr/ecmwf_hr_300_v_',Ayear,Amonth,Aday,'00f00',fcast,'.grib');
    meanU_file = strcat('/hpc/home/hpcops/bodner/waves/packets/15day_means/data_base/ecmwf_hr/grib/ecmwf_hr_mean_u_',Ayear,Amonth,Aday,'00f00',fcast,'.grib');
    meanV_file = strcat('/hpc/home/hpcops/bodner/waves/packets/15day_means/data_base/ecmwf_hr/grib/ecmwf_hr_mean_v_',Ayear,Amonth,Aday,'00f00',fcast,'.grib');
elseif forecast < 100
	fileout = strcat('/hpc/home/hpcops/bodner/waves/packets/matlab/netcdf/Waves_EC_',Ayear,Amonth,Aday,'00f0',fcast,'.nc');
    u_file = strcat('/hpc/home/hpcops/bodner/waves/packets/matlab/grib/ecmwf_hr/ecmwf_hr_300_u_',Ayear,Amonth,Aday,'00f0',fcast,'.grib');
    v_file = strcat('/hpc/home/hpcops/bodner/waves/packets/matlab/grib/ecmwf_hr/ecmwf_hr_300_v_',Ayear,Amonth,Aday,'00f0',fcast,'.grib');
    meanU_file = strcat('/hpc/home/hpcops/bodner/waves/packets/15day_means/data_base/ecmwf_hr/grib/ecmwf_hr_mean_u_',Ayear,Amonth,Aday,'00f0',fcast,'.grib');
    meanV_file = strcat('/hpc/home/hpcops/bodner/waves/packets/15day_means/data_base/ecmwf_hr/grib/ecmwf_hr_mean_v_',Ayear,Amonth,Aday,'00f0',fcast,'.grib');
else
    fileout = strcat('/hpc/home/hpcops/bodner/waves/packets/matlab/netcdf/Waves_EC_',Ayear,Amonth,Aday,'00f',fcast,'.nc');
    u_file = strcat('/hpc/home/hpcops/bodner/waves/packets/matlab/grib/ecmwf_hr/ecmwf_hr_300_u_',Ayear,Amonth,Aday,'00f',fcast,'.grib');
    v_file = strcat('/hpc/home/hpcops/bodner/waves/packets/matlab/grib/ecmwf_hr/ecmwf_hr_300_v_',Ayear,Amonth,Aday,'00f',fcast,'.grib');
    meanU_file = strcat('/hpc/home/hpcops/bodner/waves/packets/15day_means/data_base/ecmwf_hr/grib/ecmwf_hr_mean_u_',Ayear,Amonth,Aday,'00f',fcast,'.grib');
    meanV_file = strcat('/hpc/home/hpcops/bodner/waves/packets/15day_means/data_base/ecmwf_hr/grib/ecmwf_hr_mean_v_',Ayear,Amonth,Aday,'00f',fcast,'.grib');
end


ncin = ncgeodataset(u_file);

gvar = ncin.geovariable('u_wind');
ugrddata = double(squeeze(gvar.data(:)));
ugrddata = inpaint_nans(ugrddata);

ncin = ncgeodataset(v_file);
gvar = ncin.geovariable('v_wind');
vgrddata = double(squeeze(gvar.data(:)));
vgrddata = inpaint_nans(vgrddata);

ncmean = ncgeodataset(meanU_file);
gvar = ncmean.geovariable('u_wind');
meanUdatainit = double(squeeze(gvar.data(:)));
meanUdata = inpaint_nans(meanUdatainit);

ncmean = ncgeodataset(meanV_file);
gvar = ncmean.geovariable('v_wind');
meanVdata = double(squeeze(gvar.data(:)));
meanVdata = inpaint_nans(meanVdata);

vgrddata = flipdim(vgrddata,1);
meanVdata = flipdim(meanVdata,1);
meanUdata = flipdim(meanUdata,1);


WPA = amplitude_wigner_mex_1d_new((vgrddata(:,:,1)-meanVdata(:,:,1)),meanVdata(:,:,1),meanUdatainit(:,:,1),73,144);

warning off

%% Create new reduce:d NetCDF file
nc = netcdf(fileout, 'clobber');
 
%% Global attributes:
 
nc.classification_level = 'UNCLASSIFIED\0\0\0\0\0\0\0\0';
%nc.distribution_statement = 'Approved for public release. Distribution unlimited.';
%nc.downgrade_date = 'not applicable';
%nc.classification_authority = 'not applicable';
nc.institution = 'NOAA/NCEP';
nc.contact = 'NOAA/NCEP/HPC, Mike Bodner';
nc.history = strcat('created on ',Ayear,Amonth,Aday);
%nc.generating_model = 'Global NCOM with OSU tides';
nc.operational_status = 'development';
%nc.model_type = 'x-curvilinear lon, y-curvilinear lat, z-sigma_z';
%nc.input_data_source = 'FNMOC NOGAPS, NAVO MODAS, NAVO NLOM';
nc.Conventions = 'netcdf_v1.0';
%nc.message = 'UNCLASSIFIED';
%nc.reference = 'https://www.navo.navy.mil/';
nc.comment = '...';
nc.time_origin = strcat(Ayear,Amonth,Aday,' 00:00:00');
%nc.FillValue_=-30000;
 
%% Dimensions:
 
nc('lat') = 73;
nc('lon') = 144;
%nc('level') = 300;
nc('time') = 1; %% (record dimension)
%nc('tau') = 25;

%% Variables and attributes:
 
nc{'lat'} = ncdouble('lat'); %% 144 elements.
nc{'lat'}.long_name = 'Latitude';
nc{'lat'}.units = 'degrees_north';
nc{'lat'}.NAVO_code = nclong(1);
 
nc{'lon'} = ncdouble('lon'); %% 73 elements.
nc{'lon'}.long_name = 'Longitude';
nc{'lon'}.units = 'degrees_east';
nc{'lon'}.NAVO_code = nclong(2);
 
%nc{'level'} = ncdouble('level'); %% 1 element.
%nc{'level'}.long_name = 'Height';
%nc{'level'}.units = 'milibars';
%nc{'level'}.NAVO_code = nclong(5);
%nc{'level'}.positive = 'up';
 
nc{'time'} = ncdouble('time'); %% 25 elements.
nc{'time'}.long_name = 'Valid Time';
nc{'time'}.units = 'hour since 1970-01-01 00:00:00';
nc{'time'}.NAVO_code = nclong(13);
nc{'time'}.time_origin = '00-01-01 00:00:00\0\0\0\0\0\0\0\0\0\0\0\0\0';
 
%nc{'tau'} = ncdouble('time'); %% 25 elements.
%nc{'tau'}.long_name = 'Tau';
%nc{'tau'}.units = 'hours since analysis';
%nc{'tau'}.NAVO_code = nclong(56);
%nc{'tau'}.time_origin = '2008-06-03 00:00:00             ';
 
nc{'wpak'} = ncfloat('time','lat', 'lon'); %% 97128000 elements.
nc{'wpak'}.long_name = 'WPA Amplitude';
nc{'wpak'}.units = 'WPA units';
nc{'wpak'}.NAVO_code = nclong(17);
nc{'wpak'}.FillValue_ = ncshort(-9999);
nc{'wpak'}.missing_value = ncshort(-9999);
%nc{'water_u'}.scale_factor = ncfloat(0.00100000004749745);
nc{'wpak'}.add_offset = ncfloat(0);

%Redefine and write variables to file

nc{'lat'}(:,:) = latwpak; 
nc{'lon'}(:,:) = lonwpak;
nc{'time'}(:,:) = Nhours; 
%nc{'tau'}(:,:) = fcast;
%nc{'level'}(:,:) = 300;
nc{'wpak'}(:,:) = WPA; 
endef(nc)
close(nc)


end
return
