### Start API (Portuguese) Source: https://github.com/luisaraujo/api-tabua-mare/blob/master/README.md Initiates the API by providing a location code. Verify the locale code in 'arrLocations' (bdLocations.js). ```sh startAPI(10); ``` -------------------------------- ### Start API with Location Code and Prefix Source: https://github.com/luisaraujo/api-tabua-mare/blob/master/README.md Starts the API with a location code and an optional directory prefix if the API script is not in the same level as your application. ```sh startAPI(10, ".."); ``` -------------------------------- ### Start API with Location Code Source: https://github.com/luisaraujo/api-tabua-mare/blob/master/README.md Initiates the API by providing a location code. Ensure the locale code is valid and present in the 'locais' section. ```sh StartAPI (10); ``` -------------------------------- ### startAPI(idlocation, dir) Source: https://context7.com/luisaraujo/api-tabua-mare/llms.txt Initializes the API by loading the tide data for the specified location and starting the conversion process. `idlocation` is the index of the location in `arrLocations`, and `dir` is the path prefix for scripts if the application is in a subdirectory. ```APIDOC ## `startAPI(idlocation, dir)` ### Description Initializes the API by loading the PDF for the specified location and starting the conversion pipeline. The `idlocation` parameter is the numerical index of the location in the `arrLocations` array, and `dir` is the path prefix to locate the script folder if the application is in a different subdirectory. ### Parameters #### Path Parameters - **idlocation** (number) - Required - The index of the location in the `arrLocations` array. - **dir** (string) - Required - The prefix path to locate the script folder. ### Request Example ```javascript // Initialize the API for Porto de Maceió (index 24) // Second parameter: root directory prefix relative to the current page startAPI(24, "../../"); ``` ``` -------------------------------- ### Implement Logic in API Ready Source: https://github.com/luisaraujo/api-tabua-mare/blob/master/README.md Example of implementing custom logic within the APIready callback function to append tide data to an HTML element with the ID 'body'. ```javascript function APIready (data) { for(i=0; i Tábua de Maré - Porto de Maceió

