Index: trunk/tools/module_ForInterpolate.F90
===================================================================
--- trunk/tools/module_ForInterpolate.F90	(revision 763)
+++ trunk/tools/module_ForInterpolate.F90	(revision 764)
@@ -478,8 +478,112 @@
 END SUBROUTINE lonlatFind
 
-SUBROUTINE CoarseInterpolate(projlon, projlat, lonvs, latvs, percen, mindiff, ivar, newvar, newvarin, &
-  newvarinpt, newvarindiff, dimx, dimy, Ninpts)
+SUBROUTINE CoarseInterpolate(projlon, projlat, lonvs, latvs, percen, mindiff, inpt, ilonlat,          &
+  mindiffLl, dimx, dimy, Ninpts)
 ! Subroutine which finds the closest grid point within a projection throughout a first guest 
 !   approche from percentages of the whole domain
+
+  USE module_generic
+
+  IMPLICIT NONE
+
+  INTEGER, PARAMETER                                     :: r_k = KIND(1.d0)
+  INTEGER, INTENT(in)                                    :: dimx, dimy
+  REAL(r_k), DIMENSION(dimx,dimy), INTENT(in)            :: projlon, projlat
+  INTEGER, INTENT(in)                                    :: Ninpts
+  REAL(r_k), DIMENSION(Ninpts), INTENT(in)               :: inpt, lonvs, latvs
+  REAL(r_k), INTENT(in)                                  :: mindiff, percen
+  INTEGER, DIMENSION(Ninpts,2), INTENT(out)              :: ilonlat
+  REAL(r_k), DIMENSION(Ninpts), INTENT(out)              :: mindiffLl
+
+! Local
+  INTEGER                                                :: iv,i,j
+  INTEGER                                                :: ierr
+  INTEGER                                                :: Ninpts1
+  REAL(r_k), DIMENSION(2)                                :: extremelon, extremelat
+  REAL(r_k), ALLOCATABLE, DIMENSION(:,:)                 :: fractionlon, fractionlat
+  INTEGER                                                :: dfracdx, dfracdy, fracdx, fracdy
+  CHARACTER(LEN=50)                                      :: fname
+
+!!!!!!! Variables
+! dimx, dimy: dimension length of the target interpolation
+! proj[lon/lat]: longitudes and latitudes of the target interpolation
+! Ninpts: number of points to interpolate
+! [lon/lat]vs: longitudes and latitudes of the points to interpolate
+! mindiff: minimal accepted distance to the target point
+! percen: size (as percentage of the total domain) of the first guess portions to provide the first gues
+! inpt: whether the point has already been localized (1) or not (0)
+! ilonlat: Longitude and Latitude of the input points
+! mindiffLl: minimum difference between target and source longitude/latitude (in degrees)
+
+  fname = 'CoarseInterpolate'
+  Ninpts1 = Ninpts/100
+
+  extremelon = (/ MINVAL(projlon), MAXVAL(projlon) /)
+  extremelat = (/ MINVAL(projlat), MAXVAL(projlat) /)
+
+  PRINT *,'  ' // TRIM(fname) //' total space:', dimx, ', ', dimy, ' %', percen
+
+  dfracdx = INT(1./percen+1)
+  dfracdy = INT(1./percen+1)
+  fracdx = INT(dimx*percen)
+  fracdy = INT(dimy*percen)
+  PRINT *,'  ' // TRIM(fname) //' fraction:', dfracdx, ', ', dfracdy, ' freq:', fracdx,', ',fracdy
+
+  IF (ALLOCATED(fractionlon)) DEALLOCATE(fractionlon)
+  ALLOCATE(fractionlon(dfracdx, dfracdy), STAT=ierr)
+  IF (ierr /= 0) THEN
+    PRINT *,TRIM(ErrWarnMsg('err'))
+    PRINT *,'  ' // TRIM(fname) //": problem allocating 'fractionlon' !!"
+    STOP
+  END IF
+  IF (ALLOCATED(fractionlat)) DEALLOCATE(fractionlat)
+  ALLOCATE(fractionlat(dfracdx, dfracdy), STAT=ierr)
+  IF (ierr /= 0) THEN
+    PRINT *,TRIM(ErrWarnMsg('err'))
+    PRINT *,'  ' // TRIM(fname) //": problem allocating 'fractionlat' !!"
+    STOP
+  END IF
+
+  DO i=1,dfracdx
+    DO j=1,dfracdy
+      fractionlon(i,j) = projlon(fracdx*(i-1)+1,fracdy*(j-1)+1)
+      fractionlat(i,j) = projlat(fracdx*(i-1)+1,fracdy*(j-1)+1)
+!      PRINT *,'i,j:',i,', ',j,' frac ij:',fracdx*(i-1),', ',fracdy*(j-1),' lonlat:', fractionlon(i,j),&
+!        ', ',fractionlat(i,j)
+    END DO
+  END DO
+
+!  PRINT *,'  ' // TRIM(fname) // ' fractions of:'
+!  PRINT *,' lon _______ (',dfracdx,', ',dfracdy,')'
+!  DO i=1,dfracdx
+!    PRINT *,fractionlon(i,:)
+!  END DO
+!  PRINT *,' lat_______'
+!  DO i=1,dfracdx
+!    PRINT *,fractionlat(i,:)
+!  END DO
+
+  DO iv=1,Ninpts
+    IF (inpt(iv) == 0) THEN
+      CALL CoarselonlatFind(dimx, dimy, projlon, projlat, extremelon, extremelat, fractionlon,        &
+        fractionlat, lonvs(iv), latvs(iv), percen, dfracdx, dfracdy, ilonlat(iv,:), mindiffLl(iv))
+
+      IF ((mindiffLl(iv) <= mindiff) .AND. .NOT.(ilonlat(iv,1) >= 0 .AND. ilonlat(iv,1) >= 0)) THEN
+        PRINT *,TRIM(ErrWarnMsg('err'))
+        PRINT *,'  ' // TRIM(fname) // ': point iv:', iv, ' at', lonvs(iv), ' ,', latvs(iv),        &
+          ' not relocated !!'
+        PRINT *,'    mindiffl:', mindiffLl(iv), ' ilon:', ilonlat(iv,1), ' ilat:', ilonlat(iv,2)
+        STOP
+      END IF
+
+    END IF
+  END DO
+
+END SUBROUTINE CoarseInterpolate
+
+SUBROUTINE CoarseInterpolateExact(projlon, projlat, lonvs, latvs, percen, mindiff, ivar, newvar,      &
+  newvarin, newvarinpt, newvarindiff, dimx, dimy, Ninpts)
+! Subroutine which finds the closest grid point within a projection throughout a first guest 
+!   and then whole domain approche from percentages of the whole domain 
 
   USE module_generic
