readau.c File Reference

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

Include dependency graph for readau.c:

Go to the source code of this file.

Functions

int C2F (cvstr)


Function Documentation

int C2F ( cvstr   ) 

Definition at line 7 of file readau.c.

References buffer, cvstr(), f(), F2C(), fd, i, irep, job, long, m, mget2(), offset, sciprint(), str, and y.

00013                       : file name length
00014      ipar[2:4] = fmt  : numbers type ascii code
00015      ipar[5]   = void
00016      ipar[6]   = n : buffer length in number of records
00017      ipar[7]   = maxvoie : record size
00018      ipar[8]   = swap
00019      ipar[9]   = first : first record to read
00020      ipar[10:9+lfil] = character codes for file name
00021      */
00022 integer *flag,*nevprt,*nx,*nz,*ntvec,*nrpar,ipar[],*nipar;
00023 integer insz[],*nin,outsz[],*nout;
00024 double x[],xd[],z[],tvec[],rpar[];
00025 double *inptr[],*outptr[],*t;
00026 
00027 {
00028   char str[100],type[4];
00029   int job = 1,three=3;
00030   FILE *fd;
00031   int n, k, kmax, /*no, lfil,*/ m, i, irep,/* nm,*/ ierr;
00032   double *buffer,*record;
00033   long offset;
00034   double y;
00035   /*  div_t divt;*/int quot, rem;
00036   double SCALE=0.000030517578125;
00037   /*  int ETAB[8]={0, 132, 396, 924, 1980, 4092, 8316, 16764}; */
00038   int ETAB[8];
00039   int mu;
00040   int sig;
00041   int e;
00042   int f;
00043 /*  double ff;*/
00044 
00045   ETAB[0]=0; ETAB[1]=132; ETAB[2]= 396; ETAB[3]=924; ETAB[4]=1980;
00046   ETAB[5]=4092; ETAB[6]=8316; ETAB[7]=16764;
00047 
00048   --ipar;
00049   --z;
00050   fd=(FILE *)(long)z[3];
00051   buffer = (z+4);
00052     
00053   /*
00054     k    : record counter within the buffer
00055     kmax :  number of records in the buffer
00056   */
00057 
00058   if (*flag==1) {
00059     n    = ipar[6];
00060     k    = (int)z[1];
00061     /* copy current record to output */
00062     record=buffer+(k-1)*ipar[7];
00063 
00064     for (i=0;i<*nout;i++)
00065       {
00066         mu=(int) record[i];
00067 
00068         mu=255-mu;
00069         if(mu>127)
00070           sig=1;
00071         else
00072           sig=0;
00073         /* comment out for SUNOS SS 8/10/99 
00074         divt=div(mu,16);
00075         e=divt.quot-8*sig+1;
00076         f=divt.rem;
00077         */
00078         quot=mu/16;rem=mu-16*quot;
00079         e=quot-8*sig+1;
00080         f=rem;
00081 
00082         y=ldexp((double)(f),(e+2));
00083         /* ff=(double)(e+2);
00084            y=((double) f) * pow(two, ff); */
00085 
00086         e=ETAB[e-1];
00087 
00088         y=SCALE*(1-2*sig)*(e+y);
00089 
00090         *outptr[i]=y;
00091       }
00092     if (*nevprt>0) {
00093       /*     discrete state */
00094       kmax =(int) z[2];
00095       if (k>=kmax&&kmax==n) {
00096         /*     read a new buffer */
00097         m=ipar[6]*ipar[7];
00098         F2C(cvstr)(&three,&(ipar[2]),type,&job,(unsigned long)strlen(type));
00099         for (i=2;i>=0;i--)
00100           if (type[i]!=' ') { type[i+1]='\0';break;}
00101         ierr=0;
00102         mget2(fd,ipar[8],buffer,m,type,&ierr);
00103         if (ierr>0) {
00104           sciprint("Read error!\n");
00105           fclose(fd);
00106           z[3] = 0.0;
00107           *flag = -1;
00108           return;
00109         }
00110         else if (ierr<0) { /* EOF reached */
00111           kmax=-(ierr+1)/ipar[7];
00112         }
00113         else
00114           kmax=ipar[6];
00115 
00116         z[1] = 1.0;
00117         z[2] = kmax;
00118       }
00119       else if (k<kmax) 
00120         z[1] = z[1]+1.0;
00121     }
00122   }
00123   else if (*flag==4) {
00124     F2C(cvstr)(&(ipar[1]),&(ipar[10]),str,&job,(unsigned long)strlen(str));
00125     str[ipar[1]] = '\0';
00126     fd = fopen(str,"rb");
00127     if (!fd ) {
00128       sciprint("Could not open the file!\n");
00129       *flag = -1;
00130       return;
00131     }
00132     z[3]=(long)fd;
00133     /* skip first records */
00134     if (ipar[9]>1) {
00135       F2C(cvstr)(&three,&(ipar[2]),type,&job,(unsigned long)strlen(type));
00136       for (i=2;i>=0;i--)
00137           if (type[i]!=' ') { type[i+1]='\0';break;}
00138       offset=(ipar[9]-1)*ipar[7]*sizeof(char);
00139       irep = fseek(fd,offset,0) ;
00140       if ( irep != 0 ) 
00141         {
00142           sciprint("Read error\r\n");
00143           *flag = -1;
00144           fclose(fd);
00145           z[3] = 0.0;
00146           return;
00147         }
00148     }
00149     /* read first buffer */
00150     m=ipar[6]*ipar[7];
00151     F2C(cvstr)(&three,&(ipar[2]),type,&job,(unsigned long)strlen(type));
00152     for (i=2;i>=0;i--)
00153           if (type[i]!=' ') { type[i+1]='\0';break;}
00154     mget2(fd,ipar[8],buffer,m,type,&ierr);
00155     if (ierr>0) {
00156       sciprint("Read error!\n");
00157       *flag = -1;
00158       fclose(fd);
00159       z[3] = 0.0;
00160       return;
00161     }
00162     else if (ierr<0) { /* EOF reached */
00163       kmax=-(ierr+1)/ipar[7];
00164     }
00165     else
00166       kmax=ipar[6];
00167 
00168     z[1] = 1.0;
00169     z[2] = kmax;
00170   }
00171   else if (*flag==5) {
00172     if(z[3]==0) return;
00173     fclose(fd);
00174     z[3] = 0.0;
00175   }
00176   return;
00177 }

Here is the call graph for this function:


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