Thanks for the pointer folks.
I've cobbled together a python script to edit the ogimet output
I hope it works for you
I've done nothing clever to select the data, if the ogimet txt file format changes, some tweaks may be required.
# file to read ogimet SYNOP format files and write a SYNOP ascii file
# to read into Digital Atmosphere
#
from datetime import datetime
from pathlib import Path
import os
def readInteger(inputPrompt,low,high):
"""read integer within specific bounds"""
while True:
try:
number = int(input(inputPrompt))
except ValueError:
print('oops not an integer')
continue
if number >= low and number <= high:
return number
else:
print('try again, number out of range')
homeDir = Path('D:/meteorology_data/METEO/')
# check current time
now = datetime.now()
# select date and time to read ogimet txt files
# for specific countries
# typically Germany, Hungary, Portugal and Sweden in Europe
# go to
https://www.ogimet.com/synopsc.phtml.en
# set begin and end at same time if you like
# select the country and click send
# then save page as ...
# the file in "YYMMDDHH * ogimet * .txt" format
# I tend to use a previous file and change a few numbers
#
# a couple of lines to save typing in the year every time
if now.month<3:
useYear = readInteger("Please enter year ", now.year - 1, now.year)
else:
useYear = now.year
# enter the month, day and hour to process
useMonth = readInteger("Please enter month ", 1, 12)
# beware I don't check for days that aren't in a month
useDay = readInteger("Please enter day ", 1, 31)
useHour = readInteger("please enter hour ", 0, 23)
readTime = datetime(useYear, useMonth, useDay, useHour, 0, 0)
# create a time string to match the ogimet file date time
timeString = readTime.strftime("%Y%m%d%H%M")
# print("date time to use: ", timeString)
# create a glob string to search for files with the date format
globStr = readTime.strftime("%y%m%d%H")
# print("date time glob str:", globStr)
# I have a folder for each current month
monthFolder = Path(readTime.strftime("%Y-%m"))
# modify the path to the month folder for output
homeDir = homeDir / monthFolder
# select files of interest
fileList = []
fileList = list(homeDir.glob(globStr+'*ogimet*.txt'))
for k, workingFile in enumerate(fileList):
filePathStr = str(fileList[k])
outFileStr = filePathStr.replace(".txt",".asc")
print()
print("output file name", outFileStr)
# read file line-by-line and find AAXX with the timeString
# or lines starting with 333
ogimetFile = open(fileList[k])
with open(fileList[k]) as ogimetFile:
ogimetData = ogimetFile.readlines()
print('input file lines ',len(ogimetData))
# process the data
# skip header rows and find first line of SYNOP data
j=0
while "AAXX" not in ogimetData[j] and j in range(len(ogimetData)):
j=j+1
# open output file
outFile = open(outFileStr, "w")
# write each valid line
for i in range(j, len(ogimetData)):
if ogimetData
[0] == "\n" : # only a new line character
# blank line
print()
outFile.write("\n")
elif ogimetData[0] == "#":
# comment - do nothing
pass
elif "AAXX" in ogimetData and ogimetData[:12] == timeString:
# first line of data
print(ogimetData[13:23])
outFile.write(ogimetData[13:23]+"\n")
print(ogimetData[24:len(ogimetData)],end='') # new line already there
outFile.write(ogimetData[24:len(ogimetData)])
elif " 333 " in ogimetData[i] and ogimetData[i-1][:12] == timeString:
# second line SYNOP section three
print(ogimetData[i].lstrip(),end='') # new line already there
outFile.write(ogimetData[i].lstrip())
elif " 333 " in ogimetData[i-1] and ogimetData[i-2][:12] == timeString:
# the occasional third line
print(ogimetData[i].lstrip(),end='') # new line already there
outFile.write(ogimetData[i].lstrip())
# else:
# print("something odd happened")
outFile.close()
print("end of processing")