## Copyright (C) 2016 - Alex Provan
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program. If not, see <http://www.gnu.org/licenses/>.

## Author: 	Alex Prova <yourmail@mail>

## -*- texinfo -*-
## @defun {Function File} {[@var{lat}, @var{lon}] =} polyjoin (@var{latcells}, @var{loncells})
## Convert polygons or lines from cell array format to column vector form.
##
## Input: latitundinal cell array and longitudinal cell array.
##
## Output: latitudinal column vector and longitudinal column vector.
##
## Both in cell array format, each cell is a vector definition of a polygon.
##
## @seealso{polysplit}
## @end defun

function [lat, lon] = polyjoin (latcells, loncells)

  %checks to make sure there are two arguments
  if (nargin ~= 2)
    error ('Incorrect number of inputs')
  endif

  %checks to make sure all of the inputs are of type cell
  if (~iscell (latcells) | ~iscell (loncells))
    error ('Octave:invalid-input-arg','Both latcells and loncells must be of cell type')
  endif

  %checks to make sure that each of the inputs have contents in them
  if (isempty (latcells) | isempty (loncells))
      error ('Octave:invalid-input-arg', 'Inputted cells must not be empty')
  endif

  %copies the first vector to lat and lon
  lat = latcells{:};
  lon = loncells{:};

  %loop throug the cell array and expand the lat and lon vectors. placing NaN inbetween faces.
  for i = 2:length(latcells)
    lat = [lat; NaN; latcells{i}];
    lon = [lon; NaN; loncells{i}];
  endfor

endfunction
