/************************************************************************* * * (c) Copyright 1992,1993,1994 by G & A Technical Software, Inc., * 28 Research Drive, Hampton, Virginia, 23666. * * All Rights Reserved. No part of this software or publication may be * reproduced, stored in a retrieval system, or transmitted, in any form * or by any means, electronic, mechanical, photocopying, recording, or * otherwise without the prior written permission of G & A Technical * Software, Inc. * ************************************************************************* * * Filename: * * Purpose: * * Author: John Burton * * Date: 5/31/94 * ************************************************************************* * * Modification History: * * $Log: s3_idl_rpc.c,v $ * Revision 2.1 1994/07/08 17:52:21 jcburt * Updated typedefs, defines and function protypes to allow recursive * parsing of pct files. Enabled use of sub-PDT files and scoping of * datasets. Datasets used in a pct must be defined either in the * associated pdt file or the pdt file associated with the direct * ancestors of the current pct file. * * DataSet functions and subroutines now have an additional parameter * passed to them, indicating the number of parameters passed in the * dataset list, i.e. was: function(DataSet **dl) * now: function(int nargs, DataSet **dl) * Parameters passed to the dataset routines from the PCT level are all * still contained in the dataset list, nargs is during the function or * subroutine call from s3_exec_enode * * Revision 2.0.0.1 1994/06/28 18:48:27 jcburt * S3 Version 2.0 Initial Source * * ************************************************************************* * * Revision Control Information: */ static char rcsid[] = "$Id: s3_idl_rpc.c,v 2.1 1994/07/08 17:52:21 jcburt Exp $"; static char rcsrev[] = "$Revision: 2.1 $"; /************************************************************************* * * Include Files * *************************************************************************/ #ifdef _HAVE_IDL_RPC #include "s3_defines.h" #include "s3_typedefs.h" #include "s3_globals.h" #include #include #include "export.h" #include "s3_rpc_idl.h" /************************************************************************* * * Defines and Macros * *************************************************************************/ /************************************************************************* * * Global Variables * *************************************************************************/ static CLIENT *idl_client; /************************************************************************* * * Module: * * Description: * * Syntax: * * Inputs: * * Outputs: * * Returns: * * Modules Called: * *************************************************************************/ /**** please read "read_me" file in s3_idl directory ****/ /* void initialize_idl_server(int nargs, DataSet **dl); void send_idl_data_value(DataSet *ds); void send_idl_data_array(DataSet *ds); void send_dataset_to_idl(int nargs, DataSet **dl); void send_command_to_idl(int nargs, DataSet **dl); void shutdown_idl_server(int nargs, DataSet **dl); */ /*** start IDL server and register client ***/ void initialize_idl_server(int nargs, DataSet **dl) { int count; if((idl_client=register_idl_client(0,NULL,NULL)) == NULL) system("idl -server &"); count = 0; while(((idl_client=register_idl_client(0,NULL,NULL))==NULL)&&(count<10)) sleep(3); if (idl_client==NULL) s3_error(LOC,"initialize_idl_server: unable to connect to server"); if(debug) fprintf(fperr,"IDL server ready.\n"); } /*** create varinfo_t vDS from DataSet and send it to IDL server ***/ /* problem sending strings and string arrays. */ void send_idl_data_value(DataSet *ds) { varinfo_t vDS; int okay; dtype d; d = ds->d; bzero(&vDS,sizeof(vDS)); switch (ds->type){ case CONST: okay = v_make_long(&vDS,ds->name,*(d.in)); break; case BYTE: okay = v_make_byte(&vDS,ds->name,*(d.by)); break; case CHAR: okay = v_make_string(&vDS,ds->name,d.ch); break; case STRING: okay = v_make_string(&vDS,ds->name,d.st); break; case INT: okay = v_make_long(&vDS,ds->name,*(d.in)); break; case REAL: okay = v_make_float(&vDS,ds->name,(double)*(d.fl)); break; case DREAL: okay = v_make_double(&vDS,ds->name,*(d.db)); break; case COMP: okay = v_make_complex(&vDS,ds->name,(double)d.co->r,(double)d.co->i); break; case DCOMP: okay = v_make_complex(&vDS,ds->name,d.dc->r,d.dc->i); break; default: s3_internal_error(__FILE__,__LINE__,LOC,"Invalid data type %o",ds->type); } if(!okay) s3_error(LOC,"send_idl_data_value: Unable to allocate memory for idl dataset %s.\n",ds->name); switch (set_idl_variable(idl_client,&vDS)) { case -1: s3_error(LOC,"send_idl_data_value: Bad parameters passed to set_idl_variable for %s",ds->name); break; case 0: s3_error(SYS,"send_idl_data_value: RPC failure for %s",ds->name); break; default: break; } } void send_idl_data_array(DataSet *ds) { varinfo_t vDS; int i,type,size,nelem,length; int okay; long *dlist; bzero(&vDS,sizeof(vDS)); nelem=1; dlist = (long *)xcalloc(ds->NDIMS,sizeof(long)); for (i=0;iNDIMS;i++) { nelem=nelem*ds->dimlist[i]->co.value; dlist[i] = ds->dimlist[i]->co.value; } switch(ds->type) { case CONST: type = TYP_LONG; size = sizeof(int); break; case BYTE: type = TYP_BYTE; size = sizeof(byte); break; case CHAR: case STRING: type = TYP_STRING; size = sizeof(char); break; case INT: type = TYP_LONG; size = sizeof(int); break; case REAL: type = TYP_FLOAT; size = sizeof(float); break; case DREAL: type = TYP_DOUBLE; size = sizeof(double); break; case COMP: case DCOMP: type = TYP_COMPLEX; size = sizeof(complex); break; default: s3_internal_error(__FILE__,__LINE__,LOC,"Invalid data type %o",ds->type); break; } length=nelem*size; if (!v_fill_array (&vDS,ds->name,type,ds->NDIMS,dlist,ds->d.data,length)) s3_error(LOC,"send_idl_data_array: Unable to allocate memory for idl array %s.\n",ds->name); switch (set_idl_variable(idl_client,&vDS)) { case -1: s3_error(LOC,"send_idl_data_value: Bad parameters passed to set_idl_variable for %s",ds->name); break; case 0: s3_error(SYS,"send_idl_data_value: RPC failure for %s",ds->name); break; default: break; } } /*** send multiple datasets by first specifying number of datasets ** eg. a:DS:send_data :3,var1,var2,var3; ** b:DS:send_data :1,var4; */ void send_dataset_to_idl(int nargs, DataSet **dl) { int i; for (i=0;iNDIMS == 0) send_idl_data_value(dl[i]); else send_idl_data_array(dl[i]); } } /*** Send multiple commands by first specifying number of commands ** eg. a:DS:send_commands :3,command1,command2,command3; ** b:DS:send_commands :1,command4; */ void send_command_to_idl(int nargs, DataSet **dl) { int i; int rtn; for (i=0;id.ch); switch(rtn) { case -1: s3_error(SYS,"send_command_to_idl: RPC failure"); break; case 0: s3_error(LOC,"send_command_to_idl: Command %s is NULL",dl[i]->d.ch); break; case 1: break; default: s3_error(SYS,"send_command_to_idl: Unknown error #%d",rtn); break; } } } /*** unregisters client and kills IDL server ***/ /* problem: gives error message when kills server. */ void idl_kill_server() { if(idl_client!=NULL) sleep(4); /* pause to look at plot, if applicable. */ if (kill_server(idl_client)==0) printf("kill_server:failed to kill server.\n"); unregister_idl_client(idl_client); } void idl_unregister() { unregister_idl_client(idl_client); } void shutdown_idl_server(int nargs, DataSet **dl) { idl_kill_server(); idl_unregister(); } #endif