Conversion notes for Squaw to Unix for E852, 	Nov, 1994, thru Jan, 1996.
							JMBishop
To IBM RS/6000, AIX 3.2.5, xlFortran 2.3
To SGI Indigo, IRIX 5.2, f77
From VAX/VMS (from IBM 370, from ...)

Typos and coding errors are not included in these notes.

Etype and Fudge extracted from Flecs and partially updated to F77 logic.

Squaw divided up into init, exec, and end routines.
Open of print file added to Squawinit.

Gammas and Gamtrk from Apache incorporated as read routines called from Wread.
Coordinate and variable conversions updated for E852 analyzer output.
Ctracks and Chgtrk created from Gammas & Gamtrk for charged tracks.
Makeid created for initializing TVGP block and making event id.

Zhepsub library cleaned up, with some dummies and some missing routines
added.

Hbook calls updated for Hbook4.  On the first attempt, all calls did not
get the now required full list of arguments.

IDblock modified, and formats changed in Head and Sumprt.

Compiled OK on VAX; no link attempted.

Fixes for IBM xlf 2.3:

Some short new routines ended up with trailing nulls when moved via nfs
to the IBM.  These were edited on the IBM and the last line of nulls deleted.
This had to be done each time the file was copied from VAX; a quirk of the
VMS UCX internet package.

