function OK = convertCoordinates_test_germany(varargin)
%CONVERTCOORDINATES_TEST_GERMANY  official test for 125 german points
%
%    OK = convertCoordinates_test_germany(<EPSG>)
%
%  x   is accurate to 3 m
%  y   is accurate to 2 m
%  lon is accurate to 0.0018 deg
%  lat is accurate to 0.0017 deg
%
%See also: convert_coordinates

   if nargin==1
   EPSG = varargin{1};
   else
   EPSG = load('EPSG');
   end
   
   OPT.disp = 0;

%% do test data preparations, downloaded manuyally from 
%  http://crs.bkg.bund.de/crseu/crs/descrtrans/BeTA/de_dhdn2etrs_beta.php

   D = csv2struct('BETA2007testdaten.csv');
   
   D.CS1.code = D.Quell_Bezugssystem;
   D.CS2.code = D.Ziel_Bezugssystem;
   
   D.CS1.code = strrep(D.CS1.code,'DE_DHDN_3GK2'   ,'31466'); % [~,~]=convertCoordinates(0,0,'CS1.name','DHD','CS2.code',[])
   D.CS1.code = strrep(D.CS1.code,'DE_DHDN_3GK3'   ,'31467');
   D.CS1.code = strrep(D.CS1.code,'DE_DHDN_3GK4'   ,'31468');
   D.CS1.code = strrep(D.CS1.code,'DE_DHDN_3GK5'   ,'31469');
   D.CS1.code = strrep(D.CS1.code,'DE_DHDN_Lat-Lon', '4258'); % [~,~]=convertCoordinates(0,0,'CS1.name','etrs','CS1.type','geographic','CS2.code',[])
   
   D.CS2.code = strrep(D.CS2.code,'ETRS89_Lat-Lon' , '4326'); % [~,~]=convertCoordinates(0,0,'CS1.name','wgs','CS1.type','geographic','CS2.code',[])
   D.CS2.code = strrep(D.CS2.code,'ETRS89_UTM32'   ,'25832'); % [~,~]=convertCoordinates(0,0,'CS1.name','32','CS2.code',[])
   D.CS2.code = strrep(D.CS2.code,'ETRS89_UTM33'   ,'25833'); % [~,~]=convertCoordinates(0,0,'CS1.name','33','CS2.code',[])
   
%% do conversions

   n = length(D.Pkt_Nr_);
   for i=1:n
     [D.CS2.x(i),D.CS2.y(i),logs]=convertCoordinates(D.Quell_X(i),D.Quell_Y(i),EPSG,'CS1.code',D.CS1.code{i},'CS2.code',D.CS2.code{i});
      D.CS2.type{i} = logs.CS2.type;
      if strcmpi(D.CS2.type{i},'projected')
         D.CS2.cartesian(i) = 1==1;
      else
         D.CS2.cartesian(i) = 1==0;
      end
   end
   
   D.CS2.dx = D.Ziel_X - D.CS2.x(:);
   D.CS2.dy = D.Ziel_Y - D.CS2.y(:);

%% disp

   if OPT.disp
   for i=1:length(D.Pkt_Nr_)

     if D.CS2.cartesian(i)
       fmtx= '%-8.1f    ';unit = ' [deg]';
       fmty= '%-8.1f    ';unit = ' [deg]';
     else
       fmtx = '%-10.6f  ';unit = ' [m]';
       fmty = '%-11.6f  ';unit = ' [m]';
     end

     fprintf(1,fmtx,D.CS2.x(i) );
     fprintf(1,fmtx,D.Ziel_X(i));
     fprintf(1,fmtx,D.CS2.dx(i));
     
     fprintf(1,fmty,D.CS2.y(i) );
     fprintf(1,fmty,D.Ziel_Y(i));
     fprintf(1,fmty,D.CS2.dy(i));
     fprintf(1,'%s\n',unit);

   end     
   end

%% disp

OK(1) = max(abs(D.CS2.dx( D.CS2.cartesian))) < 2; % [m] 1.76
OK(2) = max(abs(D.CS2.dy( D.CS2.cartesian))) < 3; % [m] 2.12

OK(3) = max(abs(D.CS2.dx(~D.CS2.cartesian))) < 0.002; % [m] 0.0018
OK(4) = max(abs(D.CS2.dy(~D.CS2.cartesian))) < 0.002; % [m] 0.0017

OK  = all(OK);

