Skip to content

Instantly share code, notes, and snippets.

@sq9ozh
Created March 24, 2013 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sq9ozh/5232449 to your computer and use it in GitHub Desktop.
Save sq9ozh/5232449 to your computer and use it in GitHub Desktop.
A groovy script for converting SOTA log files 2 adif file
package pl.sq9ozh.sota2adif
/**
* Sota log 2 ADIF converter
*
* Creation Date: 16.03.12
* @author SQ9OZH
* Public Domain
*/
def version='0.0.2'
println "sq9ozh - sota2adif log converter - $version"
if (this.args.size() != 1) {
println "usage sota2adif sotaLogFile.csv"
System.exit(1);
}
def csvName = this.args[0]
def csv = new File(csvName)
def adif = new File((csvName =~ /.csv$/).replaceFirst('.adi'))
adif.delete();
adif.createNewFile();
def convertDate = { sotaDate ->
Date.parse('dd/MM/yyyy', sotaDate).format('yyyyMMdd')
}
def convertTime = { sotaTime ->
Date.parse('HH:mm', sotaTime).format('HHmm')
}
def convertBand = { sotaBand ->
['VLF':'2190m', '1.8MHZ':'160m', '3.5MHZ':'80m', '5MHZ':'60m' , '7MHZ':'40m', '10MHZ':'30m', '14MHZ':'20m',
'18MHZ':'17m', '21MHZ':'15m', '24MHZ':'12m', '28MHZ':'10m', '50MHZ':'6m', '70MHZ':'4m', '144MHZ':'2m',
'220MHZ':'1.25m', '433MHZ':'70cm', '900MHZ':'33cm', '1240MHZ':'23cm', '2.3GHZ':'13cm', '3.4GHZ':'9cm',
'5.6GHZ':'6cm', '10GHZ':'3cm', '24GHZ':'1.25cm'].get(sotaBand.toUpperCase())
}
def convertMode = { sotaMode ->
['AM':'AM', 'CW':'CW', 'FM':'FM', 'SSB':'SSB'].get(sotaMode.toUpperCase())
}
adif << "this data was converted from sota log file ($csvName) at ${new Date()}\n"
adif << "<adif_ver:4>2.27<USERDEF1:7>SOTA<USERDEF2:7>MY_SOTA<USERDEF3:11:N>SOTA_POINTS<USERDEF4:17:N>SOTA_BONUS_POINTS<eoh>\n\n"
csv.splitEachLine(~ /,(?=([^"]*"[^"]*")*(?![^"]*"))/) { fields ->
call = fields[6]
if (call == 'Station worked')
return
adif << "<CALL:${call.size()}>$call"
band = convertBand(fields[4])
if (band)
adif << "<BAND:${band.size()}>$band"
mode = convertMode(fields[5])
if (mode)
adif << "<MODE:${mode.size()}>$mode\n"
qsoDate = convertDate(fields[1])
adif << "<QSO_DATE:${qsoDate.size()}>$qsoDate"
qsoTime = convertTime(fields[2])
adif << "<TIME_ON:${qsoTime.size()}>$qsoTime\n"
sota = fields[3]
sotaPoints = fields[8]
sotaBonusPoints = fields[9]
if (sotaPoints && !sotaBonusPoints)
adif << "<SOTA:${sota.size()}>$sota"
else
adif << "<MY_SOTA:${sota.size()}>$sota"
if (sotaPoints)
adif << "<SOTA_POINTS:${sotaPoints.size()}>$sotaPoints"
if (sotaBonusPoints)
adif << "<SOTA_BONUS_POINTS:${sotaBonusPoints.size()}>$sotaBonusPoints"
station = fields[0]
adif << "\n<STATION_CALLSIGN:${station.size()}>$station"
comment = fields[7]
if (comment)
adif << "\n<COMMENT:${comment.size()}>$comment"
adif << "<eor>\n\n"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment