#!/usr/bin/env python3

import sys, os
sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'pccora'))
from pccora import *

from netCDF4 import Dataset

def convert2netcdf4(data, options, file):
	head = data['head']
	ident = data['ident']

	#data_data = data['data']
	hires_data = data['hires_data']

	rootgrp = Dataset(file, "w", format="NETCDF4")
	# Attributes
	rootgrp.category = "Radiosonde"
	rootgrp.instrument = "Vaisala"
	# TODO: or should we use launch_time?
	print(pccora_identification.build(ident))
	return
	rootgrp.start_datetime = ident['datetime']

	# Dimensions
	height_dimension = rootgrp.createDimension("height")
	height_dimension.parameter = "height"
	height_dimension.units = "metre"
	height_dimension.missing_value = "-32768"

	# Variables
	for container in hires_data:
		print(container)
		break
	rootgrp.close()


def main():
	file = '/home/kinow/Downloads/96010109.EDT'
	output = '/home/kinow/Downloads/96010109-nohead-noident-hires.nc'

	pccora_parser = PCCORAParser()
	pccora_parser.parse_file(file)

	# Data
	head = pccora_parser.get_header()
	ident = pccora_parser.get_identification()
	#syspar = pccora_parser.get_syspar()
	data = pccora_parser.get_data()
	hires_data = pccora_parser.get_hires_data()

	# Call function to print CSV
	convert2netcdf4(
		data=dict(head=head, ident=ident, data=data, hires_data=hires_data), 
		options=dict(),
		file=output)

if __name__ == '__main__':
	main()
@@ -125,16 +125,40 @@
 import *
+%0Afrom construct import *
 %0A%0Afrom n
@@ -178,16 +178,622 @@
  Dataset
+%0Aimport numpy as np%0A%0Ab2 = np.dtype('int16')%0Ab4 = np.dtype('int32')%0Ast = np.dtype('str_')%0A%0Adef get_type(subcon):%0A%09if Value == subcon.__class__:%0A%09%09return st%0A%09elif FormatField == subcon.__class__:%0A%09%09packer = subcon.packer%0A%09%09if packer.size == 2:%0A%09%09%09return b2%0A%09%09else:%0A%09%09%09return b4%0A%09else:%0A%09%09raise Exception(%22Unexpected subcon %22 + str(subcon))%0A%0Adef get_variable(dataset, subcon, name):%0A%09variable_type = get_type(subcon)%0A%09v = dataset.createVariable(name, variable_type, (%22height%22, ))%0A%09return v%0A%0Adef hashify_subcons(subcons):%0A%09h = dict()%0A%09for format_field in subcons:%0A%09%09h%5Bformat_field.name%5D = format_field%0A%09return h
 %0A%0Adef co
@@ -982,16 +982,189 @@
 TCDF4%22)%0A
+%0A%09# Dimensions%0A%09rootgrp.createDimension(%22height%22)%0A%09# height_dimension.parameter = %22height%22%0A%09# height_dimension.units = %22metre%22%0A%09# height_dimension.missing_value = %22-32768%22%0A%0A
 %09# Attri
@@ -1274,21 +1274,35 @@
 _time?%0A%09
-print
+d = hashify_subcons
 (pccora_
@@ -1320,258 +1320,178 @@
 ion.
-build(ident))%0A%09return%0A%09rootgrp.start_datetime = ident%5B'datetime'%5D%0A%0A%09# Dimensions%0A%09height_dimension = rootgrp.createDimension(%22height%22)%0A%09height_dimension.parameter = %22height%22%0A%09height_dimension.units = %22metre%22%0A%09height_dimension.missing_value = %22-32768%22
+subcons)%0A%09v = get_variable(rootgrp, d%5B'datetime'%5D, %22datetime%22)%0A%09print(v)%0A%09return%0A%09print(pccora_identification.build(ident))%0A%09rootgrp.start_datetime = ident%5B'datetime'%5D%0A%0A%09
 %0A%0A%09#

Add logic to script to guess data type from construct, generating a numpy data type