Index: trunk/SRC/ReadWrite/ncdf_getaxis.pro
===================================================================
--- trunk/SRC/ReadWrite/ncdf_getaxis.pro	(revision 391)
+++ trunk/SRC/ReadWrite/ncdf_getaxis.pro	(revision 399)
@@ -51,4 +51,22 @@
 ; x/yaxis = keyword_set(start1) + findgen(jpi/jpj)
 ;
+; @keyword XMINMESH {default=0L}{type=scalar}
+; Define common (cm_4mesh) variables ixminmesh used to define the localization
+; of the first point of the grid along the x direction in a zoom of the original grid
+;
+; @keyword YMINMESH {default=0L}{type=scalar}
+; Define common (cm_4mesh) variables iyminmesh used to define the localization
+; of the first point of the grid along the y direction in a zoom of the original grid
+;
+; @keyword XMAXMESH {default=jpiglo-1}{type=scalar}
+; Define common (cm_4mesh) variables ixmaxmesh used to define the localization
+; of the last point of the grid along the x direction in a zoom of the original grid
+; Note that if XMAXMESH < 0 then ixmaxmesh is defined as ixmaxmesh = jpiglo -1 + xmaxmesh
+;
+; @keyword YMAXMESH {default=jpjglo-1}{type=scalar}
+; Define common (cm_4mesh) variables iymaxmesh used to define the localization
+; of the last point of the grid along the y direction in a zoom of the original grid
+; Note that if YMAXMESH < 0 then iymaxmesh is defined as iymaxmesh = jpjglo -1 + ymaxmesh
+;
 ; @keyword _EXTRA
 ; Used to be able to call ncdf_getaxis with _extra
@@ -62,13 +80,19 @@
 ;-
 PRO ncdf_getaxis, fileid, dimidx, dimidy, xaxis, yaxis $
-                  , XAXISNAME=xaxisname, YAXISNAME=yaxisname $
-                  , XDIMNAME=xdimname, YDIMNAME=ydimname $
-                  , XYINDEX=xyindex, START1=start1 $
-                  , ROMSGRID=romsgrid, _EXTRA=ex
+                  , XAXISNAME = xaxisname, YAXISNAME = yaxisname $
+                  , XDIMNAME = xdimname, YDIMNAME = ydimname $
+                  , XYINDEX = xyindex, START1 = start1 $
+                  , XMINMESH = xminmesh, XMAXMESH = xmaxmesh $
+                  , YMINMESH = yminmesh, YMAXMESH = ymaxmesh $
+                  , ROMSGRID = romsgrid, _EXTRA = ex
 ;
   compile_opt idl2, strictarrsubs
 ;
-  @cm_general                      ;   needed for iodir
-;
+@cm_general                   ;   needed for iodir
+@cm_4mesh
+;
+  IF n_elements(xminmesh) NE 0 THEN ixminmesh = 0L > long(xminmesh[0]) ELSE ixminmesh  = 0l
+  IF n_elements(yminmesh) NE 0 THEN iyminmesh = 0L > long(yminmesh[0]) ELSE iyminmesh  = 0l
+  IF n_elements(zminmesh) NE 0 THEN izminmesh = 0L > long(zminmesh[0]) ELSE izminmesh  = 0l
 ; should we open the file?
   IF size(fileid, /type) EQ 7 THEN $
@@ -140,10 +164,34 @@
     xaxisname = xinq.name
     dimidx = xinq.dim[0]
-    IF xinq.ndims GE 2 THEN ncdf_diminq, cdfid, xinq.dim[1], blabla, jpjfromx
+    xoffset = lonarr(xinq.ndims)
+    xcount = lonarr(xinq.ndims)
+    FOR i = 0, xinq.ndims -1 DO BEGIN
+      ncdf_diminq, cdfid, xinq.dim[i], blabla, tmpsz
+      xcount[i] = tmpsz
+    ENDFOR
+    jpiglo = xcount[0]
+    IF n_elements(xmaxmesh) NE 0 THEN BEGIN 
+      IF xmaxmesh GE 0 THEN ixmaxmesh = long(xmaxmesh[0]) ELSE ixmaxmesh = xcount[0] -1 + long(xmaxmesh[0])
+    ENDIF ELSE ixmaxmesh = xcount[0] - 1L
+    ixmaxmesh  = 0 > ixmaxmesh < (xcount[0] - 1L) ; make sure ixmaxmesh is not too big
+    xoffset[0] = ixminmesh
+    xcount[0] = ixmaxmesh - ixminmesh + 1L
+    jpifromx = xcount[0]
+    jpi = jpifromx
+    IF xinq.ndims GE 2 THEN BEGIN 
+      jpjglo = xcount[1]
+      IF n_elements(ymaxmesh) NE 0 THEN BEGIN 
+        IF ymaxmesh GE 0 THEN iymaxmesh = long(ymaxmesh[0]) ELSE iymaxmesh = xcount[1] - 1L + long(ymaxmesh[0])
+      ENDIF ELSE iymaxmesh = xcount[1] - 1L
+      iymaxmesh  = 0 > iymaxmesh < (xcount[1] - 1L) ; make sure ixmaxmesh is not too big
+      xoffset[1] = iyminmesh
+      xcount[1] = iymaxmesh - iyminmesh + 1L
+      jpjfromx = xcount[1]
+      jpj = jpjfromx
+    ENDIF
   ENDELSE
