/******* -*-C++-*- **********************************************/
/*  proc_dosy       16.11.2010                                  */
/****************************************************************/
/*  Short Description :                                         */
/*  AU program to process DOSY data in automation               */
/****************************************************************/
/*  Keywords :                                                  */
/*  DOSY, automation, processing                                */
/****************************************************************/
/*  Description/Usage :                                         */
/*  Processing AU program for 2D DOSY spectra.                  */
/*  The projection in F2 is 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.      */
/****************************************************************/
/*  Author(s) :                                                 */
/*  Name            : Rainer Kerssebaum                         */
/*  Organisation    : Bruker BioSpin GmbH                       */
/*  Email           : rainer.kerssebaum@bruker-biospin.de       */
/****************************************************************/
/*  Name        Date    Modification:                           */
/*  rke         101116  created                                 */
/****************************************************************/
/*
$Id:$
*/

/* Declare filenames etc. for the portfolio file handling */
#ifndef PROCPATH2
#define PROCPATH2(x) curd_path(0,disk2,user2,name2,expno2,procno2,x)
#endif
#ifndef PROCPATH3
#define PROCPATH3(x) curd_path(0,disk3,user3,name3,expno3,procno3,x)
#endif

char    xwlay[PATH_MAX], portf[PATH_MAX];
int     parmode, digmod, s_procno;
float   ph0, ph1;

portf[0] = 0;
DECLARE_PORTFOLIO

/* The program only works on 2D datasets */
FETCHPARS("PPARMOD",&parmode)
if (parmode != 1)
    STOPMSG("Not a 2D dataset")

/* get phase correction */
s_procno=procno;
XF2
ERRORABORT

RSR(1, 111)
ERRORABORT

RPROCNO(111)
FETCHPARS("DIGMOD", &digmod)

if (digmod == 3)
    APK0
else
    APK

ERRORABORT

FETCHPARS("PHC0", &ph0);
FETCHPARS("PHC1", &ph1);
RPROCNO(s_procno)
STOREPAR("PHC0", ph0);
STOREPAR("PHC1", ph1);
STOREPAR("PH_mod", 1);
XF2
ERRORABORT

/* process DOSY */
XCMD("setdiffparm")
STOREDOSYPAR("PC", 50.0)
if (digmod != 3)
    {
    STOREPAR("ABSG", 1);
    STOREPAR("ABSF1", 100.0);
    STOREPAR("ABSF2", -100.0);
    ABS2
    }
XCMD("dosy2d setup")
XCMD("dosy2d")

/* prepare plot */
/* 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(112)
    DATASET2(name, expno, 112, disk, user)
    GETCURDATA2
    }

/* Create and open portfolio file portf */
strcpy(portf, PROCPATH("portf"));
CREATE_PORTFOLIO(portf)
ADD_CURDAT_TO_PORTFOLIO
ADD_TO_PORTFOLIO(disk2,user2,name2,expno2,procno2)
CLOSE_PORTFOLIO

AUTOPLOT_WITH_PORTFOLIO

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

QUIT
