/*** ^^A -*-C++-*- **********************************************/
/*  proc_2dplxf2m           11.04.2013                          */
/****************************************************************/
/*  Short Description :                                         */
/*  Processes and plots 2D HMBC-et type spectra.                */
/****************************************************************/
/*  Keywords :                                                  */
/*  2D inverse HMBC                                             */
/****************************************************************/
/*  Description/Usage :                                         */
/*  Processing AU program for 2D spectra like HMBC-et, which    */
/*  are phase sensitive in F1, but magnitude in F2.             */
/*  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_inv.xwp'           */
/*  is used.                                                    */
/****************************************************************/
/*  Author(s) :                                                 */
/*  Name            : Rainer Kerssebaum                         */
/*  Organisation    : Bruker BioSpin GmbH                       */
/*  Email           : nmr-software-support@bruker.de		*/
/****************************************************************/
/*  Name        Date    Modification:                           */
/*  rke         130411  created, derived from proc_2dpl         */
/****************************************************************/
/*
$Id:$
*/

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

portf[0]=0;


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


/*********************************************/
/* processing */
XFB
ERRORABORT
XF2M
ABS2
ABS1
XCMD("clev")


/*********************************************/
/* use aquisition range for the peak picking limits */
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_inv.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 F1 projection is used                */
GETCURDATA3
if (AUERR < 0 || access(PROCPATH3("1r"), F_OK))
{
    RVPP(99)
    DATASET3(name, expno, 99, disk, user)
    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. This    */
/* command uses the portfolio file specified in the         */
/* CREATE_PORTFOLIO command                                 */
AUTOPLOT_WITH_PORTFOLIO


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


QUIT
