El programa dbm2ozi es para poder intercambiar datos entre los programas AVIAdbm y el Oziexplorer u otro similar que
permita la importacin y exportacin en formato wpt de Oziexplorer.

Con ellos se pueden realizar las siguientes operaciones:


INT OZIEXPLORER <---> AVIADBM INT
VOR OZIEXPLORER <---> AVIADBM VOR
NDB OZIEXPLORER <---> AVIADBM NDB
APT OZIEXPLORER <---> AVIADBM APT

Y todo a la vez en uno de los sentidos, el programa dbm2ozi analiza el fichero de entrada y acta en consecuencia.


Se guardan todos los datos del fichero original AVIAdbm en el fichero wpt y se restauran tal y como estaban.

Para ello se utiliza el campo de datos del wpt de Oziexplorer al tener un error detectado.

En las ayudas de este programa, Oziexplorer, dice que solo admite 40 caracteres, he comprobado personalmente que la
capacidad real es de 100 caracteres, este espacio es el que utilizo para archivar los datos necesarios sin interferir
con el oziexplorer.

Durante la visualizacin de los puntos no se muestra esta informacin, solo al editar el parmetro comentarios del
punto CUIDADO PUEDE CORROMPER LA INFORMACI ALMACENADA.

Usted podr editar el fichero wpt siempre que respete los caracteres que se encuentra a continuacin del primer
separador | ya que si no perder la informacin y no podr restaurar el fichero dbm original.

Recuerde que debe utilizar el fichero wpt como el master pues solo el guarda toda la informacin, el fichero dbm
es para actualizar los GPS aeronuticos.

Si lo que desea es restaurar el fichero dbm original desde un fichero wpt master volver a tener un fichero dbm
completo sin perder ningn dato solo las lneas de frecuencias y de pistas que no tienen utilidad en oziexplorer.

Tengo otro programa en el horno sobre este tema y en breve saldr al mercado FREEWARE para uso y disfrute de todos.

Si usted tiene una lista de puntos de inters que quiere archivarlos en la base de datos de un garmin aeronutico,
tiene que transformarlos en ficheros aptos para el programa AVIAdbm, para ello puede utilizar un cuarto parmetro
que formatea sus datos en alguno de los 4 disponibles en la base de datos aeronutica.

Estos son:

APT  Aeropuertos  A  Aerdromos
VOR  V
NDB  N
INT  I  Instrumentales

Cualquiera de los cuatro tipos anteriores es valido pues solo se procesa la primera letra y se pasa a maysculas.



El programa necesita dos parmetros mnimos 

Dbm2ozi filein.put fileout.put