@@ -523,5 +627,5 @@
 ! ncid: netCDF output file id
 
-  fname = 'CoarseInterpolate'
+  fname = 'CoarseInterpolateExact'
   Ninpts1 = Ninpts/100
 
@@ -573,8 +677,9 @@
   DO iv=1,Ninpts
     IF (newvarinpt(iv) == 0) THEN
-      CALL CoarselonlatFind(dimx, dimy, projlon, projlat, extremelon, extremelat, fractionlon,        &
-        fractionlat, lonvs(iv), latvs(iv), percen, dfracdx, dfracdy, ilonlat, mindiffLl)
-
-      IF (mindiffLl <= mindiff) THEN 
+      CALL CoarselonlatFindExact(dimx, dimy, projlon, projlat, extremelon, extremelat, fracdx, fracdy,&
+        fractionlon, fractionlat, iv, lonvs(iv), latvs(iv), percen, dfracdx, dfracdy, mindiff,        &
+        ilonlat, mindiffLl)
+
+      IF (mindiffLl >= mindiff) THEN 
 !        percendone(iv,Ninpts,0.5,'done:')
 
@@ -596,137 +701,4 @@
 
 !        IF (MOD(iv,Ninpts1) == 0) newnc.sync()
-!      ELSE
-! Because doing boxes and Goode is not conitnuos, we should jump this error message
-!        PRINT *,TRIM(ErrWarnMsg('err'))
-!        PRINT *,'  ' // TRIM(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 *,'    found minimum difference:', mindiffLl
-!        STOP
-      END IF
-    END IF
-  END DO
-
-END SUBROUTINE CoarseInterpolate
-
-SUBROUTINE CoarseInterpolateExact(projlon, projlat, lonvs, latvs, percen, mindiff, ivar, newvar,      &
-  newvarin, newvarinpt, newvarindiff, dimx, dimy, Ninpts)
-! Subroutine which finds the closest grid point within a projection throughout a first guest 
-!   and then whole domain approche from percentages of the whole domain 
-
-  USE module_generic
-
-  IMPLICIT NONE
-
-  INTEGER, PARAMETER                                     :: r_k = KIND(1.d0)
-  INTEGER, INTENT(in)                                    :: dimx, dimy
-  REAL(r_k), DIMENSION(dimx,dimy), INTENT(in)            :: projlon, projlat
-  INTEGER, INTENT(in)                                    :: Ninpts
-  REAL(r_k), DIMENSION(Ninpts), INTENT(in)               :: ivar, lonvs, latvs
-  REAL(r_k), INTENT(in)                                  :: mindiff, percen
-  REAL(r_k), DIMENSION(dimx,dimy), INTENT(out)           :: newvar
-  INTEGER, DIMENSION(dimx,dimy), INTENT(out)             :: newvarin
-  INTEGER, DIMENSION(Ninpts), INTENT(out)                :: newvarinpt
-  REAL(r_k), DIMENSION(Ninpts), INTENT(out)              :: newvarindiff
-
-! Local
-  INTEGER                                                :: iv,i,j
-  INTEGER                                                :: ierr
-  INTEGER, DIMENSION(2)                                  :: ilonlat
-  REAL(r_k)                                              :: mindiffLl
-  INTEGER                                                :: Ninpts1
-  REAL(r_k), DIMENSION(2)                                :: extremelon, extremelat
-  REAL(r_k), ALLOCATABLE, DIMENSION(:,:)                 :: fractionlon, fractionlat
-  INTEGER                                                :: dfracdx, dfracdy, fracdx, fracdy
-  CHARACTER(LEN=50)                                      :: fname
-
-!!!!!!! Variables
-! dimx, dimy: dimension length of the target interpolation
-! proj[lon/lat]: longitudes and latitudes of the target interpolation
-! Ninpts: number of points to interpolate
-! [lon/lat]vs: longitudes and latitudes of the points to interpolate
-! mindiff: minimal accepted distance to the target point
-! percen: size (as percentage of the total domain) of the first guess portions to provide the first gues
-! ivar: values to localize in the target projection
-! newvar: localisation of the [lon/lat]vs point in the target projection
-! newvarin: number of point from the input data
-! newvarinpt: integer value indicating if the value has been already located (0: no, 1: yes)
-! newvarindiff: distance of point from the input data to the closest target point
-! ncid: netCDF output file id
-
-  fname = 'CoarseInterpolateExact'
-  Ninpts1 = Ninpts/100
-
-  extremelon = (/ MINVAL(projlon), MAXVAL(projlon) /)
-  extremelat = (/ MINVAL(projlat), MAXVAL(projlat) /)
-
-  PRINT *,'  ' // TRIM(fname) //' total space:', dimx, ', ', dimy, ' %', percen
-
-  dfracdx = INT(1./percen+1)
-  dfracdy = INT(1./percen+1)
-  fracdx = INT(dimx*percen)
-  fracdy = INT(dimy*percen)
-  PRINT *,'  ' // TRIM(fname) //' fraction:', dfracdx, ', ', dfracdy, ' freq:', fracdx,', ',fracdy
-
-  IF (ALLOCATED(fractionlon)) DEALLOCATE(fractionlon)
-  ALLOCATE(fractionlon(dfracdx, dfracdy), STAT=ierr)
-  IF (ierr /= 0) THEN
-    PRINT *,TRIM(ErrWarnMsg('err'))
-    PRINT *,'  ' // TRIM(fname) //": problem allocating 'fractionlon' !!"
-    STOP
-  END IF
-  IF (ALLOCATED(fractionlat)) DEALLOCATE(fractionlat)
-  ALLOCATE(fractionlat(dfracdx, dfracdy), STAT=ierr)
-  IF (ierr /= 0) THEN
-    PRINT *,TRIM(ErrWarnMsg('err'))
-    PRINT *,'  ' // TRIM(fname) //": problem allocating 'fractionlat' !!"
-    STOP
-  END IF
-
-  DO i=1,dfracdx
-    DO j=1,dfracdy
-      fractionlon(i,j) = projlon(fracdx*(i-1)+1,fracdy*(j-1)+1)
-      fractionlat(i,j) = projlat(fracdx*(i-1)+1,fracdy*(j-1)+1)
-!      PRINT *,'i,j:',i,', ',j,' frac ij:',fracdx*(i-1),', ',fracdy*(j-1),' lonlat:', fractionlon(i,j),&
-!        ', ',fractionlat(i,j)
-    END DO
-  END DO
-
-!  PRINT *,'  ' // TRIM(fname) // ' fractions of:'
-!  PRINT *,' lon _______ (',dfracdx,', ',dfracdy,')'
-!  DO i=1,dfracdx
-!    PRINT *,fractionlon(i,:)
-!  END DO
-!  PRINT *,' lat_______'
-!  DO i=1,dfracdx
-!    PRINT *,fractionlat(i,:)
-!  END DO
-
-  DO iv=1,Ninpts
-    IF (newvarinpt(iv) == 0) THEN
-      CALL CoarselonlatFindExact(dimx, dimy, projlon, projlat, extremelon, extremelat, fracdx, fracdy,&
-        fractionlon, fractionlat, iv, lonvs(iv), latvs(iv), percen, dfracdx, dfracdy, mindiff,        &
-        ilonlat, mindiffLl)
-
-      IF (mindiffLl >= mindiff) THEN 
-!        percendone(iv,Ninpts,0.5,'done:')
-
-        IF (ilonlat(1) >= 0 .AND. ilonlat(1) >= 0) THEN
-          newvar(ilonlat(1),ilonlat(2)) = ivar(iv)
-          newvarin(ilonlat(1),ilonlat(2)) = iv
-          newvarinpt(iv) = 1
-          newvarindiff(iv) = mindiffLl
-!          PRINT *,'Lluis iv:', newvarin(ilonlat(1),ilonlat(2)), ' localized:', newvarinpt(iv),        &
-!            ' values:', newvar(ilonlat(1),ilonlat(2)), ' invalues:', ivar(iv), ' mindist:',           &
-!            newvarindiff(iv), ' point:',ilonlat    
-        ELSE
-          PRINT *,TRIM(ErrWarnMsg('err'))
-          PRINT *,'  ' // TRIM(fname) // ': point iv:', iv, ' at', lonvs(iv), ' ,', latvs(iv),        &
-            ' not relocated !!'
-          PRINT *,'    mindiffl:', mindiffLl, ' ilon:', ilonlat(1), ' ilat:', ilonlat(2)
-          STOP
-        END IF
-
-!        IF (MOD(iv,Ninpts1) == 0) newnc.sync()
       ELSE
         PRINT *,TRIM(ErrWarnMsg('err'))
