<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Convert a CSV data file to netCDF file
read the CSV file
generate the gridfile from the CSV lon and lat values
write data to file
write netcdf file
Input data
data/input.csv
Step1:  For the sake of simplicity
Step2:  Read the CSV data
Step3:  Get the longitude, latitude and data values of the data columns
Step4:  Get size of the coordinates
Step5:  Print some information
Step6:  Set variable name
Step7:  Set time and reference time
Step8:  Write value array to file data/var.txt
Step9:  Write grid description file
Step10:  CDO command
<ASSISTANT_TASK:>
Python Code:
import numpy as np
from cdo import *
Explanation: Convert a CSV data file to netCDF file
read the CSV file
generate the gridfile from the CSV lon and lat values
write data to file
write netcdf file
Input data
data/input.csv:
lon, lat, value
5.0, 40.0, 1000
5.0, 41.0, 1000
5.0, 42.0, 1200
5.0, 44.0, 1600
5.5, 40.0, 1000
5.5, 41.0, 1000
5.5, 42.0, 1200
5.5, 44.0, 1600
6.0, 40.0, 1300
6.0, 42.0, 1700
6.0, 44.0, 1900
6.0, 45.0, 2000
...
Output file
input.nc
</br></br>
End of explanation
cdo = Cdo()
Explanation: For the sake of simplicity
End of explanation
csv_data = np.genfromtxt('data/input.csv', usecols=(0, 1, 2), skip_header=1, 
                          dtype=None, delimiter=',')
Explanation: Read the CSV data
End of explanation
lon = list(map(float, csv_data['f0']))
lat = list(map(float, csv_data['f1']))
values = list(map(float, csv_data['f2']))
Explanation: Get the longitude, latitude and data values of the data columns
End of explanation
nlon = len(lon)
nlat = len(lat)
nlines = nlon
Explanation: Get size of the coordinates
End of explanation
print('--> longitudes:   ', lon)
print('--> # longitudes: %d' % nlon)
print('--> latitudes:    ', lat)
print('--> # latitudes:  %d' % nlat)
print('--> values:       ', values)
Explanation: Print some information
End of explanation
varname = 'var'
Explanation: Set variable name
End of explanation
time = '1950-01-01,12:00:00,1day'
Explanation: Set time and reference time
End of explanation
fv = open('data/var.txt', 'w')
[fv.write(str(s)+'\n') for s in values]
fv.close()
Explanation: Write value array to file data/var.txt
End of explanation
f = open('data/gridfile.txt', 'w')
f.write('gridtype  = unstructured'+'\n')
f = open('data/gridfile.txt', 'a')
f.write('gridsize  = '+str(nlines)+'\n')
f.write('xname     = lon'+'\n')
f.write('xlongname = longitude'+'\n')
f.write('xunits    = degrees_east'+'\n')
f.write('yname     = lat'+'\n')
f.write('ylongname = latitude'+'\n')
f.write('yunits    = degrees_north'+'\n')
f.write('xsize     = ' + str(nlon)+'\n')
f.write('ysize     = ' + str(nlat)+'\n')
f.write('xvals     = ' + ', '.join(str(x) for x in tuple(lon))+'\n')
f.write('yvals     = ' + ', '.join(str(x) for x in tuple(lat))+'\n')
f.close()
Explanation: Write grid description file
End of explanation
cdo.settaxis(
        time, 
        input='-setname,'+varname+ \
        ' -input,data/gridfile.txt < data/var.txt',
        output='input.nc',
        options = '-f nc')
Explanation: CDO command
End of explanation
<END_TASK>