Index: /trunk/tools/nc_var_tools.py
===================================================================
--- /trunk/tools/nc_var_tools.py	(revision 1399)
+++ /trunk/tools/nc_var_tools.py	(revision 1400)
@@ -44,4 +44,5 @@
 # compute_tevolboxtraj: Function to compute tevolboxtraj: temporal evolution at a given point along a box following a trajectory
 # compute_tevolboxtraj_radialsec: Function to compute tevolboxtraj_radialsec: temporal evolution at a given point along a number of radii at a given frequency following a trajectory
+# curve_section: Function to provide a section of a file following a given curve
 # DataSetSection: Function to get a section (values along a dimension) of a given data-set
 # DataSetSection_multidims: Function to get a section (values along multiple dimensions) of a given data-set
@@ -258,9 +259,10 @@
 
     for dn in dnames:
-        print '  ' + fname + ': adding dim:',dn,' ...'
-        if oc.dimensions[dn].isunlimited():
-            newdim = nc.createDimension(dn, None)
-        else:
-            newdim = nc.createDimension(dn, len(oc.dimensions[dn]))
+        if not gen.searchInlist(nc.dimensions, dn):
+            print '  ' + fname + ': adding dim:',dn,' ...'
+            if oc.dimensions[dn].isunlimited():
+                newdim = nc.createDimension(dn, None)
+            else:
+                newdim = nc.createDimension(dn, len(oc.dimensions[dn]))
 
     nc.sync()
@@ -18438,11 +18440,11 @@
           [iBL],[jBL] to `right-up' grid point [iUR],[jUR] and [Ncurve] number of line-points with 
           [xdimn],[ydimn] name of the x and y dimensions
-        'lonlatline',[londimn]|[lonvarname],[latdimn]|[latvarname],[iSW],[jSW],[iNE],[jNE],[Ncurve]: line from starting 
-          `SW' lonlat point [lonSW],[latSW] to `NE' lonlat point [lonNE],[latNE] and [Ncurve] line-points 
+        'lonlatline',[londimn]|[lonvarname],[latdimn]|[latvarname],[lonSW],[latSW],[lonNE],[latNE],[Ncurve]: line from  
+          starting `SW' lonlat point [lonSW],[latSW] to `NE' lonlat point [lonNE],[latNE] and [Ncurve] line-points 
           with '[lon/latdimn]|[lon/latvarn]' name of the dimension and variable-dimension of longitude
           and latitude
-        'gridfilecurve',[xdimn],[ydimn],[curvefile]: line following grid-values in the file 
+        'gridfilecurve',[xdimn],[ydimn],[curvefile]: curve following grid-values in the file 
           [curvefile](x y; two columns space separated, '#' commment) with [xdimn],[ydimn] name of the x and y dimensions
-        'lonlatfilecurve',[londimn]|[lonvarname],[latdimn]|[latvarname],[curvefile]: line following 
+        'lonlatfilecurve',[londimn]|[lonvarname],[latdimn]|[latvarname],[curvefile]: curve following 
           lonlat-values in the file [curvefile](lon lat; two columns space separated, '#' commment) with 
           '[lon/latdimn]|[lon/latvarn]' name of the dimension and variable-dimension of longitude
@@ -18524,6 +18526,6 @@
         curve = np.zeros((Ncurve,2), dtype=np.float)
         for icv in range(Ncurve):
-            curve[icv,0] = lonSW + Dycurve*icv
-            curve[icv,1] = latSW + Dxcurve*icv
+            curve[icv,0] = latSW + Dycurve*icv
+            curve[icv,1] = lonSW + Dxcurve*icv
 
     elif values.split(',')[0] == 'gridfilecurve':
@@ -18627,5 +18629,6 @@
 
     # Getting curve-values
-    loccurve, curvewgts, Nwgts, curveloc3x3 = gen.curvelocalize_2D(curve,xvals,yvals)
+    loccurve, curvewgts, Nwgts, curveloc3x3, exctloccurve = gen.curvelocalize_2D(    \
+      curve,xvals,yvals)
 
     # Creation of file
@@ -18647,5 +18650,64 @@
     basicvardef(newvar,'ycurve', 'y-' +Lcurvey+ ' localization of the curve', cyunit)
 
