#!/bin/csh
# Download MODIS netCDF data
# Written by: Taylor Shropshire 
# date: 9/1/2021

# Parameters
setenv url https://oceandata.sci.gsfc.nasa.gov/ob/getfile/
setenv path1 /nexsan/people/taylor/postdoc/observations/MODIS/MODIS_chl/data/

# Year loop
#foreach year (2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020)
setenv year 2021

/bin/rm -rf ${path1}${year}
/bin/mkdir ${path1}${year}

setenv odir /nexsan/people/taylor/postdoc/observations/MODIS/MODIS_chl/data/${year}/
setenv day 1

# Day loop
while ($day<366)
setenv day_char `echo $day | awk '{printf("%03d", $1)}'`

setenv fname A${year}${day_char}.L3m_DAY_CHL_chlor_a_9km.nc
setenv in_file ${url}${fname}

setenv out_file1 ${odir}${fname}
setenv out_file2 ${odir}MODIS_chl_9km_daily_${year}_${day_char}.nc

echo $in_file 

# !!!!!!
# Note: You need to get your own username and pass from the oceandata website
# !!!!!
#
wget --user=USERNAME --password=PASS --auth-no-challenge=on ${in_file} -O ${out_file1}
#wget --no-check-certificate ${in_file} -O ${out_file1}

chmod 755 $out_file1
echo 'Processing file: '$out_file1
ncks -d lon,-102.,-70. -d lat,10.,50. $out_file1 $out_file2
/bin/rm $out_file1

setenv day `expr $day + 1`

end