-  IF arg_present(xdimname) THEN ncdf_diminq, cdfid, dimidx,  xdimname, jpifromx
+  IF arg_present(xdimname) THEN ncdf_diminq, cdfid, dimidx,  xdimname, tmp
 ;
   IF arg_present(xaxis) THEN BEGIN
-    ncdf_diminq, cdfid, dimidx, blabla, jpifromx
 ; should we read or compute the xaxis?
     IF keyword_set(xyindex) OR xvarid EQ -1 THEN BEGIN
@@ -152,5 +200,5 @@
     ENDIF ELSE BEGIN
 ; read the xaxis
-      ncdf_varget, cdfid, xvarid, xaxis
+      ncdf_varget, cdfid, xvarid, xaxis, offset = xoffset, count = xcount
       ncdf_getatt, cdfid, xvarid, ADD_OFFSET = add_offset, SCALE_FACTOR = scale_factor
       IF scale_factor NE 1. THEN xaxis = temporary(xaxis) * scale_factor
@@ -208,13 +256,38 @@
     yinq = ncdf_varinq(cdfid, yvarid)
     yaxisname = yinq.name
-    IF yinq.ndims GE 2 THEN BEGIN
-      ncdf_diminq, cdfid, yinq.dim[0], blabla, jpifromy
-      dimidy = yinq.dim[1]
-    ENDIF ELSE dimidy = yinq.dim[0]
+    IF yinq.ndims GE 2 THEN dimidy = yinq.dim[1] ELSE dimidy = yinq.dim[0]
+    yoffset = lonarr(yinq.ndims)
+    ycount = lonarr(yinq.ndims)
+    FOR i = 0, yinq.ndims -1 DO BEGIN
+      ncdf_diminq, cdfid, yinq.dim[i], blabla, tmpsz
+      ycount[i] = tmpsz
+    ENDFOR
+    idy = yinq.ndims GE 2
+    jpjglo = ycount[idy]
+    IF n_elements(ymaxmesh) NE 0 THEN BEGIN 
+      IF ymaxmesh GE 0 THEN iymaxmesh = long(ymaxmesh[0]) ELSE iymaxmesh = ycount[idy] - 1L + long(ymaxmesh[0])
+    ENDIF ELSE iymaxmesh = ycount[idy] - 1L
+    iymaxmesh  = iymaxmesh < (ycount[idy] - 1L) ; make sure ixmaxmesh is not too big
+    yoffset[idy] = iyminmesh
+    ycount[idy] = iymaxmesh - iyminmesh + 1L
+    jpjfromy = ycount[idy]
+    jpj = jpjfromy
+    IF yinq.ndims GE 2 THEN BEGIN 
+      jpiglo = ycount[0]
+      IF n_elements(xmaxmesh) NE 0 THEN BEGIN 
+        IF xmaxmesh GE 0 THEN ixmaxmesh = long(xmaxmesh[0]) ELSE ixmaxmesh = ycount[0] - 1L + long(xmaxmesh[0])
+      ENDIF ELSE ixmaxmesh = ycount[0] - 1L
+      ixmaxmesh  = ixmaxmesh < (ycount[0] - 1L) ; make sure ixmaxmesh is not too big
+      yoffset[0] = ixminmesh
+      ycount[0] = ixmaxmesh - ixminmesh + 1L
+      jpifromy = xcount[0]
+      jpi = jpifromy
+    ENDIF
   ENDELSE
-  IF arg_present(ydimname) THEN ncdf_diminq, cdfid, dimidy,  ydimname, jpjfromy
+  IF arg_present(ydimname) THEN ncdf_diminq, cdfid, dimidy,  ydimname, tmp
 ;
   IF arg_present(yaxis) THEN BEGIN
     IF n_elements(jpifromy) NE 0 THEN BEGIN
+      IF n_elements(jpifromx) EQ 0 THEN ncdf_diminq, cdfid, dimidx, blabla, jpifromx
       IF jpifromy NE jpifromx THEN BEGIN
         dummy = report('x/y axes do not have the same x dimension...')
@@ -222,6 +295,6 @@
       ENDIF
     ENDIF
-    ncdf_diminq, cdfid, dimidy, blabla, jpjfromy
     IF n_elements(jpjfromx) NE 0 THEN BEGIN
+      IF n_elements(jpjfromy) EQ 0 THEN ncdf_diminq, cdfid, dimidy, blabla, jpjfromy
       IF jpjfromy NE jpjfromx THEN BEGIN
         dummy = report(' x/y axes do not have the same y dimension...')
@@ -234,5 +307,5 @@
     ENDIF ELSE BEGIN
 ; read the yaxis
-      ncdf_varget, cdfid, yvarid, yaxis
+      ncdf_varget, cdfid, yvarid, yaxis, offset = yoffset, count = ycount
       ncdf_getatt, cdfid, yvarid, ADD_OFFSET = add_offset, SCALE_FACTOR = scale_factor
       IF scale_factor NE 1. THEN yaxis = temporary(yaxis) * scale_factor
