Index: trunk/tools/nc_var.py
===================================================================
--- trunk/tools/nc_var.py	(revision 692)
+++ trunk/tools/nc_var.py	(revision 693)
@@ -34,5 +34,5 @@
   'maskvar',                                                                         \
   'ncreplace', 'ncstepdiff', 'netcdf_concatenation', 'netcdf_fold_concatenation',    \
-  'remapnn',                                                                         \
+  'Partialmap_Entiremap', 'remapnn',                                                 \
   'seasmean', 'sellonlatbox', 'sellonlatlevbox', 'selvar', 'setvar_asciivalues',     \
   'sorttimesmat', 'spacemean', 'SpatialWeightedMean', 'statcompare_files', 'submns', \
@@ -207,4 +207,6 @@
 elif oper == 'remapnn':
     ncvar.remapnn(opts.values, opts.ncfile, opts.varname)
+elif oper == 'Partialmap_Entiremap':
+    ncvar.Partialmap_Entiremap(opts.values, opts.ncfile, opts.varname)
 elif oper == 'seasmean':
     ncvar.seasmean(timename, opts.ncfile, opts.varname)
Index: trunk/tools/nc_var_tools.py
===================================================================
--- trunk/tools/nc_var_tools.py	(revision 692)
+++ trunk/tools/nc_var_tools.py	(revision 693)
@@ -17747,4 +17747,7 @@
         Nlat = int(np.pi * EarthR / dyres) + 1
 
+        if np.mod(Nlon,2) == 0: Nlon = Nlon + 1
+        if np.mod(Nlat,2) == 0: Nlat = Nlat + 1
+
         lonProj = np.zeros((Nlon), dtype=np.float)
         latProj = np.zeros((Nlat), dtype=np.float)
@@ -17821,7 +17824,7 @@
         newdim = onewnc.createDimension('y', dimy)
         newdim = onewnc.createDimension('Npts', Npts)
-        newdim = onewnc.createDimension('Ncoord', 2)
-        newdim = onewnc.createDimension('xcirc', Nlonmaxcirc)
-        newdim = onewnc.createDimension('ycirc', Nlat)
+        if project == 'lonlat_dxdyFix':
+            newdim = onewnc.createDimension('xcirc', Nlonmaxcirc)
+            newdim = onewnc.createDimension('ycirc', Nlat)
 
 # Variables
@@ -17832,15 +17835,4 @@
         newvar.setncattr('_CoordinateAxisType', 'Lon')   
 
-# Longitudes sorted by latitudes
-        if len(Npoints.shape) == 1:
-            newvar = onewnc.createVariable('Nloncirc', 'i', ('ycirc'))
-            newvar[:] = Nloncirc
-            basicvardef(newvar, 'Nloncirc', 'Number of longitudes by latitude circs', '-')
-
-            newvar = onewnc.createVariable('loncirc', 'f8', ('ycirc','xcirc'))
-            basicvardef(newvar, 'longitude', 'Longitude by latitude circs', 'degrees_East')
-            for iL in range(Nlat):
-                newvar[iL,0:Nloncirc[iL]] = np.asarray(lonProjcirc[iL])
-
         newvar = onewnc.createVariable('lat', 'f8', ('y'))
         basicvardef(newvar, 'latitude', 'Latitude', 'degrees_North')
@@ -17849,7 +17841,18 @@
         newvar.setncattr('_CoordinateAxisType', 'Lat')   
 
