--------------------------------------------------------
--  File created - Friday-November-20-2015   
--------------------------------------------------------

--------------------------------------------------------
--  DDL for Table ALGORITHMOUTPUTS
--------------------------------------------------------

  CREATE TABLE "NVCL"."ALGORITHMOUTPUTS" 
   (	"ALGORITHMOUTPUT_ID" NUMBER(10,0), 
	"ALGORITHMOUTPUTNAME" VARCHAR2(4000), 
	"SCRIPT" VARCHAR2(4000), 
	"DESCRIPTION" VARCHAR2(4000), 
	"OUTPUTLOGTYPE" NUMBER(10,0), 
	"ALGORITHM_ID" NUMBER(10,0), 
	"ALGVERSION" NUMBER(8,4)
   )   PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255  NOCOMPRESS LOGGING 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLTBLSPC" ;

   COMMENT ON COLUMN "NVCL"."ALGORITHMOUTPUTS"."ALGORITHMOUTPUT_ID" IS 'Algorithm identifier, integer sequence';
   COMMENT ON COLUMN "NVCL"."ALGORITHMOUTPUTS"."ALGORITHMOUTPUTNAME" IS 'name give to this algorithm';
   COMMENT ON COLUMN "NVCL"."ALGORITHMOUTPUTS"."SCRIPT" IS 'TSG script used to generate result logs';
   COMMENT ON COLUMN "NVCL"."ALGORITHMOUTPUTS"."DESCRIPTION" IS 'Text description of this algorithm';
   COMMENT ON COLUMN "NVCL"."ALGORITHMOUTPUTS"."OUTPUTLOGTYPE" IS 'The log type generated by this algorithm';
   COMMENT ON COLUMN "NVCL"."ALGORITHMOUTPUTS"."ALGORITHM_ID" IS 'identifier of algorithm this output belongs too';
   COMMENT ON TABLE "NVCL"."ALGORITHMOUTPUTS"  IS 'This table contains the definition of algorithms used to produce logs.  Where the algorithm can be represented as a TSG script, it is also stored.';
  GRANT SELECT ON "NVCL"."ALGORITHMOUTPUTS" TO "NVCLVIEWER";
  GRANT UPDATE ON "NVCL"."ALGORITHMOUTPUTS" TO "NVCLANALYST";
  GRANT SELECT ON "NVCL"."ALGORITHMOUTPUTS" TO "NVCLANALYST";
  GRANT INSERT ON "NVCL"."ALGORITHMOUTPUTS" TO "NVCLANALYST";
  GRANT DELETE ON "NVCL"."ALGORITHMOUTPUTS" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Table ALGORITHMS
--------------------------------------------------------

  CREATE TABLE "NVCL"."ALGORITHMS" 
   (	"ALGORITHM_ID" NUMBER(10,0), 
	"ALGORITHMNAME" VARCHAR2(4000), 
	"CREATORUSERNAME" VARCHAR2(4000), 
	"ISPUBLIC" NUMBER(1,0), 
	"DESCRIPTION" VARCHAR2(4000), 
	"CREATEDDATE" TIMESTAMP (0) WITH TIME ZONE
   )   PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255  NOCOMPRESS LOGGING 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLTBLSPC" ;

   COMMENT ON COLUMN "NVCL"."ALGORITHMS"."ALGORITHM_ID" IS 'Algorithm identifier, integer sequence';
   COMMENT ON COLUMN "NVCL"."ALGORITHMS"."ALGORITHMNAME" IS 'name give to this algorithm';
   COMMENT ON COLUMN "NVCL"."ALGORITHMS"."CREATORUSERNAME" IS 'algorithm creator''s name';
   COMMENT ON COLUMN "NVCL"."ALGORITHMS"."ISPUBLIC" IS 'Boolean field indicating whether other users can use this algorithm or not';
   COMMENT ON COLUMN "NVCL"."ALGORITHMS"."DESCRIPTION" IS 'Text description of this algorithm';
   COMMENT ON COLUMN "NVCL"."ALGORITHMS"."CREATEDDATE" IS 'Timestamp when algorithm was created';
   COMMENT ON TABLE "NVCL"."ALGORITHMS"  IS 'This table contains the definition of algorithms used to produce logs.  Where the algorithm can be represented as a TSG script, it is also stored.';
  GRANT SELECT ON "NVCL"."ALGORITHMS" TO "NVCLVIEWER";
  GRANT UPDATE ON "NVCL"."ALGORITHMS" TO "NVCLANALYST";
  GRANT SELECT ON "NVCL"."ALGORITHMS" TO "NVCLANALYST";
  GRANT INSERT ON "NVCL"."ALGORITHMS" TO "NVCLANALYST";
  GRANT DELETE ON "NVCL"."ALGORITHMS" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Table CALIBRATIONLOGDATA
--------------------------------------------------------

  CREATE TABLE "NVCL"."CALIBRATIONLOGDATA" 
   (	"LOG_ID" VARCHAR2(64), 
	"SAMPLENUMBER" NUMBER(10,0), 
	"CALIBRATIONDATA" BLOB
   )   PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255  NOCOMPRESS LOGGING 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLTBLSPC" 
 LOB ("CALIBRATIONDATA") STORE AS SECUREFILE (
  TABLESPACE "NVCLLOBTS" ENABLE STORAGE IN ROW CHUNK 8192
  NOCACHE LOGGING  NOCOMPRESS  KEEP_DUPLICATES 
  STORAGE(INITIAL 106496 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0  BUFFER_POOL DEFAULT)) ;

   COMMENT ON COLUMN "NVCL"."CALIBRATIONLOGDATA"."LOG_ID" IS 'log identifier, indicating which log this data belongs to';
   COMMENT ON COLUMN "NVCL"."CALIBRATIONLOGDATA"."SAMPLENUMBER" IS 'sample number maps to the spatial sampling domain to give a depth down-hole';
   COMMENT ON COLUMN "NVCL"."CALIBRATIONLOGDATA"."CALIBRATIONDATA" IS 'Calibration data blob';
   COMMENT ON TABLE "NVCL"."CALIBRATIONLOGDATA"  IS 'This table contains the data for calibtration type logs.  ';
  GRANT SELECT ON "NVCL"."CALIBRATIONLOGDATA" TO "NVCLVIEWER";
  GRANT SELECT ON "NVCL"."CALIBRATIONLOGDATA" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Table CALIBRATIONLOGS
--------------------------------------------------------

  CREATE TABLE "NVCL"."CALIBRATIONLOGS" 
   (	"LOG_ID" VARCHAR2(64)
   )   PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255  NOCOMPRESS LOGGING 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLTBLSPC" ;

   COMMENT ON COLUMN "NVCL"."CALIBRATIONLOGS"."LOG_ID" IS 'Log identifier, calibrationlogs are specialisations of logs and share a unique identifier';
   COMMENT ON TABLE "NVCL"."CALIBRATIONLOGS"  IS 'This table contains information about calibration type logs. A calibration type log is a log of binary calibration data captured during the creation of a dataset.';
  GRANT SELECT ON "NVCL"."CALIBRATIONLOGS" TO "NVCLVIEWER";
  GRANT SELECT ON "NVCL"."CALIBRATIONLOGS" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Table CLASSIFICATIONS
--------------------------------------------------------

  CREATE TABLE "NVCL"."CLASSIFICATIONS" 
   (	"ALGORITHMOUTPUT_ID" NUMBER(10,0), 
	"INTINDEX" NUMBER(10,0), 
	"COLOUR" NUMBER(10,0), 
	"CLASSTEXT" VARCHAR2(4000), 
	"DESCRIPTION" VARCHAR2(4000)
   )   PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255  NOCOMPRESS LOGGING 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLTBLSPC" ;

   COMMENT ON COLUMN "NVCL"."CLASSIFICATIONS"."ALGORITHMOUTPUT_ID" IS 'algorithm identifier, classifications belong to an algorithm';
   COMMENT ON COLUMN "NVCL"."CLASSIFICATIONS"."INTINDEX" IS 'classifications index';
   COMMENT ON COLUMN "NVCL"."CLASSIFICATIONS"."COLOUR" IS 'display colour';
   COMMENT ON COLUMN "NVCL"."CLASSIFICATIONS"."CLASSTEXT" IS 'short text ';
   COMMENT ON COLUMN "NVCL"."CLASSIFICATIONS"."DESCRIPTION" IS 'longer description of the meaning of this classification';
   COMMENT ON TABLE "NVCL"."CLASSIFICATIONS"  IS 'This table holds all available classification results for known algorithms including their display colour, short text and a full description.';
  GRANT SELECT ON "NVCL"."CLASSIFICATIONS" TO "WEBSERVICE";
  GRANT SELECT ON "NVCL"."CLASSIFICATIONS" TO "NVCLVIEWER";
  GRANT UPDATE ON "NVCL"."CLASSIFICATIONS" TO "NVCLANALYST";
  GRANT SELECT ON "NVCL"."CLASSIFICATIONS" TO "NVCLANALYST";
  GRANT INSERT ON "NVCL"."CLASSIFICATIONS" TO "NVCLANALYST";
  GRANT DELETE ON "NVCL"."CLASSIFICATIONS" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Table CLASSLOGDATA
--------------------------------------------------------

  CREATE TABLE "NVCL"."CLASSLOGDATA" 
   (	"LOG_ID" VARCHAR2(64), 
	"SAMPLENUMBER" NUMBER(10,0), 
	"CLASSLOGVALUE" NUMBER(10,0)
   )   PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255  NOCOMPRESS LOGGING 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLTBLSPC" ;

   COMMENT ON COLUMN "NVCL"."CLASSLOGDATA"."LOG_ID" IS 'log identifier, indentifies which log this data belongs to';
   COMMENT ON COLUMN "NVCL"."CLASSLOGDATA"."SAMPLENUMBER" IS 'Sample number used to map onto the spatial sampling domain';
   COMMENT ON COLUMN "NVCL"."CLASSLOGDATA"."CLASSLOGVALUE" IS 'data value references a classifier index';
   COMMENT ON TABLE "NVCL"."CLASSLOGDATA"  IS 'This table contains the data for class type logs.  The values stored here in combination with the log identifier reference the index values store in the classifiers table.';
  GRANT SELECT ON "NVCL"."CLASSLOGDATA" TO "WEBSERVICE";
  GRANT SELECT ON "NVCL"."CLASSLOGDATA" TO "NVCLVIEWER";
  GRANT SELECT ON "NVCL"."CLASSLOGDATA" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Table CLASSLOGS
--------------------------------------------------------

  CREATE TABLE "NVCL"."CLASSLOGS" 
   (	"LOG_ID" VARCHAR2(64), 
	"SCALARGROUP_ID" NUMBER(10,0)
   )   PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255  NOCOMPRESS LOGGING 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLTBLSPC" ;

   COMMENT ON COLUMN "NVCL"."CLASSLOGS"."LOG_ID" IS 'log identifier, references the logs table';
   COMMENT ON COLUMN "NVCL"."CLASSLOGS"."SCALARGROUP_ID" IS 'scalargroup identifier, identifies the group the user assigned this log to';
   COMMENT ON TABLE "NVCL"."CLASSLOGS"  IS 'This table contains class type logs (specialisation of a log).';
  GRANT SELECT ON "NVCL"."CLASSLOGS" TO "NVCLVIEWER";
  GRANT SELECT ON "NVCL"."CLASSLOGS" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Table CLASSSPECIFICCLASSIFICATIONS
--------------------------------------------------------

  CREATE TABLE "NVCL"."CLASSSPECIFICCLASSIFICATIONS" 
   (	"LOG_ID" VARCHAR2(64), 
	"INTINDEX" NUMBER(10,0), 
	"COLOUR" NUMBER(10,0), 
	"CLASSTEXT" VARCHAR2(4000), 
	"DESCRIPTION" VARCHAR2(4000)
   )   PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255  NOCOMPRESS LOGGING 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLTBLSPC" ;

   COMMENT ON COLUMN "NVCL"."CLASSSPECIFICCLASSIFICATIONS"."LOG_ID" IS 'log unique identifier';
   COMMENT ON COLUMN "NVCL"."CLASSSPECIFICCLASSIFICATIONS"."INTINDEX" IS 'classification index';
   COMMENT ON COLUMN "NVCL"."CLASSSPECIFICCLASSIFICATIONS"."COLOUR" IS 'classification new colour';
   COMMENT ON COLUMN "NVCL"."CLASSSPECIFICCLASSIFICATIONS"."CLASSTEXT" IS 'short text for this classification';
   COMMENT ON COLUMN "NVCL"."CLASSSPECIFICCLASSIFICATIONS"."DESCRIPTION" IS 'long description of classification';
   COMMENT ON TABLE "NVCL"."CLASSSPECIFICCLASSIFICATIONS"  IS 'This table records classification schemes when a customised class type log is defined.';
  GRANT SELECT ON "NVCL"."CLASSSPECIFICCLASSIFICATIONS" TO "WEBSERVICE";
  GRANT SELECT ON "NVCL"."CLASSSPECIFICCLASSIFICATIONS" TO "NVCLVIEWER";
  GRANT SELECT ON "NVCL"."CLASSSPECIFICCLASSIFICATIONS" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Table DATASETS
--------------------------------------------------------

  CREATE TABLE "NVCL"."DATASETS" 
   (	"DATASET_ID" VARCHAR2(64), 
	"DATASETNAME" VARCHAR2(4000), 
	"DOMAIN_ID" VARCHAR2(64), 
	"ISREFERENCELIBRARY" NUMBER(1,0), 
	"CREATEDDATE" TIMESTAMP (0) WITH TIME ZONE, 
	"MODIFIEDDATE" TIMESTAMP (0) WITH TIME ZONE, 
	"CREATORUSERNAME" VARCHAR2(4000), 
	"MODIFIERUSERNAME" VARCHAR2(4000), 
	"PRIMARYLOGGER_ID" NUMBER(10,0), 
	"SPECLOG_ID" VARCHAR2(64), 
	"IMAGELOG_ID" VARCHAR2(64), 
	"PROFLOG_ID" VARCHAR2(64), 
	"TRAYLOG_ID" VARCHAR2(64), 
	"SECTIONLOG_ID" VARCHAR2(64), 
	"TSGLAYOUT" CLOB, 
	"HOLEDATASOURCENAME" VARCHAR2(4000), 
	"HOLEIDENTIFIER" VARCHAR2(256), 
	"DSDESCRIPTION" VARCHAR2(4000), 
	"ORIGAUTHOR" VARCHAR2(4000), 
	"IMPORTDATE" TIMESTAMP (0) WITH TIME ZONE, 
	"SCANDATE" TIMESTAMP (0) WITH TIME ZONE, 
	"CUSTOMDATASET_ID" VARCHAR2(64), 
	"CUSTCALCDATASET_ID" VARCHAR2(64), 
	"ISPUBLIC" NUMBER(1,0), 
	"CHK_L0ARCHIVED" NUMBER(10,0) DEFAULT 0, 
	"CHK_FMSTATUS" NUMBER(10,0) DEFAULT 0, 
	"CHK_TIDLSTATUS" NUMBER(10,0) DEFAULT 0, 
	"CHK_IMGSTATUS" NUMBER(10,0) DEFAULT 0, 
	"CHK_SUTSA" NUMBER(10,0) DEFAULT 0, 
	"CHK_VUTSA" NUMBER(10,0) DEFAULT 0, 
	"CHK_TUTSA" NUMBER(10,0) DEFAULT 0, 
	"CHK_IMPORTS" NUMBER(10,0) DEFAULT 0, 
	"CHK_RMARKS" NUMBER(10,0) DEFAULT 0, 
	"CHK_BATSTATUS" NUMBER(10,0) DEFAULT 0, 
	"CHK_SCLRSTATUS" NUMBER(10,0) DEFAULT 0, 
	"CHK_DOMAINS" NUMBER(10,0) DEFAULT 0, 
	"CHK_PLOTS" NUMBER(10,0) DEFAULT 0, 
	"CHK_LAYOUTS" NUMBER(10,0) DEFAULT 0, 
	"CHK_DBASE" NUMBER(10,0) DEFAULT 0
   )   PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255  NOCOMPRESS LOGGING 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLTBLSPC" 
 LOB ("TSGLAYOUT") STORE AS SECUREFILE (
  TABLESPACE "NVCLLOBTS" ENABLE STORAGE IN ROW CHUNK 8192
  NOCACHE LOGGING  NOCOMPRESS  KEEP_DUPLICATES 
  STORAGE(INITIAL 106496 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0  BUFFER_POOL DEFAULT)) ;

   COMMENT ON COLUMN "NVCL"."DATASETS"."DATASET_ID" IS 'dataset identifier, integer sequence';
   COMMENT ON COLUMN "NVCL"."DATASETS"."DATASETNAME" IS 'name given to this dataset';
   COMMENT ON COLUMN "NVCL"."DATASETS"."DOMAIN_ID" IS 'log identifier of the default spatial sampling domain to be used';
   COMMENT ON COLUMN "NVCL"."DATASETS"."ISREFERENCELIBRARY" IS 'Boolean indicating if this dataset is a library of results used for comparisons';
   COMMENT ON COLUMN "NVCL"."DATASETS"."CREATEDDATE" IS 'Timestamp when dataset was created';
   COMMENT ON COLUMN "NVCL"."DATASETS"."MODIFIEDDATE" IS 'Timestamp when dataset was last modified';
   COMMENT ON COLUMN "NVCL"."DATASETS"."CREATORUSERNAME" IS 'Creators username';
   COMMENT ON COLUMN "NVCL"."DATASETS"."MODIFIERUSERNAME" IS 'Last modified by username';
   COMMENT ON COLUMN "NVCL"."DATASETS"."SPECLOG_ID" IS 'base spectral log identifier';
   COMMENT ON COLUMN "NVCL"."DATASETS"."IMAGELOG_ID" IS 'base image log id (in TSG this will be the master linescan image log)';
   COMMENT ON COLUMN "NVCL"."DATASETS"."PROFLOG_ID" IS 'base proflog id';
   COMMENT ON COLUMN "NVCL"."DATASETS"."TSGLAYOUT" IS 'TSG display layout information, string';
   COMMENT ON COLUMN "NVCL"."DATASETS"."HOLEDATASOURCENAME" IS 'name of datasource containing this drill holes meta data.';
   COMMENT ON COLUMN "NVCL"."DATASETS"."HOLEIDENTIFIER" IS 'identifier of hole within holedatasourcename WFS';
   COMMENT ON COLUMN "NVCL"."DATASETS"."ORIGAUTHOR" IS 'author as specified by the person who uploaded this dataset';
   COMMENT ON TABLE "NVCL"."DATASETS"  IS 'This table contains dataset specific information.  This data is used to recreate an analysis session within "The Spectral Geologist" software application.  Schema_Version=1.1';
  GRANT UPDATE ON "NVCL"."DATASETS" TO "NVCLANALYST";
  GRANT DELETE ON "NVCL"."DATASETS" TO "NVCLANALYST";
  GRANT SELECT ON "NVCL"."DATASETS" TO "NVCLVIEWER";
  GRANT SELECT ON "NVCL"."DATASETS" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Table DATASETSTATS
--------------------------------------------------------

  CREATE TABLE "NVCL"."DATASETSTATS" 
   (	"DATASETSTATS_ID" VARCHAR2(64), 
	"VALIDBITMASK" NUMBER(38,0), 
	"STATSTYPE" NUMBER(1,0), 
	"SAMPLES" NUMBER(10,0), 
	"LIBCHANNELS" NUMBER(10,0), 
	"CHANNELS" NUMBER(10,0), 
	"WSUB" NUMBER(10,0), 
	"WUFLAGS" NUMBER(38,0), 
	"LCWHICH" NUMBER(38,0), 
	"LCPRENORM" NUMBER(38,0), 
	"LCBKREM" NUMBER(38,0), 
	"LCPOSTNORM" NUMBER(38,0), 
	"LCSGLEFT" NUMBER(38,0), 
	"LCSGRIGHT" NUMBER(38,0), 
	"LCSGPOLY" NUMBER(38,0), 
	"LCSGDERIV" NUMBER(38,0), 
	"RESAMPLINGALGORITHM" NUMBER(38,0), 
	"RESWMIN" FLOAT(126), 
	"RESWMAX" FLOAT(126), 
	"RESWINC" FLOAT(126), 
	"WMIN" FLOAT(126), 
	"WMAX" FLOAT(126), 
	"WTOL" FLOAT(126), 
	"LIBRARYDATASET_ID" VARCHAR2(64), 
	"MASKLOG_ID" VARCHAR2(64), 
	"USERCOMMENTS" VARCHAR2(4000), 
	"WVL" BLOB, 
	"CHMAX" BLOB, 
	"CHMIN" BLOB, 
	"MEAN" BLOB, 
	"SDEV" BLOB, 
	"COVAR" BLOB, 
	"CORREL" BLOB, 
	"NOISECV" BLOB, 
	"EVAL" BLOB, 
	"FTRANS" BLOB, 
	"RTRANS" BLOB, 
	"LIB_WVL" BLOB
   )   PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255  NOCOMPRESS LOGGING 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLTBLSPC" 
 LOB ("WVL") STORE AS SECUREFILE (
  TABLESPACE "NVCLLOBTS" ENABLE STORAGE IN ROW CHUNK 8192
  NOCACHE LOGGING  NOCOMPRESS  KEEP_DUPLICATES 
  STORAGE(INITIAL 106496 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0  BUFFER_POOL DEFAULT)) 
 LOB ("CHMAX") STORE AS SECUREFILE (
  TABLESPACE "NVCLLOBTS" ENABLE STORAGE IN ROW CHUNK 8192
  NOCACHE LOGGING  NOCOMPRESS  KEEP_DUPLICATES 
  STORAGE(INITIAL 106496 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0  BUFFER_POOL DEFAULT)) 
 LOB ("CHMIN") STORE AS SECUREFILE (
  TABLESPACE "NVCLLOBTS" ENABLE STORAGE IN ROW CHUNK 8192
  NOCACHE LOGGING  NOCOMPRESS  KEEP_DUPLICATES 
  STORAGE(INITIAL 106496 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0  BUFFER_POOL DEFAULT)) 
 LOB ("MEAN") STORE AS SECUREFILE (
  TABLESPACE "NVCLLOBTS" ENABLE STORAGE IN ROW CHUNK 8192
  NOCACHE LOGGING  NOCOMPRESS  KEEP_DUPLICATES 
  STORAGE(INITIAL 106496 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0  BUFFER_POOL DEFAULT)) 
 LOB ("SDEV") STORE AS SECUREFILE (
  TABLESPACE "NVCLLOBTS" ENABLE STORAGE IN ROW CHUNK 8192
  NOCACHE LOGGING  NOCOMPRESS  KEEP_DUPLICATES 
  STORAGE(INITIAL 106496 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0  BUFFER_POOL DEFAULT)) 
 LOB ("COVAR") STORE AS SECUREFILE (
  TABLESPACE "NVCLLOBTS" ENABLE STORAGE IN ROW CHUNK 8192
  NOCACHE LOGGING  NOCOMPRESS  KEEP_DUPLICATES 
  STORAGE(INITIAL 106496 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0  BUFFER_POOL DEFAULT)) 
 LOB ("CORREL") STORE AS SECUREFILE (
  TABLESPACE "NVCLLOBTS" ENABLE STORAGE IN ROW CHUNK 8192
  NOCACHE LOGGING  NOCOMPRESS  KEEP_DUPLICATES 
  STORAGE(INITIAL 106496 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0  BUFFER_POOL DEFAULT)) 
 LOB ("NOISECV") STORE AS SECUREFILE (
  TABLESPACE "NVCLLOBTS" ENABLE STORAGE IN ROW CHUNK 8192
  NOCACHE LOGGING  NOCOMPRESS  KEEP_DUPLICATES 
  STORAGE(INITIAL 106496 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0  BUFFER_POOL DEFAULT)) 
 LOB ("EVAL") STORE AS SECUREFILE (
  TABLESPACE "NVCLLOBTS" ENABLE STORAGE IN ROW CHUNK 8192
  NOCACHE LOGGING  NOCOMPRESS  KEEP_DUPLICATES 
  STORAGE(INITIAL 106496 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0  BUFFER_POOL DEFAULT)) 
 LOB ("FTRANS") STORE AS SECUREFILE (
  TABLESPACE "NVCLLOBTS" ENABLE STORAGE IN ROW CHUNK 8192
  NOCACHE LOGGING  NOCOMPRESS  KEEP_DUPLICATES 
  STORAGE(INITIAL 106496 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0  BUFFER_POOL DEFAULT)) 
 LOB ("RTRANS") STORE AS SECUREFILE (
  TABLESPACE "NVCLLOBTS" ENABLE STORAGE IN ROW CHUNK 8192
  NOCACHE LOGGING  NOCOMPRESS  KEEP_DUPLICATES 
  STORAGE(INITIAL 106496 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0  BUFFER_POOL DEFAULT)) 
 LOB ("LIB_WVL") STORE AS SECUREFILE (
  TABLESPACE "NVCLLOBTS" ENABLE STORAGE IN ROW CHUNK 8192
  NOCACHE LOGGING  NOCOMPRESS  KEEP_DUPLICATES 
  STORAGE(INITIAL 106496 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0  BUFFER_POOL DEFAULT)) ;

   COMMENT ON COLUMN "NVCL"."DATASETSTATS"."DATASETSTATS_ID" IS 'TSG statsfile UUID';
   COMMENT ON COLUMN "NVCL"."DATASETSTATS"."VALIDBITMASK" IS 'TSG bitmask showing valid components';
   COMMENT ON COLUMN "NVCL"."DATASETSTATS"."STATSTYPE" IS 'statistics type 0= covariance PCs, 1=correlation PCs, 2=MNF';
   COMMENT ON COLUMN "NVCL"."DATASETSTATS"."SAMPLES" IS 'number of samples that contributed to the statistics';
   COMMENT ON COLUMN "NVCL"."DATASETSTATS"."LIBCHANNELS" IS 'number of channels in the original dataset before spectral subsetting or resampling';
   COMMENT ON COLUMN "NVCL"."DATASETSTATS"."CHANNELS" IS 'number of active channels used to calculate statistics';
   COMMENT ON COLUMN "NVCL"."DATASETSTATS"."WSUB" IS 'spectral subsetting/resampling method 0=none, 1=resampling,2=subsetting';
   COMMENT ON COLUMN "NVCL"."DATASETSTATS"."WUFLAGS" IS 'XSPECIO wavelength unit flags and thermal flag';
   COMMENT ON COLUMN "NVCL"."DATASETSTATS"."LCWHICH" IS 'option bitmask in layer calc spec';
   COMMENT ON COLUMN "NVCL"."DATASETSTATS"."LCPRENORM" IS 'option in layer calc spec';
   COMMENT ON COLUMN "NVCL"."DATASETSTATS"."LCBKREM" IS 'option in layer calc spec';
   COMMENT ON COLUMN "NVCL"."DATASETSTATS"."LCPOSTNORM" IS 'option in layer calc spec';
   COMMENT ON COLUMN "NVCL"."DATASETSTATS"."LCSGLEFT" IS 'option in layer calc spec';
   COMMENT ON COLUMN "NVCL"."DATASETSTATS"."LCSGRIGHT" IS 'option in layer calc spec';
   COMMENT ON COLUMN "NVCL"."DATASETSTATS"."LCSGPOLY" IS 'option in layer calc spec';
   COMMENT ON COLUMN "NVCL"."DATASETSTATS"."LCSGDERIV" IS 'option in layer calc spec';
   COMMENT ON COLUMN "NVCL"."DATASETSTATS"."RESAMPLINGALGORITHM" IS 'Spectral resampling algorithm: 0=no resampling; 1=linear; 2=spline; 3=bandpass convol ';
   COMMENT ON COLUMN "NVCL"."DATASETSTATS"."RESWMIN" IS 'Minimum wavelength for spectral resampling ';
   COMMENT ON COLUMN "NVCL"."DATASETSTATS"."RESWMAX" IS 'Maximum wavelength for spectral resampling';
   COMMENT ON COLUMN "NVCL"."DATASETSTATS"."RESWINC" IS 'Wavelength increment for spectral resampling';
   COMMENT ON COLUMN "NVCL"."DATASETSTATS"."WMIN" IS 'Bottom of stats'' spectral coverage';
   COMMENT ON COLUMN "NVCL"."DATASETSTATS"."WMAX" IS 'Top of stats'' spectral coverage';
   COMMENT ON COLUMN "NVCL"."DATASETSTATS"."WTOL" IS 'A tolerance to be used in wavelength matching';
   COMMENT ON COLUMN "NVCL"."DATASETSTATS"."LIBRARYDATASET_ID" IS 'identifier of dataset these stats we created from';
   COMMENT ON COLUMN "NVCL"."DATASETSTATS"."MASKLOG_ID" IS 'log identifier of the mask used for spatial subsetting';
   COMMENT ON COLUMN "NVCL"."DATASETSTATS"."USERCOMMENTS" IS 'User comments';
   COMMENT ON COLUMN "NVCL"."DATASETSTATS"."WVL" IS 'Channel wavelengths that apply to the stats ';
   COMMENT ON COLUMN "NVCL"."DATASETSTATS"."CHMAX" IS 'Spectrum of channel maxima ';
   COMMENT ON COLUMN "NVCL"."DATASETSTATS"."CHMIN" IS 'Spectrum of channel minima';
   COMMENT ON COLUMN "NVCL"."DATASETSTATS"."MEAN" IS 'Spectrum of channel means';
   COMMENT ON COLUMN "NVCL"."DATASETSTATS"."SDEV" IS 'Spectrum of channel standard deviations';
   COMMENT ON COLUMN "NVCL"."DATASETSTATS"."COVAR" IS 'Signal covariance matrix';
   COMMENT ON COLUMN "NVCL"."DATASETSTATS"."CORREL" IS 'Signal correlation matrix';
   COMMENT ON COLUMN "NVCL"."DATASETSTATS"."NOISECV" IS 'Second (e.g., noise) covariance matrix';
   COMMENT ON COLUMN "NVCL"."DATASETSTATS"."EVAL" IS 'Eigenvalues';
   COMMENT ON COLUMN "NVCL"."DATASETSTATS"."FTRANS" IS 'Forward transformation matrix, each vector contiguous in memory';
   COMMENT ON COLUMN "NVCL"."DATASETSTATS"."RTRANS" IS 'Reverse transformation matrix, each vector contiguous in memory';
   COMMENT ON COLUMN "NVCL"."DATASETSTATS"."LIB_WVL" IS 'library wavelengths';
   COMMENT ON TABLE "NVCL"."DATASETSTATS"  IS 'This table stores spectral statistics gathered from reflectance spectral logs.';
  GRANT SELECT ON "NVCL"."DATASETSTATS" TO "NVCLVIEWER";
  GRANT SELECT ON "NVCL"."DATASETSTATS" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Table DECIMALLOGDATA
