\can mode verify ! Usage: go def_cubesphere_unfold ivar_pre [ovar layout arc_attach antarc_attach eq_start] ! $1 [ $2 $3 $4 $5 $6 ] ! Defines an output variable OVAR consisting of the unfolded-cube ! representation of the tile variables IVAR_PRE[1-6]. IVAR_PRE must be ! a simple one-word prefix. Choices for the unfolded LAYOUT are: ! ! EQUATOR (default): Unfold the cube with the equatorial tiles in the middle ! row, and the Arctic & Antarctic tiles attached above & below. The ! equatorial tiles numbered {1,2,4,5} and those are the only valid choices ! for EQ_START, ARC_ATTACH, and ANTARC_ATTACH. The equatorial tiles to ! which the polar tiles are attached are selected with ARC_ATTACH & ! ANTARC_ATTACH; default connects through the Americas. The first ! equatorial tile on the left is selected with EQ_START. This is a 3x4 ! layout, half empty. ! ! ARCTIC: A 4x3 cross that preserves connections with the Arctic, and connects ! through the specified ANTARC_ATTACH equatorial tile to the Antarctic. ! Default connects through the Americas. EQ_START does not affect this ! layout. ! ! ANTARCTIC: A 4x3 upside-down cross that preserves connections with the ! Antarctic, and connects through the specified ARC_ATTACH equatorial ! tile to the Arctic. Default connects through the Americas. EQ_START ! does not affect this layout. ! ! STAIR: A 3x4 staircase configuration, half empty. This preserves the ! order & orientation of the tiles as found in the input NetCDF files, ! with tile 1 at the bottom left and tile 6 at the top right. ! ! RECTANGLE: A 2x3 rectangle that preserves the connections through the ! IndoPacific & North America. The Antarctic and Atlantic tiles are tossed ! into the top left corner, with their original orientations but separated ! from their neighboring tiles. This is the most compact layout. ! ! The EQ_START, ARC_ATTACH, and ANTARC_ATTACH arguments are ignored for the ! STAIR and RECTANGLE layouts. ! ! The following tile connectivity is assumed: ! ! Neighbors ! Tile Landmark L R B T ! ---------------------------- ! 1 Atlantic 5 2 6 3 ! 2 Indian Ocean 1 4 6 3 ! 3 Arctic 1 4 2 5 ! 4 West Pacific 3 6 2 5 ! 5 East Pacific 3 6 4 1 ! 6 Antarctic 5 2 4 1 ! ! EXAMPLES ! ! Setup: ! yes? def sym ipre "fv_core.res.tile" ! yes? def sym ipre "data/00491208.atmos_daily.tile" ! yes? def sym isuf ".nc" ! yes? def sym retitle set var/title="\`(\$var)[d=1],r=title\`"/unit="\`(\$var)[d=1],r=unit\`" var_cube ! ! Define a general cubed-sphere variable, preserving title & units. After ! this, multiple variables can be plotted with the same layout without having ! to re-run this script. ! yes? go def_cubesphere_unfold var ! ! Switch to t_surf and assign the tile variables: ! yes? def sym var t_surf; let var = ($var) ! yes? rep/name=s/range=1:6 (use "($ipre)`s`($isuf)"; let var`s` = var[d=`($var),r=dsetnum`]) ! yes? ($retitle); shade var_cube ! ! Switching to zsurf is easy, if we have the same tile datasets and layout: ! yes? def sym var zsurf; let var = ($var) ! yes? ($retitle); shade var_cube ! ! An equatorial strip, attaching Arctic at equatorial tile 2 and Antarctic ! at equatorial tile 5, and start equatorial strip at tile 1: ! yes? go def_cubesphere_unfold var " " EQUATOR 2 5 1 ! yes? ($retitle); shade var_cube ! ! An Arctic cross, connecting through Atlantic tile 1 to the Antarctic: ! yes? go def_cubesphere_unfold var " " ARCTIC 1 ! yes? ($retitle); shade var_cube ! ! atw 2008aug14 def sym dcu_ipre $1 !input variable name prefix (one word) def sym dcu_ovar $2"$1_cube" !output variable to define def sym dcu_layout $3"EQUATOR|EQUATOR|STAIR|RECTANGLE|ARCTIC|ANTARCTIC" def sym dcu_arc_attach $4"5|1|2|4|5" !Arctic attaches to this equatorial tile def sym dcu_antarc_attach $5"($dcu_arc_attach)|1|2|4|5" !Antarctic attaches to this equatorial tile def sym dcu_eq_start $6"2|1|2|4|5" !leftmost tile in the equatorial strip ! for the ARCTIC & ANTARCTIC displays, force the polar tiles ! to attach to the same equatorial tile IF `"($dcu_layout)" EQ "ARCTIC"` THEN def sym dcu_arc_attach ($dcu_antarc_attach) ELIF `"($dcu_layout)" EQ "ANTARCTIC"` THEN def sym dcu_antarc_attach ($dcu_arc_attach) ENDIF ! rotation operations (angles are counter-clockwise) def sym dcu_rot90 "xreverse(transpose_xy(" def sym dcu_rot180 "yreverse(xreverse(" def sym dcu_rot270 "transpose_xy(xreverse(" ! define rotations for Arctic & Antarctic that will ! attach to the specified upright equatorial tile IF `($dcu_arc_attach) EQ 1` THEN def sym dcu_arc1 "($dcu_rot90)" def sym dcu_arc2 "))" ELIF `($dcu_arc_attach) EQ 2` THEN def sym dcu_arc1 "" def sym dcu_arc2 "" ELIF `($dcu_arc_attach) EQ 4` THEN def sym dcu_arc1 "($dcu_rot270)" def sym dcu_arc2 "))" ELIF `($dcu_arc_attach) EQ 5` THEN def sym dcu_arc1 "($dcu_rot180)" def sym dcu_arc2 "))" ENDIF IF `($dcu_antarc_attach) EQ 1` THEN def sym dcu_ant1 "" def sym dcu_ant2 "" ELIF `($dcu_antarc_attach) EQ 2` THEN def sym dcu_ant1 "($dcu_rot90)" def sym dcu_ant2 "))" ELIF `($dcu_antarc_attach) EQ 4` THEN def sym dcu_ant1 "($dcu_rot180)" def sym dcu_ant2 "))" ELIF `($dcu_antarc_attach) EQ 5` THEN def sym dcu_ant1 "($dcu_rot270)" def sym dcu_ant2 "))" ENDIF def sym dcu_null ($dcu_ipre)6/0 ! define the final tiled variable IF `"($dcu_layout)" EQ "STAIR"` THEN let ($dcu_ovar) = ycat(ycat(\ xcat(xcat(xcat(($dcu_ipre)1,($dcu_ipre)2),($dcu_null)),($dcu_null)),\ xcat(xcat(xcat(($dcu_null),($dcu_ipre)3),($dcu_ipre)4),($dcu_null))),\ xcat(xcat(xcat(($dcu_null),($dcu_null)),($dcu_ipre)5),($dcu_ipre)6)) ELIF `"($dcu_layout)" EQ "RECTANGLE"` THEN let ($dcu_ovar) = ycat(\ xcat(xcat(($dcu_ipre)2,($dcu_rot270)($dcu_ipre)4))),($dcu_rot270)($dcu_ipre)5))),\ xcat(xcat(($dcu_ipre)6,($dcu_ipre)1),($dcu_rot180)($dcu_ipre)3)))) ELIF `"($dcu_layout)" EQ "ARCTIC"` THEN ! make the 3x3 Arctic "+", rotate it, then add the rotated Antarctic let ($dcu_ovar) = ycat(\ xcat(xcat(($dcu_null),($dcu_ant1)($dcu_ipre)6($dcu_ant2)),($dcu_null)),\ ($dcu_arc1)ycat(ycat(\ xcat(xcat(($dcu_null),($dcu_ipre)2),($dcu_null)),\ xcat(xcat(($dcu_rot270)($dcu_ipre)1)),($dcu_ipre)3),($dcu_ipre)4)),\ xcat(xcat(($dcu_null),($dcu_rot90)($dcu_ipre)5))),($dcu_null)))($dcu_arc2)) ELIF `"($dcu_layout)" EQ "ANTARCTIC"` THEN ! make the 3x3 Antarctic "+", rotate it, then add the rotated Arctic let ($dcu_ovar) = ycat(\ ($dcu_ant1)ycat(ycat(\ xcat(xcat(($dcu_null),($dcu_rot90)($dcu_ipre)4))),($dcu_null)),\ xcat(xcat(($dcu_ipre)5,($dcu_ipre)6),($dcu_rot270)($dcu_ipre)2)))),\ xcat(xcat(($dcu_null),($dcu_ipre)1),($dcu_null)))($dcu_ant2),\ xcat(xcat(($dcu_null),($dcu_arc1)($dcu_ipre)3($dcu_arc2)),($dcu_null))) ELIF `"($dcu_layout)" EQ "EQUATOR"` THEN ! rotations that connect the equatorial tiles def sym dcu_eqdisp1 ($dcu_ipre)1 def sym dcu_eqdisp2 ($dcu_ipre)2 def sym dcu_eqdisp4 ($dcu_rot270)($dcu_ipre)4)) def sym dcu_eqdisp5 ($dcu_rot270)($dcu_ipre)5)) ! rotations & masks to connect polar tiles to equatorial tiles def sym dcu_adisp1 ($dcu_null) def sym dcu_adisp2 ($dcu_null) def sym dcu_adisp4 ($dcu_null) def sym dcu_adisp5 ($dcu_null) def sym dcu_aadisp1 ($dcu_null) def sym dcu_aadisp2 ($dcu_null) def sym dcu_aadisp4 ($dcu_null) def sym dcu_aadisp5 ($dcu_null) def sym dcu_adisp($dcu_arc_attach) ($dcu_arc1)($dcu_ipre)3($dcu_arc2) def sym dcu_aadisp($dcu_antarc_attach) ($dcu_ant1)($dcu_ipre)6($dcu_ant2) ! define the equatorial & polar strips let dcu_eqtiles = {1,2,4,5,1,2,4,5} let dcu_eqtile1 = dcu_eqtiles[i=`dcu_eqtiles[i=@loc:($dcu_eq_start)]`] let dcu_eqtile2 = dcu_eqtiles[i=`dcu_eqtiles[i=@loc:($dcu_eq_start)]+1`] let dcu_eqtile3 = dcu_eqtiles[i=`dcu_eqtiles[i=@loc:($dcu_eq_start)]+2`] let dcu_eqtile4 = dcu_eqtiles[i=`dcu_eqtiles[i=@loc:($dcu_eq_start)]+3`] def sym dcu_equator xcat(xcat(xcat((\$dcu_eqdisp`dcu_eqtile1`),(\$dcu_eqdisp`dcu_eqtile2`)),(\$dcu_eqdisp`dcu_eqtile3`)),(\$dcu_eqdisp`dcu_eqtile4`)) def sym dcu_astrip xcat(xcat(xcat((\$dcu_adisp`dcu_eqtile1`),(\$dcu_adisp`dcu_eqtile2`)),(\$dcu_adisp`dcu_eqtile3`)),(\$dcu_adisp`dcu_eqtile4`)) def sym dcu_aastrip xcat(xcat(xcat((\$dcu_aadisp`dcu_eqtile1`),(\$dcu_aadisp`dcu_eqtile2`)),(\$dcu_aadisp`dcu_eqtile3`)),(\$dcu_aadisp`dcu_eqtile4`)) can var dcu_eqtiles dcu_eqtile1 dcu_eqtile2 dcu_eqtile3 dcu_eqtile4 ! stack the strips to define the output variable let ($dcu_ovar) = ycat(ycat(($dcu_aastrip),($dcu_equator)),($dcu_astrip)) can sym dcu_eqdisp1 dcu_eqdisp2 dcu_eqdisp4 dcu_eqdisp5 can sym dcu_adisp1 dcu_adisp2 dcu_adisp4 dcu_adisp5 can sym dcu_aadisp1 dcu_aadisp2 dcu_aadisp4 dcu_aadisp5 can sym dcu_equator dcu_astrip dcu_aastrip ENDIF can sym dcu_ipre dcu_ovar can sym dcu_layout dcu_eq_start dcu_arc_attach dcu_antarc_attach can sym dcu_arc1 dcu_arc2 dcu_ant1 dcu_ant2 dcu_null can sym dcu_rot90 dcu_rot180 dcu_rot270 set mode/last verify