-    # variables
+    # variable curvetype
+    curvetype = values.split(',')[0]
+    newvar = newnc.createVariable(curvetype, 'c')
+    if curvetype == 'gridline':
+        desc = "line from starting `bottom-left` grid point [iBL],[jBL] to " +       \
+          "`right-up` grid point [iUR],[jUR] and [Ncurve] number of line-points " +  \
+          "with [xdimn],[ydimn] name of the x and y dimensions"
+        set_attributek(newvar,'description',desc,'S')
+        set_attributek(newvar,'xdimn',xdimn,'S')
+        set_attributek(newvar,'ydimn',ydimn,'S')
+        set_attributek(newvar,'iBL',iBL,'I')
+        set_attributek(newvar,'jBL',jBL,'I')
+        set_attributek(newvar,'iUR',iUR,'I')
+        set_attributek(newvar,'jUR',jUR,'I')
+        set_attributek(newvar,'Ncurve',Ncurve,'I')
+    elif curvetype == 'lonlatline':
+        desc = "line from starting `SW` lonlat point [lonSW],[latSW] to `NE` " +     \
+          "lonlat point [lonNE],[latNE] and [Ncurve] line-points with " +            \
+          "`[lon/latdimn]|[lon/latvarn]` name of the dimension and " +               \
+          "variable-dimension of longitude and latitude"
+        set_attributek(newvar,'description',desc,'S')
+        set_attributek(newvar,'londimn',xdimn,'S')
+        set_attributek(newvar,'lonvarname',xvardimn,'S')
+        set_attributek(newvar,'latdimn',ydimn,'S')
+        set_attributek(newvar,'latvarname',yvardimn,'S')
+        set_attributek(newvar,'lonSW',lonSW,'R')
+        set_attributek(newvar,'latSW',latSW,'R')
+        set_attributek(newvar,'lonNE',lonNE,'R')
+        set_attributek(newvar,'latNE',latNE,'R')
+        set_attributek(newvar,'Ncurve',Ncurve,'I')
+    elif curvetype == 'gridfilecurve':
+        desc = "curve following grid-values in the file [curvefile](x y; two " +     \
+          "columns space separated, `#` commment) with [xdimn],[ydimn] name of " +   \
+          "the x and y dimensions"
+        set_attributek(newvar,'description',desc,'S')
+        set_attributek(newvar,'xdimn',xdimn,'S')
+        set_attributek(newvar,'ydimn',ydimn,'S')
+        set_attributek(newvar,'curvefile',curvefile,'S')
+    elif curvetype == 'lonlatfilecurve':
+        desc = "curve following lonlat-values in the file [curvefile](lon lat; " +   \
+          "two columns space separated, `#` commment) with `[lon/latdimn]|" +        \
+          "[lon/latvarn]` name of the dimension and variable-dimension of " +        \
+          "longitude and latitude"
+        set_attributek(newvar,'description',desc,'S')
+        set_attributek(newvar,'londimn',xdimn,'S')
+        set_attributek(newvar,'lonvarname',xvardimn,'S')
+        set_attributek(newvar,'latdimn',ydimn,'S')
+        set_attributek(newvar,'latvarname',yvardimn,'S')
+        set_attributek(newvar,'curvefile',curvefile,'S')
+
+    # Localization curve within file
+    newvar = newnc.createVariable('icurve', 'f8', ('curve'))
+    newvar[:] = exctloccurve[:,1]
+    basicvardef(newvar,'icurve', 'x-axis localization of the curve', '1')
+
+    newvar = newnc.createVariable('jcurve', 'f8', ('curve'))
+    newvar[:] = exctloccurve[:,0]
+    basicvardef(newvar,'jcurve', 'y-axis localization of the curve', '1')
+
+    # variable weight
     newvar = newnc.createVariable('weights', 'f', ('box','box','curve'))
     for icv in range(Ncurve):
@@ -18653,5 +18715,5 @@
     basicvardef(newvar,'weights', 'weights on the 3x3 around box following curve','1')
 
-    # variables
+    # variable Nweigth
     newvar = newnc.createVariable('Nweights', 'f', ('curve'))
     newvar[:] = Nwgts[:]
@@ -18659,5 +18721,5 @@
       'following curve', '-')
 
-    # variables
+    # variable coordweights
     newvar = newnc.createVariable('coordweights', 'f', ('pt','boxbox','curve'))
     for icv in range(Ncurve):
@@ -18666,4 +18728,5 @@
       '3x3 around box following curve', '-')
 
+    # File variables to get the section
     for vn in varns:
         if not onc.variables.has_key(vn):
@@ -18676,18 +18739,28 @@
 
         ovar = onc.variables[vn]
-        dimvar = list(ovar.dimensions)
-        if gen.searchInlist(dimvar, xdimn): dimvar.remove(xdimn)
-        if gen.searchInlist(dimvar, ydimn): dimvar.remove(ydimn)
-
-        varcurve = interp_curve(ovar, xdimn, ydimn, loccurve, curvewgts, Nwgts,      \
-          curveloc3x3)
-
-        # Writing values of variable along the curve
-        add_dims(onc,newnc,dimvar)
-
-        newvar = newnc.createVariable(vn+'curve', 'f4', tuple(dimvar+['curve']))
-        newvar[:] = varcurve[:]
-        add_varattrs(onc,newnc,[vn],[vn+'curve'])
-        set_attribute(newvar,'along','xcurve,ycurve')
+        if len(ovar.shape) == 0:
+            print warnmsg
+            print '  ' +fname+ ": scalar variable '" + vn + "' section impossible !!"
+            newvar = newnc.createVariable(vn, ovar.dtype)
+            newvar[:] = ovar[:]
+            add_varattrs(onc,newnc,[vn],[vn])
+        else:
+            print '    ' + fname + ": adding section of '" + vn + "' ..."
+            dimvar = list(ovar.dimensions)
+            if gen.searchInlist(dimvar, xdimn): dimvar.remove(xdimn)
+            if gen.searchInlist(dimvar, ydimn): dimvar.remove(ydimn)
+
+            varcurve = interp_curve(ovar, xdimn, ydimn, loccurve, curvewgts, Nwgts, \
+              curveloc3x3)
+
+            # Writing values of variable along the curve
+            add_dims(onc,newnc,dimvar)
+
+            newvar = newnc.createVariable(vn+'curve', 'f4', tuple(dimvar+['curve']))
+            newvar[:] = varcurve[:]
+            add_varattrs(onc,newnc,[vn],[vn+'curve'])
+            set_attribute(newvar,'along','xcurve,ycurve')
+            set_attribute(newvar,'curve',curvetype)
+            newnc.sync()
  
     # Global attributes
@@ -18708,6 +18781,3 @@
     return
 
-values = 'gridline,x,y,8.,8.,16.,16.,32'
-curve_section(values,'/home/lluis/PY/test.nc','var')
-
 #quit()