VAX continuations (tab,#) converted to 5 blanks #.
Data statement to common in RDWRT put as exec statements in Squawinit.
Some missing commas in format statements fixed (warnings, only).
Missing argument to Hfill replaced by 0. (... ,, --> ,0.,).
Character data in real changed from '  ' to 4H form ("holerith data").

Many warnings are generated on equivalence without required number of 
subscripts, a relic of ancient Fortran that was once required.  Compiler 
appears to assume correct interpretation.  NO changes made on this (see below).

All subroutines made into a library.  A dummy main program was created to
test linking.  

Explicit, non-executed call to Conset block data added to Squawinit to attempt
to insure inclusion, was rejected as undefined external.  An explicit check
of one variable initialized by Conset was added, with an error message.  
When the linked dummy main was run, no error message was received, so 
apparently Conset was properly loaded, i.e., the archive program properly
keeps all routines in a module together in the created library.  Check was 
deleted.

The above test also showed that too much was removed from the writing phase
of RDWRT (WriteZ); status set was added back.

Initialization of first location of buffer (NLOC1) was required in conversion
routines, since they did not have the common block used by the rest of Squaw.
Some former local variables in the Squaw main program were equivalenced into 
/Concom/ for communication between Squaw, Squawinit and Squawend.

Field subroutine appeared ignored; name changed to Bfield, since there is a
FIELD variable in common.  As Bfield, it worked.

There were apparent problems with the initialization of variables to real 1.0.  
Data statements to a variable were tried.  It worked.  (Possibly due to 1.0 
being used as an argument to a subroutine which then changed it, but now 
believed to really be the VMS output cludge in TPDUMP, below.)

The first run with properly configured input file produced some pi0 fits.

A call to fflush was added at points in Etype to dump the buffers for debugging.
(It does not appear to really work; padding added in Squawend/ETPEND.)

After one fit in each event, the input record was clobbered:
Too much was removed from WREAD, initialization restored.  Multiple good fits.
	12/9/94, JMB
Now to tune it.

Pulls do not look right - for all vars & all trks, all pulls are same mag, with
opposite signs. - investigating.  This appears to be a result of the way the
1 constraint fits work.
Pull width not bad, but a little wide.

Added Etaprime mass and fit.  Killed single cluster pi0 and outgoing proton.
Reconfigured id block (run no. to 5 digits) for next run.
Masses updated to July 94 Particle Properties.

Fixed write statements to correct data type in Sumprt.  VAX had used a
work-around that was not available on IBM, and clearly had noticeable overhead.

Moved all histogramming from Wimper and Sumprt to Binset, so it does not
depend on level of print.

Printing logic in Sumprt fixed to avoid empty lines, events without ids, etc.

When debug print from above was removed, program core-dumped in the calling
C program.  Program ran after putting debug print back into Squaw subroutine,
only.  Debug print left with test on level of debug print, so that it is
normally not executed; no more dumps. ??

Compiled on SGIs with same errors as on IBMs.  Ran it but something is not
right since it forces debug print, and ends with a format problem.  
--comparing results.

Moved IBM code into .../squaw/ibm, so structure is symmetrical for SGI, which
is in .../squaw/sgi.

Created code to pass fitted output back to calling program, based on what 
Amir Sanjari's fitter returns, but somewhat more rational from a squaw point 
of view.  Dimensions were reduced in most cases.  Initial version returns a 
common block; a later version will optionally accept arguments ala AHS.

Found apparent bug in xlf format conversion that proved to be a VMS work-around
in TPDUMP.  Work-around commented out; no real bug.

Added multivertex fits for 2 gamma and 4 gamma events.  First pass is just
reactivating old KKN+gammas (E769) code with KK deleted. - not working correctly

Created subroutine SQUAWA to transfer arguments ala AHS, and then call Squaw.
SquawA works. (1/13/95)

Added option to suppress all print and file reading (except internally used
fortran unit 2).  New subroutine SQUAWIO sets flags for print and histogramming.

Hbook common /PAWC/ expanded to 10000, since hist output states that is what
it thinks it is, even with the call to HLIMIT(5000).  (Maybe 10k is also
declared by some part of the Cern pkg, as a minimum.)

SquawIO modified to also control whether main vertex fits are done.

Picon modified to save fitted variables and errors for Fitset, for full error
matrix output. These are then put into the modified /fitout/ common block. 
(1/11/95)

Tried again on SGI, with full debug.  Major problems, probably due to 
misinterpretation of old Fortran of Squaw.  Compiler messages are the same 
(equivalence with 1 subscript), but resulting code has problems.  It takes
the 1st 2 gammas & tries a pi0, then takes 3rd gamma by itself, then 4th
gamma by itself.  Error matrix handling is not right even on 1st more or less
properly set up pi0 permutation.  Input block to squaw is the same on both 
IBM & SGI, so the problem is within the historic squaw code itself.  Since 
we now have SGI IRIX 5.3, we will install it and see if the accompanying 
Fortran has fixed anything in Squaw before we start to try to go thru the
squaw code.  2/1/95

Cleaned up Etype to be more easily followed.  Also added logic so it will
not try pi0/eta/etaprime MV fits if no g-g fits (or not enough) of class 
worked.  Also added in charged tracks to MV fits, assuming even # of pi+/pi-.
Main vertex gammas MM fits tried on all multiplicites.  Constrained multivertex
fits are tried only on 2 and 4 gamma events.  6 gamma events MV constrained 
fits and MM fits supersaturate and cause coredumps; looked at but not resolved.
There is no output to the calling program yet for MV fits.
Tested on mixed sample and Doran's sample of eta eta'(-->pi+pi-eta) MC events.
Amir has used it (g-g fits only) on his large sample.  2/17/95

Tried recompile on SGI with -static compiler flag.  Permutations now correct,
but error matrix still singular.  Will add SAVE statement to all routines.

Made controllable routine Dumpfit to dump /fitout/ from outside Squaw.

Made histogramming setup and filling routines to check /fitout/ common block.
Reorganized subscripts on some variables in /fitout/, keeping sizes and
locations unchanged.
Added new output common block for main vertex fits; not yet filled.
Commented output section of Binset, as it was killing 6 gamma main vertex fits.
SAVE added to all routines (to try to get SGI version to work).  3/10/95

Main vertex output block /fitoutmv/ created & filled.  Size of some arrays
of /fitout/ enlarged as there are more fits than space allocated.  Number 
of saved fit info lines in Mnemnc increased to 500 (from 100).  New 
histogramming routine JBhist created to check output blocks outside Squaw.  
Dumpfit will now dump MV fit block, if there are any MV fits.  6 gamma
main vertex fits reactivated & work.  Main vertex/multivertex fits done for
2, 4, 6 gammas, with 2 or 4 charged main vertex tracks.  Fits with connecting
neutrals and missing neutron are done.  Missing mass fits are done with
fitted connecting neutrals and with all gammas at the main vertex.  3/21/95

Output blocks documented in squaw.h include file.  4/3/95

Code added to handle odd number of charged tracks, and odd number of gammas.
By default, the odd gamma is treated as a batchelor gamma at the main vertex.
Optionally thru new routine SQUAWMV, the odd gamma may be treated as a stray
and dropped from fits.  4/10/95

From problems linking with Squaw, with libraries in different orders, it was
found that a common block in Etype/Mnemnc conflicted with a subroutine in
CERNlib.  This block had been added at Ohio Univ. for passing info between
Mnemnc and Etype.  The common block has been renamed.  Also, we found that
both our Zhepsub miscellaneous subroutine package and CERNlib had routines
for the error function ERF, which is used in the calculation of the confidence
level.  The ERF routine has been removed from Zhepsub.  4/11/95

Squaw on SGI status: still not working correctly.  -static made it go thru
the permutations correctly.  Adding SAVE to the fortran code made no further
effect.  Now fits that fail on the IBMs fail with the same failure and Chisq
and Fsum on the SGIs.  However fits that work on the IBM now fail with
IFAIL =53 on the SGIs.  This failure is from subr. EFORM which is forming
the final fit error matrix.  The translation of the failure is that the
error matrix is singular.  However, the chisq, fsum, etc of the failing
fit are the same as the IBMs return with their successful fits.  So the SGI
is getting the same fits, but failing at the last instant as it manipulates
the error matrix.  Since Ifail 53 is set from about 3 places in Eform,
we need to go thru, with cvg or some debug print and find out what it really
thinks is the matter.   5/3/95

Scott Teige (IU) took the code, and converted the equivalences:
"To get the clean compile I replaced common/wampum/... and a few things 
following it with an include statement. In the included file, I fixed the
"single index equivalence" warning in the following way: (below is a generic 
example, if you look at the include file the details will be clear.)
old code:
        common/wampum/... ee(72,72) ....
        dimension abc(1256)
        equivalance (abc,ee(1))
new code:
        common/wampum/... ee(72,72) ....
        dimension abc(1256)
        dimension estr(6100)
        equivalence (ee(1,1),estr(1))
        equivalance (abc,estr(1))

This does what the "single index equivalence" was supposed to do.

The other thing I changed was to **remove** common/ffcom/. I looked at 
how this common mapped into storage space and discovered that it was entirely 
contained in /wampum/ and that there were no routines referencing  /ffcom/ 
that did not reference /wampum/.

There were also several isolated "single index equivalence" warnings scattered 
randomly through the code. I fixed these on a case by case basis. You can find 
my fixes by searching for the string swt in the code.  My fix is immediately 
below swt and is in lower case.

I get a clean compile except for:
        etype.f : branch to inner loop (2 ocurrances)."  15-MAY-1995 
The code ran for him on his SGI system, with no ifail 53's.  

(Note that the etype branch complaint is an artifact of the program logic.  
In order to remove this, a large chunk of code would have to be duplicated, 
or one needs the Fortran 90 internal procedures.  The code in question was 
a logical internal procedure in the original Flecs preprocessed code.)

I brought the code back to ND and rebuilt both IBM and SGI code.  Directory
structure revised so there is one directory for library source and a directory
for each architecture for library and objects and executables:  .../squaw/ibm,
.../squaw/sgi and .../squaw.src.  Makefiles revised for new structure.
They both ran with the same result as before: fits on IBM and ifail 53 on SGI.  
I then noticed that he built the executable by explicitly including all the 
*.o files at the beginning of his link.  Guessing that link order might be the 
problem, I tried to get a load map -- easy on IBM, complicated on SGI.  There 
is no flag on f77 to get a load map.  There is on ld, but f77 eats it.  I had 
tried the -v flag on SGI, which then echoed what it gave to the loader, which 
showed the -m flag missing.  When I captured the echoed command from -v, and 
cleaned it up from the line breaks at wrap, and added -m, I then got the map 
-- to the terminal, but redirection worked so I got a printable load map.  Then 
I relocated the order of the libraries, so that squaw was first, again with a 
map.  But when I run it, I get exactly the same thing, ifail 53 instead of 
good fits.  It also has always ended with an error on a clobbered format, at 
the last print statement of running.  This also is unchanged.  5/26/95

After extensive trial and error on changing the linking with no effect, I 
finally discovered (6/7/95) that the creation of a version of the squaw 
libraries by others (BNL) had overwritten our links to the libraries I was 
creating.  Thus, if I explicitly linked as Scott had done, I got code that 
(mostly) worked.  However, if I used the normal library route, I got the 
familiar old failure, because I was using the old libraries of 5/10/95.  We now
get fits on SGI, but main vertex fits fail underconstrained after the first
event.  This is under investigation at both ND & IU.  I do believe that 
Scott's common fix is what makes it work at all on the SGIs.  The SGI compiler 
was evidently misinterpreting the ancient Fortran.
Since it was the premature installation of Squaw at BNL and its subsequent 
overwrite of our links that made it appear nothing was working here, I oppose 
really updating the BNL code until we get the current bug fixed.  Since ND 
is the only place with IBMs where it works correctly, going from one incorrect 
version for SGI to another incorrect version seems a waste to me.  Additions 
are one thing, but wrong code "someplace" should not be standardized.  As it 
is, the entire sccs for squaw should be replaced.  I will leave this project 
for one of our grad students or someone else.

Also, several minor fixes for compiler cleanliness have been made.  A fit to
eta + etaprime has been added.  6/8/95

Based on clues from both of us, Scott found the problem with the SGI version:
we replaced (in Etype)
        CALL RDY(NPART,01,.....)
with (the equivalent of)
        IONE=1
        CALL RDY(NPART,IONE,.....)
and it works.  We also replaced the calls with 11 as the second argument.  
It appears that the leading 0 of the 01 confuses the SGI Fortran compiler.
We also padded the argument list with dummies so that there are always the 
same number of arguments being passed.  Squaw now runs on both platforms.
Optimization was tried on both platforms.  -O2 on IBM works and runs 4 times
faster than the debug noopt version.  On SGI, -O2 coredumps on the first event.
It works with nodebug and -O1, but with only a 20% gain over the debug version. 
6/16/95

In response to a statement from Scott that Squaw would quit after 9999 events,
we found that what he was seeing was an old format protection from earlier 
days when TVGP generated the event ID.  A comment has been added there in Inset
and some protection against triggering it, by making the id wrap around if 
needed, has been added in Makeid.f.  Libraries rebuilt.  It does not look like
we will spend any time trying to find why the SGI Fortran coredumps with -O2.
Aside from possible fitting changes, Squaw is probably in final form.  6/20/95

Some file cleanup has been done, in that some files in the .../src directories
which were test or relics have been removed.  The original versions exist on
the VAX in other subdirectories.  The intent has been to leave in .../src
only those files needed for the library, plus a few example main programs.
6/22/95

Report from IU that Squaw compiles with -O2 under IRIX 5.3.  We have yet
to check this.  9/8/95

Added eta to 3 pi (-+0) main vertex fits.  Squaw appears not to be doing
permutations of pi0s between the main vertex and the eta vertex.  --> This 
is a documented failure of Linque for identical particles at 2 different
vertices.  Explicitly defined APIZRO (anti-pi0), using slot in mass names 
already filled by Conset, and used it as pi0 from eta to work around Linque 
failure, since I found that it worked correctly if gammas came from different
mass neutrals.  
Now there are 5 GOTO's that the compiler complains about in Etype.  I may
be able to work around these by inverting some logic and using GO TOs.
Logic errors were found in Fudge in the testing for failed 2 gamma fits.  
These are leftovers from old code, altho' modified for E852:  fixed.
Include file MassNames.inc is now necessary for Etype and Fudge. 9/12/95

Also added omega (780) to 3 pi and etaprime to pi pi eta, with same logic.
Explicitly labeled AETA & APIZRO in MNEMNC, and added omega in both MNEMNC
and Conset.  9/15/95
MV fits for omega and etaprime (via eta pi pi) added.  Fitset updated for
new topologies.  Event code is as before, excluding tracks from intermediate 
vertex.  New flag in output for these fits.  9/19/95

Recompiled SGI library with -O2, now IRIX 5.3.  It ran (in contrast to -O2
under IRIX 5.2), producing identical results to those of the IBM.  Since 
the original data sample is no longer available, time comparisons must be 
extracted by comparisons, see SQTIMINGS.TXT.	9/26/95

From Rob Lindenbush, IU:
	Squaw now runs -n32 -mips4 on R8000 machines. For those who care, there
seems to be a compiler bug with the R8000 f77 compiler which was causing
problems. This hase been worked around in the following manner:
in ambig() (ambig.f)
	Remove the equiv. statement (BX,IX)
	Replace references to BX with IX (i.e. get rid of BX)
BTW, it still does not work full 64-bit (-mips4) - core dumps etc...
(This was a local equivalence, and several of the involved variables had been
forced to integer 10 years ago for VAX.  The dual names were no longer needed
or really understandable.  JMB)  11/28/95

In attempting to understand a shift in fitted beam momentum from the
reconstructed value which was much larger than the allowed errors, we discovered
a peculiarity of Squaw.  We have not traced thru Squaw for the reason, but we
have a workaround.  The peculiarity is that, although the beam momemtum was
set the same at both the beginning and end of the track, Squaw insists on
applying some sort of de/dx change in the momentum to the ending momentum.
Even more peculiar, is that de/dx=0 is not for beam track length 0, but, at
least for E852, at beam track length of 136 cm!  For shorter beam track
lengths, the beam momentum is actually raised.  The change in the beam momentum
is actually linear in the beam track length.  This 136 cm distance has no
known significance in the E852 coordinate systems.  By arbitrarily setting the
beam track length to 136 cm, we have removed this peculiar momentum shift,
so that the beam track momemtum at the vertex which is used in the fit is now
the reconstructed value.  JMB, 1/19/96