@@ -841,3 +813,112 @@
 END SUBROUTINE Interpolate
 
+SUBROUTINE Interpolate1DLl(projlon, projlat, lonvs, latvs, mindiff, inpt, diffs, ilonlat, dimx, dimy, &
+  Ninpts)
+! Subroutine which finds the closest grid point within a projection with 1D longitudes and latitudes
+
+  USE module_generic
+
+  IMPLICIT NONE
+
+  INTEGER, PARAMETER                                     :: r_k = KIND(1.d0)
+  INTEGER, INTENT(in)                                    :: dimx, dimy
+  REAL(r_k), DIMENSION(dimx), INTENT(in)                 :: projlon
+  REAL(r_k), DIMENSION(dimy), INTENT(in)                 :: projlat
+  INTEGER, INTENT(in)                                    :: Ninpts
+  REAL(r_k), DIMENSION(Ninpts), INTENT(in)               :: lonvs, latvs
+  REAL(r_k), INTENT(in)                                  :: mindiff
+  INTEGER, DIMENSION(Ninpts), INTENT(inout)              :: inpt
+  REAL(r_k), DIMENSION(Ninpts), INTENT(out)              :: diffs
+  INTEGER, DIMENSION(Ninpts,2), INTENT(out)              :: ilonlat
+
+! Local
+  INTEGER                                                :: iv
+  REAL(r_k)                                              :: mindifflo, mindiffLa, mindiffLl
+  INTEGER                                                :: Ninpts1
+  REAL(r_k), DIMENSION(dimx)                             :: difflon
+  REAL(r_k), DIMENSION(dimy)                             :: difflat
+  REAL(r_k), DIMENSION(2)                                :: extremelon, extremelat
+  CHARACTER(LEN=50)                                      :: fname
+
+!!!!!!! Variables
+! dimx, dimy: dimension length of the target interpolation
+! proj[lon/lat]: longitudes and latitudes of the target interpolation
+! Ninpts: number of points to interpolate
+! [lon/lat]vs: longitudes and latitudes of the points to interpolate
+! mindiff: minimal accepted distance to the target point
+! inpt: whether the point has already been localized
+! diffs: distance of point from the input data to the closest target point
+! ilonlat: longitude and latitude of the point
+! ncid: netCDF output file id
+
+  fname = 'Interpolate1DLl'
+  Ninpts1 = Ninpts/100
+
+  extremelon = (/ MINVAL(projlon), MAXVAL(projlon) /)
+  extremelat = (/ MINVAL(projlat), MAXVAL(projlat) /)
+
+  DO iv=1,Ninpts
+    IF (inpt(iv) <= 0) THEN
+! Not using the subroutine, not efficient!
+!      CALL lonlatFind(dimx, dimy, projlon, projlat, extremelon, extremelat, lonvs(iv), latvs(iv),     &
+!        ilonlat, mindiffLl)
+
+      IF (lonvs(iv) < extremelon(1) .OR. lonvs(iv) > extremelon(2)) THEN
+        PRINT *, TRIM(ErrWarnMsg('err'))
+        PRINT *,'  ' // TRIM(fname) // ': longitude outside data range!!'
+        PRINT *,'    given value:', lonvs(iv),' outside (',extremelon(1),' ,',extremelon(2),' )'
+        STOP
+      END IF
+      IF (latvs(iv) < extremelat(1) .OR. latvs(iv) > extremelat(2)) THEN
+        PRINT *, TRIM(ErrWarnMsg('err'))
+        PRINT *,'  ' // TRIM(fname) // ': latitude outside data range!!'
+        PRINT *,'    given value:', latvs(iv),' outside (',extremelat(1),' ,',extremelat(2),' )'
+        STOP
+      END IF
+
+! Find point
+      difflon = SQRT((projlon-lonvs(iv))**2.)
+      difflat = SQRT((projlat-latvs(iv))**2.)
+      mindifflo = MINVAL(difflon)
+      mindiffLa = MINVAL(difflat)
+      mindifflL = SQRT(mindifflo*mindifflo + mindiffLa*mindiffLa)
+      ilonlat(iv,1) = index1DArrayR(difflon, dimx, mindifflo)
+      ilonlat(iv,2) = index1DArrayR(difflat, dimy, mindiffLa)
+!      PRINT *,'  Lluis: iv',iv,' lonvs:', lonvs(iv),' latvs:',latvs(iv)
+!      PRINT *,'  Lluis: mindifflo:', mindifflo,' ilonlat(1):',ilonlat(iv,1)
+!      PRINT *,'  Lluis: mindiffLa:', mindiffLa,' ilonlat(2):',ilonlat(iv,2)
+
+
+      IF (mindiffLl <= mindiff) THEN 
+!        percendone(iv,Ninpts,0.5,'done:')
+
+        IF (ilonlat(iv,1) >= 0 .AND. ilonlat(iv,2) >= 0) THEN
+          diffs(iv) = mindiffLl
+          inpt(iv) = 1
+!          PRINT *,'Lluis iv:', newvarin(ilonlat(1),ilonlat(2)), ' localized:', newvarinpt(iv),        &
+!            ' values:', newvar(ilonlat(1),ilonlat(2)), ' invalues:', ivar(iv), ' mindist:',           &
+!            newvarindiff(iv), ' point:',ilonlat    
+        ELSE
+          PRINT *,TRIM(ErrWarnMsg('err'))
+          PRINT *,'  ' // TRIM(fname) // ': point iv:', iv, ' at', lonvs(iv), ' ,', latvs(iv),        &
+            ' not relocated !!'
+          PRINT *,'    mindiffl:', mindiffLl, ' ilon:', ilonlat(iv,1), ' ilat:', ilonlat(iv,2)
+          STOP
+        END IF
+
+!        IF (MOD(iv,Ninpts1) == 0) newnc.sync()
+      ELSE
+! Because doing boxes and Goode is not conitnuos, we should jump this error message
+        PRINT *,TRIM(ErrWarnMsg('err'))
+        PRINT *,'  ' // TRIM(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 *,'    found minimum difference:', mindiffLl
+        STOP
+      END IF
+    END IF
+  END DO
+
+END SUBROUTINE Interpolate1DLl
+
 END MODULE module_ForInterpolate
Index: trunk/tools/module_generic.F90
===================================================================
--- trunk/tools/module_generic.F90	(revision 763)
+++ trunk/tools/module_generic.F90	(revision 764)
@@ -3,4 +3,31 @@
 
   CONTAINS
+
+  INTEGER FUNCTION Index1DArrayR(array1D, d1, val)
+! Function to provide the first index of a given value inside a 1D real array
+
+    IMPLICIT NONE
+
+    INTEGER, PARAMETER                                   :: r_k = KIND(1.d0)
+    INTEGER, INTENT(in)                                  :: d1
+    REAL(r_k), INTENT(in)                                :: val
+    REAL(r_k), DIMENSION(d1), INTENT(in)                 :: array1D
+
+! Local
+    INTEGER                                              :: i
+    CHARACTER(LEN=50)                                    :: fname
+
+    fname = 'Index1DArrayR'
+
+    Index1DArrayR = -1
+
+    DO i=1,d1
+      IF (array1d(i) == val) THEN
+        Index1DArrayR = i
+        EXIT
+      END IF
+    END DO
+
+  END FUNCTION Index1DArrayR
 
   FUNCTION Index2DArrayR(array2D, d1, d2, val)
Index: trunk/tools/nc_var_tools.py
===================================================================
--- trunk/tools/nc_var_tools.py	(revision 763)
+++ trunk/tools/nc_var_tools.py	(revision 764)
@@ -4467,5 +4467,4 @@
         for ich in range(Lstr):
             chrv = stringv[ich:ich+1]
