Not logged inOcean Color Forum

The forum is locked.

The Ocean Color Forum has transitioned over to the Earthdata Forum (https://forum.earthdata.nasa.gov/). The information existing below will be retained for historical reference. Please sign into the Earthdata Forum for active user support.

Up Topic Products and Algorithms / Satellite Data Access / "Find swaths" with scripts
- By cfontana Date 2018-10-30 01:23 Edited 2018-10-30 02:14
Hi,

I would like to know if there's a way to find MODIS swaths for a given area automatically in a script, just like the "Find swaths" button does.
Is it possible actually ?

Many thanks
- By norman Date 2018-10-30 14:21 Edited 2018-10-30 14:25
Hi,

The browse code was not explicitly set up for this, but it is possible with a little
parsing of the html that the browser sends back.  If you are using bash or a similar
shell, the following example will download Aqua/MODIS level-2 files that cover
the Argentine Sea in 2018.

url=https://oceancolor.gsfc.nasa.gov/cgi/browse.pl

wget -qO - \
$url'?sub=level1or2list&sen=am&per=YR&day=17532&n=-40&s=-54&w=-70&e=-54&dnm=D' \
| perl -n -0777 \
       -e 'if(/filenamelist&id=(\d+\.\d+)/){' \
       -e 'print `wget "'$url'?sub=filenamelist&id=$1&prm=CHL" -qO -`;' \
       -e '}' \
       -e 'elsif(/(A\d+\.L2_LAC_OC.nc)/){' \
       -e 'print "$1\n";' \
       -e '}' \
| wget -B https://oceandata.sci.gsfc.nasa.gov/cgi/getfile/ \
--content-disposition -i -

There was a forum discussion on this topic some years ago.
https://oceancolor.gsfc.nasa.gov/forum/oceancolor/topic_show.pl?pid=19165

Regards,
Norman
- By cfontana Date 2018-10-30 17:07
Hi,

Thank you very much. I'm going to try this.

Best,

Clément
- By cfontana Date 2018-10-30 19:10
I have some issues using wget with oceancolor server.
So here's a quick and dirty way to do the same with shell and curl.

--------------------------------------------------------------------------
url='https://oceancolor.gsfc.nasa.gov/cgi/browse.pl'
curl -o "curl.dat" -s -L -O \
$url'?sub=level1or2list&sen=v0&per=DAY&day=15400&n=-49&s=-51&w=70&e=73' \
| perl -n -0777 \
       -e 'if(/filenamelist&id=(\d+\.\d+)/){' \
       -e 'print `wget "'$url'?sub=filenamelist&id=$1&prm=CHL" -qO -`;' \
       -e '}' \
       -e 'elsif(/(V\d+\.L2_NPP_OC)/){' \
       -e 'print "$1\n";' \
       -e '}' \

cat curl.dat | grep colspan | grep file | sed -e s/"&"/" "/g  >tmp.dat
rm list.dat

# Loop on lines
while l= read -r line ;do
   # Loop on words
   for w in $line;do

      # Search "file" keyword
      echo `echo $w | sed -e s/'\='/' '/` | read args
      if [ `echo $args | awk '{print $1}'` == "file" ];then
   echo `echo $args | awk '{print $2}'` >> list.dat
      fi
   done
  
done <"tmp.dat"

rm curl.dat
rm tmp.dat

cat list.dat 
-------------------------------------------

Output :

V2012061190600.L2_SNPP_OC_CHLOR_A_BRS
V2012061105400.L2_SNPP_OC_CHLOR_A_BRS
V2012061190600.L2_SNPP_OC_CHLOR_A_BRS
V2012061110000.L2_SNPP_OC_CHLOR_A_BRS
V2012061105400.L2_SNPP_OC_CHLOR_A_BRS
V2012061091800.L2_SNPP_OC_CHLOR_A_BRS
V2012061110000.L2_SNPP_OC_CHLOR_A_BRS
V2012061091800.L2_SNPP_OC_CHLOR_A_BRS

Best,
- By norman Date 2018-10-30 19:42
Note that, in your version, you could leave out the pipe to perl since you
direct your output to a file (curl.dat), and there is nothing for the perl command
to parse.

Note also that, instead of downloading files, your version is producing a list
of browse file names.  (We do not actually distribute any of our level-1 or level-2
browse files.  They are for internal use only).

Nevertheless, as the Perl motto says, "TMTOWTDI".   :-)

Best,
Norman
Up Topic Products and Algorithms / Satellite Data Access / "Find swaths" with scripts

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill