Skip to content

Commit

Permalink
Merge pull request #144 from IPGP/master
Browse files Browse the repository at this point in the history
master > gnssrnx3
  • Loading branch information
PierreS-alpha authored Dec 14, 2023
2 parents 9aebfab + 68b4cfc commit 9255bb9
Show file tree
Hide file tree
Showing 156 changed files with 4,262 additions and 42,701 deletions.
19 changes: 1 addition & 18 deletions CODE/cgi-bin/OSM.pl
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,7 @@ END
<DIV id="map" style="height: ${height}px"></DIV>
<script type="text/javascript">
var esriAttribution = 'Tiles &copy; Esri &mdash; Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community';
var stamenAttribution = 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a> &mdash; Map data &copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors';
var osmAttribution = 'Map data &copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors';
var terrain = L.tileLayer('https://stamen-tiles-{s}.a.ssl.fastly.net/terrain/{z}/{x}/{y}{r}.{ext}', {
attribution: stamenAttribution,
subdomains: 'abcd',
minZoom: 0,
maxZoom: 18,
ext: 'png'
});
var watercolor = L.tileLayer('https://stamen-tiles-{s}.a.ssl.fastly.net/watercolor/{z}/{x}/{y}.{ext}', {
attribution: stamenAttribution,
subdomains: 'abcd',
minZoom: 1,
maxZoom: 18,
ext: 'jpg'
});
var topo = L.tileLayer('https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png', {
maxZoom: 17,
attribution: osmAttribution});
Expand All @@ -141,12 +126,10 @@ END
var map = L.map('map', {
center: [$lat, $lon],
zoom: $WEBOBS{OSM_ZOOM_VALUE},
layers: [terrain,topo,osm,watercolor,satellite]});
layers: [topo,osm,satellite]});
var baseMaps = {
"Stamen Terrain": terrain,
"OpenTopoMap": topo,
"OpenStreetMap": osm,
"Stamen Watercolor": watercolor,
"ESRI World Imagery": satellite,
};
var layerControl = L.control.layers(baseMaps).addTo(map);
Expand Down
260 changes: 260 additions & 0 deletions CODE/cgi-bin/WebObs/GML.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,260 @@
#---------------------------------------------------------------
# ------------------- WEBOBS / IPGP ----------------------------
# GML.pm
# ------
# Perl module to import GeodesyML files
#
# Authors: Pierre Sakic <[email protected]>
# Created: 2022-12-07
#--------------------------------------------------------------s
use strict;
use WebObs::XML2;
#--------------------------------------------------------------
sub gmlarray2nodearray {
#
# Convert **reference** XML/GeodesyML array
# (imported with xml2 buildin fct)
# to
# a "Node Array" i.e. one device change
# OR
# a list of Node Arrays if 'all' is used as index

### Inputs
my @GmlArray = @{$_[0]}; # an **reference** GeodesyML array parsed with XML2 Linux bin
my $nodename = $_[1]; # rec, ant, etc....
my $idx = $_[2]; # node index, we recommend -1 (last one per default)
# OR
# 'all' to get all the nodes
my $root ;
my $root0 ;

$root0 = '/geo:GeodesyML/geo:siteLog';

if ( $nodename eq "rec" ) {
$root = "$root0/geo:gnssReceiver/geo:GnssReceiver";
} elsif ( $nodename eq "ant" ) {
$root = "$root0/geo:gnssAntenna/geo:GnssAntenna";
} else {
die ("nodename not defined !!")
}

## get all ids for all nodes
my @Ids = findvalues("$root/\@gml:id=",\@GmlArray);

## Case 1: we want all nodes (idx == "all")
if ( $idx eq "all" ){
my @NodesList;
my $id;
foreach $id (@Ids){
$id =~ s/^\s+|\s+$//g ; # very important, id must be trimmed
## Get the Node we want
my @Node = findnodes($root,"/\@gml:id=",$id,\@GmlArray);
## stack it
push(@NodesList,[ @Node ]); # [] are very important, to force Node as a list
}
return @NodesList;

## Case 2: we want a specific node (idx € int)
} else {
## find id of the node we want
my $id = @Ids[$idx];
$id =~ s/^\s+|\s+$//g ; # very important, id must be trimmed
## Get the Node we want
my @Node = findnodes($root,"/\@gml:id=",$id,\@GmlArray);
return @Node;
}
}