Y as funciona de aviadbm -> wpt master
Y de          wpt `master -> aviadbm.

Si quiere crear un fichero dbm con los datos adaptados a un tipo de la base de datos partiendo de un fichero wpt
no master (normal) debe indicarlo con un tercer parmetro en la entrada, o solo tendr una lnea de cabecera, ejemplo:

Dbm2ozi entrada.wpt salida.dbm A

Con esta lnea quiere crear un fichero dbm de puntos que son aeropuertos y el resultado ser algo similar a esto:

--------------------------------------------------------------------------------------------
// dbm2ozi (C) Rafael Leon Rico version 1.0 10/Dic/2003 email:rleonr@wanadoo.es

ADD|APT|AIB01|*PAIS*|*NOMBRE1*|*NOMBRE2*|N 39~01.548|E001~21.718|*ALT*  //|19-JUN-00 12:47
ADD|APT|AIB02|*PAIS*|*NOMBRE1*|*NOMBRE2*|N 39~02.210|E001~21.716|*ALT*  //|19-JUN-00 12:47
--------------------------------------------------------------------------------------------

Como ve se ha rellenado con *PAIS*, *NOMBRE1*, *NOMBRE2*, *ALT* los campos mnimos necesarios para que el fichero
sea correcto a los ojos del programa AVIAdbm, ojo puede y de hecho existen otros parmetros que pueden no ser
necesarios como combustible J,JA y tipo de aerdromo [MIL], le aconsejo que obtenga un fichero dbm desde el programa,
shareware y utilice una base de datos de GARMIN, las dos cosas las puede obtener gratis en la WEB.

Las lneas de los ficheros de tipo NDB, INT y VOR son diferentes, pero os dejo que descubris la informacin por vosotros.

El programa AVIAdbm es shareware y no podr comunicarse con su GPS aeronutico GARMIN si no est registrado.

El fichero de base de datos de GARMIN tiene un instalador para el GPS conclave de pago para instalarse en el GPS
GARMIN por 35 dlares del ala cada 28 das, "BARATO" n?.

Pero si sigue mis instrucciones que estn en Internet en las pginas de ayuda del programa aviadbm ser fcil sacar
la informacin.

Tomamos el fichero ejecutable de actualizacin del GARMIN y hacemos una copia con la extensin ZIP y EUREKA lo dems
es fcil.

Con la base de datos y el aviadbm instalado pasamos a crear una nueva base dbm con el programa com y el modelo de gps
adecuado y despus metemos el filtro del pas que nos plazca y lo grabamos en un fichero de texto con la extensin
fileALL.BAT y sale toito lo necesario para tener la informacin en formato dbm.

Con practica y probando descubriris mas cosas de mi programa dbm2ozi, sobre los iconos que se utilizan automticamente,
colores, comentarios ozi que pasan a comentarios dbm, etc. aunque si no os gusta los colores y dems, ya sabis, a
cambiarlos y asunto zanjado.

El programa es FREEWARE, y si alguien tiene mucho inters en el cdigo lo pide y si averigua la siguiente pregunta:
Dnde nac?
Como pista pongo una poesa a continuacin de este texto, Facillo!.

Ya aviso que es un poco popurri, y que est sin limpiar.

Tanta redundancia en las comprobaciones es porque no me fio de corromper los datos y navegar a Pernanbuco, de todas
formas le recuerdo que usted y solo usted es el responsable del uso de este programa, faltara mas!despues de lo que
ha pagado.

El programa est escrito en pascal, que es como me gusta a m y a muchisima gente programar, para as poder depurar
el programa (quitar errores) en un momento y no acabar en un frenoptico.

Si alguien modifica el cdigo debe hacermelo saber ya que el cdigo es de mi propiedad y solo lo suministro para que
sea mas facil depurar el programa, todas la mejoras que se hagan deben comunicarmelas para que las prximas distribuciones
sigan siendo distribuidas por m.

Puede copiar todo el programa y el cdigo fuente hasta que se aburra y regarlas por Navidad siempre y cuando no cambie nada
del cdigo original ni del programa, hasta que no salga las distribuciones autorizadas por mi.

Puede incluir en el cdigo modificado el nombre del autor y as ser distribuido, esto es el inicio, pero puede crecer
con la ayuda de todos.

Tena anteriormente unos programas en PERL pero despus de pasar mi porttil por el taller, pasaron a la historia,
aprovecho para recordaros lo importante que es hacer copia de seguridad, yo cada 3 aos, mas o menos.

Por ltimo, NO SUMINISTRO CLAVES NI NINGN TIPO DE DESPROTECCIN DE LOS PROGRAMA AVIADBM NI OZIEXPLORER, son buenos,
bonitos y baratos, pero aviso si reinstalas el AVIADBM con un ordenador o Windows nuevo, tendrs que volver a pedir
nuevamente la clave que amablemente a mi me han suministradoo 3  4 que no os sirven para nada, ni a mi tampoco hoy da.


Si detestas algn fallo o haces alguna mejora en el programa DBM2OZI comuncamelo por correo electrnico.

Rafael Len Rico

Piloto de Transporte en helicpteros
Licencia n 53 de Espaa

rleonr@wanadoo.es
		     	
----------------------------------------------------------------------------------------------------
Direccin del programa AVIADBM                             http://www.abnormal.com/~avia_dbm/
Direccin del programa OZIEXPLORER                         http://www.oziexplorer.com/
Direccin en Garmin de las bases de datos aeronauticas:    http://shop.garmin.com/aviation/databases/

------------------------------------
   A Crdoba

Oh excelso muro, oh torres coronadas 
De honor, de majestad, de gallarda! 
Oh gran ro, gran rey de Andaluca, 
De arenas nobles, ya que no doradas! 

Oh frtil llano, oh sierras levantadas, 
Que privilegia el cielo y dora el da! 
Oh siempre glorosa patria ma, 
Tanto por plumas cuanto por espadas! 

Si entre aquellas rinas y despojos 
Que enriquece Genil y Dauro baa 
Tu memoria no fue alimento mo, 

Nunca merezcan mis ausentes ojos 
Ver tu muro, tus torres y tu ro, 
Tu llano y sierra, oh patria, oh flor de Espaa!

 
Luis de Gngora y Argote, 1585

-------------------------------------










































El cdigo va a continuacin:

(*---------------------------------------------------------------------------------
Este programa transforma un fichero de puntos instrumentales en formato (C) AVIAdbm
al formato de texto apto para ser importado por el programa (C)OZIEXPLORER.

Se ha optado por este formato ya que permite mantener otros datos de interes en
el fichero de texto y posteriormente restaurar el fichero de Puntos instrumentales
en el formato original (C)AVIAdbm (shareware) sin perdida de informacin.

El programa tambin procesa el fichero de texto de wpt en formato OZIEXPLORER
(Shareware) y nos entrega el fichero de salida en el formato apto
para el programa C)AVIAdbm (Shareware).

Puede distribuir el programa original y el cdigo fuente sin modificarlo, si
usted detecta algn error o sugiere una mejora deber comunicarlo al autor, para
que este mantenga el control de las futuras versiones, si usted dispone del
cdigo fuente es para su estudio y mejoras, pero este cdigo no es de su propiedad.

Si adapta el cdigo a otros lenguajes, el programa resultante debe seguir siendo
FREEWARE y distribuirlo con el cdigo fuente, con las mismas limitaciones del
cdigo original, le agradecera me enve una cpia del ejecutable y el cdigo fuente.

email: rleonr@wanadoo.es

Rafael Len Rico, Piloto de Transporte en Helicpteros n 53 de Espaa

Cdigo fuente compilado con DELPHI 5.0 sin errores.
---------------------------------------------------------------------------------*)
program dbm2ozi;
{$APPTYPE CONSOLE}
uses
  SysUtils,
  General in 'General.pas';

var
file_input, file_output, parametro : string;

(*---------------------------------------------------------------------------
Bloque principal del programa
---------------------------------------------------------------------------*)
begin
        if ParamCount < 2 then mensaje_error;

        file_input  := ParamStr(1);
        file_output := ParamStr(2);

        if ParamCount >2 then parametro := ParamStr(3) else parametro:=' ';


        elegir_proceso(file_input,file_output,parametro);

end.

------------------------------------------------------------------------------------------------
y ahora la libreria



unit General;

interface
Const
        VERSION ='dbm2ozi (C) Rafael Leon Rico version 1.0 10/Dic/2003 email:rleonr@wanadoo.es';
Var
        tipo_wpt_dbm : string; {|A  |N  |V  |I}

procedure abre_lectura(nombre : string);
procedure abre_escritura(nombre : string);
procedure cierra_ficheros;
procedure lee(var linea:string; var fin:boolean);
procedure escribe(cadena : string);
procedure Pulsar_Continuar;

function FileExists(FileName: string): Boolean;
function Es_letras(entrada: string):boolean;
function Es_numeros_latlon(entrada: string):boolean;
function Es_numeros(entrada: string):boolean;
function Es_num_sexagesimal(var entrada: variant):boolean;
function Es_num_latitud(var entrada: variant):boolean;
function Es_num_longitud(var entrada: variant):boolean;
function obtener_parametro(linea,sepa:string; posicion:byte):string;
function corrige_caracter(linea: string):string;
function es_coment_APT (var linea:string):boolean;
function es_coment_VOR (var linea:string):boolean;
function es_coment_NDB (var linea:string):boolean;
function es_coment_INT (var linea:string):boolean;
procedure lee_coment_APT(linea :string);
procedure lee_coment_VOR(linea :string);
procedure lee_coment_NDB(linea :string);
procedure lee_coment_INT(linea :string);
function lee_linea_wpt(linea:string):string;
function crea_coment_APT(linea :string):string;
function crea_coment_VOR(linea :string):string;
function crea_coment_NDB(linea :string):string;
function crea_coment_INT(linea :string):string;
function es_linea_APT (var linea:string):boolean;
function es_linea_VOR (var linea:string):boolean;
function es_linea_NDB (var linea:string):boolean;
function es_linea_INT (var linea:string):boolean;
function es_linea_dbm (var linea:string):boolean;
function es_linea_wpt (var linea:string):boolean;
function ajusta_lat_dbm(var LAT:string):string;
function ajusta_lon_dbm(var LON:string):string;
function ajusta_lat_wpt(var LAT:string):string;
function ajusta_lon_wpt(var LON:string):string;
procedure escribe_linea_wpt(linea:string);
procedure abre_wpt_escritura(nombre : string);
Procedure dbmtowpt(file1,file2:string);
procedure wpttodbm(file1,file2:string);
procedure elegir_proceso(file_input,file_output,parametro:string);
procedure mensaje_error;

implementation


uses
        Sysutils;


Const

        C_SEXAGESIMAL     =  60;
        C_LATITUD         =  90;
        C_LONGITUD        = 180;
        C_NUMEROS_LATLON  = 'EWONS ';
        C_NUMEROS         = '0123456789.,+-';
        C_LETRAS      ='abcdefghijklmnopqrstvuwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ ';
        C_SEPARA      =';, |*';
        C_LETRA_A     ='';
        C_LETRA_E     ='';
        C_LETRA_I     ='';
        C_LETRA_O     ='';
        C_LETRA_U     ='';
        C_LETRA_GN    ='';
        C_LETRA_SS    ='';
        NO_EXISTE = '* ERROR * - No existe el fichero de entrada';

{Inicios de lnea en fichero dbm}
   inicio_linea_APT='ADD|APT|';
   inicio_linea_VOR='ADD|VOR|';
   inicio_linea_NDB='ADD|NDB|';
   inicio_linea_INT='ADD|INT|';
   inicio_linea_FRQ='ADD|FRQ|';
   inicio_linea_RWY='ADD|RWY|';

var
        file_INP, file_OUT :textfile;

        indica,lat,lon,altura,comentarios:string;
        pais,nombre,nombre2,combustible, frecu, tipo, alcance, mi_nombre:string;
        fin :boolean;



{------------------------------------------------------------------
------------------------------------------------------------------}
procedure abre_lectura(nombre : string);
begin
   if FileExists(nombre) then {recoge el nombre de la lnea de comandos}
     begin
        AssignFile(file_INP, nombre);
        Reset(file_INP);
     end
   else
     begin
        writeln(NO_EXISTE);
        writeln(nombre);
        writeln;
        pulsar_continuar;
        exit;
     end;
end;

{------------------------------------------------------------------
------------------------------------------------------------------}
procedure abre_escritura(nombre : string);
begin
        AssignFile(file_OUT, nombre);
        Rewrite(file_OUT);
end;
{------------------------------------------------------------------
------------------------------------------------------------------}
procedure cierra_ficheros;
begin
        Close(File_INP);
        Close(File_OUT);
end;
{------------------------------------------------------------------
------------------------------------------------------------------}
procedure lee(var linea:string; var fin:boolean);
begin
     if not Eof(File_INP) then
                begin
                        readln(file_INP, Linea);
                        fin := false;
                end
          else
                begin
                        Linea :='';
                        fin := true;
                end;
end;

{------------------------------------------------------------------
------------------------------------------------------------------}
procedure escribe(cadena : string);
begin
        writeln(File_OUT,cadena);
end;
{---------------------------------------------------------------------------
Saca mensaje de Pulsar para continuar y espera que pulsemos ENTER
---------------------------------------------------------------------------}
procedure Pulsar_Continuar;
const
        PULSAR = 'Pulsar ENTER para continuar';
begin
        writeln;
        writeln(PULSAR);
        readln;
end;
{---------------------------------------------------------------------------
Comprueba que existe el fichero de texto a procesar
devuelve cierto si existe, cierra el fichero al final
---------------------------------------------------------------------------}

function FileExists(FileName: string): Boolean;

 var
  F: file;
begin
  {$I-}
  AssignFile(F, FileName);
  FileMode := 0;  {accede al fichero solo en modo lectura}
  Reset(F);
  CloseFile(F);
  {$I+}
  FileExists := (IOResult = 0) and (FileName <> '');
end;

{-------------------------------------------------------
devuelve TRUE si el valor variant de entrada est compuesto
por caracteres de prmetro indicado
-------------------------------------------------------}
function Es_caracter(entrada, compara: string):boolean;
var
        valor, n : integer;
        es       : boolean;
begin
        valor := length(entrada);

        if (valor>0) and (pos(entrada[1],compara)>0) then es := true
                                                     else es := false;

        if es= true then
             for n := 1 to valor do if pos(entrada[n],compara)>0
                then es := (es and true)
                else
                   begin
                      es:= false;
                      Break;
                   end;

        Es_caracter := es;

end;

{-------------------------------------------------------
devuelve TRUE si el valor de cadena de entrada est compuesto
por caracteres de letras
-------------------------------------------------------}
function Es_letras(entrada: string):boolean;
begin
        Es_letras := Es_caracter(entrada,C_LETRAS);
end;

{-------------------------------------------------------
devuelve TRUE si el valor de cadena de entrada est compuesto
por caracteres de numeros vlidos como lat o lon
-------------------------------------------------------}
function Es_numeros_latlon(entrada: string):boolean;
begin
        Es_numeros_latlon := Es_caracter(entrada,C_NUMEROS+C_NUMEROS_LATLON);
end;
{-------------------------------------------------------
devuelve TRUE si el valor de cadena de entrada est compuesto
por caracteres de numeros
-------------------------------------------------------}
function Es_numeros(entrada: string):boolean;
begin
        Es_numeros := Es_caracter(entrada,C_NUMEROS);
end;
{-------------------------------------------------------
devuelve TRUE si el valor variant de entrada es inferior
al valor de comparacin
-------------------------------------------------------}
function Es_inferior(entrada, compara: variant):boolean;
var
        valor, n : integer;
begin
        val(entrada,valor,n);
        valor := abs(valor);
        IF (valor < compara) and (length(entrada)>0) then Es_inferior:= true else Es_inferior := false;
end;

{-------------------------------------------------------
devuelve TRUE si el valor variant de entrada es inferior
al valor 60
-------------------------------------------------------}
function Es_num_sexagesimal(var entrada: variant):boolean;
begin
        Es_num_sexagesimal := Es_inferior(entrada,C_SEXAGESIMAL);
end;

{-------------------------------------------------------
devuelve TRUE si el valor variant de entrada es inferior
al valor 90
-------------------------------------------------------}
function Es_num_latitud(var entrada: variant):boolean;
begin
        Es_num_latitud := Es_inferior(entrada,C_LATITUD);
end;

{-------------------------------------------------------
devuelve TRUE si el valor variant de entrada es inferior
al valor 180
-------------------------------------------------------}
function Es_num_longitud(var entrada: variant):boolean;
begin
        Es_num_longitud := Es_inferior(entrada,C_LONGITUD);
end;

(*---------------------------------------------------------------------------
Busca en la cadena linea con nmero indicado en la lnea de entrada, el
parametro detras del separador indicado en la constantes de entrada [sepa].
---------------------------------------------------------------------------*)
function obtener_parametro(linea,sepa:string; posicion:byte):string;
var
        i:byte;
        longitud:integer;
begin
    i:=0;
    linea := sepa+linea+sepa;
    while i<posicion do
    begin
        inc(i);
        longitud := pos(sepa,linea);
        linea := copy(linea,longitud+1,length(linea)-longitud+1);
    end;
    linea := copy(linea,1,pos(sepa,linea)-1);

    obtener_parametro :=linea;
end;


function corrige_caracter(linea: string):string;
var
        i, longitud: integer;
        tempo      : string;
begin
        longitud := length(linea);
        tempo    := linea;

        for i :=1 to longitud do
           begin
                if pos(tempo[i],C_LETRA_A)>0  then tempo[i] := 'A';
                if pos(tempo[i],C_LETRA_E)>0  then tempo[i] := 'E';
                if pos(tempo[i],C_LETRA_I)>0  then tempo[i] := 'I';
                if pos(tempo[i],C_LETRA_O)>0  then tempo[i] := 'O';
                if pos(tempo[i],C_LETRA_U)>0  then tempo[i] := 'U';
                if pos(tempo[i],C_LETRA_GN)>0 then tempo[i] := 'N';
                if pos(tempo[i],C_LETRA_SS)>0 then tempo[i] := 'S';
           end;
        corrige_caracter := UpperCase(tempo);
end;

(*---------------------------------------------------------------------------
ADD|APT|FMNQ|FM-MADAGASCAR|BESALAMPY|BESALAMPY|S 16~45.002|E044~28.998|130      //Besalampi
Besalampi|A*|FM-MADAGASCAR|BESALAMPY|BESALAMPY|130||
1234567890123456789012345678901234567890

ADD|APT|DAAG|DA-ALGERIA|ALGIERS|HOUARI BOUMEDIENE|N 36~41.670|E003~13.016|80|JA     //Argelia
Argelia|A*|DA-ALGERIA|ALGIERS|HOUARI BOUMEDIENE|80|JA|
1234567890123456789012345678901234567890

En este ejemplo como no existe comentario tras // copia el nombre para el usuario
ADD|APT|DAAJ|DA-ALGERIA|DJANET|TISKA|N 24~17.580|E009~27.121|3180|J
DJANET|A*|DA-ALGERIA|DJANET|TISKA|3180|J|
1234567890123456789012345678901234567890
---------------------------------------------------------------------------*)
function es_coment_APT (var linea:string):boolean;
begin
        if pos('|A*|',linea)>0 then es_coment_APT := true
                            else es_coment_APT := false;
end;


(*---------------------------------------------------------------------------
ADD|VOR|ZEM|DA-ALGERIA|ZEMMOURI|ZEMMOURI|N 36~48.334|E003~38.219|116.60|VORDME|High    //Zemmouri
Zemmouri|V*|DA-ALGERIA|ZEMMOURI|ZEMMOURI|116.60|VORDME|High|
1234567890123456789012345678901234567890

ADD|VOR|ZFR|LL-ISRAEL|ZOFAR|ZOFAR|N 30~33.498|E035~09.663|115.60|VORDME
ZOFAR|V*|LL-ISRAEL|ZOFAR|ZOFAR|115.60|VORDME||
1234567890123456789012345678901234567890
---------------------------------------------------------------------------*)
function es_coment_VOR (var linea:string):boolean;
begin
        if pos('|V*|',linea)>0 then es_coment_VOR := true
                            else es_coment_VOR := false;
end;


(*---------------------------------------------------------------------------
ADD|NDB|CNL|GM-MOROCCO|KENITRA|KENITRA|N 34~17.403|W006~37.331|380.0
KENITRA|N*|GM-MOROCCO|KENITRA|KENITRA|380.0||
1234567890123456789012345678901234567890

ADD|NDB|CNL|VC-SRI LANKA|COLOMBO|BANDARANAIKE INTL|N 07~16.119|E079~57.057|315.0|L   //Colombo
Colombo|N*|VC-SRI LANKA|COLOMBO|BANDARANAIKE INTL|315.0|L|
1234567890123456789012345678901234567890
---------------------------------------------------------------------------*)
function es_coment_NDB (var linea:string):boolean;
begin
        if pos('|N*|',linea)>0 then es_coment_NDB := true
                            else es_coment_NDB := false;
end;


(*---------------------------------------------------------------------------
ADD|INT|ABJR|VG-BANGLADESH|N 23~06.049|E089~12.838     //Comentario
Comentario|I*|VG-BANGLADESH|
1234567890123456789012345678901234567890

ADD|INT|ABKAR|OE-SAUDI ARAB|N 19~05.181|E040~16.203
ABKAR|I*|OE-SAUDI ARAB|
1234567890123456789012345678901234567890
---------------------------------------------------------------------------*)
function es_coment_INT (var linea:string):boolean;
begin
        if pos('|I*|',linea)>0 then es_coment_INT := true
                            else es_coment_INT := false;
end;

{
Lee comentarios para un APT

ADD|APT|FMNQ|FM-MADAGASCAR|BESALAMPY|BESALAMPY|S 16~45.002|E044~28.998|130      //Besalampi
Besalampi|A*|FM-MADAGASCAR|BESALAMPY|BESALAMPY|130||
1234567890123456789012345678901234567890

ADD|APT|DAAG|DA-ALGERIA|ALGIERS|HOUARI BOUMEDIENE|N 36~41.670|E003~13.016|80|JA     //Argelia
Argelia|A*|DA-ALGERIA|ALGIERS|HOUARI BOUMEDIENE|80|JA|
1234567890123456789012345678901234567890

En este ejemplo como no existe comentario tras // copia el nombre para el usuario
ADD|APT|DAAJ|DA-ALGERIA|DJANET|TISKA|N 24~17.580|E009~27.121|3180|J
DJANET|A*|DA-ALGERIA|DJANET|TISKA|3180|J|
1234567890123456789012345678901234567890

Este es el nombre|A*|ZZ-ESTE ES EL PAIS|ESTE ES OTRO NOMBRE LARGO|9990|Y AQUI VIENE EL COMBUSTIBLE
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890

AUNQUE LA AYUDA DICE QUE ADMITE COMENTARIOS DE LONGITUD 40 LO CIERTO ES QUE LLEGA A LONGITUD 100
y logra guardarlos y recuperarlos del fichero de waipoint de oziexplorer
}
procedure lee_coment_APT(linea :string);
const
        pos_minombre    = 1;
        pos_pais        = 3;
        pos_nombre      = 4;
        pos_nombre2     = 5;
        pos_altura      = 6;
        pos_combustible = 7;
        pos_tipo        = 8;
begin
        mi_nombre       := obtener_parametro(Linea,'|',pos_minombre);
        pais            := obtener_parametro(linea,'|',pos_pais);
        nombre          := obtener_parametro(linea,'|',pos_nombre);
        nombre2         := obtener_parametro(linea,'|',pos_nombre2);
        altura          := obtener_parametro(linea,'|',pos_altura);
        combustible     := obtener_parametro(linea,'|',pos_combustible);
        tipo            := obtener_parametro(linea,'|',pos_tipo);
        if combustible<>'' then combustible :='|'+combustible;
        if tipo       <>'' then tipo        :='|'+tipo;
end;
{
Crea comentarios para un ndb

ADD|NDB|CNL|GM-MOROCCO|KENITRA|KENITRA|N 34~17.403|W006~37.331|380.0
KENITRA|N*|GM-MOROCCO|KENITRA|KENITRA|380.0||
1234567890123456789012345678901234567890

ADD|NDB|CNL|VC-SRI LANKA|COLOMBO|BANDARANAIKE INTL|N 07~16.119|E079~57.057|315.0|L   //Colombo
Colombo|N*|VC-SRI LANKA|COLOMBO|BANDARANAIKE INTL|315.0|L|
1234567890123456789012345678901234567890


Este es el nombre|N*|ZZ-ESTE ES EL PAIS MUY LARGO|ESTE ES EL OTRO NOMBRE LARGISIMO|999.9|ALCANCE|
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890

AUNQUE LA AYUDA DICE QUE ADMITE COMENTARIOS DE LONGITUD 40 LO CIERTO ES QUE LLEGA A LONGITUD 100
y logra guardarlos y recuperarlos del fichero de waipoint de oziexplorer
}
procedure lee_coment_NDB(linea :string);
const
        pos_minombre    = 1;
        pos_pais        = 3;
        pos_nombre      = 4;
        pos_nombre2     = 5;
        pos_frecu       = 6;
        pos_tipo        = 7;
begin
        mi_nombre       := obtener_parametro(Linea,'|',pos_minombre);
        pais            := obtener_parametro(linea,'|',pos_pais);
        nombre          := obtener_parametro(linea,'|',pos_nombre);
        nombre2         := obtener_parametro(linea,'|',pos_nombre2);
        frecu           := obtener_parametro(linea,'|',pos_frecu);
        tipo            := obtener_parametro(linea,'|',pos_tipo);
        if tipo<>'' then tipo :='|'+ tipo;
end;

{
Crea comentarios para un vor

ADD|VOR|ZEM|DA-ALGERIA|ZEMMOURI|ZEMMOURI|N 36~48.334|E003~38.219|116.60|VORDME|High    //Zemmouri
Zemmouri|V*|DA-ALGERIA|ZEMMOURI|ZEMMOURI|116.60|VORDME|High|
1234567890123456789012345678901234567890

ADD|VOR|ZFR|LL-ISRAEL|ZOFAR|ZOFAR|N 30~33.498|E035~09.663|115.60|VORDME
ZOFAR|V*|LL-ISRAEL|ZOFAR|ZOFAR|115.60|VORDME||
1234567890123456789012345678901234567890

Este es el nombre|V*|ZZ-ESTE ES EL PAIS MUY LARGO|ESTE ES EL OTRO NOMBRE LARGISIMO|999.9|TIPO|High|
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890

AUNQUE LA AYUDA DICE QUE ADMITE COMENTARIOS DE LONGITUD 40 LO CIERTO ES QUE LLEGA A LONGITUD 100
y logra guardarlos y recuperarlos del fichero de waipoint de oziexplorer
}
procedure lee_coment_VOR(linea :string);
const
        pos_minombre    = 1;
        pos_pais        = 3;
        pos_nombre      = 4;
        pos_nombre2     = 5;
        pos_frecu       = 6;
        pos_tipo        = 7;
        pos_alcance     = 8;

begin
        mi_nombre       := obtener_parametro(Linea,'|',pos_minombre);
        pais            := obtener_parametro(linea,'|',pos_pais);
        nombre          := obtener_parametro(linea,'|',pos_nombre);
        nombre2         := obtener_parametro(linea,'|',pos_nombre2);
        frecu           := obtener_parametro(linea,'|',pos_frecu);
        tipo            := obtener_parametro(linea,'|',pos_tipo);
        alcance         := obtener_parametro(linea,'|',pos_alcance);

        if tipo<>'' then tipo :='|'+ tipo;
        if alcance<>'' then alcance :='|'+ alcance;
end;

{
Crea comentarios para un int

ADD|INT|ABJR|VG-BANGLADESH|N 23~06.049|E089~12.838     //Comentario
Comentario|I*|VG-BANGLADESH|
1234567890123456789012345678901234567890

ADD|INT|ABKAR|OE-SAUDI ARAB|N 19~05.181|E040~16.203
ABKAR|I*|OE-SAUDI ARAB|
1234567890123456789012345678901234567890


Este es el nombre|I*|ZZ-ESTE ES EL PAIS MUY LARGO|
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890

AUNQUE LA AYUDA DICE QUE ADMITE COMENTARIOS DE LONGITUD 40 LO CIERTO ES QUE LLEGA A LONGITUD 100
y logra guardarlos y recuperarlos del fichero de waipoint de oziexplorer
}
procedure lee_coment_INT(linea :string);
const
        pos_minombre    = 1;
        pos_pais        = 3;
begin
        mi_nombre       := obtener_parametro(Linea,'|',pos_minombre);
        pais            := obtener_parametro(linea,'|',pos_pais);
end;

{----------------------------------------------------------------------------
Graba datos en fichero dbm

   1,APT,  39.552054,   2.740810,37962.5356874,  0, 1, 4,         0,     65535,aeropuerto, 0, 0,    0,   1111, 8, 0,25,0,10.0,2,,,
   2,NDB,  39.641685,   2.916016,37962.5365889, 13, 1, 4,       255,  16776960,ndb, 0, 0,    0,   -777, 8, 0,17,0,10.0,2,,,
   3,VOR,  39.435885,   2.758566,37962.5378872, 30, 1, 4,     65535,   8388608,vor, 0, 0,    0,   -777, 8, 0,17,0,10.0,2,,,
   4,INT,  39.431458,   3.019149,37962.5395314, 70, 1, 4,     65535,   8388736,int, 0, 0,    0,   -777, 8, 0,17,0,10.0,2,,,

ADD|APT|DAAG|DA-ALGERIA|ALGIERS|HOUARI BOUMEDIENE|N 36~41.670|E003~13.016|80|JA     //Argelia
ADD|NDB|CNL|VC-SRI LANKA|COLOMBO|BANDARANAIKE INTL|N 07~16.119|E079~57.057|315.0|L   //Colombo
ADD|VOR|ZEM|DA-ALGERIA|ZEMMOURI|ZEMMOURI|N 36~48.334|E003~38.219|116.60|VORDME|High    //Zemmouri
ADD|INT|ABJR|VG-BANGLADESH|N 23~06.049|E089~12.838     //Comentario

----------------------------------------------------------------------------}
function lee_linea_wpt(linea:string):string;
Const
        pos_indica  = 2;
        pos_lat     = 3;
        pos_lon     = 4;
        pos_coment  = 11;
        pos_altura  = 15;

var
        tempo   : string;
        recicla : boolean;
begin

        indica          := obtener_parametro(linea,',',pos_indica);
        lat             := obtener_parametro(linea,',',pos_lat);
        lat             := ajusta_lat_dbm(lat);

        lon             := obtener_parametro(linea,',',pos_lon);
        lon             := ajusta_lon_dbm(lon);

        comentarios     := obtener_parametro(linea,',',pos_coment);
        altura          := obtener_parametro(linea,',',pos_altura);

{
         indica,lat,lon,altura,comentarios:string;
        pais,nombre,nombre2,combustible, frecu, tipo, alcance, mi_nombre:string;

ADD|APT|DAAG|DA-ALGERIA|ALGIERS|HOUARI BOUMEDIENE|N 36~41.670|E003~13.016|80|JA     //Argelia
ADD|NDB|CNL|VC-SRI LANKA|COLOMBO|BANDARANAIKE INTL|N 07~16.119|E079~57.057|315.0|L   //Colombo
ADD|VOR|ZEM|DA-ALGERIA|ZEMMOURI|ZEMMOURI|N 36~48.334|E003~38.219|116.60|VORDME|High    //Zemmouri
ADD|INT|ABJR|VG-BANGLADESH|N 23~06.049|E089~12.838     //Comentario
}
        tipo_wpt_dbm := uppercase(tipo_wpt_dbm[1]);
        recicla := pos(tipo_wpt_dbm,'ANVI')>0;
        recicla := (length(indica) > 0)and recicla and es_linea_wpt(linea);
        recicla := recicla and (pos('|A*|',comentarios)=0);  {no tiene la marca de aeropuerto}
        recicla := recicla and (pos('|N*|',comentarios)=0);  {no tiene la marca de aeropuerto}
        recicla := recicla and (pos('|V*|',comentarios)=0);  {no tiene la marca de aeropuerto}
        recicla := recicla and (pos('|I*|',comentarios)=0);  {no tiene la marca de aeropuerto}

         if recicla then comentarios := comentarios + '|'+tipo_wpt_dbm+'*|||||||';

        if es_coment_APT(comentarios) then
                begin
                        lee_coment_APT(comentarios);
                        if pais=''       then pais :='*PAIS*';
                        if nombre=''     then nombre  :='*NOMBRE1*';
                        if nombre2=''    then nombre2 :='*NOMBRE2*';
                        if altura=''     then altura  :='*ALT*';

                        tempo := inicio_linea_APT+indica+'|'+pais+'|'+nombre+'|'+nombre2+'|'+lat+'|'+lon;
                        tempo := tempo+'|'+altura+combustible+tipo;
                        if mi_nombre<>nombre then tempo := tempo + '  //|'+mi_nombre;
                end;
        if es_coment_VOR(comentarios) then
                begin
                        lee_coment_VOR(comentarios);

                        if pais=''    then pais    :='*PAIS*';
                        if nombre=''  then nombre  :='*NOMBRE1*';
                        if nombre2='' then nombre2 :='*NOMBRE2*';
                        if frecu=''   then frecu   :='*FRECU*';

                        tempo := inicio_linea_VOR+indica+'|'+pais+'|'+nombre+'|'+nombre2+'|'+lat+'|'+lon;
                        tempo := tempo+'|'+frecu+tipo+alcance;
                        if mi_nombre<>nombre then tempo := tempo + '  //|'+mi_nombre;
                end;
        if es_coment_NDB(comentarios) then
                begin
                        lee_coment_NDB(comentarios);
                        if pais=''    then pais    :='*PAIS*';
                        if nombre=''  then nombre  :='*NOMBRE1*';
                        if nombre2='' then nombre2 :='*NOMBRE2*';
                        if frecu=''   then frecu   :='*FRECU*';

                        tempo := inicio_linea_NDB+indica+'|'+pais+'|'+nombre+'|'+nombre2+'|'+lat+'|'+lon;
                        tempo := tempo+'|'+frecu+tipo;
                        if mi_nombre<>nombre then tempo := tempo + '  //|'+mi_nombre;
                end;
        if es_coment_INT(comentarios) then
                begin
                        lee_coment_INT(comentarios);
                        if pais=''    then pais    :='*PAIS*';

                        tempo := inicio_linea_INT+indica+'|'+pais+'|'+lat+'|'+lon;
                        if mi_nombre<>indica then tempo := tempo + '  //|'+mi_nombre;
                end;
        lee_linea_wpt := tempo;
end;

{
Crea comentarios para un APT

ADD|APT|FMNQ|FM-MADAGASCAR|BESALAMPY|BESALAMPY|S 16~45.002|E044~28.998|130      //Besalampi
Besalampi|A*|FM-MADAGASCAR|BESALAMPY|BESALAMPY|130||
1234567890123456789012345678901234567890

ADD|APT|DAAG|DA-ALGERIA|ALGIERS|HOUARI BOUMEDIENE|N 36~41.670|E003~13.016|80|JA     //Argelia
Argelia|A*|DA-ALGERIA|ALGIERS|HOUARI BOUMEDIENE|80|JA|
1234567890123456789012345678901234567890

En este ejemplo como no existe comentario tras // copia el nombre para el usuario
ADD|APT|DAAJ|DA-ALGERIA|DJANET|TISKA|N 24~17.580|E009~27.121|3180|J
DJANET|A*|DA-ALGERIA|DJANET|TISKA|3180|J|
1234567890123456789012345678901234567890

Este es el nombre|A*|ZZ-ESTE ES EL PAIS|ESTE ES OTRO NOMBRE LARGO|9990|Y AQUI VIENE EL COMBUSTIBLE
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890

AUNQUE LA AYUDA DICE QUE ADMITE COMENTARIOS DE LONGITUD 40 LO CIERTO ES QUE LLEGA A LONGITUD 100
y logra guardarlos y recuperarlos del fichero de waipoint de oziexplorer
}
function crea_coment_APT(linea :string):string;
const
        pos_pais        = 4;
        pos_nombre      = 5;
        pos_nombre2     = 6;
        pos_altura      = 9;
        pos_combustible =10;
        pos_tipo        =11;
var
        longitud :integer;
        pais,nombre,nombre2,altura,combustible, mi_nombre,tempo:string;

begin
        pais            := obtener_parametro(linea,'|',pos_pais);
        nombre          := obtener_parametro(linea,'|',pos_nombre);
        nombre2         := obtener_parametro(linea,'|',pos_nombre2);
        altura          := obtener_parametro(linea,'|',pos_altura);
        combustible     := obtener_parametro(linea,'|',pos_combustible);
        tipo            := obtener_parametro(linea,'|',pos_tipo);

        longitud := pos('//',linea);           {busca comentario en fichero dbm}
        if longitud>0 then mi_nombre :=trim(copy(linea,longitud+2,length(linea)-longitud-2))
                      else mi_nombre := Nombre;  {pone nombre usuario el del fichero dbm si no existe}

        tempo := '|A*|'+pais+'|'+nombre+'|'+nombre2+'|'+altura+'|'+combustible+'|'+tipo+'|';
        longitud := length(tempo);

        while longitud + length(mi_nombre)>100 do
              mi_nombre := copy(mi_nombre,1,length(mi_nombre)-1); {recorta nombre usuario si no hay sitio}

        crea_coment_APT := mi_nombre+tempo;
end;
{
        writeln('linea original = ',linea);
        writeln('mi_nombre      = ',mi_nombre);
        writeln('pais           = ',pais);
        writeln('nombre         = ',nombre);
        writeln('nombre2        = ',nombre2);
        writeln('altura         = ',altura);
        writeln('combustib      = ',combustible);
}
{
Crea comentarios para un vor

ADD|VOR|ZEM|DA-ALGERIA|ZEMMOURI|ZEMMOURI|N 36~48.334|E003~38.219|116.60|VORDME|High    //Zemmouri
Zemmouri|V*|DA-ALGERIA|ZEMMOURI|ZEMMOURI|116.60|VORDME|High|
1234567890123456789012345678901234567890

ADD|VOR|ZFR|LL-ISRAEL|ZOFAR|ZOFAR|N 30~33.498|E035~09.663|115.60|VORDME
ZOFAR|V*|LL-ISRAEL|ZOFAR|ZOFAR|115.60|VORDME||
1234567890123456789012345678901234567890

Este es el nombre|V*|ZZ-ESTE ES EL PAIS MUY LARGO|ESTE ES EL OTRO NOMBRE LARGISIMO|999.9|TIPO|High|
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890

AUNQUE LA AYUDA DICE QUE ADMITE COMENTARIOS DE LONGITUD 40 LO CIERTO ES QUE LLEGA A LONGITUD 100
y logra guardarlos y recuperarlos del fichero de waipoint de oziexplorer
}
function crea_coment_VOR(linea :string):string;
const
        pos_pais        = 4;
        pos_nombre      = 5;
        pos_nombre2     = 6;
        pos_frecu       = 9;
        pos_tipo        =10;
        pos_alcance     =11;
var
        longitud :integer;
        pais,nombre,nombre2,frecu,tipo,alcance,mi_nombre, tempo:string;

begin
        pais            := obtener_parametro(linea,'|',pos_pais);
        nombre          := obtener_parametro(linea,'|',pos_nombre);
        nombre2         := obtener_parametro(linea,'|',pos_nombre2);
        frecu           := obtener_parametro(linea,'|',pos_frecu);
        tipo            := obtener_parametro(linea,'|',pos_tipo);
        alcance         := obtener_parametro(linea,'|',pos_alcance);

        longitud := pos('//',linea);           {busca comentario en fichero dbm}
        if longitud>0 then tempo :=trim(copy(linea,longitud+2,length(linea)-longitud-2))
                      else mi_nombre := Nombre;  {pone nombre usuario el del fichero dbm si no existe}

        tempo := '|V*|'+pais+'|'+nombre+'|'+nombre2+'|'+frecu+'|'+tipo+'|'+alcance+'|';
        longitud := length(tempo);

        while longitud + length(mi_nombre)>100 do
              mi_nombre := copy(mi_nombre,1,length(mi_nombre)-1); {recorta nombre usuario si no hay sitio}

        crea_coment_VOR := mi_nombre+tempo;
end;

{
Crea comentarios para un ndb

ADD|NDB|CNL|GM-MOROCCO|KENITRA|KENITRA|N 34~17.403|W006~37.331|380.0
KENITRA|N*|GM-MOROCCO|KENITRA|KENITRA|380.0||
1234567890123456789012345678901234567890

ADD|NDB|CNL|VC-SRI LANKA|COLOMBO|BANDARANAIKE INTL|N 07~16.119|E079~57.057|315.0|L   //Colombo
Colombo|N*|VC-SRI LANKA|COLOMBO|BANDARANAIKE INTL|315.0|L|
1234567890123456789012345678901234567890


Este es el nombre|N*|ZZ-ESTE ES EL PAIS MUY LARGO|ESTE ES EL OTRO NOMBRE LARGISIMO|999.9|ALCANCE|
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890

AUNQUE LA AYUDA DICE QUE ADMITE COMENTARIOS DE LONGITUD 40 LO CIERTO ES QUE LLEGA A LONGITUD 100
y logra guardarlos y recuperarlos del fichero de waipoint de oziexplorer
}
function crea_coment_NDB(linea :string):string;
const
        pos_pais        = 4;
        pos_nombre      = 5;
        pos_nombre2     = 6;
        pos_frecu       = 9;
        pos_tipo        =10;
var
        longitud :integer;
        pais,nombre,nombre2,frecu,tipo,mi_nombre, tempo:string;

begin
        pais            := obtener_parametro(linea,'|',pos_pais);
        nombre          := obtener_parametro(linea,'|',pos_nombre);
        nombre2         := obtener_parametro(linea,'|',pos_nombre2);
        frecu           := obtener_parametro(linea,'|',pos_frecu);
        tipo            := obtener_parametro(linea,'|',pos_tipo);

        longitud := pos('//',linea);           {busca comentario en fichero dbm}
        if longitud>0 then tempo :=trim(copy(linea,longitud+2,length(linea)-longitud-2))
                      else mi_nombre := Nombre;  {pone nombre usuario el del fichero dbm si no existe}

        tempo := '|N*|'+pais+'|'+nombre+'|'+nombre2+'|'+frecu+'|'+tipo+'|';
        longitud := length(tempo);

        while longitud + length(mi_nombre)>100 do
              mi_nombre := copy(mi_nombre,1,length(mi_nombre)-1); {recorta nombre usuario si no hay sitio}

        crea_coment_NDB := mi_nombre+tempo;
end;

{
Crea comentarios para un int

ADD|INT|ABJR|VG-BANGLADESH|N 23~06.049|E089~12.838     //Comentario
Comentario|I*|VG-BANGLADESH|
1234567890123456789012345678901234567890

ADD|INT|ABKAR|OE-SAUDI ARAB|N 19~05.181|E040~16.203
ABKAR|I*|OE-SAUDI ARAB|
1234567890123456789012345678901234567890


Este es el nombre|I*|ZZ-ESTE ES EL PAIS MUY LARGO|
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890

AUNQUE LA AYUDA DICE QUE ADMITE COMENTARIOS DE LONGITUD 40 LO CIERTO ES QUE LLEGA A LONGITUD 100
y logra guardarlos y recuperarlos del fichero de waipoint de oziexplorer
}
function crea_coment_INT(linea :string):string;
const
        pos_pais        = 4;
        pos_nombre      = 3;
var
        longitud :integer;
        pais,nombre,mi_nombre, tempo:string;

begin
        pais            := obtener_parametro(linea,'|',pos_pais);
        nombre          := obtener_parametro(linea,'|',pos_nombre);

        longitud := pos('//',linea);           {busca comentario en fichero dbm}
        if longitud>0 then tempo :=trim(copy(linea,longitud+2,length(linea)-longitud-2))
                      else mi_nombre := Nombre;  {pone nombre usuario el del fichero dbm si no existe}

        tempo := '|I*|'+pais+'|';
        longitud := length(tempo);

        while longitud + length(mi_nombre)>100 do
              mi_nombre := copy(mi_nombre,1,length(mi_nombre)-1); {recorta nombre usuario si no hay sitio}

        crea_coment_INT := mi_nombre+tempo;
end;

(*---------------------------------------------------------------------------
Comprueba que la lnea indicada es lnea de aeropuertos

Datos que comprueba para identificar lnea de datos al comienzo de ella
ADD|APT|
---------------------------------------------------------------------------*)
function es_linea_APT (var linea:string):boolean;
begin
        if pos(inicio_linea_APT,linea)>0 then es_linea_APT := true
                                         else es_linea_APT := false;
end;

(*---------------------------------------------------------------------------
Comprueba que la lnea indicada es lnea de puntos wpt

   1,APT,  39.552054,   2.740810,37962.5356874,  0, 1, 4,         0,     65535,aeropuerto, 0, 0,    0,   1111, 8, 0,25,0,10.0,2,,,
   2,NDB,  39.641685,   2.916016,37962.5365889, 13, 1, 4,       255,  16776960,ndb, 0, 0,    0,   -777, 8, 0,17,0,10.0,2,,,
   3,VOR,  39.435885,   2.758566,37962.5378872, 30, 1, 4,     65535,   8388608,vor, 0, 0,    0,   -777, 8, 0,17,0,10.0,2,,,
   4,INT,  39.431458,   3.019149,37962.5395314, 70, 1, 4,     65535,   8388736,int, 0, 0,    0,   -777, 8, 0,17,0,10.0,2,,,

---------------------------------------------------------------------------*)
function es_linea_wpt (var linea:string):boolean;
var
        lat, lon :variant;
begin
        lat := obtener_parametro(linea,',',3);
        lon := obtener_parametro(linea,',',4);
        es_linea_wpt := Es_num_latitud(lat) and Es_num_longitud(lon);
end;

(*---------------------------------------------------------------------------
Comprueba que la lnea indicada es lnea de VOR

Datos que comprueba para identificar lnea de datos al comienzo de ella
ADD|VOR|
---------------------------------------------------------------------------*)
function es_linea_VOR (var linea:string):boolean;
begin
        if pos(inicio_linea_VOR,linea)>0 then es_linea_VOR := true
                                         else es_linea_VOR := false;
end;


(*---------------------------------------------------------------------------
Comprueba que la lnea indicada es lnea de NDB

Datos que comprueba para identificar lnea de datos al comienzo de ella
ADD|NDB|
---------------------------------------------------------------------------*)
function es_linea_NDB (var linea:string):boolean;
begin
        if pos(inicio_linea_NDB,linea)>0 then es_linea_NDB := true
                                         else es_linea_NDB := false;
end;


(*---------------------------------------------------------------------------
Comprueba que la lnea indicada es lnea de puntos INT

Datos que comprueba para identificar lnea de datos al comienzo de ella
ADD|INT|
---------------------------------------------------------------------------*)
function es_linea_INT (var linea:string):boolean;
begin
        if pos(inicio_linea_INT,linea)>0 then es_linea_INT := true
                                         else es_linea_INT := false;
end;

(*---------------------------------------------------------------------------
Comprueba que la lnea indicada es lnea de DBM de datos aptos para ozi

Datos que comprueba para identificar lnea de datos al comienzo de ella
ADD|VOR|
---------------------------------------------------------------------------*)
function es_linea_dbm (var linea:string):boolean;
begin
        es_linea_dbm := es_linea_APT(linea) or es_linea_VOR(linea) or
                        es_linea_NDB(linea) or es_linea_INT(linea);
end;

(*---------------------------------------------------------------------------
Cambia el formato de latitud entrada
   1,APT,  39.552054,   2.740810,37962.5356874,  0, 1, 4,         0,     65535,aeropuerto, 0, 0,    0,   1111, 8, 0,25,0,10.0,2,,,
   2,NDB,  39.641685,   2.916016,37962.5365889, 13, 1, 4,       255,  16776960,ndb, 0, 0,    0,   -777, 8, 0,17,0,10.0,2,,,
   3,VOR,  39.435885,   2.758566,37962.5378872, 30, 1, 4,     65535,   8388608,vor, 0, 0,    0,   -777, 8, 0,17,0,10.0,2,,,
   4,INT,  39.431458,   3.019149,37962.5395314, 70, 1, 4,     65535,   8388736,int, 0, 0,    0,   -777, 8, 0,17,0,10.0,2,,,

al formato de salida
N 11~59.896
icluyendo el signo +/- dependiendo de si es Norte/Sur

rellenado los ceros y espacios necesarios
---------------------------------------------------------------------------*)
function ajusta_lat_dbm(var LAT:string):string;
var
        nada:integer;
        negativo: boolean;
        latg, latm :double;
        LAT_GRA, LAT_MIN :string;
begin
        val(LAT,latg,nada);
        latg := latg + 0.000001;
        str(int(latg):3:0,LAT_GRA);
        LAT_GRA := trim(LAT_GRA);

        latm := (latg - int(latg))*60;
        str(abs(latm):8:3,LAT_MIN);
        LAT_MIN := trim(LAT_MIN);

        negativo := false;
        if LAT_GRA[1]='-' then
        begin
                negativo := true;
                nada     := length(LAT_GRA);
                LAT_GRA  := copy(LAT_GRA,2,nada-1);
        end;

                while length(LAT_GRA)<2 do LAT_GRA := '0'+LAT_GRA;
        if negativo then LAT_GRA := 'S '+LAT_GRA
                    else LAT_GRA := 'N '+LAT_GRA;

        for nada:=1 to length(LAT_MIN) do if LAT_MIN[nada]=' ' then LAT_MIN[nada]:='0';

        while length(LAT_MIN)<6 do LAT_MIN := '0'+LAT_MIN;

        ajusta_lat_dbm:=LAT_GRA+'~'+LAT_MIN;
end;

(*---------------------------------------------------------------------------
Cambia el formato de longitud de entrada
-15,33.800

al formato de salida
W015~33.800
icluyendo el signo +/- dependiendo de si es Este/Oeste

rellenado los ceros necesarios
---------------------------------------------------------------------------*)
function ajusta_lon_dbm(var LON:string):string;
var
        nada:integer;
        negativo: boolean;
        long,lonm : double;
        LON_GRA, LON_MIN : string;
begin
        val(LON,long,nada);
        long := long + 0.000001;
        str(int(long):3:0,LON_GRA);
        LON_GRA := trim(LON_GRA);

        lonm := (long - int(long))*60;
        str(abs(lonm):8:3,LON_MIN);
        LON_MIN := trim(LON_MIN);

        negativo := false;
        if LON_GRA[1]='-' then
        begin
                negativo := true;
                nada     := length(LON_GRA);
                LON_GRA  := copy(LON_GRA,2,nada-1);
        end;

        while length(LON_GRA)<3 do LON_GRA := '0'+LON_GRA;
        if negativo then LON_GRA := 'W'+LON_GRA
                    else LON_GRA := 'E'+LON_GRA;


        for nada:=1 to length(LON_MIN) do if LON_MIN[nada]=' ' then LON_MIN[nada]:='0';

        while length(LON_MIN)<6 do LON_MIN := '0'+LON_MIN;

        ajusta_lon_dbm:=LON_GRA+'~'+LON_MIN;
end;

(*---------------------------------------------------------------------------
Cambia el formato de longitud de entrada

al formato de salida
W015~33.800  -> 15.mmmmmmm
icluyendo el signo +/- dependiendo de si es Este/Oeste

rellenado los ceros necesarios
---------------------------------------------------------------------------*)
function ajusta_lat_wpt(var LAT:string):string;
var
        nada:integer;
        latg,latm : double;
        LAT_GRA, LAT_MIN : string;
begin
        LAT_GRA := copy(LAT,3,2);
        val(LAT_GRA,latg,nada);

        LAT_MIN := copy(LAT,6,6);
        val(LAT_MIN,latm,nada);

        latg := latg+latm/60;
        if pos('S',LAT)>0 then latg :=-latg;

        str((latg):15:6,LAT_GRA);

        ajusta_lat_wpt :=trim(LAT_GRA);
end;

(*---------------------------------------------------------------------------
Cambia el formato de longitud de entrada

al formato de salida
W015~33.800  -> 15.mmmmmmm
icluyendo el signo +/- dependiendo de si es Este/Oeste

rellenado los ceros necesarios
---------------------------------------------------------------------------*)
function ajusta_lon_wpt(var LON:string):string;
var
        nada:integer;
        long,lonm : double;
        LON_GRA, LON_MIN : string;
begin
        LON_GRA := copy(LON,2,3);
        val(LON_GRA,long,nada);

        LON_MIN := copy(LON,6,6);
        val(LON_MIN,lonm,nada);

        long := long+lonm/60;
        if pos('W',LON)>0 then long :=-long;

        str(long:15:6,LON_GRA);

        ajusta_lon_wpt :=trim(LON_GRA);
end;

{----------------------------------------------------------------------------
Escribe lnea de Aeropuertose fichero de WPT del Oziexplorer
ajustando color de texto, de fondo, tamao letra e icono

   1,APT,  39.552054,   2.740810,37962.5356874,  0, 1, 4,         0,     65535,aeropuerto, 0, 0,    0,   1111, 8, 0,25,0,10.0,2,,,
   2,NDB,  39.641685,   2.916016,37962.5365889, 13, 1, 4,       255,  16776960,ndb, 0, 0,    0,   -777, 8, 0,17,0,10.0,2,,,
   3,VOR,  39.435885,   2.758566,37962.5378872, 30, 1, 4,     65535,   8388608,vor, 0, 0,    0,   -777, 8, 0,17,0,10.0,2,,,
   4,INT,  39.431458,   3.019149,37962.5395314, 70, 1, 4,     65535,   8388736,int, 0, 0,    0,   -777, 8, 0,17,0,10.0,2,,,

obtiene datos de
ADD|APT|DAAG|DA-ALGERIA|ALGIERS|HOUARI BOUMEDIENE|N 36~41.670|E003~13.016|80|JA     //Argelia
ADD|NDB|CNL|VC-SRI LANKA|COLOMBO|BANDARANAIKE INTL|N 07~16.119|E079~57.057|315.0|L   //Colombo
ADD|VOR|ZEM|DA-ALGERIA|ZEMMOURI|ZEMMOURI|N 36~48.334|E003~38.219|116.60|VORDME|High    //Zemmouri
ADD|INT|ABJR|VG-BANGLADESH|N 23~06.049|E089~12.838     //Comentario

----------------------------------------------------------------------------}
procedure escribe_linea_wpt(linea:string);
Const
        pos_tipo    = 2;
        pos_indica  = 3;
        pos_lat     = 7;
        pos_lat_int = 5;
        pos_lon     = 8;
        pos_lon_int = 6;
        pos_altura  = 9;
var
        tipo,indica,lat,lon,altura,comentarios,mi_tipo:string;
begin
        tipo            := obtener_parametro(linea,'|',pos_tipo);
        indica          := obtener_parametro(linea,'|',pos_indica);
        if tipo='INT'
            then
                begin
                    lat   := obtener_parametro(linea,'|',pos_lat_int);
                    lon   := obtener_parametro(linea,'|',pos_lon_int);
                end
            else
                begin
                    lat   := obtener_parametro(linea,'|',pos_lat);
                    lon   := obtener_parametro(linea,'|',pos_lon);

                end;
         lat := ajusta_lat_wpt(lat);
         lon := ajusta_lon_wpt(lon);

         if tipo = 'APT' then
                        begin
                                mi_tipo := ',,0,1,4,0,65535,';
                                altura  := obtener_parametro(linea,'|',pos_altura);
                                comentarios := crea_coment_APT(linea);
                        end
                     else altura :='-777';              {quita altura si no es aeropuerto}

         if tipo = 'NDB' then
                        begin
                                mi_tipo := ',,108,1,4,255,16776960,';
                                comentarios := crea_coment_NDB(linea);
                        end;


        if tipo = 'VOR' then
                        begin
                                mi_tipo := ',,109,1,4,65535,8388608,';
                                comentarios := crea_coment_VOR(linea);
                        end;

        if tipo = 'INT' then
                        begin
                                mi_tipo := ',,70,1,4,65535,8388736,';
                                comentarios := crea_coment_INT(linea);
                        end;

        if es_linea_dbm(linea) then
        escribe('-1'+','+indica+','+lat+','+lon+mi_tipo+comentarios+',0,0,0,'+altura+',6,0,17,0,10.0,2,,,');
end;

{----------------------------------------------------------------------------
Asigna nombre al fichero de salida y graba la cabecera de WPT del Oziexplorer

Archivo de Waypoint (.wpt) cabecera del fichero a generar o leer

Lnea 1 : Informacin sobre el tipo y versin del archivo de waypoint.

Lnea 2 : Datum Geodsico en el que estn expresadas las posiciones de Latitud y Longitud
grabadas en el archivo de Waypoint viene heredado de la base de datos del Garmin aeronautico.

Lnea 3 : En esta lnea se puede especificar cul es el grado de reduccin o amplificacin
de un mapa. Tiene ms sentido usarlo cuando se utiliza la versin de OziExplorer para Windows CE,
pero tambin puede utilizarse con la versin para PC. Si hemos reducido el tamao de un mapa a
la mitad de su tamao original, no podremos usar el Archivo de Mapa *.map original si no se
indica el hecho de que usamos una imgen reducida usando esta lnea. Para ms informacin
sobre este particular, visita la ayuda de OziExplorerCE.
Nosotros no lo utilizaremos en el fichero originado - pendiente probar

Lnea 4 : Especifica la serie de Smbolos de iconos grficos para el GPS. Pueden ser garmin,
lei28, garmin16, etc. - nosotros la dejaremos en garmin - pendiente probar
----------------------------------------------------------------------------}
procedure abre_wpt_escritura(nombre : string);
const
   Linea1_oziwpt = 'OziExplorer Waypoint File Version 1.1 dbm2ozi(C)Rafael Len Rico rleonr@wanadoo.es';
   Linea2_oziwpt = 'WGS 84';
   Linea3_oziwpt = 'Reserved 2';
   Linea4_oziwpt = 'garmin';
begin
   abre_escritura(nombre);
   escribe(Linea1_oziwpt);
   escribe(Linea2_oziwpt);
   escribe(Linea3_oziwpt);
   escribe(Linea4_oziwpt);
end;


(*---------------------------------------------------------------------------
proceso dbm --> wpt
---------------------------------------------------------------------------*)
Procedure dbmtowpt(file1,file2:string);
var
        cadena:string;
        si    :boolean;
begin
        abre_lectura(file1);
        abre_wpt_escritura(file2);
  repeat
        lee (cadena,si);
        escribe_linea_wpt(cadena);
  until si;
  cierra_ficheros;
end;

(*---------------------------------------------------------------------------
proceso wpt --> dbm
---------------------------------------------------------------------------*)
procedure wpttodbm(file1,file2:string);
var
        cadena : string;
        si     : boolean;
begin
        abre_lectura(file1);
        abre_escritura(file2);

        escribe('// '+VERSION);
        escribe('');
  repeat
        lee(cadena, si);
        cadena :=lee_linea_wpt (cadena);
        if pos('ADD|',cadena)>0 then escribe(cadena);
  until si;
  cierra_ficheros;
end;

(*---------------------------------------------------------------------------
proceso principal que llama al resto MAIN
---------------------------------------------------------------------------*)
procedure elegir_proceso(file_input,file_output,parametro:string);
var
        cadena : string;
        es_wpt, es_dbm, si     : boolean;
begin
        es_dbm := false;
        es_wpt := false;
        tipo_wpt_dbm := parametro;

        abre_lectura(file_input);
  repeat
        lee(cadena, si);
        es_dbm := es_dbm or es_linea_dbm(cadena);
        es_wpt := es_wpt or es_linea_wpt(cadena);
  until si;
  close(file_INP);
{        writeln(es_dbm);
        writeln(es_wpt);
        writeln;
        pulsar_continuar;}
  if     (es_dbm and es_wpt) then mensaje_error;
  if not(es_dbm) and es_wpt then wpttodbm(file_input,file_output);
  if not(es_wpt) and es_dbm then dbmtowpt(file_input,file_output);

end;

(*---------------------------------------------------------------------------
Nos entrega el mensaje de error y de como usar el programa
---------------------------------------------------------------------------*)
procedure mensaje_error;
begin
        writeln(VERSION);
        writeln;
        writeln('Transforma un fichero de texto en formato AVIAdbm al');
        writeln('formato wpt de OZIEXPLORER y viceversa.');
        writeln;
        writeln('El programa analiza el fichero de entrada y realiza la conversion en sentido');
        writeln('correcto, puede crear un fichero dbm para editar con archivos segn el tercer');
        writeln('parmetro optativo. (vale Aeropuerto, Vor, NDB, Int, solo procesa primera letra)');
        writeln;
        writeln('Se necesita los nombres de los fichero de entrada y salida:');
        writeln('OZI2APTdbm input.fil output.fil [A|V|N|I]');
        writeln;
        writeln('EL PROGRAMA ES GRATUITO Y SE ENTREGA SIN NINGUN TIPO DE');
        writeln('GARANTIA, USTED ES EL UNICO RESPONSABLE SI LO USA, COMPRUEBE');
        writeln('QUE LOS DATOS DE SALIDA SON CORRECTOS.');
        writeln;
        Pulsar_continuar;
        exit;
end;
end.