--------------------------------------------------------

  CREATE TABLE "NVCL"."DECIMALLOGDATA" 
   (	"LOG_ID" VARCHAR2(64), 
	"SAMPLENUMBER" NUMBER(10,0), 
	"DECIMALVALUE" FLOAT(126)
   )   PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255  NOCOMPRESS LOGGING 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLTBLSPC" ;

   COMMENT ON COLUMN "NVCL"."DECIMALLOGDATA"."LOG_ID" IS 'log identifier, identifies the log to which this data belongs';
   COMMENT ON COLUMN "NVCL"."DECIMALLOGDATA"."SAMPLENUMBER" IS 'Sample number used to map onto the spatial sampling domain';
   COMMENT ON COLUMN "NVCL"."DECIMALLOGDATA"."DECIMALVALUE" IS 'Decimal type data';
   COMMENT ON TABLE "NVCL"."DECIMALLOGDATA"  IS 'This table contains the data for decimal type logs.';
  GRANT SELECT ON "NVCL"."DECIMALLOGDATA" TO "WEBSERVICE";
  GRANT SELECT ON "NVCL"."DECIMALLOGDATA" TO "NVCLVIEWER";
  GRANT SELECT ON "NVCL"."DECIMALLOGDATA" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Table DECIMALLOGS
--------------------------------------------------------

  CREATE TABLE "NVCL"."DECIMALLOGS" 
   (	"LOG_ID" VARCHAR2(64), 
	"SCALARGROUP_ID" NUMBER(10,0), 
	"MINTHRESHOLD" FLOAT(126), 
	"MAXTHRESHOLD" FLOAT(126), 
	"RESULTISRGBCOLOUR" NUMBER(1,0)
   )   PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255  NOCOMPRESS LOGGING 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLTBLSPC" ;

   COMMENT ON COLUMN "NVCL"."DECIMALLOGS"."LOG_ID" IS 'log identifier, references the logs table';
   COMMENT ON COLUMN "NVCL"."DECIMALLOGS"."SCALARGROUP_ID" IS 'scalar group the user assigned this log to';
   COMMENT ON COLUMN "NVCL"."DECIMALLOGS"."MINTHRESHOLD" IS 'Miinimum threshold of values';
   COMMENT ON COLUMN "NVCL"."DECIMALLOGS"."MAXTHRESHOLD" IS 'Maximum threshold of values';
   COMMENT ON COLUMN "NVCL"."DECIMALLOGS"."RESULTISRGBCOLOUR" IS 'Boolean indicating that the result of this log is a RGB colour';
   COMMENT ON TABLE "NVCL"."DECIMALLOGS"  IS 'This table contains decimal log information.  This type of log is usually a calculated value stored at each point within the log.';
  GRANT SELECT ON "NVCL"."DECIMALLOGS" TO "NVCLVIEWER";
  GRANT SELECT ON "NVCL"."DECIMALLOGS" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Table DOMAINLOGDATA
--------------------------------------------------------

  CREATE TABLE "NVCL"."DOMAINLOGDATA" 
   (	"LOG_ID" VARCHAR2(64), 
	"SAMPLENUMBER" NUMBER(10,0), 
	"STARTVALUE" FLOAT(126), 
	"ENDVALUE" FLOAT(126), 
	"SAMPLENAME" VARCHAR2(4000), 
	"DESCRIPTION" VARCHAR2(4000), 
	"COLOUR" NUMBER(10,0), 
	"SWIRMINLIST" BLOB, 
	"SWIRTSAVERSION" NUMBER(10,0), 
	"VNIRMINLIST" BLOB, 
	"VNIRTSAVERSION" NUMBER(10,0), 
	"TIRMINLIST" BLOB, 
	"TIRTSAVERSION" NUMBER(10,0), 
	"AMINLIST" BLOB, 
	"ATSAVERSION" NUMBER(10,0) DEFAULT 0, 
	"BMINLIST" BLOB, 
	"BTSAVERSION" NUMBER(10,0) DEFAULT 0
   )   PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255  NOCOMPRESS LOGGING 
  STORAGE(INITIAL 131072 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLTBLSPC" 
 LOB ("SWIRMINLIST") STORE AS BASICFILE (
  TABLESPACE "NVCLTBLSPC" ENABLE STORAGE IN ROW CHUNK 8192 RETENTION 
  NOCACHE LOGGING 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)) 
 LOB ("VNIRMINLIST") STORE AS BASICFILE (
  TABLESPACE "NVCLTBLSPC" ENABLE STORAGE IN ROW CHUNK 8192 RETENTION 
  NOCACHE LOGGING 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)) 
 LOB ("TIRMINLIST") STORE AS BASICFILE (
  TABLESPACE "NVCLTBLSPC" ENABLE STORAGE IN ROW CHUNK 8192 RETENTION 
  NOCACHE LOGGING 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)) 
 LOB ("AMINLIST") STORE AS BASICFILE (
  TABLESPACE "NVCLTBLSPC" ENABLE STORAGE IN ROW CHUNK 8192 RETENTION 
  NOCACHE LOGGING 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)) 
 LOB ("BMINLIST") STORE AS BASICFILE (
  TABLESPACE "NVCLTBLSPC" ENABLE STORAGE IN ROW CHUNK 8192 RETENTION 
  NOCACHE LOGGING 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)) ;

   COMMENT ON COLUMN "NVCL"."DOMAINLOGDATA"."LOG_ID" IS 'log identifier, references logs table';
   COMMENT ON COLUMN "NVCL"."DOMAINLOGDATA"."SAMPLENUMBER" IS 'Sample number';
   COMMENT ON COLUMN "NVCL"."DOMAINLOGDATA"."STARTVALUE" IS 'Start depth at this sample number';
   COMMENT ON COLUMN "NVCL"."DOMAINLOGDATA"."ENDVALUE" IS 'End depth at this sample number';
   COMMENT ON COLUMN "NVCL"."DOMAINLOGDATA"."SAMPLENAME" IS 'Name of this sample.  Usually only used for reference libraries.';
   COMMENT ON TABLE "NVCL"."DOMAINLOGDATA"  IS 'This table contains spatial domain log data.  Each record consists of a sample number and a depth down hole start and end point.';
  GRANT SELECT ON "NVCL"."DOMAINLOGDATA" TO "WEBSERVICE";
  GRANT SELECT ON "NVCL"."DOMAINLOGDATA" TO "NVCLVIEWER";
  GRANT SELECT ON "NVCL"."DOMAINLOGDATA" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Table DOMAINLOGS
--------------------------------------------------------

  CREATE TABLE "NVCL"."DOMAINLOGS" 
   (	"LOG_ID" VARCHAR2(64), 
	"UNITS" VARCHAR2(4000), 
	"ISSUBDOMAINOFLOG_ID" VARCHAR2(64), 
	"SCALARGROUP_ID" NUMBER(10,0)
   )   PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255  NOCOMPRESS LOGGING 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLTBLSPC" ;

   COMMENT ON COLUMN "NVCL"."DOMAINLOGS"."LOG_ID" IS 'log identifier, references logs table';
   COMMENT ON COLUMN "NVCL"."DOMAINLOGS"."UNITS" IS 'depth down hole units, usually metres';
   COMMENT ON COLUMN "NVCL"."DOMAINLOGS"."ISSUBDOMAINOFLOG_ID" IS 'Define this domain relative to another';
   COMMENT ON COLUMN "NVCL"."DOMAINLOGS"."SCALARGROUP_ID" IS 'scalar group the user assigned this domain log to.';
   COMMENT ON TABLE "NVCL"."DOMAINLOGS"  IS 'This table contains spatial domain information.  All logs will be defined on a spatial sampling domain relative to depth down hole.';
  GRANT SELECT ON "NVCL"."DOMAINLOGS" TO "NVCLVIEWER";
  GRANT SELECT ON "NVCL"."DOMAINLOGS" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Table EVENTJOURNAL
--------------------------------------------------------

  CREATE TABLE "NVCL"."EVENTJOURNAL" 
   (	"DATASET_ID" VARCHAR2(64), 
	"EVENTNUMBER" NUMBER(10,0), 
	"CATNO" NUMBER(10,0), 
	"ISPRIMARY" NUMBER(1,0), 
	"EVENTTIME" DATE, 
	"TSGPRODUCT" VARCHAR2(100), 
	"TSGUSER" VARCHAR2(4000), 
	"CONTENT" VARCHAR2(4000)
   ) SEGMENT CREATION DEFERRED 
  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255  NOCOMPRESS LOGGING 
  TABLESPACE "NVCLTBLSPC" ;
  GRANT SELECT ON "NVCL"."EVENTJOURNAL" TO "NVCLVIEWER";
  GRANT SELECT ON "NVCL"."EVENTJOURNAL" TO "NVCLANALYST";
  GRANT DELETE ON "NVCL"."EVENTJOURNAL" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Table IMAGELOGDATA
--------------------------------------------------------

  CREATE TABLE "NVCL"."IMAGELOGDATA" 
   (	"LOG_ID" VARCHAR2(64), 
	"SAMPLENUMBER" NUMBER(10,0), 
	"IMAGEDATA" BLOB, 
	"IMAGECOMMENT" VARCHAR2(4000)
   )   PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255  NOCOMPRESS LOGGING 
  STORAGE(INITIAL 131072 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLTBLSPC" 
 LOB ("IMAGEDATA") STORE AS SECUREFILE (
  TABLESPACE "NVCLLOBTS" ENABLE STORAGE IN ROW CHUNK 8192
  NOCACHE LOGGING  NOCOMPRESS  KEEP_DUPLICATES 
  STORAGE(INITIAL 106496 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0  BUFFER_POOL DEFAULT)) ;

   COMMENT ON COLUMN "NVCL"."IMAGELOGDATA"."LOG_ID" IS 'log identifier, indicating which log this data belongs to';
   COMMENT ON COLUMN "NVCL"."IMAGELOGDATA"."SAMPLENUMBER" IS 'sample number maps to the spatial sampling domain to give a depth down-hole';
   COMMENT ON COLUMN "NVCL"."IMAGELOGDATA"."IMAGEDATA" IS 'Image data blob usually jpeg compressed';
   COMMENT ON COLUMN "NVCL"."IMAGELOGDATA"."IMAGECOMMENT" IS 'User comments made about this image';
   COMMENT ON TABLE "NVCL"."IMAGELOGDATA"  IS 'This table contains the data for image type logs.  ';
  GRANT SELECT ON "NVCL"."IMAGELOGDATA" TO "NVCLVIEWER";
  GRANT SELECT ON "NVCL"."IMAGELOGDATA" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Table IMAGELOGS
--------------------------------------------------------

  CREATE TABLE "NVCL"."IMAGELOGS" 
   (	"LOG_ID" VARCHAR2(64), 
	"IMGHISTOGRAM" BLOB, 
	"IMGCLIPPERCENT" NUMBER(38,0), 
	"LOGTIMESTAMP" TIMESTAMP (0) WITH TIME ZONE, 
	"IMGWIDTH" NUMBER(10,0), 
	"IMGHEIGHT" NUMBER(10,0)
   )   PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255  NOCOMPRESS LOGGING 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLTBLSPC" 
 LOB ("IMGHISTOGRAM") STORE AS SECUREFILE (
  TABLESPACE "NVCLLOBTS" ENABLE STORAGE IN ROW CHUNK 8192
  NOCACHE LOGGING  NOCOMPRESS  KEEP_DUPLICATES 
  STORAGE(INITIAL 106496 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0  BUFFER_POOL DEFAULT)) ;

   COMMENT ON COLUMN "NVCL"."IMAGELOGS"."LOG_ID" IS 'log identifier, image logs are a specialisation of logs and share a unique identifier.';
   COMMENT ON COLUMN "NVCL"."IMAGELOGS"."IMGHISTOGRAM" IS 'RGB histogram of the colours present in the entire image log';
   COMMENT ON COLUMN "NVCL"."IMAGELOGS"."IMGCLIPPERCENT" IS 'Percentage top and bottom of the histogram removed for automatic image adjustments.';
   COMMENT ON COLUMN "NVCL"."IMAGELOGS"."LOGTIMESTAMP" IS 'Timestamp taken when imagery was logged';
   COMMENT ON COLUMN "NVCL"."IMAGELOGS"."IMGWIDTH" IS 'Default image width used in TSG for image logs with consistently sized images forming 1 long log';
   COMMENT ON COLUMN "NVCL"."IMAGELOGS"."IMGHEIGHT" IS 'Default image height used in TSG for image logs with consistently sized images forming 1 long log';
   COMMENT ON TABLE "NVCL"."IMAGELOGS"  IS 'This table contains information about logs of imagery.  Which usually form continuous images down the length of the drillhole.';
  GRANT SELECT ON "NVCL"."IMAGELOGS" TO "NVCLVIEWER";
  GRANT SELECT ON "NVCL"."IMAGELOGS" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Table LAYOUTS
--------------------------------------------------------

  CREATE TABLE "NVCL"."LAYOUTS" 
   (	"DATASET_ID" VARCHAR2(64), 
	"LAYOUTNO" NUMBER(10,0), 
	"LAYOUTDATA" CLOB, 
	"LAYOUTNAME" VARCHAR2(4000)
   )   PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255  NOCOMPRESS LOGGING 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLTBLSPC" 
 LOB ("LAYOUTDATA") STORE AS BASICFILE (
  TABLESPACE "NVCLTBLSPC" ENABLE STORAGE IN ROW CHUNK 8192 RETENTION 
  NOCACHE LOGGING 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)) ;
  GRANT SELECT ON "NVCL"."LAYOUTS" TO "NVCLVIEWER";
  GRANT SELECT ON "NVCL"."LAYOUTS" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Table LOGDEPENDENCIES
--------------------------------------------------------

  CREATE TABLE "NVCL"."LOGDEPENDENCIES" 
   (	"LOG_ID" VARCHAR2(64), 
	"DEPENDSON" VARCHAR2(64), 
	"RELATIONNAME" VARCHAR2(4000), 
	"PRIORITYORDER" NUMBER(10,0)
   )   PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255  NOCOMPRESS LOGGING 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLTBLSPC" ;

   COMMENT ON COLUMN "NVCL"."LOGDEPENDENCIES"."LOG_ID" IS 'log identifier of the dependent log';
   COMMENT ON COLUMN "NVCL"."LOGDEPENDENCIES"."DEPENDSON" IS 'Log identifier or the log the dependent depends on';
   COMMENT ON COLUMN "NVCL"."LOGDEPENDENCIES"."RELATIONNAME" IS 'Name assigned to this dependency relationship';
   COMMENT ON COLUMN "NVCL"."LOGDEPENDENCIES"."PRIORITYORDER" IS 'dependency priority order';
   COMMENT ON TABLE "NVCL"."LOGDEPENDENCIES"  IS 'This table records which logs are functionaly dependant on other logs.  Because a log may depend on more than 1 other log and a log may have more than 1 log depending on it this table is used to provided a many-to-many relationship.';
  GRANT SELECT ON "NVCL"."LOGDEPENDENCIES" TO "NVCLVIEWER";
  GRANT SELECT ON "NVCL"."LOGDEPENDENCIES" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Table LOGS
--------------------------------------------------------

  CREATE TABLE "NVCL"."LOGS" 
   (	"LOG_ID" VARCHAR2(64), 
	"LOGNAME" VARCHAR2(4000), 
	"CREATORUSERNAME" VARCHAR2(4000), 
	"MODIFIEDDATE" TIMESTAMP (0) WITH TIME ZONE, 
	"DATASET_ID" VARCHAR2(64), 
	"DOMAINLOG_ID" VARCHAR2(64), 
	"LOGTYPE" NUMBER(10,0), 
	"CREATEDDATE" TIMESTAMP (0) WITH TIME ZONE, 
	"DESCRIPTION" VARCHAR2(4000), 
	"ISPUBLIC" NUMBER(1,0), 
	"MODIFIERUSERNAME" VARCHAR2(4000), 
	"ALGORITHMOUTPUT_ID" NUMBER, 
	"MASKLOG_ID" VARCHAR2(64), 
	"REFSTATS_ID" VARCHAR2(64), 
	"TSARETRAINING_ID" VARCHAR2(64), 
	"TSGHANDMASK" NUMBER(10,0), 
	"CUSTOMSCRIPT" CLOB, 
	"BATCHSCRIPT" CLOB, 
	"MIXNUMBER" NUMBER(2,0), 
	"AUXSPECTRALLAYER_ID" VARCHAR2(64), 
	"LOCALSPECTRALLAYER_ID" VARCHAR2(64), 
	"PLS_ID" VARCHAR2(64)
   )   PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255  NOCOMPRESS LOGGING 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLTBLSPC" 
 LOB ("CUSTOMSCRIPT") STORE AS SECUREFILE (
  TABLESPACE "NVCLLOBTS" ENABLE STORAGE IN ROW CHUNK 8192
  NOCACHE LOGGING  NOCOMPRESS  KEEP_DUPLICATES 
  STORAGE(INITIAL 106496 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0  BUFFER_POOL DEFAULT)) 
 LOB ("BATCHSCRIPT") STORE AS SECUREFILE (
  TABLESPACE "NVCLLOBTS" ENABLE STORAGE IN ROW CHUNK 8192
  NOCACHE LOGGING  NOCOMPRESS  KEEP_DUPLICATES 
  STORAGE(INITIAL 106496 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0  BUFFER_POOL DEFAULT)) ;

   COMMENT ON COLUMN "NVCL"."LOGS"."LOG_ID" IS 'log identifier, integer sequence';
   COMMENT ON COLUMN "NVCL"."LOGS"."LOGNAME" IS 'Log name';
   COMMENT ON COLUMN "NVCL"."LOGS"."CREATORUSERNAME" IS 'Log creator''s user name';
   COMMENT ON COLUMN "NVCL"."LOGS"."MODIFIEDDATE" IS 'timestamp when log was last changed';
   COMMENT ON COLUMN "NVCL"."LOGS"."DATASET_ID" IS 'Dataset identifier that this log is a part of';
   COMMENT ON COLUMN "NVCL"."LOGS"."DOMAINLOG_ID" IS 'Log identifier of the spatial sampling domain log that this log is defined over';
   COMMENT ON COLUMN "NVCL"."LOGS"."LOGTYPE" IS 'log types : 0=domain 1=class 2=decimal 3=image 4=profilometer 5=spectral 6=mask';
   COMMENT ON COLUMN "NVCL"."LOGS"."CREATEDDATE" IS 'Timestamp when log was created';
   COMMENT ON COLUMN "NVCL"."LOGS"."DESCRIPTION" IS 'Text description of this log ';
   COMMENT ON COLUMN "NVCL"."LOGS"."ISPUBLIC" IS 'Boolean indicating if this log is public ';
   COMMENT ON COLUMN "NVCL"."LOGS"."MODIFIERUSERNAME" IS 'Username of the last person to modify this log';
   COMMENT ON COLUMN "NVCL"."LOGS"."ALGORITHMOUTPUT_ID" IS 'Algorithm output identifier of the standard algorithm used to generate this log';
   COMMENT ON COLUMN "NVCL"."LOGS"."REFSTATS_ID" IS 'identifier of statistics item used to generate this log';
   COMMENT ON COLUMN "NVCL"."LOGS"."TSARETRAINING_ID" IS 'identifier of TSA retraining settings';
   COMMENT ON COLUMN "NVCL"."LOGS"."TSGHANDMASK" IS 'TSG bit mask of log type';
   COMMENT ON COLUMN "NVCL"."LOGS"."BATCHSCRIPT" IS 'for storage of batch processing scripts used to generate logs';
   COMMENT ON COLUMN "NVCL"."LOGS"."MIXNUMBER" IS 'mixture number for calculated scalars';
   COMMENT ON COLUMN "NVCL"."LOGS"."AUXSPECTRALLAYER_ID" IS 'aux spectral layer for aux match calulations';
   COMMENT ON COLUMN "NVCL"."LOGS"."LOCALSPECTRALLAYER_ID" IS 'local spectral layer for aux match calculations';
   COMMENT ON TABLE "NVCL"."LOGS"  IS 'This table contains information about the various types of log stored in the database.';
  GRANT SELECT ON "NVCL"."LOGS" TO "NVCLVIEWER";
  GRANT SELECT ON "NVCL"."LOGS" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Table LOGTYPES
--------------------------------------------------------

  CREATE TABLE "NVCL"."LOGTYPES" 
   (	"LOGTYPE_ID" NUMBER(10,0), 
	"LOGTYPENAME" VARCHAR2(20)
   )   PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255  NOCOMPRESS LOGGING 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLTBLSPC" ;
  GRANT SELECT ON "NVCL"."LOGTYPES" TO "NVCLVIEWER";
  GRANT SELECT ON "NVCL"."LOGTYPES" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Table MACHINES
--------------------------------------------------------

  CREATE TABLE "NVCL"."MACHINES" 
   (	"MACHINE_ID" NUMBER(10,0), 
	"MACHINENAME" VARCHAR2(4000), 
	"NAMESPACEID" VARCHAR2(4000)
   )   PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255  NOCOMPRESS LOGGING 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLTBLSPC" ;

   COMMENT ON COLUMN "NVCL"."MACHINES"."MACHINE_ID" IS 'machine identifier, integer sequence';
   COMMENT ON COLUMN "NVCL"."MACHINES"."MACHINENAME" IS 'Machine name';
   COMMENT ON TABLE "NVCL"."MACHINES"  IS 'This table contains information about the machines used to log data.';
  GRANT SELECT ON "NVCL"."MACHINES" TO "NVCLVIEWER";
  GRANT SELECT ON "NVCL"."MACHINES" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Table MASKLOGDATA
--------------------------------------------------------

  CREATE TABLE "NVCL"."MASKLOGDATA" 
   (	"LOG_ID" VARCHAR2(64), 
	"SAMPLENUMBER" NUMBER(10,0), 
	"MASKVALUE" NUMBER(1,0)
   )   PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255  NOCOMPRESS LOGGING 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLTBLSPC" ;
  GRANT SELECT ON "NVCL"."MASKLOGDATA" TO "NVCLVIEWER";
  GRANT SELECT ON "NVCL"."MASKLOGDATA" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Table MASKLOGS
--------------------------------------------------------

  CREATE TABLE "NVCL"."MASKLOGS" 
   (	"LOG_ID" VARCHAR2(64), 
	"SCALARGROUP_ID" NUMBER(10,0)
   )   PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255  NOCOMPRESS LOGGING 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLTBLSPC" ;

   COMMENT ON COLUMN "NVCL"."MASKLOGS"."LOG_ID" IS 'Log identifier, masklogs are specialisations of logs and share a unique identifier';
   COMMENT ON COLUMN "NVCL"."MASKLOGS"."SCALARGROUP_ID" IS 'Scalar group identifier, users can assign logs to particular groups to make them more manageable';
   COMMENT ON TABLE "NVCL"."MASKLOGS"  IS 'This table contains information about mask type logs. A mask type log is a log of values 1 or 0 used to mask other results.';
  GRANT SELECT ON "NVCL"."MASKLOGS" TO "NVCLVIEWER";
  GRANT SELECT ON "NVCL"."MASKLOGS" TO "NVCLANALYST";

--------------------------------------------------------
--  DDL for Table PLSDATA
--------------------------------------------------------

  CREATE TABLE "NVCL"."PLSDATA" 
   (	"PLS_ID" VARCHAR2(64), 
	"DATASET_ID" VARCHAR2(64), 
	"PLSNAME" VARCHAR2(4000), 
	"PLSDATA" BLOB
   )   PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255  NOCOMPRESS LOGGING 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLTBLSPC" 
 LOB ("PLSDATA") STORE AS SECUREFILE (
  TABLESPACE "NVCLLOBTS" ENABLE STORAGE IN ROW CHUNK 8192
  NOCACHE LOGGING  NOCOMPRESS  KEEP_DUPLICATES 
  STORAGE(INITIAL 106496 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0  BUFFER_POOL DEFAULT)) ;
  GRANT SELECT ON "NVCL"."PLSDATA" TO "NVCLVIEWER";
  GRANT SELECT ON "NVCL"."PLSDATA" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Table PROFLOGDATA
--------------------------------------------------------

  CREATE TABLE "NVCL"."PROFLOGDATA" 
   (	"LOG_ID" VARCHAR2(64), 
	"SAMPLENUMBER" NUMBER(10,0), 
	"PROFILOMETERVALUES" BLOB
   )   PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255  NOCOMPRESS LOGGING 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLTBLSPC" 
 LOB ("PROFILOMETERVALUES") STORE AS SECUREFILE (
  TABLESPACE "NVCLLOBTS" ENABLE STORAGE IN ROW CHUNK 8192
  NOCACHE LOGGING  NOCOMPRESS  KEEP_DUPLICATES 
  STORAGE(INITIAL 106496 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0  BUFFER_POOL DEFAULT)) ;

   COMMENT ON COLUMN "NVCL"."PROFLOGDATA"."LOG_ID" IS 'Log identifier of the log this data belongs to';
   COMMENT ON COLUMN "NVCL"."PROFLOGDATA"."SAMPLENUMBER" IS 'Sample number used to map to spatial sampling domain';
   COMMENT ON COLUMN "NVCL"."PROFLOGDATA"."PROFILOMETERVALUES" IS 'Array of floating point numbers representing the relative height, taken at each sampling point, stored as a BLOB.';
   COMMENT ON TABLE "NVCL"."PROFLOGDATA"  IS 'This table contains the data for profilometer type logs.  This data is recorded as an array of floating point numbers stored as a BLOB at each sampling point.';
  GRANT SELECT ON "NVCL"."PROFLOGDATA" TO "NVCLVIEWER";
  GRANT SELECT ON "NVCL"."PROFLOGDATA" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Table PROFLOGS
--------------------------------------------------------

  CREATE TABLE "NVCL"."PROFLOGS" 
   (	"LOG_ID" VARCHAR2(64), 
	"LOGTIMESTAMP" TIMESTAMP (0) WITH TIME ZONE, 
	"FLOATSPERSAMPLE" NUMBER(10,0), 
	"MINVAL" FLOAT(126), 
	"MAXVAL" FLOAT(126)
   )   PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255  NOCOMPRESS LOGGING 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLTBLSPC" ;

   COMMENT ON COLUMN "NVCL"."PROFLOGS"."LOG_ID" IS 'Log identifier, as a specialisation of logs a proflogs row shares a unique identifier with the logs table';
   COMMENT ON COLUMN "NVCL"."PROFLOGS"."LOGTIMESTAMP" IS 'Timestamp when the log was taken';
   COMMENT ON COLUMN "NVCL"."PROFLOGS"."MINVAL" IS 'minimum floating point value in log';
   COMMENT ON COLUMN "NVCL"."PROFLOGS"."MAXVAL" IS 'maximum floating point value in log';
   COMMENT ON TABLE "NVCL"."PROFLOGS"  IS 'This table contains information about logs of the profile of the core above the tray surface.  It is used to automatical check for the absence of, cracks in and shape of core under the logging instruments.';
  GRANT SELECT ON "NVCL"."PROFLOGS" TO "NVCLVIEWER";
  GRANT SELECT ON "NVCL"."PROFLOGS" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Table SCALARGROUPS
--------------------------------------------------------

  CREATE TABLE "NVCL"."SCALARGROUPS" 
   (	"SCALARGROUP_ID" NUMBER(10,0), 
	"SCALARGROUPNAME" VARCHAR2(4000), 
	"DESCRIPTION" VARCHAR2(4000), 
	"PARENTSCALARGROUP_ID" NUMBER(10,0)
   )   PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255  NOCOMPRESS LOGGING 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLTBLSPC" ;

   COMMENT ON COLUMN "NVCL"."SCALARGROUPS"."SCALARGROUP_ID" IS 'scalargroup identifier, integer sequence';
   COMMENT ON COLUMN "NVCL"."SCALARGROUPS"."SCALARGROUPNAME" IS 'Name given to scalargroup';
   COMMENT ON COLUMN "NVCL"."SCALARGROUPS"."DESCRIPTION" IS 'Text description of this group including intended outcomes.';
   COMMENT ON COLUMN "NVCL"."SCALARGROUPS"."PARENTSCALARGROUP_ID" IS 'Scalargroup identifier of this group?s parent group.  This allows a hierarchy of groups';
   COMMENT ON TABLE "NVCL"."SCALARGROUPS"  IS 'This table contains analyst defined log/scalar groups.  When a log/scalar is created it can be assigned to a particular group or it will go into a special group of uncategorised logs/scalars.';
  GRANT SELECT ON "NVCL"."SCALARGROUPS" TO "NVCLVIEWER";
  GRANT UPDATE ON "NVCL"."SCALARGROUPS" TO "NVCLANALYST";
  GRANT SELECT ON "NVCL"."SCALARGROUPS" TO "NVCLANALYST";
  GRANT INSERT ON "NVCL"."SCALARGROUPS" TO "NVCLANALYST";
  GRANT DELETE ON "NVCL"."SCALARGROUPS" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Table SCALARSETS
--------------------------------------------------------

  CREATE TABLE "NVCL"."SCALARSETS" 
   (	"DATASET_ID" VARCHAR2(64), 
	"SETNUMBER" NUMBER(2,0), 
	"SETNAME" VARCHAR2(20), 
	"SETTYPE" NUMBER(2,0)
   )   PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255  NOCOMPRESS LOGGING 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLTBLSPC" ;
  GRANT SELECT ON "NVCL"."SCALARSETS" TO "NVCLVIEWER";
  GRANT SELECT ON "NVCL"."SCALARSETS" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Table SPECTRALLOGDATA
--------------------------------------------------------

  CREATE TABLE "NVCL"."SPECTRALLOGDATA" 
   (	"LOG_ID" VARCHAR2(64), 
	"SAMPLENUMBER" NUMBER(10,0), 
	"SPECTRALVALUES" BLOB
   )   PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255  NOCOMPRESS LOGGING 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLTBLSPC" 
 LOB ("SPECTRALVALUES") STORE AS SECUREFILE (
  TABLESPACE "NVCLLOBTS" ENABLE STORAGE IN ROW CHUNK 8192
  NOCACHE LOGGING  NOCOMPRESS  KEEP_DUPLICATES 
  STORAGE(INITIAL 106496 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0  BUFFER_POOL DEFAULT)) ;

   COMMENT ON COLUMN "NVCL"."SPECTRALLOGDATA"."LOG_ID" IS 'Log identifier of the log this data belongs to';
   COMMENT ON COLUMN "NVCL"."SPECTRALLOGDATA"."SAMPLENUMBER" IS 'Sample number used to map to the spatial sampling domain';
   COMMENT ON COLUMN "NVCL"."SPECTRALLOGDATA"."SPECTRALVALUES" IS 'Array of floating point numbers containing the spectrum.';
   COMMENT ON TABLE "NVCL"."SPECTRALLOGDATA"  IS 'This table contains data from spectral logs.  Each spectrum is an array of floating point numbers stored as a BLOB.  One spectrum is stored at each sampling point.';
  GRANT SELECT ON "NVCL"."SPECTRALLOGDATA" TO "NVCLVIEWER";
  GRANT SELECT ON "NVCL"."SPECTRALLOGDATA" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Table SPECTRALLOGS