sub rec_nodearray2hash {
#
# Convert a **reference** Receiver Node Array
# (created with gmlarray2nodearray)
# to
# a hash (i.e. a dict-like)
#
my @Rec = @{$_[0]};
my %hashrec;

$hashrec{model} = findvalue('/geo:igsModelCode=',\@Rec);
$hashrec{satsys} = findvalue('/geo:satelliteSystem=',\@Rec);
$hashrec{sn} = findvalue('/geo:manufacturerSerialNumber=',\@Rec);
$hashrec{vfirm} = findvalue('/geo:firmwareVersion=',\@Rec);
$hashrec{cutoff} = findvalue('/geo:elevationCutoffSetting=',\@Rec);
$hashrec{dinsta} = findvalue('/geo:dateInstalled=',\@Rec);
$hashrec{dremov} = findvalue('/geo:dateRemoved=',\@Rec);

return %hashrec;
}

sub ant_nodearray2hash {
#
# Convert a **reference** Antenna Node Array
# (created with gmlarray2nodearray)
# to
# a hash (i.e. a dict-like)
#
my @Ant = @{$_[0]};
my %hashant;

$hashant{model} = findvalue('/geo:igsModelCode=',\@Ant);
$hashant{sn} = findvalue('/geo:manufacturerSerialNumber=',\@Ant);
$hashant{radome} = findvalue('/geo:antennaRadomeType=',\@Ant);
$hashant{alignN} = findvalue('/geo:alignmentFromTrueNorth=',\@Ant);
$hashant{lcable} = findvalue('/geo:antennaCableLength=',\@Ant);
$hashant{dinsta} = findvalue('/geo:dateInstalled=',\@Ant);
$hashant{dremov} = findvalue('/geo:dateRemoved=',\@Ant);

return %hashant;
}

sub gmlread_feature {
#
# Wrapper function
#
# Convert a XML/GeodesyML file
# to
# **reference** hashes (rec, ant, misc)
# for the CURRENT instrumentation
#
my $file = $_[0];
my %hashrec;
my %hashant;
my %hashmisc;
my @Gml;

if ( not -f $file)
{
die "$file not found"
}

#### HARDCODED XML2
# my @Gml = qx($WEBOBS{XML2_PRGM} < $file);
my @Gml = qx(/usr/bin/xml2 < $file);

###### Receiver
my @Rec = gmlarray2nodearray(\@Gml,"rec",-1);
%hashrec = rec_nodearray2hash(\@Rec);

###### Antenna
my @Ant = gmlarray2nodearray(\@Gml,"ant",-1);
%hashant = ant_nodearray2hash(\@Ant);

####### Misc Info
## common root path
my $rootdomes = '/geo:GeodesyML/geo:siteLog/geo:siteIdentification/geo:iersDOMESNumber';
$hashmisc{'domes'} = findvalue("$rootdomes",\@Gml);

## backslash because we need to output a reference
# https://www.oreilly.com/library/view/perl-cookbook/1565922433/ch10s10.html
return (\%hashrec, \%hashant, \%hashmisc);
}

sub gml2mmdfeature {
#
# Wrapper function
#
# Convert a XML/GeodesyML file
# to
# a WebObs markdown feature text for the CURRENT instrumentation
#
my $gmlfile = $_[0];
my $featsection = $_[1];


if ( not -f $gmlfile)
{
die "$gmlfile not found"
}

## dollar sign ($) because we need to get references
# https://www.oreilly.com/library/view/perl-cookbook/1565922433/ch10s10.html
my ($hashrec, $hashant, $hashmisc) = gmlread_feature($gmlfile);

my @outlines ;

# here we need $hashrec->{'blabla'} and not simply $hashrec{'blabla'}
# because $hashrec is a reference of a hash
# abd not a hash it self
if ( $featsection eq "gnssrec" ) {
push(@outlines,"//Model//: $hashrec->{'model'} \n");
push(@outlines,"Satellite system: $hashrec->{'satsys'}\n");
push(@outlines,"Serial number: $hashrec->{'sn'}\n");
push(@outlines,"Firmware version: $hashrec->{'vfirm'} \n");
push(@outlines,"Date installed: $hashrec->{'dinsta'}\n");
push(@outlines,"Date removed: $hashrec->{'dremov'}\n");
} elsif ( $featsection eq "gnssant" ) {
push(@outlines,"Model: $hashant->{'model'} \n");
push(@outlines,"Radome: $hashant->{'radome'} \n");
push(@outlines,"Serial number: $hashant->{'sn'}\n");
push(@outlines,"Alignment from North: $hashant->{'alignN'} \n");
push(@outlines,"Cable length (m): $hashant->{'lcable'} \n");
push(@outlines,"Date installed: $hashant->{'dinsta'}\n");
push(@outlines,"Date removed: $hashant->{'dremov'}\n");
}

return @outlines;
#### !!!! EXCEPTION HERE IF FILE NOT FOUND GMLFILE!!!!
#### !!!! EXCEPTION HERE IF $featsection NOT FOUND !!!!

}

