#!/bin/sh
#-------------------------------------------------------------------------
# Bourne shell script to derive sea ice concentration data for a
# rectilinear grid whose cells measure two degrees of latitude by two
# degrees of longitude.
#
# The procedure is to use a list of the geographic coordinates of the grid
# cell centers as the request file for the program u_rtrv.  The result is
# a table where each row is a grid cell, and columns 3 through 14
# represent the ice concentration profile for each grid cell (columns 1
# and 2 reiterate the grid cell coordinates).
#
# Using the UNIX cut command, the columns themselves are isolated in
# separate files, and the program table.c is used to rearrange each column
# into a tab-delimited ASCII table suitable for entry into a spreadsheet.
#
# Peter N. Schweitzer (U.S. Geological Survey, Reston, VA 22092)
#-------------------------------------------------------------------------
#
# Set the values of the following variables to the full names of the
# directories containing the appropriate files

# BIN contains the (compiled) executable version of topo.c

BIN=/var/ftp/pub/data/sea_ice/bin

# SRC is the directory that contains the list of composite monthly average
# sea-ice concentration data files.

SRC=/var/ftp/pub/data/sea_ice/Derived/unix

# DST is the directory whose subdirectories will contain the results

DST=/var/ftp/pub/data/sea_ice/Derived/grids

#-------------------------------------------------------------------------
#- NORTHERN HEMISPHERE ---------------------------------------------------
#-------------------------------------------------------------------------

cd $SRC
$BIN/u_rtrv -v \
	-i n \
	-r $DST/north/grid_n.2x2 \
	-o $DST/north/arctic.2x2

cut -f3  $DST/north/arctic.2x2 >$DST/north/jan
cut -f4  $DST/north/arctic.2x2 >$DST/north/feb
cut -f5  $DST/north/arctic.2x2 >$DST/north/mar
cut -f6  $DST/north/arctic.2x2 >$DST/north/apr
cut -f7  $DST/north/arctic.2x2 >$DST/north/may
cut -f8  $DST/north/arctic.2x2 >$DST/north/jun
cut -f9  $DST/north/arctic.2x2 >$DST/north/jul
cut -f10 $DST/north/arctic.2x2 >$DST/north/aug
cut -f11 $DST/north/arctic.2x2 >$DST/north/sep
cut -f12 $DST/north/arctic.2x2 >$DST/north/oct
cut -f13 $DST/north/arctic.2x2 >$DST/north/nov
cut -f14 $DST/north/arctic.2x2 >$DST/north/dec

for M in jan feb mar apr may jun jul aug sep oct nov dec
do
	$BIN/table $DST/north/$M >$DST/north/$M.tab
	done

#-------------------------------------------------------------------------
#- SOUTHERN HEMISPHERE ---------------------------------------------------
#-------------------------------------------------------------------------

$BIN/u_rtrv -v \
	-i $SRC/s \
	-r $DST/south/grid_s.2x2 \
	-o $DST/south/antarct.2x2

cut -f3  $DST/south/antarct.2x2 >$DST/south/jan
cut -f4  $DST/south/antarct.2x2 >$DST/south/feb
cut -f5  $DST/south/antarct.2x2 >$DST/south/mar
cut -f6  $DST/south/antarct.2x2 >$DST/south/apr
cut -f7  $DST/south/antarct.2x2 >$DST/south/may
cut -f8  $DST/south/antarct.2x2 >$DST/south/jun
cut -f9  $DST/south/antarct.2x2 >$DST/south/jul
cut -f10 $DST/south/antarct.2x2 >$DST/south/aug
cut -f11 $DST/south/antarct.2x2 >$DST/south/sep
cut -f12 $DST/south/antarct.2x2 >$DST/south/oct
cut -f13 $DST/south/antarct.2x2 >$DST/south/nov
cut -f14 $DST/south/antarct.2x2 >$DST/south/dec

for M in jan feb mar apr may jun jul aug sep oct nov dec
do
	$BIN/table $DST/south/$M >$DST/south/$M.tab
	done

#-------------------------------------------------------------------------