C                  INTERNATIONAL AVS CENTER
C        (This disclaimer must remain at the top of all files)
C
C WARRANTY DISCLAIMER
C
C This module and the files associated with it are distributed free of charge.
C It is placed in the public domain and permission is granted for anyone to use,
C duplicate, modify, and redistribute it unless otherwise noted.  Some modules
C may be copyrighted.  You agree to abide by the conditions also included in
C the AVS Licensing Agreement, version 1.0, located in the main module
C directory located at the International AVS Center ftp site and to include
C the AVS Licensing Agreement when you distribute any files downloaded from
C that site.
C
C The International AVS Center, MCNC, the AVS Consortium and the individual
C submitting the module and files associated with said module provide absolutely
C NO WARRANTY OF ANY KIND with respect to this software.  The entire risk as to
C the quality and performance of this software is with the user.  IN NO EVENT
C WILL The International AVS Center, MCNC, the AVS Consortium and the individual
C submitting the module and files associated with said module BE LIABLE TO
C ANYONE FOR ANY DAMAGES ARISING FROM THE USE OF THIS SOFTWARE, INCLUDING,
C WITHOUT LIMITATION, DAMAGES RESULTING FROM LOST DATA OR LOST PROFITS, OR ANY
C SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES.
C
C This AVS module and associated files are public domain software unless
C otherwise noted.  Permission is hereby granted to do whatever you like with
C it, subject to the conditions that may exist in copyrighted materials. Should
C you wish to make a contribution toward the improvement, modification, or
C general performance of this module, please send us your comments:  why you
C liked or disliked it, how you use it, and most important, how it helps your
C work. We will receive your comments at avs@ncsc.org.
C
C Please send AVS module bug reports to avs@ncsc.org.
C
C	"@(#)map_vals.f	1.1 Stardent 90/03/23"
C			Copyright (c) 1989 by
C			Stardent Computer Inc.
C			All Rights Reserved
C	
C	This software comprises unpublished confidential information of
C	Stardent Computer Inc. and may not be used, copied or made
C	available to anyone, except in accordance with the license
C	under which it is furnished.
C	
C	This file is under sccs control at Stardent in:
C	/sccs/avs/user_modules/data/read_dyna3d/src/s.map_vals.f
C	
C	
c     *--------------------------------------------------------*
c     *                                                        *
c     *              ****  map_values  ****                    *
c     *                                                        *
c     * map analysis values to colors.                         *
c     *                                                        *
c     * map_vals.f                                             *
c     *--------------------------------------------------------*

      subroutine map_values (num_nodes, num_states, contour_type, 
     &   num_node_data, node_data, vert_colors, state, data_ranges)

      include 'read_dyna3d.h'

      integer num_states, num_nodes, num_node_data, contour_type, state 

      real node_data(num_nodes, num_node_data, num_states),
     1     data_ranges(2, num_node_data, num_states)
    

      character comp_types(4)*3

      integer node, i, max_node, min_node, offset 

      logical map_not_defined, comp_mag

      real x, xinc, r, g, b, color_map(3, max_colors), 
     &  vert_colors(3, 10000), max_val, min_val, scale, val, 
     &  mag, y, z

      data map_not_defined /.true./

      data comp_types/'mag', 'x', 'y', 'z'/

c     **************
c     ***  body  ***
c     **************

c     define a color mapping for the nodal values.

      if (map_not_defined) then
        call def_color_map (max_colors, color_map)
        map_not_defined = .false.
      end if

      min_val  = data_ranges(1, contour_type, state)
      max_val  = data_ranges(2, contour_type, state)

      if (abs(max_val - min_val) .gt. 0.1e-20) then
        scale = float(max_colors - 1) / (max_val - min_val)
      else
        scale = 0 
      end if
  
      do node = 1, num_nodes 
        val  = node_data(node, contour_type, state)
        i = int((max_val - val) * scale) + 1

        vert_colors(1, node) = color_map(1, i)
        vert_colors(2, node) = color_map(2, i)
        vert_colors(3, node) = color_map(3, i)
      end do

      return
      end