--------------------------------------------------------

  CREATE TABLE "NVCL"."SPECTRALLOGS" 
   (	"LOG_ID" VARCHAR2(64), 
	"SPECTRALSAMPLINGPOINTS" BLOB, 
	"FWHM" BLOB, 
	"SPECTRALUNITS" VARCHAR2(4000), 
	"LOGTIMESTAMP" TIMESTAMP (0) WITH TIME ZONE, 
	"LAYERORDER" NUMBER(10,0), 
	"TIRQ" BLOB
   )   PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255  NOCOMPRESS LOGGING 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLTBLSPC" 
 LOB ("SPECTRALSAMPLINGPOINTS") STORE AS SECUREFILE (
  TABLESPACE "NVCLLOBTS" ENABLE STORAGE IN ROW CHUNK 8192
  NOCACHE LOGGING  NOCOMPRESS  KEEP_DUPLICATES 
  STORAGE(INITIAL 106496 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0  BUFFER_POOL DEFAULT)) 
 LOB ("FWHM") STORE AS SECUREFILE (
  TABLESPACE "NVCLLOBTS" ENABLE STORAGE IN ROW CHUNK 8192
  NOCACHE LOGGING  NOCOMPRESS  KEEP_DUPLICATES 
  STORAGE(INITIAL 106496 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0  BUFFER_POOL DEFAULT)) 
 LOB ("TIRQ") STORE AS BASICFILE (
  TABLESPACE "NVCLTBLSPC" ENABLE STORAGE IN ROW CHUNK 8192 RETENTION 
  NOCACHE LOGGING 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)) ;

   COMMENT ON COLUMN "NVCL"."SPECTRALLOGS"."LOG_ID" IS 'Log identifier, spectral logs, as a specialisation of logs, share a unique identifier';
   COMMENT ON COLUMN "NVCL"."SPECTRALLOGS"."SPECTRALSAMPLINGPOINTS" IS 'The sampling points in the spectral domain for this log.  I.E. a list of wavelength/wave numbers where reflectance was measured.';
   COMMENT ON COLUMN "NVCL"."SPECTRALLOGS"."SPECTRALUNITS" IS 'Units in the spectral sampling domain.  Wavelengths / wave number.';
   COMMENT ON COLUMN "NVCL"."SPECTRALLOGS"."LOGTIMESTAMP" IS 'Timestamp when log was taken';
   COMMENT ON COLUMN "NVCL"."SPECTRALLOGS"."LAYERORDER" IS 'number representing the order spectral logs appear in TSG.  Lowest to highest is first to last.';
   COMMENT ON TABLE "NVCL"."SPECTRALLOGS"  IS 'This table contains information about spectral logs.  That is a log of EM reflectance spectra.';
  GRANT SELECT ON "NVCL"."SPECTRALLOGS" TO "NVCLVIEWER";
  GRANT SELECT ON "NVCL"."SPECTRALLOGS" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Table TSARETRAINING
--------------------------------------------------------

  CREATE TABLE "NVCL"."TSARETRAINING" 
   (	"TSARETRAINING_ID" VARCHAR2(64), 
	"NUMALLCLASSES" NUMBER, 
	"NUMTRAINCLASSES" NUMBER, 
	"TSAPARAMS" BLOB, 
	"MINMASK" BLOB, 
	"MIXMASK" BLOB, 
	"DBIX" NUMBER(3,0), 
	"TRAINSEL" NUMBER, 
	"SEVEN" NUMBER, 
	"ILLITE" NUMBER, 
	"DOMAINED" NUMBER, 
	"VERSION" NUMBER, 
	"PLUS" NUMBER(10,0) DEFAULT 0
   )   PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255  NOCOMPRESS LOGGING 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLTBLSPC" 
 LOB ("TSAPARAMS") STORE AS SECUREFILE (
  TABLESPACE "NVCLLOBTS" ENABLE STORAGE IN ROW CHUNK 8192
  NOCACHE LOGGING  NOCOMPRESS  KEEP_DUPLICATES 
  STORAGE(INITIAL 106496 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0  BUFFER_POOL DEFAULT)) 
 LOB ("MINMASK") STORE AS SECUREFILE (
  TABLESPACE "NVCLLOBTS" ENABLE STORAGE IN ROW CHUNK 8192
  NOCACHE LOGGING  NOCOMPRESS  KEEP_DUPLICATES 
  STORAGE(INITIAL 106496 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0  BUFFER_POOL DEFAULT)) 
 LOB ("MIXMASK") STORE AS SECUREFILE (
  TABLESPACE "NVCLLOBTS" ENABLE STORAGE IN ROW CHUNK 8192
  NOCACHE LOGGING  NOCOMPRESS  KEEP_DUPLICATES 
  STORAGE(INITIAL 106496 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0  BUFFER_POOL DEFAULT)) ;

   COMMENT ON COLUMN "NVCL"."TSARETRAINING"."TSARETRAINING_ID" IS 'tsa customisation identifier';
   COMMENT ON COLUMN "NVCL"."TSARETRAINING"."NUMALLCLASSES" IS 'number of unconsolidated, unsubsetted minerals in the training source data';
   COMMENT ON COLUMN "NVCL"."TSARETRAINING"."NUMTRAINCLASSES" IS 'number of unconsolidated, subsetted minerals trained on';
   COMMENT ON COLUMN "NVCL"."TSARETRAINING"."TSAPARAMS" IS '14 TSA double precision parameters';
   COMMENT ON COLUMN "NVCL"."TSARETRAINING"."MINMASK" IS 'shows which minerals were trained on';
   COMMENT ON COLUMN "NVCL"."TSARETRAINING"."MIXMASK" IS 'shows which minerals are allowed to mix together';
   COMMENT ON COLUMN "NVCL"."TSARETRAINING"."DBIX" IS 'TSG internal index';
  GRANT SELECT ON "NVCL"."TSARETRAINING" TO "NVCLVIEWER";
  GRANT SELECT ON "NVCL"."TSARETRAINING" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for View COMPOUNDMATERIAL
--------------------------------------------------------

  CREATE OR REPLACE FORCE VIEW "NVCL"."COMPOUNDMATERIAL" ("LOGINTERVALSCAL_ID", "LOGINTERVAL_ID", "STARTDEPTH", "ENDDEPTH", "VALCOUNT", "CLASSTEXT", "COLOUR") AS 
  SELECT 'constituentpart.'
    || LOG_ID
    || '.'
    || CAST(STARTDEPTH AS VARCHAR(64))
    || '-'
    || CAST(ENDDEPTH AS VARCHAR(64))
    || '#'
    || CLASSTEXT AS LOGINTERVALSCAL_ID,
    'om.observations.'
    || LOG_ID
    || '.'
    || CAST(STARTDEPTH AS VARCHAR(64))
    || '-'
    || CAST(ENDDEPTH AS VARCHAR(64)) AS LOGINTERVAL_ID,
    startdepth,
    enddepth,
    VALCOUNT,
    CLASSTEXT,
    COLOUR
  FROM MV_COMPOUNDMATERIAL;
  GRANT SELECT ON "NVCL"."COMPOUNDMATERIAL" TO "WEBSERVICE";
--------------------------------------------------------
--  DDL for View DATASETDETAILSVIEW
--------------------------------------------------------

  CREATE OR REPLACE FORCE VIEW "NVCL"."DATASETDETAILSVIEW" ("Dataset_ID", "Dataset Name", "Drillhole Identifier", "Scanned Date", "Processed Date") AS 
  SELECT dataset_id,datasetname, holeidentifier, scandate, importdate from datasets;
--------------------------------------------------------
--  DDL for View DOMAINLOGDATAVIEW
--------------------------------------------------------

  CREATE OR REPLACE FORCE VIEW "NVCL"."DOMAINLOGDATAVIEW" ("LOG_ID", "SAMPLENUMBER", "STARTVALUE", "ENDVALUE", "SAMPLENAME") AS 
  SELECT subdom.log_id,subdom.samplenumber,coalesce(min(maindom.startvalue), min(subdom.startvalue)) as startvalue,coalesce(max(maindom.endvalue),max(subdom.endvalue)) as endvalue,subdom.samplename FROM domainlogdata subdom inner join domainlogs on subdom.log_id= domainlogs.log_id left outer join domainlogdata maindom on maindom.log_id=domainlogs.issubdomainoflog_id and maindom.samplenumber BETWEEN subdom.startvalue ANd subdom.endvalue Group BY subdom.log_id,subdom.samplenumber,subdom.samplename ORDER by subdom.log_id,subdom.samplenumber;
--------------------------------------------------------
--  DDL for View GETPUBLISHEDSYSTEMTSA
--------------------------------------------------------

  CREATE OR REPLACE FORCE VIEW "NVCL"."GETPUBLISHEDSYSTEMTSA" ("DATASET_ID", "SAMPLENUMBER", "STARTVALUE", "ENDVALUE", "SYSTEMTSASMINERAL1", "SYSTEMTSASMINERAL2", "SYSTEMTSASGROUP1", "SYSTEMTSASGROUP2", "SYSTEMTSASWEIGHT1", "SYSTEMTSASWEIGHT2", "SYSTEMTSAVMINERAL1", "SYSTEMTSAVMINERAL2", "SYSTEMTSAVGROUP1", "SYSTEMTSAVGROUP2", "SYSTEMTSAVWEIGHT1", "SYSTEMTSAVWEIGHT2") AS 
  SELECT publisheddatasets.dataset_id,
    domainlogdata.samplenumber,
    domainlogdata.startvalue,
    domainlogdata.endvalue,
    COALESCE(stsasmin1class.classtext,'NULL') SYSTEMTSASMINERAL1,
    COALESCE(stsasmin2class.classtext,'NULL') SYSTEMTSASMINERAL2,
    COALESCE(stsasgrp1class.classtext,'NULL') SYSTEMTSASGROUP1,
    COALESCE(stsasgrp2class.classtext,'NULL') SYSTEMTSASGROUP2,
    COALESCE(stsaswei1data.decimalvalue,0) SYSTEMTSASWEIGHT1,
    COALESCE(stsaswei2data.decimalvalue,0) SYSTEMTSASWEIGHT2,
    COALESCE(stsavmin1class.classtext,'NULL') SYSTEMTSAVMINERAL1,
    COALESCE(stsavmin2class.classtext,'NULL') SYSTEMTSAVMINERAL2,
    COALESCE(stsavgrp1class.classtext,'NULL') SYSTEMTSAVGROUP1,
    COALESCE(stsavgrp2class.classtext,'NULL') SYSTEMTSAVGROUP2,
    COALESCE(stsavwei1data.decimalvalue,0) SYSTEMTSAVWEIGHT1,
    COALESCE(stsavwei2data.decimalvalue,0) SYSTEMTSAVWEIGHT2
  FROM domainlogdata
  INNER JOIN publisheddatasets
  ON publisheddatasets.domain_id=domainlogdata.log_id
  INNER JOIN publishedlogs stsasmin1
  ON stsasmin1.dataset_id           = publisheddatasets.dataset_id
  AND stsasmin1.mixnumber =0
  AND stsasmin1.TSARETRAINING_ID is null
  INNER JOIN Algorithmoutputs swirminalg
  ON stsasmin1.algorithmoutput_id = swirminalg.algorithmoutput_id
  AND swirminalg.algorithmoutputname = 'SWIR Mineral'
  INNER JOIN classlogdata stsasmin1data
  ON stsasmin1data.log_id       =stsasmin1.log_id
  AND stsasmin1data.samplenumber= domainlogdata.samplenumber
  LEFT OUTER JOIN classifications stsasmin1class
  ON stsasmin1class.algorithmoutput_id= stsasmin1.algorithmoutput_id
  AND stsasmin1data.classlogvalue     = stsasmin1class.intindex
  INNER JOIN publishedlogs stsasmin2
  ON stsasmin2.dataset_id           = publisheddatasets.dataset_id
  AND stsasmin2.mixnumber =1
  AND stsasmin2.TSARETRAINING_ID is null
  AND stsasmin2.algorithmoutput_id = swirminalg.algorithmoutput_id
  INNER JOIN classlogdata stsasmin2data
  ON stsasmin2data.log_id       =stsasmin2.log_id
  AND stsasmin2data.samplenumber= domainlogdata.samplenumber
  LEFT OUTER JOIN classifications stsasmin2class
  ON stsasmin2class.algorithmoutput_id= stsasmin2.algorithmoutput_id
  AND stsasmin2data.classlogvalue     = stsasmin2class.intindex
  INNER JOIN publishedlogs stsasgrp1
  ON stsasgrp1.dataset_id           = publisheddatasets.dataset_id
  AND stsasgrp1.mixnumber =0
  AND stsasgrp1.TSARETRAINING_ID is null
  INNER JOIN Algorithmoutputs swirgrpalg
  ON stsasgrp1.algorithmoutput_id = swirgrpalg.algorithmoutput_id
  AND swirgrpalg.algorithmoutputname = 'SWIR Group'
  INNER JOIN classlogdata stsasgrp1data
  ON stsasgrp1data.log_id       =stsasgrp1.log_id
  AND stsasgrp1data.samplenumber= domainlogdata.samplenumber
  LEFT OUTER JOIN classifications stsasgrp1class
  ON stsasgrp1class.algorithmoutput_id= stsasgrp1.algorithmoutput_id
  AND stsasgrp1data.classlogvalue     = stsasgrp1class.intindex
  INNER JOIN publishedlogs stsasgrp2
  ON stsasgrp2.dataset_id           = publisheddatasets.dataset_id
  AND stsasgrp2.mixnumber =1
  AND stsasgrp2.TSARETRAINING_ID is null
  AND stsasgrp2.algorithmoutput_id = swirgrpalg.algorithmoutput_id
  INNER JOIN classlogdata stsasgrp2data
  ON stsasgrp2data.log_id       =stsasgrp2.log_id
  AND stsasgrp2data.samplenumber= domainlogdata.samplenumber
  LEFT OUTER JOIN classifications stsasgrp2class
  ON stsasgrp2class.algorithmoutput_id= stsasgrp2.algorithmoutput_id
  AND stsasgrp2data.classlogvalue     = stsasgrp2class.intindex
  INNER JOIN publishedlogs stsaswei1
  ON stsaswei1.dataset_id           = publisheddatasets.dataset_id
  AND stsaswei1.mixnumber =0
  AND stsaswei1.TSARETRAINING_ID is null
  INNER JOIN Algorithmoutputs swirweialg
  ON stsaswei1.algorithmoutput_id = swirweialg.algorithmoutput_id
  AND swirweialg.algorithmoutputname =  'SWIR Weight'
  INNER JOIN decimallogdata stsaswei1data
  ON stsaswei1data.log_id       =stsaswei1.log_id
  AND stsaswei1data.samplenumber= domainlogdata.samplenumber
  INNER JOIN publishedlogs stsaswei2
  ON stsaswei2.dataset_id           = publisheddatasets.dataset_id
  AND stsaswei2.mixnumber =1
  AND stsaswei2.TSARETRAINING_ID is null
  AND stsaswei2.algorithmoutput_id = swirweialg.algorithmoutput_id
  INNER JOIN decimallogdata stsaswei2data
  ON stsaswei2data.log_id       =stsaswei2.log_id
  AND stsaswei2data.samplenumber= domainlogdata.samplenumber
  INNER JOIN publishedlogs stsavmin1
  ON stsavmin1.dataset_id           = publisheddatasets.dataset_id
  AND stsavmin1.mixnumber =0
  AND stsavmin1.TSARETRAINING_ID is null
  INNER JOIN Algorithmoutputs vnirminalg
  ON stsavmin1.algorithmoutput_id = vnirminalg.algorithmoutput_id
  AND vnirminalg.algorithmoutputname = 'VNIR Mineral'
  INNER JOIN classlogdata stsavmin1data
  ON stsavmin1data.log_id       =stsavmin1.log_id
  AND stsavmin1data.samplenumber= domainlogdata.samplenumber
  LEFT OUTER JOIN classifications stsavmin1class
  ON stsavmin1class.algorithmoutput_id= stsavmin1.algorithmoutput_id
  AND stsavmin1data.classlogvalue     = stsavmin1class.intindex
  INNER JOIN publishedlogs stsavmin2
  ON stsavmin2.dataset_id           = publisheddatasets.dataset_id
  AND stsavmin2.mixnumber =1
  AND stsavmin2.TSARETRAINING_ID is null
  AND stsavmin2.algorithmoutput_id = vnirminalg.algorithmoutput_id
  INNER JOIN classlogdata stsavmin2data
  ON stsavmin2data.log_id       =stsavmin2.log_id
  AND stsavmin2data.samplenumber= domainlogdata.samplenumber
  LEFT OUTER JOIN classifications stsavmin2class
  ON stsavmin2class.algorithmoutput_id= stsavmin2.algorithmoutput_id
  AND stsavmin2data.classlogvalue     = stsavmin2class.intindex
  INNER JOIN publishedlogs stsavgrp1
  ON stsavgrp1.dataset_id           = publisheddatasets.dataset_id
  AND stsavgrp1.mixnumber =0
  AND stsavgrp1.TSARETRAINING_ID is null
  INNER JOIN Algorithmoutputs vnirgrpalg
  ON stsavgrp1.algorithmoutput_id = vnirgrpalg.algorithmoutput_id
  AND vnirgrpalg.algorithmoutputname = 'VNIR Group'
  INNER JOIN classlogdata stsavgrp1data
  ON stsavgrp1data.log_id       =stsavgrp1.log_id
  AND stsavgrp1data.samplenumber= domainlogdata.samplenumber
  LEFT OUTER JOIN classifications stsavgrp1class
  ON stsavgrp1class.algorithmoutput_id= stsavgrp1.algorithmoutput_id
  AND stsavgrp1data.classlogvalue     = stsavgrp1class.intindex
  INNER JOIN publishedlogs stsavgrp2
  ON stsavgrp2.dataset_id           = publisheddatasets.dataset_id
  AND stsavgrp2.mixnumber =1
  AND stsavgrp2.TSARETRAINING_ID is null
  AND stsavgrp2.algorithmoutput_id = vnirgrpalg.algorithmoutput_id
  INNER JOIN classlogdata stsavgrp2data
  ON stsavgrp2data.log_id       =stsavgrp2.log_id
  AND stsavgrp2data.samplenumber= domainlogdata.samplenumber
  LEFT OUTER JOIN classifications stsavgrp2class
  ON stsavgrp2class.algorithmoutput_id= stsavgrp2.algorithmoutput_id
  AND stsavgrp2data.classlogvalue     = stsavgrp2class.intindex
  INNER JOIN publishedlogs stsavwei1
  ON stsavwei1.dataset_id           = publisheddatasets.dataset_id
  AND stsavwei1.mixnumber =0
  AND stsavwei1.TSARETRAINING_ID is null
  INNER JOIN Algorithmoutputs vnirweialg
  ON stsavwei1.algorithmoutput_id = vnirweialg.algorithmoutput_id
  AND vnirweialg.algorithmoutputname =  'VNIR Weight'
  INNER JOIN decimallogdata stsavwei1data
  ON stsavwei1data.log_id       =stsavwei1.log_id
  AND stsavwei1data.samplenumber= domainlogdata.samplenumber
  INNER JOIN publishedlogs stsavwei2
  ON stsavwei2.dataset_id           = publisheddatasets.dataset_id
  AND stsavwei2.mixnumber =1
  AND stsavwei2.TSARETRAINING_ID is null
  AND stsavwei2.algorithmoutput_id = vnirweialg.algorithmoutput_id
  INNER JOIN decimallogdata stsavwei2data
  ON stsavwei2data.log_id       =stsavwei2.log_id
  AND stsavwei2data.samplenumber= domainlogdata.samplenumber
  ORDER BY samplenumber;
  GRANT SELECT ON "NVCL"."GETPUBLISHEDSYSTEMTSA" TO "WEBSERVICE";
--------------------------------------------------------
--  DDL for View GETPUBLISHEDUSERTSA
--------------------------------------------------------

  CREATE OR REPLACE FORCE VIEW "NVCL"."GETPUBLISHEDUSERTSA" ("DATASET_ID", "SAMPLENUMBER", "STARTVALUE", "ENDVALUE", "SYSTEMTSASMINERAL1", "SYSTEMTSASMINERAL2", "SYSTEMTSASGROUP1", "SYSTEMTSASGROUP2", "SYSTEMTSASWEIGHT1", "SYSTEMTSASWEIGHT2", "SYSTEMTSAVMINERAL1", "SYSTEMTSAVMINERAL2", "SYSTEMTSAVGROUP1", "SYSTEMTSAVGROUP2", "SYSTEMTSAVWEIGHT1", "SYSTEMTSAVWEIGHT2") AS 
  SELECT publisheddatasets.dataset_id,
    domainlogdata.samplenumber,
    domainlogdata.startvalue,
    domainlogdata.endvalue,
    COALESCE(utsasmin1class.classtext,'NULL') USERTSASMINERAL1,
    COALESCE(utsasmin2class.classtext,'NULL') USERTSASMINERAL2,
    COALESCE(utsasgrp1class.classtext,'NULL') USERTSASGROUP1,
    COALESCE(utsasgrp2class.classtext,'NULL') USERTSASGROUP2,
    COALESCE(utsaswei1data.decimalvalue,0) USERTSASWEIGHT1,
    COALESCE(utsaswei2data.decimalvalue,0) USERTSASWEIGHT2,
    COALESCE(utsavmin1class.classtext,'NULL') USERTSAVMINERAL1,
    COALESCE(utsavmin2class.classtext,'NULL') USERTSAVMINERAL2,
    COALESCE(utsavgrp1class.classtext,'NULL') USERTSAVGROUP1,
    COALESCE(utsavgrp2class.classtext,'NULL') USERTSAVGROUP2,
    COALESCE(utsavwei1data.decimalvalue,0) USERTSAVWEIGHT1,
    COALESCE(utsavwei2data.decimalvalue,0) USERTSAVWEIGHT2
  FROM domainlogdata
  INNER JOIN publisheddatasets
  ON publisheddatasets.domain_id=domainlogdata.log_id
  INNER JOIN publishedlogs utsasmin1
  ON utsasmin1.dataset_id           = publisheddatasets.dataset_id
  AND utsasmin1.mixnumber =0
  AND utsasmin1.TSARETRAINING_ID is not null
  INNER JOIN Algorithmoutputs swirminalg
  ON utsasmin1.algorithmoutput_id = swirminalg.algorithmoutput_id
  AND swirminalg.algorithmoutputname = 'SWIR Mineral'
  INNER JOIN classlogdata utsasmin1data
  ON utsasmin1data.log_id       =utsasmin1.log_id
  AND utsasmin1data.samplenumber= domainlogdata.samplenumber
  LEFT OUTER JOIN classifications utsasmin1class
  ON utsasmin1class.algorithmoutput_id= utsasmin1.algorithmoutput_id
  AND utsasmin1data.classlogvalue     = utsasmin1class.intindex
  INNER JOIN publishedlogs utsasmin2
  ON utsasmin2.dataset_id           = publisheddatasets.dataset_id
  AND utsasmin2.mixnumber =1
  AND utsasmin2.TSARETRAINING_ID is not null
  AND utsasmin2.algorithmoutput_id = swirminalg.algorithmoutput_id
  INNER JOIN classlogdata utsasmin2data
  ON utsasmin2data.log_id       =utsasmin2.log_id
  AND utsasmin2data.samplenumber= domainlogdata.samplenumber
  LEFT OUTER JOIN classifications utsasmin2class
  ON utsasmin2class.algorithmoutput_id= utsasmin2.algorithmoutput_id
  AND utsasmin2data.classlogvalue     = utsasmin2class.intindex
  INNER JOIN publishedlogs utsasgrp1
  ON utsasgrp1.dataset_id           = publisheddatasets.dataset_id
  AND utsasgrp1.mixnumber =0
  AND utsasgrp1.TSARETRAINING_ID is not null
  INNER JOIN Algorithmoutputs swirgrpalg
  ON utsasgrp1.algorithmoutput_id = swirgrpalg.algorithmoutput_id
  AND swirgrpalg.algorithmoutputname = 'SWIR Group'
  INNER JOIN classlogdata utsasgrp1data
  ON utsasgrp1data.log_id       =utsasgrp1.log_id
  AND utsasgrp1data.samplenumber= domainlogdata.samplenumber
  LEFT OUTER JOIN classifications utsasgrp1class
  ON utsasgrp1class.algorithmoutput_id= utsasgrp1.algorithmoutput_id
  AND utsasgrp1data.classlogvalue     = utsasgrp1class.intindex
  INNER JOIN publishedlogs utsasgrp2
  ON utsasgrp2.dataset_id           = publisheddatasets.dataset_id
  AND utsasgrp2.mixnumber =1
  AND utsasgrp2.TSARETRAINING_ID is not null
  AND utsasgrp2.algorithmoutput_id = swirgrpalg.algorithmoutput_id
  INNER JOIN classlogdata utsasgrp2data
  ON utsasgrp2data.log_id       =utsasgrp2.log_id
  AND utsasgrp2data.samplenumber= domainlogdata.samplenumber
  LEFT OUTER JOIN classifications utsasgrp2class
  ON utsasgrp2class.algorithmoutput_id= utsasgrp2.algorithmoutput_id
  AND utsasgrp2data.classlogvalue     = utsasgrp2class.intindex
  INNER JOIN publishedlogs utsaswei1
  ON utsaswei1.dataset_id           = publisheddatasets.dataset_id
  AND utsaswei1.mixnumber =0
  AND utsaswei1.TSARETRAINING_ID is not null
  INNER JOIN Algorithmoutputs swirweialg
  ON utsaswei1.algorithmoutput_id = swirweialg.algorithmoutput_id
  AND swirweialg.algorithmoutputname =  'SWIR Weight'
  INNER JOIN decimallogdata utsaswei1data
  ON utsaswei1data.log_id       =utsaswei1.log_id
  AND utsaswei1data.samplenumber= domainlogdata.samplenumber
  INNER JOIN publishedlogs utsaswei2
  ON utsaswei2.dataset_id           = publisheddatasets.dataset_id
  AND utsaswei2.mixnumber =1
  AND utsaswei2.TSARETRAINING_ID is not null
  AND utsaswei2.algorithmoutput_id = swirweialg.algorithmoutput_id
  INNER JOIN decimallogdata utsaswei2data
  ON utsaswei2data.log_id       =utsaswei2.log_id
  AND utsaswei2data.samplenumber= domainlogdata.samplenumber
  INNER JOIN publishedlogs utsavmin1
  ON utsavmin1.dataset_id           = publisheddatasets.dataset_id
  AND utsavmin1.mixnumber =0
  AND utsavmin1.TSARETRAINING_ID is not null
  INNER JOIN Algorithmoutputs vnirminalg
  ON utsavmin1.algorithmoutput_id = vnirminalg.algorithmoutput_id
  AND vnirminalg.algorithmoutputname = 'VNIR Mineral'
  INNER JOIN classlogdata utsavmin1data
  ON utsavmin1data.log_id       =utsavmin1.log_id
  AND utsavmin1data.samplenumber= domainlogdata.samplenumber
  LEFT OUTER JOIN classifications utsavmin1class
  ON utsavmin1class.algorithmoutput_id= utsavmin1.algorithmoutput_id
  AND utsavmin1data.classlogvalue     = utsavmin1class.intindex
  INNER JOIN publishedlogs utsavmin2
  ON utsavmin2.dataset_id           = publisheddatasets.dataset_id
  AND utsavmin2.mixnumber =1
  AND utsavmin2.TSARETRAINING_ID is not null
  AND utsavmin2.algorithmoutput_id = vnirminalg.algorithmoutput_id
  INNER JOIN classlogdata utsavmin2data
  ON utsavmin2data.log_id       =utsavmin2.log_id
  AND utsavmin2data.samplenumber= domainlogdata.samplenumber
  LEFT OUTER JOIN classifications utsavmin2class
  ON utsavmin2class.algorithmoutput_id= utsavmin2.algorithmoutput_id
  AND utsavmin2data.classlogvalue     = utsavmin2class.intindex
  INNER JOIN publishedlogs utsavgrp1
  ON utsavgrp1.dataset_id           = publisheddatasets.dataset_id
  AND utsavgrp1.mixnumber =0
  AND utsavgrp1.TSARETRAINING_ID is not null
  INNER JOIN Algorithmoutputs vnirgrpalg
  ON utsavgrp1.algorithmoutput_id = vnirgrpalg.algorithmoutput_id
  AND vnirgrpalg.algorithmoutputname = 'VNIR Group'
  INNER JOIN classlogdata utsavgrp1data
  ON utsavgrp1data.log_id       =utsavgrp1.log_id
  AND utsavgrp1data.samplenumber= domainlogdata.samplenumber
  LEFT OUTER JOIN classifications utsavgrp1class
  ON utsavgrp1class.algorithmoutput_id= utsavgrp1.algorithmoutput_id
  AND utsavgrp1data.classlogvalue     = utsavgrp1class.intindex
  INNER JOIN publishedlogs utsavgrp2
  ON utsavgrp2.dataset_id           = publisheddatasets.dataset_id
  AND utsavgrp2.mixnumber =1
  AND utsavgrp2.TSARETRAINING_ID is not null
  AND utsavgrp2.algorithmoutput_id = vnirgrpalg.algorithmoutput_id
  INNER JOIN classlogdata utsavgrp2data
  ON utsavgrp2data.log_id       =utsavgrp2.log_id
  AND utsavgrp2data.samplenumber= domainlogdata.samplenumber
  LEFT OUTER JOIN classifications utsavgrp2class
  ON utsavgrp2class.algorithmoutput_id= utsavgrp2.algorithmoutput_id
  AND utsavgrp2data.classlogvalue     = utsavgrp2class.intindex
  INNER JOIN publishedlogs utsavwei1
  ON utsavwei1.dataset_id           = publisheddatasets.dataset_id
  AND utsavwei1.mixnumber =0
  AND utsavwei1.TSARETRAINING_ID is not null
  INNER JOIN Algorithmoutputs vnirweialg
  ON utsavwei1.algorithmoutput_id = vnirweialg.algorithmoutput_id
  AND vnirweialg.algorithmoutputname =  'VNIR Weight'
  INNER JOIN decimallogdata utsavwei1data
  ON utsavwei1data.log_id       =utsavwei1.log_id
  AND utsavwei1data.samplenumber= domainlogdata.samplenumber
  INNER JOIN publishedlogs utsavwei2
  ON utsavwei2.dataset_id           = publisheddatasets.dataset_id
  AND utsavwei2.mixnumber =1
  AND utsavwei2.TSARETRAINING_ID is not null
  AND utsavwei2.algorithmoutput_id = vnirweialg.algorithmoutput_id
  INNER JOIN decimallogdata utsavwei2data
  ON utsavwei2data.log_id       =utsavwei2.log_id
  AND utsavwei2data.samplenumber= domainlogdata.samplenumber
  ORDER BY samplenumber;
