writec.c File Reference

#include <stdio.h>
#include <string.h>
#include "machine.h"
#include "sciprint.h"

Include dependency graph for writec.c:

Go to the source code of this file.

Functions

int C2F (cvstr)


Function Documentation

int C2F ( cvstr   ) 

Definition at line 7 of file writec.c.

References buffer, cvstr(), F2C(), fd, i, job, long, mput2(), sciprint(), and str.

00018                       : file name length
00019      ipar[2:4] = fmt  : numbers type ascii code
00020      ipar[5]   = n : buffer length in number of records
00021      ipar[6]   = swap
00022      ipar[7:6+lfil] = character codes for file name
00023      */
00024 {
00025   char str[100],type[4];
00026   int job = 1,three=3;
00027   FILE *fd;
00028   int n, k,/* m,*/ i, ierr;
00029   double *buffer,*record;
00030 /*  long offset;*/
00031   
00032 
00033   --ipar;
00034   --z;
00035   fd=(FILE *)(long)z[2];
00036   buffer = (z+3);
00037   ierr=0;
00038   /*
00039     k    : record counter within the buffer
00040   */
00041 
00042   if (*flag==2&&*nevprt>0) { /* add a new record to the buffer */
00043     n    = ipar[5];
00044     k    = (int)z[1];
00045     /* copy current record to output */
00046     record=buffer+(k-1)*(insz[0]);
00047 
00048     for (i=0;i<insz[0];i++)
00049       record[i] = *(inptr[0]+i);
00050     if (k<n) 
00051       z[1] = z[1]+1.0;
00052     else {/* buffer is full write it to the file */
00053       F2C(cvstr)(&three,&(ipar[2]),type,&job,(unsigned long)strlen(type));
00054       for (i=2;i>=0;i--)
00055         if (type[i]!=' ') { type[i+1]='\0';break;}
00056       mput2(fd,ipar[6],buffer,ipar[5]*insz[0],type,&ierr);
00057       if(ierr!=0) {
00058         *flag = -3;
00059         return;
00060       }
00061       z[1] = 1.0;
00062     }
00063   }
00064   else if (*flag==4) {
00065     F2C(cvstr)(&(ipar[1]),&(ipar[7]),str,&job,(unsigned long)strlen(str));
00066     str[ipar[1]] = '\0';
00067     fd = fopen(str,"wb");
00068     if (!fd ) {
00069       sciprint("Could not open the file!\n");
00070       *flag = -3;
00071       return;
00072     }
00073     z[2]=(long)fd;
00074     z[1] = 1.0;
00075   }
00076   else if (*flag==5) {
00077     if(z[2]==0) return;
00078     k    =(int) z[1];
00079     if (k>=1) {/* flush rest of buffer */
00080       F2C(cvstr)(&three,&(ipar[2]),type,&job,(unsigned long)strlen(type));
00081       for (i=2;i>=0;i--)
00082         if (type[i]!=' ') { type[i+1]='\0';break;}
00083       mput2(fd,ipar[6],buffer,(k-1)*insz[0],type,&ierr);
00084       if(ierr!=0) {
00085         *flag = -3;
00086         return;
00087       }
00088     }
00089     fclose(fd);
00090     z[2] = 0.0;
00091   }
00092   return;
00093 }

Here is the call graph for this function:


Generated on Sun Mar 4 16:12:29 2007 for Scilab [trunk] by  doxygen 1.5.1