# Copyright 2005-2018 ECMWF.
#
# This software is licensed under the terms of the Apache Licence Version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
# 
# In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
# virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
#


unsigned[2] Ni  : can_be_missing,dump;
alias numberOfPointsAlongAParallel=Ni;
alias Nx = Ni;

unsigned[2] Nj : can_be_missing,dump;
alias numberOfPointsAlongAMeridian=Nj;
alias Ny = Nj;

# Latitudes and Longitudes of the first and the last points
# Resolution and component flags
include "grib1/grid_first_last_resandcomp.def";

unsigned[2] iDirectionIncrement : can_be_missing, edition_specific;
unsigned[2] jDirectionIncrement : can_be_missing, edition_specific;
alias Dj = jDirectionIncrement;
alias Dy = jDirectionIncrement;
alias Di = iDirectionIncrement;
alias Dx = iDirectionIncrement;

include "grib1/scanning_mode.def";

meta  geography.jDirectionIncrementInDegrees latlon_increment(ijDirectionIncrementGiven,jDirectionIncrement,
  jScansPositively,
  latitudeOfFirstGridPointInDegrees,latitudeOfLastGridPointInDegrees,
  numberOfPointsAlongAMeridian,oneConstant,grib1divider,0) : can_be_missing,dump;

alias DjInDegrees=jDirectionIncrementInDegrees;
alias DyInDegrees=jDirectionIncrementInDegrees;

meta  geography.iDirectionIncrementInDegrees latlon_increment(ijDirectionIncrementGiven,iDirectionIncrement,
  iScansPositively,
  longitudeOfFirstGridPointInDegrees,longitudeOfLastGridPointInDegrees,
  Ni,oneConstant,grib1divider,1) : can_be_missing,dump;
alias DiInDegrees=iDirectionIncrementInDegrees;
alias DxInDegrees=iDirectionIncrementInDegrees;

meta numberOfDataPoints number_of_points(Ni,Nj,PLPresent,pl) : dump;
alias numberOfPoints=numberOfDataPoints;
meta numberOfValues number_of_values(values,bitsPerValue,numberOfDataPoints,
                            bitmapPresent,bitmap,numberOfCodedValues) : dump;
#alias ls.valuesCount=numberOfValues;

if(missing(Ni)){
   iterator latlon_reduced(numberOfPoints,missingValue,values,
        latitudeFirstInDegrees,longitudeFirstInDegrees,
        latitudeLastInDegrees,longitudeLastInDegrees,
      Nj,DjInDegrees,pl);
   nearest latlon_reduced(values,radius,Nj,pl,longitudeFirstInDegrees,longitudeLastInDegrees);
} else {
   iterator latlon(numberOfPoints,missingValue,values,longitudeFirstInDegrees,
                   DiInDegrees ,Ni,Nj,iScansNegatively ,
                   latitudeFirstInDegrees,DjInDegrees,jScansPositively,jPointsAreConsecutive);
   nearest regular(values,radius,Ni,Nj);
}


meta latLonValues latlonvalues(values);
alias latitudeLongitudeValues=latLonValues;
meta latitudes latitudes(values,0);
meta longitudes longitudes(values,0);
meta distinctLatitudes latitudes(values,1);
meta distinctLongitudes longitudes(values,1);

