/***********************************************-*-C++-*-********/
/*	proc_2dhom		18.05.2000			*/
/****************************************************************/
/*	Short Description :					*/
/* 	Processes and plots 2D homonuclear type spectra.	*/
/****************************************************************/
/*	Keywords :						*/
/*	2D homonuclear COSY MLEV NOESY ROESY			*/
/****************************************************************/
/*	Description/Usage :					*/
/*	Processing AU program for 2D homonuclear type spectra.	*/
/*	If you want to use your individual plot layout, you	*/
/*	can define it within TopSpin with the command 'layout'.	*/
/*	If no layout is defined, the default '2D_hom.xwp'	*/
/*	is used.						*/
/* 	The phase in F2 and F1 is calculated with the AU 	*/
/*	program calcphhomo. 					*/
/*	The projections in F1 and F2 are read from the 		*/
/*	curdat2 file, which is defined by the TopSpin command 	*/
/*	'edc2'. If there is no dataset available, the positive 	*/
/*	F2 projection is used as projection for both axes.	*/
/****************************************************************/
/*	Author(s) :						*/
/*	Name		: Peter Dvortsak, Rainer Kerssebaum,	*/
/*			  Ruediger Weisemann, Mike Engelhardt	*/
/*			  Sven Cunskis				*/
/*	Organisation	: Bruker BioSpin GmbH			*/
/*	Email		: nmr-software-support@bruker.de	*/
/****************************************************************/
/*	Name		Date	Modification:			*/
/*	pdv		910901	created				*/
/*	eng		000418	set plot limits			*/
/*	rke,rwe,eng	000503	calls AU program calcphhomo 	*/
/*	eng		000518	set projections			*/
/*	svcu		010102	use XWIN-PLOT for plotting	*/
/*	svcu		030115	use ext. dataset for F1 proj.	*/
/*	svcu		041001	increase print_to_file options	*/
/*	wem,svcu	060530	optimized functionality		*/
/*								*/
/****************************************************************/
/*
$Id:$ */


/*********************************************/
/* Declare variables */
double sw1,sw2,sf1,sf2,sum1,sum2;
float offs1,offs2;
char xwlay[PATH_MAX], portf[PATH_MAX];
 
portf[0] = 0;


/*********************************************/
/* Declare filenames etc. for the portfolio file handling */
DECLARE_PORTFOLIO


/*********************************************/
/* phase correction by the AU program 'calcphhomo' */
XCMD("calcphhomo")
ERRORABORT

/*********************************************/
/* processing */
XFB
ERRORABORT
ABS2
ABS1
LEVCALC
FETCHPARS("OFFSET",&offs2)
FETCHPARS("SW_p",&sw2)
FETCHPARS("SF",&sf2)
FETCHPAR1S("OFFSET",&offs1)
FETCHPAR1S("SW_p",&sw1)
FETCHPAR1S("SF",&sf1)
sum1 = offs1 - sw1 / sf1;
sum2 = offs2 - sw2 / sf2;
STOREPAR1("F1P",offs1)
STOREPAR("F1P",offs2)
STOREPAR1("F2P",sum1)
STOREPAR("F2P",sum2)


/*********************************************/
/* If no layout is defined the default layout will be used  */
FETCHPAR("LAYOUT",&xwlay)
if (xwlay[0] == '\0')
{
    STOREPAR("LAYOUT","+/2D_hom.xwp")
}


/*********************************************/
/* set F2 reference for plotting. If no dataset is 	*/
/* defined the positive F2 projection is used  		*/
GETCURDATA2
if (AUERR < 0 || access(PROCPATH2("1r"),F_OK)) 
{ 
    RHPP(98)
    DATASET2(name, expno, 98, disk, user)
    GETCURDATA2
}


/*********************************************/
/* set F1 reference for plotting. If no dataset is 	*/
/* defined the F2 projection is used  			*/
GETCURDATA3
if (AUERR < 0 || access(PROCPATH3("1r"), F_OK))
{
    DATASET3(name2, expno2, procno2, disk2, user2)
    GETCURDATA3
}

/*********************************************/
/* Create and open portfolio file portf */
strcpy(portf, PROCPATH("portf"));
CREATE_PORTFOLIO(portf)


/*********************************************/
/* The 2D dataset is written first to the portfolio file */ 
ADD_CURDAT_TO_PORTFOLIO


/*********************************************/
/* Now add the F2 projection (2nd dataset) to the portfolio file */
ADD_TO_PORTFOLIO(disk2,user2,name2,expno2,procno2)


/*********************************************/
/* Now add the F1 projection (3rd dataset) to the portfolio file */
ADD_TO_PORTFOLIO(disk3,user3,name3,expno3,procno3)


/*********************************************/
/* Close protfolio file */
CLOSE_PORTFOLIO


/*********************************************/
/* Plot with two datasets defined in the portfolio. */
AUTOPLOT_WITH_PORTFOLIO


/*********************************************/
/* Adds include file 'printtofile' that manage	*/
/* the 'plot_to_file' information		*/
#include <inc/printtofile>


QUIT
