#include #include #include #include #include #include #include "xgdatamacros.h" extern void XGWrite(void *ptr, int size, int nitems, FILE * stream, char *type); /*void Bin_TwoD_Window(WindowType theWindow, char *filename, char *type) */ // Function BXG_Write_2D() {{{ void BXG_Write_2D(DataType theData, LabelType theLabel, StructType *structs, char *filename, char type, double *theTimeStep) { FILE *fp; /*DataType theData = theWindow->data; LabelType theLabel= theWindow->label;*/ int i,n; double xscale, yscale; float theTime; char *buf; xscale = theLabel->X_Scale; yscale = theLabel->Y_Scale; buf = (char *) malloc(strlen(filename) * sizeof(char)); strcpy(buf,filename); sprintf(buf + strlen(buf) -3, "%s", "num"); if ((fp = fopen(buf,"r"))==NULL) { if ((fp = fopen(buf,"w")) == NULL) { fprintf(stderr, "Error, cannot open %s", buf); free(buf); return; } n=0; fprintf(fp,"1"); fclose(fp); /* write the first file count */ } else { fscanf(fp, "%d", &n); n+=1; fclose(fp); fp=fopen(buf, "w"); fprintf(fp, "%d", n); fclose(fp); } free(buf); fp = fopen(filename,"a"); /* always append */ if (fp == NULL) { printf("Bin_TwoD_Window couldn't create file\n"); return; } theTime = *theTimeStep; /* tag the file */ XGWriteStructures(structs,filename); i = LINE_PLOT; if (Is_Scatter(theData)) i = SCATTER_PLOT; XGWrite(&i, sizeof(int), 1, fp, "int"); XGWriteLabel(theLabel, fp); XGWrite(&theTime,sizeof(float), 1, fp, "float"); while (theData) { // float theTime; n = *(theData->npoints); /*fprintf(fp,"\n##### time= %g \n", *theTimeStep);*/ XGWrite(&n,sizeof(int), 1, fp, "int"); i = theData->color; XGWrite(&i,sizeof(int), 1, fp, "int"); for (i = 0; i < n; i++) { float x,y; x = xscale * CurveX(theData,i); y = yscale * CurveY(theData,i); XGWrite(&x,sizeof(float), 1, fp, "float"); XGWrite(&y,sizeof(float), 1, fp, "float"); } theData = theData->next; } /* the EOF mark of the data set */ n=-1; XGWrite(&n,sizeof(int), 1, fp, "int"); XGWrite(&n,sizeof(int), 1, fp, "int"); fclose(fp); } // }}} // Function BXG_Write_3D() {{{ /*void Bin_ThreeD_Window(WindowType theWindow, char *filename, char type) */ void BXG_Write_3D(DataType theData, LabelType theLabel, char *filename, char type, double *theTimeStep) { FILE *fp; /* DataType theData = theWindow->data; LabelType theLabel= theWindow->label;*/ int i,j,m,n; char *buf; double xscale, yscale, zscale; float x,y,z, theTime; xscale = theLabel->X_Scale; yscale = theLabel->Y_Scale; zscale = theLabel->Z_Scale; buf = (char *) malloc(strlen(filename) * sizeof(char)); strcpy(buf,filename); sprintf(buf + strlen(buf) - 3, "%s", "num"); if ((fp = fopen(buf,"r"))==NULL) { if ((fp = fopen(buf,"w")) == NULL) { fprintf(stderr,"Error, cannot open %s",buf); free(buf); return; } n=0; fprintf(fp,"1"); fclose(fp); /* write the first file count */ } else { fscanf(fp,"%d",&n); n+=1; fclose(fp); fp=fopen(buf,"w"); fprintf(fp,"%d",n); fclose(fp); } free(buf); fp = fopen(filename,"a"); if (fp == NULL) { printf("Bin_ThreeD_Window couldn't create file\n"); return; } /*fprintf(fp,"\n##### time= %g \n", *theTimeStep);*/ theTime = *theTimeStep; n = *(theData->npoints); if (Is_Scatter(theData)) { i = SCATTER3D; XGWrite(&i,sizeof(int),1,fp,"int"); XGWriteLabel(theLabel,fp); XGWrite(&theTime,sizeof(float),1,fp,"float"); XGWrite(&n,sizeof(int),1,fp,"int"); for (i=0;impoints); if (Is_Irr_Surf(theData)) { i = IRREGULAR3D; XGWrite(&i,sizeof(int),1,fp,"int"); XGWriteLabel(theLabel,fp); XGWrite(&theTime,sizeof(float),1,fp,"float"); XGWrite(&n,sizeof(int),1,fp,"int"); XGWrite(&m,sizeof(int),1,fp,"int"); for (i=0;idata; */ int i,j,m,n; float x,y,w,z; float theTime; char *buf; buf = (char *) malloc(strlen(filename) * sizeof(char)); strcpy(buf,filename); sprintf(buf + strlen(filename) - 3, "%s", "num"); if ((fp = fopen(buf,"r"))==NULL) { if ((fp = fopen(buf,"w")) == NULL) { fprintf(stderr,"Error, cannot open %s",buf); free(buf); return; } n=0; fprintf(fp,"1"); fclose(fp); /* write the first file count */ } else { fscanf(fp,"%d",&n); n+=1; fclose(fp); fp=fopen(buf,"w"); fprintf(fp,"%d",n); fclose(fp); } free(buf); fp = fopen(filename,"a"); if (fp == NULL) { printf("Bin_Vector_Window couldn't create file\n"); return; } m = *(theData->mpoints); n = *(theData->npoints); XGWriteStructures(structs,filename); i = VECTOR_PLOT; theTime = *theTimeStep; XGWrite(&i,sizeof(int),1,fp,"int"); XGWriteLabel(theLabel,fp); XGWrite(&theTime,sizeof(float),1,fp,"float"); XGWrite(&n,sizeof(int),1,fp,"int"); XGWrite(&m,sizeof(int),1,fp,"int"); for (i=0;iX_Label) { l = strlen(theLabel->X_Label); XGWrite(&l,sizeof(int),1,fp,"int"); XGWrite(theLabel->X_Label,sizeof(char),l+1,fp,"char"); } else { l=0; XGWrite(&l,sizeof(int),1,fp,"int"); } if (theLabel->Y_Label) { l = strlen(theLabel->Y_Label); XGWrite(&l,sizeof(int),1,fp,"int"); XGWrite(theLabel->Y_Label,sizeof(char),l+1,fp,"char"); } else { l=0; XGWrite(&l,sizeof(int),1,fp,"int"); } if (theLabel->Z_Label) { l = strlen(theLabel->Z_Label); XGWrite(&l,sizeof(int),1,fp,"int"); XGWrite(theLabel->Z_Label,sizeof(char),l+1,fp,"char"); } else { l=0; XGWrite(&l,sizeof(int),1,fp,"int"); } scale = theLabel->X_Scale; min = theLabel->X_Min; max = theLabel->X_Max; l = theLabel->X_Auto_Rescale; XGWrite(&scale,sizeof(float),1,fp,"float"); XGWrite(&min,sizeof(float),1,fp,"float"); XGWrite(&max,sizeof(float),1,fp,"float"); XGWrite(&l,sizeof(int),1,fp,"int"); scale = theLabel->Y_Scale; min = theLabel->Y_Min; max = theLabel->Y_Max; l = theLabel->Y_Auto_Rescale; XGWrite(&scale,sizeof(float),1,fp,"float"); XGWrite(&min,sizeof(float),1,fp,"float"); XGWrite(&max,sizeof(float),1,fp,"float"); XGWrite(&l,sizeof(int),1,fp,"int"); scale = theLabel->Z_Scale; min = theLabel->Z_Min; max = theLabel->Z_Max; l = theLabel->Z_Auto_Rescale; XGWrite(&scale,sizeof(float),1,fp,"float"); XGWrite(&min,sizeof(float),1,fp,"float"); XGWrite(&max,sizeof(float),1,fp,"float"); XGWrite(&l,sizeof(int),1,fp,"int"); } // }}} // Function XGWriteStructures() {{{ void XGWriteStructures(StructType *s, char *filename) { FILE *fp; char *buf; int l; float temp; char *dest; /* no structures */ if (!s) return; /* alocate memeory to buf + (strlen(".str") - 1) */ buf = (char *) malloc((strlen(filename) + 3) * sizeof(char)); strcpy(buf,filename); if ((dest=strstr(buf,"_"))) /* if an underscore is found in the filename*/ { sprintf(dest,".str"); } else sprintf(buf + strlen(buf) - 3, "%s", "str"); /* if there's already a struct file return: we don't need to redo it. */ if ((fp=fopen(buf,"r"))) { fclose(fp); free(buf); return; } if ((fp=fopen(buf,"w"))==NULL) { fprintf(stderr,"\nError: cannot open file %s\n",buf); free(buf); return; } free(buf); while (s) { XGWrite(&(s->numberPoints),sizeof(int),1,fp,"int"); l = s->fillFlag; XGWrite(&l,sizeof(int),1,fp,"int"); XGWrite(&(s->lineColor),sizeof(int),1,fp,"int"); XGWrite(&(s->fillColor),sizeof(int),1,fp,"int"); for (l=0;lnumberPoints;l++) { temp = s->x[l]; XGWrite(&temp,sizeof(float),1,fp,"float"); temp = s->y[l]; XGWrite(&temp,sizeof(float),1,fp,"float"); } s=s->next; } l = -1; XGWrite(&l,sizeof(int),1,fp,"int");/* the end marker */ fclose(fp); } // }}} // Modeline for ViM {{{1 // vim:set ts=4: // vim600:fdm=marker fdl=0 fdc=3: // 1}}}