Index: trunk/tools/TS_ASCII_netCDF.py
===================================================================
--- trunk/tools/TS_ASCII_netCDF.py	(revision 351)
+++ trunk/tools/TS_ASCII_netCDF.py	(revision 352)
@@ -1,4 +1,4 @@
 # Python script to transfomr ASCII LIDAR outputs to netCDF
-## g.e. # TS_ASCII_netCDF.py -f //media/ExtDiskD/bkup/ciclad/etudes/WL_HyMeX/iop15/wrf/run/control/stations_20121018000000-20121022000000/h0001.d01.TS
+## g.e. # TS_ASCII_netCDF.py -f //media/ExtDiskD/bkup/ciclad/etudes/WL_HyMeX/iop15/wrf/run/control/stations_20121018000000-20121022000000/h0001.d01.TS -s 20121018000000
 
 import os
@@ -18,5 +18,7 @@
 parser = OptionParser()
 parser.add_option("-f", "--TS_file", dest="lfile",
-                  help="Time Series ASCII text file to use", metavar="FILE")
+  help="Time Series ASCII text file to use", metavar="FILE")
+parser.add_option("-s", "--SimulationStartTime", dest="stime",
+  help="Starting time of the simulation ([YYYY][MM][DD][HH][MI][SS] format)", metavar="DATE")
 
 (opts, args) = parser.parse_args()
@@ -27,5 +29,5 @@
 tsvln = ['2 m Temperature', '2 m vapor mixing ratio', '10 m U wind (earth-relative)', '10 m V wind (earth-relative)', 'surface pressure', 'downward longwave radiation flux at the ground (downward is positive)', 'net shortwave radiation flux at the ground (downward is positive)', 'surface sensible heat flux (upward is positive)', 'surface latent heat flux (upward is positive)', 'skin temperature', 'top soil layer temperature', 'rainfall from a cumulus scheme', 'rainfall from an explicit scheme', 'total column-integrated water vapor and cloud variables']
 
-tsvu = ['K', 'kg/kg', 'm/s', 'm/s', 'Pa', 'W/m2', 'W/m2', 'W/m2', 'W/m2', 'K', 'K', 'mm', 'mm', 1']
+tsvu = ['K', 'kg/kg', 'm/s', 'm/s', 'Pa', 'W/m2', 'W/m2', 'W/m2', 'W/m2', 'K', 'K', 'mm', 'mm', '1']
 
 #######    #######
@@ -38,7 +40,17 @@
 if not os.path.isfile(opts.lfile):
     print errormsg
-    print '  Time-Series ASCII text file "' + opts.lfile + '" does not exist !!'
+    print '  ' + main + ': Time-Series ASCII text file "' + opts.lfile +             \
+      '" does not exist !!'
     print errormsg
     quit()
+
+if opts.stime is None:
+    print errormsg
+    print '  ' + main + ': No initial date/time of the simulation is provided!'
+    quit(-1)
+else:
+    stime = opts.stime
+    refdate = stime[0:4] + '-' + stime[4:6] + '-' + stime[6:8] + ' ' + stime[8:10] + \
+      ':' + stime[10:12] + ':' + stime[12:14]
 
 objlfile = open(opts.lfile, 'r')
@@ -91,65 +103,38 @@
         ncvar.set_attribute(newvar, 'model_height',                                  \
           np.float(values[13].replace(',','').replace('(','').replace(')','')) )
-        simstarttime = values[18]
+        simstarttime = refdate
     else:
         tsvals[itz] = values
+        time_step.append(np.float(values[1]))
+        itz = itz + 1
     iline = iline + 1
 
 dimt = len(time_step)
 
-print '  Found:',dimt,'time steps, over:',dimz,'vertical levels'
+print '  Found:',dimt,'time steps'
 objlfile.close()
 
-objofile.createDimension('z',dimz)
-
 time_stepv = np.zeros((dimt), dtype=np.float)
-psfcv = np.zeros((dimt), dtype=np.float)
-raincv = np.zeros((dimt), dtype=np.float)
-rainncv = np.zeros((dimt), dtype=np.float)
-drydensv = np.zeros((dimt), dtype=np.float)
-
-tsvaluesv = np.zeros( (dimt,dimz,Ntsvariables), dtype= np.float)
+tsvaluesv = np.zeros( (dimt,Ntsvariables), dtype= np.float)
 
 itz = 0
 for it in range(dimt):
     time_stepv[it] = np.float(time_step[it])
-    psfcv[it] = np.float(psfc[it])
-    raincv[it] = np.float(rainc[it])
-    rainncv[it] = np.float(rainnc[it])
-    drydensv[it] = np.float(drydens[it])
 
-    for iz in range(dimz):
-        for iv in range(Ntsvariables):
-            tsvaluesv[it,iz,iv] = np.float(tsvals[itz][iv+1])
+    for iv in range(Ntsvariables):
+        tsvaluesv[it,iv] = np.float(tsvals[itz][iv+5])
 
-        itz = itz + 1
+    itz = itz + 1
 # Surface variables
-newvar = objofile.createVariable('time','f4',('time',))
+newvar = objofile.createVariable('time','f8',('time'))
 newvar[:] = time_stepv
 newattr = ncvar.basicvardef(newvar, 'time', 'time', 'hours since ' +                 \
   simstarttime.replace('_',' '))
+ncvar.set_attribute(newvar, 'calendar', 'standard')
 
-newvar = objofile.createVariable('psfc','f4',('time',))
-newvar[:] = psfcv
-newattr = ncvar.basicvardef(newvar, 'psfc', 'surface pressure', 'hPa')
-
-newvar = objofile.createVariable('rainc','f4',('time',))
-newvar[:] = raincv
-newattr = ncvar.basicvardef(newvar, 'rainc',                                         \
-  'accumulated precipitation from cumulus scheme', 'mm')
-
-newvar = objofile.createVariable('rainnc','f4',('time',))
-newvar[:] = rainncv
-newattr = ncvar.basicvardef(newvar, 'rainnc',                                        \
-  'accumulated precipitation not from cumulus scheme', 'mm')
-
-newvar = objofile.createVariable('drydens','f4',('time',))
-newvar[:] = drydensv
-newattr = ncvar.basicvardef(newvar, 'drydens', 'total dry air column pressure', 'hPa')
-
-# Lidar variables
+# time-series variables
 for iv in range(Ntsvariables):
-    newvar = objofile.createVariable(tsvn[iv], 'f4', ('time','z'))
-    newvar[:] = tsvaluesv[:,:,iv]
+    newvar = objofile.createVariable(tsvn[iv], 'f4', ('time'))
+    newvar[:] = tsvaluesv[:,iv]
     newattr = ncvar.basicvardef(newvar, tsvn[iv], tsvln[iv], tsvu[iv] )
 
@@ -157,3 +142,3 @@
 objofile.close()
 
-print 'Successfull generation of LIDAR netCDF file "' + ofile + '" !!!!!'
+print 'Successfull generation of Time-Series netCDF file "' + ofile + '" !!!!!'
