[Thread Prev][Thread Next][Index]

Re: [las_users] ERROR: inconsistent sizes of data regions



Hi All,
I'm attempting to plot u and v components of ocean momentum and surface stress in LAS 7.1.1. The u component of both of these variables plots fine. However, the v components each give me the following error (full text pasted after message):
  **ERROR: inconsistent sizes of data regions: box edges (on Y axis)
           allowed only with SHADE
What does this error mean?, and how can I correct it?


We're just learning all the details of configuring curvilinear datasets ourselves, and this is a case I hadn't seen. The sigma-depths is a separate issue, not the reason for this error message.

Opening your dataset in Ferret, I see that some of the the data fields and curvilinear coordiantes are defined on a 293x193 grid in IJ, and others are defined on a 294x194 grid in IJ. The first generally represents the centers of grid cells, and the second represents the edges (staggered grids). Actually this data seems to have more combinations, with some sets of coordinates being (I,J), some (I,J+1),some (I+1,J) and yet others being (I+1,J+1).

Using Ferret to look at the data,
yes? use "http://oos.soest.hawaii.edu/thredds/dodsC/hioos/roms_forec/hiig/HI-ROMS_Forecast_Model_Run_Collection_best.ncd";
yes? show data

Picking out some variables from the list, find variables where the first two columns representing the size in I and J match:

TEMP, SALINITY, AKV, etc have grid dimensions that match LON_RHO and LAT_RHO
TEMP potential temperature 1:294 1:194 1:30 1:105 LON_RHO longitude of RHO-points 1:294 1:194 ... ... LAT_RHO latitude of RHO-points 1:294 1:194 ... ...

U  and SUSTR  and Ubar, etc.
U u-momentum component 1:293 1:194 1:30 1:105 SUSTR surface u-momentum stress 1:293 1:194 ... 1:105 LON_U longitude of U-points 1:293 1:194 ... ... LAT_U latitude of U-points 1:293 1:194 ... ...

V and SVSTR and VBAR, etc.
V v-momentum component 1:294 1:193 1:30 1:105 SVSTR surface v-momentum stress 1:294 1:193 ... 1:105 LON_V longitude of V-points 1:294 1:193 ... ... LAT_V latitude of V-points 1:294 1:193 ... ...

MASK_PSI and LON_PSI, LAT_PSI
MASK_PSI mask on psi-points 1:293 1:193 ... ... LON_PSI longitude of PSI-points 1:293 1:193 ... ... LAT_PSI latitude of PSI-points 1:293 1:193 ... ...


The Ferret SHADE command (raster plots) can use coordinates defined as cell boundaries for the definition of the curvilinear grid to plot a variable that's defined at the centers, but the FILL (filed contour command) needs the dimension sizes to match. And Ferret does not handle those mixed cases where the data field is at cell centers but only one of the X coordinates andY coordinates is edges.

So the answer is to match the longitude/latitude coordinate variables with the variables. For SVSTR it looks like you would use the coordinates with matching dimensions, LON_V and LAT_V. The curvilinear coordinate configuration can be specified within the configuration of the variables rather than the dataset, so your block of curvilinear coordinate configuration information will need to be given for each variable instead of in the dataset configuration at the start of the xml file.



These model output data are calculated at different ocean depths (sigma coordinates). The plot is accessing our TDS via OPeNDAP for the "Best Time Series" at:

http://oos.soest.hawaii.edu/thredds/catalog/hioos/roms_forec/hiig/catalog.html?dataset=roms_hiig_forecast/HI-ROMS_Forecast_Model_Run_best.ncd

Thanks for your help,
John Maurer
Hawaii Ocean Observing System (HiOOS)

P.S. The URLs in the error message below won't work outside our firewall unless you replace the base URL lawelawe.soest.hawaii.edu:8080 with oos.soest.hawaii.edu:
STOP -script mode, ERROR RUNNING SCRIPT
  **ERROR: inconsistent sizes of data regions: box edges (on Y axis)
           allowed only with SHADE
CONTOUR/FILL/HLIM=-158.3675:-158.1002/LEVELS=Vv/PALETTE=rainbow/HLIM=-158.3675:-158.100236/VLIM=21.25:21.5611/OVER/NOLAB plot_var[d=1] , xcoord, ycoord
Command file, command group, or REPEAT execution aborted

go "$1"
  !->  go "/usr/local/apache-tomcat-6.0.18/webapps/las/WEB-INF/classes/resources/ferret/temp/ferret_operation_1276896470193.jnl"
! Symbols from the server
                         DEFINE SYMBOL data_0_ID = svstr-hiroms_hiomwg
                                  DEFINE SYMBOL data_0_dataset_ID = hiroms_hiomwg
                                  DEFINE SYMBOL data_0_dataset_name = Hawaii Regional Oceanic Modeling System (HI-ROMS) Oahu Waianae Grid (50m)
                                  DEFINE SYMBOL data_0_dataset_url = http://lawelawe.soest.hawaii.edu:8080/thredds/dodsC/hioos/roms_forec/hiomwg/HI-ROMS_Forecast_Model_Run_Collection_best.ncd
                                  DEFINE SYMBOL data_0_ftds_url = http://lawelawe.soest.hawaii.edu:8080/thredds/dodsC/las/hiroms_hiomwg/data_lawelawe.soest.hawaii.edu_8080_thredds_dodsC_hioos_roms_forec_hiomwg_HI-ROMS_Forecast_Model_Run_Collection_best.ncd.jnl
                                  DEFINE SYMBOL data_0_grid_type = regular
                                  DEFINE SYMBOL data_0_intervals = xyt
                                  DEFINE SYMBOL data_0_name = surface v-momentum stress
                                  DEFINE SYMBOL data_0_points = xyt
                                  DEFINE SYMBOL data_0_region = region_0
                                  DEFINE SYMBOL data_0_title = surface v-momentum stress
                                  DEFINE SYMBOL data_0_units = newton meter-2
                                  DEFINE SYMBOL data_0_url = http://lawelawe.soest.hawaii.edu:8080/thredds/dodsC/hioos/roms_forec/hiomwg/HI-ROMS_Forecast_Model_Run_Collection_best.ncd
                                  DEFINE SYMBOL data_0_var = svstr
                                  DEFINE SYMBOL data_0_xpath = /lasdata/datasets/hiroms_hiomwg/variables/svstr-hiroms_hiomwg
                                  DEFINE SYMBOL data_count = 1
                                  DEFINE SYMBOL ferret_curv_lat_max = 21.570575858175
                                  DEFINE SYMBOL ferret_curv_lat_min = 21.250212932786
                                  DEFINE SYMBOL ferret_curv_lon_max = -158.095644459455
                                  DEFINE SYMBOL ferret_curv_lon_min = -158.36753276978
                                  DEFINE SYMBOL ferret_curvi_coord_lat = lat_rho
                                  DEFINE SYMBOL ferret_curvi_coord_lon = lon_rho
                                  DEFINE SYMBOL ferret_curvi_coord_mapfile = /usr/local/las/conf/server/mapfile_hiroms_hiomwg.nc
                                  DEFINE SYMBOL ferret_curvi_coord_mapvar = map
                                  DEFINE SYMBOL ferret_fill_type = fill
                                  DEFINE SYMBOL ferret_interpolate_data = false
                                  DEFINE SYMBOL ferret_land_type = contour
                                  DEFINE SYMBOL ferret_mark_grid = no
                                  DEFINE SYMBOL ferret_service_action = Plot_2D_XY
                                  DEFINE SYMBOL ferret_size = 0.5
                                  DEFINE SYMBOL ferret_view = xy
                                  DEFINE SYMBOL las_debug = false
                                  DEFINE SYMBOL operation_ID = Plot_2D_XY_zoom
                                  DEFINE SYMBOL operation_key = 417E0FADE4ABE69377D6A5B29A41B974
                                  DEFINE SYMBOL operation_name = Color plot
                                  DEFINE SYMBOL operation_service = ferret
                                  DEFINE SYMBOL operation_service_action = Plot_2D_XY
                                  DEFINE SYMBOL product_server_0_ps_timeout = 3600
                                  DEFINE SYMBOL product_server_0_ui_timeout = 20
                                  DEFINE SYMBOL product_server_0_use_cache = true
                                  DEFINE SYMBOL region_0_t_hi = 05-Jun-2010 00:00:00
                                  DEFINE SYMBOL region_0_t_lo = 05-Jun-2010 00:00:00
                                  DEFINE SYMBOL region_0_x_hi = -158.100236
                                  DEFINE SYMBOL region_0_x_lo = -158.3675
                                  DEFINE SYMBOL region_0_y_hi = 21.5611
                                  DEFINE SYMBOL region_0_y_lo = 21.25
                                  DEFINE SYMBOL result_cancel_ID = cancel
                                  DEFINE SYMBOL result_cancel_filename = /usr/local/tomcat/webapps/las/output/417E0FADE4ABE69377D6A5B29A41B974_cancel.txt
                                  DEFINE SYMBOL result_cancel_type = cancel
                                  DEFINE SYMBOL result_count = 6
                                  DEFINE SYMBOL result_debug_ID = debug
                                  DEFINE SYMBOL result_debug_filename = /usr/local/tomcat/webapps/las/output/417E0FADE4ABE69377D6A5B29A41B974_debug.txt
                                  DEFINE SYMBOL result_debug_type = debug
                                  DEFINE SYMBOL result_map_scale_ID = map_scale
                                  DEFINE SYMBOL result_map_scale_filename = /usr/local/tomcat/webapps/las/output/417E0FADE4ABE69377D6A5B29A41B974_map_scale.xml
                                  DEFINE SYMBOL result_map_scale_type = map_scale
                                  DEFINE SYMBOL result_plot_image_ID = plot_image
                                  DEFINE SYMBOL result_plot_image_filename = /usr/local/tomcat/webapps/las/output/417E0FADE4ABE69377D6A5B29A41B974_plot_image.gif
                                  DEFINE SYMBOL result_plot_image_type = image
                                  DEFINE SYMBOL result_ref_map_ID = ref_map
                                  DEFINE SYMBOL result_ref_map_filename = /usr/local/tomcat/webapps/las/output/417E0FADE4ABE69377D6A5B29A41B974_ref_map.gif
                                  DEFINE SYMBOL result_ref_map_type = image
                                  DEFINE SYMBOL result_rss_ID = rss
                                  DEFINE SYMBOL result_rss_filename = /usr/local/tomcat/webapps/las/output/BC0CB203B484F1CEC441DB126F508866_rss.rss
                                  DEFINE SYMBOL result_rss_type = rss
          GO ($operation_service_action)
  !->  GO Plot_2D_XY
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! $Author: rhs $
!
! Plot_2d_XY.jnl decides which script to call to make a 2D plot.
! In the "old" LAS UI a 2D plot has for XY has different options and other
! UI characteristics than other 2D plots so it needs its own script.
!
IF ($ferret_view"|xy>1|*>0") THEN
  !->  IF 1 THEN

    !! Make a plot in XY...
    go xy_plot_2D
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! $RCSfile: xy_plot_2D.jnl,v $
! $Revision: 1.12 $
!
! $Author: ansley $
! $Date: 2006/08/11 16:45:54 $
! 2006/07/19 Fix test of ($ferret_contour_levels"0|*>1")
! 3/7/2007: ACM. Put code to check that the region was not too small, resulting
!           in degenerate plot into LAS_initialize_data.jnl rather than in the
!           individual plot scripts.
! 3/29/2007 ACM Fix logic interpreting contents of ferret_interpolate_data
! 7/15/2007 ACM Add lines to remove labels when a degenerate 2D plot is made
!               This happens when the region chosen is smaller than a grid cell.
! 3/2008 ACM Use SHADE/TRIM for shade underlays of FILL plots (Ferret v6.1)
! 3/2008 ACM For native curvilinear plots use MODULO qualifier only on SHADE plots

! XY_plot.jnl creates an XY plot for use with the Back End Server
! code that sits behind a Live Access Server (LAS).
!
! NOTE:  This code handles overlays but not differencing.
!
! TODO:  We should support user choice of the 'base layer' variable.
! TODO:  From the Ferret script writers' perspective it would be nice
! TODO:  if this were handled in the UI so that ($data_0_...) always
! TODO:  referred to the base layer.


! Set any Ferret modes
!
! NOTE:  Should we support any of the following Ferrt modes?
! NOTE:    ASCII_FONT, CALENDAR, DEPTH_LABEL, LABELS, LATIT_LABEL, LONG_LABEL

IF ($ferret_interpolate_data%0|false>0|true>1|1|0|*>1%) THEN SET MODE INTERPOLATE
  !->  IF 0 THEN SET MODE INTERPOLATE

DEFINE SYMBOL fview = `UPCASE("($ferret_view)")`
  !->  DEFINE SYMBOL fview = XY

! Define symbols associated with the regign and data and perform any
! initialization needed for this dataset.
!
! NOTE:  Adding support for a 'base layer' variable would mean passing
! NOTE:  some other argument.  For now, though, we always use 'data_0'
! NOTE:  for the base layer and region.

GO LAS_initialize_region 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! $RCSfile: LAS_initialize_region.jnl,v $
! $Revision: 1.1 $
!
! $Author: ansley $
! $Date: 2006/07/06 17:54:11 $
!
! The LAS_initialize_region.jnl script defines the following symbols
! based on the region associated with data_#:
!
! region_~_lo/hi   -- lo and hi points on a given axis
! region_~_range   -- numeric range on a given axis
! region_~         -- domain in 'lo:hi' notation
! region_full      -- synonym for 'region_xyzt'
!
! Incoming argument determines which region to use
! The default number is 0, and the default region is region_0.
! If we are making only a map, then there are no data_ symbols
! defined, so data_0_region is not set, but we can define region
! as region_0.
!
! ACM trac 267: Do not cancel any previously set limits or region symbols;
! The previous v6 UI as to how it worked in the old product server expects
! to inherit some or all region info from the first dataset for use by the
! second in comparisons etc. Keep this behavior.

DEFINE SYMBOL num ($1"0")
  !->  DEFINE SYMBOL num 0
DEFINE SYMBOL region_name data_($num)_region
  !->  DEFINE SYMBOL region_name data_0_region
DEFINE SYMBOL region ($($region_name)"region_0")
  !->  DEFINE SYMBOL region region_0

! NOTE:  Occasionally the LAS applet will send in a longitude or latitude
! NOTE:  that looks like "24.400000000000002".  Such long, numerically
! NOTE:  irrelevant numbers can overflow Ferret's maximum symbol length.
! NOTE:  Rounding longitudes and latitudes to the nearest .00001 seems
! NOTE:  reasonable for all but the most detailed datasets.

! NOTE:  'region_x_m360' and 'region_x_p360' are used for those visualizations
! NOTE:  where Ferret doesn't auomatically deal with the modulo nature of
! NOTE:  longitude and allow the script writer to deal with this manually.

IF ($($region)_x_lo"0|*>1") THEN
  !->  IF 1 THEN
   DEFINE SYMBOL region_x_lo = `INT(100000 * ($($region)_x_lo)) / 100000`
  !->  DEFINE SYMBOL region_x_lo = -158.3675
   DEFINE SYMBOL region_x_hi = `INT(100000 * ($($region)_x_hi)) / 100000`
  !->  DEFINE SYMBOL region_x_hi = -158.1002
   DEFINE SYMBOL limits_x = ($region_x_lo):($region_x_hi)
  !->  DEFINE SYMBOL limits_x = -158.3675:-158.1002
   DEFINE SYMBOL limits_x_m360 = `($region_x_lo)-360`:`($region_x_hi)-360`
  !->  DEFINE SYMBOL limits_x_m360 = -518.3675:-518.1002
   DEFINE SYMBOL limits_x_p360 = `($region_x_lo)+360`:`($region_x_hi)+360`
  !->  DEFINE SYMBOL limits_x_p360 = 201.6325:201.8998
   DEFINE SYMBOL region_x = X=($region_x_lo):($region_x_hi)
  !->  DEFINE SYMBOL region_x = X=-158.3675:-158.1002
   DEFINE SYMBOL region_x_m360 X=`($region_x_lo)-360`:`($region_x_hi)-360`
  !->  DEFINE SYMBOL region_x_m360 X=-518.3675:-518.1002
   DEFINE SYMBOL region_x_p360 X=`($region_x_lo)+360`:`($region_x_hi)+360`
  !->  DEFINE SYMBOL region_x_p360 X=201.6325:201.8998
   IF `($region_x_hi) GE ($region_x_lo)` THEN
  !->  IF 1 THEN
     DEFINE SYMBOL region_x_range = `($region_x_hi) - ($region_x_lo)`
  !->  DEFINE SYMBOL region_x_range = 0.2672882
   ELSE
   ENDIF
ENDIF

IF ($($region)_y_lo"0|*>1") THEN
  !->  IF 1 THEN
   DEFINE SYMBOL region_y_lo = `INT(1000 * ($($region)_y_lo)) / 1000`
  !->  DEFINE SYMBOL region_y_lo = 21.25
   DEFINE SYMBOL region_y_hi = `INT(1000 * ($($region)_y_hi)) / 1000`
  !->  DEFINE SYMBOL region_y_hi = 21.561
   DEFINE SYMBOL limits_y = ($region_y_lo):($region_y_hi)
  !->  DEFINE SYMBOL limits_y = 21.25:21.561
   DEFINE SYMBOL region_y = Y=($region_y_lo):($region_y_hi)
  !->  DEFINE SYMBOL region_y = Y=21.25:21.561
   IF `($region_y_hi) GE ($region_y_lo)` THEN
  !->  IF 1 THEN
     DEFINE SYMBOL region_y_range = `($region_y_hi) - ($region_y_lo)`
  !->  DEFINE SYMBOL region_y_range = 0.3110008
   ELSE
   ENDIF
ENDIF

IF ($($region)_z_lo"0|*>1") THEN
  !->  IF 0 THEN
   ENDIF
ENDIF

! NOTE:  Normally we use 'DEFINE SYMBOL ~ = ...'
! NOTE:  For the time axis we use 'DEFINE SYMBOL ~ ...' because the Ferret
! NOTE:  parser complains about unmatched quotes if we do it the other way.

IF ($($region)_t_lo"0|*>1") THEN
  !->  IF 1 THEN
   DEFINE SYMBOL region_t_lo = ($($region)_t_lo)
  !->  DEFINE SYMBOL region_t_lo = 05-Jun-2010 00:00:00
   DEFINE SYMBOL region_t_hi = ($($region)_t_hi)
  !->  DEFINE SYMBOL region_t_hi = 05-Jun-2010 00:00:00
   DEFINE SYMBOL limits_t \"($region_t_lo)\":\"($region_t_hi)\"
  !->  DEFINE SYMBOL limits_t \"05-Jun-2010 00:00:00\":\"05-Jun-2010 00:00:00\"
   DEFINE SYMBOL region_t T=\"($region_t_lo)\":\"($region_t_hi)\"
  !->  DEFINE SYMBOL region_t T=\"05-Jun-2010 00:00:00\":\"05-Jun-2010 00:00:00\"
ENDIF

! Now build up all possible multi-axis regions, being careful not to use
! commas when a region is missing

