From 227c0089b8413853fad5f602f5350026fb71fa8f Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (home)" <j.wuttke@fz-juelich.de>
Date: Sat, 4 Feb 2012 19:05:47 +0100
Subject: [PATCH] - import old conversions from code/ - 64bit corrections

---
 pub/share/old-conversions/a01-to-i96 | 26 +++++++++++
 pub/share/old-conversions/i96-to-a01 | 48 ++++++++++++++++++++
 pub/share/old-conversions/ida2rda.rb | 66 ++++++++++++++++++++++++++++
 pub/src/axis.cpp                     | 43 ++++++++----------
 pub/src/axis.h                       |  2 +-
 pub/src/dualplot.cpp                 | 40 ++++++++++-------
 pub/src/dualplot.h                   |  4 +-
 7 files changed, 186 insertions(+), 43 deletions(-)
 create mode 100755 pub/share/old-conversions/a01-to-i96
 create mode 100755 pub/share/old-conversions/i96-to-a01
 create mode 100755 pub/share/old-conversions/ida2rda.rb

diff --git a/pub/share/old-conversions/a01-to-i96 b/pub/share/old-conversions/a01-to-i96
new file mode 100755
index 00000000..da755328
--- /dev/null
+++ b/pub/share/old-conversions/a01-to-i96
@@ -0,0 +1,26 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+
+# does NOT directly convert a01 to i96;
+# rather produces an auxiliary .xy file that can be fed into ida>fm
+
+while (<>) {
+    last if (m/^scn/);
+}
+
+SPECTRA: while (1) {
+
+   $_ = <>;  # Z
+   $_ = <>; m/(\S+)/; print "$1\n";
+   $_ = <>;  #XY
+   while (<>) {
+      if (m/scn/) { print "\n"; next SPECTRA; }
+      if (m/eof/) { last; }
+      m/(\S+)\s+(\S+)/ or die ("invalid data line");
+      printf "$1 $2\n";
+   }
+
+   print "\n\n";
+   last;
+}
diff --git a/pub/share/old-conversions/i96-to-a01 b/pub/share/old-conversions/i96-to-a01
new file mode 100755
index 00000000..55742a05
--- /dev/null
+++ b/pub/share/old-conversions/i96-to-a01
@@ -0,0 +1,48 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+
+# does NOT directly convert i96 to a01;
+# rather produces an auxiliary .xy file that can be fed into rda>fm
+
+while (<>) {
+   if (m/^fil\s+(.*)/) { print "$1\n"; last }
+}
+
+while (<>) { last if (m/^\&eob 4/); }
+
+my ($lab, $var, $uni);
+my $hasz = 0;
+while (<>) {
+   if (m/^([xyz])([\s\d]{3})(.{0,24})(.{0,24})/) {
+	$lab = $1; $var = $3; $uni = $4;
+        $var =~ s/(\s*)$//;
+        $uni =~ s/(\s*)$//;
+        print "$var ($uni)\n";
+	if ($lab eq "z") { $hasz=1; last; }
+   } elsif (m/^\&/) {
+	print "\\\n";
+	last;
+   }
+}
+
+print "3\n1\n";
+
+while (<>) { last if (m/^\&spectrum/); }
+
+SPECTRA: while (1) {
+
+   $_ = <>; 
+   if ($hasz) { 
+      m/(\S+)\s+(\S+)/ or die ("invalid header line");
+      print "$2\n";
+   }
+   while (<>) {
+      if (m/\&spectrum/) { print "\\\n"; next SPECTRA; }
+      m/(\S+)\s+(\S+)/ or die ("invalid data line");
+      printf "$1 $2\n";
+   }
+
+   print "\\\n\\\n";
+   last;
+}
\ No newline at end of file
diff --git a/pub/share/old-conversions/ida2rda.rb b/pub/share/old-conversions/ida2rda.rb
new file mode 100755
index 00000000..31eb75ca
--- /dev/null
+++ b/pub/share/old-conversions/ida2rda.rb
@@ -0,0 +1,66 @@
+#!/usr/bin/ruby
+
+require 'rlib2'
+
+opth = scanarg( "", 1, 1 )
+
+infile = ARGV[0]
+unless infile =~ /(.*)\.i96$/
+    exxx( "input file must have extension .i96" )
+end
+outfile = $1 + ".a01"
+
+fin = File.new( infile )
+
+begin
+    fout = File.new( outfile, "r" )
+rescue
+else
+    exxx( "outfile already exists" )
+end
+fout = File.new( outfile, "w" )
+
+## block 1: data format
+
+unless fin.readline =~ /^ASCII-96/ then exxx( "line 1 invalid" ) end
+
+D = Hash.new
+
+## block 2: text
+
+fin.readline
+
+lin=fin.readline
+unless lin=~/^fil/ then exxx( "missing entry 1:fil" ) end
+D["fil"] = lin[24..-1]
+
+lin=fin.readline
+unless lin=~/^tit/ then exxx( "missing entry 1:tit" ) end
+D["tit"] = lin[24..-1]
+
+# provisorisch: nur EINE doc-Linie
+lin=fin.readline
+unless lin=~/^doc/ then exxx( "missing entry 1:doc" ) end
+D["doc"] = lin[24..-1]
+
+lin=fin.readline
+unless lin=~/^dir/ then exxx( "missing entry 1:dir" ) end
+D["dir"] = lin[24..-1]
+
+lin=fin.readline
+unless lin=~/^&eob 2/ then exxx( "missing eob 2" ) end
+
+## block 3: int pars
+
+lin=fin.readline
+lin=fin.readline
+unless lin=~/^&eob 3/ then exxx( "missing eob 3" ) end
+
+## block 4: r pars ## provisorisch: igoniere r-pars
+lin=fin.readline
+while true
+    lin=fin.readline
+    next if lin=~/^&eob 4/
+end
+
+## block 5:
diff --git a/pub/src/axis.cpp b/pub/src/axis.cpp
index d3e06b72..e1bb9b3d 100644
--- a/pub/src/axis.cpp
+++ b/pub/src/axis.cpp
@@ -84,7 +84,6 @@ void CAxis::ask_and_set( const string& quest )
                  << str() << "]\n";
             continue;
         }
