V6.4
authorA.M. Thurnherr <athurnherr@yahoo.com>
Thu, 17 Mar 2016 07:48:45 -0400
changeset 26 cfee523c4432
parent 25 47b4a3600f5a
child 27 abeaad5308ba
V6.4
HISTORY
ants.pl
libGMT.pl
libGMT4.pl
--- a/HISTORY
+++ b/HISTORY
@@ -1,9 +1,9 @@
 #======================================================================
 #                    H I S T O R Y 
 #                    doc: Thu May  7 13:12:05 2015
-#                    dlm: Tue Mar  8 15:53:24 2016
+#                    dlm: Thu Mar 17 07:48:16 2016
 #                    (c) 2015 A.M. Thurnherr
-#                    uE-Info: 43 23 NIL 0 0 70 0 2 4 NIL ofnI
+#                    uE-Info: 51 37 NIL 0 0 72 0 2 4 NIL ofnI
 #======================================================================
 
 May  7, 2015:
@@ -43,3 +43,11 @@
 	- updated [HISTORY]
 	- V6.3 [ants.pl] [.hg/hgrc] 
 
+Mar 16, 2016:
+	- V6.4 [ants.pl] [.hg/hgrc] 
+	- adapted [libGMT.pl] to gmt5 => [libGMT4.pl]
+
+Mar 17, 2016:
+	- published for LADCP_w V1.2beta5
+	
+
--- a/ants.pl
+++ b/ants.pl
@@ -2,9 +2,9 @@
 #======================================================================
 #                    A N T S . P L 
 #                    doc: Fri Jun 19 14:01:06 1998
-#                    dlm: Tue Mar  8 15:53:49 2016
+#                    dlm: Wed Mar 16 14:08:12 2016
 #                    (c) 1998 A.M. Thurnherr
-#                    uE-Info: 19 51 NIL 0 0 72 2 2 4 NIL ofnI
+#                    uE-Info: 20 56 NIL 0 0 72 2 2 4 NIL ofnI
 #======================================================================
 
 # HISTORY:
@@ -16,12 +16,14 @@
 #  Oct 29, 2014: - added $antsLibVersion with compile-time version check (V6.0)
 #  May 17, 2015: - updated to V6.1
 #  Oct 12, 2015: - updated to V6.2 (for LADCP_w 1.0)
-#  Mar  8, 2016: - updated to V6.3 (for LADCP_w 1.2)
+#  Mar  8, 2016: - updated to V6.3 (for LADCP_w 1.2beta)
+#  Mar 16, 2016: - updated to V6.4 (for LADCP_w 1.2beta5)
 
 exec($ENV{ANTS_PERL},$0,@ARGV),die("$ENV{ANTS_PERL}: $!")
     if (defined($ENV{ANTS_PERL}) && $^X ne $ENV{ANTS_PERL});
 
-$antsLibVersion = 6.3;
+$antsLibVersion = 6.4;
+
 die(sprintf("$0: obsolete library V%.1f; V%.1f required\n",
 	$antsLibVersion,$antsMinLibVersion))
 		if (!defined($antsMinLibVersion) || $antsMinLibVersion>$antsLibVersion);
--- a/libGMT.pl
+++ b/libGMT.pl
@@ -1,9 +1,9 @@
 #======================================================================
 #                    L I B G M T . P L 
 #                    doc: Sun Jun 14 13:45:47 2015
-#                    dlm: Sun Sep 27 09:23:46 2015
+#                    dlm: Wed Mar 16 16:12:38 2016
 #                    (c) 2015 A.M. Thurnherr
-#                    uE-Info: 45 10 NIL 0 0 72 2 2 4 NIL ofnI
+#                    uE-Info: 188 49 NIL 0 0 72 2 2 4 NIL ofnI
 #======================================================================
 
 # perl implementation of /Data/Makefiles/Makefile.GMT
@@ -41,6 +41,7 @@
 #	Jul 26, 2015: - added usage documentation
 #				  - simplified GMT_unitcoords()
 #	Jul 28, 2015: - added GMT_setAnnotFontSize(), GMT_psscale()
