IDL_VPTR pgsql_query(int argc, IDL_VPTR *argv, char *argk) { IDL_VPTR queryVptr; char *query; char *connect_info; IDL_VPTR resultVptr; int async = 1; int status; (void) IDL_KWProcessByOffset(argc, argv, argk, kw_pars, (IDL_VPTR *) 0, 1, &kw); if (kw.nrows_there) IDL_StoreScalarZero(kw.nrows, IDL_TYP_ULONG64); /* Check number of input parameters */ if (pgsql_query_nparams(argc) < 1) { IDL_Message(IDL_M_NAMED_GENERIC, IDL_MSG_INFO, "-Syntax: result=pgsql_query(query, nrows=, connect_info=, file=, /append, /nointerrupt, /verbose, status=)\nIf there are results for the query, a structure is returned. Otherwise the result is -1"); return(IDL_GettmpInt(-1)); } /* Get the input query */ queryVptr = argv[0]; query = IDL_VarGetString(queryVptr); /* The user may have input connection information */ if (kw.connect_info_there) connect_info=IDL_STRING_STR(&kw.connect_info); else connect_info=""; /* Should we query asynchronously? This would allow cancel through ^C */ if (kw.nointerrupt_there) if (kw.nointerrupt) async = 0; if (async) status = pgsql_query_send_async(query, connect_info, &resultVptr); else status = pgsql_query_send(query, connect_info, &resultVptr); setStatus(status); IDL_KW_FREE; if (status == MYPG_SUCCESS) return(resultVptr); else return(IDL_GettmpInt(-1)); }
/** * Get the current position of a layer in the layer list. * * @param[in] [1] * The name of the layer. * @param[in] WINDOW @opt * The name of the window. Defaults to the active window. * @return The 0 based position of the layer in the layer list. * @usage idx = get_layer_position("data.tif") * @endusage */ IDL_VPTR get_layer_position(int argc, IDL_VPTR pArgv[], char* pArgk) { typedef struct { IDL_KW_RESULT_FIRST_FIELD; int windowExists; IDL_STRING windowName; } KW_RESULT; //IDL_KW_FAST_SCAN is the type of scan we are using, following it is the //name of the keyword, followed by the type, the mask(which should be 1), //flags, a boolean whether the value was populated and finally the value itself static IDL_KW_PAR kw_pars[] = { IDL_KW_FAST_SCAN, {"WINDOW", IDL_TYP_STRING, 1, 0, reinterpret_cast<int*>(IDL_KW_OFFSETOF(windowExists)), reinterpret_cast<char*>(IDL_KW_OFFSETOF(windowName))}, {NULL} }; IdlFunctions::IdlKwResource<KW_RESULT> kw(argc, pArgv, pArgk, kw_pars, 0, 1); std::string windowName; std::string name; int index = -1; if (kw->windowExists) { windowName = IDL_STRING_STR(&kw->windowName); } if (argc < 1) { IDL_Message(IDL_M_GENERIC, IDL_MSG_RET, "get_layer_position takes a layer name as a parameter with a " "window as an optional keyword to specify a non current window."); } else { //layer name passed in as a parameter name = IDL_VarGetString(pArgv[0]); SpatialDataView* pView = dynamic_cast<SpatialDataView*>(IdlFunctions::getViewByWindowName(windowName)); if (pView != NULL) { Layer* pLayer = IdlFunctions::getLayerByName(windowName, name, false); if (pLayer != NULL) { index = pView->getLayerDisplayIndex(pLayer); } } } return IDL_GettmpInt(index); }
/** * Get the number of layers in a window. * * @param[in] WINDOW @opt * The name of the window. Defaults to the active window. * @return The number of layers in the window. * @usage num_layers = get_num_layers() * @endusage */ IDL_VPTR get_num_layers(int argc, IDL_VPTR pArgv[], char* pArgk) { typedef struct { IDL_KW_RESULT_FIRST_FIELD; int windowExists; IDL_STRING windowName; } KW_RESULT; //IDL_KW_FAST_SCAN is the type of scan we are using, following it is the //name of the keyword, followed by the type, the mask(which should be 1), //flags, a boolean whether the value was populated and finally the value itself static IDL_KW_PAR kw_pars[] = { IDL_KW_FAST_SCAN, {"WINDOW", IDL_TYP_STRING, 1, 0, reinterpret_cast<int*>(IDL_KW_OFFSETOF(windowExists)), reinterpret_cast<char*>(IDL_KW_OFFSETOF(windowName))}, {NULL} }; IdlFunctions::IdlKwResource<KW_RESULT> kw(argc, pArgv, pArgk, kw_pars, 0, 1); std::string windowName; int layers = 0; if (kw->windowExists) { windowName = IDL_STRING_STR(&kw->windowName); } SpatialDataView* pView = dynamic_cast<SpatialDataView*>(IdlFunctions::getViewByWindowName(windowName)); if (pView != NULL) { LayerList* pList = pView->getLayerList(); if (pList != NULL) { layers = pList->getNumLayers(); } } return IDL_GettmpInt(layers); }
IDL_VPTR rdObjmask(int argc, IDL_VPTR *argv, char *argk) { /* the desired atlas image. */ ATLAS_IMAGE *ai; /* The fits file */ FITS *fits; char *atlasFileName; // The input file name IDL_VPTR idlistVptr; // optional idlist input keyword IDL_MEMINT* idlist; IDL_MEMINT nid=0; int idiscopy=0; IDL_MEMINT nrows=0; // actual number of rows in file IDL_MEMINT i=0, j=0; IDL_VPTR result; // The result and temporary copies char* resptr; char* rowptr; char* elptr; IDL_LONG elval; int elsize; // Structure definition void* sdef; // offsets structure offsetstruct os; // First make sure IDL_LONG is 4-byte int elsize=sizeof(IDL_LONG); if (elsize != 4) { IDL_Message(IDL_M_NAMED_GENERIC, IDL_MSG_LONGJMP, "sizeof(IDL_LONG) must be 4"); } /* Get the keywords */ (void) IDL_KWProcessByOffset(argc, argv, argk, kw_pars, (IDL_VPTR *) 0, 1, &kw); /* Check arguments */ if (nParams(argc) < 1) { IDL_Message(IDL_M_NAMED_GENERIC, IDL_MSG_INFO, "Syntax: struct = rdObjmask(atlasFile, idlist=, status=)"); setStatus(FAILURE); return(IDL_GettmpInt(-1)); } /* get file name and open fits file */ atlasFileName = getFileNameVal(argv[0]); if((fits = open_fits_table(atlasFileName, 1)) == NULL) { /* Memory is cleaned up in open_fits_table() */ setStatus(FAILURE); return(IDL_GettmpInt(-1)); } nrows = fits->naxis2; // See if idlist was sent, else generate a list of all if (kw.idlist_there) { /* make sure it is a MEMINT. Copy if needed */ idlistVptr = getAsMEMINT(argv[1], &idiscopy); IDL_VarGetData(idlistVptr, &nid, (char **) &idlist, IDL_TRUE); } else { idiscopy=1; nid=nrows; idlist = (IDL_MEMINT *) calloc(nrows, sizeof(IDL_MEMINT)); for (i=1;i<=nrows;i++) idlist[i-1] = i; } /* structure definition and create output */ sdef = IDL_MakeStruct(0, stags); resptr = IDL_MakeTempStructVector(sdef, nid, &result, IDL_TRUE); os = GetOffsets(sdef); /* Copy in the info */ for (i=0;i<nid;i++) { // Point to the appropriate row in output data rowptr = (char *) result->value.s.arr->data + i*( result->value.arr->elt_len ); // Copy id. Do it here since if the object has no atlas image // it wouldn't be copied elval = (IDL_LONG) idlist[i]; elptr = rowptr + os.id; memcpy(elptr, &elval, elsize); // Read the atlas image ai = read_atlas_image(fits, (int) idlist[i]); // In what follows, copy -1 if the ai is invalid if (ai != NULL) { // Copy run elval = (IDL_LONG) ai->run; elptr = rowptr + os.run; memcpy(elptr, &elval, elsize); // Copy rerun elval = (IDL_LONG) ai->rerun; elptr = rowptr + os.rerun; memcpy(elptr, &elval, elsize); // Copy camcol elval = (IDL_LONG) ai->camCol; elptr = rowptr + os.camcol; memcpy(elptr, &elval, elsize); // Copy field elval = (IDL_LONG) ai->field; elptr = rowptr + os.field; memcpy(elptr, &elval, elsize); // Copy id //elval = (IDL_LONG) ai->id; //elptr = rowptr + os.id; //memcpy(elptr, &elval, elsize); // Copy parent elval = (IDL_LONG) ai->parent; elptr = rowptr + os.parent; memcpy(elptr, &elval, elsize); // copy row0 elptr = rowptr + os.row0; for (j=0;j<5;j++) { if (ai->id > 0) elval = (IDL_LONG) (ai->master_mask->rmin + ai->drow[j]); else elval=-1; memcpy(elptr, &elval, elsize); elptr+=elsize; } // copy col0 elptr = rowptr + os.col0; for (j=0;j<5;j++) { if (ai->id > 0) elval = (IDL_LONG) (ai->master_mask->cmin + ai->dcol[j]); else elval=-1; memcpy(elptr, &elval, elsize); elptr+=elsize; } // copy rowmax elptr = rowptr + os.rowmax; for (j=0;j<5;j++) { if (ai->id > 0) elval = (IDL_LONG) (ai->master_mask->rmax + ai->drow[j]); else elval=-1; memcpy(elptr, &elval, elsize); elptr+=elsize; } // copy colmax elptr = rowptr + os.colmax; for (j=0;j<5;j++) { if (ai->id > 0) elval = (IDL_LONG) (ai->master_mask->cmax + ai->dcol[j]); else elval=-1; memcpy(elptr, &elval, elsize); elptr+=elsize; } // copy drow elptr = rowptr + os.drow; for (j=0;j<5;j++) { if (ai->id > 0) elval = (IDL_LONG) (ai->drow[j]); else elval = -1; memcpy(elptr, &elval, elsize); elptr+=elsize; } // copy dcol elptr = rowptr + os.dcol; for (j=0;j<5;j++) { if (ai->id > 0) elval = (IDL_LONG) (ai->dcol[j]); else elval = -1; memcpy(elptr, &elval, elsize); elptr+=elsize; } phAtlasImageDel(ai,1); } } /* clean up */ phFitsDel(fits); if (kw.idlist_there & idiscopy) IDL_Deltmp(idlistVptr); else free(idlist); /* Clean up the keyword info */ IDL_KW_FREE; setStatus(SUCCESS); //return(IDL_GettmpInt(-1)); return(result); }