--------------------------------------------------------
--  DDL for View LOCATEDSPECIMENS
--------------------------------------------------------

  CREATE OR REPLACE FORCE VIEW "NVCL"."LOCATEDSPECIMENS" ("LS_ID", "DATASET_ID", "HOLEIDENTIFIER", "GEOM_LINESTRING", "CREATEDDATE", "STARTDEPTH", "ENDDEPTH") AS 
  SELECT 'sa.locatedspecimen.'
    || DATASET_ID
    || '.'
    || STARTDEPTH
    || '-'
    || ENDDEPTH AS LS_ID,
    DATASET_ID,
    HOLEIDENTIFIER,
    mdsys.SDO_GEOMETRY(2002,NULL,NULL,MDSYS.SDO_ELEM_INFO_ARRAY(1,2,1),MDSYS.SDO_ORDINATE_ARRAY(startdepth,NULL,enddepth,NULL)) AS geom_linestring,
    TO_CHAR(CREATEDDATE,'YYYY-MM-DD') AS CREATEDDATE,
    startdepth,
    enddepth
  FROM MV_LOCATEDSPECIMENS;
  GRANT SELECT ON "NVCL"."LOCATEDSPECIMENS" TO "WEBSERVICE";
--------------------------------------------------------
--  DDL for View OBSERVATIONS
--------------------------------------------------------

  CREATE OR REPLACE FORCE VIEW "NVCL"."OBSERVATIONS" ("LS_ID", "LOG_ID", "LOGNAME", "CREATEDDATE", "RESULTS") AS 
  SELECT 
      LOCATEDSPECIMENS.LS_ID AS LS_ID, 
      'om.observations.'||LOGS.LOG_ID || '.' || LOCATEDSPECIMENS.STARTDEPTH || '-' || LOCATEDSPECIMENS.ENDDEPTH AS LOG_ID, 
      LOGS.LOGNAME AS LOGNAME,  
      TO_CHAR(logs."CREATEDDATE",'YYYY-MM-DD') AS CREATEDDATE,
      count(COMPOUNDMATERIAL.loginterval_id) AS results
   FROM 
      LOGS 
         INNER JOIN DATASETS
         ON LOGS.DATASET_ID = DATASETS.DATASET_ID 
         INNER JOIN LOCATEDSPECIMENS 
         ON LOCATEDSPECIMENS.DATASET_ID = DATASETS.DATASET_ID 
         INNER JOIN ALGORITHMOUTPUTS 
         ON LOGS.ALGORITHMOUTPUT_ID = ALGORITHMOUTPUTS.ALGORITHMOUTPUT_ID
         left join COMPOUNDMATERIAL 
         ON COMPOUNDMATERIAL.loginterval_id='om.observations.'||LOGS.LOG_ID || '.' || LOCATEDSPECIMENS.STARTDEPTH || '-' || LOCATEDSPECIMENS.ENDDEPTH
 WHERE LOGS.logtype          IN (1,2) and LOGS.ispublic=1 and datasets.ispublic=1
  AND LOGS.algorithmoutput_id IN ( 1, 12, 32, 40, 48, 74, 88, 7, 20, 26, 82, 96)
 GROUP BY LOCATEDSPECIMENS.LS_ID, 'om.observations.'||LOGS.LOG_ID || '.' || LOCATEDSPECIMENS.STARTDEPTH || '-' || LOCATEDSPECIMENS.ENDDEPTH, LOGS.LOGNAME, TO_CHAR(logs."CREATEDDATE",'YYYY-MM-DD');
  GRANT SELECT ON "NVCL"."OBSERVATIONS" TO "WEBSERVICE";
--------------------------------------------------------
--  DDL for View PUBLISHEDALGORITHMS
--------------------------------------------------------

  CREATE OR REPLACE FORCE VIEW "NVCL"."PUBLISHEDALGORITHMS" ("DATASET_ID", "ALGORITHM_ID", "ALGORITHMNAME", "DESCRIPTION", "SCANDATE") AS 
  SELECT DISTINCT publishedlogs.dataset_id, algorithmoutputs.algorithm_id,algorithms.algorithmname,algorithms.description,publisheddatasets.scandate FROM publisheddatasets inner join publishedlogs on publisheddatasets.dataset_id=publishedlogs.dataset_id inner join algorithmoutputs on publishedlogs.algorithmoutput_id=algorithmoutputs.algorithmoutput_id inner join algorithms on algorithmoutputs.algorithm_id=algorithms.algorithm_id;
--------------------------------------------------------
--  DDL for View PUBLISHEDDATASETS
--------------------------------------------------------

  CREATE OR REPLACE FORCE VIEW "NVCL"."PUBLISHEDDATASETS" ("DATASET_ID", "GML_ID", "GML_NAME", "DATASETNAME", "DOMAIN_ID", "ISREFERENCELIBRARY", "CREATEDDATE", "MODIFIEDDATE", "CREATORUSERNAME", "MODIFIERUSERNAME", "SPECLOG_ID", "IMAGELOG_ID", "PROFLOG_ID", "TRAYLOG_ID", "SECTIONLOG_ID", "HOLEDATASOURCENAME", "HOLEIDENTIFIER", "DSDESCRIPTION", "ORIGAUTHOR", "IMPORTDATE", "SCANDATE", "CUSTOMDATASET_ID", "CUSTCALCDATASET_ID", "MACHINENAME") AS 
  SELECT datasets.DATASET_ID,
    'sa.samplingfeaturecollection.' || datasets.DATASET_ID GML_ID, 
    'urn:ogc:feature:SamplingFeatureCollection:SamplingFeatureCollection.' || datasets.DATASET_ID GML_NAME, 
    datasets.DATASETNAME,
    datasets.DOMAIN_ID,
    datasets.ISREFERENCELIBRARY,
    CAST(datasets.CREATEDDATE as Date),
    CAST(datasets.MODIFIEDDATE as Date),
    datasets.CREATORUSERNAME,
    datasets.MODIFIERUSERNAME,
    datasets.SPECLOG_ID,
    datasets.IMAGELOG_ID,
    datasets.PROFLOG_ID,
    datasets.TRAYLOG_ID,
    datasets.SECTIONLOG_ID,
    datasets.HOLEDATASOURCENAME,
    datasets.HOLEIDENTIFIER,
    datasets.DSDESCRIPTION,
    datasets.ORIGAUTHOR,
    datasets.IMPORTDATE,
    datasets.SCANDATE,
    datasets.CUSTOMDATASET_ID,
    datasets.CUSTCALCDATASET_ID,
    machines.machinename
  FROM DATASETS
  LEFT OUTER JOIN machines
  ON datasets.primarylogger_id= machines.machine_id
  WHERE ispublic =1;
  GRANT SELECT ON "NVCL"."PUBLISHEDDATASETS" TO "WEBSERVICE";
--------------------------------------------------------
--  DDL for View PUBLISHEDIMAGELOGDATA
--------------------------------------------------------

  CREATE OR REPLACE FORCE VIEW "NVCL"."PUBLISHEDIMAGELOGDATA" ("LOG_ID", "SAMPLENUMBER", "IMAGEDATA", "IMAGECOMMENT") AS 
  select publishedlogs.LOG_ID,imagelogdata.SAMPLENUMBER,imagelogdata.IMAGEDATA,imagelogdata.IMAGECOMMENT from imagelogdata inner join publishedlogs on imagelogdata.log_id=publishedlogs.log_id;
  GRANT SELECT ON "NVCL"."PUBLISHEDIMAGELOGDATA" TO "WEBSERVICE";
--------------------------------------------------------
--  DDL for View PUBLISHEDLOGS
--------------------------------------------------------

  CREATE OR REPLACE FORCE VIEW "NVCL"."PUBLISHEDLOGS" ("LOG_ID", "LOGNAME", "CREATORUSERNAME", "MODIFIEDDATE", "DATASET_ID", "DOMAINLOG_ID", "LOGTYPE", "CREATEDDATE", "DESCRIPTION", "MODIFIERUSERNAME", "ALGORITHMOUTPUT_ID", "ALOGRITHM_ID", "MASKLOG_ID", "REFSTATS_ID", "TSARETRAINING_ID", "TSGHANDMASK", "CUSTOMSCRIPT", "BATCHSCRIPT", "MIXNUMBER", "AUXSPECTRALLAYER_ID", "LOCALSPECTRALLAYER_ID", "SAMPLECOUNT") AS 
  SELECT logs."LOG_ID",
    logs."LOGNAME",
    logs."CREATORUSERNAME",
    CAST(logs."MODIFIEDDATE" AS DATE),
    logs."DATASET_ID",
    logs."DOMAINLOG_ID",
    logs."LOGTYPE",
    CAST(logs."CREATEDDATE" AS DATE),
    logs."DESCRIPTION",
    logs."MODIFIERUSERNAME",
    logs."ALGORITHMOUTPUT_ID",
    algorithmoutputs.algorithm_id,
    logs."MASKLOG_ID",
    logs."REFSTATS_ID",
    logs."TSARETRAINING_ID",
    logs."TSGHANDMASK",
    logs."CUSTOMSCRIPT",
    logs."BATCHSCRIPT",
    logs."MIXNUMBER",
    logs."AUXSPECTRALLAYER_ID",
    logs."LOCALSPECTRALLAYER_ID",
    GETDATAPOINTS(logs."LOG_ID")
  FROM LOGS
  INNER JOIN publisheddatasets
  ON logs.dataset_id=publisheddatasets.dataset_id
  LEFT OUTER JOIN algorithmoutputs
  ON logs.algorithmoutput_id= algorithmoutputs.algorithmoutput_id
  WHERE logs.ispublic       =1;
  GRANT SELECT ON "NVCL"."PUBLISHEDLOGS" TO "WEBSERVICE";
--------------------------------------------------------
--  DDL for View SAMPLINGFEATURECOLLECTIONS
--------------------------------------------------------

  CREATE OR REPLACE FORCE VIEW "NVCL"."SAMPLINGFEATURECOLLECTIONS" ("DATASET_ID", "NAME", "GML_ID", "GML_NAME", "HOLEIDENTIFIER") AS 
  SELECT datasets.DATASET_ID,
  datasets.datasetname,
    'sa.samplingfeaturecollection.'
    || datasets.DATASET_ID GML_ID,
    'urn:ogc:feature:SamplingFeatureCollection:SamplingFeatureCollection.'
    || datasets.DATASET_ID GML_NAME,
    datasets.HOLEIDENTIFIER
  FROM DATASETS
  WHERE ispublic =1;
  GRANT SELECT ON "NVCL"."SAMPLINGFEATURECOLLECTIONS" TO "WEBSERVICE";
--------------------------------------------------------
--  DDL for View SEARCHFORDATASETS
--------------------------------------------------------

  CREATE OR REPLACE FORCE VIEW "NVCL"."SEARCHFORDATASETS" ("DATASETNAME", "DATASET_ID", "HOLEIDENTIFIER", "MODIFIEDDATE", "CREATEDDATE", "CREATORUSERNAME", "MODIFIERUSERNAME", "MACHINENAME", "TRAYCOUNT", "SAMPLECOUNT") AS 
  SELECT DATASETS.DATASETNAME,DATASETS.DATASET_ID,DATASETS.HOLEIDENTIFIER, DATASETS.MODIFIEDDATE,DATASETS.CREATEDDATE,DATASETS.CREATORUSERNAME,DATASETS.MODIFIERUSERNAME,MACHINES.MACHINENAME,(SELECT count(SAMPLENUMBER) from domainlogdata WHERE domainlogdata.log_id= datasets.traylog_id||'DOMAIN') traycount, (SELECT count(SAMPLENUMBER) from domainlogdata WHERE domainlogdata.log_id= datasets.domain_id) samplecount FROM DATASETS LEFT JOIN MACHINES ON DATASETS.PRIMARYLOGGER_ID=MACHINES.MACHINE_ID;
  GRANT SELECT ON "NVCL"."SEARCHFORDATASETS" TO "NVCLVIEWER";
  GRANT SELECT ON "NVCL"."SEARCHFORDATASETS" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for View TRAYIMAGESANDDETAILSVIEW
--------------------------------------------------------

  CREATE OR REPLACE FORCE VIEW "NVCL"."TRAYIMAGESANDDETAILSVIEW" ("Dataset_ID", "Tray Number", "Start Depth", "End Depth", "Tray Image", "Last Update Date") AS 
  SELECT depths.DATASET_ID Dataset_ID,
    CAST(CLASSSPECIFICCLASSIFICATIONS.CLASSTEXT AS INT) "Tray Number",
    depths.STARTVALUE,
    depths.ENDVALUE,
    IMAGELOGDATA.IMAGEDATA "Tray Image",
    DATASETS.modifieddate
  FROM
    (SELECT DATASETS.DATASET_ID Dataset_ID,
      traydomdata.samplenumber samplenumber,
      MIN(sampdomdata.STARTVALUE) startvalue,
      MAX(sampdomdata.ENDVALUE) endvalue,
      trayimagelog.log_id imagelogid
    FROM DATASETS
    INNER JOIN LOGS trayimagelog
    ON trayimagelog.DATASET_ID = DATASETS.DATASET_ID
    AND trayimagelog.LOGTYPE   = 3
    AND trayimagelog.LOGNAME   = 'Tray Images'
    INNER JOIN domainlogs traydom
    ON traydom.log_id=trayimagelog.domainlog_id
    INNER JOIN DOMAINLOGDATA traydomdata
    ON traydomdata.log_id=traydom.log_id
    INNER JOIN domainlogs sampdom
    ON sampdom.log_id=traydom.issubdomainoflog_id
    INNER JOIN DOMAINLOGDATA sampdomdata
    ON sampdomdata.log_id=sampdom.log_id
    AND sampdomdata.SAMPLENUMBER BETWEEN traydomdata.STARTVALUE AND traydomdata.ENDVALUE
    GROUP BY DATASETS.DATASET_ID,
      traydomdata.samplenumber,
      trayimagelog.log_id
    ORDER BY DATASETS.DATASET_ID,
      traydomdata.samplenumber
    ) depths
  INNER JOIN datasets
  ON depths.dataset_id=datasets.dataset_id
  INNER JOIN CLASSLOGDATA
  ON CLASSLOGDATA.LOG_ID         = DATASETS.TRAYLOG_ID
  AND CLASSLOGDATA.SAMPLENUMBER  = depths.SAMPLENUMBER
  AND CLASSLOGDATA.classlogvalue>=0
  INNER JOIN CLASSSPECIFICCLASSIFICATIONS
  ON CLASSSPECIFICCLASSIFICATIONS.LOG_ID    = CLASSLOGDATA.LOG_ID
  AND CLASSSPECIFICCLASSIFICATIONS.INTINDEX = CLASSLOGDATA.CLASSLOGVALUE
  INNER JOIN IMAGELOGDATA
  ON IMAGELOGDATA.LOG_ID                        = depths.imageLOGID
  AND IMAGELOGDATA.SAMPLENUMBER                 = depths.SAMPLENUMBER
  WHERE CLASSSPECIFICCLASSIFICATIONS.CLASSTEXT IS NOT NULL
  ORDER BY DATASETS.DATASET_ID,
    CAST(CLASSSPECIFICCLASSIFICATIONS.CLASSTEXT AS INT);
