!*******************************************************************************
!$RCSfile$
!$Revision$
!$Date$
!*******************************************************************************
!==============================================================================
! createFields
!==============================================================================
SUBROUTINE createFields()

USE Extract_fi

IMPLICIT NONE

INTEGER, EXTERNAL :: PostCreateField

IF( output3D )THEN

  CALL CreateOutput3D()
  IF( nError /= NO_ERROR )GOTO 9999

ELSE

  CALL allocateFields( 1 )
  IF( nError /= NO_ERROR )GOTO 9999

  Fields(1) = Field
  FieldIds(1) = PostCreateField( Fields(1),ClassData,.TRUE.,'Plot' )
  IF( FieldIds(1) < 0 )GOTO 9999

END IF

9999 CONTINUE

RETURN
END
!==============================================================================
! createFields
!==============================================================================
INTEGER FUNCTION PostCreateField( thisField,thisData,doMax,header )

USE Extract_fi
USE SCIPtool

IMPLICIT NONE

TYPE( SCIPPlotFieldT ) :: thisField
REAL, DIMENSION(*)     :: thisData
LOGICAL                :: doMax
CHARACTER(*)           :: header

INTEGER fID, irv
REAL    dmin, dmax, fmin, fmax, dmn, dmx

PostCreateField = -1

fID = SCIPCreateField( callerID,thisField,thisData )
IF( fID <= 0 )THEN
  CALL toolError( 'Error retrieving '//TRIM(header)//' field from SCIPtool' )
  GOTO 9999
END IF

IF( doMax )THEN
  irv = SCIPGetFieldMinMax( callerID,fID,plotType,dmin,dmax,fmin,fmax,dmn,dmx)
  IF( irv /= SCIPsuccess )THEN
    CALL toolError( 'Error in SCIPGetFieldMinMax' )
    GOTO 9999
  END IF
  FldMin(1) = dmn
  FldMax(1) = dmx
END IF

PostCreateField = fID


9999 CONTINUE

RETURN
END