-        // cout << "DEBUG: inf_in = " << inf_in << "\n";
         if ( logflag && inf_in<=0 ) {
             cout << "log axis requires lower bound>0\n";
             continue;
@@ -235,14 +234,14 @@ double CAxis::value2plotcoord( double v ) const
 double CAxis::value2ploterror( double v, double dv ) const
 {
     if ( !finite() )
-        throw string( "undefined plot range" );
+        throw "undefined plot range";
     if ( dv<0 )
         throw "negative error";
     if ( dv==0 )
         return 0;
     if ( logflag ) {
         if( inf<0 || v<0 )
-            throw string( "negative value in log range" );
+            throw "negative value in log range";
         return dv / v / log(sup/inf);
     } else {
         return dv / (sup-inf);
@@ -315,15 +314,16 @@ double CAxis::pcerr( double v, double dv ) const
 
 //! Calculate appropriate division of plot axis.
 
-void CAxis::calc_ticks( int *ntack, double **tack, int *ntpt, double *ticklim)
+void CAxis::calc_ticks( vector<double>& Tacks, int *ntpt, double *ticklim)
     const
 {
-    int ir, nt, i;
+    int ir, nt, i, ntack;
     double r, rd, rdr, d, vsub, vsup, tack0, tackn, dtack;
 	
     if ( inf >= sup )
-        throw "PROGRAM ERROR/ Ticks/ Bad Limits: " +
-            strg(inf) + ", " + strg(sup);
+        throw "BUG detected by calc_ticks: inf=" + strg(inf) +
+            " >= sup=" + strg(sup);
+    Tacks.clear();
 
     if (!logflag) {
         r = log10(sup - inf);
@@ -356,16 +356,15 @@ void CAxis::calc_ticks( int *ntack, double **tack, int *ntpt, double *ticklim)
         vsub = inf - (sup-inf)*1.e-4;
         vsup = sup + (sup-inf)*1.e-4;
         nt = (int) ((tackn-tack0) / dtack) + 3; // allocate enough
-        *tack = (double*) malloc(sizeof(double)*nt);
-        *ntack = 0;
         for (i=0; i<nt; i++) {
             d = tack0 + i*dtack;
             if (vsub<=d && d<=vsup)
-                (*tack)[(*ntack)++] = d;
+                Tacks.push_back( d );
         }
 
+        ntack = Tacks.size();
         ticklim[0] = tack0;
-        ticklim[1] = (*tack)[(*ntack)-1] + dtack;
+        ticklim[1] = Tacks[ntack-1] + dtack;
 		
     } else { // log scale
 
@@ -374,13 +373,13 @@ void CAxis::calc_ticks( int *ntack, double **tack, int *ntpt, double *ticklim)
         int    minexp, maxexp, incr;
 
         if (inf <= 0)
-            throw string( "PROGRAM ERROR/ Ticks/ negative log argument" );
+            throw "PROGRAM ERROR/ Ticks/ negative log argument";
 
         rlgmin = log10(inf);
         rlgmax = log10(sup);
         rlgrel = rlgmax - rlgmin;
         if (rlgrel > 40)
-            throw string( "Excessive log range" );
+            throw "Excessive log range";
 
         minexp = (rlgmin>0 ? 
                   (int) (rlgmin+1e-6) :
@@ -399,24 +398,18 @@ void CAxis::calc_ticks( int *ntack, double **tack, int *ntpt, double *ticklim)
         }
 
         /*  - Set large ticks array : */
-        static int mt=30;
-        *tack = (double*) malloc(sizeof(double)*mt);
-
-        *ntack = 0;
         d1 = inf / eins;
         d2 = sup * eins;
         for ( i = minexp; incr < 0 ? i >= maxexp : i <= maxexp; i += incr ) {
             r0 = pow(10., i);
-            if (d1<=r0 && r0<=d2) {
-                if(*ntack>=mt)
-                    throw string( "PROG ERR too many tacks" );
-                (*tack)[(*ntack)++] = r0;
-            }
+            if (d1<=r0 && r0<=d2)
+                Tacks.push_back( r0 );
         }
 
-        if (*ntack >= 1) {
-            ticklim[0] = (*tack)[0]          / pow(10., incr);
-            ticklim[1] = (*tack)[(*ntack)-1] * pow(10., incr);
+        ntack = Tacks.size();
+        if ( ntack >= 1 ) {
+            ticklim[0] = Tacks[0]       / pow(10., incr);
+            ticklim[1] = Tacks[ntack-1] * pow(10., incr);
         } else {
             // untested. just to allow plots when no tacks in window
             ticklim[0] = pow( 10., minexp );
diff --git a/pub/src/axis.h b/pub/src/axis.h
index 87f33f4f..9e5654ab 100644
--- a/pub/src/axis.h
+++ b/pub/src/axis.h
@@ -25,6 +25,6 @@ class CAxis {
     double pc( double v ) const;
     double pcerr( double v, double dv ) const;
     double inf_pos() const;
-    void calc_ticks( int *ntack, double **tack, int *ntpt, double *ticklim )
+    void calc_ticks( vector<double>& Tacks, int *ntpt, double *ticklim )
         const;
 };
diff --git a/pub/src/dualplot.cpp b/pub/src/dualplot.cpp
index 1956628f..ff939d3f 100644
--- a/pub/src/dualplot.cpp
+++ b/pub/src/dualplot.cpp
@@ -122,6 +122,7 @@ void CPlot::setAux( string cmd )
 
 void CPlot::plotFrame( string xlabel, string ylabel )
 {
+    cout << "DEB00\n";
     gp_write( "set nologscale" );
     string whichlog="";
     if (X.logflag) whichlog += "x";
@@ -140,15 +141,18 @@ void CPlot::plotFrame( string xlabel, string ylabel )
               0, 0., 0., 0 );
     ps_accu.push_back( outlin );
 
-    int ntack, ntpt;
-    double *tack, ticklim[2];
+    int ntpt;
+    double ticklim[2];
+    vector<double> Tacks;
 
     ps_accu.push_back( "\n/xPlotFrame {\n" );
     if ( X.logflag && X.inf<= 0 )
         throw "BUG: x log incompatible with limits " + X.str();
-    X.calc_ticks( &ntack, &tack, &ntpt, ticklim );
-    ps_ticktack(ntack, tack, ntpt, ticklim, &X);
-    free(tack);
+    cout << "DEB11\n";
+    X.calc_ticks( Tacks, &ntpt, ticklim );
+    cout << "DEB12\n";
+    ps_ticktack( Tacks, ntpt, ticklim, &X);
+    cout << "DEB13\n";
     snprintf( outlin, mLin-4, "  {(%s", xlabel.c_str() );
     strncat( outlin, ")}\n", mLin );
     ps_accu.push_back( outlin );
@@ -159,15 +163,19 @@ void CPlot::plotFrame( string xlabel, string ylabel )
     ps_accu.push_back( "  xCL\n" );
     ps_accu.push_back( "} def\n" );
     
+    cout << "DEB20\n";
     ps_accu.push_back( "\n/yPlotFrame {\n" );
     if ( Y.logflag && Y.inf<= 0 )
         throw "BUG: y log incompatible with limits " + Y.str();
-    Y.calc_ticks( &ntack, &tack, &ntpt, ticklim );
-    ps_ticktack(ntack, tack, ntpt, ticklim, &Y);
-    free(tack);
+    cout << "DEB21\n";
+    Y.calc_ticks( Tacks, &ntpt, ticklim );
+    cout << "DEB22\n";
+    ps_ticktack( Tacks, ntpt, ticklim, &Y);
+    cout << "DEB23\n";
     snprintf( outlin, mLin, "   {(%s", ylabel.c_str() );
     strncat( outlin, ")}\n", mLin );
     ps_accu.push_back( outlin );
+    cout << "DEB30\n";
     ps_accu.push_back( "   0 10   0  0    90   0 "
                        "OneAxx Axx Tic Tac yNumL %% left y axis\n" );
     ps_accu.push_back( "   0 10  10  0    90 180 "
@@ -175,6 +183,7 @@ void CPlot::plotFrame( string xlabel, string ylabel )
     ps_accu.push_back( "  yCL\n" );
     ps_accu.push_back( "} def\n" );
     ps_accu.push_back( "\n%% modeDD\nplotbefore\n" );
+    cout << "DEB99\n";
 }
 
 
@@ -351,23 +360,24 @@ void CPlot::gp_write( string in )
 
 //! Format ticks and tacks for postscript file.
 
-void CPlot::ps_ticktack(
-    uint ntack, double *tack, int ntpt, double *ticklim, CAxis *A )
+void CPlot::ps_ticktack( const vector<double>& Tacks, int ntpt,
+                         const double *ticklim, const CAxis *A )
 {
-    uint i;
+    uint i, ntack;
+    ntack = Tacks.size();
     ps_accu.push_back( "  [\n" );
-    if (A->logflag && ( tack[0]<1e-3 || tack[ntack-1]>1e3 )) {
+    if (A->logflag && ( Tacks[0]<1e-3 || Tacks[ntack-1]>1e3 )) {
         for (i=0; i<ntack; i++) {
             snprintf( outlin, mLin,
                       "   %9.6f {(10)(%d)sp()} %%{(%g)}\n", 
-                      A->pc(tack[i]), (int)(log10(tack[i])),
-                      (float) tack[i]);
+                      A->pc(Tacks[i]), (int)(log10(Tacks[i])),
+                      (float) Tacks[i]);
             ps_accu.push_back( outlin );
         }
     } else {
         for (i=0; i<ntack; i++) {
             snprintf( outlin, mLin, "   %9.6f {(%g)}\n", 
-                      A->pc(tack[i]), (float) tack[i]);
+                      A->pc(Tacks[i]), (float) Tacks[i]);
             ps_accu.push_back( outlin );
         }
     }
diff --git a/pub/src/dualplot.h b/pub/src/dualplot.h
index 5a11163c..c15a06d1 100644
--- a/pub/src/dualplot.h
+++ b/pub/src/dualplot.h
@@ -37,8 +37,8 @@ private:
     uint ps_snum; // spectrum
     uint ps_pnum; // spectrum with pstyle
     uint ps_cnum; // spectrum with cstyle
-    void ps_ticktack( uint ntack, double *tack, int ntpt, double *ticklim,
-                      CAxis *A );
+    void ps_ticktack( const vector<double>& Tacks, int ntpt,
+                      const double *ticklim, const CAxis *A );
     vector<string> ps_Doc;
     vector<string> ps_accu; // future output is accumulated here
     char outlin[ mLin ];
-- 
GitLab