--------------------------------------------------------
--  DDL for Materialized View MV_COMPOUNDMATERIAL
--------------------------------------------------------

  CREATE MATERIALIZED VIEW "NVCL"."MV_COMPOUNDMATERIAL" ("LOG_ID", "STARTDEPTH", "ENDDEPTH", "VALCOUNT", "CLASSTEXT", "COLOUR")
  ORGANIZATION HEAP PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255  NOCOMPRESS LOGGING 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLTBLSPC" 
  BUILD IMMEDIATE
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 161 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLTBLSPC" 
  REFRESH COMPLETE ON DEMAND START WITH sysdate+0 NEXT NEXT_DAY(TRUNC(SYSDATE), 'SATURDAY') + 1/24
  USING DEFAULT LOCAL ROLLBACK SEGMENT
  USING ENFORCED CONSTRAINTS DISABLE QUERY REWRITE
  AS SELECT LOGS.LOG_ID,
    FLOOR(DOMAINLOGDATA.startvalue)   AS startdepth,
    FLOOR(DOMAINLOGDATA.startvalue+1) AS enddepth,
    COUNT(                        *)  AS VALCOUNT,
    CLASSIFICATIONS.CLASSTEXT         AS CLASSTEXT,
    CLASSIFICATIONS.COLOUR            AS COLOUR
  FROM LOGS
  INNER JOIN DATASETS
  ON LOGS.dataset_id=DATASETS.dataset_id
  INNER JOIN DOMAINLOGDATA
  ON DOMAINLOGDATA.LOG_ID = LOGS.DOMAINLOG_ID
  INNER JOIN CLASSLOGDATA
  ON CLASSLOGDATA.LOG_ID          = LOGS.LOG_ID
  AND CLASSLOGDATA.CLASSLOGVALUE IS NOT NULL
  AND DOMAINLOGDATA.SAMPLENUMBER  = CLASSLOGDATA.SAMPLENUMBER
  INNER JOIN ALGORITHMOUTPUTS
  ON ALGORITHMOUTPUTS.ALGORITHMOUTPUT_ID = LOGS.ALGORITHMOUTPUT_ID
  INNER JOIN CLASSIFICATIONS
  ON ALGORITHMOUTPUTS.ALGORITHMOUTPUT_ID = CLASSIFICATIONS.ALGORITHMOUTPUT_ID
  AND CLASSLOGDATA.CLASSLOGVALUE         = CLASSIFICATIONS.INTINDEX
  WHERE DATASETS.ispublic                =1
  AND LOGS.ISPUBLIC                      = 1
  AND LOGS.ALGORITHMOUTPUT_ID           IN ( 1, 12, 32, 40, 48, 74, 88, 7, 20, 26, 82, 96
  GROUP BY LOGS.LOG_ID,
    FLOOR(DOMAINLOGDATA.startvalue),
    FLOOR(DOMAINLOGDATA.startvalue+1),
    CLASSIFICATIONS.CLASSTEXT,
    CLASSIFICATIONS.COLOUR;


   COMMENT ON MATERIALIZED VIEW "NVCL"."MV_COMPOUNDMATERIAL"  IS 'snapshot table for snapshot NVCL.MV_COMPOUNDMATERIAL';
--------------------------------------------------------
--  DDL for Materialized View MV_LOCATEDSPECIMENS
--------------------------------------------------------

  CREATE MATERIALIZED VIEW "NVCL"."MV_LOCATEDSPECIMENS" ("DATASET_ID", "HOLEIDENTIFIER", "STARTDEPTH", "ENDDEPTH", "CREATEDDATE")
  ORGANIZATION HEAP PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255  NOCOMPRESS LOGGING 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLTBLSPC" 
  BUILD IMMEDIATE
  USING INDEX 
  REFRESH COMPLETE ON DEMAND START WITH sysdate+0 NEXT NEXT_DAY(TRUNC(SYSDATE), 'SATURDAY') + 0.5/24
  USING DEFAULT LOCAL ROLLBACK SEGMENT
  USING ENFORCED CONSTRAINTS DISABLE QUERY REWRITE
  AS SELECT     DATASETS.DATASET_ID,
				DATASETS.HOLEIDENTIFIER,
	FLOOR(DOMAINLOGDATA.STARTVALUE) AS STARTDEPTH,
	FLOOR(DOMAINLOGDATA.STARTVALUE+1) AS ENDDEPTH,
  LOGS.createddate
FROM       DATASETS INNER JOIN LOGS
	ON DATASETS.DOMAIN_ID = LOGS.LOG_ID
	INNER JOIN DOMAINLOGDATA
	ON DOMAINLOGDATA.LOG_ID = LOGS.LOG_ID
WHERE DATASETS.ispublic =1 and logs.ispublic=1
GROUP BY   DATASETS.DATASET_ID,
	DATASETS.HOLEIDENTIFIER,
	FLOOR(DOMAINLOGDATA.STARTVALUE),
	FLOOR(DOMAINLOGDATA.STARTVALUE+1),
  LOGS.createddate;

   COMMENT ON MATERIALIZED VIEW "NVCL"."MV_LOCATEDSPECIMENS"  IS 'snapshot table for snapshot NVCL.MV_LOCATEDSPECIMENS';
--------------------------------------------------------
--  DDL for Index CALIBRATIONLOGDATA_PK
--------------------------------------------------------

  CREATE UNIQUE INDEX "NVCL"."CALIBRATIONLOGDATA_PK" ON "NVCL"."CALIBRATIONLOGDATA" ("LOG_ID", "SAMPLENUMBER") 
  PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS" ;
--------------------------------------------------------
--  DDL for Index ALGORITHMOUTPUTS_PK
--------------------------------------------------------

  CREATE UNIQUE INDEX "NVCL"."ALGORITHMOUTPUTS_PK" ON "NVCL"."ALGORITHMOUTPUTS" ("ALGORITHMOUTPUT_ID") 
  PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS" ;
--------------------------------------------------------
--  DDL for Index TSARETRAINING_PK
--------------------------------------------------------

  CREATE UNIQUE INDEX "NVCL"."TSARETRAINING_PK" ON "NVCL"."TSARETRAINING" ("TSARETRAINING_ID") 
  PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS" ;
--------------------------------------------------------
--  DDL for Index DOMAINLOGDATA_PK
--------------------------------------------------------

  CREATE UNIQUE INDEX "NVCL"."DOMAINLOGDATA_PK" ON "NVCL"."DOMAINLOGDATA" ("LOG_ID", "SAMPLENUMBER") 
  PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 131072 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS" ;
--------------------------------------------------------
--  DDL for Index MASKLOGDATA_PK
--------------------------------------------------------

  CREATE UNIQUE INDEX "NVCL"."MASKLOGDATA_PK" ON "NVCL"."MASKLOGDATA" ("LOG_ID", "SAMPLENUMBER") 
  PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS" ;
--------------------------------------------------------
--  DDL for Index CALIBRATIONLOG_PK
--------------------------------------------------------

  CREATE UNIQUE INDEX "NVCL"."CALIBRATIONLOG_PK" ON "NVCL"."CALIBRATIONLOGS" ("LOG_ID") 
  PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS" ;
--------------------------------------------------------
--  DDL for Index DOMAINLOGS_PK
--------------------------------------------------------

  CREATE UNIQUE INDEX "NVCL"."DOMAINLOGS_PK" ON "NVCL"."DOMAINLOGS" ("LOG_ID") 
  PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS" ;
--------------------------------------------------------
--  DDL for Index SCALARSET_PK
--------------------------------------------------------

  CREATE UNIQUE INDEX "NVCL"."SCALARSET_PK" ON "NVCL"."SCALARSETS" ("DATASET_ID", "SETNUMBER") 
  PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS" ;
--------------------------------------------------------
--  DDL for Index MASKLOG_PK
--------------------------------------------------------

  CREATE UNIQUE INDEX "NVCL"."MASKLOG_PK" ON "NVCL"."MASKLOGS" ("LOG_ID") 
  PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS" ;
--------------------------------------------------------
--  DDL for Index CLASSIFICATIONS_PK
--------------------------------------------------------

  CREATE UNIQUE INDEX "NVCL"."CLASSIFICATIONS_PK" ON "NVCL"."CLASSIFICATIONS" ("ALGORITHMOUTPUT_ID", "INTINDEX") 
  PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS" ;
--------------------------------------------------------
--  DDL for Index HOLEIDENTIFIER_IDX
--------------------------------------------------------

  CREATE INDEX "NVCL"."HOLEIDENTIFIER_IDX" ON "NVCL"."DATASETS" ("HOLEIDENTIFIER") 
  PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLTBLSPC" ;
--------------------------------------------------------
--  DDL for Index SPECTRALLOGDATA_PK
--------------------------------------------------------

  CREATE UNIQUE INDEX "NVCL"."SPECTRALLOGDATA_PK" ON "NVCL"."SPECTRALLOGDATA" ("LOG_ID", "SAMPLENUMBER") 
  PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS" ;
--------------------------------------------------------
--  DDL for Index PROFLOGDATA_PK
--------------------------------------------------------

  CREATE UNIQUE INDEX "NVCL"."PROFLOGDATA_PK" ON "NVCL"."PROFLOGDATA" ("LOG_ID", "SAMPLENUMBER") 
  PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS" ;
--------------------------------------------------------
--  DDL for Index PLSDATA_PK
--------------------------------------------------------

  CREATE UNIQUE INDEX "NVCL"."PLSDATA_PK" ON "NVCL"."PLSDATA" ("PLS_ID") 
  PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS" ;
--------------------------------------------------------
--  DDL for Index DATASETSTATS_PK
--------------------------------------------------------

  CREATE UNIQUE INDEX "NVCL"."DATASETSTATS_PK" ON "NVCL"."DATASETSTATS" ("DATASETSTATS_ID") 
  PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS" ;
--------------------------------------------------------
--  DDL for Index LOGDEPENDENCIES_PK
--------------------------------------------------------

  CREATE UNIQUE INDEX "NVCL"."LOGDEPENDENCIES_PK" ON "NVCL"."LOGDEPENDENCIES" ("LOG_ID", "PRIORITYORDER") 
  PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS" ;
--------------------------------------------------------
--  DDL for Index CLASSIFICATIONSCOLOUROVER_PK
--------------------------------------------------------

  CREATE UNIQUE INDEX "NVCL"."CLASSIFICATIONSCOLOUROVER_PK" ON "NVCL"."CLASSSPECIFICCLASSIFICATIONS" ("LOG_ID", "INTINDEX") 
  PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS" ;
--------------------------------------------------------
--  DDL for Index DECIMALLOGDATA_PK
--------------------------------------------------------

  CREATE UNIQUE INDEX "NVCL"."DECIMALLOGDATA_PK" ON "NVCL"."DECIMALLOGDATA" ("LOG_ID", "SAMPLENUMBER") 
  PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 131072 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS" ;
--------------------------------------------------------
--  DDL for Index MACHINES_PK
--------------------------------------------------------

  CREATE UNIQUE INDEX "NVCL"."MACHINES_PK" ON "NVCL"."MACHINES" ("MACHINE_ID") 
  PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS" ;
--------------------------------------------------------
--  DDL for Index TSGDATASET_PK
--------------------------------------------------------

  CREATE UNIQUE INDEX "NVCL"."TSGDATASET_PK" ON "NVCL"."DATASETS" ("DATASET_ID") 
  PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS" ;
--------------------------------------------------------
--  DDL for Index EVENTJOURNAL_PK
--------------------------------------------------------

  CREATE UNIQUE INDEX "NVCL"."EVENTJOURNAL_PK" ON "NVCL"."EVENTJOURNAL" ("DATASET_ID", "EVENTNUMBER", "ISPRIMARY") 
  PCTFREE 10 INITRANS 2 MAXTRANS 255 
  TABLESPACE "NVCLTBLSPC" ;
--------------------------------------------------------
--  DDL for Index SCALARGROUPS_PK
--------------------------------------------------------

  CREATE UNIQUE INDEX "NVCL"."SCALARGROUPS_PK" ON "NVCL"."SCALARGROUPS" ("SCALARGROUP_ID") 
  PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS" ;
--------------------------------------------------------
--  DDL for Index CLASSLOG_PK
--------------------------------------------------------

  CREATE UNIQUE INDEX "NVCL"."CLASSLOG_PK" ON "NVCL"."CLASSLOGS" ("LOG_ID") 
  PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS" ;
--------------------------------------------------------
--  DDL for Index LAYOUTS_PK
--------------------------------------------------------

  CREATE UNIQUE INDEX "NVCL"."LAYOUTS_PK" ON "NVCL"."LAYOUTS" ("DATASET_ID", "LAYOUTNO") 
  PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS" ;
--------------------------------------------------------
--  DDL for Index CLASSLOGDATA_PK
--------------------------------------------------------

  CREATE UNIQUE INDEX "NVCL"."CLASSLOGDATA_PK" ON "NVCL"."CLASSLOGDATA" ("LOG_ID", "SAMPLENUMBER") 
  PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS" ;
--------------------------------------------------------
--  DDL for Index SPECTRALLOG_PK
--------------------------------------------------------

  CREATE UNIQUE INDEX "NVCL"."SPECTRALLOG_PK" ON "NVCL"."SPECTRALLOGS" ("LOG_ID") 
  PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS" ;
--------------------------------------------------------
--  DDL for Index LOGS_PK
--------------------------------------------------------

  CREATE UNIQUE INDEX "NVCL"."LOGS_PK" ON "NVCL"."LOGS" ("LOG_ID") 
  PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS" ;
--------------------------------------------------------
--  DDL for Index IMAGELOGDATA_PK
--------------------------------------------------------

  CREATE UNIQUE INDEX "NVCL"."IMAGELOGDATA_PK" ON "NVCL"."IMAGELOGDATA" ("LOG_ID", "SAMPLENUMBER") 
  PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS" ;
--------------------------------------------------------
--  DDL for Index LOGTYPES_PK
--------------------------------------------------------

  CREATE UNIQUE INDEX "NVCL"."LOGTYPES_PK" ON "NVCL"."LOGTYPES" ("LOGTYPE_ID") 
  PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS" ;
--------------------------------------------------------
--  DDL for Index ALGORITHMS_PK
--------------------------------------------------------

  CREATE UNIQUE INDEX "NVCL"."ALGORITHMS_PK" ON "NVCL"."ALGORITHMS" ("ALGORITHM_ID") 
  PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS" ;
--------------------------------------------------------
--  DDL for Index PROFLOG_PK
--------------------------------------------------------

  CREATE UNIQUE INDEX "NVCL"."PROFLOG_PK" ON "NVCL"."PROFLOGS" ("LOG_ID") 
  PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS" ;
--------------------------------------------------------
--  DDL for Index IMAGELOG_PK
--------------------------------------------------------

  CREATE UNIQUE INDEX "NVCL"."IMAGELOG_PK" ON "NVCL"."IMAGELOGS" ("LOG_ID") 
  PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS" ;
--------------------------------------------------------
--  DDL for Index DECIMALLOG_PK
--------------------------------------------------------

  CREATE UNIQUE INDEX "NVCL"."DECIMALLOG_PK" ON "NVCL"."DECIMALLOGS" ("LOG_ID") 
  PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS" ;
--------------------------------------------------------
--  Constraints for Table ALGORITHMOUTPUTS
--------------------------------------------------------

  ALTER TABLE "NVCL"."ALGORITHMOUTPUTS" ADD CONSTRAINT "ALGORITHMOUTPUTS_PK" PRIMARY KEY ("ALGORITHMOUTPUT_ID")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS"  ENABLE;
  ALTER TABLE "NVCL"."ALGORITHMOUTPUTS" MODIFY ("ALGORITHMOUTPUT_ID" NOT NULL ENABLE);
  ALTER TABLE "NVCL"."ALGORITHMOUTPUTS" MODIFY ("ALGORITHMOUTPUTNAME" NOT NULL ENABLE);
--------------------------------------------------------
--  Constraints for Table LAYOUTS
--------------------------------------------------------

  ALTER TABLE "NVCL"."LAYOUTS" MODIFY ("DATASET_ID" NOT NULL ENABLE);
  ALTER TABLE "NVCL"."LAYOUTS" MODIFY ("LAYOUTNO" NOT NULL ENABLE);
  ALTER TABLE "NVCL"."LAYOUTS" ADD CONSTRAINT "LAYOUTS_PK" PRIMARY KEY ("DATASET_ID", "LAYOUTNO")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS"  ENABLE;
--------------------------------------------------------
--  Constraints for Table CLASSSPECIFICCLASSIFICATIONS
--------------------------------------------------------

  ALTER TABLE "NVCL"."CLASSSPECIFICCLASSIFICATIONS" ADD CONSTRAINT "CLASSIFICATIONSCOLOUROVER_PK" PRIMARY KEY ("LOG_ID", "INTINDEX")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS"  ENABLE;
  ALTER TABLE "NVCL"."CLASSSPECIFICCLASSIFICATIONS" MODIFY ("LOG_ID" NOT NULL ENABLE);
  ALTER TABLE "NVCL"."CLASSSPECIFICCLASSIFICATIONS" MODIFY ("INTINDEX" NOT NULL ENABLE);
  ALTER TABLE "NVCL"."CLASSSPECIFICCLASSIFICATIONS" MODIFY ("COLOUR" NOT NULL ENABLE);
--------------------------------------------------------
--  Constraints for Table CLASSLOGS
--------------------------------------------------------

  ALTER TABLE "NVCL"."CLASSLOGS" ADD CONSTRAINT "CLASSLOG_PK" PRIMARY KEY ("LOG_ID")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS"  ENABLE;
  ALTER TABLE "NVCL"."CLASSLOGS" MODIFY ("LOG_ID" NOT NULL ENABLE);
--------------------------------------------------------
--  Constraints for Table SPECTRALLOGS
--------------------------------------------------------

  ALTER TABLE "NVCL"."SPECTRALLOGS" ADD CONSTRAINT "SPECTRALLOG_PK" PRIMARY KEY ("LOG_ID")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS"  ENABLE;
  ALTER TABLE "NVCL"."SPECTRALLOGS" MODIFY ("LOG_ID" NOT NULL ENABLE);
--------------------------------------------------------
--  Constraints for Table MACHINES
--------------------------------------------------------

  ALTER TABLE "NVCL"."MACHINES" ADD CONSTRAINT "MACHINES_PK" PRIMARY KEY ("MACHINE_ID")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS"  ENABLE;
  ALTER TABLE "NVCL"."MACHINES" MODIFY ("MACHINE_ID" NOT NULL ENABLE);
  ALTER TABLE "NVCL"."MACHINES" MODIFY ("MACHINENAME" NOT NULL ENABLE);
--------------------------------------------------------
--  Constraints for Table IMAGELOGS
--------------------------------------------------------

  ALTER TABLE "NVCL"."IMAGELOGS" ADD CONSTRAINT "IMAGELOG_PK" PRIMARY KEY ("LOG_ID")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS"  ENABLE;
  ALTER TABLE "NVCL"."IMAGELOGS" MODIFY ("LOG_ID" NOT NULL ENABLE);
--------------------------------------------------------
--  Constraints for Table MASKLOGS
--------------------------------------------------------

  ALTER TABLE "NVCL"."MASKLOGS" ADD CONSTRAINT "MASKLOG_PK" PRIMARY KEY ("LOG_ID")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS"  ENABLE;
  ALTER TABLE "NVCL"."MASKLOGS" MODIFY ("LOG_ID" NOT NULL ENABLE);
--------------------------------------------------------
--  Constraints for Table CLASSLOGDATA
--------------------------------------------------------

  ALTER TABLE "NVCL"."CLASSLOGDATA" ADD CONSTRAINT "CLASSLOGDATA_PK" PRIMARY KEY ("LOG_ID", "SAMPLENUMBER")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS"  ENABLE;
  ALTER TABLE "NVCL"."CLASSLOGDATA" MODIFY ("LOG_ID" NOT NULL ENABLE);
  ALTER TABLE "NVCL"."CLASSLOGDATA" MODIFY ("SAMPLENUMBER" NOT NULL ENABLE);
--------------------------------------------------------
--  Constraints for Table DOMAINLOGDATA
--------------------------------------------------------

  ALTER TABLE "NVCL"."DOMAINLOGDATA" ADD CONSTRAINT "DOMAINLOGDATA_PK" PRIMARY KEY ("LOG_ID", "SAMPLENUMBER")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 131072 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS"  ENABLE;
  ALTER TABLE "NVCL"."DOMAINLOGDATA" MODIFY ("LOG_ID" NOT NULL ENABLE);
  ALTER TABLE "NVCL"."DOMAINLOGDATA" MODIFY ("SAMPLENUMBER" NOT NULL ENABLE);
--------------------------------------------------------
--  Constraints for Table LOGDEPENDENCIES
--------------------------------------------------------

  ALTER TABLE "NVCL"."LOGDEPENDENCIES" ADD CONSTRAINT "LOGDEPENDENCIES_PK" PRIMARY KEY ("LOG_ID", "PRIORITYORDER")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS"  ENABLE;
  ALTER TABLE "NVCL"."LOGDEPENDENCIES" MODIFY ("LOG_ID" NOT NULL ENABLE);
  ALTER TABLE "NVCL"."LOGDEPENDENCIES" MODIFY ("RELATIONNAME" NOT NULL ENABLE);
  ALTER TABLE "NVCL"."LOGDEPENDENCIES" MODIFY ("PRIORITYORDER" NOT NULL ENABLE);
--------------------------------------------------------
--  Constraints for Table LOGTYPES
--------------------------------------------------------

  ALTER TABLE "NVCL"."LOGTYPES" ADD CONSTRAINT "LOGTYPES_PK" PRIMARY KEY ("LOGTYPE_ID")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS"  ENABLE;
  ALTER TABLE "NVCL"."LOGTYPES" MODIFY ("LOGTYPE_ID" NOT NULL ENABLE);
--------------------------------------------------------
--  Constraints for Table ALGORITHMS
--------------------------------------------------------

  ALTER TABLE "NVCL"."ALGORITHMS" ADD CONSTRAINT "ALGORITHMS_ISPUBLIC_CHK" CHECK (
ISPUBLIC in (0,1)
) ENABLE;
  ALTER TABLE "NVCL"."ALGORITHMS" ADD CONSTRAINT "ALGORITHMS_PK" PRIMARY KEY ("ALGORITHM_ID")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS"  ENABLE;
  ALTER TABLE "NVCL"."ALGORITHMS" MODIFY ("ALGORITHM_ID" NOT NULL ENABLE);
  ALTER TABLE "NVCL"."ALGORITHMS" MODIFY ("ISPUBLIC" NOT NULL ENABLE);
--------------------------------------------------------
--  Constraints for Table CALIBRATIONLOGS
--------------------------------------------------------

  ALTER TABLE "NVCL"."CALIBRATIONLOGS" MODIFY ("LOG_ID" NOT NULL ENABLE);
  ALTER TABLE "NVCL"."CALIBRATIONLOGS" ADD CONSTRAINT "CALIBRATIONLOG_PK" PRIMARY KEY ("LOG_ID")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS"  ENABLE;
--------------------------------------------------------
--  Constraints for Table PLSDATA
--------------------------------------------------------

  ALTER TABLE "NVCL"."PLSDATA" MODIFY ("PLS_ID" NOT NULL ENABLE);
  ALTER TABLE "NVCL"."PLSDATA" MODIFY ("DATASET_ID" NOT NULL ENABLE);
  ALTER TABLE "NVCL"."PLSDATA" MODIFY ("PLSNAME" NOT NULL ENABLE);
  ALTER TABLE "NVCL"."PLSDATA" MODIFY ("PLSDATA" NOT NULL ENABLE);
  ALTER TABLE "NVCL"."PLSDATA" ADD CONSTRAINT "PLSDATA_PK" PRIMARY KEY ("PLS_ID")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS"  ENABLE;
--------------------------------------------------------
--  Constraints for Table DECIMALLOGS
--------------------------------------------------------

  ALTER TABLE "NVCL"."DECIMALLOGS" ADD CONSTRAINT "DECIMALLOGS_ISRBGCOLOUR_CHK" CHECK (
resultisrgbcolour in (0,1)
) ENABLE;
  ALTER TABLE "NVCL"."DECIMALLOGS" ADD CONSTRAINT "DECIMALLOG_PK" PRIMARY KEY ("LOG_ID")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS"  ENABLE;
  ALTER TABLE "NVCL"."DECIMALLOGS" MODIFY ("LOG_ID" NOT NULL ENABLE);
--------------------------------------------------------
--  Constraints for Table IMAGELOGDATA
--------------------------------------------------------

  ALTER TABLE "NVCL"."IMAGELOGDATA" ADD CONSTRAINT "IMAGELOGDATA_PK" PRIMARY KEY ("LOG_ID", "SAMPLENUMBER")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS"  ENABLE;
  ALTER TABLE "NVCL"."IMAGELOGDATA" MODIFY ("LOG_ID" NOT NULL ENABLE);
  ALTER TABLE "NVCL"."IMAGELOGDATA" MODIFY ("SAMPLENUMBER" NOT NULL ENABLE);
--------------------------------------------------------
--  Constraints for Table DATASETSTATS
--------------------------------------------------------

  ALTER TABLE "NVCL"."DATASETSTATS" ADD CONSTRAINT "DATASETSTATS_PK" PRIMARY KEY ("DATASETSTATS_ID")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS"  ENABLE;
  ALTER TABLE "NVCL"."DATASETSTATS" MODIFY ("DATASETSTATS_ID" NOT NULL ENABLE);
--------------------------------------------------------
--  Constraints for Table TSARETRAINING
--------------------------------------------------------

  ALTER TABLE "NVCL"."TSARETRAINING" MODIFY ("TSARETRAINING_ID" NOT NULL ENABLE);
  ALTER TABLE "NVCL"."TSARETRAINING" ADD CONSTRAINT "TSARETRAINING_PK" PRIMARY KEY ("TSARETRAINING_ID")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS"  ENABLE;
--------------------------------------------------------
--  Constraints for Table CALIBRATIONLOGDATA
--------------------------------------------------------

  ALTER TABLE "NVCL"."CALIBRATIONLOGDATA" MODIFY ("LOG_ID" NOT NULL ENABLE);
  ALTER TABLE "NVCL"."CALIBRATIONLOGDATA" MODIFY ("SAMPLENUMBER" NOT NULL ENABLE);
  ALTER TABLE "NVCL"."CALIBRATIONLOGDATA" ADD CONSTRAINT "CALIBRATIONLOGDATA_PK" PRIMARY KEY ("LOG_ID", "SAMPLENUMBER")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS"  ENABLE;
--------------------------------------------------------
--  Constraints for Table SCALARGROUPS
--------------------------------------------------------

  ALTER TABLE "NVCL"."SCALARGROUPS" ADD CONSTRAINT "SCALARGROUPS_PK" PRIMARY KEY ("SCALARGROUP_ID")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS"  ENABLE;
  ALTER TABLE "NVCL"."SCALARGROUPS" MODIFY ("SCALARGROUP_ID" NOT NULL ENABLE);
--------------------------------------------------------
--  Constraints for Table DECIMALLOGDATA
--------------------------------------------------------

  ALTER TABLE "NVCL"."DECIMALLOGDATA" ADD CONSTRAINT "DECIMALLOGDATA_PK" PRIMARY KEY ("LOG_ID", "SAMPLENUMBER")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 131072 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS"  ENABLE;
  ALTER TABLE "NVCL"."DECIMALLOGDATA" MODIFY ("LOG_ID" NOT NULL ENABLE);
  ALTER TABLE "NVCL"."DECIMALLOGDATA" MODIFY ("SAMPLENUMBER" NOT NULL ENABLE);
--------------------------------------------------------
--  Constraints for Table SCALARSETS
--------------------------------------------------------

  ALTER TABLE "NVCL"."SCALARSETS" ADD CONSTRAINT "SCALARSET_PK" PRIMARY KEY ("DATASET_ID", "SETNUMBER")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS"  ENABLE;
  ALTER TABLE "NVCL"."SCALARSETS" MODIFY ("DATASET_ID" NOT NULL ENABLE);
  ALTER TABLE "NVCL"."SCALARSETS" MODIFY ("SETNUMBER" NOT NULL ENABLE);
--------------------------------------------------------
--  Constraints for Table DATASETS
--------------------------------------------------------

  ALTER TABLE "NVCL"."DATASETS" ADD CONSTRAINT "DATASETS_ISPUBLIC_CHK" CHECK (ispublic in (0,1)) ENABLE;
  ALTER TABLE "NVCL"."DATASETS" ADD CONSTRAINT "DATASETS_ISREFLIBRARY_CHK" CHECK (
ISREFERENCELIBRARY in (0,1)
) ENABLE;
  ALTER TABLE "NVCL"."DATASETS" MODIFY ("DATASET_ID" NOT NULL ENABLE);
  ALTER TABLE "NVCL"."DATASETS" MODIFY ("ISPUBLIC" NOT NULL ENABLE);
  ALTER TABLE "NVCL"."DATASETS" ADD CONSTRAINT "TSGDATASET_PK" PRIMARY KEY ("DATASET_ID")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS"  ENABLE;
--------------------------------------------------------
--  Constraints for Table SPECTRALLOGDATA
--------------------------------------------------------

  ALTER TABLE "NVCL"."SPECTRALLOGDATA" ADD CONSTRAINT "SPECTRALLOGDATA_PK" PRIMARY KEY ("LOG_ID", "SAMPLENUMBER")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS"  ENABLE;
  ALTER TABLE "NVCL"."SPECTRALLOGDATA" MODIFY ("LOG_ID" NOT NULL ENABLE);
  ALTER TABLE "NVCL"."SPECTRALLOGDATA" MODIFY ("SAMPLENUMBER" NOT NULL ENABLE);
--------------------------------------------------------
--  Constraints for Table CLASSIFICATIONS
--------------------------------------------------------

  ALTER TABLE "NVCL"."CLASSIFICATIONS" ADD CONSTRAINT "CLASSIFICATIONS_PK" PRIMARY KEY ("ALGORITHMOUTPUT_ID", "INTINDEX")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS"  ENABLE;
  ALTER TABLE "NVCL"."CLASSIFICATIONS" MODIFY ("ALGORITHMOUTPUT_ID" NOT NULL ENABLE);
  ALTER TABLE "NVCL"."CLASSIFICATIONS" MODIFY ("INTINDEX" NOT NULL ENABLE);
  ALTER TABLE "NVCL"."CLASSIFICATIONS" MODIFY ("COLOUR" NOT NULL ENABLE);
  ALTER TABLE "NVCL"."CLASSIFICATIONS" MODIFY ("CLASSTEXT" NOT NULL ENABLE);
--------------------------------------------------------
--  Constraints for Table MASKLOGDATA
--------------------------------------------------------

  ALTER TABLE "NVCL"."MASKLOGDATA" ADD CONSTRAINT "MASKLOGDATA_CHK" CHECK (
maskvalue in (0, 1)
) ENABLE;
  ALTER TABLE "NVCL"."MASKLOGDATA" ADD CONSTRAINT "MASKLOGDATA_PK" PRIMARY KEY ("LOG_ID", "SAMPLENUMBER")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS"  ENABLE;
  ALTER TABLE "NVCL"."MASKLOGDATA" MODIFY ("LOG_ID" NOT NULL ENABLE);
  ALTER TABLE "NVCL"."MASKLOGDATA" MODIFY ("SAMPLENUMBER" NOT NULL ENABLE);
--------------------------------------------------------
--  Constraints for Table DOMAINLOGS
--------------------------------------------------------

  ALTER TABLE "NVCL"."DOMAINLOGS" ADD CONSTRAINT "DOMAINLOGS_PK" PRIMARY KEY ("LOG_ID")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS"  ENABLE;
  ALTER TABLE "NVCL"."DOMAINLOGS" MODIFY ("LOG_ID" NOT NULL ENABLE);
--------------------------------------------------------
--  Constraints for Table PROFLOGDATA
--------------------------------------------------------

  ALTER TABLE "NVCL"."PROFLOGDATA" ADD CONSTRAINT "PROFLOGDATA_PK" PRIMARY KEY ("LOG_ID", "SAMPLENUMBER")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS"  ENABLE;
  ALTER TABLE "NVCL"."PROFLOGDATA" MODIFY ("LOG_ID" NOT NULL ENABLE);
  ALTER TABLE "NVCL"."PROFLOGDATA" MODIFY ("SAMPLENUMBER" NOT NULL ENABLE);
--------------------------------------------------------
--  Constraints for Table LOGS
--------------------------------------------------------

  ALTER TABLE "NVCL"."LOGS" ADD CONSTRAINT "LOGS_ISPUBLIC_CHK" CHECK (
ispublic in (0,1)
) ENABLE;
  ALTER TABLE "NVCL"."LOGS" ADD CONSTRAINT "LOGS_PK" PRIMARY KEY ("LOG_ID")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS"  ENABLE;
  ALTER TABLE "NVCL"."LOGS" MODIFY ("LOG_ID" NOT NULL ENABLE);
  ALTER TABLE "NVCL"."LOGS" MODIFY ("DATASET_ID" NOT NULL ENABLE);
  ALTER TABLE "NVCL"."LOGS" MODIFY ("ISPUBLIC" NOT NULL ENABLE);
--------------------------------------------------------
--  Constraints for Table PROFLOGS
--------------------------------------------------------

  ALTER TABLE "NVCL"."PROFLOGS" ADD CONSTRAINT "PROFLOG_PK" PRIMARY KEY ("LOG_ID")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1  BUFFER_POOL DEFAULT)
  TABLESPACE "NVCLINDTS"  ENABLE;
  ALTER TABLE "NVCL"."PROFLOGS" MODIFY ("LOG_ID" NOT NULL ENABLE);
--------------------------------------------------------
--  Constraints for Table EVENTJOURNAL
--------------------------------------------------------

  ALTER TABLE "NVCL"."EVENTJOURNAL" ADD CONSTRAINT "EVENTJOURNAL_PK" PRIMARY KEY ("DATASET_ID", "EVENTNUMBER", "ISPRIMARY")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 
  TABLESPACE "NVCLTBLSPC"  ENABLE;
  ALTER TABLE "NVCL"."EVENTJOURNAL" MODIFY ("EVENTNUMBER" NOT NULL ENABLE);
  ALTER TABLE "NVCL"."EVENTJOURNAL" MODIFY ("DATASET_ID" NOT NULL ENABLE);
--------------------------------------------------------
--  Ref Constraints for Table ALGORITHMOUTPUTS
--------------------------------------------------------

  ALTER TABLE "NVCL"."ALGORITHMOUTPUTS" ADD CONSTRAINT "ALGORITHMOUTPUTS_ALGORITH_FK1" FOREIGN KEY ("ALGORITHM_ID")
	  REFERENCES "NVCL"."ALGORITHMS" ("ALGORITHM_ID") ON DELETE CASCADE ENABLE;
  ALTER TABLE "NVCL"."ALGORITHMOUTPUTS" ADD CONSTRAINT "ALGORITHMS_LOGTYPES_FK" FOREIGN KEY ("OUTPUTLOGTYPE")
	  REFERENCES "NVCL"."LOGTYPES" ("LOGTYPE_ID") ENABLE;
--------------------------------------------------------
--  Ref Constraints for Table CALIBRATIONLOGDATA
--------------------------------------------------------

  ALTER TABLE "NVCL"."CALIBRATIONLOGDATA" ADD CONSTRAINT "CALIBLOGDATA_CALIBLOGS_FK" FOREIGN KEY ("LOG_ID")
	  REFERENCES "NVCL"."CALIBRATIONLOGS" ("LOG_ID") ON DELETE CASCADE ENABLE;
--------------------------------------------------------
--  Ref Constraints for Table CALIBRATIONLOGS
--------------------------------------------------------

  ALTER TABLE "NVCL"."CALIBRATIONLOGS" ADD CONSTRAINT "CALIBRATIONLOGS_LOGS_FK" FOREIGN KEY ("LOG_ID")
	  REFERENCES "NVCL"."LOGS" ("LOG_ID") ON DELETE CASCADE ENABLE;
--------------------------------------------------------
--  Ref Constraints for Table CLASSIFICATIONS
--------------------------------------------------------

  ALTER TABLE "NVCL"."CLASSIFICATIONS" ADD CONSTRAINT "CLASSIFICATIONS_ALGORITHM_FK1" FOREIGN KEY ("ALGORITHMOUTPUT_ID")
	  REFERENCES "NVCL"."ALGORITHMOUTPUTS" ("ALGORITHMOUTPUT_ID") ON DELETE CASCADE ENABLE;
--------------------------------------------------------
--  Ref Constraints for Table CLASSLOGDATA
--------------------------------------------------------

  ALTER TABLE "NVCL"."CLASSLOGDATA" ADD CONSTRAINT "CLASSLOGDATA_CLASSLOG_FK" FOREIGN KEY ("LOG_ID")
	  REFERENCES "NVCL"."CLASSLOGS" ("LOG_ID") ON DELETE CASCADE ENABLE;
--------------------------------------------------------
--  Ref Constraints for Table CLASSLOGS
--------------------------------------------------------

  ALTER TABLE "NVCL"."CLASSLOGS" ADD CONSTRAINT "CLASSLOGS_LOGS_FK" FOREIGN KEY ("LOG_ID")
	  REFERENCES "NVCL"."LOGS" ("LOG_ID") ON DELETE CASCADE ENABLE;
  ALTER TABLE "NVCL"."CLASSLOGS" ADD CONSTRAINT "CLASSSCALARGROUP_FK" FOREIGN KEY ("SCALARGROUP_ID")
	  REFERENCES "NVCL"."SCALARGROUPS" ("SCALARGROUP_ID") ENABLE;
--------------------------------------------------------
--  Ref Constraints for Table CLASSSPECIFICCLASSIFICATIONS
--------------------------------------------------------

  ALTER TABLE "NVCL"."CLASSSPECIFICCLASSIFICATIONS" ADD CONSTRAINT "CLASSSPEC_CLASSLOG_FK" FOREIGN KEY ("LOG_ID")
	  REFERENCES "NVCL"."CLASSLOGS" ("LOG_ID") ON DELETE CASCADE ENABLE;
--------------------------------------------------------
--  Ref Constraints for Table DATASETS
--------------------------------------------------------

  ALTER TABLE "NVCL"."DATASETS" ADD CONSTRAINT "CUSTCALCDATASETS_DATASETS_FK1" FOREIGN KEY ("CUSTCALCDATASET_ID")
	  REFERENCES "NVCL"."DATASETS" ("DATASET_ID") ENABLE;
  ALTER TABLE "NVCL"."DATASETS" ADD CONSTRAINT "CUSTOMDATASET_DATASETS_FK1" FOREIGN KEY ("CUSTOMDATASET_ID")
	  REFERENCES "NVCL"."DATASETS" ("DATASET_ID") ENABLE;
  ALTER TABLE "NVCL"."DATASETS" ADD CONSTRAINT "DATASETS_DOMAINLOGS_FK" FOREIGN KEY ("DOMAIN_ID")
	  REFERENCES "NVCL"."DOMAINLOGS" ("LOG_ID") ENABLE;
  ALTER TABLE "NVCL"."DATASETS" ADD CONSTRAINT "DATASETS_IMAGELOGS_FK" FOREIGN KEY ("IMAGELOG_ID")
	  REFERENCES "NVCL"."IMAGELOGS" ("LOG_ID") ENABLE;
  ALTER TABLE "NVCL"."DATASETS" ADD CONSTRAINT "DATASETS_MACHINES_FK" FOREIGN KEY ("PRIMARYLOGGER_ID")
	  REFERENCES "NVCL"."MACHINES" ("MACHINE_ID") ENABLE;
  ALTER TABLE "NVCL"."DATASETS" ADD CONSTRAINT "DATASETS_PROFLOGS_FK" FOREIGN KEY ("PROFLOG_ID")
	  REFERENCES "NVCL"."PROFLOGS" ("LOG_ID") ENABLE;
  ALTER TABLE "NVCL"."DATASETS" ADD CONSTRAINT "DATASETS_SECTION_LOGS_FK" FOREIGN KEY ("SECTIONLOG_ID")
	  REFERENCES "NVCL"."LOGS" ("LOG_ID") ENABLE;
  ALTER TABLE "NVCL"."DATASETS" ADD CONSTRAINT "DATASETS_SPECTRALLOGS_FK" FOREIGN KEY ("SPECLOG_ID")
	  REFERENCES "NVCL"."SPECTRALLOGS" ("LOG_ID") ENABLE;
  ALTER TABLE "NVCL"."DATASETS" ADD CONSTRAINT "DATASETS_TRAY_LOGS_FK" FOREIGN KEY ("TRAYLOG_ID")
	  REFERENCES "NVCL"."LOGS" ("LOG_ID") ENABLE;
--------------------------------------------------------
--  Ref Constraints for Table DECIMALLOGDATA
--------------------------------------------------------

  ALTER TABLE "NVCL"."DECIMALLOGDATA" ADD CONSTRAINT "DECIMALLOGDATA_DECIMALLOG_FK" FOREIGN KEY ("LOG_ID")
	  REFERENCES "NVCL"."DECIMALLOGS" ("LOG_ID") ON DELETE CASCADE ENABLE;
--------------------------------------------------------
--  Ref Constraints for Table DECIMALLOGS
--------------------------------------------------------

  ALTER TABLE "NVCL"."DECIMALLOGS" ADD CONSTRAINT "DECIMALLOGS_LOGS_FK" FOREIGN KEY ("LOG_ID")
	  REFERENCES "NVCL"."LOGS" ("LOG_ID") ON DELETE CASCADE ENABLE;
  ALTER TABLE "NVCL"."DECIMALLOGS" ADD CONSTRAINT "DECIMALSCALARGROUP_FK" FOREIGN KEY ("SCALARGROUP_ID")
	  REFERENCES "NVCL"."SCALARGROUPS" ("SCALARGROUP_ID") ENABLE;
--------------------------------------------------------
--  Ref Constraints for Table DOMAINLOGDATA
--------------------------------------------------------

  ALTER TABLE "NVCL"."DOMAINLOGDATA" ADD CONSTRAINT "DOMAINLOGDATA_DOMAINLOGS_FK" FOREIGN KEY ("LOG_ID")
	  REFERENCES "NVCL"."DOMAINLOGS" ("LOG_ID") ON DELETE CASCADE ENABLE;
--------------------------------------------------------
--  Ref Constraints for Table DOMAINLOGS
--------------------------------------------------------

  ALTER TABLE "NVCL"."DOMAINLOGS" ADD CONSTRAINT "DOMAINLOGS_LOGS_FK1" FOREIGN KEY ("LOG_ID")
	  REFERENCES "NVCL"."LOGS" ("LOG_ID") ON DELETE CASCADE ENABLE;
  ALTER TABLE "NVCL"."DOMAINLOGS" ADD CONSTRAINT "DOMAINSCALARGROUP_FK" FOREIGN KEY ("SCALARGROUP_ID")
	  REFERENCES "NVCL"."SCALARGROUPS" ("SCALARGROUP_ID") ENABLE;
--------------------------------------------------------
--  Ref Constraints for Table EVENTJOURNAL
--------------------------------------------------------

  ALTER TABLE "NVCL"."EVENTJOURNAL" ADD CONSTRAINT "EVENTJOURNAL_DATASETS_FK" FOREIGN KEY ("DATASET_ID")
	  REFERENCES "NVCL"."DATASETS" ("DATASET_ID") ON DELETE CASCADE ENABLE;
--------------------------------------------------------
--  Ref Constraints for Table IMAGELOGDATA
--------------------------------------------------------

  ALTER TABLE "NVCL"."IMAGELOGDATA" ADD CONSTRAINT "IMAGELOGDATA_IMAGELOGS_FK" FOREIGN KEY ("LOG_ID")
	  REFERENCES "NVCL"."IMAGELOGS" ("LOG_ID") ON DELETE CASCADE ENABLE;
--------------------------------------------------------
--  Ref Constraints for Table IMAGELOGS
--------------------------------------------------------

  ALTER TABLE "NVCL"."IMAGELOGS" ADD CONSTRAINT "IMAGELOGS_LOGS_FK" FOREIGN KEY ("LOG_ID")
	  REFERENCES "NVCL"."LOGS" ("LOG_ID") ON DELETE CASCADE ENABLE;
--------------------------------------------------------
--  Ref Constraints for Table LAYOUTS
--------------------------------------------------------

  ALTER TABLE "NVCL"."LAYOUTS" ADD CONSTRAINT "LAYOUTS_DATASETS_FK" FOREIGN KEY ("DATASET_ID")
	  REFERENCES "NVCL"."DATASETS" ("DATASET_ID") ON DELETE CASCADE ENABLE;
--------------------------------------------------------
--  Ref Constraints for Table LOGDEPENDENCIES
--------------------------------------------------------

  ALTER TABLE "NVCL"."LOGDEPENDENCIES" ADD CONSTRAINT "LOGDEPENDENCIES_DEP_LOGS_FK" FOREIGN KEY ("DEPENDSON")
	  REFERENCES "NVCL"."LOGS" ("LOG_ID") DEFERRABLE INITIALLY DEFERRED ENABLE;
  ALTER TABLE "NVCL"."LOGDEPENDENCIES" ADD CONSTRAINT "LOGDEPENDENCIES_LOGS_FK" FOREIGN KEY ("LOG_ID")
	  REFERENCES "NVCL"."LOGS" ("LOG_ID") ON DELETE CASCADE ENABLE;