+#	Mar 16, 2016: - began adaptation to GMT5
 
 $DEBUG = 0;
 
@@ -69,7 +70,7 @@
 
 sub GMT_set(@)											# set GMT defaults
 {
-	GMT_spawn("| gmtset @_");
+	GMT_spawn("| gmt set @_");
 }
 
 #----------------------------------------------------------------------
@@ -90,21 +91,20 @@
 	chdir("/tmp/antsGMT.$$") ||
 		croak("/tmp/antsGMT.$$: $!\n");
 	system("rm -f .gmt*
-			gmtset MEASURE_UNIT cm PAPER_MEDIA letter \\
-			       LABEL_FONT_SIZE ${LABEL_FONT_SIZE} \\
-	               ANNOT_FONT_SIZE_PRIMARY ${ANNOT_FONT_SIZE} \\
-	               WANT_EURO_FONT true \\
-	               PLOT_DEGREE_FORMAT ddd:mm:ssF") &&
-		croak("gmtset failed\n");
+			gmt set PROJ_LENGTH_UNIT cm PS_MEDIA letter \\
+			        FONT_LABEL ${LABEL_FONT_SIZE} \\
+	                FONT_ANNOT_PRIMARY ${ANNOT_FONT_SIZE} \\
+	                FORMAT_GEO_MAP ddd:mm:ssF") &&
+		croak("gmt set failed\n");
 	$GMT_plotfile = "$ENV{PWD}/$pfn";
 	GMT_setJ($J); GMT_setR($R);
-	GMT_spawn("| psxy -K $J $R $extra > $GMT_plotfile");
+	GMT_spawn("| gmt psxy -K $J $R $extra > $GMT_plotfile");
 	close(GMT);
 }
 
 sub GMT_setAnnotFontSize($)
 {
-	GMT_set("ANNOT_FONT_SIZE_PRIMARY $_[0]");
+	GMT_set("FONT_ANNOT_PRIMARY $_[0]");
 }
 
 #----------------------------------------------------------------------
@@ -118,9 +118,11 @@
 sub GMT_end(@)
 {
 	my($opt) = @_;
-	$opt = '-G' unless defined($opt);
-	
-	GMT_spawn("| psbasemap -O $GMT_J $GMT_R $opt >> $GMT_plotfile");
+	if (defined($opt)) {
+		GMT_spawn("| gmt psbasemap -O $GMT_J $GMT_R $opt >> $GMT_plotfile");
+	} else {
+		GMT_spawn("| gmt psxy -O $GMT_J $GMT_R -Sc0.1 >> $GMT_plotfile");
+	}
 	close(GMT);
 	chdir("$ENV{PWD}") || croak("ENV{PWD}: $!\n");
 	system("rm -rf /tmp/antsGMT.$$") &&
@@ -151,7 +153,7 @@
 		}
 	}
 	GMT_setR('-R0/1/0/1');
-#	GMT_spawn("| psxy -O -K $GMT_J $GMT_R >> $GMT_plotfile");
+#	GMT_spawn("| gmt psxy -O -K $GMT_J $GMT_R >> $GMT_plotfile");
 #	close(GMT);
 }
 
@@ -165,25 +167,25 @@
 sub GMT_psxy(@)
 {
 	my($opts) = @_;
-	GMT_spawn("| psxy -O -K $GMT_J $GMT_R $opts >> $GMT_plotfile");
+	GMT_spawn("| gmt psxy -O -K $GMT_J $GMT_R $opts >> $GMT_plotfile");
 }
 
 sub GMT_psbasemap(@)
 {
 	my($opts) = @_;
-	GMT_spawn("| psbasemap -O -K $GMT_J $GMT_R $opts >> $GMT_plotfile");
+	GMT_spawn("| gmt psbasemap -O -K $GMT_J $GMT_R $opts >> $GMT_plotfile");
 }
 
 sub GMT_pstext(@)
 {
 	my($opts) = @_;
-	GMT_spawn("| pstext -O -K $GMT_J $GMT_R $opts >> $GMT_plotfile");
+	GMT_spawn("| gmt pstext -O -K $GMT_J $GMT_R $opts >> $GMT_plotfile");
 }
 
 sub GMT_psscale(@)
 {
 	my($opts) = @_;
-	GMT_spawn("| psscale -O -K $opts >> $GMT_plotfile");
+	GMT_spawn("| gmt psscale -O -K $GMT_J $GMT_R $opts >> $GMT_plotfile");
 }
 
 1;