-        newvar = onewnc.createVariable('latcirc', 'f8', ('ycirc'))
-        basicvardef(newvar, 'latitude', 'Latitude', 'degrees_North')
-        newvar[:] = latProjcirc
+# Specific variables
+        if project == 'lonlat_dxdyFix':
+            newvar = onewnc.createVariable('Nloncirc', 'i', ('ycirc'))
+            newvar[:] = Nloncirc
+            basicvardef(newvar, 'Nloncirc', 'Number of longitudes by latitude circs', '-')
+
+            newvar = onewnc.createVariable('loncirc', 'f8', ('ycirc','xcirc'))
+            basicvardef(newvar, 'longitude', 'Longitude by latitude circs', 'degrees_East')
+            for iL in range(Nlat):
+                newvar[iL,0:Nloncirc[iL]] = np.asarray(lonProjcirc[iL])
+
+            newvar = onewnc.createVariable('latcirc', 'f8', ('ycirc'))
+            basicvardef(newvar, 'latitude', 'Latitude', 'degrees_North')
+            newvar[:] = latProjcirc
 
         if len(Npoints.shape) == 2:
@@ -17876,15 +17879,15 @@
         print fname + "Successfull written of '" + ofile + "' !!'"
 
-    if len(Npoints.shape) == 2:
+    if project == 'lonlat':
         return lonProj, latProj
-    else:
+    elif project == 'lonlat_dxdyFix':
         return lonProjcirc, latProj
 