--------------------------------------------------------
--  Ref Constraints for Table LOGS
--------------------------------------------------------

  ALTER TABLE "NVCL"."LOGS" ADD CONSTRAINT "LOGS_ALGORITHMOUTPUTS_FK" FOREIGN KEY ("ALGORITHMOUTPUT_ID")
	  REFERENCES "NVCL"."ALGORITHMOUTPUTS" ("ALGORITHMOUTPUT_ID") ENABLE;
  ALTER TABLE "NVCL"."LOGS" ADD CONSTRAINT "LOGS_AUX_SPECTRALLOGS_FK" FOREIGN KEY ("AUXSPECTRALLAYER_ID")
	  REFERENCES "NVCL"."SPECTRALLOGS" ("LOG_ID") ENABLE;
  ALTER TABLE "NVCL"."LOGS" ADD CONSTRAINT "LOGS_DATASETSTATS_FK" FOREIGN KEY ("REFSTATS_ID")
	  REFERENCES "NVCL"."DATASETSTATS" ("DATASETSTATS_ID") ENABLE;
  ALTER TABLE "NVCL"."LOGS" ADD CONSTRAINT "LOGS_DATASETS_FK" FOREIGN KEY ("DATASET_ID")
	  REFERENCES "NVCL"."DATASETS" ("DATASET_ID") ON DELETE CASCADE ENABLE;
  ALTER TABLE "NVCL"."LOGS" ADD CONSTRAINT "LOGS_DOMAINLOGS_FK" FOREIGN KEY ("DOMAINLOG_ID")
	  REFERENCES "NVCL"."DOMAINLOGS" ("LOG_ID") DEFERRABLE INITIALLY DEFERRED ENABLE;
  ALTER TABLE "NVCL"."LOGS" ADD CONSTRAINT "LOGS_LAYER_SPECTRALLOGS_FK" FOREIGN KEY ("LOCALSPECTRALLAYER_ID")
	  REFERENCES "NVCL"."SPECTRALLOGS" ("LOG_ID") ENABLE;
  ALTER TABLE "NVCL"."LOGS" ADD CONSTRAINT "LOGS_LOGTYPES_FK" FOREIGN KEY ("LOGTYPE")
	  REFERENCES "NVCL"."LOGTYPES" ("LOGTYPE_ID") ENABLE;
  ALTER TABLE "NVCL"."LOGS" ADD CONSTRAINT "LOGS_MASKLOGS_FK1" FOREIGN KEY ("MASKLOG_ID")
	  REFERENCES "NVCL"."LOGS" ("LOG_ID") DEFERRABLE INITIALLY DEFERRED ENABLE;
  ALTER TABLE "NVCL"."LOGS" ADD CONSTRAINT "LOGS_PLSDATA_FK" FOREIGN KEY ("PLS_ID")
	  REFERENCES "NVCL"."PLSDATA" ("PLS_ID") ENABLE;
  ALTER TABLE "NVCL"."LOGS" ADD CONSTRAINT "LOGS_TSARETRAINING_FK" FOREIGN KEY ("TSARETRAINING_ID")
	  REFERENCES "NVCL"."TSARETRAINING" ("TSARETRAINING_ID") ENABLE;
--------------------------------------------------------
--  Ref Constraints for Table MASKLOGDATA
--------------------------------------------------------

  ALTER TABLE "NVCL"."MASKLOGDATA" ADD CONSTRAINT "MASKLOGDATA_MASKLOGS_FK" FOREIGN KEY ("LOG_ID")
	  REFERENCES "NVCL"."MASKLOGS" ("LOG_ID") ON DELETE CASCADE ENABLE;
--------------------------------------------------------
--  Ref Constraints for Table MASKLOGS
--------------------------------------------------------

  ALTER TABLE "NVCL"."MASKLOGS" ADD CONSTRAINT "MASKLOGS_LOGS_FK" FOREIGN KEY ("LOG_ID")
	  REFERENCES "NVCL"."LOGS" ("LOG_ID") ON DELETE CASCADE ENABLE;
  ALTER TABLE "NVCL"."MASKLOGS" ADD CONSTRAINT "MASKSCALARGROUP_FK" FOREIGN KEY ("SCALARGROUP_ID")
	  REFERENCES "NVCL"."SCALARGROUPS" ("SCALARGROUP_ID") ENABLE;
--------------------------------------------------------
--  Ref Constraints for Table PROFLOGDATA
--------------------------------------------------------

  ALTER TABLE "NVCL"."PROFLOGDATA" ADD CONSTRAINT "PROFLOGDATA_PROFLOGS_FK" FOREIGN KEY ("LOG_ID")
	  REFERENCES "NVCL"."PROFLOGS" ("LOG_ID") ON DELETE CASCADE ENABLE;
--------------------------------------------------------
--  Ref Constraints for Table PROFLOGS
--------------------------------------------------------

  ALTER TABLE "NVCL"."PROFLOGS" ADD CONSTRAINT "PROFLOGS_LOGS_FK" FOREIGN KEY ("LOG_ID")
	  REFERENCES "NVCL"."LOGS" ("LOG_ID") ON DELETE CASCADE ENABLE;
--------------------------------------------------------
--  Ref Constraints for Table SCALARGROUPS
--------------------------------------------------------

  ALTER TABLE "NVCL"."SCALARGROUPS" ADD CONSTRAINT "SCALARGROUPPARENT_FK" FOREIGN KEY ("PARENTSCALARGROUP_ID")
	  REFERENCES "NVCL"."SCALARGROUPS" ("SCALARGROUP_ID") ENABLE;
--------------------------------------------------------
--  Ref Constraints for Table SCALARSETS
--------------------------------------------------------

  ALTER TABLE "NVCL"."SCALARSETS" ADD CONSTRAINT "SCALARSET_DATASETS_FK" FOREIGN KEY ("DATASET_ID")
	  REFERENCES "NVCL"."DATASETS" ("DATASET_ID") ON DELETE CASCADE ENABLE;
--------------------------------------------------------
--  Ref Constraints for Table SPECTRALLOGDATA
--------------------------------------------------------

  ALTER TABLE "NVCL"."SPECTRALLOGDATA" ADD CONSTRAINT "SPECTRALLOGDATA_SPECTRALL_FK" FOREIGN KEY ("LOG_ID")
	  REFERENCES "NVCL"."SPECTRALLOGS" ("LOG_ID") ON DELETE CASCADE ENABLE;
--------------------------------------------------------
--  Ref Constraints for Table SPECTRALLOGS
--------------------------------------------------------

  ALTER TABLE "NVCL"."SPECTRALLOGS" ADD CONSTRAINT "SPECTRALLOGS_LOGS_FK" FOREIGN KEY ("LOG_ID")
	  REFERENCES "NVCL"."LOGS" ("LOG_ID") ON DELETE CASCADE ENABLE;
--------------------------------------------------------
--  DDL for Function GETDATAPOINTS
--------------------------------------------------------

  CREATE OR REPLACE FUNCTION "NVCL"."GETDATAPOINTS" ( v_logid IN VARCHAR2
) RETURN NUMBER AS
curlogtype number;
datapointcount number;
BEGIN
  SELECT logtype into curlogtype from Logs WHERE log_id= v_logid;
  CASE curlogtype
    WHEN 0 THEN SELECT count(*) into datapointcount FROM domainlogdata WHERE log_id=v_logid;
    WHEN 1 THEN SELECT count(*) into datapointcount FROM classlogdata WHERE log_id=v_logid;
    WHEN 2 THEN SELECT count(*) into datapointcount FROM decimallogdata WHERE log_id=v_logid;
    WHEN 3 THEN SELECT count(*) into datapointcount FROM imagelogdata WHERE log_id=v_logid;
    WHEN 4 THEN SELECT count(*) into datapointcount FROM proflogdata WHERE log_id=v_logid;
    WHEN 5 THEN SELECT count(*) into datapointcount FROM spectrallogdata WHERE log_id=v_logid;
    WHEN 6 THEN SELECT count(*) into datapointcount FROM masklogdata WHERE log_id=v_logid;
	WHEN 7 THEN SELECT count(*) into datapointcount FROM calibrationlogdata WHERE log_id=v_logid;
  END CASE;
  return datapointcount;
  EXCEPTION
    WHEN NO_DATA_FOUND THEN return 0;
END GETDATAPOINTS;

/

  GRANT EXECUTE ON "NVCL"."GETDATAPOINTS" TO "NVCLVIEWER";
  GRANT EXECUTE ON "NVCL"."GETDATAPOINTS" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Function GETDOMAINDATA
--------------------------------------------------------

  CREATE OR REPLACE FUNCTION "NVCL"."GETDOMAINDATA" (v_domainlog_id VARCHAR2) RETURN TYPES.REF_CURSOR AS
	subdomid VARCHAR2(64);
  tmpstr VARCHAR2(4000):=' ';
 curs TYPES.REF_CURSOR;