``` -------------------------------- ### Initialize Tábua de Maré API Source: https://context7.com/luisaraujo/api-tabua-mare/llms.txt Call the `startAPI` function with the location ID and directory to initialize the API. This should be done after the API scripts have loaded. ```javascript startAPI(idlocation, dir) ``` -------------------------------- ### Configure Data Folder in bdLocations.js Source: https://context7.com/luisaraujo/api-tabua-mare/llms.txt Modify the `folder` variable in `bdLocations.js` to point to the directory containing the tide prediction PDFs for the desired year. Ensure the corresponding folder exists and contains the updated DHN PDFs. ```javascript var folder = "tables2024/"; ``` -------------------------------- ### Handle Tábua de Maré API Ready Callback Source: https://context7.com/luisaraujo/api-tabua-mare/llms.txt Implement the `APIready` callback function to receive tide data and implement your desired presentation logic, such as filtering by date or rendering charts. ```javascript function APIready(dados) { // Implement your logic here } ``` -------------------------------- ### Implement APIready Callback Source: https://context7.com/luisaraujo/api-tabua-mare/llms.txt This is a mandatory callback function that the API calls automatically upon completion of PDF processing. It receives tide data as an array of `TableDay` objects. Use this function to display or process the tide information. ```javascript // Implementação do callback APIready // "dados" é um Array de objetos TableDay com todas as medições do ano function APIready(dados) { // Exibe o nome da localidade (usando o índice salvo antes de chamar startAPI) var cod = 24; // Porto de Maceió $("#location").html(arrLocations[cod].name); // => "PORTO DE MACEIÓ" // Filtra apenas o dia de hoje var hoje = new Date(); var diaHoje = String(hoje.getDate()).padStart(2, "0"); var mesHoje = String(hoje.getMonth() + 1).padStart(2, "0"); var anoHoje = String(hoje.getFullYear()); var dataHoje = diaHoje + "/" + mesHoje + "/" + anoHoje; var registroHoje = dados.filter(function(d) { return d.date === dataHoje; }); if (registroHoje.length > 0) { var d = registroHoje[0]; // Estrutura de um objeto TableDay: // d.day => "SEG" | "TER" | "QUA" | "QUI" | "SEX" | "SAB" | "DOM" // d.date => "15/06/2023" // d.hour1 => "00:54" — horário da 1ª medição // d.height1 => "0.2" — altura em metros da 1ª medição // d.hour2 => "06:47" // d.height2 => "5.1" // d.hour3 => "13:09" // d.height3 => "0.4" // d.hour4 => "18:54" // d.height4 => "5.3" $("#list").append( "
  • " + d.date + " (" + d.day + ")
    " + "Medição 1: " + d.hour1 + " → " + d.height1 + "m
    " + "Medição 2: " + d.hour2 + " → " + d.height2 + "m
    " + "Medição 3: " + d.hour3 + " → " + d.height3 + "m
    " + "Medição 4: " + d.hour4 + " → " + d.height4 + "m" + "
  • " ); } else { $("#list").append("
  • Sem dados para hoje.
  • "); } console.log("Total de dias carregados:", dados.length); // ex: 365 } ``` -------------------------------- ### Integrate Tábua de Maré API Scripts Source: https://context7.com/luisaraujo/api-tabua-mare/llms.txt Include these scripts in your HTML to enable the Tábua de Maré API functionality. Ensure they are loaded before calling API functions. ```html ``` -------------------------------- ### Location Data Structure and Year Configuration Source: https://context7.com/luisaraujo/api-tabua-mare/llms.txt Global array mapping locations to display names and PDF file paths. The `folder` variable allows changing the base directory for PDFs to switch between years. ```javascript // Estrutura de cada entrada: arrLocations[índice] = { name: "NOME DO LOCAL", url: "pasta/arquivo.pdf" } // Localidades disponíveis (principais): arrLocations[0] // FUNDEADOURO DE SALINÓPOLIS arrLocations[5] // PORTO DE BELÉM arrLocations[10] // TERMINAL PORTUÁRIO DA PONTA DO FÉLIX arrLocations[12] // PORTO DO RECIFE arrLocations[15] // PORTO DO RIO DE JANEIRO-ILHA FISCAL arrLocations[24] // PORTO DE MACEIÓ arrLocations[30] // PORTO DE SANTOS-TORRE GRANDE arrLocations[38] // PORTO DE SALVADOR arrLocations[43] // PORTO DE VITÓRIA-CAPITANIA DOS PORTOS DO ES // Exemplo: trocar o ano dos dados sem mudar o código da aplicação // Em bdLocations.js, alterar: folder = "tables2023"; // aponta para a pasta com PDFs de 2023 // ou: folder = "tables2021"; // reverte para os dados de 2021 // Exemplo: obter o nome do local pelo índice console.log(arrLocations[38].name); // => "PORTO DE SALVADOR" console.log(arrLocations[38].url); // => "tables2023/salvador.pdf" // Uso com parâmetro via URL (exemplo idfromget): // Acesse: index.html?cod=38 var urls = window.location.search.substring(1).split("&"); var cod = null; for (var i = 0; i < urls.length; i++) { var parameter = urls[i].split("="); if (parameter[0] === "cod") cod = parseInt(parameter[1]); } cod = (cod === null || isNaN(cod)) ? 0 : cod; startAPI(cod, "../../"); ``` -------------------------------- ### API Ready Callback Function Source: https://github.com/luisaraujo/api-tabua-mare/blob/master/README.md A placeholder function to implement your custom logic. It receives the tide table data as an array. ```javascript function APIready (data) { } ``` -------------------------------- ### APIready(dados) Source: https://context7.com/luisaraujo/api-tabua-mare/llms.txt A mandatory callback function defined by the developer, automatically called by the API when PDF processing is complete. It receives `dados`, an array of `TableDay` objects containing all measurements for the selected location for the year. ```APIDOC ## `function APIready(dados)` ### Description This is a mandatory callback function that you, the developer, must define. The API automatically calls this function once the PDF processing is finished. It receives a single parameter, `dados`, which is an array of `TableDay` objects. Each object in the array represents tide measurements for a specific day of the year for the selected location. ### Parameters #### Path Parameters - **dados** (Array) - Required - An array of `TableDay` objects containing all tide measurements for the year. ### Response Example ```javascript // Implementation of the APIready callback // "dados" is an Array of TableDay objects with all measurements for the year function APIready(dados) { // Display the location name (using the index saved before calling startAPI) var cod = 24; // Porto de Maceió $("#location").html(arrLocations[cod].name); // => "PORTO DE MACEIÓ" // Filter for today's date var hoje = new Date(); var diaHoje = String(hoje.getDate()).padStart(2, "0"); var mesHoje = String(hoje.getMonth() + 1).padStart(2, "0"); var anoHoje = String(hoje.getFullYear()); var dataHoje = diaHoje + "/" + mesHoje + "/" + anoHoje; var registroHoje = dados.filter(function(d) { return d.date === dataHoje; }); if (registroHoje.length > 0) { var d = registroHoje[0]; // Structure of a TableDay object: // d.day => "SEG" | "TER" | "QUA" | "QUI" | "SEX" | "SAB" | "DOM" // d.date => "15/06/2023" // d.hour1 => "00:54" — time of the 1st measurement // d.height1 => "0.2" — height in meters of the 1st measurement // d.hour2 => "06:47" // d.height2 => "5.1" // d.hour3 => "13:09" // d.height3 => "0.4" // d.hour4 => "18:54" // d.height4 => "5.3" $("#list").append( "
  • " + d.date + " (" + d.day + ")
    " + "Medição 1: " + d.hour1 + " → " + d.height1 + "m
    " + "Medição 2: " + d.hour2 + " → " + d.height2 + "m
    " + "Medição 3: " + d.hour3 + " → " + d.height3 + "m
    " + "Medição 4: " + d.hour4 + " → " + d.height4 + "m" + "
  • " ); } else { $("#list").append("
  • Sem dados para hoje.
  • "); } console.log("Total de dias carregados:", dados.length); // e.g., 365 } ``` ``` -------------------------------- ### Scraping Proxy for Tide Data Source: https://context7.com/luisaraujo/api-tabua-mare/llms.txt PHP script acting as a proxy to bypass CORS restrictions when fetching tide data from the Brazilian Navy website. Handles post code, month, and year parameters. ```bash # Requisição de exemplo via curl # Parâmetros: cod=posto, mes=mês (0=Jan, 11=Dez), ano=ano curl "http://seu-servidor/getSite.php?cod=40140&mes=5&ano=2023" # Resposta esperada: URL gerada + HTML da página da DHN # => http://www.mar.mil.br/dhn/chm/box-previsao-mare/tabuas/40140Jun2023.htm # => ...(conteúdo da tábua de maré)... # Mapeamento de meses (parâmetro numérico → abreviação em português): # 0=Jan, 1=Fev, 2=Mar, 3=Abr, 4=Mai, 5=Jun # 6=Jul, 7=Ago, 8=Set, 9=Out, 10=Nov, 11=Dez ``` -------------------------------- ### Validate Day Name Abbreviations Source: https://context7.com/luisaraujo/api-tabua-mare/llms.txt Auxiliary function to identify valid Portuguese day name abbreviations in extracted text. Distinguishes tide data entries from other numbers. ```javascript // Retorna true para abreviações válidas em português isDayName("SEG"); // true — Segunda-feira isDayName("TER"); // true — Terça-feira isDayName("QUA"); // true — Quarta-feira isDayName("QUI"); // true — Quinta-feira isDayName("SEX"); // true — Sexta-feira isDayName("SAB"); // true — Sábado isDayName("DOM"); // true — Domingo isDayName("MON"); // false — abreviação em inglês não reconhecida isDayName("123"); // false isDayName(""); // false ``` -------------------------------- ### Parse PDF Text Data Source: https://context7.com/luisaraujo/api-tabua-mare/llms.txt Parses raw text extracted from DHN format PDFs into structured table data. Handles normalized spaces and negative tide heights. Assumes a fixed line format for tide data. ```javascript // Formato de linha esperado no texto do PDF (DHN): // "01 SEG 0054 0.2 0647 5.1 1309 0.4 1854 5.3" // ^dia ^nome ^h1 ^a1 ^h2 ^a2 ^h3 ^a3 ^h4 ^a4 // Exemplo de uso direto do parser (normalmente chamado internamente): var textoExtraido = "2023 ... 01 SEG 0054 0.2 0647 5.1 1309 0.4 1854 5.3 02 TER ..."; var resultado = parseText(textoExtraido.replace(/\s+/g, " ")); console.log(resultado[0]); // Saída esperada: // { // day: "SEG", // date: "01/01/2023", // hour1: "00:54", // height1: "0.2", // hour2: "06:47", // height2: "5.1", // hour3: "13:09", // height3: "0.4", // hour4: "18:54", // height4: "5.3" // } // Suporte a alturas negativas (maré abaixo de zero): // Linha: "15 QUI 0312 -0.1 0901 4.8 1512 -0.2 2103 5.0" // resultado[x].height1 => "-0.1" // resultado[x].height3 => "-0.2" ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.