-#lonlatProj(100000.,100000.,'lonlat_dxdyFix',True)
+#lonlatProj(100000.,100000.,'lonlat',True)
 #quit()
 
 def Partialmap_Entiremap(values, filen, varn):
     """ Function to transform from a partial global map (e.g.: only land points) to an entire one
-      values= [lonmame],[latname],[fillVal],[resolution]
+      values= [lonmame],[latname],[fillVal],[resolution],[kind]
         [lonname]: name of the longitude variable
         [latname]: name of the latitude variable
@@ -17896,4 +17899,7 @@
            Integer32 = -99999
         [resolution]: resolution of the map
+        [kind]: kind of target projection
+         'lonlat': standard lon/lat projection tacking number of points from [dx/dy]res at the Equator
+         'lonlat_dxdyFix': projection with a fixed grid distance
       filen= name of the netCDF file
       varn= name of the variable
@@ -17904,4 +17910,7 @@
     fname = 'Partialmap_Entiremap'
 
+    arguments = '[lonmame],[latname],[fillVal],[resolution],[kind]'
+    check_arguments(fname, values, arguments, ',')
+
     if values == 'h':
         print fname + '_____________________________________________________________'
@@ -17910,6 +17919,4 @@
 
     ofile = 'EntireGlobalMap.nc'
-
-    lonlatProjfile = filen.split('.')[0] + '_lonlatProj.nc'
 
     onc = NetCDFFile(filen, 'r')
@@ -17924,4 +17931,8 @@
     fval0 = values.split(',')[2]
     resolution = np.float(values.split(',')[3])
+    kind = values.split(',')[4]
+
+# Input reference lonlat map
+    lonlatProjfile = filen.split('.')[0] + '_' + kind + '.nc'
 
     if not onc.variables.has_key(lonname):
@@ -17995,11 +18006,25 @@
 
     if not os.path.isfile(lonlatProjfile):
-        print lonlatProjfile
-        quit(-1)
-        lonmap, latmap = lonlatProj(resolution, resolution, 'lonlat_dxdyFix', True)
-        sub.call(['mv','lonlatProj.nc',lonlatProjfile], shell=True)
-        Ntotvals = len(lonmap)
-    else:
-        oproj = NetCDFFile(lonlatProjfile, 'r')
+        print warnmsg
+        print '  ' + fname + ": no reference map '" + lonlatProjfile + "' found !!"
+        print '  creating it via: lonlatProj(', resolution, ',', resolution,         \
+          ', ' + kind + ', True)'
+        lonmap, latmap = lonlatProj(resolution, resolution, kind, True)
+        sub.call(['mv','lonlatProj.nc',lonlatProjfile])
+
+    oproj = NetCDFFile(lonlatProjfile, 'r')
+    if kind == 'lonlat':
+        olon = oproj.variables['lon']
+        olat = oproj.variables['lat']
+        lonmap = olon[:]
+        latmap = olat[:]
+        projlon = olon[:]
+        projlat = olat[:]
+        omapvals = oproj.variables['points']
+        Ntotvals = omapvals.shape[0] * omapvals.shape[1]
+        Nmaplon = olon.shape[0]
+        Nmaplat = olat.shape[0]
+
+    elif kind == 'lonlat_dxdyFix':
         oprojlon = oproj.variables['loncirc']
         oprojlat = oproj.variables['latcirc']
@@ -18015,6 +18040,10 @@
 
 #    Ntotvals = len(lonmap)
-    Nmaplon = Ntotvals
-    Nmaplat = Ntotvals
+        Nmaplon = Ntotvals
+        Nmaplat = Ntotvals
+    else:
+        print errormsg
+        print '  ' + fname + ": projection kind '" + kind + "' not ready!!"
+        quit(-1)
 
 # Matrix map creation
@@ -18060,42 +18089,71 @@
 
     print '  ' + fname + ': re-locating:',Ntotvals,'points...'
-    for iv in range(Ntotvals):
-#    for iv in range(15):
-#        print 'Lluis:',iv,'lon lat:',lonvs[iv],',',latvs[iv]
-        difflat = np.abs(projlat - latvs[iv])
-        mindiffL = np.min(difflat)
-        ilat = index_mat(difflat, mindiffL)
-#        print '  Lluis mindiffL:',mindiffL,'<> ilat:',ilat,'lat_ilat:',projlat[ilat],'Nprojlon:',Nprojlon[ilat],'shape oporjlon:',oprojlon[ilat,:].shape, type(oprojlon[ilat,:])
-        loncirc = np.zeros((Nprojlon[ilat]), dtype=np.float)
-        loncirc[:] = np.asarray(oprojlon[ilat,0:int(Nprojlon[ilat])].flatten())
-        difflon = np.abs(loncirc - lonvs[iv])
-        mindiffl = difflon.min()
-        ilon = index_mat(difflon, mindiffl)
-#        print '  difflon:',type(difflon),'shape difflon',difflon.shape,'shape loncirc:', loncirc.shape
-#        print '  Lluis mindiffl:',mindiffl,'<> ilon:',ilon,'oprojlon:', loncirc[ilon]
-
-        percendone(iv,Ntotvals,0.5,'done:')
-        if mindiffl > mindiff or mindiffL > mindiff:
-            print errormsg
-            print '  ' + fname + ': for point #', iv,'lon,lat in incomplet map:',   \
-              lonvs[iv], ',', latvs[iv], 'there is not a set of lon,lat in the ' +  \
-              'completed map closer than: ', mindiff, '!!'
-            print '    minimum difflon:', np.min(difflon), 'difflat:', np.min(difflat)
-            quit()
-
-        if ilon > 0 and ilat > 0:
-#            print 'Lluis shapes:',newvar.shape,'i lon/lat:',ilon,ilat
-            if Lmapvalsshape ==1:
-                newvar[iv] = ovar[iv]
+    if kind == 'lonlat':
+        for iv in range(Ntotvals):
+            difflat = np.abs(projlat - latvs[iv])
+            mindiffL = np.min(difflat)
+            ilat = index_mat(difflat, mindiffL)
+            difflon = np.abs(projlon - lonvs[iv])
+            mindiffl = difflon.min()
+            ilon = index_mat(difflon, mindiffl)
+            percendone(iv,Ntotvals,0.5,'done:')
+            if mindiffl > mindiff or mindiffL > mindiff:
+                print errormsg
+                print '  ' + fname + ': for point #', iv,'lon,lat in incomplet map:',   \
+                  lonvs[iv], ',', latvs[iv], 'there is not a set of lon,lat in the ' +  \
+                  'completed map closer than: ', mindiff, '!!'
+                print '    minimum difflon:', np.min(difflon), 'difflat:', np.min(difflat)
+                quit()
+
+            if ilon > 0 and ilat > 0:
+                newvar[ilat,ilon] = ovar[iv]         
+                newnc.sync()
             else:
-                newvar[ilat,ilon] = ovar[iv]
+                print errormsg
+                print '  ' + fname + ': point iv:',iv,'at',lonvs[iv],',',latvs[iv],' not relocated !!'
+                print '    mindiffl:',mindiffl,'mindiffL:',mindiffL,'ilon:',ilon,'ilat:',ilat
+                quit(-1)
+
+        newnc.sync()
+                        
+
+    elif kind == 'lonlat_dxdyFix':
+
+        for iv in range(Ntotvals):
+#        for iv in range(15):
+#            print 'Lluis:',iv,'lon lat:',lonvs[iv],',',latvs[iv]
+            difflat = np.abs(projlat - latvs[iv])
+            mindiffL = np.min(difflat)
+            ilat = index_mat(difflat, mindiffL)
+#            print '  Lluis mindiffL:',mindiffL,'<> ilat:',ilat,'lat_ilat:',projlat[ilat],'Nprojlon:',Nprojlon[ilat],'shape oporjlon:',oprojlon[ilat,:].shape, type(oprojlon[ilat,:])
+            loncirc = np.zeros((Nprojlon[ilat]), dtype=np.float)
+            loncirc[:] = np.asarray(oprojlon[ilat,0:int(Nprojlon[ilat])].flatten())
+            difflon = np.abs(loncirc - lonvs[iv])
+            mindiffl = difflon.min()
+            ilon = index_mat(difflon, mindiffl)
+#            print '  difflon:',type(difflon),'shape difflon',difflon.shape,'shape loncirc:', loncirc.shape
+#            print '  Lluis mindiffl:',mindiffl,'<> ilon:',ilon,'oprojlon:', loncirc[ilon]
+
+            percendone(iv,Ntotvals,0.5,'done:')
+            if mindiffl > mindiff or mindiffL > mindiff:
+                print errormsg
+                print '  ' + fname + ': for point #', iv,'lon,lat in incomplet map:',   \
+                  lonvs[iv], ',', latvs[iv], 'there is not a set of lon,lat in the ' +  \
+                  'completed map closer than: ', mindiff, '!!'
+                print '    minimum difflon:', np.min(difflon), 'difflat:', np.min(difflat)
+                quit()
+
+            if ilon > 0 and ilat > 0:
+#                print 'Lluis shapes:',newvar.shape,'i lon/lat:',ilon,ilat
+                if Lmapvalsshape ==1:
+                    newvar[iv] = ovar[iv]
             
-            newnc.sync()
-        else:
-            print errormsg
-            print '  ' + fname + ': point:',lonvs[iv],',',latvs[iv],' not relocated !!'
-            quit(-1)
-
-    newnc.sync()
+                newnc.sync()
+            else:
+                print errormsg
+                print '  ' + fname + ': point:',lonvs[iv],',',latvs[iv],' not relocated !!'
+                quit(-1)
+
+        newnc.sync()
 # Global attributes
 ##
@@ -18118,5 +18176,6 @@
     return 
 
-#Partialmap_Entiremap('longitude,latitude,std,5000.', '/home/lluis/etudes/DYNAMICO/ORCHIDEE/interpolation/data/carteveg5km.nc', 'vegetation_map')
+#Partialmap_Entiremap('longitude,latitude,std,5000.,lonlat_dxdyFix', '/home/lluis/etudes/DYNAMICO/ORCHIDEE/interpolation/data/carteveg5km.nc', 'vegetation_map')
+#Partialmap_Entiremap('longitude,latitude,std,5000.,lonlat', '/home/lluis/etudes/DYNAMICO/ORCHIDEE/interpolation/data/carteveg5km.nc', 'vegetation_map')
 #quit()
 