-            if ord(chrv) == 32: chrv = unichr(32)
             charvals[ich] = stringv[ich:ich+1]
         varo[iv,:] = charvals
@@ -13113,5 +13112,5 @@
     else:
         print errormsg
-        print '  ' + fnamne + ": projection '" + project + "' not ready !!"
+        print '  ' + fname + ": projection '" + project + "' not ready !!"
         quit(-1)
 
@@ -13636,5 +13635,5 @@
       foudre: f2py -m module_ForInterpolate --f90exec=/usr/bin/gfortran-4.7 -c module_ForInterpolate.F90 module_generic.F90 >& run_f2py.log
       ciclad: f2py --f90flags="-fPIC" -L/opt/canopy-1.3.0/Canopy_64bit/System/lib/ -L/usr/lib64/ -L/opt/canopy-1.3.0/Canopy_64bit/System/lib/ -m module_ForInterpolate -c module_ForInterpolate.F90 module_generic.F90
-      values= [lonmame],[latname],[fillVal],[resolution],[kind],[lonlatProjfile],[ipoint],[fracd],[fracs]
+      values= [lonmame],[latname],[fillVal],[resolution],[kind],[lonlatProjfile],[ipoint],[fracd],[fracs],[mindiff]
         [lonname]: name of the longitude variable
         [latname]: name of the latitude variable
