# (C) Copyright 2005- ECMWF.

flags[1] scanningMode 'grib2/tables/[tablesVersion]/3.4.table' : edition_specific,no_copy ;

# Note our flagbit numbers go from 7 to 0, while WMO convention is from 1 to 8
flagbit iScansNegatively(scanningMode,7) : dump;   # WMO bit 1
flagbit jScansPositively(scanningMode,6) : dump;   # WMO bit 2
flagbit jPointsAreConsecutive(scanningMode,5) : dump;
flagbit alternativeRowScanning(scanningMode,4) = 0 : edition_specific,dump;
alias alternateRowScanning = alternativeRowScanning;

if (jPointsAreConsecutive) {
    alias numberOfRows=Ni;
    alias numberOfColumns=Nj;
} else {
    alias numberOfRows=Nj;
    alias numberOfColumns=Ni;
}

alias geography.iScansNegatively=iScansNegatively;
alias geography.jScansPositively=jScansPositively;
alias geography.jPointsAreConsecutive=jPointsAreConsecutive;

transient iScansPositively = !iScansNegatively : constraint, read_only;
transient jScansNegatively = !jScansPositively : constraint, read_only;

# The following modes are not yet supported
flagbit scanningMode5(scanningMode,3) = 0: read_only; #Points within odd rows...
flagbit scanningMode6(scanningMode,2) = 0: read_only; #Points within even rows...
flagbit scanningMode7(scanningMode,1) = 0: read_only; #Points offset
flagbit scanningMode8(scanningMode,0) = 0: read_only; #Rows have Ni grid points...

meta swapScanningX change_scanning_direction(
    values,Ni,Nj,
    iScansNegatively,jScansPositively,
    xFirst,xLast,x) : edition_specific,hidden,no_copy;
alias swapScanningLon = swapScanningX;

meta swapScanningY change_scanning_direction(
    values,Ni,Nj,
    iScansNegatively,jScansPositively,
    yFirst,yLast,y) : edition_specific,hidden,no_copy;
alias swapScanningLat = swapScanningY;

meta swapScanningAlternativeRows change_alternative_row_scanning(
    values, Ni, Nj, alternativeRowScanning): edition_specific,hidden,no_copy;
