Simple RINEX Processing Script

This article describes the batch file which ships with SNIP (from Rev 3.19 onward) in a line-by-line fashion.  The intent is to educate so that you can easily edit the file to suit your own needs.  No particular knowledge of Windows batch scripts is presumed, but this can be very helpful. Many web based teaching resources can be found at the prior link.

Hint:  To download a clean copy of the batch script (in a zipped file format), click here.

Best practice: Rename the script whenever you edit it. Then link to the new file in RINEX part of the Data Logging Settings dialog by entering the file path and file name in the RINEX Bat File Location text box.

The batch file begins with a few comment lines (“REM” = remark) that serve to explain the basic purpose of the file and give a time stamp when last edited.  The command @echo off removes the command prompt from appearing with each line as the batch script is run, so only the output results are displayed.

@echo off
REM
REM  A simple RINEX batch file you can modify to suit your own needs
REM  SCSC Simple NTRIP (R) Tools, Rev of Feb 18, 2026
REM

When the file is called by SNIP, a few variables (vars) are created or passed into the call as command line arguments.  We need to use those values to locate the files and the folder the script will operate on.  This is achieved with the below lines:

REM Where the program is to be found, hard code for your own machine
set "RTKLIB_BIN_PATH=C:\Users\First\OneDrive\Desktop\demo5L\"
REM Where data is to be found and saved to, use this method if not passed in by SNIP
REM set "INPUT_DIR=C:\Users\First\OneDrive\Documents\RINEXbatch\input"
REM set "OUTPUT_DIR=C:\Users\First\OneDrive\Documents\RINEXbatch\output"
REM Use below when SNIP sends in paths as command vars
set fileCnt=0
set INPUT_DIR=%1
set OUTPUT_DIR=%2

In above the pattern “set INPUT_DIR=%1” is the normal way to pass in a value from the command line assigning it to a var.  In this case we need to know where to look to process a set of matching files and where to put the resulting created files.  But it may be that during the debugging period you want to hard wire these values to observe the results.  The lines below (shown commented out) serve to fill that need.

REM set "INPUT_DIR=C:\Users\First\OneDrive\Documents\RINEXbatch\input"
REM set "OUTPUT_DIR=C:\Users\First\OneDrive\Documents\RINEXbatch\output"

If you were to use this, you would likely comment out the section assigning values from the command and un-comment these lines to assign the value directly.  The result would be something like the below.

set "INPUT_DIR= C:\Program Files (x86)\SNIP_3_16\bin\data\RINEX_RawFiles"
set "OUTPUT_DIR= C:\Program Files (x86)\SNIP_3_16\bin\data\RINEX_ProcessedFilesoutput"
set fileCnt=0
REM set INPUT_DIR=%1
REM set OUTPUT_DIR=%2

One method or the other would be used at any time (never both).  Once this logic is executed the script now knows what directory to look in to find the list of files to be processed.  In the next step, simply to be helpful, this information is echoed out to the console screen with the below fragment of code:

echo Running script to Convert Files from RTCM3 to RINEX... (Start time: %date% at %time%)
echo Inputs path is %INPUT_DIR%
echo Output path is %OUTPUT_DIR%

If the selected target folder is not present, we use the DOS command mkdir to create it:

REM Create output directory if it doesn't exist
if not exist "%OUTPUT_DIR%" mkdir "%OUTPUT_DIR%"

Now things can start to get interesting. We first create a for loop for every file that matches the pattern “*.dat” in the input directory.   We will then process every matching file until we are done.  If your raw data is not of type “.dat” (which is what SNIP defaults to when saving raw RTCM messages) you would replace that with the file type you use.

REM Loop through all raw data files in the input directory
for %%f in ("%INPUT_DIR%\*.dat") do (

   REM Here we will process each file in turn,
   REM see notes that follow
)

At this point the file (and its complete path) is represented by “%%f” and we will use that variable to operate on it.  We first save a copy of the name for deleting the file later, and then we echo out to the console the current file we are operating on.

    set deleteFile = "%%f"
    echo Converting "%%f" to RINEX...

Next comes the most critical line where we invoke the RINEX conversion tool and pass it the target file as well as various control settings to achieve  the conversion we want.  Here we are using the “convbin.exe” tool from RTKLIB, but there are many other tools that could also be used. After calling the tool (which will likely take many tens of seconds to run to completion on a 24 hour raw file) we then echo to the console that we have completed the translation.

"%RTKLIB_BIN_PATH%\convbin.exe" "%%f" -r rtcm3 -ti 10 -o "%OUTPUT_DIR%\%%~nf.obs"
echo RINEX Conversion complete for: "%%f"

The line calling the tool passes in a number of details which we now consider further. The variable RTKLIB_BIN_PATH  is simply the path where the tool can be found (set at the very start of the script, see lines above).  The text convbin.exe  is the name of the tool itself, the program to be run.  The next item is a command line variable  being passed into the program,  Recall that %%F is the current file and its path, here treated as the input file to process.  The command line argument “-r  rtcm3” means to decode the data in the file as RTCM3 message content. The argument “-ti 10“ means to set a time interval of every 10 seconds.  In other words the data is decimated to just one measurement every 10th second.  Remove this line or replace the value ten with the value one if you want a RINEX file with data at a 1Hz date.  If even less output data is wanted (some post processing systems want data no more often than 15 seconds), then increase the ten to be the value wanted.   Finally, the argument -o “%OUTPUT_DIR%\%%~nf.obs sets the output file path, name, and file type.  The extension  *.obs is a common file type used for RINEX observation files. When run, this command takes one raw data file containing RTCM3 messages and converts it to a RINEX file with a data decimation rate of one measurement every 10th second.

After this point we have a bit of clean up to do before processing the next file in the list of matching files.  First we have to remove the original file, and then we tell the user the full name and path of the file we have just created.

    del "%%f"
    echo Created file: "%%~nf.obs"

And then we compress the newly created RINEX file into a *.zip format (this is done simply to save disk space). We use the DOS tar command to do this and then delete the original file, and again inform the user with text echoed to the console.

    REM 'tar' requires Window 10 or better, use a 3rd party tool if needed
    if exist "%OUTPUT_DIR%\%%~nf.obs" do (
        REM use local paths to avoid creating folders in the ZIP file
        cd %OUTPUT_DIR%
        set /a fileCnt+=1
        tar.exe -a -c -f "%%~nf.zip" "%%~nf.obs"
        del "%OUTPUT_DIR%\%%~nf.obs"
        echo Zip of RINEX output file created: "%OUTPUT_DIR%\%%~nf.obs"
        echo Created Zip file: "%%~nf.zip"   -Note: the original *.obs file was removed
    )

The above is repeated for every matching file before the code drops out of the enclosing for loop.

At this point we have processed all matching files and simply need to tell the user we have completed things.

REM We presume the output folder is also an FTP site for others
REM Now remove any older files in the output folder, OBS or ZIP

echo Output files placed at "%OUTPUT_DIR%"
echo ...All Raw.dat (RTCM) to RINEX.obs files have now been processed (%fileCnt% files)
echo Ending time: %date% at %time%

The batch script then ends. It will be run again at the time interval you have set for it (in the Data Logging Settings dialog).

 

This article has described the default RINEX batch file which ships with SNIP in a line-by-line fashion.  Many additional features and logic could be added to it but these are left to the reader.

 

 

 

 

 

 

 

Was this article helpful?

Related Articles