1.  summary:		conservative mappings between gx1v3 and finite volume
                        1x1.125 degree grid

2.  created by:		Gary Strand
 
3.  date and time:	25 Jul 2003

4.  created on: 	dave
 
5.  dataset format: 	nc
 
6.  endian:		n/a
 
7.  archival copy location:
			/CCSM/mapping/maps
 
8.  creation summary:
 
The following is a deSCRIPtion of how one would produce a netcdf mapping file
between gx1v3 and fv_1x1.125d grids. You may wish to replace these grid names in
the following and then make use of copy-paste to produce grid files and/or
weights.

-----------
-- Setup --
-----------

Copy SCRIP from most recent scrip directory, under
    /fs/cgd/csm/mapping

Copied SCRIP from these directories:
   (/fs/cgd/data0/hecht/mapping/scrip1.4/grids)
   (/fs/cgd/data0/hecht/mapping/scrip1.4/source)

In grids/convert[POPT, gauss, etc.].f
   Edit nx, ny, grid_name, and grid_file_out.
   Any other edits?
   make

In source subdir,
   make scrip

   This didn't work. So linked to Hecht's executables:
/fs/cgd/data0/hecht/mapping/scrip1.4/scrip
/fs/cgd/data0/hecht/mapping/scrip1.4/scrip_test



-----------
-- Grids --
-----------

Note: As of November 2001 we are not using the standard scrip1.4
version of convertPOPT, but have nonstandard code to use the
ccsm_pop/cice calculation of T-grid cell center locations, and we use
Keith's nonstd calculation of southern-most points. I'm getting this
code from 
  /fs/cgd/home0/hecht/csm/fortran/SCRIP/scrip1.4/grids/convertPOPT.f
This file is under revision control, in 
  /home/hecht/my_cvs/SCRIP/scrip1.4/grids/convertPOPT.f,v
Note also that there was a (harmless, it seems) bug in this nonstandard 
version of convertPOPT.f, affecting the grid coordinates in the (unused)
j=1 row. This is why these maps are being regenerated today. The diffs
between buggy -r1.3 code and bug-fixed code are:
*** 306,313 ****
        n = 0
        do i=1,nx
           n   = n + 1
!          np1 = n + ny
!          np2 = n + 2*ny
           grid_center_lon(n) = grid_center_lon(np1)
           grid_center_lat(n) = 2.0*grid_center_lat(np1) - 
       $        grid_center_lat(np2)
--- 306,313 ----
        n = 0
        do i=1,nx
           n   = n + 1
!          np1 = n + nx
!          np2 = n + 2*nx
           grid_center_lon(n) = grid_center_lon(np1)
           grid_center_lat(n) = 2.0*grid_center_lat(np1) - 
       $        grid_center_lat(np2)
---

In grids subdir,
produce gx1v3_020513.nc from:

   convertPOPT

Add documentation:

   ncatted -O -h -a Created_by,global,a,c,"`whoami`, `date`" gx1v3_020513.nc
   ncatted -O -h -a 1D_grid_indexing,global,a,c,"if n is 1D index, i runs fast, j runs slow: n=(j-1)*fast_grid_dim+i" gx1v3_020513.nc

-----------
-- Scrip --
-----------

In SCRIP directory, 

write scrip_in:

    cat >! scrip_in
&remap_inputs
    num_maps = 2,
    grid1_file = '/fs/cgd/csm/mapping/grids/gx1v3_020513.nc',
    grid2_file = '/fs/cgd/csm/mapping/grids/fv_1x1.125d.nc'
    interp_file1 = 'map_gx1v3_to_1x1.125d_aave_da.nc',
    interp_file2 = 'map_1x1.125d_to_gx1v3_aave_da.nc',
    map1_name = 'gx1v3 to finite volume 1x1.125d conservative',
    map2_name = 'finite volume 1x1.125d to gx1v3 conservative',
    map_method = 'conservative',
    normalize_opt = 'destarea',
    output_opt = 'ncar-csm',
    restrict_type = 'latlon',
    num_srch_bins = 10
/

Note that the grid files should come from the standard CCSM
location (/fs/cgd/csm/mapping/grids/) unless the grid is untested (see
below for the testing procedure which is recommended at this point in
time).

Run scrip:
   ln -s /fs/cgd/data0/hecht/mapping/scrip1.4/scrip scrip
   ln -s /fs/cgd/data0/hecht/mapping/scrip1.4/scrip_test scrip_test

   scrip > map_gx1v3_and_1x1.125d_aave_da.out

------------------------
-- Testing of Weights --
------------------------

-- Run ferret and check stats of both maps.

-- Run scrip_test for 1x1.125d_to_gx1v3:

In SCRIP directory, write scrip_test_in:

    cat >! scrip_test_in
&remap_inputs
    field_choice = 2
    interp_file = 'map_1x1.125d_to_gx1v3_aave_da.nc'
    output_file = 'test_1x1.125d_to_gx1v3_aave_da.nc'