new file mode 100644
--- /dev/null
+++ b/libGMT4.pl
@@ -0,0 +1,189 @@
+#======================================================================
+#                    L I B G M T . P L 
+#                    doc: Sun Jun 14 13:45:47 2015
+#                    dlm: Sun Sep 27 09:23:46 2015
+#                    (c) 2015 A.M. Thurnherr
+#                    uE-Info: 45 10 NIL 0 0 72 2 2 4 NIL ofnI
+#======================================================================
+
+# perl implementation of /Data/Makefiles/Makefile.GMT
+
+#----------------------------------------------------------------------
+# USAGE
+#----------------------------------------------------------------------
+#
+# Basic Example
+# -------------
+# GMT_begin('temp_prof.ps','-JX10/-10','-R0/30/0/5000');
+# GMT_psxy('-W1,red');
+# print(GMT "$temp $depth\n");
+# GMT_end('-Ba5f1:"Temperature [degC]":/a500f100:"Depth [m]":WeSn');
+#
+# Other GMT Utilities
+# -------------------
+# GMT_pstext(<opts>)			x y size angle fontno justify(ML,BC,TR,...) "text"
+# GMT_psbasemap(<opts>)			often implies GMT_end() w/o args
+# GMT_psscale(<opts>)			scale bar
+#
+# Other Extensions
+# ----------------
+# GMT_unitcoords();				afterwards, x and y range from 0 to 1; useful for legends
+# GMT_setR('-R0/1/0/1')			subsequent GMT utilities use this ROI
+# GMT_setJ('-JX10/-1-')			subsequent GMT utilities use this projection
+# GMT_setAnnotFontSize(7)		set primary annotation font size
+#
+#----------------------------------------------------------------------
+
+# HISTORY:
+#	Jun 14, 2015: - created
+#	Jun 16, 2015: - BUG: forgot to return to PWD
+#	Jun 18, 2015: - added $DEBUG
+#	Jul 26, 2015: - added usage documentation
+#				  - simplified GMT_unitcoords()
+#	Jul 28, 2015: - added GMT_setAnnotFontSize(), GMT_psscale()
+
+$DEBUG = 0;
+
+#----------------------------------------------------------------------
+# Library
+#----------------------------------------------------------------------
+
+my($GMT_plotfile);
+my($GMT_J);
+my($GMT_R);
+
+sub GMT_setR($) { ($GMT_R) = @_; }						# (re-)define -R
+sub GMT_setJ($) { ($GMT_J) = @_; }						# (re-)define -J
+
+sub GMT_spawn($)										# spawn GMT command in temp dir
+{
+	my($cmd) = @_;
+	close(GMT);
+	chdir("/tmp/antsGMT.$$") ||
+		croak("/tmp/antsGMT.$$: $!\n");
+	print(STDERR "$cmd\n") if ($DEBUG);
+	open(GMT,$cmd) || croak("$cmd: $!\n");
+	chdir("$ENV{PWD}") ||
+		croak("$ENV{PWD}: $!\n");
+}
+
+sub GMT_set(@)											# set GMT defaults
+{
+	GMT_spawn("| gmtset @_");
+}
+
+#----------------------------------------------------------------------
+# GMT_begin(plot_file,J,R,extra_opts),
+#	e.g. GMT_begin('temp_prof.ps','-JX10/-10','-R0/30/0/5000');
+#		1) create temp directory
+#		2) set GMT defaults
+#		3) create plot file with empty psxy
+#----------------------------------------------------------------------
+
+my($LABEL_FONT_SIZE) = 14 unless defined($LABEL_FONT_SIZE);
+my($ANNOT_FONT_SIZE) = 14 unless defined($ANNOT_FONT_SIZE);
+
+sub GMT_begin(@)
+{
+	my($pfn,$J,$R,$extra) = @_;
+	mkdir("/tmp/antsGMT.$$");
+	chdir("/tmp/antsGMT.$$") ||
+		croak("/tmp/antsGMT.$$: $!\n");
+	system("rm -f .gmt*
+			gmtset MEASURE_UNIT cm PAPER_MEDIA letter \\
+			       LABEL_FONT_SIZE ${LABEL_FONT_SIZE} \\
+	               ANNOT_FONT_SIZE_PRIMARY ${ANNOT_FONT_SIZE} \\
+	               WANT_EURO_FONT true \\
+	               PLOT_DEGREE_FORMAT ddd:mm:ssF") &&
+		croak("gmtset failed\n");
+	$GMT_plotfile = "$ENV{PWD}/$pfn";
+	GMT_setJ($J); GMT_setR($R);
+	GMT_spawn("| psxy -K $J $R $extra > $GMT_plotfile");
+	close(GMT);
+}
+
+sub GMT_setAnnotFontSize($)
+{
+	GMT_set("ANNOT_FONT_SIZE_PRIMARY $_[0]");
+}
+
+#----------------------------------------------------------------------
+# GMT_end(B)
+#	1) chdir to temp-dir
+#	2) psbasemap w/o -K
+#	3) close GMT file
+#	4) remove GMT temp dir
+#----------------------------------------------------------------------
+
+sub GMT_end(@)
+{
+	my($opt) = @_;
+	$opt = '-G' unless defined($opt);
+	
+	GMT_spawn("| psbasemap -O $GMT_J $GMT_R $opt >> $GMT_plotfile");
+	close(GMT);
+	chdir("$ENV{PWD}") || croak("ENV{PWD}: $!\n");
+	system("rm -rf /tmp/antsGMT.$$") &&
+		croak("Offending command: rm -rf /tmp/antsGMT.$$\n");
+}
+
+#----------------------------------------------------------------------
+# GMT_unitcoords()
+#	- set unit coordinate system
+#----------------------------------------------------------------------
+
+sub GMT_unitcoords()
+{
+	GMT_setR('-R0/1/0/1');
+}
+
+sub GMT_unitcoords_logscale()
+{
+	($jx,$jy) = ($GMT_J =~ m{-J.-?(\d+)[a-z]*/-?(\d+)});
+	if (defined($jy)) {
+		GMT_setJ("-JX$jx/$jy");
+	} else {
+		($jx) = ($GMT_J =~ m{-J.-?(\d+)});
+		if (defined($jx)) {
+			GMT_setJ("-JX$jx");
+		} else {
+			croak("cannot decode $GMT_J ($jx,$jy)");
+		}
+	}
+	GMT_setR('-R0/1/0/1');
+#	GMT_spawn("| psxy -O -K $GMT_J $GMT_R >> $GMT_plotfile");
+#	close(GMT);
+}
+
+#----------------------------------------------------------------------
+# GMT_psxy(opts)
+# GMT_psbasemap(opts)
+# GMT_pstext(opts)
+# GMT_psscale(opts)
+#----------------------------------------------------------------------
+
+sub GMT_psxy(@)
+{
+	my($opts) = @_;
+	GMT_spawn("| psxy -O -K $GMT_J $GMT_R $opts >> $GMT_plotfile");
+}
+
+sub GMT_psbasemap(@)
+{
+	my($opts) = @_;
+	GMT_spawn("| psbasemap -O -K $GMT_J $GMT_R $opts >> $GMT_plotfile");
+}
+
+sub GMT_pstext(@)
+{
+	my($opts) = @_;
+	GMT_spawn("| pstext -O -K $GMT_J $GMT_R $opts >> $GMT_plotfile");
+}
+
+sub GMT_psscale(@)
+{
+	my($opts) = @_;
+	GMT_spawn("| psscale -O -K $opts >> $GMT_plotfile");
+}
+
+1;