@@ -13648,4 +13647,7 @@
         [kind]: kind of target projection
          'lonlat': standard lon/lat projection tacking number of points from [dx/dy]res at the Equator
+         'lonlatfrac': standard lon/lat projection tacking number of points from [dx/dy]res at the Equator with
+            mnultiple values at the target interpolation grid [kind]@[Ntypes]
+              [Ntypes]: Number of types at each grid-point
          'lonlat_dxdyFix': projection with a fixed grid distance
          'Goode': Goode projection
@@ -13654,4 +13656,5 @@
         [fracd]: Percentage of the fractions within perform the first guess search
         [fracs]: Number of grid points to perform the syncronization with the file and the computed values
+        [mindiff]: Authorized minium distance between input and final lon,lat point
       filen= name of the netCDF file
       varn= name of the variable
@@ -13669,6 +13672,6 @@
 
     arguments = '[lonmame],[latname],[fillVal],[resolution],[kind],' +               \
-      '[lonlatProjfile],[ipoint],[fracd],[fracs]'
-    check_arguments(fname, values, arguments, ',')
+      '[lonlatProjfile],[ipoint],[fracd],[fracs],[mindiff]'
+    gen.check_arguments(fname, values, arguments, ',')
 
     ofile = 'EntireGlobalMap.nc'
