Newer
Older
/* Copyright (c) Anglo-Australian Telescope Board, 1999.
Not to be used for commercial purposes without AATB permission. */
#include "DitsFix.h"
#include "Sdp.h"
#include "Git.h"
#include "dul_err.h"
/* externals */
extern void combine_image_(DitsArgType*,StatusType*);
extern void combine_spectra_(DitsArgType*,StatusType*);
/* extern void flx_calib_(DitsArgType*,StatusType*); */
/* extern void gen_calib_(DitsArgType*,StatusType*); */
extern void plotserver_(DitsArgType*,DitsArgType*,StatusType*);
extern void reduce_arc_(DitsArgType*,StatusType*);
extern void reduce_bias_(DitsArgType*,StatusType*);
extern void reduce_fflat_(DitsArgType*,StatusType*);
extern void reduce_lflat_(DitsArgType*,StatusType*);
extern void reduce_fflx_(DitsArgType*,StatusType*);
extern void reduce_object_(DitsArgType*,StatusType*);
extern void reduce_sky_(DitsArgType*,StatusType*);
extern void reduce_gen(DitsArgType*,StatusType*);
mnb
committed
extern void make_im___(DitsArgType*,StatusType*);
extern void make_ex_(DitsArgType*,StatusType*);
extern void make_red_(DitsArgType*,StatusType*);
extern void detect_cosmic_streaks_(DitsArgType*,StatusType*);
extern void transfer_function_correction_(DitsArgType*,StatusType*);
static void changeWorkingDirectory(StatusType*);
static void combineImageAction(StatusType*);
static void combineSpectraAction(StatusType*);
/* static void flxCalibAction(StatusType*); */
/* static void genCalibAction(StatusType*); */
mnb
committed
static void plotKick(StatusType*);
static void reduceArcAction(StatusType*);
static void reduceBiasAction(StatusType*);
static void reduceFFlatAction(StatusType*);
static void reduceLFlatAction(StatusType*);
static void reduceFFluxAction(StatusType*);
static void reduceObjAction(StatusType*);
static void reduceSkyAction(StatusType*);
static void reduceGenAction(StatusType*);
mnb
committed
static void makeIMAction(StatusType*);
static void makeEXAction(StatusType*);
static void makeREDAction(StatusType*);
static void transfuncAction(StatusType*);
static void detectCosmicStreaksAction(StatusType*);
mnb
committed
static void testAction(StatusType*);
static void testKick(StatusType*);
mnb
committed
void SetPgplotRequest(char key, float x, float y);
void GetPgplotRequest(char* key, float* x, float* y);
/*---------------------------------------------------------------------------*/
* This task acts as an action server for 2dfdr. drcontrol acts as the client
* DRAMA task sending this task requests for 2dfdr processing.
* N.B. This task BREAKS one of the cardinal rules of DRAMA -
* 1. Tasks accepting and servicing actions shall reschedule immediately
* thereby being ready for any new actions (or kicks).
* Notice the DRAMA actions served by this task are quite CPU intensive,
* and the program does NOT reschedule until they complete.
StatusType status = DITS__OK;
char taskName[40];
{ changeWorkingDirectory, 0,0,0,0,0,"CHANGE_WD" },
{ combineImageAction, plotKick,0,0,0,0,"COMBINE_IMAGE" },
{ combineSpectraAction,plotKick,0,0,0,0,"COMBINE_SPECTRA" },
{ find2dfFibresAction, plotKick,0,0,0,0,"GFIBPOS" },
{ plotAction, plotKick,0,0,0,0,"PLOT" },
{ reduceArcAction, plotKick,0,0,0,0,"REDUCE_ARC" },
{ reduceBiasAction, plotKick,0,0,0,0,"REDUCE_BIAS" },
{ reduceDarkAction, plotKick,0,0,0,0,"REDUCE_DARK" },
{ reduceFFlatAction, plotKick,0,0,0,0,"REDUCE_FFLAT" },
{ reduceLFlatAction, plotKick,0,0,0,0,"REDUCE_LFLAT" },
{ reduceFFluxAction, plotKick,0,0,0,0,"REDUCE_FFLX" },
{ reduceObjAction, plotKick,0,0,0,0,"REDUCE_OBJECT" },
{ reduceSkyAction, plotKick,0,0,0,0,"REDUCE_SKY" },
{ reduceGenAction, plotKick,0,0,0,0,"REDUCE_GEN" },
{ makeIMAction, plotKick,0,0,0,0,"MAKE_IM" },
{ makeEXAction, plotKick,0,0,0,0,"MAKE_EX" },
{ makeREDAction, plotKick,0,0,0,0,"MAKE_RED" },
{ skysubPCAAction, plotKick,0,0,0,0,"SKYSUB_PCA" },
{ spliceAction, plotKick,0,0,0,0,"SPLICE" },
{ transfuncAction, plotKick,0,0,0,0,"TRANSFUNC" },
{ detectCosmicStreaksAction,plotKick,0,0,0,0,"DETECT_CSTRKS"},
{ exitAction, 0, 0,0,0,0,"EXIT" },
{ NOPAction, plotKick, 0,0,0,0,"NOP" },
{ testAction, plotKick,0,0,0,0,"TEST" }
/* The task name is normally given in argv[1]. Multiple copies of the
task can be started using different task names. A default name is
used if one is not given. */
strcpy(taskName,(argc > 1) ? argv[1] : "DREXEC");
/* initialise DRAMA
DITS_M_NOEXHAND => we will install exit handler */
DitsAppInit(taskName,300000,DITS_M_NOEXHAND,0,&status);
/* define supported actions */
DitsPutActions(DitsNumber(actions),actions,&status);
/* enter DRAMA main loop
This returns when action returns DITS_REQ_EXIT */
DitsMainLoop(&status);
/* here returned from DRAMA main loop, shutdown DRAMA and exit */
/*---------------------------------------------------------------------------*/
void NOPAction(
StatusType* pStatus)
/*
* Handler for "No Operation" DRAMA action (i.e. do nothing).
*/
{
if (*pStatus != DITS__OK) return;
printf(" +++NOP Action++++ Status=%i\n",*pStatus);
printf(" +++NOP Finished++ Status=%i\n",*pStatus);
DitsPutRequest(DITS_REQ_END,pStatus);
}
/*---------------------------------------------------------------------------*/
void changeWorkingDirectory(
StatusType* pStatus)
/*
* Handler for "CHANGE_WD" DRAMA action.
*/
{
DitsArgType args;
long len;
char dirname[1024];
if (*pStatus != DITS__OK) return;
/* get our SDS argument structure */
args = DitsGetArgument();
/* Get the name of the new working directory from the SDS arg*/
len=1024;
ArgGetString(args, "NEW_WORK_DIR", len, dirname, pStatus);
/* Change the working directory to the new location*/
chdir(dirname);
DitsPutRequest(DITS_REQ_END,pStatus);
}
/*---------------------------------------------------------------------------*/
/* for debug print our argument structure on stdout
SdsList(args,pStatus); /*
/*---------------------------------------------------------------------------*/
/* get our SDS argument structure */
args = DitsGetArgument();
/* Dump arguments list to screen for diagnostic purposes */
/* call Fortran COMBINE_SPECTRA() */
combine_spectra_(&args,pStatus);
DitsPutRequest(DITS_REQ_END,pStatus);
/*---------------------------------------------------------------------------*/
*
* This action is not currently working. See flux_cal.f.
/* for debug print our argument structure on stdout
SdsList(args,pStatus); */
/* make copy so it can be changed (external SDS -> internal) */
/* SdsCopy(args,&localArgs,pStatus); */
/* flx_calib_(&args,pStatus); */
/* delete local SDS copy */
/*---------------------------------------------------------------------------*/
*
* This action is not currently working. See flux_cal.f.
/* get our SDS argument structure */
args = DitsGetArgument();
/* for debug print our argument structure on stdout
SdsList(args,pStatus);*/
/* make copy so it can be changed (external SDS -> internal) */
/* SdsCopy(args,&localArgs,pStatus); */
/* gen_calib_(&args,pStatus); */
/* delete local SDS copy */
/* SdsDelete(localArgs,pStatus); */
DitsPutRequest(DITS_REQ_END,pStatus);
/*---------------------------------------------------------------------------*/
*
* This action is not currently working. See find_fib_2df.f.
/* for debug print our argument structure on stdout
SdsList(args,pStatus);*/
/*---------------------------------------------------------------------------*/
SdsIdType inpArgs, outArgs;
SdsIdType id2;
/* Get our input SDS argument structure */
/* Note: This is an external SDS object and cannot be modified*/
SdsCopy(args,&inpArgs,pStatus);
/* Create a return sds object that can be written to*/
SdsNew(0,"retArgs",0,NULL,SDS_STRUCT,0,NULL,&outArgs,pStatus);
/* call the Fortran subroutine plotSERVER() */
plotserver_(&inpArgs,&outArgs,pStatus);
/* Set the return SDS object to be outArgs*/
DitsPutArgument (outArgs,DITS_ARG_DELETE, pStatus);
}
/*---------------------------------------------------------------------------*/
mnb
committed
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
void plotKick(
StatusType *pStatus)
/*
* Handler for kicking the "Plot" DRAMA action.
*/
{
DitsArgType args;
char key;
char Buffer[10];
float x,y;
if (*pStatus != DITS__OK) return;
/* get our SDS argument structure */
args = DitsGetArgument();
/* Obtain the KEY character and the X Y values*/
/* Note: ArgGetc(args,"KEY",&key,pStatus) doesn't appear to work so
we use ArgGetString instead */
ArgGetString(args,"KEY",10,Buffer,pStatus);
key=Buffer[0];
ArgGetf(args,"X",&x,pStatus);
ArgGetf(args,"Y",&y,pStatus);
/* Store these values with Pgplot Request Set Functions*/
SetPgplotRequest(key,x,y);
/* Now this is the bit I am not sure about but is supposed to unblock
the DitsActionWait command */
DitsPutRequest(DITS_REQ_STAGE,pStatus);
}
/*---------------------------------------------------------------------------*/
SdsIdType localArgs = 0;
StatusType ignore = STATUS__OK;
/* for debug print our argument structure on stdout
SdsList(args,pStatus);*/
/* make copy so it can be changed (external SDS -> internal) */
SdsCopy(args,&localArgs,pStatus);
if (*pStatus!=DITS__OK) {
ErsRep(0,pStatus,"%s","reduce arc error");
}
/* delete local SDS copy and free id */
SdsDelete(localArgs,&ignore);
SdsFreeId(localArgs,&ignore);
DitsPutRequest(DITS_REQ_END,pStatus);
}
/*---------------------------------------------------------------------------*/
*/
{
DitsArgType args;
if (*pStatus != DITS__OK) return;
/* for debug print our argument structure on stdout
SdsList(args,pStatus); */
if (*pStatus!=DITS__OK) {
ErsRep(0,pStatus,"%s","reduce bias error");
}
DitsPutRequest(DITS_REQ_END,pStatus);
}
/*---------------------------------------------------------------------------*/
void reduceDarkAction(
StatusType* pStatus)
/*
* Handler for "REDUCE_DARK" DRAMA action.
*/
{
DitsArgType args;
if (*pStatus != DITS__OK) return;
/* get our SDS argument structure */
args = DitsGetArgument();
/* for debug print our argument structure on stdout
SdsList(args,pStatus); */
if (*pStatus!=DITS__OK) {
ErsRep(0,pStatus,"%s","reduce dark error");
}
DitsPutRequest(DITS_REQ_END,pStatus);
}
/*---------------------------------------------------------------------------*/
SdsIdType localArgs = 0;
StatusType ignore = STATUS__OK;
/* for debug print our argument structure on stdout
SdsList(args,pStatus); */
/* make copy so it can be changed (external SDS -> internal) */
SdsCopy(args,&localArgs,pStatus);
ErsRep(0,pStatus,"%s","Reduce flat error");
/* delete local SDS copy and free id */
SdsDelete(localArgs,&ignore);
SdsFreeId(localArgs,&ignore);
DitsPutRequest(DITS_REQ_END,pStatus);
}
/*---------------------------------------------------------------------------*/
*/
{
DitsArgType args;
if (*pStatus != DITS__OK) return;
/* for debug print our argument structure on stdout
SdsList(args,pStatus); */
ErsRep(0,pStatus,"%s","Reduce long flat error");
DitsPutRequest(DITS_REQ_END,pStatus);
}
/*---------------------------------------------------------------------------*/
void reduceFFluxAction(
StatusType* pStatus)
/*
* Handler for "REDUCE_FFLX" DRAMA action.
*/
{
DitsArgType args;
SdsIdType localArgs = 0;
StatusType ignore = STATUS__OK;
if (*pStatus != DITS__OK) return;
/* get our SDS argument structure */
args = DitsGetArgument();
/* for debug print our argument structure on stdout*/
/*SdsList(args,pStatus); */
/* make copy so it can be changed (external SDS -> internal) */
SdsCopy(args,&localArgs,pStatus);
/* call Fortran REDUCE_OBJECT() */
reduce_fflx_(&localArgs,pStatus);
if (*pStatus!=DITS__OK) {
ErsRep(0,pStatus,"%s","Reduce object error");
}
/* delete local SDS copy and free its id*/
SdsDelete(localArgs,&ignore);
SdsFreeId(localArgs,&ignore);
DitsPutRequest(DITS_REQ_END,pStatus);
}
/*---------------------------------------------------------------------------*/
SdsIdType localArgs = 0;
StatusType ignore = STATUS__OK;
if (*pStatus != DITS__OK) return;
/* for debug print our argument structure on stdout
SdsList(args,pStatus); */
/* make copy so it can be changed (external SDS -> internal) */
SdsCopy(args,&localArgs,pStatus);
ErsRep(0,pStatus,"%s","Reduce object error");
/* delete local SDS copy and free its id*/
SdsDelete(localArgs,&ignore);
SdsFreeId(localArgs,&ignore);
DitsPutRequest(DITS_REQ_END,pStatus);
}
/*---------------------------------------------------------------------------*/
SdsIdType localArgs = 0;
StatusType ignore = STATUS__OK;
/* for debug print our argument structure on stdout
SdsList(args,pStatus); */
/* make copy so it can be changed (external SDS -> internal) */
SdsCopy(args,&localArgs,pStatus);
ErsRep(0,pStatus,"%s","Reduce sky error");
/* delete local SDS copy and free its id*/
SdsDelete(localArgs,&ignore);
SdsFreeId(localArgs,&ignore);
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
/*---------------------------------------------------------------------------*/
void reduceGenAction(
StatusType* pStatus)
/*
* Handler for "REDUCE_GEN" DRAMA action.
*/
{
DitsArgType args;
SdsIdType localArgs = 0;
StatusType ignore = STATUS__OK;
if (*pStatus != DITS__OK) return;
/* get our SDS argument structure */
args = DitsGetArgument();
/* for debug print our argument structure on stdout */
SdsList(args,pStatus);
/* make copy so it can be changed (external SDS -> internal) */
SdsCopy(args,&localArgs,pStatus);
/* call Fortran REDUCE_GEN() */
reduce_gen_(&localArgs,pStatus);
if (*pStatus!=DITS__OK) {
ErsRep(0,pStatus,"%s","Reduce sky error");
}
/* delete local SDS copy and free its id*/
SdsDelete(localArgs,&ignore);
SdsFreeId(localArgs,&ignore);
DitsPutRequest(DITS_REQ_END,pStatus);
}
/*---------------------------------------------------------------------------*/
mnb
committed
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
void makeIMAction(
StatusType* pStatus)
/*
* Handler for "make_IM" DRAMA action.
*/
{
DitsArgType args;
SdsIdType localArgs = 0;
StatusType ignore = STATUS__OK;
if (*pStatus != DITS__OK) return;
/* get our SDS argument structure */
args = DitsGetArgument();
/* for debug print our argument structure on stdout
SdsList(args,pStatus); */
/* make copy so it can be changed (external SDS -> internal) */
SdsCopy(args,&localArgs,pStatus);
/* call Fortran make_im() */
make_im___(&localArgs,pStatus);
if (*pStatus!=DITS__OK) {
ErsRep(0,pStatus,"%s","Make im error");
}
/* delete local SDS copy and free its id*/
SdsDelete(localArgs,&ignore);
SdsFreeId(localArgs,&ignore);
DitsPutRequest(DITS_REQ_END,pStatus);
}
/*---------------------------------------------------------------------------*/
void makeEXAction(
StatusType* pStatus)
/*
* Handler for "make_IM" DRAMA action.
*/
{
DitsArgType args;
SdsIdType localArgs = 0;
StatusType ignore = STATUS__OK;
if (*pStatus != DITS__OK) return;
/* get our SDS argument structure */
args = DitsGetArgument();
/* for debug print our argument structure on stdout
SdsList(args,pStatus); */
/* make copy so it can be changed (external SDS -> internal) */
SdsCopy(args,&localArgs,pStatus);
/* call Fortran make_ex() */
make_ex_(&localArgs,pStatus);
if (*pStatus!=DITS__OK) {
ErsRep(0,pStatus,"%s","Make ex error");
}
/* delete local SDS copy and free its id*/
SdsDelete(localArgs,&ignore);
SdsFreeId(localArgs,&ignore);
DitsPutRequest(DITS_REQ_END,pStatus);
}
/*---------------------------------------------------------------------------*/
void makeREDAction(
StatusType* pStatus)
/*
* Handler for "make_IM" DRAMA action.
*/
{
DitsArgType args;
SdsIdType localArgs = 0;
StatusType ignore = STATUS__OK;
if (*pStatus != DITS__OK) return;
/* get our SDS argument structure */
args = DitsGetArgument();
/* for debug print our argument structure on stdout
SdsList(args,pStatus); */
/* make copy so it can be changed (external SDS -> internal) */
SdsCopy(args,&localArgs,pStatus);
/* call Fortran make_red() */
make_red_(&localArgs,pStatus);
if (*pStatus!=DITS__OK) {
ErsRep(0,pStatus,"%s","Make red error");
}
/* delete local SDS copy and free its id*/
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
SdsDelete(localArgs,&ignore);
SdsFreeId(localArgs,&ignore);
DitsPutRequest(DITS_REQ_END,pStatus);
}
/*---------------------------------------------------------------------------*/
void skysubPCAAction(
StatusType* pStatus)
/*
* Handler for "make_IM" DRAMA action.
*/
{
DitsArgType args;
SdsIdType localArgs = 0;
StatusType ignore = STATUS__OK;
if (*pStatus != DITS__OK) return;
/* get our SDS argument structure */
args = DitsGetArgument();
/* for debug print our argument structure on stdout*/
SdsList(args,pStatus);
/* make copy so it can be changed (external SDS -> internal) */
SdsCopy(args,&localArgs,pStatus);
/* call Fortran make_red() */
skysub_pca_(&localArgs,pStatus);
if (*pStatus!=DITS__OK) {
ErsRep(0,pStatus,"%s","PCA Sky Subtraction error");
}
/* delete local SDS copy and free its id*/
mnb
committed
SdsDelete(localArgs,&ignore);
SdsFreeId(localArgs,&ignore);
DitsPutRequest(DITS_REQ_END,pStatus);
}
/*---------------------------------------------------------------------------*/
*/
{
DitsArgType args;
if (*pStatus != DITS__OK) return;
/* get our SDS argument structure */
args = DitsGetArgument();
/* for debug print our argument structure on stdout
SdsList(args,pStatus); */
if (*pStatus != DITS__OK) {
ErsRep(0,pStatus,"%s","splice error");
}
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
/*---------------------------------------------------------------------------*/
void transfuncAction(
StatusType* pStatus)
/*
* Handler for "SPLICE" DRAMA action.
*/
{
DitsArgType args;
if (*pStatus != DITS__OK) return;
/* get our SDS argument structure */
args = DitsGetArgument();
/* for debug print our argument structure on stdout*/
SdsList(args,pStatus);
/* call Fortran SPLICE_AAOMEGA() */
transfer_function_correction_(&args,pStatus);
if (*pStatus != DITS__OK) {
ErsRep(0,pStatus,"%s","Tansfer Function Correction error");
}
DitsPutRequest(DITS_REQ_END,pStatus);
}
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
/*---------------------------------------------------------------------------*/
void detectCosmicStreaksAction(
StatusType* pStatus)
/*
* Handler for "DETECT_CSTRKS" DRAMA action.
*/
{
DitsArgType args;
SdsIdType localArgs = 0;
StatusType ignore = STATUS__OK;
if (*pStatus != DITS__OK) return;
/* get our SDS argument structure */
args = DitsGetArgument();
/* for debug print our argument structure on stdout
SdsList(args,pStatus); */
/* make copy so it can be changed (external SDS -> internal) */
SdsCopy(args,&localArgs,pStatus);
/* call Fortran DETECT_COSMIC_STREAKS() */
detect_cosmic_streaks_(&args,pStatus);
if (*pStatus!=DITS__OK) {
ErsRep(0,pStatus,"%s","cosmic streak detection error error");
}
/* delete local SDS copy and free its id*/
SdsDelete(localArgs,&ignore);
SdsFreeId(localArgs,&ignore);
DitsPutRequest(DITS_REQ_END,pStatus);
}
/*---------------------------------------------------------------------------*/
mnb
committed
/*---------------------------------------------------------------------------*/
void testAction(
StatusType *pStatus)
/*
* Handler for "TEST" DRAMA action.
*/
{
printf("Test Drama Action Called\n");
DitsPutRequest(DITS_REQ_MESSAGE,pStatus);
mnb
committed
DitsPutRequest(DITS_REQ_END,pStatus);
}
/*---------------------------------------------------------------------------*/
mnb
committed
void testKick(
StatusType *pStatus)
/*
mnb
committed
*/
{
mnb
committed
DitsPutRequest(DITS_REQ_END,pStatus);
}