#include "gpextend.h" int NumParams=0; int NumConstants=0; int UserExit(void) { float *p,*c; char *fname; int save; p=GetGPArray("P"); c=GetGPArray("C"); if ((p)&&(c)) { TTYprintf("\np(0)=%f\tNumParams=%i\n", p[0], NumParams); save=1; } else { TTYprintf("ERROR Getting Parameters Array P From Genplot!!!\n"); save=0; } fname=GetGPString("MacroName"); if (fname) { save++; } else { TTYprintf("ERROR: Can't get the macro file name from the variable \"MacroName\"\n"); save=0; } if (save) { if (SaveGPParams(p, c, fname)) { TTYprintf("Current parameters saved in macro: %s\n", fname); } else { TTYprintf("Current parameters not saved!\n"); } } else { TTYprintf("New parameters were NOT saved do to the errors above!\n"); } GVDeallocate("MacroName"); GVDeallocate("FitFunc"); TTYprintf("GENPLOT extension being removed from memory...\n"); return 0; } float *GetGPArray(char *name) { ARRAY *ar; float *p; ARRAY **ptr; int itt; if (GVGetInfo(name, &itt,(void **) &ptr)) /* Get the array from GENPLOT */ { ar=*ptr; p=ar->x; /* Set p=array of floats represented by P() in GENPLOT */ return p; } else { TTYprintf("Error getting array: %s!\n", name); return NULL; } } char *GetGPString(char *name) { ARRAY *ar; ARRAY **ptr; int itt; char *s; if (GVGetInfo(name, &itt, (void **) &ptr)) { ar=*ptr; s=(char *) ar; return s; } else { TTYprintf("Error getting string: %s!\n", name); return NULL; } } void SetNumParams(int x) { NumParams=x; } void SetNumConstants(int x) { NumConstants=x; } /* SaveGPParams: Saves the parameters given by the floating point array p into a GENPLOT macro which has its parameters delimited by /* Begin Parameters ... /* End Parameters This routine will remove all the statements between the delimiters and insert a series of 'let P(x)=yyy.yyy' statements based on the values in the array p. This function should be called by compatible functions in the UserExit function. */ int SaveGPParams(float *p, float *c, char *fname) { FILE *tmpfile; FILE *infile; char tmpstr[1024]; int i=0; tmpfile=fopen("c:\\GPParam.tmp", "w"); infile=fopen(fname, "r"); if (!infile) { TTYprintf("ERROR: Could not find file \"%s\" !\n", fname); return 0; } fgets(tmpstr, 1023, infile); while((strcmp("/* Begin Parameters\n", tmpstr))&&(!feof(infile))) { fprintf(tmpfile, "%s", tmpstr); fgets(tmpstr, 1023, infile); } fprintf(tmpfile, "%s", tmpstr); for (i=0; i