Skip to content
Snippets Groups Projects
Commit 227c0089 authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

- import old conversions from code/

- 64bit corrections
parent 83b3d961
No related branches found
No related tags found
No related merge requests found
#!/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;
}
#!/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
#!/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:
...@@ -84,7 +84,6 @@ void CAxis::ask_and_set( const string& quest ) ...@@ -84,7 +84,6 @@ void CAxis::ask_and_set( const string& quest )
<< str() << "]\n"; << str() << "]\n";
continue; continue;
} }
// cout << "DEBUG: inf_in = " << inf_in << "\n";
if ( logflag && inf_in<=0 ) { if ( logflag && inf_in<=0 ) {
cout << "log axis requires lower bound>0\n"; cout << "log axis requires lower bound>0\n";
continue; continue;
...@@ -235,14 +234,14 @@ double CAxis::value2plotcoord( double v ) const ...@@ -235,14 +234,14 @@ double CAxis::value2plotcoord( double v ) const
double CAxis::value2ploterror( double v, double dv ) const double CAxis::value2ploterror( double v, double dv ) const
{ {
if ( !finite() ) if ( !finite() )
throw string( "undefined plot range" ); throw "undefined plot range";
if ( dv<0 ) if ( dv<0 )
throw "negative error"; throw "negative error";
if ( dv==0 ) if ( dv==0 )
return 0; return 0;
if ( logflag ) { if ( logflag ) {
if( inf<0 || v<0 ) if( inf<0 || v<0 )
throw string( "negative value in log range" ); throw "negative value in log range";
return dv / v / log(sup/inf); return dv / v / log(sup/inf);
} else { } else {
return dv / (sup-inf); return dv / (sup-inf);
...@@ -315,15 +314,16 @@ double CAxis::pcerr( double v, double dv ) const ...@@ -315,15 +314,16 @@ double CAxis::pcerr( double v, double dv ) const
//! Calculate appropriate division of plot axis. //! 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 const
{ {
int ir, nt, i; int ir, nt, i, ntack;
double r, rd, rdr, d, vsub, vsup, tack0, tackn, dtack; double r, rd, rdr, d, vsub, vsup, tack0, tackn, dtack;
if ( inf >= sup ) if ( inf >= sup )
throw "PROGRAM ERROR/ Ticks/ Bad Limits: " + throw "BUG detected by calc_ticks: inf=" + strg(inf) +
strg(inf) + ", " + strg(sup); " >= sup=" + strg(sup);
Tacks.clear();
if (!logflag) { if (!logflag) {
r = log10(sup - inf); r = log10(sup - inf);
...@@ -356,16 +356,15 @@ void CAxis::calc_ticks( int *ntack, double **tack, int *ntpt, double *ticklim) ...@@ -356,16 +356,15 @@ void CAxis::calc_ticks( int *ntack, double **tack, int *ntpt, double *ticklim)
vsub = inf - (sup-inf)*1.e-4; vsub = inf - (sup-inf)*1.e-4;
vsup = sup + (sup-inf)*1.e-4; vsup = sup + (sup-inf)*1.e-4;
nt = (int) ((tackn-tack0) / dtack) + 3; // allocate enough nt = (int) ((tackn-tack0) / dtack) + 3; // allocate enough
*tack = (double*) malloc(sizeof(double)*nt);
*ntack = 0;
for (i=0; i<nt; i++) { for (i=0; i<nt; i++) {
d = tack0 + i*dtack; d = tack0 + i*dtack;
if (vsub<=d && d<=vsup) if (vsub<=d && d<=vsup)
(*tack)[(*ntack)++] = d; Tacks.push_back( d );
} }
ntack = Tacks.size();
ticklim[0] = tack0; ticklim[0] = tack0;
ticklim[1] = (*tack)[(*ntack)-1] + dtack; ticklim[1] = Tacks[ntack-1] + dtack;
} else { // log scale } else { // log scale
...@@ -374,13 +373,13 @@ void CAxis::calc_ticks( int *ntack, double **tack, int *ntpt, double *ticklim) ...@@ -374,13 +373,13 @@ void CAxis::calc_ticks( int *ntack, double **tack, int *ntpt, double *ticklim)
int minexp, maxexp, incr; int minexp, maxexp, incr;
if (inf <= 0) if (inf <= 0)
throw string( "PROGRAM ERROR/ Ticks/ negative log argument" ); throw "PROGRAM ERROR/ Ticks/ negative log argument";
rlgmin = log10(inf); rlgmin = log10(inf);
rlgmax = log10(sup); rlgmax = log10(sup);
rlgrel = rlgmax - rlgmin; rlgrel = rlgmax - rlgmin;
if (rlgrel > 40) if (rlgrel > 40)
throw string( "Excessive log range" ); throw "Excessive log range";
minexp = (rlgmin>0 ? minexp = (rlgmin>0 ?
(int) (rlgmin+1e-6) : (int) (rlgmin+1e-6) :
...@@ -399,24 +398,18 @@ void CAxis::calc_ticks( int *ntack, double **tack, int *ntpt, double *ticklim) ...@@ -399,24 +398,18 @@ void CAxis::calc_ticks( int *ntack, double **tack, int *ntpt, double *ticklim)
} }
/* - Set large ticks array : */ /* - Set large ticks array : */
static int mt=30;
*tack = (double*) malloc(sizeof(double)*mt);
*ntack = 0;
d1 = inf / eins; d1 = inf / eins;
d2 = sup * eins; d2 = sup * eins;
for ( i = minexp; incr < 0 ? i >= maxexp : i <= maxexp; i += incr ) { for ( i = minexp; incr < 0 ? i >= maxexp : i <= maxexp; i += incr ) {
r0 = pow(10., i); r0 = pow(10., i);
if (d1<=r0 && r0<=d2) { if (d1<=r0 && r0<=d2)
if(*ntack>=mt) Tacks.push_back( r0 );
throw string( "PROG ERR too many tacks" );
(*tack)[(*ntack)++] = r0;
}
} }
if (*ntack >= 1) { ntack = Tacks.size();
ticklim[0] = (*tack)[0] / pow(10., incr); if ( ntack >= 1 ) {
ticklim[1] = (*tack)[(*ntack)-1] * pow(10., incr); ticklim[0] = Tacks[0] / pow(10., incr);
ticklim[1] = Tacks[ntack-1] * pow(10., incr);
} else { } else {
// untested. just to allow plots when no tacks in window // untested. just to allow plots when no tacks in window
ticklim[0] = pow( 10., minexp ); ticklim[0] = pow( 10., minexp );
......
...@@ -25,6 +25,6 @@ class CAxis { ...@@ -25,6 +25,6 @@ class CAxis {
double pc( double v ) const; double pc( double v ) const;
double pcerr( double v, double dv ) const; double pcerr( double v, double dv ) const;
double inf_pos() 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; const;
}; };
...@@ -122,6 +122,7 @@ void CPlot::setAux( string cmd ) ...@@ -122,6 +122,7 @@ void CPlot::setAux( string cmd )
void CPlot::plotFrame( string xlabel, string ylabel ) void CPlot::plotFrame( string xlabel, string ylabel )
{ {
cout << "DEB00\n";
gp_write( "set nologscale" ); gp_write( "set nologscale" );
string whichlog=""; string whichlog="";
if (X.logflag) whichlog += "x"; if (X.logflag) whichlog += "x";
...@@ -140,15 +141,18 @@ void CPlot::plotFrame( string xlabel, string ylabel ) ...@@ -140,15 +141,18 @@ void CPlot::plotFrame( string xlabel, string ylabel )
0, 0., 0., 0 ); 0, 0., 0., 0 );
ps_accu.push_back( outlin ); ps_accu.push_back( outlin );
int ntack, ntpt; int ntpt;
double *tack, ticklim[2]; double ticklim[2];
vector<double> Tacks;
ps_accu.push_back( "\n/xPlotFrame {\n" ); ps_accu.push_back( "\n/xPlotFrame {\n" );
if ( X.logflag && X.inf<= 0 ) if ( X.logflag && X.inf<= 0 )
throw "BUG: x log incompatible with limits " + X.str(); throw "BUG: x log incompatible with limits " + X.str();
X.calc_ticks( &ntack, &tack, &ntpt, ticklim ); cout << "DEB11\n";
ps_ticktack(ntack, tack, ntpt, ticklim, &X); X.calc_ticks( Tacks, &ntpt, ticklim );
free(tack); cout << "DEB12\n";
ps_ticktack( Tacks, ntpt, ticklim, &X);
cout << "DEB13\n";
snprintf( outlin, mLin-4, " {(%s", xlabel.c_str() ); snprintf( outlin, mLin-4, " {(%s", xlabel.c_str() );
strncat( outlin, ")}\n", mLin ); strncat( outlin, ")}\n", mLin );
ps_accu.push_back( outlin ); ps_accu.push_back( outlin );
...@@ -159,15 +163,19 @@ void CPlot::plotFrame( string xlabel, string ylabel ) ...@@ -159,15 +163,19 @@ void CPlot::plotFrame( string xlabel, string ylabel )
ps_accu.push_back( " xCL\n" ); ps_accu.push_back( " xCL\n" );
ps_accu.push_back( "} def\n" ); ps_accu.push_back( "} def\n" );
cout << "DEB20\n";
ps_accu.push_back( "\n/yPlotFrame {\n" ); ps_accu.push_back( "\n/yPlotFrame {\n" );
if ( Y.logflag && Y.inf<= 0 ) if ( Y.logflag && Y.inf<= 0 )
throw "BUG: y log incompatible with limits " + Y.str(); throw "BUG: y log incompatible with limits " + Y.str();
Y.calc_ticks( &ntack, &tack, &ntpt, ticklim ); cout << "DEB21\n";
ps_ticktack(ntack, tack, ntpt, ticklim, &Y); Y.calc_ticks( Tacks, &ntpt, ticklim );
free(tack); cout << "DEB22\n";
ps_ticktack( Tacks, ntpt, ticklim, &Y);
cout << "DEB23\n";
snprintf( outlin, mLin, " {(%s", ylabel.c_str() ); snprintf( outlin, mLin, " {(%s", ylabel.c_str() );
strncat( outlin, ")}\n", mLin ); strncat( outlin, ")}\n", mLin );
ps_accu.push_back( outlin ); ps_accu.push_back( outlin );
cout << "DEB30\n";
ps_accu.push_back( " 0 10 0 0 90 0 " ps_accu.push_back( " 0 10 0 0 90 0 "
"OneAxx Axx Tic Tac yNumL %% left y axis\n" ); "OneAxx Axx Tic Tac yNumL %% left y axis\n" );
ps_accu.push_back( " 0 10 10 0 90 180 " ps_accu.push_back( " 0 10 10 0 90 180 "
...@@ -175,6 +183,7 @@ void CPlot::plotFrame( string xlabel, string ylabel ) ...@@ -175,6 +183,7 @@ void CPlot::plotFrame( string xlabel, string ylabel )
ps_accu.push_back( " yCL\n" ); ps_accu.push_back( " yCL\n" );
ps_accu.push_back( "} def\n" ); ps_accu.push_back( "} def\n" );
ps_accu.push_back( "\n%% modeDD\nplotbefore\n" ); ps_accu.push_back( "\n%% modeDD\nplotbefore\n" );
cout << "DEB99\n";
} }
...@@ -351,23 +360,24 @@ void CPlot::gp_write( string in ) ...@@ -351,23 +360,24 @@ void CPlot::gp_write( string in )
//! Format ticks and tacks for postscript file. //! Format ticks and tacks for postscript file.
void CPlot::ps_ticktack( void CPlot::ps_ticktack( const vector<double>& Tacks, int ntpt,
uint ntack, double *tack, int ntpt, double *ticklim, CAxis *A ) const double *ticklim, const CAxis *A )
{ {
uint i; uint i, ntack;
ntack = Tacks.size();
ps_accu.push_back( " [\n" ); 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++) { for (i=0; i<ntack; i++) {
snprintf( outlin, mLin, snprintf( outlin, mLin,
" %9.6f {(10)(%d)sp()} %%{(%g)}\n", " %9.6f {(10)(%d)sp()} %%{(%g)}\n",
A->pc(tack[i]), (int)(log10(tack[i])), A->pc(Tacks[i]), (int)(log10(Tacks[i])),
(float) tack[i]); (float) Tacks[i]);
ps_accu.push_back( outlin ); ps_accu.push_back( outlin );
} }
} else { } else {
for (i=0; i<ntack; i++) { for (i=0; i<ntack; i++) {
snprintf( outlin, mLin, " %9.6f {(%g)}\n", 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 ); ps_accu.push_back( outlin );
} }
} }
......
...@@ -37,8 +37,8 @@ private: ...@@ -37,8 +37,8 @@ private:
uint ps_snum; // spectrum uint ps_snum; // spectrum
uint ps_pnum; // spectrum with pstyle uint ps_pnum; // spectrum with pstyle
uint ps_cnum; // spectrum with cstyle uint ps_cnum; // spectrum with cstyle
void ps_ticktack( uint ntack, double *tack, int ntpt, double *ticklim, void ps_ticktack( const vector<double>& Tacks, int ntpt,
CAxis *A ); const double *ticklim, const CAxis *A );
vector<string> ps_Doc; vector<string> ps_Doc;
vector<string> ps_accu; // future output is accumulated here vector<string> ps_accu; // future output is accumulated here
char outlin[ mLin ]; char outlin[ mLin ];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment