--==============================================================================
--==============================================================================
--==============================================================================
--==============================================================================
--============     DO NOT USE THIS SCRIPT ANYMORE     ==========================
--============         (WHEN USING JAVA-CERA)         ==========================
--============     TAKE THE EQUIVALENT FROM DKRZ!     ==========================
--============          ft,  2001-01-30               ==========================
--==============================================================================
--==============================================================================
--==============================================================================
--==============================================================================
-- ------------------------------------------------------ LOADING OF DATA: load_cover
--                                                                      1999.04.22 ft
-- filling NULLs
update LOAD_COVER set spatial_coverage_id = 0     where spatial_coverage_id  is NULL;
update LOAD_COVER set min_lat      = 0            where min_lat              is NULL;
update LOAD_COVER set max_lat      = 0            where max_lat              is NULL;
update LOAD_COVER set min_lon      = 0            where min_lon              is NULL;
update LOAD_COVER set max_lon      = 0            where max_lon              is NULL;
update LOAD_COVER set min_altitude = 0            where min_altitude         is NULL;
update LOAD_COVER set min_alt_unit ='*not filled' where min_alt_unit         is NULL;
update LOAD_COVER set max_altitude = 0            where max_altitude         is NULL;
update LOAD_COVER set max_alt_unit ='*not filled' where max_alt_unit         is NULL;
update LOAD_COVER set temporal_coverage_id = 0    where temporal_coverage_id is NULL;
update LOAD_COVER set start_year   = 0            where start_year           is NULL;
update LOAD_COVER set start_month  = 0            where start_month          is NULL;
update LOAD_COVER set start_day    = 0            where start_day            is NULL;
update LOAD_COVER set stop_year    = 0            where stop_year            is NULL;
update LOAD_COVER set stop_month   = 0            where stop_month           is NULL;
update LOAD_COVER set stop_day     = 0            where stop_day             is NULL;
update LOAD_COVER set currentness_ref_descr = '*not filled' where currentness_ref_descr is NULL;
--
-- ------------------------------------------------------ LOCATION_CONNECT relation:
insert into LOCATION_CONNECT (entry_id, location_id)
  select                      entry_id, location_id
  from LOAD_COVER, LOCATION
 where location_id > 0
   and LOCATION.location_name   = LOAD_COVER.location_name;
--
-- ------------------------------------------------------- TEMPORAL_COVERAGE entity:
--     identical records are stored one by one, they are not gathered....
--               ...(hope to change this one day...).
insert into TEMPORAL_COVERAGE (temporal_coverage_id, start_year, start_month, 
       start_day, stop_year, stop_month, stop_day,                 currentness_ref_id)
  select                       temporal_coverage_id, start_year, start_month, 
       start_day, stop_year, stop_month, stop_day, CURRENTNESS_REF.currentness_ref_id
  from LOAD_COVER,CURRENTNESS_REF
 where LOAD_COVER.currentness_ref_descr=CURRENTNESS_REF.currentness_ref_descr;
--
-- -------------------------------------------------------- SPATIAL_COVERAGE entity:
--     identical records are stored one by one, they are not gathered.
insert into SPATIAL_COVERAGE (spatial_coverage_id, min_lat, max_lat, min_lon,
            max_lon, min_altitude, min_alt_unit_id, max_altitude, max_alt_unit_id)
  select                      spatial_coverage_id, min_lat, max_lat, min_lon,
            max_lon, min_altitude,   UNIT1.unit_id, max_altitude,   UNIT2.unit_id
  from LOAD_COVER, UNIT1, UNIT2
 where LOAD_COVER.min_alt_unit           = UNIT1.unit_acronym
   and LOAD_COVER.max_alt_unit           = UNIT2.unit_acronym;
-- 
-- -------------------------------------------------------------- COVERAGE relation:
insert into COVERAGE (entry_id, temporal_coverage_id, spatial_coverage_id)
  select              entry_id, temporal_coverage_id, spatial_coverage_id
  from LOAD_COVER;
