drop view titan.epn_core;
CREATE or REPLACE VIEW titan.epn_core AS SELECT 
replace(filename,'.txt','_q_votable')::text AS granule_uid,  
text 'temp_abundance'::text AS granule_gid,  
replace(filename,'.txt','')::text  AS obs_id,
text 'pr' AS dataproduct_type, 
text 'Titan' AS target_name, 
text 'satellite' AS target_class, 
cast(to_char(date::date,'J') as double precision) AS time_min,
cast(to_char(date::date,'J') as double precision) AS time_max,
CAST(NULL AS DOUBLE PRECISION) AS time_sampling_step_min,
CAST(NULL AS DOUBLE PRECISION) AS time_sampling_step_max,
CAST(NULL AS DOUBLE PRECISION) AS time_exp_min,
CAST(NULL AS DOUBLE PRECISION) AS time_exp_max,
CAST(NULL AS DOUBLE PRECISION) AS spectral_range_min,
CAST(NULL AS DOUBLE PRECISION) AS spectral_range_max,
CAST(NULL AS DOUBLE PRECISION) AS spectral_sampling_step_min,
CAST(NULL AS DOUBLE PRECISION) AS spectral_sampling_step_max,
CAST(NULL AS DOUBLE PRECISION) AS spectral_resolution_min,
CAST(NULL AS DOUBLE PRECISION) AS spectral_resolution_max,
longitude AS c1min,
longitude AS c1max,
latitude AS c2min,
latitude AS c2max,
altmin as c3min,
altmax as c3max,
CAST(NULL AS DOUBLE PRECISION) as c1_resol_min,
CAST(NULL AS DOUBLE PRECISION) as c1_resol_max,
CAST(NULL AS DOUBLE PRECISION) as c2_resol_min,
CAST(NULL AS DOUBLE PRECISION) as c2_resol_max,
CAST(NULL AS DOUBLE PRECISION) as c3_resol_min,
CAST(NULL AS DOUBLE PRECISION) as c3_resol_max,
text 'body' AS spatial_frame_type,
CAST(NULL AS DOUBLE PRECISION) as incidence_min,
CAST(NULL AS DOUBLE PRECISION) as incidence_max,
CAST(NULL AS DOUBLE PRECISION) as emergence_min,
CAST(NULL AS DOUBLE PRECISION) as emergence_max,
CAST(NULL AS DOUBLE PRECISION) as phase_min,
CAST(NULL AS DOUBLE PRECISION) as phase_max,
text 'Cassini' AS instrument_host_name,
text 'Composite Infrared Spectrometer#CIRS' AS instrument_name, 
text 'phys.pressure#phys.temperature#phys.abund' AS measurement_type,
'http://voparis-srv-paris.obspm.fr/titan/to_vot_titan.py?fileurl=http://voparis-srv.obspm.fr/vo/planeto/titan/profil/'||filename::text AS access_url,
text 'application/x-votable+xml' AS access_format,
integer '143' AS access_estsize,
integer '5' AS processing_level,
text 'PADC on behalf of LESIA' AS publisher,
reference::text AS bib_reference,
text 'Titan_density_profile' AS service_title,
text 'atmosphere' AS target_region,
element::text AS species,
subsolar_lon AS solar_longitude,
local_time AS local_time_min,
local_time AS local_time_max,
text  'UTC' AS time_scale,
CAST(NULL AS timestamp) as release_date,
cast(date_crea::timestamp without time zone AT TIME ZONE 'UTC' as timestamp) AS creation_date,
cast(modif_date::timestamp without time zone AT TIME ZONE 'UTC' as timestamp) AS modification_date,
CAST(NULL AS spoly) AS s_region,
'http://voparis-srv.obspm.fr/vo/planeto/titan/thumbnail/'||replace(filename,'.txt','.png')::text AS thumbnail_url
FROM titan.profq
UNION ALL
SELECT 
replace(filename,'.txt','_q_ascii')::text AS granule_uid,  
text 'temp_abundance'::text AS granule_gid,  
replace(filename,'.txt','')::text  AS obs_id,
text 'pr' AS dataproduct_type, 
text 'Titan' AS target_name, 
text 'satellite' AS target_class, 
cast(to_char(date::date,'J') as double precision) AS time_min,
cast(to_char(date::date,'J') as double precision) AS time_max,
CAST(NULL AS DOUBLE PRECISION) AS time_sampling_step_min,
CAST(NULL AS DOUBLE PRECISION) AS time_sampling_step_max,
CAST(NULL AS DOUBLE PRECISION) AS time_exp_min,
CAST(NULL AS DOUBLE PRECISION) AS time_exp_max,
CAST(NULL AS DOUBLE PRECISION) AS spectral_range_min,
CAST(NULL AS DOUBLE PRECISION) AS spectral_range_max,
CAST(NULL AS DOUBLE PRECISION) AS spectral_sampling_step_min,
CAST(NULL AS DOUBLE PRECISION) AS spectral_sampling_step_max,
CAST(NULL AS DOUBLE PRECISION) AS spectral_resolution_min,
CAST(NULL AS DOUBLE PRECISION) AS spectral_resolution_max,
longitude AS c1min,
longitude AS c1max,
latitude AS c2min,
latitude AS c2max,
altmin as c3min,
altmax as c3max,
CAST(NULL AS DOUBLE PRECISION) as c1_resol_min,
CAST(NULL AS DOUBLE PRECISION) as c1_resol_max,
CAST(NULL AS DOUBLE PRECISION) as c2_resol_min,
CAST(NULL AS DOUBLE PRECISION) as c2_resol_max,
CAST(NULL AS DOUBLE PRECISION) as c3_resol_min,
CAST(NULL AS DOUBLE PRECISION) as c3_resol_max,
text 'body' AS spatial_frame_type,
CAST(NULL AS DOUBLE PRECISION) as incidence_min,
CAST(NULL AS DOUBLE PRECISION) as incidence_max,
CAST(NULL AS DOUBLE PRECISION) as emergence_min,
CAST(NULL AS DOUBLE PRECISION) as emergence_max,
CAST(NULL AS DOUBLE PRECISION) as phase_min,
CAST(NULL AS DOUBLE PRECISION) as phase_max,
text 'Cassini' AS instrument_host_name,
text 'Composite Infrared Spectrometer#CIRS' AS instrument_name, 
text 'phys.pressure#phys.temperature#phys.abund' AS measurement_type,
'http://voparis-srv.obspm.fr/vo/planeto/titan/profil/'||filename::text AS access_url,
text 'text/plain' AS access_format,
integer '143' AS access_estsize,
integer '5' AS processing_level,
text 'PADC on behalf of LESIA' AS publisher,
reference::text AS bib_reference,
text 'Titan_density_profile' AS service_title,
text 'atmosphere' AS target_region,
element::text AS species,
subsolar_lon AS solar_longitude,
local_time AS local_time_min,
local_time AS local_time_max,
text  'UTC' AS time_scale,
CAST(NULL AS timestamp) as release_date,
cast(date_crea::timestamp without time zone AT TIME ZONE 'UTC' as timestamp) AS creation_date,
cast(modif_date::timestamp without time zone AT TIME ZONE 'UTC' as timestamp) AS modification_date,
CAST(NULL AS spoly) AS s_region,
'http://voparis-srv.obspm.fr/vo/planeto/titan/thumbnail/'||replace(filename,'.txt','.png')::text AS thumbnail_url
FROM titan.profq
UNION ALL
SELECT 
replace(filename,'.txt','_t_votable')::text AS granule_uid,  
text 'temp_presure' AS granule_gid,  
replace(filename,'.txt','')::text  AS obs_id,
text 'pr' AS dataproduct_type, 
text 'Titan' AS target_name, 
text 'satellite' AS target_class, 
cast(to_char(date::date,'J') as double precision) AS time_min,
cast(to_char(date::date,'J') as double precision) AS time_max,
CAST(NULL AS DOUBLE PRECISION) AS time_sampling_step_min,
CAST(NULL AS DOUBLE PRECISION) AS time_sampling_step_max,
CAST(NULL AS DOUBLE PRECISION) AS time_exp_min,
CAST(NULL AS DOUBLE PRECISION) AS time_exp_max,
CAST(NULL AS DOUBLE PRECISION) AS spectral_range_min,
CAST(NULL AS DOUBLE PRECISION) AS spectral_range_max,
CAST(NULL AS DOUBLE PRECISION) AS spectral_sampling_step_min,
CAST(NULL AS DOUBLE PRECISION) AS spectral_sampling_step_max,
CAST(NULL AS DOUBLE PRECISION) AS spectral_resolution_min,
CAST(NULL AS DOUBLE PRECISION) AS spectral_resolution_max,
longitude AS c1min,
longitude AS c1max,
latitude AS c2min,
latitude AS c2max,
altmin as c3min,
altmax as c3max,
CAST(NULL AS DOUBLE PRECISION) as c1_resol_min,
CAST(NULL AS DOUBLE PRECISION) as c1_resol_max,
CAST(NULL AS DOUBLE PRECISION) as c2_resol_min,
CAST(NULL AS DOUBLE PRECISION) as c2_resol_max,
CAST(NULL AS DOUBLE PRECISION) as c3_resol_min,
CAST(NULL AS DOUBLE PRECISION) as c3_resol_max,
text 'body' AS spatial_frame_type,
CAST(NULL AS DOUBLE PRECISION) as incidence_min,
CAST(NULL AS DOUBLE PRECISION) as incidence_max,
CAST(NULL AS DOUBLE PRECISION) as emergence_min,
CAST(NULL AS DOUBLE PRECISION) as emergence_max,
CAST(NULL AS DOUBLE PRECISION) as phase_min,
CAST(NULL AS DOUBLE PRECISION) as phase_max,
text 'Cassini' AS instrument_host_name,
text 'Composite Infrared Spectrometer#CIRS' AS instrument_name, 
text 'phys.pressure#phys.temperature' AS measurement_type,
'http://voparis-srv-paris.obspm.fr/titan/to_vot_titan.py?fileurl=http://voparis-srv.obspm.fr/vo/planeto/titan/profil/'||filename::text AS access_url,
text 'application/x-votable+xml' AS access_format,
integer '8' AS access_estsize,
integer '5' AS processing_level,
text 'PADC on behalf of LESIA' AS publisher,
reference::text AS bib_reference,
text 'Titan_Temperature_Pressure_Profile' AS service_title,
text 'atmosphere' AS target_region,
NULL AS species,
subsolar_lon AS solar_longitude,
local_time AS local_time_min,
local_time AS local_time_max,
text  'UTC' AS time_scale,
CAST(NULL AS timestamp) as release_date,
cast(date_crea::timestamp without time zone AT TIME ZONE 'UTC' as timestamp) AS creation_date,
cast(modif_date::timestamp without time zone AT TIME ZONE 'UTC' as timestamp) AS modification_date,
CAST(NULL AS spoly) AS s_region,
'http://voparis-srv.obspm.fr/vo/planeto/titan/thumbnail/'||replace(filename,'.txt','.png') AS thumbnail_url
FROM titan.proft
UNION ALL
SELECT 
replace(filename,'.txt','_t_ascii')::text AS granule_uid,  
text 'temp_presure' AS granule_gid,  
replace(filename,'.txt','')::text  AS obs_id,
text 'pr' AS dataproduct_type, 
text 'Titan' AS target_name, 
text 'satellite' AS target_class, 
cast(to_char(date::date,'J') as double precision) AS time_min,
cast(to_char(date::date,'J') as double precision) AS time_max,
CAST(NULL AS DOUBLE PRECISION) AS time_sampling_step_min,
CAST(NULL AS DOUBLE PRECISION) AS time_sampling_step_max,
CAST(NULL AS DOUBLE PRECISION) AS time_exp_min,
CAST(NULL AS DOUBLE PRECISION) AS time_exp_max,
CAST(NULL AS DOUBLE PRECISION) AS spectral_range_min,
CAST(NULL AS DOUBLE PRECISION) AS spectral_range_max,
CAST(NULL AS DOUBLE PRECISION) AS spectral_sampling_step_min,
CAST(NULL AS DOUBLE PRECISION) AS spectral_sampling_step_max,
CAST(NULL AS DOUBLE PRECISION) AS spectral_resolution_min,
CAST(NULL AS DOUBLE PRECISION) AS spectral_resolution_max,
longitude AS c1min,
longitude AS c1max,
latitude AS c2min,
latitude AS c2max,
altmin as c3min,
altmax as c3max,
CAST(NULL AS DOUBLE PRECISION) as c1_resol_min,
CAST(NULL AS DOUBLE PRECISION) as c1_resol_max,
CAST(NULL AS DOUBLE PRECISION) as c2_resol_min,
CAST(NULL AS DOUBLE PRECISION) as c2_resol_max,
CAST(NULL AS DOUBLE PRECISION) as c3_resol_min,
CAST(NULL AS DOUBLE PRECISION) as c3_resol_max,
text 'body' AS spatial_frame_type,
CAST(NULL AS DOUBLE PRECISION) as incidence_min,
CAST(NULL AS DOUBLE PRECISION) as incidence_max,
CAST(NULL AS DOUBLE PRECISION) as emergence_min,
CAST(NULL AS DOUBLE PRECISION) as emergence_max,
CAST(NULL AS DOUBLE PRECISION) as phase_min,
CAST(NULL AS DOUBLE PRECISION) as phase_max,
text 'Cassini' AS instrument_host_name,
text 'Composite Infrared Spectrometer#CIRS' AS instrument_name, 
text 'phys.pressure#phys.temperature' AS measurement_type,
'http://voparis-srv.obspm.fr/vo/planeto/titan/profil/'||filename::text AS access_url,
text 'text/plain' AS access_format,
integer '8' AS access_estsize,
integer '5' AS processing_level,
text 'PADC on behalf of LESIA' AS publisher,
reference::text AS bib_reference,
text 'Titan_Temperature_Pressure_Profile' AS service_title,
text 'atmosphere' AS target_region,
NULL AS species,
subsolar_lon AS solar_longitude,
local_time AS local_time_min,
local_time AS local_time_max,
text  'UTC' AS time_scale,
CAST(NULL AS timestamp) as release_date,
cast(date_crea::timestamp without time zone AT TIME ZONE 'UTC' as timestamp) AS creation_date,
cast(modif_date::timestamp without time zone AT TIME ZONE 'UTC' as timestamp) AS modification_date,
CAST(NULL AS spoly) AS s_region,
'http://voparis-srv.obspm.fr/vo/planeto/titan/thumbnail/'||replace(filename,'.txt','.png') AS thumbnail_url
FROM titan.proft;

GRANT ALL PRIVILEGES ON SCHEMA titan TO gavo WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON SCHEMA titan TO gavoadmin WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON titan.proft to gavoadmin WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON titan.proft to gavo WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON titan.proft to dachsroot WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON titan.profq to gavoadmin WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON titan.profq to dachsroot WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON titan.profq to gavo WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON titan.epn_core to gavoadmin WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON titan.epn_core to gavo WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON titan.epn_core to dachsroot WITH GRANT OPTION;