@@ -13685,9 +13688,10 @@
     fval0 = values.split(',')[2]
     resolution = np.float(values.split(',')[3])
-    kind = values.split(',')[4]
+    kind0 = values.split(',')[4]
     Projfile = values.split(',')[5]
     ipoint = int(values.split(',')[6])
-    fracd = np.float(values.split(',')[7])
+    fracd = np.float64(values.split(',')[7])
     fracs = int(values.split(',')[8])
+    mindiff = np.float64(values.split(',')[9])
 
     if Projfile == 'None':
@@ -13695,4 +13699,18 @@
     else:
         lonlatProjfile = Projfile
+
+    if kind0.find('@') != -1: 
+        kind = kind0.split('@')[0]
+        Ntypes = np.int(kind0.split('@')[1])
+    else:
+        kind = kind0
+
+    Lkind = len(kind)
+    if kind[Lkind-4:Lkind] == 'frac' and kind0.find('@') == -1:
+        print errormsg
+        print '  ' + fname + ": there is a fractional kind of interpolation '" +     \
+          kind + "' but no number of types has been privided!!"
+        print "    when [kind] is provided, should be '[kind]@[Ntypes]'"
+        quit()
 
     if not onc.variables.has_key(lonname):
@@ -13767,6 +13785,6 @@
         quit(-1)
 
-    if lonlatProjfile is None:
-        lonlatProjfile = kind + '.nc'
+    if lonlatProjfile is None or not os.path.isfile(lonlatProjfile):
+        if lonlatProjfile is None: lonlatProjfile = kind + '.nc'
         print warnmsg
         print '  ' + fname + ": no reference map !!"
@@ -13774,6 +13792,9 @@
         print '    creating it via: lonlatProj(', resolution, ',', resolution,       \
           ', ' + kind + ', True)'
-        lonmap, latmap = lonlatProj(resolution, resolution, kind, True)
-        sub.call(['mv','lonlatProj.nc',lonlatProjfile])
+        if kind[Lkind-4:Lkind] == 'frac':
+            lonmap, latmap = lonlatProj(resolution, resolution, kind[0:Lkind-4], True)
+        else:
+            lonmap, latmap = lonlatProj(resolution, resolution, kind, True)
+        sub.call(['mv','lonlatProj.nc', lonlatProjfile])
 
     oproj = NetCDFFile(lonlatProjfile, 'r')
@@ -13802,4 +13823,16 @@
         Nmaplat = olat.shape[0]
 
+    elif kind == 'lonlatfrac':
+        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']
@@ -13830,6 +13863,6 @@
     varunits = ovar.units
 
-    fval = fillvalue_kind(type(ovar[0]), fval0)
-
+    fval = gen.fillvalue_kind(type(ovar[0]), fval0)
+    
 # Final map creation
 ##
@@ -13867,12 +13900,20 @@
 
         newvarindiff = newnc.createVariable('locindiff','f4',('inpts'))
-        basicvardef(newvarindiff, 'locindiff', 'distance between input point and its final location','degree')
+        basicvardef(newvarindiff, 'locindiff', 'distance between input point and ' + \
+          'its final location','degree')
 
 # map variable
         Lmapvalsshape = len(omapvals.shape)
         if Lmapvalsshape == 1:
-            newvar = newnc.createVariable(varn, nctype(vartype), ('pts'), fill_value=fval)
+            newvar = newnc.createVariable(varn, nctype(vartype), ('pts'),            \
+              fill_value=fval)
         else:
-            newvar = newnc.createVariable(varn, nctype(vartype), ('lat','lon'), fill_value=fval)
+            if kind[Lkind-4:Lkind] == 'frac':
+                newdim = newnc.createDimension('Ntypes', Ntypes)
+                newvar = newnc.createVariable(varn, 'f4', ('Ntypes','lat','lon'),    \
+                  fill_value=gen.fillvalue_kind(type(1.), fval0))
+            else:
+                newvar = newnc.createVariable(varn, nctype(vartype), ('lat','lon'),  \
+                  fill_value=fval)
 
         basicvardef(newvar, varn, varlongname, varunits)