! region_xy
IF ($region_x"0|*>1") THEN
  !->  IF 1 THEN
   IF ($region_y"0|*>1") THEN
  !->  IF 1 THEN
     DEFINE SYMBOL region_xy = ($region_x),($region_y)
  !->  DEFINE SYMBOL region_xy = X=-158.3675:-158.1002,Y=21.25:21.561
   ELSE
   ENDIF
ELSE
   ENDIF
ENDIF

! region_xz
IF ($region_x"0|*>1") THEN
  !->  IF 1 THEN
   IF ($region_z"0|*>1") THEN
  !->  IF 0 THEN
   ELSE
     DEFINE SYMBOL region_xz = ($region_x)
  !->  DEFINE SYMBOL region_xz = X=-158.3675:-158.1002
   ENDIF
ELSE
   ENDIF
ENDIF

! region_xt
IF ($region_x"0|*>1") THEN
  !->  IF 1 THEN
   IF ($region_t"0|*>1") THEN
  !->  IF 1 THEN
     DEFINE SYMBOL region_xt = ($region_x),($region_t)
  !->  DEFINE SYMBOL region_xt = X=-158.3675:-158.1002,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
   ELSE
   ENDIF
ELSE
   ENDIF
ENDIF

! region_yz
IF ($region_y"0|*>1") THEN
  !->  IF 1 THEN
   IF ($region_z"0|*>1") THEN
  !->  IF 0 THEN
   ELSE
     DEFINE SYMBOL region_yz = ($region_y)
  !->  DEFINE SYMBOL region_yz = Y=21.25:21.561
   ENDIF
ELSE
   ENDIF
ENDIF

! region_yt
IF ($region_y"0|*>1") THEN
  !->  IF 1 THEN
   IF ($region_t"0|*>1") THEN
  !->  IF 1 THEN
     DEFINE SYMBOL region_yt = ($region_y),($region_t)
  !->  DEFINE SYMBOL region_yt = Y=21.25:21.561,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
   ELSE
   ENDIF
ELSE
   ENDIF
ENDIF

! region_zt
IF ($region_z"0|*>1") THEN
  !->  IF 0 THEN
   ENDIF
ELSE
   IF ($region_t"0|*>1") THEN
  !->  IF 1 THEN
     DEFINE SYMBOL region_zt = ($region_t)
  !->  DEFINE SYMBOL region_zt = T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
   ENDIF
ENDIF

! region_xyz
IF ($region_xy"0|*>1") THEN
  !->  IF 1 THEN
   IF ($region_z"0|*>1") THEN
  !->  IF 0 THEN
   ELSE
     DEFINE SYMBOL region_xyz = ($region_xy)
  !->  DEFINE SYMBOL region_xyz = X=-158.3675:-158.1002,Y=21.25:21.561
   ENDIF
ELSE
   ENDIF
ENDIF

! region_xyt
IF ($region_xy"0|*>1") THEN
  !->  IF 1 THEN
   IF ($region_t"0|*>1") THEN
  !->  IF 1 THEN
     DEFINE SYMBOL region_xyt = ($region_xy),($region_t)
  !->  DEFINE SYMBOL region_xyt = X=-158.3675:-158.1002,Y=21.25:21.561,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
   ELSE
   ENDIF
ELSE
   ENDIF
ENDIF

! region_yzt
IF ($region_yz"0|*>1") THEN
  !->  IF 1 THEN
   IF ($region_t"0|*>1") THEN
  !->  IF 1 THEN
     DEFINE SYMBOL region_yzt = ($region_yz),($region_t)
  !->  DEFINE SYMBOL region_yzt = Y=21.25:21.561,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
   ELSE
   ENDIF
ELSE
   ENDIF
ENDIF

! region_xyzt
IF ($region_xyz"0|*>1") THEN
  !->  IF 1 THEN
   IF ($region_t"0|*>1") THEN
  !->  IF 1 THEN
     DEFINE SYMBOL region_xyzt = ($region_xyz),($region_t)
  !->  DEFINE SYMBOL region_xyzt = X=-158.3675:-158.1002,Y=21.25:21.561,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
   ELSE
   ENDIF
ELSE
   ENDIF
ENDIF

DEFINE SYMBOL region_full = ($region_xyzt)
  !->  DEFINE SYMBOL region_full = X=-158.3675:-158.1002,Y=21.25:21.561,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"


! For sampling from a curvilinear variable, save the region definitions with
! the variable number.
IF ($region_x"0|*>1") THEN DEFINE SYMBOL region_($num)_x = ($region_x)
  !->  IF 1 THEN DEFINE SYMBOL region_0_x = X=-158.3675:-158.1002
  !->  DEFINE SYMBOL region_0_x = X=-158.3675:-158.1002
IF ($region_y"0|*>1") THEN DEFINE SYMBOL region_($num)_y = ($region_y)
  !->  IF 1 THEN DEFINE SYMBOL region_0_y = Y=21.25:21.561
  !->  DEFINE SYMBOL region_0_y = Y=21.25:21.561
IF ($region_z"0|*>1") THEN DEFINE SYMBOL region_($num)_z = ($region_z)
  !->  IF 0 THEN DEFINE SYMBOL region_0_z =
IF ($region_t"0|*>1") THEN DEFINE SYMBOL region_($num)_t = ($region_t)
  !->  IF 1 THEN DEFINE SYMBOL region_0_t = T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
  !->  DEFINE SYMBOL region_0_t = T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
IF ($region_xt"0|*>1") THEN DEFINE SYMBOL region_($num)_xt = ($region_xt)
  !->  IF 1 THEN DEFINE SYMBOL region_0_xt = X=-158.3675:-158.1002,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
  !->  DEFINE SYMBOL region_0_xt = X=-158.3675:-158.1002,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
IF ($region_xy"0|*>1") THEN DEFINE SYMBOL region_($num)_xy = ($region_xy)
  !->  IF 1 THEN DEFINE SYMBOL region_0_xy = X=-158.3675:-158.1002,Y=21.25:21.561
  !->  DEFINE SYMBOL region_0_xy = X=-158.3675:-158.1002,Y=21.25:21.561
IF ($region_xz"0|*>1") THEN DEFINE SYMBOL region_($num)_xz = ($region_xz)
  !->  IF 1 THEN DEFINE SYMBOL region_0_xz = X=-158.3675:-158.1002
  !->  DEFINE SYMBOL region_0_xz = X=-158.3675:-158.1002
IF ($region_yt"0|*>1") THEN DEFINE SYMBOL region_($num)_yt = ($region_yt)
  !->  IF 1 THEN DEFINE SYMBOL region_0_yt = Y=21.25:21.561,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
  !->  DEFINE SYMBOL region_0_yt = Y=21.25:21.561,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
IF ($region_yz"0|*>1") THEN DEFINE SYMBOL region_($num)_yz = ($region_yz)
  !->  IF 1 THEN DEFINE SYMBOL region_0_yz = Y=21.25:21.561
  !->  DEFINE SYMBOL region_0_yz = Y=21.25:21.561
IF ($region_zt"0|*>1") THEN DEFINE SYMBOL region_($num)_zt = ($region_zt)
  !->  IF 1 THEN DEFINE SYMBOL region_0_zt = T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
  !->  DEFINE SYMBOL region_0_zt = T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"

! For SOCAT server labels, make time symbols w/o the trailing 00:00:00

IF ($region_0_t_lo"0|*>1") THEN
  !->  IF 1 THEN
    DEFINE SYMBOL t_lab_lo = ($region_0_t_lo)
  !->  DEFINE SYMBOL t_lab_lo = 05-Jun-2010 00:00:00
    LET iz = STRINDEX("($region_0_t_lo)", " 00:00:00")
  !->  DEFINE VARIABLE iz = STRINDEX("05-Jun-2010 00:00:00", " 00:00:00")
    IF `iz GT 0` THEN
  !->  IF 1 THEN
       DEFINE SYMBOL t_lab_lo = `SUBSTRING("($region_0_t_lo)", 1, iz-1)`
  !->  DEFINE SYMBOL t_lab_lo = 05-Jun-2010
    ELSE
    ENDIF
ENDIF

IF ($region_0_t_hi"0|*>1") THEN
  !->  IF 1 THEN
    DEFINE SYMBOL t_lab_hi = ($region_0_t_hi)
  !->  DEFINE SYMBOL t_lab_hi = 05-Jun-2010 00:00:00
    LET iz = STRINDEX("($region_0_t_hi)", " 00:00:00")
  !->  DEFINE VARIABLE iz = STRINDEX("05-Jun-2010 00:00:00", " 00:00:00")
    IF `iz GT 0` THEN
  !->  IF 1 THEN
       DEFINE SYMBOL t_lab_hi = `SUBSTRING("($region_0_t_hi)", 1, iz-1)`
  !->  DEFINE SYMBOL t_lab_hi = 05-Jun-2010
    ELSE
    ENDIF
ENDIF

! If no regions have been defined then we have an error.

IF ($region_full"1|*>0")  THEN
  !->  IF 0  THEN
ENDIF

! End of LAS_initialize_region.jnl ------------------------------------------------------
GO LAS_initialize_data 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! $RCSfile: LAS_initialize_data.jnl,v $
! $Revision: 1.2 $
!
! $Author: ansley $
! $Date: 2007/29/2007
!
! The LAS_initialize_data.jnl script takes care of everything having to
! do with initializing a datset for later use.
!
! LAS_initialize_data.jnl takes an argument that specifies which data
! item [0|1|2|3|...] to create symbols for.
!
! 3/2007:
! split up previous version of LAS_initialize_data.jnl into two;
! initialize the dataset and define the plot (or output listing) variable.
! This allows the custom init scripts to call LAS_initialize_dataset, then
! issue commands for the customization, then call LAS_initialize_variable
!
! 8/2007:
! The custom init scripts now consist of only SET DATA and the custom commands.
! This lets F-TDS run first and call the init script to create the data set
! that will be used by the Ferret product script. When F-TDS is done it will
! not send the symbol ferret_init_script to the product scripts so we will just skip
! that step.
!
! 8/2007:
! Some of the custom init scripts previously contained commands like SET MEMORY
! or SET MODE which are intended to be executed by the product script These need
! to be separated from commands for fixing grids or regridding which are executed
! prior to the product script being run by F-TDS. These commands are to be specified
! in the dataset configuration as ferret_init_commands, whose the value is a set
! of Ferret commands separated by semicolons.
!
GO LAS_initialize_dataset ($1"0")
  !->  GO LAS_initialize_dataset 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! $RCSfile: LAS_initialize_dataset.jnl

! This is the first part of LAS_initialize_data.jnl used for standard and
! customized init scripts

! $Author: ansley, jing
! $Date: 2007/29/2007

! 6/29/2007
! Allow for data_0_units or data_1_units etc to be defined a null string or a
! string containing a single space. If data_0_units is either undefined or is
! one of these blank strings, then use the attnames syntax to see if the dataset
! variable has units defined, and if so define the data_units symbol from that.


! The LAS_initialize_data.jnl script takes care of everything having to
! do with initializing a datset for later use.
!
! LAS_initialize_data.jnl takes an argument that specifies which data
! item [0|1|2|3|...] to create symbols for.

!ACM_note: if we use a loop in the plot routine, we are not
! limited to 9 data items
! DEFINE SYMBOL num ($1"0|0|1|2|3|4|5|6|7|8|9")
DEFINE SYMBOL num ($1"0")
  !->  DEFINE SYMBOL num 0

! TODO:  It would be nice if the java code removed this dependency upon
! TODO:  whether an operation was 'chained' or not.

! Check whether the source data was part of a 'chained' operation.
!ACM note: How does this jibe with what I do below changing data_url to data_num??