/
   scrip_test > ! test_1x1.125d_to_gx1v3_aave_da.out

Inspect output netcdf file out[...].nc file with ferret.
yes? set data out_1x1.125d_to_gx1v3_aave_da.nc
yes? shade src_array
yes? shade dst_array1
yes? shade dst_error1

Append some of the output of scrip_test to the map file, documenting 
error field:
   1) copy the output from scrip_test to tmp file called foo
   2) edit foo, saving FIELD_CHOICE and all lines from 

 First order mapping from grid1 to grid2:

      on down.
   3) replace each end-of-line with \n
   4) append this business as a global ncdf attribute:
      ncatted -O -h -a scrip_test_output,global,a,c,"`cat foo`" map_1x1.125d_to_gx1v3_aave_da.nc 

-- Run scrip_test for gx1v3_to_1x1.125d:

In SCRIP directory, write scrip_test_in:

    cat >! scrip_test_in
&remap_inputs
    field_choice = 2
    interp_file = 'map_gx1v3_to_1x1.125d_aave_da.nc'
    output_file = 'test_gx1v3_to_1x1.125d_aave_da.nc'
/

   scrip_test > ! test_gx1v3_to_1x1.125d_aave_da.out

Inspect output netcdf file out[...].nc file with ferret.
 set data test_gx1v3_to_1x1.125d_aave_da.nc
 shade src_array
 shade dst_array1
 shade dst_error1


Append some of the output of scrip_test to the map file, documenting 
error field:
   1) copy the output from scrip_test to tmp file called foo
   2) edit foo, saving FIELD_CHOICE and all lines from 

 First order mapping from grid1 to grid2:

      on down.
   3) replace each end-of-line with \n
   4) append this business as a global ncdf attribute:
      ncatted -O -h -a scrip_test_output,global,a,c,"`cat foo`" \
              map_gx1v3_to_1x1.125d_aave_da.nc

------------------------------
-- Consistency of Grid Data --
------------------------------

If this is not the first mapping file produced for this ocean (ice) grid, 
then check that the grid info included in the map.nc file agrees with that
from existing files.

-------------
-- Caution --
-------------

Brian has some test code built into the coupler that

1) checks that array elements are in [0,1]
2) checks that array rows add up to one (or zero for masked out regions)
3) checks what percent of array rows add up to one (eg. a->o should be about
   70%)
4) checks that SCRIP domain info is compatible with info sent to cpl at run
   time.

For now, this information must be inspected the first time a map is used
by the cpl. In the near future we will have stand-alone code to do this.

---------------
-- Finish up --
---------------

If mappings are ok then, again, add documentation:

   ncatted -O -h -a Created_by,global,a,c,"`whoami`, `date`" map_1x1.125d_to_gx1v3_aave_da.nc
   ncatted -O -h -a 1D_grid_indexing,global,a,c,"if n is 1D index, i runs fast, j runs slow: n=(j-1)*fast_grid_dim+i" map_1x1.125d_to_gx1v3_aave_da.nc

   ncatted -O -h -a Created_by,global,a,c,"`whoami`, `date`" map_gx1v3_to_1x1.125d_aave_da.nc
   ncatted -O -h -a 1D_grid_indexing,global,a,c,"if n is 1D index, i runs fast, j runs slow: n=(j-1)*fast_grid_dim+i" map_gx1v3_to_1x1.125d_aave_da.nc

and to be installed in /fs/cgd/csm/mapping/maps:
(do later)

   mv map_1x1.125d_to_gx1v3_aave_da.nc /fs/cgd/csm/mapping/maps
   chgrp cgdcsm /fs/cgd/csm/mapping/maps/map_1x1.125d_to_gx1v3_aave_da.nc
   chmod 444    /fs/cgd/csm/mapping/maps/map_1x1.125d_to_gx1v3_aave_da.nc
   mv map_1x1.125d_to_gx1v3_aave_da.readme /fs/cgd/csm/mapping/maps
   chgrp cgdcsm /fs/cgd/csm/mapping/maps/map_1x1.125d_to_gx1v3_aave_da.readme
   chmod 444    /fs/cgd/csm/mapping/maps/map_1x1.125d_to_gx1v3_aave_da.readme

   mv map_gx1v3_to_1x1.125d_aave_da.nc /fs/cgd/csm/mapping/maps
   chgrp cgdcsm /fs/cgd/csm/mapping/maps/map_gx1v3_to_1x1.125d_aave_da.nc
   chmod 444    /fs/cgd/csm/mapping/maps/map_gx1v3_to_1x1.125d_aave_da.nc
   ln -s /fs/cgd/csm/mapping/maps/map_1x1.125d_to_gx1v3_aave_da.readme \
         /fs/cgd/csm/mapping/maps/map_gx1v3_to_1x1.125d_aave_da.readme