@@ -13909,9 +13950,16 @@
 
 # Reducing the searching points
-    newvarinvals = newvarinpt[:]
+    Nsearchpt = 499999
+    Ninpts=np.min([Nsearchpt, Ninpts-ipoint])
+    newvarinvals = newvarinpt[ipoint:ipoint+Ninpts]
     maskpt = np.where(newvarinvals.mask == True, False, True)
-    points = np.arange(Ninpts)
+    points = np.arange(ipoint,ipoint+Ninpts,1)
     mapoints = ma.array(points, mask=maskpt)
     ptsf = mapoints.compressed()
+
+    Nptsf = len(ptsf)
+    print Ninpts,'Npoints to find:', len(ptsf), ptsf[0:10], newvarindiff[ptsf[0:10]]
+    print '  ' + fname + ': from:', Ninpts,'re-locating:',Nptsf,'points starting at',\
+      ipoint,'...'
 
     Nptsf = len(ptsf)
@@ -13943,30 +13991,57 @@
 
     elif 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:
-                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()
+        for ir in range(ipoint,ipoint+Ninpts,fracs):
+            iri = ir
+            ire = ir + fracs
+            print iri,',',ire
+#            percendone(iri,Ninpts,0.5,'done:')
+            lonvss = lonvs[iri:ire+1].astype('float64')
+            latvss = latvs[iri:ire+1].astype('float64')
+            inptss = newvarinpt[iri:ire+1].astype('int32')
+
+            idiff, ilonlatv = fin.module_forinterpolate.interpolate1dll(projlon,     \
+              projlat, lonvss, latvss, np.float64(mindiff), inptss)
+            print 'Lluis shapes: newvar', newvar.shape,'ilonlatv:',ilonlatv.shape,'range:',np.min([len(idiff),fracs])
+            print 'Lluis shapes: ovar:',ovar.shape
+
+            for i in range(np.min([len(idiff),fracs])):
+#                print 'Lluis:',ilonlatv[i,1],',',ilonlatv[i,0]
+                newvar[ilonlatv[i,1],ilonlatv[i,0]] = ovar[iri + i]
+                newvarin[ilonlatv[i,1],ilonlatv[i,0]] = iri + i
+                newvarinpt[iri+i] = 1
+                newvarindiff[iri+i] = idiff[i]
+
+            newnc.sync()
+#            newnc.close()
+#            quit()
+
+    elif kind == 'lonlatfrac':
+        for ir in range(ipoint,ipoint+Ninpts,fracs):
+            iri = ir
+            ire = ir + fracs
+            print iri,',',ire
+#            percendone(iri,Ninpts,0.5,'done:')
+            lonvss = lonvs[iri:ire+1].astype('float64')
+            latvss = latvs[iri:ire+1].astype('float64')
+            inptss = newvarinpt[iri:ire+1].astype('int32')
+
+            idiff, ilonlatv = fin.module_forinterpolate.interpolate1dll(projlon,     \
+              projlat, lonvss, latvss, np.float64(mindiff), inptss)
+
+            for i in range(np.min([len(idiff),fracs])):
+                print i,'Lluis:',ovar[iri+i], ilonlatv[i,1],',',ilonlatv[i,0],newvar[ovar[iri+i],ilonlatv[i,1],ilonlatv[i,0]], type(newvar[ovar[iri+i],ilonlatv[i,1],ilonlatv[i,0]])
+                if newvar[ovar[iri+i],ilonlatv[i,1],ilonlatv[i,0]].mask: 
+                    newvar[ovar[iri+i],ilonlatv[i,1],ilonlatv[i,0]].mask = False
+                    newvar[ovar[iri+i],ilonlatv[i,1],ilonlatv[i,0]] = 1.
+                else:
+                    newvar[ovar[iri+i],ilonlatv[i,1],ilonlatv[i,0]] =                \
+                      newvar[ovar[iri+i],ilonlatv[i,1],ilonlatv[i,0]] + 1
+                newvarin[ilonlatv[i,1],ilonlatv[i,0]] = iri + i
+                newvarinpt[iri+i] = 1
+                newvarindiff[iri+i] = idiff[i]
+
+            newnc.sync()
+#            newnc.close()
+#            quit()
 
     elif kind == 'lonlat_dxdyFix':