BEGIN
  SELECT issubdomainoflog_id INTO subdomid FROM domainlogs WHERE log_id = v_domainlog_id;
    if (subdomid IS NULL) then
       OPEN curs FOR 'SELECT samplenumber,startvalue,endvalue,samplename FROM DOMAINLOGDATA WHERE LOG_ID=''' || v_domainlog_id || ''' ORDER BY samplenumber';
    else
      tmpstr:=GETDOMAINDATASTR(subdomid);
      OPEN curs FOR 'SELECT subdom.samplenumber,min(maindom.startvalue) as startvalue,max(maindom.endvalue) as endvalue,subdom.samplename FROM (' || tmpstr || ') maindom inner join domainlogdata subdom on maindom.samplenumber BETWEEN subdom.startvalue ANd subdom.endvalue WHERE subdom.log_id=''' || v_domainlog_id || ''' Group BY subdom.samplenumber,subdom.samplename ORDER by subdom.samplenumber';
  end if;
--  OPEN curs FOR getdomaindatastr(v_domainlog_id);
  return curs;
END GETDOMAINDATA;

/

  GRANT EXECUTE ON "NVCL"."GETDOMAINDATA" TO "WEBSERVICE";
  GRANT EXECUTE ON "NVCL"."GETDOMAINDATA" TO "NVCLVIEWER";
  GRANT EXECUTE ON "NVCL"."GETDOMAINDATA" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Function GETDOMAINDATAASBASESPS
--------------------------------------------------------

  CREATE OR REPLACE FUNCTION "NVCL"."GETDOMAINDATAASBASESPS" (v_domainlog_id VARCHAR2) RETURN TYPES.REF_CURSOR AS
 curs TYPES.REF_CURSOR;
 subdomid VARCHAR2(64);
BEGIN
  SELECT issubdomainoflog_id INTO subdomid FROM domainlogs WHERE log_id = v_domainlog_id;
  if (subdomid is not null) then
  OPEN curs FOR getdomaindatastrsps(v_domainlog_id);
  return curs;
  end if;
  return null;
END GETDOMAINDATAASBASESPS;

/

  GRANT EXECUTE ON "NVCL"."GETDOMAINDATAASBASESPS" TO "NVCLVIEWER";
  GRANT EXECUTE ON "NVCL"."GETDOMAINDATAASBASESPS" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Function GETDOMAINDATASTR
--------------------------------------------------------

  CREATE OR REPLACE FUNCTION "NVCL"."GETDOMAINDATASTR" ( v_domainlog_id IN VARCHAR2) return varchar2
AS
	subdomid VARCHAR2(64);
  retstr VARCHAR2(4000);
  tmpstr VARCHAR2(4000):=' ';
BEGIN
  SELECT issubdomainoflog_id INTO subdomid FROM domainlogs WHERE log_id = v_domainlog_id;
    if (subdomid IS NULL) then
      retstr:= 'SELECT samplenumber,startvalue,endvalue,samplename FROM DOMAINLOGDATA WHERE LOG_ID=''' || v_domainlog_id || ''' ORDER BY samplenumber';
    else
      tmpstr:=GETDOMAINDATASTR(subdomid);
      retstr:= 'SELECT subdom.samplenumber,min(maindom.startvalue) as startvalue,max(maindom.endvalue) as endvalue,subdom.samplename FROM (' || tmpstr || ') maindom inner join domainlogdata subdom on maindom.samplenumber BETWEEN subdom.startvalue ANd subdom.endvalue WHERE subdom.log_id=''' || v_domainlog_id || ''' Group BY subdom.samplenumber,subdom.samplename ORDER by subdom.samplenumber';
   end if;
    return retstr;
END;

/

  GRANT EXECUTE ON "NVCL"."GETDOMAINDATASTR" TO "NVCLVIEWER";
  GRANT EXECUTE ON "NVCL"."GETDOMAINDATASTR" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Function GETDOMAINDATASTRSPS
--------------------------------------------------------

  CREATE OR REPLACE FUNCTION "NVCL"."GETDOMAINDATASTRSPS" ( v_domainlog_id IN VARCHAR2) return varchar2
AS
  subdomid VARCHAR2(64);
  subsubdomid VARCHAR2(64);
  retstr varchar2(4000);
  tmpstr varchar2(4000):=' ';
BEGIN
  SELECT issubdomainoflog_id INTO subdomid FROM domainlogs WHERE log_id = v_domainlog_id;
  if(subdomid is not null) then
    SELECT issubdomainoflog_id INTO subsubdomid FROM domainlogs WHERE log_id = subdomid;
  end if;
  if (subsubdomid IS NULL) then
    retstr:= 'SELECT samplenumber,startvalue,endvalue,samplename,description,colour,swirminlist,swirtsaversion,vnirminlist,vnirtsaversion,tirminlist,tirtsaversion FROM DOMAINLOGDATA WHERE LOG_ID=''' || v_domainlog_id || ''' ORDER BY samplenumber';
  else
    tmpstr:=GETDOMAINDATASTR(subdomid);
    retstr:= 'SELECT subdom.samplenumber,min(maindom.startvalue) as startvalue,max(maindom.endvalue) as endvalue,subdom.samplename,subdom.description,subdom.colour,subdom.swirminlist,subdom.swirtsaversion,subdom.vnirminlist,subdom.vnirtsaversion,subdom.tirminlist,subdom.tirtsaversion FROM (' || tmpstr || ') maindom inner join domainlogdata subdom on maindom.samplenumber BETWEEN subdom.startvalue ANd subdom.endvalue WHERE subdom.log_id=''' || v_domainlog_id || ''' Group BY subdom.samplenumber,subdom.samplename ORDER by subdom.samplenumber';
  end if;
  return retstr;
END;

/

  GRANT EXECUTE ON "NVCL"."GETDOMAINDATASTRSPS" TO "NVCLVIEWER";
  GRANT EXECUTE ON "NVCL"."GETDOMAINDATASTRSPS" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Function GETDOWNSAMPLEDLOGVALUES
--------------------------------------------------------

  create or replace FUNCTION "NVCL"."GETDOWNSAMPLEDLOGVALUES" 
( v_logid IN VARCHAR2
, v_startdepth IN FLOAT
, v_enddepth IN FLOAT
, v_interval IN FLOAT:=1
, v_threshold in FLOAT:=5
) RETURN types.ref_cursor AS
out_rs types.ref_cursor;
logtype NUMBER;
stdalg number;
masklogid varchar2(200);
BEGIN
  SELECT logs.logtype,logs.algorithmoutput_id,MASKLOG_ID into logtype, stdalg , masklogid from logs where log_id= v_logid;
  CASE logtype
    WHEN 1 THEN 
      if (stdalg is null) then 
        if (masklogid is null ) then open out_rs for SELECT FLOOR(domainlogdata.startvalue/v_interval)*v_interval+v_interval/2 AS roundeddepth, count(*) as classcount,classspecificclassifications.classtext,classspecificclassifications.colour FROM domainlogdata left outer join classlogdata on domainlogdata.samplenumber=classlogdata.samplenumber inner join classspecificclassifications on classlogdata.classlogvalue=classspecificclassifications.intindex WHERE classlogdata.log_id=v_logid AND classspecificclassifications.log_id= v_logid AND domainlogdata.log_id=(SELECT logs.domainlog_id from logs where log_id= v_logid) and domainlogdata.startvalue >= v_startdepth AND domainlogdata.endvalue < v_enddepth HAVING count(*)>v_threshold*v_interval Group by classlogdata.classlogvalue, FLOOR(domainlogdata.startvalue/v_interval)*v_interval,classspecificclassifications.classtext,classspecificclassifications.colour order by classtext,FLOOR(domainlogdata.startvalue/v_interval)*v_interval, classcount DESC;
        else open out_rs for SELECT FLOOR(domainlogdata.startvalue/v_interval)*v_interval+v_interval/2 AS roundeddepth, count(*) as classcount,classspecificclassifications.classtext,classspecificclassifications.colour FROM domainlogdata left outer join classlogdata on domainlogdata.samplenumber=classlogdata.samplenumber inner join masklogdata on masklogdata.SAMPLENUMBER=classlogdata.SAMPLENUMBER inner join classspecificclassifications on classlogdata.classlogvalue=classspecificclassifications.intindex WHERE masklogdata.LOG_ID=masklogid AND masklogdata.MASKVALUE=1 AND classlogdata.log_id=v_logid AND classspecificclassifications.log_id= v_logid AND domainlogdata.log_id=(SELECT logs.domainlog_id from logs where log_id= v_logid) and domainlogdata.startvalue >= v_startdepth AND domainlogdata.endvalue < v_enddepth HAVING count(*)>v_threshold*v_interval  Group by classlogdata.classlogvalue, FLOOR(domainlogdata.startvalue/v_interval)*v_interval,classspecificclassifications.classtext,classspecificclassifications.colour order by classtext,FLOOR(domainlogdata.startvalue/v_interval)*v_interval, classcount DESC;
        end if;
      else 
        if (masklogid is null ) then open out_rs for SELECT FLOOR(domainlogdata.startvalue/v_interval)*v_interval+v_interval/2 AS roundeddepth, count(*) as classcount,classifications.classtext,classifications.colour FROM domainlogdata left outer join classlogdata on domainlogdata.samplenumber=classlogdata.samplenumber inner join classifications on classlogdata.classlogvalue=classifications.intindex WHERE classlogdata.log_id=v_logid AND classifications.algorithmoutput_id=stdalg AND domainlogdata.log_id=(SELECT logs.domainlog_id from logs where log_id= v_logid) and domainlogdata.startvalue >= v_startdepth AND domainlogdata.endvalue < v_enddepth HAVING count(*)>v_threshold*v_interval  Group by classlogdata.classlogvalue, FLOOR(domainlogdata.startvalue/v_interval)*v_interval,classifications.classtext,classifications.colour order by classtext,FLOOR(domainlogdata.startvalue/v_interval)*v_interval, classcount DESC;
        else open out_rs for SELECT FLOOR(domainlogdata.startvalue/v_interval)*v_interval+v_interval/2 AS roundeddepth, count(*) as classcount,classifications.classtext,classifications.colour FROM domainlogdata left outer join classlogdata on domainlogdata.samplenumber=classlogdata.samplenumber inner join masklogdata on masklogdata.SAMPLENUMBER=classlogdata.SAMPLENUMBER inner join classifications on classlogdata.classlogvalue=classifications.intindex WHERE masklogdata.LOG_ID=masklogid AND masklogdata.MASKVALUE=1 AND classlogdata.log_id=v_logid AND classifications.algorithmoutput_id=stdalg AND domainlogdata.log_id=(SELECT logs.domainlog_id from logs where log_id= v_logid) and domainlogdata.startvalue >= v_startdepth AND domainlogdata.endvalue < v_enddepth HAVING count(*)>v_threshold*v_interval Group by classlogdata.classlogvalue, FLOOR(domainlogdata.startvalue/v_interval)*v_interval,classifications.classtext,classifications.colour order by classtext,FLOOR(domainlogdata.startvalue/v_interval)*v_interval, classcount DESC;
        end if;
      end if;
    WHEN 2 THEN 
      if (masklogid is null ) then open out_rs for SELECT FLOOR(domainlogdata.startvalue/v_interval)*v_interval+v_interval/2 AS roundeddepth, avg(decimallogdata.decimalvalue) AS averagevalue FROM domainlogdata left join decimallogdata ON domainlogdata.samplenumber= decimallogdata.samplenumber WHERE decimallogdata.log_id= v_logid and domainlogdata.log_id=(SELECT logs.domainlog_id from logs where log_id= v_logid) and domainlogdata.startvalue >= v_startdepth AND domainlogdata.endvalue < v_enddepth GROUP BY FLOOR(domainlogdata.startvalue/v_interval)*v_interval order by FLOOR(domainlogdata.startvalue/v_interval)*v_interval;
      else open out_rs for SELECT FLOOR(domainlogdata.startvalue/v_interval)*v_interval+v_interval/2 AS roundeddepth, avg(decimallogdata.decimalvalue) AS averagevalue FROM domainlogdata left join decimallogdata ON domainlogdata.samplenumber= decimallogdata.samplenumber inner join masklogdata on masklogdata.SAMPLENUMBER=decimallogdata.SAMPLENUMBER WHERE masklogdata.LOG_ID=masklogid AND masklogdata.MASKVALUE=1 AND decimallogdata.log_id= v_logid and domainlogdata.log_id=(SELECT logs.domainlog_id from logs where log_id= v_logid) and domainlogdata.startvalue >= v_startdepth AND domainlogdata.endvalue < v_enddepth GROUP BY FLOOR(domainlogdata.startvalue/v_interval)*v_interval order by FLOOR(domainlogdata.startvalue/v_interval)*v_interval;
      end if;
    ELSE RAISE_APPLICATION_ERROR (-20001,'you cannot downsample a log of that type');
  END CASE;
  return out_rs;
END GETDOWNSAMPLEDLOGVALUES;

/

  GRANT EXECUTE ON "NVCL"."GETDOWNSAMPLEDLOGVALUES" TO "WEBSERVICE";
  GRANT EXECUTE ON "NVCL"."GETDOWNSAMPLEDLOGVALUES" TO "NVCLVIEWER";
  GRANT EXECUTE ON "NVCL"."GETDOWNSAMPLEDLOGVALUES" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Function ISALGORITHMOWNER
--------------------------------------------------------

  CREATE OR REPLACE FUNCTION "NVCL"."ISALGORITHMOWNER" (inalg_id in number) RETURN BOOLEAN AS
  realownerusername VARCHAR2(50);
BEGIN
  SELECT creatorusername INTO realownerusername FROM ALGORITHMS where algorithm_id=inalg_id;
  IF realownerusername= user then
  RETURN true;
  else
  return false;
  end if;
END ISALGORITHMOWNER;

/

  GRANT EXECUTE ON "NVCL"."ISALGORITHMOWNER" TO "NVCLVIEWER";
  GRANT EXECUTE ON "NVCL"."ISALGORITHMOWNER" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Function ISLOGOWNER
--------------------------------------------------------

  CREATE OR REPLACE FUNCTION "NVCL"."ISLOGOWNER" (inlog_id in number) RETURN BOOLEAN AS
  realownerusername VARCHAR2(50);
BEGIN
  SELECT creatorusername INTO realownerusername FROM logs where log_id=inlog_id;
  IF realownerusername= user then
  RETURN true;
  else
  return false;
  end if;
END ISLOGOWNER;

/

  GRANT EXECUTE ON "NVCL"."ISLOGOWNER" TO "NVCLVIEWER";
  GRANT EXECUTE ON "NVCL"."ISLOGOWNER" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Function VALIDATECLASSLOGDATA
--------------------------------------------------------

  CREATE OR REPLACE FUNCTION "NVCL"."VALIDATECLASSLOGDATA" 
( v_classlogid IN VARCHAR2
) RETURN NUMBER AS
algid NUMBER;
totalsamps number;
validsamps number;
BEGIN
  SELECT algorithmoutput_id INTO algid FROM logs WHERE log_id= v_classlogid;
  SELECT Count(*) into totalsamps FROM classlogdata WHERE log_id= v_classlogid AND classlogvalue is not null;
  if (algid is null) then
    SELECT count(*) into validsamps FROM classlogdata inner join classspecificclassifications on classlogdata.classlogvalue= classspecificclassifications.intindex WHERE classspecificclassifications.log_id= v_classlogid AND classlogdata.log_id= v_classlogid;
    if (totalsamps=validsamps) then  RETURN 1;
    else 
      raise_application_error (-20001,'Classifications for this scalar failed to validate');
      return 0;
    end if;
  else 
    SELECT count(*) into validsamps FROM classlogdata inner join classifications on classlogdata.classlogvalue= classifications.intindex WHERE classifications.algorithmoutput_id= algid AND classlogdata.log_id= v_classlogid;
    if (totalsamps=validsamps) then  RETURN 1;
    else 
      raise_application_error (-20001,'Classifications for this scalar failed to validate');
      return 0;
    end if;
  end if;
END VALIDATECLASSLOGDATA;

/

  GRANT EXECUTE ON "NVCL"."VALIDATECLASSLOGDATA" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Package TYPES
--------------------------------------------------------

  CREATE OR REPLACE PACKAGE "NVCL"."TYPES" 
 AS
     TYPE ref_cursor IS REF CURSOR;
 END;

/
--------------------------------------------------------
--  DDL for Procedure CREATECALIBRATIONLOG
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."CREATECALIBRATIONLOG" 
( v_logid IN VARCHAR2
) AS
BEGIN
  INSERT INTO CALIBRATIONLOGS (log_id) VALUES (v_logid);
END CREATECALIBRATIONLOG;

/

  GRANT EXECUTE ON "NVCL"."CREATECALIBRATIONLOG" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure CREATECALIBRATIONLOGDATA
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."CREATECALIBRATIONLOGDATA" 
( v_calibrationlog_id IN VARCHAR2
, v_samplenumber IN NUMBER
, v_calibrationdata IN BLOB
) AS
BEGIN
  if (v_calibrationlog_id is not null) then
  INSERT INTO calibrationlogdata (log_id, samplenumber, calibrationdata) VALUES (v_calibrationlog_id, v_samplenumber, v_calibrationdata);
  end if;
END CREATECALIBRATIONLOGDATA;

/

  GRANT EXECUTE ON "NVCL"."CREATECALIBRATIONLOGDATA" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure CREATECLASSLOG
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."CREATECLASSLOG" 
( v_logid IN VARCHAR2
, v_scalgroupid IN NUMBER
) AS
BEGIN
  INSERT INTO classlogs (log_id, scalargroup_id) VALUES (v_logid, v_scalgroupid);
END CREATECLASSLOG;

/

  GRANT EXECUTE ON "NVCL"."CREATECLASSLOG" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure CREATECLASSLOGDATA
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."CREATECLASSLOGDATA" 
( v_classlog_id IN VARCHAR2
, v_samplenumber IN NUMBER
, v_classvalue IN NUMBER
) AS
BEGIN
  INSERT INTO classlogdata (log_id, samplenumber, classlogvalue) VALUES (v_classlog_id,v_samplenumber,v_classvalue);
END CREATECLASSLOGDATA;

/

  GRANT EXECUTE ON "NVCL"."CREATECLASSLOGDATA" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure CREATECLASSSPECCLASSIFICATION
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."CREATECLASSSPECCLASSIFICATION" 
( v_classlog_id IN VARCHAR2
, v_intind IN NUMBER
, v_colour IN NUMBER
, v_text IN VARCHAR2
, v_description IN VARCHAR2
) AS
BEGIN
  INSERT INTO classspecificclassifications (log_id, intindex, colour, classtext, description) VALUES (v_classlog_id, v_intind, v_colour, v_text, v_description);
END CREATECLASSSPECCLASSIFICATION;

/

  GRANT EXECUTE ON "NVCL"."CREATECLASSSPECCLASSIFICATION" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure CREATEDATASET
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."CREATEDATASET" 
(  v_dsid IN VARCHAR2
, v_dsname IN VARCHAR2
, v_extdhservicename IN VARCHAR2
, v_extdhid IN VARCHAR2
, v_tsglayout IN CLob
, v_isreflib IN BOOLEAN
, v_scantime IN TIMESTAMP with time zone
, v_importtime IN TIMESTAMP with time zone
, v_origauthor IN VARCHAR2
, v_ispublic in number
, retid out NOCOPY VARCHAR2
) AS
tmpisreflib number;
now TIMESTAMP(0) with time zone:= systimestamp;
BEGIN
  if (v_isreflib) then tmpisreflib:=1;
  else tmpisreflib:=0;
  end if;
  INSERT INTO datasets (dataset_id,datasetname, holedatasourcename, holeidentifier, tsglayout, isreferencelibrary, createddate, modifieddate, creatorusername, modifierusername, origauthor, scandate, importdate, ispublic) VALUES (v_dsid,v_dsname, v_extdhservicename, v_extdhid, v_tsglayout, tmpisreflib, now, now, user,user,v_origauthor, v_scantime, v_importtime,v_ispublic) RETURNING dataset_id INTO retid;
END CREATEDATASET;

/

  GRANT EXECUTE ON "NVCL"."CREATEDATASET" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure CREATEDATASETSTATS
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."CREATEDATASETSTATS" 
( v_datasetstats_id IN VARCHAR2
,v_validbitmask IN NUMBER
,v_statstype IN NUMBER
,v_samples IN NUMBER
,v_libchannels IN NUMBER
,v_channels IN NUMBER
,v_wsub IN NUMBER
,v_wuflags IN NUMBER
,v_lcwhich IN NUMBER
,v_lcprenorm IN NUMBER
,v_lcbkrem IN NUMBER
,v_lcpostnorm IN NUMBER
,v_lcsgleft IN NUMBER
,v_lcsgright IN NUMBER
,v_lcsgpoly IN NUMBER
,v_lcsgderiv IN NUMBER
,v_resamplingalgorithm IN NUMBER
,v_reswmin IN float
,v_reswmax IN float
,v_reswinc IN float
,v_wmin IN float
,v_wmax IN float
,v_wtol IN float
,v_librarydataset_id IN VARCHAR2
,v_masklog_id IN VARCHAR2
,v_usercomments IN VARCHAR2
,v_wvl IN BLOB
,v_lib_wvl IN BLOB
,v_chmax IN BLOB
,v_chmin IN BLOB
,v_mean IN BLOB
,v_sdev IN BLOB
,v_covar IN BLOB
,v_correl IN BLOB
,v_noisecv IN BLOB
,v_eval IN BLOB
,v_ftrans IN BLOB
,v_rtrans IN BLOB
) AS
BEGIN
  INSERT INTO datasetstats (datasetstats_id, validbitmask, statstype, samples, libchannels, channels, wsub, wuflags, lcwhich, lcprenorm, lcbkrem, lcpostnorm, lcsgleft, lcsgright, lcsgpoly, lcsgderiv, resamplingalgorithm, reswmin, reswmax, reswinc, wmin, wmax, wtol, librarydataset_id, masklog_id, usercomments, wvl, chmax, chmin, mean, sdev, covar, correl, noisecv, eval, ftrans, rtrans, lib_wvl ) VALUES (v_datasetstats_id, v_validbitmask, v_statstype, v_samples, v_libchannels, v_channels, v_wsub, v_wuflags, v_lcwhich, v_lcprenorm, v_lcbkrem, v_lcpostnorm, v_lcsgleft, v_lcsgright, v_lcsgpoly, v_lcsgderiv, v_resamplingalgorithm, v_reswmin, v_reswmax, v_reswinc, v_wmin, v_wmax, v_wtol, v_librarydataset_id, v_masklog_id, v_usercomments, v_wvl, v_chmax, v_chmin, v_mean, v_sdev, v_covar, v_correl, v_noisecv, v_eval, v_ftrans, v_rtrans, v_lib_wvl);
END CREATEDATASETSTATS;

/

  GRANT EXECUTE ON "NVCL"."CREATEDATASETSTATS" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure CREATEDECIMALLOG
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."CREATEDECIMALLOG" 
( v_logid IN VARCHAR2
, v_scalgroupid IN NUMBER 
, v_minthreshold IN FLOAT 
, v_maxthreshold IN FLOAT 
, v_isrgbcolour IN NUMBER 
) AS
BEGIN
  INSERT INTO decimallogs (log_id, scalargroup_id, minthreshold, maxthreshold, resultisrgbcolour ) VALUES (v_logid, v_scalgroupid, v_minthreshold, v_maxthreshold, v_isrgbcolour);
END CREATEDECIMALLOG;

/

  GRANT EXECUTE ON "NVCL"."CREATEDECIMALLOG" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure CREATEDECIMALLOGDATA
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."CREATEDECIMALLOGDATA" 
( v_declog_id IN VARCHAR2
, v_samplenumber IN NUMBER
, v_decvalue IN DOUBLE PRECISION
) AS
BEGIN
  INSERT INTO decimallogdata (log_id, samplenumber, decimalvalue) VALUES (v_declog_id, v_samplenumber, v_decvalue);
END CREATEDECIMALLOGDATA;

/

  GRANT EXECUTE ON "NVCL"."CREATEDECIMALLOGDATA" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure CREATEDOMAINLOG
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."CREATEDOMAINLOG" 
( v_logid IN VARCHAR2
, v_units IN VARCHAR2
, v_issubdomainof IN VARCHAR2
, v_scalargroupid IN NUMBER
) AS
BEGIN
  INSERT INTO domainlogs (log_id, units, issubdomainoflog_id, scalargroup_id) VALUES (v_logid,v_units, v_issubdomainof, v_scalargroupid);
END CREATEDOMAINLOG;

/

  GRANT EXECUTE ON "NVCL"."CREATEDOMAINLOG" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure CREATEDOMLOGDATA
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."CREATEDOMLOGDATA" 
( v_domlog_id IN VARCHAR2
, v_samplenumber IN NUMBER 
, v_startvalue IN DOUBLE PRECISION
, v_endvalue IN DOUBLE PRECISION
, v_name IN VARCHAR2
, v_desc IN VARCHAR2
, v_colour IN NUMBER
, v_swirminlist IN BLOB
, v_swirtsaversion IN NUMBER
, v_vnirminlist IN BLOB
, v_vnirtsaversion IN NUMBER
, v_tirminlist IN BLOB
, v_tirtsaversion IN NUMBER
) AS
BEGIN
  INSERT INTO DOMAINLOGDATA (log_id, samplenumber, startvalue, endvalue, samplename, DESCRIPTION, COLOUR,	SWIRMINLIST, SWIRTSAVERSION, VNIRMINLIST, VNIRTSAVERSION, TIRMINLIST, TIRTSAVERSION) VALUES (v_domlog_id, v_samplenumber, v_startvalue, v_endvalue, v_name, v_desc, v_colour, v_swirminlist, v_swirtsaversion, v_vnirminlist, v_vnirtsaversion, v_tirminlist, v_tirtsaversion);
END CREATEDOMLOGDATA;

/

  GRANT EXECUTE ON "NVCL"."CREATEDOMLOGDATA" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure CREATEDOMLOGDATA2
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."CREATEDOMLOGDATA2" 
( v_domlog_id IN VARCHAR2
, v_samplenumber IN NUMBER 
, v_startvalue IN DOUBLE PRECISION
, v_endvalue IN DOUBLE PRECISION
, v_name IN VARCHAR2
, v_desc IN VARCHAR2
, v_colour IN NUMBER
, v_swirminlist IN BLOB
, v_swirtsaversion IN NUMBER
, v_vnirminlist IN BLOB
, v_vnirtsaversion IN NUMBER
, v_tirminlist IN BLOB
, v_tirtsaversion IN NUMBER
, v_aminlist IN BLOB
, v_atsaversion IN NUMBER
, v_bminlist IN BLOB
, v_btsaversion IN NUMBER
) AS
BEGIN
  INSERT INTO DOMAINLOGDATA (log_id, samplenumber, startvalue, endvalue, samplename, DESCRIPTION, COLOUR, SWIRMINLIST, SWIRTSAVERSION, VNIRMINLIST, VNIRTSAVERSION, TIRMINLIST, TIRTSAVERSION, AMINLIST, ATSAVERSION, BMINLIST, BTSAVERSION) VALUES (v_domlog_id, v_samplenumber, v_startvalue, v_endvalue, v_name, v_desc, v_colour, v_swirminlist, v_swirtsaversion, v_vnirminlist, v_vnirtsaversion, v_tirminlist, v_tirtsaversion, v_aminlist, v_atsaversion, v_bminlist, v_btsaversion);
END CREATEDOMLOGDATA2;

/

  GRANT EXECUTE ON "NVCL"."CREATEDOMLOGDATA2" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure CREATEEVENTJOURNALEVENT
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."CREATEEVENTJOURNALEVENT" 
( v_dataset_id IN VARCHAR2
, v_eventnumber IN NUMBER
, v_catno IN NUMBER
, v_isprimary IN NUMBER
, v_eventtime IN DATE 
, v_tsgproduct IN VARCHAR2 
, v_tsguser IN VARCHAR2
, v_content IN VARCHAR2
) AS
eventexists NUMBER;
BEGIN
  select count(*) into eventexists from EVENTJOURNAL where dataset_id= v_dataset_id AND EVENTNUMBER= v_eventnumber AND ISPRIMARY=v_isprimary;
  if (eventexists =1) then
    UPDATEEVENTJOURNALEVENT(v_dataset_id,v_eventnumber,v_catno, v_isprimary, v_eventtime,v_tsgproduct,v_tsguser,v_content);
  else
     INSERT INTO EVENTJOURNAL (DATASET_ID, EVENTNUMBER, CATNO, ISPRIMARY, EVENTTIME, TSGPRODUCT, TSGUSER, CONTENT ) VALUES (v_dataset_id, v_eventnumber, v_catno, v_isprimary, v_eventtime, v_tsgproduct, v_tsguser, v_content );
  end if; 
END CREATEEVENTJOURNALEVENT;

/

  GRANT EXECUTE ON "NVCL"."CREATEEVENTJOURNALEVENT" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure CREATEIMAGELOG
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."CREATEIMAGELOG" 
( v_logid IN VARCHAR2
, v_imghist IN BLOB
, v_imgclippercent IN NUMBER
, v_logtime IN timestamp with time zone
, v_imgwidth IN NUMBER
, v_imgheight IN NUMBER
) AS
BEGIN
  INSERT INTO imagelogs (log_id, imghistogram, imgclippercent, logtimestamp, imgwidth, imgheight ) VALUES (v_logid,v_imghist, v_imgclippercent, v_logtime, v_imgwidth, v_imgheight);
END CREATEIMAGELOG;

/

  GRANT EXECUTE ON "NVCL"."CREATEIMAGELOG" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure CREATEIMAGELOGDATA
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."CREATEIMAGELOGDATA" 
( v_imagelog_id IN VARCHAR2
, v_samplenumber IN NUMBER
, v_imagedata IN BLOB
, v_imgcomment IN VARCHAR2
) AS
BEGIN
  if (v_imagelog_id is not null) then
  INSERT INTO imagelogdata (log_id, samplenumber, imagedata, imagecomment) VALUES (v_imagelog_id, v_samplenumber, v_imagedata, v_imgcomment);
  end if;
END CREATEIMAGELOGDATA;

/

  GRANT EXECUTE ON "NVCL"."CREATEIMAGELOGDATA" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure CREATELAYOUT
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."CREATELAYOUT" 
( v_dsid IN VARCHAR2
,v_layoutnumber IN NUMBER
,v_layoutdata IN CLOB
,v_layoutname IN VARCHAR2
) AS
layoutexists NUMBER;
BEGIN
 select count(*) into layoutexists from layouts where dataset_id= v_dsid AND layoutno= v_layoutnumber;
  if (layoutexists =1) then
    UPDATELAYOUT(v_dsid,v_layoutnumber,v_layoutdata,v_layoutname);
  else
    INSERT INTO LAYOUTS (DATASET_ID,LAYOUTNO,LAYOUTDATA,LAYOUTNAME) VALUES (v_dsid,v_layoutnumber,v_layoutdata,v_layoutname);
  end if;
END CREATELAYOUT;

/

  GRANT EXECUTE ON "NVCL"."CREATELAYOUT" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure CREATELOG
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."CREATELOG" 
( v_dsid IN VARCHAR2
, v_logid IN VARCHAR2
, v_logname IN VARCHAR2
, v_description IN VARCHAR2
, v_ispublic IN NUMBER
, v_logtype IN NUMBER
, v_domlogid IN VARCHAR2
, v_stdalgid IN NUMBER
, v_custscript IN CLOB
, v_masklogid IN VARCHAR2
, v_refstatsid IN VARCHAR2
, v_tsaretrainid IN VARCHAR2
, v_tsghandmask IN NUMBER
, v_batchscript IN CLOB
, v_mixnumber IN NUMBER
, v_auxlayerid IN VARCHAR2
, v_locallayerid IN VARCHAR2
, v_plsid IN VARCHAR2
) AS
now TIMESTAMP(0) with time zone:= systimestamp;
BEGIN
  INSERT INTO logs (log_id,logname, creatorusername, modifierusername, createddate, modifieddate, dataset_id, domainlog_id, logtype, description, ispublic, algorithmoutput_id, customscript, masklog_id, refstats_id, tsaretraining_id, tsghandmask, batchscript , mixnumber, localspectrallayer_id, auxspectrallayer_id, pls_id) VALUES (v_logid, v_logname, user, user, now, now, v_dsid, v_domlogid, v_logtype, v_description, v_ispublic, v_stdalgid, v_custscript, v_masklogid, v_refstatsid, v_tsaretrainid, v_tsghandmask, v_batchscript, v_mixnumber, v_locallayerid, v_auxlayerid, v_plsid);
END CREATELOG;

/

  GRANT EXECUTE ON "NVCL"."CREATELOG" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure CREATELOGDEP
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."CREATELOGDEP" 
( v_logid IN VARCHAR2
, v_dependsonid IN VARCHAR2
, v_depname in VARCHAR2
, v_order in number
) AS
BEGIN
  INSERT INTO logdependencies (log_id, dependson, relationname, priorityorder) VALUES (v_logid, v_dependsonid, v_depname, COALESCE(v_order,0));
END CREATELOGDEP;

/

  GRANT EXECUTE ON "NVCL"."CREATELOGDEP" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure CREATEMASKLOG
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."CREATEMASKLOG" 
( v_logid IN VARCHAR2
, v_scalgroupid IN NUMBER 
) AS
BEGIN
  INSERT INTO masklogs (log_id, scalargroup_id) VALUES (v_logid, v_scalgroupid);
END CREATEMASKLOG;

/

  GRANT EXECUTE ON "NVCL"."CREATEMASKLOG" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure CREATEMASKLOGDATA
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."CREATEMASKLOGDATA" 
( v_masklog_id IN VARCHAR2
, v_samplenumber IN NUMBER
, v_maskvalue IN NUMBER
) AS
BEGIN
  INSERT INTO masklogdata (log_id, samplenumber, maskvalue) VALUES (v_masklog_id,v_samplenumber,v_maskvalue);
END CREATEMASKLOGDATA;

/

  GRANT EXECUTE ON "NVCL"."CREATEMASKLOGDATA" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure CREATEPLSDATA
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."CREATEPLSDATA" 
( v_plsid IN VARCHAR2
, v_dsid IN VARCHAR2
, v_plsname IN VARCHAR2
, v_plsdata IN BLOB
) AS
BEGIN
   INSERT INTO PLSDATA (PLS_ID,DATASET_ID,PLSNAME,PLSDATA) VALUES (v_plsid,v_dsid,v_plsname,v_plsdata);
END CREATEPLSDATA;

/

  GRANT EXECUTE ON "NVCL"."CREATEPLSDATA" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure CREATEPROFLOG
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."CREATEPROFLOG" 
( v_logid IN VARCHAR2
, v_logtime IN TIMESTAMP with time zone
, v_minval in float
, v_maxval in float
, v_floatspersample IN NUMBER
) AS
BEGIN
  INSERT INTO proflogs (log_id, logtimestamp, minval, maxval,FLOATSPERSAMPLE ) VALUES (v_logid, v_logtime, v_minval, v_maxval, v_floatspersample);
END CREATEPROFLOG;

/

  GRANT EXECUTE ON "NVCL"."CREATEPROFLOG" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure CREATEPROFLOGDATA
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."CREATEPROFLOGDATA" 
( v_proflog_id IN VARCHAR2
, v_samplenumber IN NUMBER
, v_profdata IN BLOB
) AS
BEGIN
  INSERT INTO proflogdata (log_id, samplenumber, profilometervalues) VALUES (v_proflog_id, v_samplenumber, v_profdata);
END CREATEPROFLOGDATA;

/

  GRANT EXECUTE ON "NVCL"."CREATEPROFLOGDATA" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure CREATESCALARSET
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."CREATESCALARSET" 
( v_dsid IN VARCHAR2
, v_setnumber IN NUMBER
, v_setname IN VARCHAR2
, v_settype IN NUMBER
) AS
setexists NUMBER;
BEGIN
  select count(*) into setexists from scalarsets where dataset_id= v_dsid AND setnumber= v_setnumber;
  if (setexists =1) then
     update scalarsets set setname= v_setname, settype=v_settype WHERE dataset_id= v_dsid AND setnumber= v_setnumber;
  else
    INSERT INTO scalarsets (dataset_id, setnumber, setname, settype) VALUES (v_dsid, v_setnumber, v_setname,v_settype);  
  end if;
END CREATESCALARSET;

/

  GRANT EXECUTE ON "NVCL"."CREATESCALARSET" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure CREATESPECTRALLOG
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."CREATESPECTRALLOG" 
( v_logid IN VARCHAR2
, v_specsamppoints in blob
, v_fwhm in blob
, v_specunits IN VARCHAR2
, v_logtime in timestamp with time zone
, v_logorder in number
, v_tirq in blob
) AS
BEGIN
  INSERT INTO spectrallogs (log_id, spectralsamplingpoints, fwhm, spectralunits, logtimestamp,layerorder,tirq) VALUES (v_logid,v_specsamppoints,v_fwhm,v_specunits,v_logtime,v_logorder,v_tirq);
END CREATESPECTRALLOG;

/

  GRANT EXECUTE ON "NVCL"."CREATESPECTRALLOG" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure CREATESPECTRALLOGDATA
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."CREATESPECTRALLOGDATA" 
( v_speclog_id IN VARCHAR2
, v_samplenumber IN NUMBER 
, v_spectrum IN BLOB
) AS
BEGIN
  INSERT INTO SPECTRALLOGDATA (log_id, samplenumber, spectralvalues) VALUES (v_speclog_id, v_samplenumber,v_spectrum);
END CREATESPECTRALLOGDATA;

/

  GRANT EXECUTE ON "NVCL"."CREATESPECTRALLOGDATA" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure CREATETSARETRAINING
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."CREATETSARETRAINING" 
( v_tsaretrainid IN VARCHAR2
, v_numallclasses IN NUMBER
, v_numtrainclasses IN NUMBER
, v_tsaparams IN BLOB
, v_minmask IN BLOB
, v_mixmask IN BLOB
, v_dbix IN NUMBER
, v_trainsel IN NUMBER
, v_seven IN NUMBER
, v_illite IN NUMBER
, v_domained IN NUMBER
, v_version IN NUMBER
, v_plus IN NUMBER
) AS
BEGIN
  INSERT INTO tsaretraining ( tsaretraining_id, numallclasses,numtrainclasses, tsaparams, minmask, mixmask, dbix,trainsel,illite,seven,domained,version,plus) VALUES ( v_tsaretrainid, v_numallclasses, v_numtrainclasses, v_tsaparams, v_minmask, v_mixmask, v_dbix, v_trainsel, v_illite, v_seven, v_domained, v_version, v_plus);
  EXCEPTION
  WHEN DUP_VAL_ON_INDEX THEN
  updatetsaretraining(v_numallclasses, v_numtrainclasses, v_tsaparams, v_minmask, v_mixmask, v_tsaretrainid, v_dbix, v_trainsel, v_seven, v_illite, v_domained, v_version, v_plus);
END CREATETSARETRAINING;

/

  GRANT EXECUTE ON "NVCL"."CREATETSARETRAINING" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure DELETEALLCLASSIFICATIONS
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."DELETEALLCLASSIFICATIONS" 
( v_logid IN VARCHAR2
) AS
BEGIN
  DELETE FROM classspecificclassifications WHERE log_id=v_logid;
  EXCEPTION
   WHEN NO_DATA_FOUND THEN return;
END DELETEALLCLASSIFICATIONS;

/

  GRANT EXECUTE ON "NVCL"."DELETEALLCLASSIFICATIONS" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure DELETEALLLOGDATA
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."DELETEALLLOGDATA" 
( v_logid IN VARCHAR2
) AS
curlogtype number;
BEGIN
  SELECT logtype into curlogtype from Logs WHERE log_id= v_logid;
  CASE curlogtype
    WHEN 0 THEN DELETE FROM domainlogdata WHERE log_id=v_logid;
    WHEN 1 THEN DELETE FROM classlogdata WHERE log_id=v_logid;
    WHEN 2 THEN DELETE FROM decimallogdata WHERE log_id=v_logid;
    WHEN 3 THEN DELETE FROM imagelogdata WHERE log_id=v_logid;
    WHEN 4 THEN DELETE FROM proflogdata WHERE log_id=v_logid;
    WHEN 5 THEN DELETE FROM spectrallogdata WHERE log_id=v_logid;
    WHEN 6 THEN DELETE FROM masklogdata WHERE log_id=v_logid;
	WHEN 7 THEN DELETE FROM calibrationlogdata WHERE log_id=v_logid;
    END CASE;
    EXCEPTION
      WHEN NO_DATA_FOUND THEN return;
END DELETEALLLOGDATA;

/

  GRANT EXECUTE ON "NVCL"."DELETEALLLOGDATA" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure DELETELAYOUT
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."DELETELAYOUT" 
( v_dsid IN VARCHAR2
,v_layoutnumber IN NUMBER
) AS
BEGIN
  DELETE FROM LAYOUTS WHERE DATASET_ID=v_dsid AND LAYOUTNO=v_layoutnumber;
END DELETELAYOUT;

/

  GRANT EXECUTE ON "NVCL"."DELETELAYOUT" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure DELETELOG
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."DELETELOG" 
( v_logid IN VARCHAR2
, v_success out number
, v_overrideusercheck in boolean default false
) AS
username varchar2(100);
BEGIN
  select creatorusername into username from logs where log_id=v_logid;
  if (username!=user) then
    if (v_overrideusercheck=true) then
      DELETE FROM LOGS WHERE LOG_ID = v_logid;
      v_success:=SQL%ROWCOUNT;
    else
      v_success:=-1;
    end if;
  else
    DELETE FROM LOGS WHERE LOG_ID = v_logid;
    v_success:=SQL%ROWCOUNT;
  end if;
  EXCEPTION
   WHEN NO_DATA_FOUND THEN
      v_success:=0;
END DELETELOG;

/

  GRANT EXECUTE ON "NVCL"."DELETELOG" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure DELETELOGDEP
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."DELETELOGDEP" 
( v_logid IN VARCHAR2
, v_dependson IN VARCHAR2
) AS
BEGIN
  if(v_dependson is null) then 
    DELETE FROM logdependencies WHERE log_id= v_logid;
  else
    DELETE FROM logdependencies WHERE log_id= v_logid and dependson= v_dependson;
  end if;
  EXCEPTION
   WHEN NO_DATA_FOUND THEN return;
END DELETELOGDEP;

/

  GRANT EXECUTE ON "NVCL"."DELETELOGDEP" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure DELETEPLSDATA
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."DELETEPLSDATA" 
( v_plsid IN VARCHAR2
) AS
BEGIN
    DELETE FROM PLSDATA WHERE pls_id= v_plsid;
    EXCEPTION
     WHEN NO_DATA_FOUND THEN return;
END DELETEPLSDATA;

/

  GRANT EXECUTE ON "NVCL"."DELETEPLSDATA" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure GETLOGDATAPOINTCOUNT
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."GETLOGDATAPOINTCOUNT" 
( v_logid IN VARCHAR2
, datapointcount OUT NUMBER
) AS
curlogtype number;
BEGIN
  SELECT logtype into curlogtype from Logs WHERE log_id= v_logid;
  CASE curlogtype
    WHEN 0 THEN SELECT count(*) into datapointcount FROM domainlogdata WHERE log_id=v_logid;
    WHEN 1 THEN SELECT count(*) into datapointcount FROM classlogdata WHERE log_id=v_logid;
    WHEN 2 THEN SELECT count(*) into datapointcount FROM decimallogdata WHERE log_id=v_logid;
    WHEN 3 THEN SELECT count(*) into datapointcount FROM imagelogdata WHERE log_id=v_logid;
    WHEN 4 THEN SELECT count(*) into datapointcount FROM proflogdata WHERE log_id=v_logid;
    WHEN 5 THEN SELECT count(*) into datapointcount FROM spectrallogdata WHERE log_id=v_logid;
    WHEN 6 THEN SELECT count(*) into datapointcount FROM masklogdata WHERE log_id=v_logid;
	WHEN 7 THEN SELECT count(*) into datapointcount FROM calibrationlogdata WHERE log_id=v_logid;
    END CASE;
    EXCEPTION
      WHEN NO_DATA_FOUND THEN datapointcount:=0;
END GETLOGDATAPOINTCOUNT;

/

  GRANT EXECUTE ON "NVCL"."GETLOGDATAPOINTCOUNT" TO "NVCLVIEWER";
  GRANT EXECUTE ON "NVCL"."GETLOGDATAPOINTCOUNT" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure GETLOGEXTENTS
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."GETLOGEXTENTS" 
( v_logid IN VARCHAR2
, v_minval OUT NUMBER
, v_maxval OUT NUMBER
) AS
curlogtype number;
BEGIN
  SELECT logtype into curlogtype from Logs WHERE log_id= v_logid;
  CASE curlogtype
    WHEN 0 THEN SELECT min(startvalue),max(endvalue) into v_minval,v_maxval FROM domainlogdata WHERE log_id=v_logid;
    WHEN 1 THEN SELECT min(classlogvalue),max(classlogvalue) into v_minval,v_maxval FROM classlogdata WHERE log_id=v_logid;
    WHEN 2 THEN SELECT min(decimalvalue),max(decimalvalue) into v_minval,v_maxval FROM decimallogdata WHERE log_id=v_logid;
    ELSE v_minval:=0;v_maxval:=0;
    END CASE;
    EXCEPTION
      WHEN NO_DATA_FOUND THEN v_minval:=0;v_maxval:=0;
END  GETLOGEXTENTS;

/

  GRANT EXECUTE ON "NVCL"."GETLOGEXTENTS" TO "NVCLVIEWER";
  GRANT EXECUTE ON "NVCL"."GETLOGEXTENTS" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure SETUPNVCLANALYST
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."SETUPNVCLANALYST" 
( v_username IN VARCHAR2
) AUTHID CURRENT_USER AS
BEGIN
  EXECUTE IMMEDIATE 'Grant NVCLAnalyst to ' || v_username;
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.DATASETSTATS FOR NVCL.DATASETSTATS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.LOGS FOR NVCL.LOGS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.ALGORITHMS FOR NVCL.ALGORITHMS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.SCALARSETS FOR NVCL.SCALARSETS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.CLASSIFICATIONS FOR NVCL.CLASSIFICATIONS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.LOGTYPES FOR NVCL.LOGTYPES';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.TSARETRAINING FOR NVCL.TSARETRAINING';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.SPECTRALLOGS FOR NVCL.SPECTRALLOGS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.SPECTRALLOGDATA FOR NVCL.SPECTRALLOGDATA';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.SCALARGROUPS FOR NVCL.SCALARGROUPS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.PROFLOGS FOR NVCL.PROFLOGS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.PROFLOGDATA FOR NVCL.PROFLOGDATA';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.MASKLOGS FOR NVCL.MASKLOGS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.MASKLOGDATA FOR NVCL.MASKLOGDATA';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.MACHINES FOR NVCL.MACHINES';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.LOGDEPENDENCIES FOR NVCL.LOGDEPENDENCIES';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.IMAGELOGS FOR NVCL.IMAGELOGS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.IMAGELOGDATA FOR NVCL.IMAGELOGDATA';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.DOMAINLOGS FOR NVCL.DOMAINLOGS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.DOMAINLOGDATA FOR NVCL.DOMAINLOGDATA';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.DECIMALLOGS FOR NVCL.DECIMALLOGS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.DECIMALLOGDATA FOR NVCL.DECIMALLOGDATA';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.DATASETS FOR NVCL.DATASETS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.CLASSSPECIFICCLASSIFICATIONS FOR NVCL.CLASSSPECIFICCLASSIFICATIONS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.CLASSLOGS FOR NVCL.CLASSLOGS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.CLASSLOGDATA FOR NVCL.CLASSLOGDATA';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.ALGORITHMOUTPUTS FOR NVCL.ALGORITHMOUTPUTS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.CREATEDATASETSTATS FOR NVCL.CREATEDATASETSTATS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.UPDATEDECIMALLOG FOR NVCL.UPDATEDECIMALLOG';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.CREATEMASKLOGDATA FOR NVCL.CREATEMASKLOGDATA';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.GETDOMAINDATA FOR NVCL.GETDOMAINDATA';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.UPDATEPROFLOG FOR NVCL.UPDATEPROFLOG';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.UPDATEIMAGELOGDATA FOR NVCL.UPDATEIMAGELOGDATA';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.DELETELOG FOR NVCL.DELETELOG';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.UPDATELOGDEP FOR NVCL.UPDATELOGDEP';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.CREATESCALARSET FOR NVCL.CREATESCALARSET';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.CREATETSARETRAINING FOR NVCL.CREATETSARETRAINING';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.ISALGORITHMOWNER FOR NVCL.ISALGORITHMOWNER';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.CREATELOG FOR NVCL.CREATELOG';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.UPDATESPECTRALLOG FOR NVCL.UPDATESPECTRALLOG';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.CREATEPROFLOGDATA FOR NVCL.CREATEPROFLOGDATA';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.UPDATEIMAGELOG FOR NVCL.UPDATEIMAGELOG';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.UPDATELOGMASK FOR NVCL.UPDATELOGMASK';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.ISLOGOWNER FOR NVCL.ISLOGOWNER';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.VALIDATECLASSLOGDATA FOR NVCL.VALIDATECLASSLOGDATA';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.CREATEDOMLOGDATA FOR NVCL.CREATEDOMLOGDATA';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.CREATEDOMLOGDATA2 FOR NVCL.CREATEDOMLOGDATA2';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.UPDATETSARETRAINING FOR NVCL.UPDATETSARETRAINING';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.CREATESPECTRALLOGDATA FOR NVCL.CREATESPECTRALLOGDATA';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.UPDATEMASKLOG FOR NVCL.UPDATEMASKLOG';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.GETLOGDATAPOINTCOUNT FOR NVCL.GETLOGDATAPOINTCOUNT';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.CREATEIMAGELOGDATA FOR NVCL.CREATEIMAGELOGDATA';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.CREATELOGDEP FOR NVCL.CREATELOGDEP';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.DELETEALLLOGDATA FOR NVCL.DELETEALLLOGDATA';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.GETDOMAINDATASTRSPS FOR NVCL.GETDOMAINDATASTRSPS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.CREATEDECIMALLOG FOR NVCL.CREATEDECIMALLOG';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.UPDATELOG FOR NVCL.UPDATELOG';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.UPDATEPROFLOGDATA FOR NVCL.UPDATEPROFLOGDATA';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.UPDATEMASKLOGDATA FOR NVCL.UPDATEMASKLOGDATA';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.CREATEPROFLOG FOR NVCL.CREATEPROFLOG';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.CREATECLASSLOGDATA FOR NVCL.CREATECLASSLOGDATA';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.UPDATEDECIMALLOGDATA FOR NVCL.UPDATEDECIMALLOGDATA';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.CREATEDECIMALLOGDATA FOR NVCL.CREATEDECIMALLOGDATA';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.CREATEDOMAINLOG FOR NVCL.CREATEDOMAINLOG';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.CREATESPECTRALLOG FOR NVCL.CREATESPECTRALLOG';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.UPDATESPECTRALLOGDATA FOR NVCL.UPDATESPECTRALLOGDATA';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.UPDATECLASSLOGDATA FOR NVCL.UPDATECLASSLOGDATA';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.UPDATECLASSSPECCLASSIFICATION FOR NVCL.UPDATECLASSSPECCLASSIFICATION';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.DELETEALLCLASSIFICATIONS FOR NVCL.DELETEALLCLASSIFICATIONS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.CREATECLASSSPECCLASSIFICATION FOR NVCL.CREATECLASSSPECCLASSIFICATION';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.GETDOMAINDATASTR FOR NVCL.GETDOMAINDATASTR';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.GETDOMAINDATAASBASESPS FOR NVCL.GETDOMAINDATAASBASESPS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.TOUCHLOG FOR NVCL.TOUCHLOG';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.UPDATEDOMAINLOG FOR NVCL.UPDATEDOMAINLOG';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.CREATEMASKLOG FOR NVCL.CREATEMASKLOG';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.UPDATEDOMLOGDATA FOR NVCL.UPDATEDOMLOGDATA';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.DELETELOGDEP FOR NVCL.DELETELOGDEP';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.CREATEIMAGELOG FOR NVCL.CREATEIMAGELOG';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.UPDATECLASSLOG FOR NVCL.UPDATECLASSLOG';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.GETLOGEXTENTS FOR NVCL.GETLOGEXTENTS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.GETDATAPOINTS FOR NVCL.GETDATAPOINTS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.UPDATEDATASET FOR NVCL.UPDATEDATASET';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.GETDOWNSAMPLEDLOGVALUES FOR NVCL.GETDOWNSAMPLEDLOGVALUES';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.CREATECLASSLOG FOR NVCL.CREATECLASSLOG';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.CREATEDATASET FOR NVCL.CREATEDATASET';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.SEARCHFORDATASETS FOR NVCL.SEARCHFORDATASETS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.PLSDATA FOR NVCL.PLSDATA';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.DELETEPLSDATA FOR NVCL.DELETEPLSDATA';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.CREATEPLSDATA FOR NVCL.CREATEPLSDATA';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.LAYOUTS FOR NVCL.LAYOUTS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.CREATELAYOUT FOR NVCL.CREATELAYOUT';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.UPDATELAYOUT FOR NVCL.UPDATELAYOUT';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.DELETELAYOUT FOR NVCL.DELETELAYOUT';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.CALIBRATIONLOGS FOR NVCL.CALIBRATIONLOGS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.CALIBRATIONLOGDATA FOR NVCL.CALIBRATIONLOGDATA';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.UPDATECALIBRATIONLOGDATA FOR NVCL.UPDATECALIBRATIONLOGDATA';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.CREATECALIBRATIONLOGDATA FOR NVCL.CREATECALIBRATIONLOGDATA';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.UPDATECALIBRATIONLOG FOR NVCL.UPDATECALIBRATIONLOG';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.CREATECALIBRATIONLOG FOR NVCL.CREATECALIBRATIONLOG';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.CREATEEVENTJOURNALEVENT FOR NVCL.CREATEEVENTJOURNALEVENT';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.UPDATEEVENTJOURNALEVENT  FOR NVCL.UPDATEEVENTJOURNALEVENT ';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.EVENTJOURNAL FOR NVCL.EVENTJOURNAL';
END SETUPNVCLANALYST;

/
--------------------------------------------------------
--  DDL for Procedure SETUPNVCLVIEWER
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."SETUPNVCLVIEWER" 
( v_username IN VARCHAR2
) AUTHID CURRENT_USER AS
BEGIN
  EXECUTE IMMEDIATE 'Grant NVCLViewer to ' || v_username;
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.DATASETSTATS FOR NVCL.DATASETSTATS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.LOGS FOR NVCL.LOGS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.ALGORITHMS FOR NVCL.ALGORITHMS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.SCALARSETS FOR NVCL.SCALARSETS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.CLASSIFICATIONS FOR NVCL.CLASSIFICATIONS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.LOGTYPES FOR NVCL.LOGTYPES';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.TSARETRAINING FOR NVCL.TSARETRAINING';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.SPECTRALLOGS FOR NVCL.SPECTRALLOGS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.SPECTRALLOGDATA FOR NVCL.SPECTRALLOGDATA';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.SCALARGROUPS FOR NVCL.SCALARGROUPS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.PROFLOGS FOR NVCL.PROFLOGS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.PROFLOGDATA FOR NVCL.PROFLOGDATA';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.MASKLOGS FOR NVCL.MASKLOGS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.MASKLOGDATA FOR NVCL.MASKLOGDATA';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.MACHINES FOR NVCL.MACHINES';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.LOGDEPENDENCIES FOR NVCL.LOGDEPENDENCIES';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.IMAGELOGS FOR NVCL.IMAGELOGS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.IMAGELOGDATA FOR NVCL.IMAGELOGDATA';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.DOMAINLOGS FOR NVCL.DOMAINLOGS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.DOMAINLOGDATA FOR NVCL.DOMAINLOGDATA';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.DECIMALLOGS FOR NVCL.DECIMALLOGS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.DECIMALLOGDATA FOR NVCL.DECIMALLOGDATA';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.DATASETS FOR NVCL.DATASETS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.CLASSSPECIFICCLASSIFICATIONS FOR NVCL.CLASSSPECIFICCLASSIFICATIONS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.CLASSLOGS FOR NVCL.CLASSLOGS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.CLASSLOGDATA FOR NVCL.CLASSLOGDATA';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.ALGORITHMOUTPUTS FOR NVCL.ALGORITHMOUTPUTS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.GETDOMAINDATA FOR NVCL.GETDOMAINDATA';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.ISALGORITHMOWNER FOR NVCL.ISALGORITHMOWNER';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.ISLOGOWNER FOR NVCL.ISLOGOWNER';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.GETLOGDATAPOINTCOUNT FOR NVCL.GETLOGDATAPOINTCOUNT';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.GETDOMAINDATASTRSPS FOR NVCL.GETDOMAINDATASTRSPS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.GETDOMAINDATASTR FOR NVCL.GETDOMAINDATASTR';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.GETDOMAINDATAASBASESPS FOR NVCL.GETDOMAINDATAASBASESPS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.GETLOGEXTENTS FOR NVCL.GETLOGEXTENTS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.GETDATAPOINTS FOR NVCL.GETDATAPOINTS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.GETDOWNSAMPLEDLOGVALUES FOR NVCL.GETDOWNSAMPLEDLOGVALUES';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.SEARCHFORDATASETS FOR NVCL.SEARCHFORDATASETS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.PLSDATA FOR NVCL.PLSDATA';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.LAYOUTS FOR NVCL.LAYOUTS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.CALIBRATIONLOGS FOR NVCL.CALIBRATIONLOGS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.CALIBRATIONLOGDATA FOR NVCL.CALIBRATIONLOGDATA';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.EVENTJOURNAL FOR NVCL.EVENTJOURNAL';
END SETUPNVCLVIEWER;

/
--------------------------------------------------------
--  DDL for Procedure SETUPWEBSERVICE
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."SETUPWEBSERVICE" 
( v_username IN VARCHAR2
) AUTHID CURRENT_USER AS
BEGIN
  EXECUTE IMMEDIATE 'Grant WEBSERVICE to ' || v_username;
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.PUBLISHEDDATASETS FOR NVCL.PUBLISHEDDATASETS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.PUBLISHEDLOGS FOR NVCL.PUBLISHEDLOGS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.COMPOUNDMATERIAL FOR NVCL.COMPOUNDMATERIAL';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.SAMPLINGFEATURECOLLECTIONS FOR NVCL.SAMPLINGFEATURECOLLECTIONS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.GETPUBLISHEDSYSTEMTSA FOR NVCL.GETPUBLISHEDSYSTEMTSA'; 
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.LOCATEDSPECIMENS FOR NVCL.LOCATEDSPECIMENS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.OBSERVATIONS FOR NVCL.OBSERVATIONS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.PUBLISHEDALGORITHMS FOR NVCL.PUBLISHEDALGORITHMS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.PUBLISHEDIMAGELOGDATA FOR NVCL.PUBLISHEDIMAGELOGDATA';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.GETDOWNSAMPLEDLOGVALUES FOR NVCL.GETDOWNSAMPLEDLOGVALUES';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.GETDOMAINDATA FOR NVCL.GETDOMAINDATA';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.DOMAINLOGDATA FOR NVCL.DOMAINLOGDATA';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.DECIMALLOGDATA FOR NVCL.DECIMALLOGDATA';  
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.CLASSLOGDATA FOR NVCL.CLASSLOGDATA';  
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.CLASSSPECIFICCLASSIFICATIONS FOR NVCL.CLASSSPECIFICCLASSIFICATIONS';
  EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM ' || v_username || '.CLASSIFICATIONS FOR NVCL.CLASSIFICATIONS';
END SETUPWEBSERVICE;

/
--------------------------------------------------------
--  DDL for Procedure TOUCHLOG
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."TOUCHLOG" 
( v_logid IN VARCHAR2
,v_usercheckok out number
) AS
now TIMESTAMP(0) with time zone:= systimestamp;
lastmodifier VARCHAR2(100);
BEGIN
  SELECT modifierusername into lastmodifier FROM logs WHERE log_id= v_logid;
  UPDATE logs SET modifierusername=user, modifieddate=now WHERE log_id = v_logid;
  if (lastmodifier=user) then v_usercheckok:=1;
  else v_usercheckok:=0;
  end if;
END TOUCHLOG;

/

  GRANT EXECUTE ON "NVCL"."TOUCHLOG" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure UPDATECALIBRATIONLOG
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."UPDATECALIBRATIONLOG" 
( v_logid IN VARCHAR2
) AS
BEGIN
  UPDATE CALIBRATIONLOGS SET LOG_ID=v_logid WHERE LOG_ID=v_logid;
END UPDATECALIBRATIONLOG;

/

  GRANT EXECUTE ON "NVCL"."UPDATECALIBRATIONLOG" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure UPDATECALIBRATIONLOGDATA
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."UPDATECALIBRATIONLOGDATA" 
( v_calibrationlog_id IN VARCHAR2
, v_samplenumber IN NUMBER
, v_calibrationdata IN BLOB
) AS
BEGIN
  UPDATE calibrationlogdata SET samplenumber= v_samplenumber, calibrationdata= v_calibrationdata WHERE log_id= v_calibrationlog_id;
END UPDATECALIBRATIONLOGDATA;

/

  GRANT EXECUTE ON "NVCL"."UPDATECALIBRATIONLOGDATA" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure UPDATECLASSLOG
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."UPDATECLASSLOG" 
( v_logid IN VARCHAR2
, v_scalgroupid IN NUMBER 
) AS
BEGIN
  UPDATE classlogs SET scalargroup_id = v_scalgroupid WHERE LOG_ID= v_logid;
END UPDATECLASSLOG;

/

  GRANT EXECUTE ON "NVCL"."UPDATECLASSLOG" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure UPDATECLASSLOGDATA
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."UPDATECLASSLOGDATA" 
( v_classlog_id IN VARCHAR2
, v_samplenumber IN NUMBER
, v_classvalue IN NUMBER
) AS
BEGIN
  UPDATE classlogdata SET classlogvalue= v_classvalue WHERE log_id = v_classlog_id AND samplenumber= v_samplenumber;
END UPDATECLASSLOGDATA;

/

  GRANT EXECUTE ON "NVCL"."UPDATECLASSLOGDATA" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure UPDATECLASSSPECCLASSIFICATION
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."UPDATECLASSSPECCLASSIFICATION" 
( v_classlog_id IN VARCHAR2
, v_intind IN NUMBER
, v_colour IN NUMBER
, v_text IN VARCHAR2
, v_description IN VARCHAR2
) AS
BEGIN
  UPDATE classspecificclassifications SET  colour= v_colour, classtext= v_text, description= v_description WHERE log_id=v_classlog_id AND intindex=v_intind;
END UPDATECLASSSPECCLASSIFICATION;

/

  GRANT EXECUTE ON "NVCL"."UPDATECLASSSPECCLASSIFICATION" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure UPDATEDATASET
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."UPDATEDATASET" 
( v_ds_id in VARCHAR2
, v_dsname IN VARCHAR2
, v_extdhservicename IN VARCHAR2
, v_extdhid IN VARCHAR2
, v_tsglayout IN clob
, v_isreflib IN BOOLEAN
, v_domlogid IN VARCHAR2
, v_primarymachineid IN NUMBER
, v_mainspectrallogid IN VARCHAR2
, v_mainimagelogid IN VARCHAR2
, v_mainproflogid IN VARCHAR2
, v_traylogid IN VARCHAR2
, v_sectionlogid IN VARCHAR2
, v_dsdescription IN VARCHAR2
, v_origauthor IN VARCHAR2
, v_scantime IN TIMESTAMP with time zone
, v_importtime IN TIMESTAMP with time zone
, v_customdsid IN VARCHAR2
, v_custcalcdsid IN VARCHAR2
, v_ispublic in BOOLEAN
, v_chk_l0archived IN NUMBER 
, v_chk_fmstatus IN NUMBER 
, v_chk_tidlstatus IN NUMBER 
, v_chk_imgstatus IN NUMBER 
, v_chk_sutsa IN NUMBER 
, v_chk_vutsa IN NUMBER 
, v_chk_tutsa IN NUMBER 
, v_chk_imports IN NUMBER 
, v_chk_rmarks IN NUMBER 
, v_chk_batstatus IN NUMBER 
, v_chk_sclrstatus IN NUMBER 
, v_chk_domains IN NUMBER 
, v_chk_plots IN NUMBER 
, v_chk_layouts IN NUMBER 
, v_chk_dbase IN NUMBER 
) AS
tmpisreflib number;
tmpispublic number;
now TIMESTAMP(0) with time zone:= systimestamp;
BEGIN
  if (v_isreflib) then tmpisreflib:=1;
  else tmpisreflib:=0;
  end if;
  if (v_ispublic) then tmpispublic:=1;
  else tmpispublic:=0;
  end if;
  UPDATE datasets SET datasetname =v_dsname,domain_id= v_domlogid, modifieddate=now, modifierusername=user, tsglayout=v_tsglayout, isreferencelibrary=tmpisreflib , primarylogger_id= v_primarymachineid, speclog_id= v_mainspectrallogid, imagelog_id= v_mainimagelogid, proflog_id= v_mainproflogid, traylog_id= v_traylogid, sectionlog_id= v_sectionlogid, holedatasourcename= v_extdhservicename, holeidentifier= v_extdhid, dsdescription=v_dsdescription, origauthor=v_origauthor, scandate=v_scantime, importdate= v_importtime, customdataset_id= v_customdsid, custcalcdataset_id= v_custcalcdsid, ispublic= tmpispublic, chk_l0archived = v_chk_l0archived, chk_fmstatus = v_chk_fmstatus, chk_tidlstatus = v_chk_tidlstatus, chk_imgstatus = v_chk_imgstatus, chk_sutsa = v_chk_sutsa, chk_vutsa = v_chk_vutsa, chk_tutsa = v_chk_tutsa, chk_imports = v_chk_imports, chk_rmarks = v_chk_rmarks, chk_batstatus = v_chk_batstatus, chk_sclrstatus = v_chk_sclrstatus, chk_domains = v_chk_domains, chk_plots = v_chk_plots, chk_layouts = v_chk_layouts, chk_dbase = v_chk_dbase WHERE dataset_id= v_ds_id;
END UPDATEDATASET;

/

  GRANT EXECUTE ON "NVCL"."UPDATEDATASET" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure UPDATEDECIMALLOG
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."UPDATEDECIMALLOG" 
( v_logid IN VARCHAR2
, v_scalgroupid IN NUMBER 
, v_minthreshold IN FLOAT 
, v_maxthreshold IN FLOAT 
, v_isrgbcolour IN NUMBER 
) AS
BEGIN
  UPDATE decimallogs SET scalargroup_id= v_scalgroupid, minthreshold=v_minthreshold, maxthreshold= v_maxthreshold, resultisrgbcolour= v_isrgbcolour WHERE log_id=v_logid;
END UPDATEDECIMALLOG;

/

  GRANT EXECUTE ON "NVCL"."UPDATEDECIMALLOG" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure UPDATEDECIMALLOGDATA
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."UPDATEDECIMALLOGDATA" 
( v_declog_id IN VARCHAR2
, v_samplenumber IN NUMBER
, v_decvalue IN DOUBLE PRECISION
) AS
BEGIN
  UPDATE decimallogdata SET decimalvalue= v_decvalue WHERE log_id = v_declog_id AND samplenumber= v_samplenumber;
END UPDATEDECIMALLOGDATA;

/

  GRANT EXECUTE ON "NVCL"."UPDATEDECIMALLOGDATA" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure UPDATEDOMAINLOG
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."UPDATEDOMAINLOG" 
( v_logid IN VARCHAR2
, v_units IN VARCHAR2
, v_issubdomainof IN VARCHAR2
, v_scalargroupid IN NUMBER
) AS

BEGIN
  UPDATE domainlogs SET units=v_units, issubdomainoflog_id= v_issubdomainof, scalargroup_id= v_scalargroupid WHERE log_id = v_logid;
END UPDATEDOMAINLOG;

/

  GRANT EXECUTE ON "NVCL"."UPDATEDOMAINLOG" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure UPDATEDOMLOGDATA
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."UPDATEDOMLOGDATA" 
( v_domlog_id IN VARCHAR2
, v_samplenumber IN NUMBER 
, v_startvalue IN DOUBLE PRECISION
, v_endvalue IN DOUBLE PRECISION
, v_name IN VARCHAR2
, v_desc IN VARCHAR2
, v_colour IN NUMBER
, v_swirminlist IN BLOB
, v_swirtsaversion IN NUMBER
, v_vnirminlist IN BLOB
, v_vnirtsaversion IN NUMBER
, v_tirminlist IN BLOB
, v_tirtsaversion IN NUMBER 
) AS
BEGIN
  UPDATE DOMAINLOGDATA SET startvalue= v_startvalue, endvalue= v_endvalue, samplename= v_name, DESCRIPTION = v_desc, COLOUR = v_colour, SWIRMINLIST = v_swirminlist, SWIRTSAVERSION = v_swirtsaversion,	VNIRMINLIST = v_vnirminlist, VNIRTSAVERSION = v_vnirtsaversion, TIRMINLIST = v_tirminlist, TIRTSAVERSION = v_tirtsaversion WHERE log_id=v_domlog_id AND samplenumber= v_samplenumber;
END UPDATEDOMLOGDATA;

/

  GRANT EXECUTE ON "NVCL"."UPDATEDOMLOGDATA" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure UPDATEEVENTJOURNALEVENT
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."UPDATEEVENTJOURNALEVENT" 
( v_dataset_id IN VARCHAR2
, v_eventnumber IN NUMBER 
, v_catno IN NUMBER
, v_isprimary IN NUMBER
, v_eventtime IN DATE 
, v_tsgproduct IN VARCHAR2 
, v_tsguser IN VARCHAR2
, v_content IN VARCHAR2
) AS
BEGIN
  UPDATE EVENTJOURNAL SET CATNO=v_catno, EVENTTIME= v_eventtime, TSGPRODUCT=v_tsgproduct, TSGUSER= v_tsguser, CONTENT= v_content WHERE DATASET_ID=v_dataset_id AND EVENTNUMBER=v_eventnumber AND ISPRIMARY=v_isprimary;
END UPDATEEVENTJOURNALEVENT;

/

  GRANT EXECUTE ON "NVCL"."UPDATEEVENTJOURNALEVENT" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure UPDATEIMAGELOG
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."UPDATEIMAGELOG" 
( v_logid IN VARCHAR2
, v_imghist IN BLOB
, v_imgclippercent IN NUMBER
, v_logtime IN timestamp with time zone
, v_imgwidth IN NUMBER 
, v_imgheight IN NUMBER 
) AS
BEGIN
  UPDATE imagelogs SET imghistogram=v_imghist, imgclippercent=v_imgclippercent, logtimestamp= v_logtime, imgwidth= v_imgwidth ,imgheight= v_imgheight WHERE LOG_ID= v_logid;
END UPDATEIMAGELOG;

/

  GRANT EXECUTE ON "NVCL"."UPDATEIMAGELOG" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure UPDATEIMAGELOGDATA
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."UPDATEIMAGELOGDATA" 
( v_imagelog_id IN VARCHAR2
, v_samplenumber IN NUMBER
, v_imagedata IN BLOB
, v_imgcomment IN VARCHAR2
) AS
BEGIN
  UPDATE imagelogdata SET samplenumber= v_samplenumber, imagedata= v_imagedata, imagecomment= v_imgcomment WHERE log_id= v_imagelog_id;
END UPDATEIMAGELOGDATA;

/

  GRANT EXECUTE ON "NVCL"."UPDATEIMAGELOGDATA" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure UPDATELAYOUT
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."UPDATELAYOUT" 
( v_dsid IN VARCHAR2
,v_layoutnumber IN NUMBER
,v_layoutdata IN CLOB
,v_layoutname IN VARCHAR2
) AS
BEGIN
  UPDATE LAYOUTS SET LAYOUTDATA=v_layoutdata,LAYOUTNAME=v_layoutname WHERE DATASET_ID=v_dsid AND LAYOUTNO=v_layoutnumber;
END UPDATELAYOUT;

/

  GRANT EXECUTE ON "NVCL"."UPDATELAYOUT" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure UPDATELOG
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."UPDATELOG" 
( v_logname IN VARCHAR2
, v_description IN VARCHAR2
, v_ispublic IN NUMBER
, v_logid IN VARCHAR2
, v_domlogid IN VARCHAR2
, v_stdalgid IN NUMBER
, v_custscript IN CLOB
, v_masklogid IN VARCHAR2
, v_refstatsid IN VARCHAR2
, v_tsaretrainid IN VARCHAR2
, v_tsghandmask IN NUMBER
, v_batchscript IN CLOB
, v_mixnumber IN NUMBER
, v_auxlayerid IN VARCHAR2
, v_locallayerid IN VARCHAR2
, v_plsid IN VARCHAR2
) AS
now TIMESTAMP(0) with time zone:= systimestamp;
BEGIN
  UPDATE logs SET logname= v_logname, modifierusername=user, modifieddate=now, domainlog_id= v_domlogid,description= v_description, ispublic= v_ispublic, algorithmoutput_id= v_stdalgid, customscript= v_custscript, masklog_id= v_masklogid, refstats_id= v_refstatsid, tsaretraining_id= v_tsaretrainid, tsghandmask= v_tsghandmask, batchscript= v_batchscript, mixnumber= v_mixnumber, localspectrallayer_id= v_locallayerid, auxspectrallayer_id= v_auxlayerid, pls_id=v_plsid WHERE log_id = v_logid;
END UPDATELOG;

/

  GRANT EXECUTE ON "NVCL"."UPDATELOG" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure UPDATELOGDEP
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."UPDATELOGDEP" 
( v_logid IN VARCHAR2
, v_dependsonid IN VARCHAR2
, v_depname in VARCHAR2
, v_order in number
) AS
BEGIN
  UPDATE logdependencies SET dependson= v_dependsonid, relationname= v_depname, priorityorder= v_order WHERE LOG_ID= v_logid;
END UPDATELOGDEP;

/

  GRANT EXECUTE ON "NVCL"."UPDATELOGDEP" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure UPDATELOGMASK
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."UPDATELOGMASK" 
( v_logid IN VARCHAR2
, v_maskid IN VARCHAR2
) AS
BEGIN
  UPDATE Logs SET masklog_id= v_maskid WHERE log_id= v_logid;
END UPDATELOGMASK;

/

  GRANT EXECUTE ON "NVCL"."UPDATELOGMASK" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure UPDATEMASKLOG
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."UPDATEMASKLOG" 
( v_logid IN VARCHAR2
, v_scalgroupid IN NUMBER 
) AS
BEGIN
  UPDATE masklogs SET scalargroup_id = v_scalgroupid WHERE LOG_ID= v_logid;
END UPDATEMASKLOG;

/

  GRANT EXECUTE ON "NVCL"."UPDATEMASKLOG" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure UPDATEMASKLOGDATA
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."UPDATEMASKLOGDATA" 
( v_masklog_id IN VARCHAR2
, v_samplenumber IN NUMBER
, v_maskvalue IN NUMBER
) AS
BEGIN
  UPDATE masklogdata SET maskvalue= v_maskvalue WHERE log_id= v_masklog_id AND samplenumber= v_samplenumber;
END UPDATEMASKLOGDATA;

/

  GRANT EXECUTE ON "NVCL"."UPDATEMASKLOGDATA" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure UPDATEPROFLOG
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."UPDATEPROFLOG" 
( v_logid IN VARCHAR2
, v_logtime IN timestamp with time zone
, v_minval in float
, v_maxval in float
, v_floatspersample IN NUMBER
) AS
BEGIN
  UPDATE proflogs SET logtimestamp=v_logtime, minval= v_minval, maxval= v_maxval, floatspersample=v_floatspersample WHERE log_id=v_logid;
END UPDATEPROFLOG;

/

  GRANT EXECUTE ON "NVCL"."UPDATEPROFLOG" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure UPDATEPROFLOGDATA
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."UPDATEPROFLOGDATA" 
( v_proflog_id IN VARCHAR2
, v_samplenumber IN NUMBER
, v_profdata IN BLOB
) AS
BEGIN
  UPDATE proflogdata SET profilometervalues= v_profdata WHERE log_id=v_proflog_id AND samplenumber= v_samplenumber;
END UPDATEPROFLOGDATA;

/

  GRANT EXECUTE ON "NVCL"."UPDATEPROFLOGDATA" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure UPDATESPECTRALLOG
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."UPDATESPECTRALLOG" 
( v_logid IN VARCHAR2
, v_specsamppoints in blob
, v_fwhm in blob
, v_specunits IN VARCHAR2
, v_logtime in timestamp with time zone
, v_logorder in number
, v_tirq in blob
) AS
BEGIN
  UPDATE spectrallogs SET spectralsamplingpoints= v_specsamppoints, fwhm= v_fwhm, spectralunits= v_specunits, logtimestamp= v_logtime, layerorder=v_logorder, tirq=v_tirq WHERE log_id = v_logid;
END UPDATESPECTRALLOG;

/

  GRANT EXECUTE ON "NVCL"."UPDATESPECTRALLOG" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure UPDATESPECTRALLOGDATA
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."UPDATESPECTRALLOGDATA" 
( v_speclog_id IN VARCHAR2
, v_samplenumber IN NUMBER 
, v_spectrum IN BLOB
) AS
BEGIN
  UPDATE SPECTRALLOGDATA SET SPECTRALVALUES = v_spectrum WHERE log_id= v_speclog_id AND samplenumber= v_samplenumber;
END UPDATESPECTRALLOGDATA;

/

  GRANT EXECUTE ON "NVCL"."UPDATESPECTRALLOGDATA" TO "NVCLANALYST";
--------------------------------------------------------
--  DDL for Procedure UPDATETSARETRAINING
--------------------------------------------------------
set define off;

  CREATE OR REPLACE PROCEDURE "NVCL"."UPDATETSARETRAINING" 
( v_numallclasses IN NUMBER
, v_numtrainclasses IN NUMBER
, v_tsaparams IN BLOB
, v_minmask IN BLOB
, v_mixmask IN BLOB
, v_tsaretrainid in VARCHAR2
, v_dbix IN NUMBER
, v_trainsel IN NUMBER
, v_seven IN NUMBER
, v_illite IN NUMBER
, v_domained IN NUMBER
, v_version IN NUMBER
, v_plus IN NUMBER
) AS
BEGIN
  UPDATE tsaretraining SET numallclasses= v_numallclasses,numtrainclasses= v_numtrainclasses,tsaparams= v_tsaparams,minmask= v_minmask,mixmask= v_mixmask, dbix= v_dbix, trainsel=v_trainsel, illite=v_illite ,seven=v_seven, domained=v_domained, version=v_version, plus=v_plus WHERE tsaretraining_id=v_tsaretrainid;
END UPDATETSARETRAINING;

/

  GRANT EXECUTE ON "NVCL"."UPDATETSARETRAINING" TO "NVCLANALYST";
REM INSERTING into NVCL.LOGTYPES
Insert into NVCL.LOGTYPES (LOGTYPE_ID,LOGTYPENAME) values (0,'domain');
Insert into NVCL.LOGTYPES (LOGTYPE_ID,LOGTYPENAME) values (1,'class');
Insert into NVCL.LOGTYPES (LOGTYPE_ID,LOGTYPENAME) values (2,'decimal');
Insert into NVCL.LOGTYPES (LOGTYPE_ID,LOGTYPENAME) values (3,'image');
Insert into NVCL.LOGTYPES (LOGTYPE_ID,LOGTYPENAME) values (4,'profile');
Insert into NVCL.LOGTYPES (LOGTYPE_ID,LOGTYPENAME) values (5,'spectral');
Insert into NVCL.LOGTYPES (LOGTYPE_ID,LOGTYPENAME) values (6,'mask');
Insert into NVCL.LOGTYPES (LOGTYPE_ID,LOGTYPENAME) values (7,'calibration');
REM INSERTING into NVCL.MACHINES
Insert into NVCL.MACHINES (MACHINE_ID,MACHINENAME,NAMESPACEID) values (1,'HyLogger 1','urn:cgi:object:CSIRO:HyLogger');
Insert into NVCL.MACHINES (MACHINE_ID,MACHINENAME,NAMESPACEID) values (7,'HyChips 6-3','urn:cgi:object:CSIRO:HyLogger');
Insert into NVCL.MACHINES (MACHINE_ID,MACHINENAME,NAMESPACEID) values (10,'HyLogger 2-2','urn:cgi:object:CSIRO:HyLogger');
Insert into NVCL.MACHINES (MACHINE_ID,MACHINENAME,NAMESPACEID) values (11,'HyLogger 2-3','urn:cgi:object:CSIRO:HyLogger');
Insert into NVCL.MACHINES (MACHINE_ID,MACHINENAME,NAMESPACEID) values (12,'HyLogger 2-4','urn:cgi:object:CSIRO:HyLogger');
Insert into NVCL.MACHINES (MACHINE_ID,MACHINENAME,NAMESPACEID) values (13,'HyLogger 2-5','urn:cgi:object:CSIRO:HyLogger');
Insert into NVCL.MACHINES (MACHINE_ID,MACHINENAME,NAMESPACEID) values (14,'HyLogger 2-6','urn:cgi:object:CSIRO:HyLogger');
Insert into NVCL.MACHINES (MACHINE_ID,MACHINENAME,NAMESPACEID) values (15,'HyLogger 2-7','urn:cgi:object:CSIRO:HyLogger');
Insert into NVCL.MACHINES (MACHINE_ID,MACHINENAME,NAMESPACEID) values (16,'HyLogger 2-8','urn:cgi:object:CSIRO:HyLogger');
Insert into NVCL.MACHINES (MACHINE_ID,MACHINENAME,NAMESPACEID) values (18,'HyLogger 3-1','urn:cgi:object:CSIRO:HyLogger');
Insert into NVCL.MACHINES (MACHINE_ID,MACHINENAME,NAMESPACEID) values (19,'HyLogger 3-2','urn:cgi:object:CSIRO:HyLogger'); -- WA
Insert into NVCL.MACHINES (MACHINE_ID,MACHINENAME,NAMESPACEID) values (20,'HyLogger 3-3','urn:cgi:object:CSIRO:HyLogger'); -- SA
Insert into NVCL.MACHINES (MACHINE_ID,MACHINENAME,NAMESPACEID) values (21,'HyLogger 3-4','urn:cgi:object:CSIRO:HyLogger'); -- NSW
Insert into NVCL.MACHINES (MACHINE_ID,MACHINENAME,NAMESPACEID) values (22,'HyLogger 3-5','urn:cgi:object:CSIRO:HyLogger'); -- Qld
Insert into NVCL.MACHINES (MACHINE_ID,MACHINENAME,NAMESPACEID) values (23,'HyLogger 3-6','urn:cgi:object:CSIRO:HyLogger'); -- Tas
Insert into NVCL.MACHINES (MACHINE_ID,MACHINENAME,NAMESPACEID) values (24,'HyLogger 3-7','urn:cgi:object:CSIRO:HyLogger'); -- NT
Insert into NVCL.MACHINES (MACHINE_ID,MACHINENAME,NAMESPACEID) values (25,'HyLogger 3-8','urn:cgi:object:CSIRO:HyLogger'); -- Vic