IF ($data_($num)_chained"0|1|*>1) THEN
  !->  IF 0 THEN
ELSE
   DEFINE SYMBOL data_url \"($data_($num)_url)\"
  !->  DEFINE SYMBOL data_url \"http://lawelawe.soest.hawaii.edu:8080/thredds/dodsC/hioos/roms_forec/hiomwg/HI-ROMS_Forecast_Model_Run_Collection_best.ncd\";
ENDIF

IF ($data_($num)_var"0|*>1") THEN DEFINE SYMBOL data_var ($data_($num)_var)
  !->  IF 1 THEN DEFINE SYMBOL data_var svstr
  !->  DEFINE SYMBOL data_var svstr

! Use the units passed in from the XML unless they are null;
! in that case try to get from the dataset

! Do not define data_units with an empty string
IF ($data_($num)_units%1|"">1|*>0%) THEN
  !->  IF 0 THEN
ELIF ($data_($num)_units%1|" ">1|*>0%) THEN
  !->  ELIF 0 THEN
ELSE
    DEFINE SYMBOL data_units ($data_($num)_units)
  !->  DEFINE SYMBOL data_units newton meter-2
ENDIF

IF ($data_units"0|*>1") THEN
  !->  IF 1 THEN
    DEFINE SYMBOL data_units (($data_($num)_units))
  !->  DEFINE SYMBOL data_units (newton meter-2)
    IF `STRINDEX("($data_units)", "((") GT 0` THEN \
      DEFINE SYMBOL data_units ($data_($num)_units)
  !->  IF 0 THEN      DEFINE SYMBOL data_units newton meter-2
ENDIF

IF ($data_($num)_name"0|1|*>1) THEN
  !->  IF 1 THEN
    IF ($data_($num)_title"0|*>1") THEN DEFINE SYMBOL data_title ($data_($num)_title)
  !->  IF 1 THEN DEFINE SYMBOL data_title surface v-momentum stress
  !->  DEFINE SYMBOL data_title surface v-momentum stress
ELSE
ENDIF

DEFINE SYMBOL ferret_plot_title "($data_title) ($data_units)"
  !->  DEFINE SYMBOL ferret_plot_title "surface v-momentum stress (newton meter-2)"

! TODO:  Use new error features in Ferret to turn off STDERR and check
! TODO:  for Ferret error symbols to see if the SET DATA command actually worked.

! SET DATA and check for errors

SET DATA ($data_url)
  !->  SET DATA "http://lawelawe.soest.hawaii.edu:8080/thredds/dodsC/hioos/roms_forec/hiomwg/HI-ROMS_Forecast_Model_Run_Collection_best.ncd";

LET ulen = STRLEN ("($data_($num)_units)")
  !->  DEFINE VARIABLE ulen = STRLEN ("newton meter-2")
IF `(STRINDEX("($data_($num)_units)", "'") EQ 1) AND (STRRINDEX("($data_($num)_units)", "'") EQ ulen)` THEN
  !->  IF 0 THEN
ENDIF

IF ($fer_last_error"0|*>1") THEN
  !->  IF 0 THEN
ENDIF

! End of $RCSfile ------------LAS_initialize_dataset.jnl--------------------------


IF ($ferret_init_script"0|*>1") THEN GO ($ferret_init_script) ($1"0")
  !->  IF 0 THEN GO   0

IF ($ferret_init_commands"0|*>1") THEN
  !->  IF 0 THEN
ENDIF

GO LAS_initialize_variable
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! $RCSfile: LAS_initialize_variable.jnl
! $Revision: 1.1
!
! $Author: Ansley, Jing $
! $Date: 2007/29/2007
! ACM 4/2007 apply ferret_expression2 to second plot of comparisons.
! ACM 8/2007 Call LAS_auto_levels to set up auto contour/fill levels.
! 3/2008 ACM Use SHADE/TRIM for shade underlays of FILL plots (Ferret v6.1),
!            so no need to call LAS_define_region_plus_1.jnl
! 10-Jul-2008 ACM Define ferret_x_var, needed for listing data to files

! this is the second part of LAS_initialize_data.jnl

! Define the plot variable. For comparison plots, we want to save the dataset number
! for each dataset.

DEFINE SYMBOL data_num = `($data_var),RETURN=dsetnum`
  !->  DEFINE SYMBOL data_num = 1
DEFINE SYMBOL data_($num)_num = `($data_var),RETURN=dsetnum`
  !->  DEFINE SYMBOL data_0_num = 1

LET attlist = ($data_var).attnames
  !->  DEFINE VARIABLE attlist = svstr.attnames
DEFINE SYMBOL data_var_only = `UPCASE("($data_var)")`
  !->  DEFINE SYMBOL data_var_only = SVSTR

! setup for analysis ops on curvilinear grids
IF `IS_ELEMENT_OF_STR (attlist, "ferret_definition") GT 0 AND\
     ($ferret_curvi_coord_lon"0|*>1")` THEN
  !->  IF 0 THEN
ENDIF

! Be sure units and title are defined.
! If units are not defined, try to get units from the data variable.
! If the variable in the file has no units, leave data_units symbol undefined.

! data_units should have been defined in LAS_initialize_dataset

IF ($data_units"0|*>1") THEN
  !->  IF 1 THEN
    DEFINE SYMBOL has_units = 1
ELSE
       ENDIF
    ENDIF
ENDIF

DEFINE SYMBOL ferret_plot_title "($data_title) ($data_units)"
  !->  DEFINE SYMBOL ferret_plot_title "surface v-momentum stress (newton meter-2)"

IF `($data_title"0|*>1") EQ 0` THEN
  !->  IF 0 THEN
   ENDIF
ENDIF


DEFINE SYMBOL ferret_plot_var = ($data_var)[d=($data_num),($region_full)]
  !->  DEFINE SYMBOL ferret_plot_var = svstr[d=1,X=-158.3675:-158.1002,Y=21.25:21.561,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"]
IF ($analysis_def"0|*>1") THEN  ! analysis_def from curvi data or transform
  !->  IF 0 THEN
ENDIF

DEFINE SYMBOL ferret_plot_var_noregion = ($data_var)[d=($data_num)]
  !->  DEFINE SYMBOL ferret_plot_var_noregion = svstr[d=1]
DEFINE SYMBOL ferret_plot_var_($num)_noregion = ($data_var)[d=($data_num)]
  !->  DEFINE SYMBOL ferret_plot_var_0_noregion = svstr[d=1]

DEFINE SYMBOL ferret_plot_base_var = ($ferret_plot_var)
  !->  DEFINE SYMBOL ferret_plot_base_var = svstr[d=1,X=-158.3675:-158.1002,Y=21.25:21.561,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"]
DEFINE SYMBOL ferret_plot_base_var_($num) = ($ferret_plot_var)
  !->  DEFINE SYMBOL ferret_plot_base_var_0 = svstr[d=1,X=-158.3675:-158.1002,Y=21.25:21.561,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"]
DEFINE SYMBOL ferret_plot_base_var_noregion = ($data_var)[d=($data_num)]
  !->  DEFINE SYMBOL ferret_plot_base_var_noregion = svstr[d=1]

! Needed for transform_seasonal, save variable definition without any
! time-region information that may be added, and also with the time region only

DEFINE SYMBOL ferret_xyz_var = ($data_var)[d=($data_num),($region_xyz)]
  !->  DEFINE SYMBOL ferret_xyz_var = svstr[d=1,X=-158.3675:-158.1002,Y=21.25:21.561]
DEFINE SYMBOL ferret_t_var = ($data_var)[d=($data_num),($region_t)]
  !->  DEFINE SYMBOL ferret_t_var = svstr[d=1,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"]

! ferret_x_var needed for listing data to files
DEFINE SYMBOL ferret_x_var = ($data_var)[d=($data_num),($region_x)]
  !->  DEFINE SYMBOL ferret_x_var = svstr[d=1,X=-158.3675:-158.1002]
IF `($region_x"0|*>1) EQ 0` THEN DEFINE SYMBOL ferret_x_var = ($data_var)[d=($data_num)]
  !->  IF 0 THEN DEFINE SYMBOL ferret_x_var = svstr[d=1]

! Apply the expression in ferret_expression. $ represents the variable.

! Check if we are working with the second of two variables in comparison mode
IF ($variables_initialized"0|*>1") THEN
  !->  IF 0 THEN
ENDIF

! The side by side plots pretend that the second plot is plot 1, so
IF `STRCMP("($operation_service_action)", "Side2") EQ 0` THEN
  !->  IF 0 THEN
ENDIF

IF ($ferret_expression"0|*>1") THEN GO LAS_expression
  !->  IF 0 THEN GO LAS_expression

! Apply any transforms that may have been specified.
GO LAS_transforms ($variables_initialized"0|*>1")
  !->  GO LAS_transforms 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! LAS_transforms.jnl
!
! $Author: ansley $
! $Date: 2006/09/27  $
! 2007/3/13 ACM changes for all slices of curvilinear data.
! 4/2007    ACM Apply Ferret symbols for any expression that may have been defined

!
! LAS_transforms.jnl applies one or more transforms to $ferret_plot_var

! This script is called from LAS_initialize_data after the region and
! data have been initialized.
! Argument is the variable number (0 or 1 if this is a comparison)

DEFINE SYMBOL num ($1"0")
  !->  DEFINE SYMBOL num 0

!  Transform to 3-month seasonal averages, with desired centering
IF `($constraint_0_lhs"0|Seasonal_Regridding>1|*>0")` THEN
  !->  IF 0 THEN
ENDIF

! Transform to 1-season per year, centered on any month, with season being 1, 3, or 5 months long.
IF `STRINDEX("($constraint_0_lhs"0")", "Season_length") GT 0` THEN
  !->  IF 0 THEN
ENDIF

! See if the grid is curvilinear in XY, Hybrid Z or both

DEFINE SYMBOL do_curvi_xy = 0
DEFINE SYMBOL do_hybrid_z = 0
DEFINE SYMBOL do_curvi_xy_and_hybrid_z = 0

IF ($ferret_curvi_coord_lat"0|*>1") THEN DEFINE SYMBOL do_curvi_xy = 1
  !->  IF 1 THEN DEFINE SYMBOL do_curvi_xy = 1
  !->  DEFINE SYMBOL do_curvi_xy = 1
IF ($ferret_thk_var"0|*>1") THEN  DEFINE SYMBOL do_hybrid_z = 1
  !->  IF 0 THEN  DEFINE SYMBOL do_hybrid_z = 1
IF `($do_curvi_xy) + ($do_hybrid_z) EQ 2` THEN DEFINE SYMBOL do_curvi_xy_and_hybrid_z = 1
  !->  IF 0 THEN DEFINE SYMBOL do_curvi_xy_and_hybrid_z = 1

IF ($do_curvi_xy_and_hybrid_z) THEN GO transform_hybrid_z_curvi_xy
  !->  IF 0 THEN GO transform_hybrid_z_curvi_xy

! Set up to deal with hybrid-Z data.
IF `($do_hybrid_z) AND ($do_curvi_xy_and_hybrid_z"0") EQ 0` THEN \
    GO transform_hybrid_z.jnl
  !->  IF 0 THEN    GO transform_hybrid_z.jnl

! Set up to deal with curvilinear XY data
IF ($do_curvi_xy) THEN GO transform_curvi_xy.jnl
  !->  IF 1 THEN GO transform_curvi_xy.jnl
  !->  GO transform_curvi_xy.jnl
! transform_curvi_xy.jnl
!
! 18-Apr-2007 extracted from LAS_transforms.jnl
! Set up for curvilinear XY data: curvilinear-to-rectilinear regridding
! or native curvilinear xy plots or sample from curvilinear coordinates.

DEFINE SYMBOL which_var ($num)
  !->  DEFINE SYMBOL which_var 0

IF `($constraint_0_lhs"0|Curv_to_Rect_Regridding>1|*>0")` THEN
  !->  IF 0 THEN
ELIF  `STRINDEX("($ferret_view)", "xy") EQ 0` THEN
  !->  ELIF  0 THEN
    ENDIF
ELSE
    IF ($ferret_interpolate_data%0|false>0|true>1|1|0|*>1%) THEN \
       DEFINE SYMBOL data_var_transform = , Interpolated from Curvilinear coordinates
  !->  IF 0 THEN       DEFINE SYMBOL data_var_transform = , Interpolated from Curvilinear coordinates
ENDIF

! Check the regions in x and y. The Sampling schemes work best if they
! dont have to do moduloing; reset x regions to try to match the longitude
! coordinate variable, and call the initialize_region script again.

! For large datasets, we might pre-set these in the initialization script.
! Compute them only if undefined

IF `($ferret_curv_lon_min"1|*>0")` THEN \
    DEFINE SYMBOL ferret_curv_lon_min = `($ferret_curvi_coord_lon)[d=($data_num),x=@min,y=@min]`
  !->  IF 0 THEN    DEFINE SYMBOL ferret_curv_lon_min = `lon_rho[d=1,x=@min,y=@min]`
IF `($ferret_curv_lon_max"1|*>0")` THEN \
    DEFINE SYMBOL ferret_curv_lon_max = `($ferret_curvi_coord_lon)[d=($data_num),x=@max,y=@max]`
  !->  IF 0 THEN    DEFINE SYMBOL ferret_curv_lon_max = `lon_rho[d=1,x=@max,y=@max]`

! e.g. tripolar grid where the range is 0 to 426 messes up the calculations...

IF `($ferret_curv_lon_max)- ($ferret_curv_lon_min) GT 360` THEN DEFINE SYMBOL ferret_curv_lon_max `($ferret_curv_lon_min) + 360`
  !->  IF 0 THEN DEFINE SYMBOL ferret_curv_lon_max `-158.36753276978 + 360`

IF `($region_x_lo_orig"0|*>1") EQ 0 AND ($region_0_x_lo"0|*>1|)` THEN
  !->  IF 1 THEN
    DEFINE SYMBOL region_0_x_lo_orig =  ($region_0_x_lo)
  !->  DEFINE SYMBOL region_0_x_lo_orig =  -158.3675
    DEFINE SYMBOL region_0_x_hi_orig =  ($region_0_x_hi)
  !->  DEFINE SYMBOL region_0_x_hi_orig =  -158.100236
ENDIF

    GO LAS_initialize_region ($num)
  !->  GO LAS_initialize_region 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! $RCSfile: LAS_initialize_region.jnl,v $
! $Revision: 1.1 $
!
! $Author: ansley $
! $Date: 2006/07/06 17:54:11 $
!
! The LAS_initialize_region.jnl script defines the following symbols
! based on the region associated with data_#:
!
! region_~_lo/hi   -- lo and hi points on a given axis
! region_~_range   -- numeric range on a given axis
! region_~         -- domain in 'lo:hi' notation
! region_full      -- synonym for 'region_xyzt'
!
! Incoming argument determines which region to use
! The default number is 0, and the default region is region_0.
! If we are making only a map, then there are no data_ symbols
! defined, so data_0_region is not set, but we can define region
! as region_0.
!
! ACM trac 267: Do not cancel any previously set limits or region symbols;
! The previous v6 UI as to how it worked in the old product server expects
! to inherit some or all region info from the first dataset for use by the
! second in comparisons etc. Keep this behavior.

DEFINE SYMBOL num ($1"0")
  !->  DEFINE SYMBOL num 0
DEFINE SYMBOL region_name data_($num)_region
  !->  DEFINE SYMBOL region_name data_0_region
DEFINE SYMBOL region ($($region_name)"region_0")
  !->  DEFINE SYMBOL region region_0

! NOTE:  Occasionally the LAS applet will send in a longitude or latitude
! NOTE:  that looks like "24.400000000000002".  Such long, numerically
! NOTE:  irrelevant numbers can overflow Ferret's maximum symbol length.
! NOTE:  Rounding longitudes and latitudes to the nearest .00001 seems
! NOTE:  reasonable for all but the most detailed datasets.

! NOTE:  'region_x_m360' and 'region_x_p360' are used for those visualizations
! NOTE:  where Ferret doesn't auomatically deal with the modulo nature of
! NOTE:  longitude and allow the script writer to deal with this manually.

IF ($($region)_x_lo"0|*>1") THEN
  !->  IF 1 THEN
   DEFINE SYMBOL region_x_lo = `INT(100000 * ($($region)_x_lo)) / 100000`
  !->  DEFINE SYMBOL region_x_lo = -158.3675
   DEFINE SYMBOL region_x_hi = `INT(100000 * ($($region)_x_hi)) / 100000`
  !->  DEFINE SYMBOL region_x_hi = -158.1002
   DEFINE SYMBOL limits_x = ($region_x_lo):($region_x_hi)
  !->  DEFINE SYMBOL limits_x = -158.3675:-158.1002
   DEFINE SYMBOL limits_x_m360 = `($region_x_lo)-360`:`($region_x_hi)-360`
  !->  DEFINE SYMBOL limits_x_m360 = -518.3675:-518.1002
   DEFINE SYMBOL limits_x_p360 = `($region_x_lo)+360`:`($region_x_hi)+360`
  !->  DEFINE SYMBOL limits_x_p360 = 201.6325:201.8998
   DEFINE SYMBOL region_x = X=($region_x_lo):($region_x_hi)
  !->  DEFINE SYMBOL region_x = X=-158.3675:-158.1002
   DEFINE SYMBOL region_x_m360 X=`($region_x_lo)-360`:`($region_x_hi)-360`
  !->  DEFINE SYMBOL region_x_m360 X=-518.3675:-518.1002
   DEFINE SYMBOL region_x_p360 X=`($region_x_lo)+360`:`($region_x_hi)+360`
  !->  DEFINE SYMBOL region_x_p360 X=201.6325:201.8998
   IF `($region_x_hi) GE ($region_x_lo)` THEN
  !->  IF 1 THEN
     DEFINE SYMBOL region_x_range = `($region_x_hi) - ($region_x_lo)`
  !->  DEFINE SYMBOL region_x_range = 0.2672882
   ELSE
   ENDIF
ENDIF

IF ($($region)_y_lo"0|*>1") THEN
  !->  IF 1 THEN
   DEFINE SYMBOL region_y_lo = `INT(1000 * ($($region)_y_lo)) / 1000`
  !->  DEFINE SYMBOL region_y_lo = 21.25
   DEFINE SYMBOL region_y_hi = `INT(1000 * ($($region)_y_hi)) / 1000`
  !->  DEFINE SYMBOL region_y_hi = 21.561
   DEFINE SYMBOL limits_y = ($region_y_lo):($region_y_hi)
  !->  DEFINE SYMBOL limits_y = 21.25:21.561
   DEFINE SYMBOL region_y = Y=($region_y_lo):($region_y_hi)
  !->  DEFINE SYMBOL region_y = Y=21.25:21.561
   IF `($region_y_hi) GE ($region_y_lo)` THEN
  !->  IF 1 THEN
     DEFINE SYMBOL region_y_range = `($region_y_hi) - ($region_y_lo)`
  !->  DEFINE SYMBOL region_y_range = 0.3110008
   ELSE
   ENDIF
ENDIF

IF ($($region)_z_lo"0|*>1") THEN
  !->  IF 0 THEN
   ENDIF
ENDIF

! NOTE:  Normally we use 'DEFINE SYMBOL ~ = ...'
! NOTE:  For the time axis we use 'DEFINE SYMBOL ~ ...' because the Ferret
! NOTE:  parser complains about unmatched quotes if we do it the other way.

IF ($($region)_t_lo"0|*>1") THEN
  !->  IF 1 THEN
   DEFINE SYMBOL region_t_lo = ($($region)_t_lo)
  !->  DEFINE SYMBOL region_t_lo = 05-Jun-2010 00:00:00
   DEFINE SYMBOL region_t_hi = ($($region)_t_hi)
  !->  DEFINE SYMBOL region_t_hi = 05-Jun-2010 00:00:00
   DEFINE SYMBOL limits_t \"($region_t_lo)\":\"($region_t_hi)\"
  !->  DEFINE SYMBOL limits_t \"05-Jun-2010 00:00:00\":\"05-Jun-2010 00:00:00\"
   DEFINE SYMBOL region_t T=\"($region_t_lo)\":\"($region_t_hi)\"
  !->  DEFINE SYMBOL region_t T=\"05-Jun-2010 00:00:00\":\"05-Jun-2010 00:00:00\"
ENDIF

! Now build up all possible multi-axis regions, being careful not to use
! commas when a region is missing

! region_xy
IF ($region_x"0|*>1") THEN
  !->  IF 1 THEN
   IF ($region_y"0|*>1") THEN
  !->  IF 1 THEN
     DEFINE SYMBOL region_xy = ($region_x),($region_y)
  !->  DEFINE SYMBOL region_xy = X=-158.3675:-158.1002,Y=21.25:21.561
   ELSE
   ENDIF
ELSE
   ENDIF
ENDIF

! region_xz
IF ($region_x"0|*>1") THEN
  !->  IF 1 THEN
   IF ($region_z"0|*>1") THEN
  !->  IF 0 THEN
   ELSE
     DEFINE SYMBOL region_xz = ($region_x)
  !->  DEFINE SYMBOL region_xz = X=-158.3675:-158.1002
   ENDIF
ELSE
   ENDIF
ENDIF

! region_xt
IF ($region_x"0|*>1") THEN
  !->  IF 1 THEN
   IF ($region_t"0|*>1") THEN
  !->  IF 1 THEN
     DEFINE SYMBOL region_xt = ($region_x),($region_t)
  !->  DEFINE SYMBOL region_xt = X=-158.3675:-158.1002,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
   ELSE
   ENDIF
ELSE
   ENDIF
ENDIF

! region_yz
IF ($region_y"0|*>1") THEN
  !->  IF 1 THEN
   IF ($region_z"0|*>1") THEN
  !->  IF 0 THEN
   ELSE
     DEFINE SYMBOL region_yz = ($region_y)
  !->  DEFINE SYMBOL region_yz = Y=21.25:21.561
   ENDIF
ELSE
   ENDIF
ENDIF

! region_yt
IF ($region_y"0|*>1") THEN
  !->  IF 1 THEN
   IF ($region_t"0|*>1") THEN
  !->  IF 1 THEN
     DEFINE SYMBOL region_yt = ($region_y),($region_t)
  !->  DEFINE SYMBOL region_yt = Y=21.25:21.561,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
   ELSE
   ENDIF
ELSE
   ENDIF
ENDIF

! region_zt
IF ($region_z"0|*>1") THEN
  !->  IF 0 THEN
   ENDIF
ELSE
   IF ($region_t"0|*>1") THEN
  !->  IF 1 THEN
     DEFINE SYMBOL region_zt = ($region_t)
  !->  DEFINE SYMBOL region_zt = T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
   ENDIF
ENDIF

! region_xyz
IF ($region_xy"0|*>1") THEN
  !->  IF 1 THEN
   IF ($region_z"0|*>1") THEN
  !->  IF 0 THEN
   ELSE
     DEFINE SYMBOL region_xyz = ($region_xy)
  !->  DEFINE SYMBOL region_xyz = X=-158.3675:-158.1002,Y=21.25:21.561
   ENDIF
ELSE
   ENDIF
ENDIF

! region_xyt
IF ($region_xy"0|*>1") THEN
  !->  IF 1 THEN
   IF ($region_t"0|*>1") THEN
  !->  IF 1 THEN
     DEFINE SYMBOL region_xyt = ($region_xy),($region_t)
  !->  DEFINE SYMBOL region_xyt = X=-158.3675:-158.1002,Y=21.25:21.561,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
   ELSE
   ENDIF
ELSE
   ENDIF
ENDIF

! region_yzt
IF ($region_yz"0|*>1") THEN
  !->  IF 1 THEN
   IF ($region_t"0|*>1") THEN
  !->  IF 1 THEN
     DEFINE SYMBOL region_yzt = ($region_yz),($region_t)
  !->  DEFINE SYMBOL region_yzt = Y=21.25:21.561,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
   ELSE
   ENDIF
ELSE
   ENDIF
ENDIF

! region_xyzt
IF ($region_xyz"0|*>1") THEN
  !->  IF 1 THEN
   IF ($region_t"0|*>1") THEN
  !->  IF 1 THEN
     DEFINE SYMBOL region_xyzt = ($region_xyz),($region_t)
  !->  DEFINE SYMBOL region_xyzt = X=-158.3675:-158.1002,Y=21.25:21.561,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
   ELSE
   ENDIF
ELSE
   ENDIF
ENDIF

DEFINE SYMBOL region_full = ($region_xyzt)
  !->  DEFINE SYMBOL region_full = X=-158.3675:-158.1002,Y=21.25:21.561,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"


! For sampling from a curvilinear variable, save the region definitions with
! the variable number.
IF ($region_x"0|*>1") THEN DEFINE SYMBOL region_($num)_x = ($region_x)
  !->  IF 1 THEN DEFINE SYMBOL region_0_x = X=-158.3675:-158.1002
  !->  DEFINE SYMBOL region_0_x = X=-158.3675:-158.1002
IF ($region_y"0|*>1") THEN DEFINE SYMBOL region_($num)_y = ($region_y)
  !->  IF 1 THEN DEFINE SYMBOL region_0_y = Y=21.25:21.561
  !->  DEFINE SYMBOL region_0_y = Y=21.25:21.561
IF ($region_z"0|*>1") THEN DEFINE SYMBOL region_($num)_z = ($region_z)
  !->  IF 0 THEN DEFINE SYMBOL region_0_z =
IF ($region_t"0|*>1") THEN DEFINE SYMBOL region_($num)_t = ($region_t)
  !->  IF 1 THEN DEFINE SYMBOL region_0_t = T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
  !->  DEFINE SYMBOL region_0_t = T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
IF ($region_xt"0|*>1") THEN DEFINE SYMBOL region_($num)_xt = ($region_xt)
  !->  IF 1 THEN DEFINE SYMBOL region_0_xt = X=-158.3675:-158.1002,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
  !->  DEFINE SYMBOL region_0_xt = X=-158.3675:-158.1002,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
IF ($region_xy"0|*>1") THEN DEFINE SYMBOL region_($num)_xy = ($region_xy)
  !->  IF 1 THEN DEFINE SYMBOL region_0_xy = X=-158.3675:-158.1002,Y=21.25:21.561
  !->  DEFINE SYMBOL region_0_xy = X=-158.3675:-158.1002,Y=21.25:21.561
IF ($region_xz"0|*>1") THEN DEFINE SYMBOL region_($num)_xz = ($region_xz)
  !->  IF 1 THEN DEFINE SYMBOL region_0_xz = X=-158.3675:-158.1002
  !->  DEFINE SYMBOL region_0_xz = X=-158.3675:-158.1002
IF ($region_yt"0|*>1") THEN DEFINE SYMBOL region_($num)_yt = ($region_yt)
  !->  IF 1 THEN DEFINE SYMBOL region_0_yt = Y=21.25:21.561,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
  !->  DEFINE SYMBOL region_0_yt = Y=21.25:21.561,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
IF ($region_yz"0|*>1") THEN DEFINE SYMBOL region_($num)_yz = ($region_yz)
  !->  IF 1 THEN DEFINE SYMBOL region_0_yz = Y=21.25:21.561
  !->  DEFINE SYMBOL region_0_yz = Y=21.25:21.561
IF ($region_zt"0|*>1") THEN DEFINE SYMBOL region_($num)_zt = ($region_zt)
  !->  IF 1 THEN DEFINE SYMBOL region_0_zt = T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
  !->  DEFINE SYMBOL region_0_zt = T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"

! For SOCAT server labels, make time symbols w/o the trailing 00:00:00

IF ($region_0_t_lo"0|*>1") THEN
  !->  IF 1 THEN
    DEFINE SYMBOL t_lab_lo = ($region_0_t_lo)
  !->  DEFINE SYMBOL t_lab_lo = 05-Jun-2010 00:00:00
    LET iz = STRINDEX("($region_0_t_lo)", " 00:00:00")
  !->  DEFINE VARIABLE iz = STRINDEX("05-Jun-2010 00:00:00", " 00:00:00")
    IF `iz GT 0` THEN
  !->  IF 1 THEN
       DEFINE SYMBOL t_lab_lo = `SUBSTRING("($region_0_t_lo)", 1, iz-1)`
  !->  DEFINE SYMBOL t_lab_lo = 05-Jun-2010
    ELSE
    ENDIF
ENDIF

IF ($region_0_t_hi"0|*>1") THEN
  !->  IF 1 THEN
    DEFINE SYMBOL t_lab_hi = ($region_0_t_hi)
  !->  DEFINE SYMBOL t_lab_hi = 05-Jun-2010 00:00:00
    LET iz = STRINDEX("($region_0_t_hi)", " 00:00:00")
  !->  DEFINE VARIABLE iz = STRINDEX("05-Jun-2010 00:00:00", " 00:00:00")
    IF `iz GT 0` THEN
  !->  IF 1 THEN
       DEFINE SYMBOL t_lab_hi = `SUBSTRING("($region_0_t_hi)", 1, iz-1)`
  !->  DEFINE SYMBOL t_lab_hi = 05-Jun-2010
    ELSE
    ENDIF
ENDIF

! If no regions have been defined then we have an error.

IF ($region_full"1|*>0")  THEN
  !->  IF 0  THEN
ENDIF

! End of LAS_initialize_region.jnl ------------------------------------------------------
IF `($region_x_lo) LT ($ferret_curv_lon_min)` THEN
  !->  IF 0 THEN
ENDIF

GO  LAS_initialize_region 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! $RCSfile: LAS_initialize_region.jnl,v $
! $Revision: 1.1 $
!
! $Author: ansley $
! $Date: 2006/07/06 17:54:11 $
!
! The LAS_initialize_region.jnl script defines the following symbols
! based on the region associated with data_#:
!
! region_~_lo/hi   -- lo and hi points on a given axis
! region_~_range   -- numeric range on a given axis
! region_~         -- domain in 'lo:hi' notation
! region_full      -- synonym for 'region_xyzt'
!
! Incoming argument determines which region to use
! The default number is 0, and the default region is region_0.
! If we are making only a map, then there are no data_ symbols
! defined, so data_0_region is not set, but we can define region
! as region_0.
!
! ACM trac 267: Do not cancel any previously set limits or region symbols;
! The previous v6 UI as to how it worked in the old product server expects
! to inherit some or all region info from the first dataset for use by the
! second in comparisons etc. Keep this behavior.

DEFINE SYMBOL num ($1"0")
  !->  DEFINE SYMBOL num 0
DEFINE SYMBOL region_name data_($num)_region
  !->  DEFINE SYMBOL region_name data_0_region
DEFINE SYMBOL region ($($region_name)"region_0")
  !->  DEFINE SYMBOL region region_0

! NOTE:  Occasionally the LAS applet will send in a longitude or latitude
! NOTE:  that looks like "24.400000000000002".  Such long, numerically
! NOTE:  irrelevant numbers can overflow Ferret's maximum symbol length.
! NOTE:  Rounding longitudes and latitudes to the nearest .00001 seems
! NOTE:  reasonable for all but the most detailed datasets.

! NOTE:  'region_x_m360' and 'region_x_p360' are used for those visualizations
! NOTE:  where Ferret doesn't auomatically deal with the modulo nature of
! NOTE:  longitude and allow the script writer to deal with this manually.

IF ($($region)_x_lo"0|*>1") THEN
  !->  IF 1 THEN
   DEFINE SYMBOL region_x_lo = `INT(100000 * ($($region)_x_lo)) / 100000`
  !->  DEFINE SYMBOL region_x_lo = -158.3675
   DEFINE SYMBOL region_x_hi = `INT(100000 * ($($region)_x_hi)) / 100000`
  !->  DEFINE SYMBOL region_x_hi = -158.1002
   DEFINE SYMBOL limits_x = ($region_x_lo):($region_x_hi)
  !->  DEFINE SYMBOL limits_x = -158.3675:-158.1002
   DEFINE SYMBOL limits_x_m360 = `($region_x_lo)-360`:`($region_x_hi)-360`
  !->  DEFINE SYMBOL limits_x_m360 = -518.3675:-518.1002
   DEFINE SYMBOL limits_x_p360 = `($region_x_lo)+360`:`($region_x_hi)+360`
  !->  DEFINE SYMBOL limits_x_p360 = 201.6325:201.8998
   DEFINE SYMBOL region_x = X=($region_x_lo):($region_x_hi)
  !->  DEFINE SYMBOL region_x = X=-158.3675:-158.1002
   DEFINE SYMBOL region_x_m360 X=`($region_x_lo)-360`:`($region_x_hi)-360`
  !->  DEFINE SYMBOL region_x_m360 X=-518.3675:-518.1002
   DEFINE SYMBOL region_x_p360 X=`($region_x_lo)+360`:`($region_x_hi)+360`
  !->  DEFINE SYMBOL region_x_p360 X=201.6325:201.8998
   IF `($region_x_hi) GE ($region_x_lo)` THEN
  !->  IF 1 THEN
     DEFINE SYMBOL region_x_range = `($region_x_hi) - ($region_x_lo)`
  !->  DEFINE SYMBOL region_x_range = 0.2672882
   ELSE
   ENDIF
ENDIF

IF ($($region)_y_lo"0|*>1") THEN
  !->  IF 1 THEN
   DEFINE SYMBOL region_y_lo = `INT(1000 * ($($region)_y_lo)) / 1000`
  !->  DEFINE SYMBOL region_y_lo = 21.25
   DEFINE SYMBOL region_y_hi = `INT(1000 * ($($region)_y_hi)) / 1000`
  !->  DEFINE SYMBOL region_y_hi = 21.561
   DEFINE SYMBOL limits_y = ($region_y_lo):($region_y_hi)
  !->  DEFINE SYMBOL limits_y = 21.25:21.561
   DEFINE SYMBOL region_y = Y=($region_y_lo):($region_y_hi)
  !->  DEFINE SYMBOL region_y = Y=21.25:21.561
   IF `($region_y_hi) GE ($region_y_lo)` THEN
  !->  IF 1 THEN
     DEFINE SYMBOL region_y_range = `($region_y_hi) - ($region_y_lo)`
  !->  DEFINE SYMBOL region_y_range = 0.3110008
   ELSE
   ENDIF
ENDIF

IF ($($region)_z_lo"0|*>1") THEN
  !->  IF 0 THEN
   ENDIF
ENDIF

! NOTE:  Normally we use 'DEFINE SYMBOL ~ = ...'
! NOTE:  For the time axis we use 'DEFINE SYMBOL ~ ...' because the Ferret
! NOTE:  parser complains about unmatched quotes if we do it the other way.

IF ($($region)_t_lo"0|*>1") THEN
  !->  IF 1 THEN
   DEFINE SYMBOL region_t_lo = ($($region)_t_lo)
  !->  DEFINE SYMBOL region_t_lo = 05-Jun-2010 00:00:00
   DEFINE SYMBOL region_t_hi = ($($region)_t_hi)
  !->  DEFINE SYMBOL region_t_hi = 05-Jun-2010 00:00:00
   DEFINE SYMBOL limits_t \"($region_t_lo)\":\"($region_t_hi)\"
  !->  DEFINE SYMBOL limits_t \"05-Jun-2010 00:00:00\":\"05-Jun-2010 00:00:00\"
   DEFINE SYMBOL region_t T=\"($region_t_lo)\":\"($region_t_hi)\"
  !->  DEFINE SYMBOL region_t T=\"05-Jun-2010 00:00:00\":\"05-Jun-2010 00:00:00\"
ENDIF

! Now build up all possible multi-axis regions, being careful not to use
! commas when a region is missing

! region_xy
IF ($region_x"0|*>1") THEN
  !->  IF 1 THEN
   IF ($region_y"0|*>1") THEN
  !->  IF 1 THEN
     DEFINE SYMBOL region_xy = ($region_x),($region_y)
  !->  DEFINE SYMBOL region_xy = X=-158.3675:-158.1002,Y=21.25:21.561
   ELSE
   ENDIF
ELSE
   ENDIF
ENDIF

! region_xz
IF ($region_x"0|*>1") THEN
  !->  IF 1 THEN
   IF ($region_z"0|*>1") THEN
  !->  IF 0 THEN
   ELSE
     DEFINE SYMBOL region_xz = ($region_x)
  !->  DEFINE SYMBOL region_xz = X=-158.3675:-158.1002
   ENDIF
ELSE
   ENDIF
ENDIF

! region_xt
IF ($region_x"0|*>1") THEN
  !->  IF 1 THEN
   IF ($region_t"0|*>1") THEN
  !->  IF 1 THEN
     DEFINE SYMBOL region_xt = ($region_x),($region_t)
  !->  DEFINE SYMBOL region_xt = X=-158.3675:-158.1002,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
   ELSE
   ENDIF
ELSE
   ENDIF
ENDIF

! region_yz
IF ($region_y"0|*>1") THEN
  !->  IF 1 THEN
   IF ($region_z"0|*>1") THEN
  !->  IF 0 THEN
   ELSE
     DEFINE SYMBOL region_yz = ($region_y)
  !->  DEFINE SYMBOL region_yz = Y=21.25:21.561
   ENDIF
ELSE
   ENDIF
ENDIF

! region_yt
IF ($region_y"0|*>1") THEN
  !->  IF 1 THEN
   IF ($region_t"0|*>1") THEN
  !->  IF 1 THEN
     DEFINE SYMBOL region_yt = ($region_y),($region_t)
  !->  DEFINE SYMBOL region_yt = Y=21.25:21.561,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
   ELSE
   ENDIF
ELSE
   ENDIF
ENDIF

! region_zt
IF ($region_z"0|*>1") THEN
  !->  IF 0 THEN
   ENDIF
ELSE
   IF ($region_t"0|*>1") THEN
  !->  IF 1 THEN
     DEFINE SYMBOL region_zt = ($region_t)
  !->  DEFINE SYMBOL region_zt = T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
   ENDIF
ENDIF

! region_xyz
IF ($region_xy"0|*>1") THEN
  !->  IF 1 THEN
   IF ($region_z"0|*>1") THEN
  !->  IF 0 THEN
   ELSE
     DEFINE SYMBOL region_xyz = ($region_xy)
  !->  DEFINE SYMBOL region_xyz = X=-158.3675:-158.1002,Y=21.25:21.561
   ENDIF
ELSE
   ENDIF
ENDIF

! region_xyt
IF ($region_xy"0|*>1") THEN
  !->  IF 1 THEN
   IF ($region_t"0|*>1") THEN
  !->  IF 1 THEN
     DEFINE SYMBOL region_xyt = ($region_xy),($region_t)
  !->  DEFINE SYMBOL region_xyt = X=-158.3675:-158.1002,Y=21.25:21.561,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
   ELSE
   ENDIF
ELSE
   ENDIF
ENDIF

! region_yzt
IF ($region_yz"0|*>1") THEN
  !->  IF 1 THEN
   IF ($region_t"0|*>1") THEN
  !->  IF 1 THEN
     DEFINE SYMBOL region_yzt = ($region_yz),($region_t)
  !->  DEFINE SYMBOL region_yzt = Y=21.25:21.561,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
   ELSE
   ENDIF
ELSE
   ENDIF
ENDIF

! region_xyzt
IF ($region_xyz"0|*>1") THEN
  !->  IF 1 THEN
   IF ($region_t"0|*>1") THEN
  !->  IF 1 THEN
     DEFINE SYMBOL region_xyzt = ($region_xyz),($region_t)
  !->  DEFINE SYMBOL region_xyzt = X=-158.3675:-158.1002,Y=21.25:21.561,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
   ELSE
   ENDIF
ELSE
   ENDIF
ENDIF

DEFINE SYMBOL region_full = ($region_xyzt)
  !->  DEFINE SYMBOL region_full = X=-158.3675:-158.1002,Y=21.25:21.561,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"


! For sampling from a curvilinear variable, save the region definitions with
! the variable number.
IF ($region_x"0|*>1") THEN DEFINE SYMBOL region_($num)_x = ($region_x)
  !->  IF 1 THEN DEFINE SYMBOL region_0_x = X=-158.3675:-158.1002
  !->  DEFINE SYMBOL region_0_x = X=-158.3675:-158.1002
IF ($region_y"0|*>1") THEN DEFINE SYMBOL region_($num)_y = ($region_y)
  !->  IF 1 THEN DEFINE SYMBOL region_0_y = Y=21.25:21.561
  !->  DEFINE SYMBOL region_0_y = Y=21.25:21.561
IF ($region_z"0|*>1") THEN DEFINE SYMBOL region_($num)_z = ($region_z)
  !->  IF 0 THEN DEFINE SYMBOL region_0_z =
IF ($region_t"0|*>1") THEN DEFINE SYMBOL region_($num)_t = ($region_t)
  !->  IF 1 THEN DEFINE SYMBOL region_0_t = T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
  !->  DEFINE SYMBOL region_0_t = T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
IF ($region_xt"0|*>1") THEN DEFINE SYMBOL region_($num)_xt = ($region_xt)
  !->  IF 1 THEN DEFINE SYMBOL region_0_xt = X=-158.3675:-158.1002,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
  !->  DEFINE SYMBOL region_0_xt = X=-158.3675:-158.1002,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
IF ($region_xy"0|*>1") THEN DEFINE SYMBOL region_($num)_xy = ($region_xy)
  !->  IF 1 THEN DEFINE SYMBOL region_0_xy = X=-158.3675:-158.1002,Y=21.25:21.561
  !->  DEFINE SYMBOL region_0_xy = X=-158.3675:-158.1002,Y=21.25:21.561
IF ($region_xz"0|*>1") THEN DEFINE SYMBOL region_($num)_xz = ($region_xz)
  !->  IF 1 THEN DEFINE SYMBOL region_0_xz = X=-158.3675:-158.1002
  !->  DEFINE SYMBOL region_0_xz = X=-158.3675:-158.1002
IF ($region_yt"0|*>1") THEN DEFINE SYMBOL region_($num)_yt = ($region_yt)
  !->  IF 1 THEN DEFINE SYMBOL region_0_yt = Y=21.25:21.561,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
  !->  DEFINE SYMBOL region_0_yt = Y=21.25:21.561,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
IF ($region_yz"0|*>1") THEN DEFINE SYMBOL region_($num)_yz = ($region_yz)
  !->  IF 1 THEN DEFINE SYMBOL region_0_yz = Y=21.25:21.561
  !->  DEFINE SYMBOL region_0_yz = Y=21.25:21.561
IF ($region_zt"0|*>1") THEN DEFINE SYMBOL region_($num)_zt = ($region_zt)
  !->  IF 1 THEN DEFINE SYMBOL region_0_zt = T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
  !->  DEFINE SYMBOL region_0_zt = T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"

! For SOCAT server labels, make time symbols w/o the trailing 00:00:00

IF ($region_0_t_lo"0|*>1") THEN
  !->  IF 1 THEN
    DEFINE SYMBOL t_lab_lo = ($region_0_t_lo)
  !->  DEFINE SYMBOL t_lab_lo = 05-Jun-2010 00:00:00
    LET iz = STRINDEX("($region_0_t_lo)", " 00:00:00")
  !->  DEFINE VARIABLE iz = STRINDEX("05-Jun-2010 00:00:00", " 00:00:00")
    IF `iz GT 0` THEN
  !->  IF 1 THEN
       DEFINE SYMBOL t_lab_lo = `SUBSTRING("($region_0_t_lo)", 1, iz-1)`
  !->  DEFINE SYMBOL t_lab_lo = 05-Jun-2010
    ELSE
    ENDIF
ENDIF

IF ($region_0_t_hi"0|*>1") THEN
  !->  IF 1 THEN
    DEFINE SYMBOL t_lab_hi = ($region_0_t_hi)
  !->  DEFINE SYMBOL t_lab_hi = 05-Jun-2010 00:00:00
    LET iz = STRINDEX("($region_0_t_hi)", " 00:00:00")
  !->  DEFINE VARIABLE iz = STRINDEX("05-Jun-2010 00:00:00", " 00:00:00")
    IF `iz GT 0` THEN
  !->  IF 1 THEN
       DEFINE SYMBOL t_lab_hi = `SUBSTRING("($region_0_t_hi)", 1, iz-1)`
  !->  DEFINE SYMBOL t_lab_hi = 05-Jun-2010
    ELSE
    ENDIF
ENDIF

! If no regions have been defined then we have an error.

IF ($region_full"1|*>0")  THEN
  !->  IF 0  THEN
ENDIF

! End of LAS_initialize_region.jnl ------------------------------------------------------
IF `($region_x_hi) GT ($ferret_curv_lon_max)` THEN
  !->  IF 0 THEN
    ENDIF
ENDIF

IF `($hvlimits_curvi"0|*>1") EQ 0` THEN \
    DEFINE SYMBOL hvlimits_curvi = /HLIM=($region_0_x_lo):($region_0_x_hi)/VLIM=($region_0_y_lo):($region_0_y_hi)
  !->  IF 1 THEN    DEFINE SYMBOL hvlimits_curvi = /HLIM=-158.3675:-158.100236/VLIM=21.25:21.5611
  !->  DEFINE SYMBOL hvlimits_curvi = /HLIM=-158.3675:-158.100236/VLIM=21.25:21.5611
    DEFINE SYMBOL ferret_curvi_quals = ($hvlimits_curvi)
  !->  DEFINE SYMBOL ferret_curvi_quals = /HLIM=-158.3675:-158.100236/VLIM=21.25:21.5611
! curvilinear to rectilinear regridding

IF `($constraint_0_lhs"0|Curv_to_Rect_Regridding>1|*>0")` THEN
  !->  IF 0 THEN
ENDIF

GO LAS_initialize_region ($num)
  !->  GO LAS_initialize_region 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! $RCSfile: LAS_initialize_region.jnl,v $
! $Revision: 1.1 $
!
! $Author: ansley $
! $Date: 2006/07/06 17:54:11 $
!
! The LAS_initialize_region.jnl script defines the following symbols
! based on the region associated with data_#:
!
! region_~_lo/hi   -- lo and hi points on a given axis
! region_~_range   -- numeric range on a given axis
! region_~         -- domain in 'lo:hi' notation
! region_full      -- synonym for 'region_xyzt'
!
! Incoming argument determines which region to use
! The default number is 0, and the default region is region_0.
! If we are making only a map, then there are no data_ symbols
! defined, so data_0_region is not set, but we can define region
! as region_0.
!
! ACM trac 267: Do not cancel any previously set limits or region symbols;
! The previous v6 UI as to how it worked in the old product server expects
! to inherit some or all region info from the first dataset for use by the
! second in comparisons etc. Keep this behavior.

DEFINE SYMBOL num ($1"0")
  !->  DEFINE SYMBOL num 0
DEFINE SYMBOL region_name data_($num)_region
  !->  DEFINE SYMBOL region_name data_0_region
DEFINE SYMBOL region ($($region_name)"region_0")
  !->  DEFINE SYMBOL region region_0

! NOTE:  Occasionally the LAS applet will send in a longitude or latitude
! NOTE:  that looks like "24.400000000000002".  Such long, numerically
! NOTE:  irrelevant numbers can overflow Ferret's maximum symbol length.
! NOTE:  Rounding longitudes and latitudes to the nearest .00001 seems
! NOTE:  reasonable for all but the most detailed datasets.

! NOTE:  'region_x_m360' and 'region_x_p360' are used for those visualizations
! NOTE:  where Ferret doesn't auomatically deal with the modulo nature of
! NOTE:  longitude and allow the script writer to deal with this manually.

IF ($($region)_x_lo"0|*>1") THEN
  !->  IF 1 THEN
   DEFINE SYMBOL region_x_lo = `INT(100000 * ($($region)_x_lo)) / 100000`
  !->  DEFINE SYMBOL region_x_lo = -158.3675
   DEFINE SYMBOL region_x_hi = `INT(100000 * ($($region)_x_hi)) / 100000`
  !->  DEFINE SYMBOL region_x_hi = -158.1002
   DEFINE SYMBOL limits_x = ($region_x_lo):($region_x_hi)
  !->  DEFINE SYMBOL limits_x = -158.3675:-158.1002
   DEFINE SYMBOL limits_x_m360 = `($region_x_lo)-360`:`($region_x_hi)-360`
  !->  DEFINE SYMBOL limits_x_m360 = -518.3675:-518.1002
   DEFINE SYMBOL limits_x_p360 = `($region_x_lo)+360`:`($region_x_hi)+360`
  !->  DEFINE SYMBOL limits_x_p360 = 201.6325:201.8998
   DEFINE SYMBOL region_x = X=($region_x_lo):($region_x_hi)
  !->  DEFINE SYMBOL region_x = X=-158.3675:-158.1002
   DEFINE SYMBOL region_x_m360 X=`($region_x_lo)-360`:`($region_x_hi)-360`
  !->  DEFINE SYMBOL region_x_m360 X=-518.3675:-518.1002
   DEFINE SYMBOL region_x_p360 X=`($region_x_lo)+360`:`($region_x_hi)+360`
  !->  DEFINE SYMBOL region_x_p360 X=201.6325:201.8998
   IF `($region_x_hi) GE ($region_x_lo)` THEN
  !->  IF 1 THEN
     DEFINE SYMBOL region_x_range = `($region_x_hi) - ($region_x_lo)`
  !->  DEFINE SYMBOL region_x_range = 0.2672882
   ELSE
   ENDIF
ENDIF

IF ($($region)_y_lo"0|*>1") THEN
  !->  IF 1 THEN
   DEFINE SYMBOL region_y_lo = `INT(1000 * ($($region)_y_lo)) / 1000`
  !->  DEFINE SYMBOL region_y_lo = 21.25
   DEFINE SYMBOL region_y_hi = `INT(1000 * ($($region)_y_hi)) / 1000`
  !->  DEFINE SYMBOL region_y_hi = 21.561
   DEFINE SYMBOL limits_y = ($region_y_lo):($region_y_hi)
  !->  DEFINE SYMBOL limits_y = 21.25:21.561
   DEFINE SYMBOL region_y = Y=($region_y_lo):($region_y_hi)
  !->  DEFINE SYMBOL region_y = Y=21.25:21.561
   IF `($region_y_hi) GE ($region_y_lo)` THEN
  !->  IF 1 THEN
     DEFINE SYMBOL region_y_range = `($region_y_hi) - ($region_y_lo)`
  !->  DEFINE SYMBOL region_y_range = 0.3110008
   ELSE
   ENDIF
ENDIF

IF ($($region)_z_lo"0|*>1") THEN
  !->  IF 0 THEN
   ENDIF
ENDIF

! NOTE:  Normally we use 'DEFINE SYMBOL ~ = ...'
! NOTE:  For the time axis we use 'DEFINE SYMBOL ~ ...' because the Ferret
! NOTE:  parser complains about unmatched quotes if we do it the other way.

IF ($($region)_t_lo"0|*>1") THEN
  !->  IF 1 THEN
   DEFINE SYMBOL region_t_lo = ($($region)_t_lo)
  !->  DEFINE SYMBOL region_t_lo = 05-Jun-2010 00:00:00
   DEFINE SYMBOL region_t_hi = ($($region)_t_hi)
  !->  DEFINE SYMBOL region_t_hi = 05-Jun-2010 00:00:00
   DEFINE SYMBOL limits_t \"($region_t_lo)\":\"($region_t_hi)\"
  !->  DEFINE SYMBOL limits_t \"05-Jun-2010 00:00:00\":\"05-Jun-2010 00:00:00\"
   DEFINE SYMBOL region_t T=\"($region_t_lo)\":\"($region_t_hi)\"
  !->  DEFINE SYMBOL region_t T=\"05-Jun-2010 00:00:00\":\"05-Jun-2010 00:00:00\"
ENDIF

! Now build up all possible multi-axis regions, being careful not to use
! commas when a region is missing

! region_xy
IF ($region_x"0|*>1") THEN
  !->  IF 1 THEN
   IF ($region_y"0|*>1") THEN
  !->  IF 1 THEN
     DEFINE SYMBOL region_xy = ($region_x),($region_y)
  !->  DEFINE SYMBOL region_xy = X=-158.3675:-158.1002,Y=21.25:21.561
   ELSE
   ENDIF
ELSE
   ENDIF
ENDIF

! region_xz
IF ($region_x"0|*>1") THEN
  !->  IF 1 THEN
   IF ($region_z"0|*>1") THEN
  !->  IF 0 THEN
   ELSE
     DEFINE SYMBOL region_xz = ($region_x)
  !->  DEFINE SYMBOL region_xz = X=-158.3675:-158.1002
   ENDIF
ELSE
   ENDIF
ENDIF

! region_xt
IF ($region_x"0|*>1") THEN
  !->  IF 1 THEN
   IF ($region_t"0|*>1") THEN
  !->  IF 1 THEN
     DEFINE SYMBOL region_xt = ($region_x),($region_t)
  !->  DEFINE SYMBOL region_xt = X=-158.3675:-158.1002,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
   ELSE
   ENDIF
ELSE
   ENDIF
ENDIF

! region_yz
IF ($region_y"0|*>1") THEN
  !->  IF 1 THEN
   IF ($region_z"0|*>1") THEN
  !->  IF 0 THEN
   ELSE
     DEFINE SYMBOL region_yz = ($region_y)
  !->  DEFINE SYMBOL region_yz = Y=21.25:21.561
   ENDIF
ELSE
   ENDIF
ENDIF

! region_yt
IF ($region_y"0|*>1") THEN
  !->  IF 1 THEN
   IF ($region_t"0|*>1") THEN
  !->  IF 1 THEN
     DEFINE SYMBOL region_yt = ($region_y),($region_t)
  !->  DEFINE SYMBOL region_yt = Y=21.25:21.561,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
   ELSE
   ENDIF
ELSE
   ENDIF
ENDIF

! region_zt
IF ($region_z"0|*>1") THEN
  !->  IF 0 THEN
   ENDIF
ELSE
   IF ($region_t"0|*>1") THEN
  !->  IF 1 THEN
     DEFINE SYMBOL region_zt = ($region_t)
  !->  DEFINE SYMBOL region_zt = T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
   ENDIF
ENDIF

! region_xyz
IF ($region_xy"0|*>1") THEN
  !->  IF 1 THEN
   IF ($region_z"0|*>1") THEN
  !->  IF 0 THEN
   ELSE
     DEFINE SYMBOL region_xyz = ($region_xy)
  !->  DEFINE SYMBOL region_xyz = X=-158.3675:-158.1002,Y=21.25:21.561
   ENDIF
ELSE
   ENDIF
ENDIF

! region_xyt
IF ($region_xy"0|*>1") THEN
  !->  IF 1 THEN
   IF ($region_t"0|*>1") THEN
  !->  IF 1 THEN
     DEFINE SYMBOL region_xyt = ($region_xy),($region_t)
  !->  DEFINE SYMBOL region_xyt = X=-158.3675:-158.1002,Y=21.25:21.561,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
   ELSE
   ENDIF
ELSE
   ENDIF
ENDIF

! region_yzt
IF ($region_yz"0|*>1") THEN
  !->  IF 1 THEN
   IF ($region_t"0|*>1") THEN
  !->  IF 1 THEN
     DEFINE SYMBOL region_yzt = ($region_yz),($region_t)
  !->  DEFINE SYMBOL region_yzt = Y=21.25:21.561,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
   ELSE
   ENDIF
ELSE
   ENDIF
ENDIF

! region_xyzt
IF ($region_xyz"0|*>1") THEN
  !->  IF 1 THEN
   IF ($region_t"0|*>1") THEN
  !->  IF 1 THEN
     DEFINE SYMBOL region_xyzt = ($region_xyz),($region_t)
  !->  DEFINE SYMBOL region_xyzt = X=-158.3675:-158.1002,Y=21.25:21.561,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
   ELSE
   ENDIF
ELSE
   ENDIF
ENDIF

DEFINE SYMBOL region_full = ($region_xyzt)
  !->  DEFINE SYMBOL region_full = X=-158.3675:-158.1002,Y=21.25:21.561,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"


! For sampling from a curvilinear variable, save the region definitions with
! the variable number.
IF ($region_x"0|*>1") THEN DEFINE SYMBOL region_($num)_x = ($region_x)
  !->  IF 1 THEN DEFINE SYMBOL region_0_x = X=-158.3675:-158.1002
  !->  DEFINE SYMBOL region_0_x = X=-158.3675:-158.1002
IF ($region_y"0|*>1") THEN DEFINE SYMBOL region_($num)_y = ($region_y)
  !->  IF 1 THEN DEFINE SYMBOL region_0_y = Y=21.25:21.561
  !->  DEFINE SYMBOL region_0_y = Y=21.25:21.561
IF ($region_z"0|*>1") THEN DEFINE SYMBOL region_($num)_z = ($region_z)
  !->  IF 0 THEN DEFINE SYMBOL region_0_z =
IF ($region_t"0|*>1") THEN DEFINE SYMBOL region_($num)_t = ($region_t)
  !->  IF 1 THEN DEFINE SYMBOL region_0_t = T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
  !->  DEFINE SYMBOL region_0_t = T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
IF ($region_xt"0|*>1") THEN DEFINE SYMBOL region_($num)_xt = ($region_xt)
  !->  IF 1 THEN DEFINE SYMBOL region_0_xt = X=-158.3675:-158.1002,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
  !->  DEFINE SYMBOL region_0_xt = X=-158.3675:-158.1002,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
IF ($region_xy"0|*>1") THEN DEFINE SYMBOL region_($num)_xy = ($region_xy)
  !->  IF 1 THEN DEFINE SYMBOL region_0_xy = X=-158.3675:-158.1002,Y=21.25:21.561
  !->  DEFINE SYMBOL region_0_xy = X=-158.3675:-158.1002,Y=21.25:21.561
IF ($region_xz"0|*>1") THEN DEFINE SYMBOL region_($num)_xz = ($region_xz)
  !->  IF 1 THEN DEFINE SYMBOL region_0_xz = X=-158.3675:-158.1002
  !->  DEFINE SYMBOL region_0_xz = X=-158.3675:-158.1002
IF ($region_yt"0|*>1") THEN DEFINE SYMBOL region_($num)_yt = ($region_yt)
  !->  IF 1 THEN DEFINE SYMBOL region_0_yt = Y=21.25:21.561,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
  !->  DEFINE SYMBOL region_0_yt = Y=21.25:21.561,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
IF ($region_yz"0|*>1") THEN DEFINE SYMBOL region_($num)_yz = ($region_yz)
  !->  IF 1 THEN DEFINE SYMBOL region_0_yz = Y=21.25:21.561
  !->  DEFINE SYMBOL region_0_yz = Y=21.25:21.561
IF ($region_zt"0|*>1") THEN DEFINE SYMBOL region_($num)_zt = ($region_zt)
  !->  IF 1 THEN DEFINE SYMBOL region_0_zt = T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"
  !->  DEFINE SYMBOL region_0_zt = T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"

! For SOCAT server labels, make time symbols w/o the trailing 00:00:00

IF ($region_0_t_lo"0|*>1") THEN
  !->  IF 1 THEN
    DEFINE SYMBOL t_lab_lo = ($region_0_t_lo)
  !->  DEFINE SYMBOL t_lab_lo = 05-Jun-2010 00:00:00
    LET iz = STRINDEX("($region_0_t_lo)", " 00:00:00")
  !->  DEFINE VARIABLE iz = STRINDEX("05-Jun-2010 00:00:00", " 00:00:00")
    IF `iz GT 0` THEN
  !->  IF 1 THEN
       DEFINE SYMBOL t_lab_lo = `SUBSTRING("($region_0_t_lo)", 1, iz-1)`
  !->  DEFINE SYMBOL t_lab_lo = 05-Jun-2010
    ELSE
    ENDIF
ENDIF

IF ($region_0_t_hi"0|*>1") THEN
  !->  IF 1 THEN
    DEFINE SYMBOL t_lab_hi = ($region_0_t_hi)
  !->  DEFINE SYMBOL t_lab_hi = 05-Jun-2010 00:00:00
    LET iz = STRINDEX("($region_0_t_hi)", " 00:00:00")
  !->  DEFINE VARIABLE iz = STRINDEX("05-Jun-2010 00:00:00", " 00:00:00")
    IF `iz GT 0` THEN
  !->  IF 1 THEN
       DEFINE SYMBOL t_lab_hi = `SUBSTRING("($region_0_t_hi)", 1, iz-1)`
  !->  DEFINE SYMBOL t_lab_hi = 05-Jun-2010
    ELSE
    ENDIF
ENDIF

! If no regions have been defined then we have an error.

IF ($region_full"1|*>0")  THEN
  !->  IF 0  THEN
ENDIF

! End of LAS_initialize_region.jnl ------------------------------------------------------

!!!!!!!!!!!

! Special setup, if a latitude has been specified such that the grid
! is linear south of ($ferret_linear_lat_max)

! Here we check whether the region is within the part of the grid that is rectilinear.
! If it is, then redefine the axes and proceed as if it is a rectilinear grid. Otherwise
! call LAS_set_strides_curvilinear.jnl


! If this is a vector plot, do this only once, on the first vector component

DEFINE SYMBOL check_linear = 1
IF ` ($operation_ID"0|Plot_vector>1|*>0") AND ($num) GT 0` THEN DEFINE SYMBOL check_linear = 0
  !->  IF 0 THEN DEFINE SYMBOL check_linear = 0

IF `($ferret_linear_coords_file"0|same_as_infile>1|*>0")` THEN CANCEL SYMBOL ferret_linear_coords_file
  !->  IF 0 THEN CANCEL SYMBOL ferret_linear_coords_file
IF `($ferret_linear_coords_file"0|*>1") AND ($check_linear)` THEN
  !->  IF 0 THEN
    ENDIF
ELSE

    GO get_curv_coord_bbox.jnl
! Special version of get_curv_coord_bbox.jnl with kludge to
! speed up finding the bounding-box.

! get_curv_coord_bbox.jnl

! get the I,J range from curvilinear coordinate variables for
! the requested output rectangle defined by
!    ($region_x_lo):($region_x_hi)
!    ($region_y_lo):($region_y_hi)
!
! The output is returned as symbols

! clon_imin
! clon_imax
! clat_jmin
! clat_jmax

! If this has already been called, we are done.
IF ($curv_coord_bbox_done"0") THEN EXIT/SCRIPT
  !->  IF 0 THEN EXIT/SCRIPT
DEFINE SYMBOL curv_coord_bbox_done = 1


! For analysis operations on curvilienar grids we may not have definitions for region_x_* and
! region_y_*  but there should be region_0_**

IF `($region_x_lo"-999") EQ -999` THEN
  !->  IF 0 THEN
ENDIF
IF `($region_y_lo"-999") EQ -999` THEN
  !->  IF 0 THEN
ENDIF

! Make computations based on the range of lon/lat in the grid.

IF `($ferret_curv_lon_min%0|*>1%) EQ 0` THEN \
    DEFINE SYMBOL ferret_curv_lon_min = `($ferret_curvi_coord_lon)[x=@min,y=@min]`
  !->  IF 0 THEN    DEFINE SYMBOL ferret_curv_lon_min = `lon_rho[x=@min,y=@min]`
IF `($ferret_curv_lon_max%0|*>1%) EQ 0` THEN \
    DEFINE SYMBOL ferret_curv_lon_max = `($ferret_curvi_coord_lon)[x=@max,y=@max]`
  !->  IF 0 THEN    DEFINE SYMBOL ferret_curv_lon_max = `lon_rho[x=@max,y=@max]`
IF `($ferret_curv_lat_min%0|*>1%) EQ 0` THEN \
    DEFINE SYMBOL ferret_curv_lat_min = `($ferret_curvi_coord_lat)[x=@min,y=@min]`
  !->  IF 0 THEN    DEFINE SYMBOL ferret_curv_lat_min = `lat_rho[x=@min,y=@min]`
IF `($ferret_curv_lat_max%0|*>1%) EQ 0` THEN \
    DEFINE SYMBOL ferret_curv_lat_max = `($ferret_curvi_coord_lat)[x=@max,y=@max]`
  !->  IF 0 THEN    DEFINE SYMBOL ferret_curv_lat_max = `lat_rho[x=@max,y=@max]`

LET ncurv_x = `($ferret_curvi_coord_lon),RETURN=isize`
  !->  DEFINE VARIABLE ncurv_x = 59
LET ncurv_y = `($ferret_curvi_coord_lon),RETURN=jsize`
  !->  DEFINE VARIABLE ncurv_y = 35
LET del_x = (($ferret_curv_lon_max) - ($ferret_curv_lon_min))/(ncurv_x/2)
  !->  DEFINE VARIABLE del_x = (-158.095644459455 - -158.36753276978)/(ncurv_x/2)
LET del_y = (($ferret_curv_lat_max) - ($ferret_curv_lat_min))/(ncurv_y/2)
  !->  DEFINE VARIABLE del_y = (21.570575858175 - 21.250212932786)/(ncurv_y/2)

! If the whole grid is specified, we are done.
IF ($ferret_curv_lon_min"0|*>1") THEN
  !->  IF 1 THEN
    LET xlodiff =  ABS(($ferret_curv_lon_min) - ($region_x_lo) )
  !->  DEFINE VARIABLE xlodiff =  ABS(-158.36753276978 - -158.3675 )
    LET xhidiff =  ABS(($ferret_curv_lon_max) - ($region_x_hi) )
  !->  DEFINE VARIABLE xhidiff =  ABS(-158.095644459455 - -158.1002 )
    LET ylodiff =  ABS(($ferret_curv_lat_min) - ($region_y_lo) )
  !->  DEFINE VARIABLE ylodiff =  ABS(21.250212932786 - 21.25 )
    LET yhidiff =  ABS(($ferret_curv_lat_max) - ($region_y_hi) )
  !->  DEFINE VARIABLE yhidiff =  ABS(21.570575858175 - 21.561 )

    IF `(MAX((xlodiff), (xhidiff)) LT del_x) AND\
        (MAX((ylodiff), (yhidiff)) LT del_y)` THEN
  !->  IF 1 THEN
       LET clon_imin = 1
       LET clon_imax = ncurv_x

       LET clat_jmin = 1
       LET clat_jmax = ncurv_y

       DEFINE SYMBOL clon_imin `clon_imin`
  !->  DEFINE SYMBOL clon_imin 1
       DEFINE SYMBOL clon_imax `clon_imax`
  !->  DEFINE SYMBOL clon_imax 59
       DEFINE SYMBOL clat_jmin `clat_jmin`
  !->  DEFINE SYMBOL clat_jmin 1
       DEFINE  SYMBOL clat_jmax `clat_jmax`
  !->  DEFINE  SYMBOL clat_jmax 35

       GO cancel_temp_regions
! cancel_temp_regions.jnl

! Called by curvi_nrst_slice.jnl
! For analysis operations on curvilienar grids we may not have definitions
! for region_x_* and region_y_*. These are temporarily assigned when setting
! up slices or getting the box limits. Now remove them.


IF ($remove_x_region"0|*>1") THEN
  !->  IF 0 THEN
ENDIF
IF ($remove_y_region"0|*>1") THEN
  !->  IF 0 THEN
ENDIF

! Make these Definitions from the end of curvi_nrst_slice
IF ($region_sample"0|*>1") THEN
  !->  IF 0 THEN
    ENDIF
ENDIF

EXIT
       EXIT/SCRIPT
    GO LAS_set_strides_curvilinear.jnl
! LAS_set_strides_curvilinear.jnl
!
! From the region and the grid we can define striding. When there's going to be
! a transformation or something, then this might be better someplace else, or
! might be undone by the transform script.


! cannot do native striding if this is a descriptor dataset.

IF ($data_var_only"0|*>1") THEN
  !->  IF 1 THEN
    DEFINE SYMBOL check_for_des =  `($data_var_only)[d=($data_num)],RETURN=dsetpath`
  !->  DEFINE SYMBOL check_for_des =  http://lawelawe.soest.hawaii.edu:8080/thredds/dodsC/hioos/roms_forec/hiomwg/HI-ROMS_Forecast_Model_Run_Collection_best.ncd
ELSE
ENDIF

IF `STRINDEX("($check_for_des)", ".des") GT 0` THEN EXIT/SCRIPT
  !->  IF 0 THEN EXIT/SCRIPT

IF `STRINDEX( "($operation_ID)", "Plot" ) EQ 0 AND \
STRINDEX( "($operation_ID)", "zoom" ) EQ 0 AND \
STRINDEX( "($operation_ID)", "Anim" ) EQ 0 AND \
STRINDEX( "($operation_ID)", "Grid_for_GE" ) EQ 0` THEN EXIT/SCRIPT
  !->  IF 0 THEN EXIT/SCRIPT

! If striding has already been set (e.g. for the other vector component) then exit
IF `($xstride"0|1>0|*>1") + ($ystride"0|1>0|*>1") + ($zstride"0|1>0|*>1") + ($tstride"0|1>0|*>1") GT 0` THEN EXIT/SCRIPT
  !->  IF 0 THEN EXIT/SCRIPT

LET maxpix = 600  ! default
IF ($ferret_size"0|0.06667>1|*>0") THEN LET maxpix = 300  ! small
  !->  IF 0 THEN LET maxpix = 300
IF ($ferret_size"0|0.25>1|*>0")    THEN LET maxpix = 500  ! medium
  !->  IF 0    THEN LET maxpix = 500
IF ($ferret_size"0|0.5>1|*>0")     THEN LET maxpix = 600  ! default
  !->  IF 1     THEN LET maxpix = 600
  !->  LET maxpix = 600
IF ($ferret_size"0|0.8333>1|*>0")  THEN LET maxpix = 700  ! large
  !->  IF 0  THEN LET maxpix = 700

IF `($ferret_google_plot"0|*>1")` THEN
  !->  IF 0 THEN
ENDIF

! Step 1  ---------------------------------------------------------------------
! Determine striding based on the memory allocation

DEFINE SYMBOL memsize = ($FERRET_MEMORY"6.4")* 1.e6
  !->  DEFINE SYMBOL memsize = 16* 1.e6

! If ($data_count) larger than 1 add the size of the variables.
!LET pvar = ($ferret_plot_var)
LET pvar = ($expr1)($data_var)[d=($data_num)]($expr2)
  !->  DEFINE VARIABLE pvar =  svstr[d=1]
IF ($region_zt"0|*>1") THEN LET pvar = ($expr1)($data_var)[d=($data_num),($region_zt)]($expr2)
  !->  IF 1 THEN LET pvar =  svstr[d=1,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"]
  !->  LET pvar =  svstr[d=1,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"]
IF ($clon_imin"0|*>1") THEN
  !->  IF 1 THEN
    LET pvar = ($expr1)($data_var)[d=($data_num),i=($clon_imin):($clon_imax),j=($clat_jmin):($clat_jmax)]($expr2)
  !->  DEFINE VARIABLE pvar =  svstr[d=1,i=1:59,j=1:35]
    IF ($region_zt"0|*>1") THEN \
       LET pvar = ($expr1)($data_var)[d=($data_num),i=($clon_imin):($clon_imax),j=($clat_jmin):($clat_jmax),($region_zt)]($expr2)
  !->  IF 1 THEN       LET pvar =  svstr[d=1,i=1:59,j=1:35,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"]
  !->  LET pvar =  svstr[d=1,i=1:59,j=1:35,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"]
    IF ($ferret_season_length"0|*>1") THEN
  !->  IF 0 THEN
    ENDIF
ENDIF
LET varsiz `pvar,RETURN=size`
  !->  DEFINE VARIABLE varsiz 2006

! If its a slice in x or y account for that
IF `($region_x_range"1|0|*>1") EQ 0 AND ($region_y_range"1|0|*>1") EQ 0` THEN
  !->  IF 0 THEN
ELIF `($region_x_range"1|0|*>1") EQ 0` THEN
  !->  ELIF 0 THEN
ELIF `($region_y_range"1|0|*>1") EQ 0` THEN
  !->  ELIF 0 THEN
ENDIF

DEFINE SYMBOL stride_for_mem = `INT( 1+ varsiz/(.1*($memsize)) )`
  !->  DEFINE SYMBOL stride_for_mem = 1

! If not a graphics product, apply the strides

IF `STRINDEX( "($operation_ID)", "Plot" ) EQ 0 AND \
     STRINDEX( "($operation_ID)", "zoom" ) EQ 0 AND \
     STRINDEX( "($operation_ID)", "Anim" ) EQ 0 AND  \
     STRINDEX( "($operation_ID)", "_GE" ) EQ 0` THEN
  !->  IF 0 THEN
       ENDIF
       ENDIF
       ENDIF
       ENDIF
    ENDIF
ENDIF

! Step 2  ---------------------------------------------------------------------
! Now for graphics products, do striding by pixel size, often larger stride than
! needed to fit in Ferret memory

LET nx = 1
IF ($clon_imin"0|*>1") THEN
  !->  IF 1 THEN
    LET nx = ($clon_imax) - ($clon_imin)
  !->  DEFINE VARIABLE nx = 59 - 1
ELSE
ENDIF

LET nx_orig = `nx`
  !->  DEFINE VARIABLE nx_orig = 58


! lon and lat max were computed in finding the bbox
DEFINE SYMBOL grid_x_range = `($ferret_curv_lon_max) - ($ferret_curv_lon_min)`
  !->  DEFINE SYMBOL grid_x_range = 0.2718964
DEFINE SYMBOL grid_y_range = `($ferret_curv_lat_max) - ($ferret_curv_lat_min)`
  !->  DEFINE SYMBOL grid_y_range = 0.3203621

! For 2D plots

IF `STRLEN("($ferret_view)") EQ 2` THEN
  !->  IF 1 THEN

! curvilinear grid? Get percentage of total that the region represents, see
! if the number of points looks like it will be large.


! Curvilinear and XY plot

    IF `($ferret_curvi_coord_lat"0|*>1") + ($ferret_view"|xy>1|*>0") EQ 2 ` THEN
  !->  IF 1 THEN

       LET xx = x[gx=($data_var)[d=($data_num)]]
  !->  DEFINE VARIABLE xx = x[gx=svstr[d=1]]
       LET nx = xx[i=@ngd]
       LET x_pct = ($region_x_range)/($grid_x_range)
  !->  DEFINE VARIABLE x_pct = 0.2672882/0.2718964
       LET pixsize = `nx*x_pct`
  !->  DEFINE VARIABLE pixsize = 58.00005
!         LET pixsize = `MAX(pixsize, nx)`  ! comment this out to set strides by region

!         IF `pixsize GT maxpix` THEN DEFINE SYMBOL xstride = `INT((pixsize/maxpix)+1)`
       IF `pixsize GT maxpix` THEN DEFINE SYMBOL xstride = `2*INT((pixsize/maxpix)+1)`
  !->  IF 0 THEN DEFINE SYMBOL xstride = `2*INT((pixsize/maxpix)+1)`

       DEFINE SYMBOL xstride = `MAX(($xstride"1"), ($stride_for_mem"1"))`
  !->  DEFINE SYMBOL xstride = 1
       IF `($xstride"0") GT 1` THEN
  !->  IF 0 THEN
       ENDIF

! Use /HLIM and /VLIM to define the plot rectangle. If this is a native
! curvilienar plot this step is done elsewhere.
       IF `($native_curvilinear_xy"0|*>1") EQ 0` THEN \
         DEFINE SYMBOL qualifiers = ($qualifiers)/HLIM=`($region_x_lo)`:`($region_x_hi)`
  !->  IF 1 THEN         DEFINE SYMBOL qualifiers =  /HLIM=`-158.3675`:`-158.1002`
  !->  DEFINE SYMBOL qualifiers =  /HLIM=`-158.3675`:`-158.1002`
  !->  DEFINE SYMBOL qualifiers =  /HLIM=-158.3675:-158.1002

       LET yy = y[gy=($data_var)[d=($data_num)]]
  !->  DEFINE VARIABLE yy = y[gy=svstr[d=1]]
       LET ny = yy[j=@ngd]; LET ny_orig = `ny`
  !->  LET ny = yy[j=@ngd]
  !->   LET ny_orig = `ny`
  !->  DEFINE VARIABLE ny_orig = 34
       LET y_pct = ($region_y_range)/($grid_y_range)
  !->  DEFINE VARIABLE y_pct = 0.3110008/0.3203621
       LET pixsize = `ny*y_pct`
  !->  DEFINE VARIABLE pixsize = 33.00648

!         LET pixsize = `MAX(pixsize, ny)`  ! comment this out to set strides by region

!         IF `pixsize GT maxpix` THEN DEFINE SYMBOL ystride = `2*INT((pixsize/maxpix)+1)`
       IF `2*pixsize GT maxpix` THEN DEFINE SYMBOL ystride = `2*INT((pixsize/maxpix)+1)`
  !->  IF 0 THEN DEFINE SYMBOL ystride = `2*INT((pixsize/maxpix)+1)`
       DEFINE SYMBOL ystride = `MAX(($ystride"1"), ($stride_for_mem"1"))`
  !->  DEFINE SYMBOL ystride = 1

       IF `($ystride"0") GT 1` THEN
  !->  IF 0 THEN
       ENDIF

! Curvilinear and some other view than xy

    ELIF `($ferret_curvi_coord_lat"0|*>1") AND (STRINDEX("($ferret_view)", "x") + STRINDEX("($ferret_view)", "y") GT 0) ` THEN
  !->  ELIF 1 THEN
            ENDIF
            ENDIF
         ENDIF
            ENDIF
            ENDIF
         ENDIF
            ENDIF
         ENDIF
            ENDIF
         ENDIF
    ENDIF ! xy or not
ENDIF  ! 2D plots


! XY and a third dimension for Google Earth placemarks

IF `STRLEN("($ferret_view)") EQ 3 AND STRINDEX("($ferret_view)", "xy") GT 0` THEN
  !->  IF 0 THEN
       ENDIF
       ENDIF
    ENDIF  ! ferret_curvi_coord_lat
ENDIF ! GE placemarks


! If long/lat index ranges were redefined, and if its a comparision
! then we need to redefine ferret_plot_base_var_0

IF `($num) GT 0 and (($xstride"0")+($ystride"0) GT 0)` THEN
  !->  IF 0 THEN
ENDIF

! Add a label about the striding at the upper left.

LET need_comma = 0
IF `($xstride"0|1>0|*>1") + ($ystride"0|1>0|*>1") + ($zstride"0|1>0|*>1") + ($tstride"0|1>0|*>1") GT 0` THEN
  !->  IF 0 THEN
    ENDIF
    ENDIF
    ENDIF
    ENDIF
ENDIF

! Redefine pvar using new longitude and latitude indices.
! They may have been reset after defining striding.

IF ($clon_imin"0|*>1") THEN
  !->  IF 1 THEN
    LET pvar = ($expr1)($data_var)[d=($data_num),i=($clon_imin):($clon_imax),j=($clat_jmin):($clat_jmax)]($expr2)
  !->  DEFINE VARIABLE pvar =  svstr[d=1,i=1:59,j=1:35]
    IF ($region_zt"0|*>1") THEN \
       LET pvar = ($expr1)($data_var)[d=($data_num),i=($clon_imin):($clon_imax),j=($clat_jmin):($clat_jmax),($region_zt)]($expr2)
  !->  IF 1 THEN       LET pvar =  svstr[d=1,i=1:59,j=1:35,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"]
  !->  LET pvar =  svstr[d=1,i=1:59,j=1:35,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00"]
    IF ($ferret_season_length"0|*>1") THEN
  !->  IF 0 THEN
    ENDIF
ENDIF

! End of $RCSfile ------------LAS_set_strides_curvilinear.jnl--------------------------


ENDIF

!!!!!!!!!!!

! Set up native curvilinear plots
LET/TITLE="Longitude"/units=degrees xcoord = ($ferret_curvi_coord_lon)[d=($data_num)]
  !->  DEFINE VARIABLE/TITLE="Longitude"/units=degrees xcoord = lon_rho[d=1]
LET/TITLE="Latitude"/units=degrees  ycoord = ($ferret_curvi_coord_lat)[d=($data_num)]
  !->  DEFINE VARIABLE/TITLE="Latitude"/units=degrees  ycoord = lat_rho[d=1]

!   Native plot in XY

IF ($ferret_view"|xy>1|*>0") THEN
  !->  IF 1 THEN

    DEFINE SYMBOL native_curvilinear_xy = 1

! Get the range of I,J needed to grab the region. Use it to define the plot or output variable.

    LET/TITLE="Longitude"/units=degrees xcoord = \
           ($ferret_curvi_coord_lon)[d=($data_num),i=($clon_imin):($clon_imax),j=($clat_jmin):($clat_jmax)]
  !->  DEFINE VARIABLE/TITLE="Longitude"/units=degrees xcoord =           lon_rho[d=1,i=1:59,j=1:35]
    LET/TITLE="Latitude"/units=degrees  ycoord = \
           ($ferret_curvi_coord_lat)[d=($data_num),i=($clon_imin):($clon_imax),j=($clat_jmin):($clat_jmax)]
  !->  DEFINE VARIABLE/TITLE="Latitude"/units=degrees  ycoord =           lat_rho[d=1,i=1:59,j=1:35]

    LET/d=($data_num) plot_var = ($data_var)[d=($data_num),i=($clon_imin):($clon_imax),j=($clat_jmin):($clat_jmax)]
  !->  DEFINE VARIABLE/d=1 plot_var = svstr[d=1,i=1:59,j=1:35]
    IF ($region_zt"0|*>1") THEN LET/d=($data_num) plot_var = \
         ($data_var)[d=($data_num),($region_zt),i=($clon_imin):($clon_imax),j=($clat_jmin):($clat_jmax)]
  !->  IF 1 THEN LET/d=1 plot_var =         svstr[d=1,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00",i=1:59,j=1:35]
  !->  LET/d=1 plot_var =         svstr[d=1,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00",i=1:59,j=1:35]
    IF ($region_($which_var)_zt"0|*>1") THEN LET/d=($data_num) plot_var = \
         ($data_var)[d=($data_num),($region_($which_var)_zt),i=($clon_imin):($clon_imax),j=($clat_jmin):($clat_jmax)]
  !->  IF 1 THEN LET/d=1 plot_var =         svstr[d=1,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00",i=1:59,j=1:35]
  !->  LET/d=1 plot_var =         svstr[d=1,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00",i=1:59,j=1:35]

    DEFINE SYMBOL ferret_plot_base_var = ($data_var)[d=($data_num),i=($clon_imin):($clon_imax),j=($clat_jmin):($clat_jmax)]
  !->  DEFINE SYMBOL ferret_plot_base_var = svstr[d=1,i=1:59,j=1:35]

    IF ($region_zt"0|*>1") THEN DEFINE SYMBOL ferret_plot_base_var = \
         ($data_var)[d=($data_num),($region_zt),i=($clon_imin):($clon_imax),j=($clat_jmin):($clat_jmax)]
  !->  IF 1 THEN DEFINE SYMBOL ferret_plot_base_var =         svstr[d=1,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00",i=1:59,j=1:35]
  !->  DEFINE SYMBOL ferret_plot_base_var =         svstr[d=1,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00",i=1:59,j=1:35]
    IF ($region_($which_var)_zt"0|*>1") THEN DEFINE SYMBOL ferret_plot_base_var = \
         ($data_var)[d=($data_num),($region_($which_var)_zt),i=($clon_imin):($clon_imax),j=($clat_jmin):($clat_jmax)]
  !->  IF 1 THEN DEFINE SYMBOL ferret_plot_base_var =         svstr[d=1,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00",i=1:59,j=1:35]
  !->  DEFINE SYMBOL ferret_plot_base_var =         svstr[d=1,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00",i=1:59,j=1:35]

    DEFINE SYMBOL ferret_plot_base_var_($which_var) ($ferret_plot_base_var)
  !->  DEFINE SYMBOL ferret_plot_base_var_0 svstr[d=1,T="05-Jun-2010 00:00:00":"05-Jun-2010 00:00:00",i=1:59,j=1:35]

    DEFINE SYMBOL ferret_plot_var ($expr1)plot_var[d=($data_num)]($expr2), xcoord, ycoord
  !->  DEFINE SYMBOL ferret_plot_var  plot_var[d=1] , xcoord, ycoord
    DEFINE SYMBOL ferret_plot_var_m360 ($expr1)plot_var[d=($data_num)]($expr2), xcoord-360, ycoord
  !->  DEFINE SYMBOL ferret_plot_var_m360  plot_var[d=1] , xcoord-360, ycoord
    IF ($region_zt"0|*>1") THEN
  !->  IF 1 THEN
       DEFINE SYMBOL ferret_plot_var ($expr1)plot_var[d=($data_num)]($expr2), xcoord, ycoord
  !->  DEFINE SYMBOL ferret_plot_var  plot_var[d=1] , xcoord, ycoord
       DEFINE SYMBOL ferret_plot_var_m360 ($expr1)plot_var[d=($data_num)]($expr2), xcoord-360, ycoord
  !->  DEFINE SYMBOL ferret_plot_var_m360  plot_var[d=1] , xcoord-360, ycoord
    ENDIF
    DEFINE SYMBOL ferret_plot_title "($expr1)($data_title)($expr2) ($data_units) Native Curvilinear Plot"
  !->  DEFINE SYMBOL ferret_plot_title " surface v-momentum stress  (newton meter-2) Native Curvilinear Plot"

    IF ($expr3"0|*>1") THEN
  !->  IF 0 THEN
       ENDIF
    ENDIF

! and if the longitudes are in a different modulo branch than requested add /MODULO
    LET its_vector =  STRINDEX("($operation_ID)", "vector") NE 0
  !->  DEFINE VARIABLE its_vector =  STRINDEX("Plot_2D_XY_zoom", "vector") NE 0
    IF `($ferret_lon_modulo"1|1|0|yes>1|no>0|*>0") AND ( ($num)+1 EQ ($data_count) )` THEN
  !->  IF 1 THEN
       LET outside = 0
       IF ($ferret_curv_lon_min"0|*>1") THEN
  !->  IF 1 THEN
          LET xc1 = ($ferret_curv_lon_min)
  !->  DEFINE VARIABLE xc1 = -158.36753276978
       ELSE
       ENDIF
       IF ($ferret_curv_lon_max"0|*>1") THEN
  !->  IF 1 THEN
          LET xcn = ($ferret_curv_lon_max)
  !->  DEFINE VARIABLE xcn = -158.095644459455
       ELSE
       ENDIF
       LET outside = `xc1 GT ($region_x_lo)` + `xcn LT ($region_x_hi)`
  !->  DEFINE VARIABLE outside = 0 + 0
       IF `($ferret_lon_modulo"1|1|0|yes>1|no>0|*>0") AND outside GT 0 AND its_vector EQ 0` THEN \
           DEFINE SYMBOL ferret_lon_modulo = 1
  !->  IF 0 THEN           DEFINE SYMBOL ferret_lon_modulo = 1
    ENDIF

! Or set up for native slices: Sample in the X and Y directions of the slice

ELIF `STRLEN ("($ferret_view)") LE 2` THEN
  !->  ELIF 1 THEN
    ENDIF
ENDIF

! End of $RCSfile ------------transform_curvi_xy.jnl-------------------------------

! End of $RCSfile ------------LAS_transforms.jnl-------------------------------


! Get any DEFINE VARIABLE analysis definitions
! This renames the data variable, and so redefines the symbol data_var
! and sets up the analysis: e.g. ,z=0:2000@ave

! unComment this for testing.

IF ($data_0_analysis_label"0|*>1") THEN
  !->  IF 0 THEN
    ENDIF
ENDIF

! Keep track of variables initialized, to tell us if next time we
! want ferret_expression or ferret_expression2

DEFINE SYMBOL variables_initialized `1 + ($variables_initialized"0")`
  !->  DEFINE SYMBOL variables_initialized 1

! From the variable we can define striding.
! TODO: script works only for rectangular data so far...

! (check for Google Earth plots is inside LAS_set_strides)
IF `($num)+1 EQ ($data_count)` THEN GO LAS_set_strides.jnl
  !->  IF 1 THEN GO LAS_set_strides.jnl
  !->  GO LAS_set_strides.jnl
! LAS_set_strides.jnl
! ACM

! From the region and the grid we can define striding. Compute strides
! based first on Ferret memory and then if it is a graphics product, on
! pixel size.
! ACM 8/312/2007 Do not issue the SET AXIS/STRIDE= command if the stride is 1
!                This partially works around TRAC #224.
! ACM 3/2008  If the transform-to-1-season per year has been set then do not
!             stride in t
! ACM 4/2008  For descriptor data or for data whose axes are replaced cant
!             do native strides. In these cases set up index strides with
!             a call to LAS_set_strides_nonative
! 10-Jul-2008 ACM  Fixes for Google Earth placemark strides

! TODO: When there's going to be a transformation or something, then these
! calculations may not be sufficient. Might be better done by the transform script.

! If the operation is writing a netCDF file, that is done in chunks. Do not use strides

IF `(STRINDEX( "($operation_ID)", "Data_Extract" ) NE 0) AND \
     (STRINDEX( "($result_ferret_listing_type)", "netcdf" ) NE 0)` THEN EXIT/SCRIPT
  !->  IF 0 THEN EXIT/SCRIPT

! See LAS_set_strides_curvilinear for first cut on dealing with strides and curvi data.
! If it is a native curvilinear plot then LAS_set_strides_curvilinear has been called.
IF ($ferret_curvi_coord_lat"0|0|*>1") THEN EXIT/SCRIPT
  !->  IF 1 THEN EXIT/SCRIPT
  !->  EXIT/SCRIPT

! to set non-native strides for dataset 1 on a difference plot.
IF `($no_native_strides_xy"0|*>1") AND ($set_ndx_strides"0|*>1") EQ 0` THEN
  !->  IF 0 THEN
ENDIF

! Mark whether there are contour levels set on first entry.
! Compute automatic open-ended levels.

IF `($data_num) EQ 1` THEN
  !->  IF 1 THEN
    IF ($ferret_contour_levels"0|*>1") THEN DEFINE SYMBOL input_contour_levels = 1
  !->  IF 0 THEN DEFINE SYMBOL input_contour_levels = 1
    IF ($ferret_fill_levels"0|*>1") THEN DEFINE SYMBOL input_fill_levels = 1
  !->  IF 0 THEN DEFINE SYMBOL input_fill_levels = 1

    IF `STRLEN("($ferret_view)") EQ 2 AND STRINDEX("($operation_ID)", "Plot") GT 0` THEN
  !->  IF 1 THEN
       IF `STRINDEX("($op)", "ANIMATION") EQ 0` THEN GO LAS_auto_levels  ! animation levels done elsewhere
  !->  IF 1 THEN GO LAS_auto_levels
  !->  GO LAS_auto_levels
! LAS_auto_levels.jnl

! ACM 8/22/2007
! acm 9/11/07 If its a descriptor file Ferret wont allow striding.
!             check for that case and just set num levels.
! acm* 2/2010 Set up a few things and then Use Ferret-s open-ended levels
!             if the levs havent been set by the user or configuration.
!             Allow for old algorithm if older Ferret is in place.

! Based on a variables value over its entire range, set strides
! if needed to quickly get stats on the variable. Use this to set levels.

! Argument: the variable to use in setting the levels.

! The symbol ferret_center_levels, if set to 1, forces the levels
! to be 2 std above and below zero. Otherwise use 2 std above
! and below the data mean

! This script should be done BEFORE any other striding is done.
! It operates on the variable on its entire native unstrided grid.

! input_fill_levels and input_contour_levels are symbols that are defined in
! LAS_initialize_variable.jnl, telling whether settings for levels were
! made

! Determine striding for speed in operating the STAT command
LET memsize = 0.5* 1.e6

IF `($FERRET_VERSION"0") GE 6.2` THEN KEYMARK 1  ! annotate plot keys with the min and max
  !->  IF 1 THEN KEYMARK 1
  !->  KEYMARK 1

! Make sure its a 2D plot operation.

DEFINE SYMBOL op = `UPCASE("($operation_ID)")`
  !->  DEFINE SYMBOL op = PLOT_2D_XY_ZOOM

IF `STRLEN("($ferret_view)") NE 2` THEN EXIT/SCRIPT
  !->  IF 0 THEN EXIT/SCRIPT
IF `STRINDEX("($op)", "VECTOR") GT 0` THEN EXIT/SCRIPT
  !->  IF 0 THEN EXIT/SCRIPT

IF `STRINDEX("($op)", "PLOT") EQ 0 AND \
   STRINDEX ("($op)", "POLY") EQ 0 AND \
   STRINDEX ("($op)", "ZOOM") EQ 0 AND \
   STRINDEX ("($op)", "CRUISE_SUMMARY") EQ 0` THEN EXIT/SCRIPT
  !->  IF 0 THEN EXIT/SCRIPT

! Levels for animations set in LAS_auto_levels_animate,
! called in list_frames.jnl
IF `STRINDEX("($op)", "ANIMATION") GT 0`  THEN EXIT/SCRIPT
  !->  IF 0  THEN EXIT/SCRIPT

! If its a compare plot, and if the ($ferret_diff_var) is not yet defined,
! just return.

IF `($ferret_diff_var"1|*>0") AND STRINDEX("($op)", "COMPARE_PLOT") NE 0` THEN
  !->  IF 0 THEN
ENDIF
IF `($ferret_diff_var"1|*>0") AND ($its_gridded_scattered"0|*>1")` THEN
  !->  IF 0 THEN
ENDIF

DEFINE SYMBOL ferret_center_levels ($ferret_center_levels"0|1|TRUE>1|*>0")
  !->  DEFINE SYMBOL ferret_center_levels 0

! See if centered levels were requested, either by setting the symbol ferret_center_levels
! or with a contour_levels or fill_levels that is centered.

! If contour levels requested with levels of nC, e.g. 20C, then get the value to
! set num_fine_levels in the %RANGE command below

! In general if other levels spec is given, return. However if it is a simple number,
! use that to set the number of fine levels.

IF ($ferret_contour_levels"0|*>1") THEN
  !->  IF 0 THEN
    ENDIF
    ENDIF
ENDIF

IF ($ferret_fill_levels"0|*>1") THEN
  !->  IF 0 THEN
    ENDIF
    ENDIF
ENDIF

! IF contour and fill levels have not been set by the user or in the config, then
! use Ferrets auto-open-ended levels

IF `($input_contour_levels"0|0|1") EQ 0` THEN
  !->  IF 1 THEN
    DEFINE SYMBOL ferret_fill_levels = ($num_fine_levels)v
  !->  DEFINE SYMBOL ferret_fill_levels =  v
    IF  ($ferret_center_levels"0|0|1") THEN \
       DEFINE SYMBOL ferret_fill_levels = ($num_fine_levels)vc
  !->  IF  0 THEN       DEFINE SYMBOL ferret_fill_levels =  vc
ENDIF
IF `($input_contour_levels"0|0|1") EQ 0` THEN
  !->  IF 1 THEN
    DEFINE SYMBOL ferret_contour_levels = ($num_fine_levels)v
  !->  DEFINE SYMBOL ferret_contour_levels =  v
    IF  ($ferret_center_levels"0|0|1") THEN DEFINE SYMBOL \
         ferret_contour_levels = ($num_fine_levels)vc
  !->  IF  0 THEN DEFINE SYMBOL         ferret_contour_levels =  vc
ENDIF

! End of file ------------LAS_auto_levels.jnl--------------------------
    ENDIF
    IF `STRLEN("($ferret_view)") EQ 2 AND STRINDEX("($operation_ID)", "zoom") GT 0` THEN GO LAS_auto_levels
  !->  IF 1 THEN GO LAS_auto_levels
  !->  GO LAS_auto_levels
! LAS_auto_levels.jnl

! ACM 8/22/2007
! acm 9/11/07 If its a descriptor file Ferret wont allow striding.
!             check for that case and just set num levels.
! acm* 2/2010 Set up a few things and then Use Ferret-s open-ended levels
!             if the levs havent been set by the user or configuration.
!             Allow for old algorithm if older Ferret is in place.

! Based on a variables value over its entire range, set strides
! if needed to quickly get stats on the variable. Use this to set levels.

! Argument: the variable to use in setting the levels.

! The symbol ferret_center_levels, if set to 1, forces the levels
! to be 2 std above and below zero. Otherwise use 2 std above
! and below the data mean

! This script should be done BEFORE any other striding is done.
! It operates on the variable on its entire native unstrided grid.

! input_fill_levels and input_contour_levels are symbols that are defined in
! LAS_initialize_variable.jnl, telling whether settings for levels were
! made

! Determine striding for speed in operating the STAT command
LET memsize = 0.5* 1.e6

IF `($FERRET_VERSION"0") GE 6.2` THEN KEYMARK 1  ! annotate plot keys with the min and max
  !->  IF 1 THEN KEYMARK 1
  !->  KEYMARK 1

! Make sure its a 2D plot operation.

DEFINE SYMBOL op = `UPCASE("($operation_ID)")`
  !->  DEFINE SYMBOL op = PLOT_2D_XY_ZOOM

IF `STRLEN("($ferret_view)") NE 2` THEN EXIT/SCRIPT
  !->  IF 0 THEN EXIT/SCRIPT
IF `STRINDEX("($op)", "VECTOR") GT 0` THEN EXIT/SCRIPT
  !->  IF 0 THEN EXIT/SCRIPT

IF `STRINDEX("($op)", "PLOT") EQ 0 AND \
   STRINDEX ("($op)", "POLY") EQ 0 AND \
   STRINDEX ("($op)", "ZOOM") EQ 0 AND \
   STRINDEX ("($op)", "CRUISE_SUMMARY") EQ 0` THEN EXIT/SCRIPT
  !->  IF 0 THEN EXIT/SCRIPT

! Levels for animations set in LAS_auto_levels_animate,
! called in list_frames.jnl
IF `STRINDEX("($op)", "ANIMATION") GT 0`  THEN EXIT/SCRIPT
  !->  IF 0  THEN EXIT/SCRIPT

! If its a compare plot, and if the ($ferret_diff_var) is not yet defined,
! just return.

IF `($ferret_diff_var"1|*>0") AND STRINDEX("($op)", "COMPARE_PLOT") NE 0` THEN
  !->  IF 0 THEN
ENDIF
IF `($ferret_diff_var"1|*>0") AND ($its_gridded_scattered"0|*>1")` THEN
  !->  IF 0 THEN
ENDIF

DEFINE SYMBOL ferret_center_levels ($ferret_center_levels"0|1|TRUE>1|*>0")
  !->  DEFINE SYMBOL ferret_center_levels 0

! See if centered levels were requested, either by setting the symbol ferret_center_levels
! or with a contour_levels or fill_levels that is centered.

! If contour levels requested with levels of nC, e.g. 20C, then get the value to
! set num_fine_levels in the %RANGE command below

! In general if other levels spec is given, return. However if it is a simple number,
! use that to set the number of fine levels.

IF ($ferret_contour_levels"0|*>1") THEN
  !->  IF 1 THEN
    PPL AXNMTC 0,0 ! Turn on PPL so we can do the edit to remove any spaces (can occur in animations)
    PPL SET nospaces $EDIT (ferret_contour_levels, COLLAPSE)
    DEFINE SYMBOL ferret_contour_levels = ($nospaces)
  !->  DEFINE SYMBOL ferret_contour_levels = v

    DEFINE SYMBOL up_contour_levels = `UPCASE("($ferret_contour_levels)")`
  !->  DEFINE SYMBOL up_contour_levels = V
    LET nc = `STRINDEX("($up_contour_levels)", "C")`
  !->  DEFINE VARIABLE nc = 0
    DEFINE SYMBOL ferret_center_levels = `nc GT 0`
  !->  DEFINE SYMBOL ferret_center_levels = 0
    IF `nc GT 0` THEN
  !->  IF 0 THEN
    ENDIF
    LET other = `STRINDEX("($up_contour_levels)", "D")` + \
       `STRINDEX("($up_contour_levels)", "(")`+ \
       `STRINDEX("($up_contour_levels)", ".")`
  !->  DEFINE VARIABLE other = 0 +       0+       0

    IF `nc EQ 0 AND other EQ 0` THEN
  !->  IF 1 THEN
       DEFINE SYMBOL num_fine_levels = ($ferret_contour_levels) ! How to test that this is just a number??
  !->  DEFINE SYMBOL num_fine_levels = v
       DEFINE SYMBOL num_fine_levels_contour = ($num_fine_levels)
  !->  DEFINE SYMBOL num_fine_levels_contour = v
       CANCEL SYMBOL input_contour_levels  ! we will redefine the levels in this script
    ENDIF
    IF `nc EQ 0 AND other NE 0` THEN  EXIT/SCRIPT
  !->  IF 0 THEN  EXIT/SCRIPT
ENDIF

IF ($ferret_fill_levels"0|*>1") THEN
  !->  IF 1 THEN

    PPL AXNMTC 0,0 ! Turn on PPL so we can do the edit to remove any spaces (can occur in animations)
    PPL SET nospaces $EDIT (ferret_fill_levels, COLLAPSE)
    DEFINE SYMBOL ferret_fill_levels = ($nospaces)
  !->  DEFINE SYMBOL ferret_fill_levels = v

    DEFINE SYMBOL up_fill_levels = `UPCASE("($ferret_fill_levels)")`
  !->  DEFINE SYMBOL up_fill_levels = V
    DEFINE SYMBOL ferret_fill_levels = ($up_fill_levels)
  !->  DEFINE SYMBOL ferret_fill_levels = V
    LET nc = `STRINDEX("($up_fill_levels)", "C")`
  !->  DEFINE VARIABLE nc = 0
    DEFINE SYMBOL ferret_center_levels = `nc GT 0`
  !->  DEFINE SYMBOL ferret_center_levels = 0
    IF `nc GT 0` THEN
  !->  IF 0 THEN
    ENDIF
    LET other = `STRINDEX("($ferret_fill_levels)", "D")` + \
       `STRINDEX("($ferret_fill_levels)", ",")`+ \
       `STRINDEX("($ferret_fill_levels)", "(")`+ \
       `STRINDEX("($ferret_fill_levels)", ".")`
  !->  DEFINE VARIABLE other = 0 +       0+       0+       0

    IF `nc EQ 0 AND other EQ 0` THEN
  !->  IF 1 THEN
       DEFINE SYMBOL num_fine_levels = ($ferret_fill_levels)  ! How to test that this is just a number??
  !->  DEFINE SYMBOL num_fine_levels = V
       CANCEL SYMBOL input_fill_levels  ! we will redefine the levels in this script
    ENDIF
    IF `nc EQ 0 AND other NE 0` THEN  EXIT/SCRIPT
  !->  IF 0 THEN  EXIT/SCRIPT
ENDIF

! IF contour and fill levels have not been set by the user or in the config, then
! use Ferrets auto-open-ended levels

IF `($input_contour_levels"0|0|1") EQ 0` THEN
  !->  IF 1 THEN
    DEFINE SYMBOL ferret_fill_levels = ($num_fine_levels)v
  !->  DEFINE SYMBOL ferret_fill_levels = Vv
    IF  ($ferret_center_levels"0|0|1") THEN \
       DEFINE SYMBOL ferret_fill_levels = ($num_fine_levels)vc
  !->  IF  0 THEN       DEFINE SYMBOL ferret_fill_levels = Vvc
ENDIF
IF `($input_contour_levels"0|0|1") EQ 0` THEN
  !->  IF 1 THEN
    DEFINE SYMBOL ferret_contour_levels = ($num_fine_levels)v
  !->  DEFINE SYMBOL ferret_contour_levels = Vv
    IF  ($ferret_center_levels"0|0|1") THEN DEFINE SYMBOL \
         ferret_contour_levels = ($num_fine_levels)vc
  !->  IF  0 THEN DEFINE SYMBOL         ferret_contour_levels = Vvc
ENDIF

! End of file ------------LAS_auto_levels.jnl--------------------------

ENDIF

! End of $RCSfile ------------LAS_initialize_variable.jnl--------------------------

! End of $RCSfile ------------LAS_initialize_data.jnl--------------------------


! Check for errors (They often occur during dataset initialization.)

IF ($error_status"0|*>1") THEN
  !->  IF 0 THEN
ENDIF

! Check whether the region is too small to make a 2D plot on this grid.
GO LAS_check_2d_region
! LAS_check_2d_region.jnl
!
! Author: ansley
! $Date: 2007/06/22
! ACM 8/7/2007 - Apply expressions here.
!              - Save symbols with information about too-small regions
!                for use by labels_above_plot.jnl
!              - If this is to be an overlay plot, and region is too small
!                then overlay cant be done. Reset number of datasets to 1.
!
! Check whether the region is too small to make a 2D plot on this grid.
! Call after region and dataset have been initialized for 2D plot.

! Change ($data_var)[d=($data_num)] to the_plot_var_noregion

CANCEL SYMBOL region_small*

LET/D=($data_num) the_plot_var_noregion = ($ferret_plot_var_noregion)
  !->  DEFINE VARIABLE/D=1 the_plot_var_noregion = svstr[d=1]

IF ($data_analysis_expr"0|*>1") THEN
  !->  IF 0 THEN
ENDIF

! Do not make the check for native curvlinear or hybrid z plots.

IF `($do_curvi_xy"0") AND ($native_curvilinear_xy"0")` THEN EXIT/SCRIPT
  !->  IF 1 THEN EXIT/SCRIPT
  !->  EXIT/SCRIPT

! Check for errors
IF ($error_status"0|ERROR>1") THEN
  !->  IF 0 THEN
ENDIF

! Here is variable 0 and its title

DEFINE SYMBOL ferret_var_0 = ($ferret_plot_var)
  !->  DEFINE SYMBOL ferret_var_0 = plot_var[d=1] , xcoord, ycoord
DEFINE SYMBOL ferret_title_0 = ($ferret_plot_title"($data_var)")
  !->  DEFINE SYMBOL ferret_title_0 =  surface v-momentum stress  (newton meter-2) Native Curvilinear Plot
IF ($ferret_plot_var_m360"0|*>1") THEN DEFINE SYMBOL ferret_var_m360_0 = ($ferret_plot_var_m360)
  !->  IF 1 THEN DEFINE SYMBOL ferret_var_m360_0 = plot_var[d=1] , xcoord-360, ycoord
  !->  DEFINE SYMBOL ferret_var_m360_0 = plot_var[d=1] , xcoord-360, ycoord

! Open the window, apply size, scale and WMS view options
GO LAS_open_window
! LAS_open_window.jnl
!
! Author: ansley
! Date: 2007/02/12
!
! The LAS_open_windw.jnl script takes care of everything having to
! do with starting the window.
!
!
! - Open the window with the desired size
! - Issue CANCEL MODE LOGO command
! - If an XY plot and if this has been requested, set the aspect
!   ratio to match the region
! - If no margins (WMS style plot) is requested, set that up,
!   including the /NOYADJUST plot qualifier.


SET WINDOW/SIZE = ($ferret_size"0.5")
  !->  SET WINDOW/SIZE = 0.5
CANCEL MODE LOGO

IF ($ferret_view"|xy>1|*>0") THEN
  !->  IF 1 THEN
   IF ($ferret_set_aspect"1|default>1|no>0|yes>1|0|1") THEN SET WINDOW/ASPECT = `($region_Y_range)/($region_X_range)`:axis
  !->  IF 1 THEN SET WINDOW/ASPECT = `0.3110008/0.2672882`:axis
  !->  SET WINDOW/ASPECT = `0.3110008/0.2672882`:axis
  !->  SET WINDOW/ASPECT = 1.163541:axis
ENDIF

IF `($ferret_margins"1|0|1|false>0|true>1") EQ 0` THEN
  !->  IF 0 THEN
ELSE
! For 2D plots, make room for the colorbar labels which sometimes get cut off.
    IF `STRLEN("($ferret_view)") EQ 2` THEN
  !->  IF 1 THEN
       DEFINE VIEW/X=0:0.95/Y=0:1 xspace
       SET VIEW xspace
    ENDIF

ENDIF

! TODO:  Should the creation of the ($qualifiers) symbol for standard
! TODO:  2D plots be separated out in a separate script called:
! TODO:    LAS_2D_plot_qualifiers.jnl
!
! Build up the plot qualifiers

!ACM note: All color plots use $ferret_fill_levels. Contour plots use $ferret_contour_levels.

IF ($ferret_contour_style"0|contour_lines>1|*>0") THEN
  !->  IF 0 THEN
    ENDIF
ELSE
    IF ($ferret_fill_levels"0|*>1") THEN
  !->  IF 1 THEN
      DEFINE SYMBOL qualifiers = ($qualifiers)/LEVELS=($ferret_fill_levels)
  !->  DEFINE SYMBOL qualifiers = /HLIM=-158.3675:-158.1002/LEVELS=Vv
    ENDIF
ENDIF

IF ($ferret_plot_key"0|0|nokey>0|*>1") THEN
  !->  IF 0 THEN
ENDIF

IF ($ferret_use_graticules"1|0|*>1) THEN
  !->  IF 1 THEN
   SET MODE GRATICULE:(DASH,COLOR=black)
ENDIF

DEFINE SYMBOL qualifiers = ($qualifiers)/PALETTE=($ferret_palette"rainbow|default>rainbow|*>*)
  !->  DEFINE SYMBOL qualifiers = /HLIM=-158.3675:-158.1002/LEVELS=Vv/PALETTE=rainbow

IF ($ferret_curvi_quals"0|*>1") THEN
  !->  IF 1 THEN
   DEFINE SYMBOL qualifiers = ($qualifiers)($ferret_curvi_quals)
  !->  DEFINE SYMBOL qualifiers = /HLIM=-158.3675:-158.1002/LEVELS=Vv/PALETTE=rainbow/HLIM=-158.3675:-158.100236/VLIM=21.25:21.5611
ENDIF

! Set up for degrees-minutes-seconds labels on axes with units of degrees

IF ($ferret_deg_min_sec"0|false>0|*>1") THEN GO LAS_set_deg_min_sec.jnl
  !->  IF 0 THEN GO LAS_set_deg_min_sec.jnl

! Set the plot type (SHADE or CONTOUR)

DEFINE SYMBOL plot_type =($ferret_contour_style"FILL|default>FILL|raster>SHADE|color_filled_contours>FILL|color_filled_plus_lines>FILL|contour_lines>CONTOUR|raster_plus_lines>SHADE")
  !->  DEFINE SYMBOL plot_type =FILL

! For all FILL plots, we will first do a SHADE underlay to get the plot to draw all the way to the edges.
DEFINE SYMBOL shade_underlay = FALSE
IF ($plot_type"0|FILL>1|*>0) THEN DEFINE SYMBOL shade_underlay = TRUE
  !->  IF 1 THEN DEFINE SYMBOL shade_underlay = TRUE
  !->  DEFINE SYMBOL shade_underlay = TRUE

! Set the URL label for the first dataset.
GO LAS_url_label 0
! LAS_url_label.jnl


! Define upper-right labels with the url; the URL is not plotted automatically when the var is
! (the same thing may be done in transform scripts or in differencing setup; that is ok
! 1/2010 fix ticket 745 - immediate-mode expressions where the string contains an = sign
!        trip up the command parsing. Break these definitions into two steps.

IF `($n_right_labels"0") EQ 0` THEN DEFINE SYMBOL n_right_labels = 0
  !->  IF 1 THEN DEFINE SYMBOL n_right_labels = 0
  !->  DEFINE SYMBOL n_right_labels = 0
!IF `($data_$1_url"0|*>1") EQ 0` THEN EXIT/SCRIPT


! Instead of the URL use the dataset name or ID passed in to the
! (addXML gets this from the title attribute from the original dataset
! dataset if that attrib exists)

LET got_dataset_label = 0

IF `got_dataset_label EQ 0` THEN
  !->  IF 1 THEN
    IF `($data_$1_dataset_id"0|*>1")+($data_$1_dataset_name"0|*>1") GT 0` THEN \
       DEFINE SYMBOL n_right_labels = `($n_right_labels)+1`
  !->  IF 1 THEN       DEFINE SYMBOL n_right_labels = `0+1`
  !->  DEFINE SYMBOL n_right_labels = `0+1`
  !->  DEFINE SYMBOL n_right_labels = 1

    IF ($data_$1_dataset_id"0|*>1") THEN
  !->  IF 1 THEN
      DEFINE SYMBOL upper_right_($n_right_labels) = DATA SET: ($data_$1_dataset_id)
  !->  DEFINE SYMBOL upper_right_1 = DATA SET: hiroms_hiomwg
      DEFINE SYMBOL upper_right_text_($n_right_labels) = DATA SET: ($data_$1_dataset_id)
  !->  DEFINE SYMBOL upper_right_text_1 = DATA SET: hiroms_hiomwg
      LET got_dataset_label = 1
    ENDIF
    IF ($data_$1_dataset_name"0|*>1") THEN
  !->  IF 1 THEN
      DEFINE SYMBOL upper_right_($n_right_labels) = DATA SET: ($data_$1_dataset_name)
  !->  DEFINE SYMBOL upper_right_1 = DATA SET: Hawaii Regional Oceanic Modeling System (HI-ROMS) Oahu Waianae Grid (50m)
      DEFINE SYMBOL upper_right_text_($n_right_labels) = DATA SET: ($data_$1_dataset_name)
  !->  DEFINE SYMBOL upper_right_text_1 = DATA SET: Hawaii Regional Oceanic Modeling System (HI-ROMS) Oahu Waianae Grid (50m)
      LET got_dataset_label = 1
    ENDIF
ENDIF

! If we didnt get a label from the above, use the URL

IF `got_dataset_label EQ 0` THEN
  !->  IF 0 THEN
       ENDIF
    ENDIF
ENDIF

! If its really long, split into multiple lines at the location of a slash.

LET slen = STRLEN ("($upper_right_($n_right_labels))")
  !->  DEFINE VARIABLE slen = STRLEN ("DATA SET: Hawaii Regional Oceanic Modeling System (HI-ROMS) Oahu Waianae Grid (50m)")

IF `slen GT 80` THEN
  !->  IF 1 THEN
    LET slen2 = INT(slen/2)
    LET last_slash = STRRINDEX("($upper_right_($n_right_labels))", "/")
  !->  DEFINE VARIABLE last_slash = STRRINDEX("DATA SET: Hawaii Regional Oceanic Modeling System (HI-ROMS) Oahu Waianae Grid (50m)", "/")

    IF `last_slash GT slen2` THEN
  !->  IF 0 THEN
    ENDIF

    IF `last_slash GT 0` THEN
  !->  IF 0 THEN
    ENDIF
ENDIF


DEFINE SYMBOL upper_right_($n_right_labels) = @AS($upper_right_($n_right_labels))
  !->  DEFINE SYMBOL upper_right_1 = @ASDATA SET: Hawaii Regional Oceanic Modeling System (HI-ROMS) Oahu Waianae Grid (50m)
IF `($n_right_labels"0") GT 1` THEN \
    DEFINE SYMBOL upper_right_($n_right_labels) = @P2($upper_right_($n_right_labels))
  !->  IF 0 THEN    DEFINE SYMBOL upper_right_1 = @P2@ASDATA SET: Hawaii Regional Oceanic Modeling System (HI-ROMS) Oahu Waianae Grid (50m)

! For comparison plots get rid of the long ugly URL labels at the upper right.
! (DO this in the difference scripts!??

IF `got_dataset_label EQ 0` THEN
  !->  IF 0 THEN
ENDIF

! End of $RCSfile ------------LAS_url_label.jnl--------------------------

! Set up for second variable, overlaid as contour lines.
! If there were more than 2 data sets, then use a loop (below) with
! CONTOUR/OVERLAY and rely on automatic Ferret labelling of the contours.
! For just two data sets, set up fancier titles and labels.

IF `($data_count"0") EQ 2` THEN
  !->  IF 0 THEN
     ENDIF
ENDIF

! If there is just one variable, draw the plot and we are done

IF ($ferret_curvi_quals"0|*>1") THEN
  !->  IF 1 THEN
    IF ($ferret_lon_modulo"1|1|0|yes>1|no>0|*>0") THEN  DEFINE SYMBOL shade_qualifiers = ($shade_qualifiers)/MODULO
  !->  IF 1 THEN  DEFINE SYMBOL shade_qualifiers =  /MODULO
  !->  DEFINE SYMBOL shade_qualifiers =  /MODULO
ENDIF

IF `($data_count"0") EQ 1` THEN
  !->  IF 1 THEN
    DEFINE SYMBOL split_title = ($ferret_plot_title)
  !->  DEFINE SYMBOL split_title =  surface v-momentum stress  (newton meter-2) Native Curvilinear Plot
    GO LAS_split_title
! LAS_split_title.jnl

! If a title is long, split into multiple lines at the location of an addition
! to the title.

LET slen = STRLEN ("($split_title)")
  !->  DEFINE VARIABLE slen = STRLEN ("surface v-momentum stress  (newton meter-2) Native Curvilinear Plot")

IF `slen GT 80` THEN
  !->  IF 0 THEN
       ENDIF
    ENDIF
ENDIF

! End of $RCSfile ------------ LAS_split_title.jnl--------------------------
    DEFINE SYMBOL ferret_plot_title = ($split_title)
  !->  DEFINE SYMBOL ferret_plot_title = surface v-momentum stress  (newton meter-2) Native Curvilinear Plot

    IF ($shade_underlay) THEN
  !->  IF TRUE THEN
       IF `($ferret_google_plot"0") EQ 0` THEN \
          DEFINE SYMBOL shade_qualifiers = ($shade_qualifiers)/TRIM
  !->  IF 1 THEN          DEFINE SYMBOL shade_qualifiers = /MODULO/TRIM
  !->  DEFINE SYMBOL shade_qualifiers = /MODULO/TRIM

       SHADE($qualifiers)($shade_qualifiers)/TITLE="($ferret_plot_title)"/SET ($ferret_var_0)
  !->  SHADE/HLIM=-158.3675:-158.1002/LEVELS=Vv/PALETTE=rainbow/HLIM=-158.3675:-158.100236/VLIM=21.25:21.5611/MODULO/TRIM/TITLE="surface v-momentum stress  (newton meter-2) Native Curvilinear Plot"/SET plot_var[d=1] , xcoord, ycoord
          IF ($xform_dms"0|*>1") THEN PPL XFOR (($xform_dms))
  !->  IF 0 THEN PPL XFOR ( )
          IF ($yform_dms"0|*>1") THEN PPL YFOR (($yform_dms))
  !->  IF 0 THEN PPL YFOR ( )
          IF ($axlab_command"0|*>1") THEN PPL ($axlab_command)
  !->  IF 0 THEN PPL
          IF ($axtic_command"0|*>1") THEN PPL ($axtic_command)
  !->  IF 0 THEN PPL
          IF ($axlen_command"0|*>1") THEN PPL ($axlen_command)
  !->  IF 0 THEN PPL
          if ($labnum_dset"0|*>1") THEN go unlabel ($labnum_dset)
  !->  if 1 THEN go unlabel 2
  !->  go unlabel 2
! usage:   GO unlabel label_number
!	where label_number is the label revealed by the command PPL LIST LABELS

!   e.g.  remove the "NOAA/PMEL TMAP" signature label from a plot
!	   yes? PLOT/SET_UP/I=1:100 SIN(I/6)
!	   yes? PPL LIST LABELS                ! notice #2 is the one to remove
!	   yes? GO unlabel 2
!	   yes? PPL PLOT


! test argument before performing any actions
QUERY/IGNORE $1"<Usage: GO unlabel n,  where n is a PLOT+ movable label number"
  !->  QUERY/IGNORE 2

! remove the label by setting its location to the origin with no text content
PPL LABS/NOUSER $1,0,0 @AS
  !->  PPL LABS/NOUSER 2,0,0 @AS

set mode/last verify
          if ($labnum_datitl"0|*>1") THEN go unlabel ($labnum_datitl)
  !->  if 1 THEN go unlabel 3
  !->  go unlabel 3
! usage:   GO unlabel label_number
!	where label_number is the label revealed by the command PPL LIST LABELS

!   e.g.  remove the "NOAA/PMEL TMAP" signature label from a plot
!	   yes? PLOT/SET_UP/I=1:100 SIN(I/6)
!	   yes? PPL LIST LABELS                ! notice #2 is the one to remove
!	   yes? GO unlabel 2
!	   yes? PPL PLOT


! test argument before performing any actions
QUERY/IGNORE $1"<Usage: GO unlabel n,  where n is a PLOT+ movable label number"
  !->  QUERY/IGNORE 3

! remove the label by setting its location to the origin with no text content
PPL LABS/NOUSER $1,0,0 @AS
  !->  PPL LABS/NOUSER 3,0,0 @AS

set mode/last verify
          if ($labnum_dods"0|*>1") THEN go unlabel ($labnum_dods)
  !->  if 1 THEN go unlabel 4
  !->  go unlabel 4
! usage:   GO unlabel label_number
!	where label_number is the label revealed by the command PPL LIST LABELS

!   e.g.  remove the "NOAA/PMEL TMAP" signature label from a plot
!	   yes? PLOT/SET_UP/I=1:100 SIN(I/6)
!	   yes? PPL LIST LABELS                ! notice #2 is the one to remove
!	   yes? GO unlabel 2
!	   yes? PPL PLOT


! test argument before performing any actions
QUERY/IGNORE $1"<Usage: GO unlabel n,  where n is a PLOT+ movable label number"
  !->  QUERY/IGNORE 4

! remove the label by setting its location to the origin with no text content
PPL LABS/NOUSER $1,0,0 @AS
  !->  PPL LABS/NOUSER 4,0,0 @AS

set mode/last verify
	 PPL SHAKEY 1,,,,,,,,,,1
       PPL SHADE
       IF `($LEV_NUM"0") GT 245/2` THEN PPL SHASET RESET
  !->  IF 0 THEN PPL SHASET RESET
       ($plot_type)($qualifiers)/OVER/NOLAB ($ferret_var_0)
  !->  CONTOUR/FILL/HLIM=-158.3675:-158.1002/LEVELS=Vv/PALETTE=rainbow/HLIM=-158.3675:-158.100236/VLIM=21.25:21.5611/OVER/NOLAB plot_var[d=1] , xcoord, ycoord



[Thread Prev][Thread Next][Index]


Contact Us
Dept of Commerce / NOAA / OAR / PMEL / TMAP

Privacy Policy | Disclaimer | Accessibility Statement