sub gml2mmdtable {
#
# Wrapper function
#
# Convert a XML/GeodesyML file
# to
# a WebObs markdown table for the COMPLETE history
#
my $gmlfile = $_[0];
my $featsection = $_[1];

if ( not -f $gmlfile)
{
die "$gmlfile not found"
}

my @outlines;
### add the "meta" line, thus the text is considered as MarkDown
push(@outlines,"WebObs: converted with wiki2MMD\n\n");

#### HARDCODED XML2
# my @Gml = qx($WEBOBS{XML2_PRGM} < $file);
my @Gml = qx(/usr/bin/xml2 < $gmlfile);

###### Receiver
if ( $featsection eq "gnssrec" ) {
push(@outlines,"| Date installed | Date removed | Model | Satellite system | Serial number | Firmware version |\n");
push(@outlines,"| ---------------------------------------------------------------------------------------------------------------------|\n");
#my @RecList = [ gmlarray2nodearray(\@Gml,"rec",-1) ];
my @RecList = gmlarray2nodearray(\@Gml,"rec","all");
my $Rec;
foreach $Rec ( @RecList ){
my %hashrec;
%hashrec = rec_nodearray2hash($Rec);
my $line = sprintf("|%22s|%22s|%18s|%18s|%15s|%18s|",$hashrec{'dinsta'},$hashrec{'dremov'},$hashrec{'model'},$hashrec{'satsys'},$hashrec{'sn'},$hashrec{'vfirm'});
push(@outlines,$line);
}
} elsif ( $featsection eq "gnssant" ) {

push(@outlines,"| Date installed | Date removed | Model | Radome | Serial number | N. Align. (°) | Cable len. (m) |\n");
push(@outlines,"| -------------------------------------------------------------------------------------------------------------------------|\n");
#my @AntList = [ gmlarray2nodearray(\@Gml,"ant",-1) ];
my @AntList = gmlarray2nodearray(\@Gml,"ant","all");
my $Ant;
foreach $Ant ( @AntList ){
my %hashant;
%hashant = ant_nodearray2hash($Ant);
my $line = sprintf("|%22s|%22s|%18s|%8s|%15s|%16s|%16s|",$hashant{'dinsta'},$hashant{'dremov'},$hashant{'model'},$hashant{'radome'},$hashant{'sn'},$hashant{'alignN'},$hashant{'lcable'});
push(@outlines,$line);
}
}

return @outlines;
}

sub gml2date {

}

1;
51 changes: 50 additions & 1 deletion CODE/cgi-bin/WebObs/XML2.pm
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ package WebObs::XML2;
#--------------------------------------------------------------
use strict;


our(@ISA, @EXPORT, $VERSION);
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(findvalue findvalues findnode);
@EXPORT = qw(findvalue findvalues findnode findnodes);
$VERSION = "1.00";

#--------------------------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -70,4 +71,52 @@ sub findnode {
}
}


#--------------------------------------------------------------------------------------------------------------------------------------
# findnodes: search for a particular array of tags and returns the wished one
# Slightly different from findnode designed for QML
# This one is designed for GeodesyML, but is should be polyvalent
# P Sakic - 2022-12-07
# Usage exemple:
# my @Rec = findnodes($root_rec,"/\@gml:id=","gnss-receiver-6011908e8ef7b",\@xml2);


sub findnodes {
my ($root,$att_name,$att_val,$xml2) = @_;

# substitute the question marks/dots with escaped equivalent signs (?)
$att_name =~ s/\?/\\\?/g;
$att_name =~ s/\./\\\./g;
$att_val =~ s/\?/\\\?/g;
$att_val =~ s/\./\\\./g;

# we grep everything starting with the root
my @tab = grep(/^$root/,@$xml2);
if (@tab) {
#for each line of the table of in the grepped elements:
# clean the root prefix
# clean the \n
# add a double bar || before each block ID (att_name)
# this is the trick to separate each block
foreach (@tab) {
s/^$root//g;
s/\n//g;
s/$att_name/\|\|$att_name/g;
}

# create big strings: each field is separated with |,
# and each block separated with ||
# we split wrt ||, and grep the right block ID (att_val)
@tab = grep(/$att_val/,split(/\|\|/,join('|',@tab)));
#print @tab;
# debug print above, make sure we have the correct block

# we recreate a correct array, one field per element
return split(/\|/,$tab[0]); #NB after the previous grep, @tab is a singleton (normally...)
} else {
return;
}
}


1;
Loading

0 comments on commit 9255bb9

Please sign in to comment.