/* Harp Scan functions V. Kakoyan 15 Sep 2014 */ #include #include #include #include #include #include #include #include #include #include /*#include "Harp.h" */ int nPosition; double x_pos,x_start,x_step,x_end; long N_p; char fName1[256]; char fName2[256]; char fName3[256]; char fName[256]; char todayDate[50]="13Sep2014"; time_t sec_all; static long HarpAsubInit(aSubRecord *prec) { /* if (HarpDebug)*/ printf(" Record %s called HarpAsubInit(%p)\n", prec->name, (void*) prec); return 0; } static long HarpAsubProcess(aSubRecord *prec) { FILE * fp; long i1; double *a,*b,*c,*d,*e,*f,*g,*h; double *i,*j,*k,*l,*m,*n,*o,*p; double *r,*s,*t; long *u; char *q; a=(double *)prec->a; b=(double *)prec->b; c=(double *)prec->c; d=(double *)prec->d; e=(double *)prec->e; f=(double *)prec->f; g=(double *)prec->g; h=(double *)prec->h; i=(double *)prec->i; j=(double *)prec->j; k=(double *)prec->k; l=(double *)prec->l; m=(double *)prec->m; n=(double *)prec->n; o=(double *)prec->o; p=(double *)prec->p; /* r-start pulses s-end pulses t-step u: 1- asub1; 2-asub2 q: fileName */ r=(double *)prec->r; s=(double *)prec->s; t=(double *)prec->t; u=(long *)prec->u; q=(char *)prec->q; /*printf("%s::%s::%d\n",__FILE__,__FUNCTION__,__LINE__); */ if(u[0]==1){ N_p=prec->noa; x_start=r[0]; x_step=t[0]; x_end=s[0]; if (fabs(s[0]-r[0])/t[0]noa) N_p=floor(fabs(s[0]-r[0])/t[0])+1; nPosition=N_p; /* printf("**aSub1** q size= %d\n",sizeof(q)); */ for (i1=0;i1<256;i1++){ fName1[i1]=q[i1]; } /* printf("**aSub1** file name is: %s\n",q); */ if((fp=fopen(fName1, "w")) == NULL) { printf("aSub1: Cannot open file %s\n",fName1); return 1; } } if(u[0]==2){ char *r; r=(char *)prec->r; for (i1=0;i1<256;i1++){ fName2[i1]=q[i1]; fName3[i1]=r[i1]; } /* printf("**aSub2** file name is: %s\n",fName2); */ if((fp=fopen(fName2, "w")) == NULL) { printf("aSub2: Cannot open file %s\n",fName2); return 1; } } printf("HarpAsubProcess: start= %lf step= %lf end= %lf N_of_scanPositions= %ld aSub= %ld\n",x_start,x_step,x_end,N_p,u[0]); for (i1=0;i1name, (void*) prec); return 0; } static long HarpSubProcess(subRecord *prec) { long i,n; double pos; double a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16; double b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16; FILE * fp1; FILE * fp2; FILE * fp3; sec_all = time(NULL); /* printf ("Number of hours since January 1, 1970 is %ld \n", sec_all/3600); int Run=sec; sprintf(fName,"HarpScanResults/harp%d.out",Run); printf("**1111**Sub* file name is: %s\n",fName); printf ( "The current local time: %s", ctime(&sec_all)); sprintf(fName,"HarpScanResults/harp%s.out",ctime(&sec_all)); printf("**2222**Sub* file name is: %s\n",fName); */ sprintf(todayDate,"%s",ctime(&sec_all)); /* printf("---- Today is: %s\n",todayDate); */ char* token; char* string; char *arrr[100]; char *day,*month,*year1,*time,*hour,*minute,*sec,*us; char year[4]; int a=(int)prec->a; int b=(int)prec->b; int c=(int)prec->c; double d=(double)prec->d; string = strdup(todayDate); if (string != NULL) { i=0; while ((token = strsep(&string, " ")) != NULL) { arrr[i]=token; i+=1; } /* day has 2numbers (>9) format of date is Wed-Sep-12-13:54:22-2014 (where - is probel) after strsep command there are 5 fields*/ if(i==5){ day=strdup(arrr[2]); month=strdup(arrr[1]); year1=strdup(arrr[4]); time=strdup(arrr[3]); } /* day has 1 numbers (<10) format of date is Wed-Sep--8-13:54:22-2014 (where - is probel) after strsep command there are 6 fields 3-rd field is empty (-) */ if(i==6){ day=strdup(arrr[3]); month=strdup(arrr[1]); year1=strdup(arrr[5]); time=strdup(arrr[4]); } us=strdup("_"); } /* remove last simbol (enter) after yare */ for(i = 0; i < strlen(year1)-1;i++){ year[i]=year1[i]; } year[i]= '\0'; /* separation of time hour:minute:sec */ string = strdup(time); if (string != NULL) { i=0; while ((token = strsep(&string, ":")) != NULL) { arrr[i]=token; i+=1; } hour=strdup(arrr[0]); minute=strdup(arrr[1]); sec=strdup(arrr[2]); } sprintf(todayDate,"%s%s%s%s%s%s%s%s%s%s%s%s",us,month,us,day,us,year,us,hour,us,minute,us,sec); sprintf(fName,"/gluex/data/HarpScans/%s%s.out",fName3,todayDate); /*printf("** Sub* file name is: %s\n",fName); */ if((fp1=fopen(fName1, "r")) == NULL) { printf("Sub: Cannot open file: %s.\n",fName1); return 1; } if((fp2=fopen(fName2, "r")) == NULL) { printf("Sub: Cannot open file: %s.\n",fName2); return 1; } if((fp3=fopen(fName, "w")) == NULL) { printf("Sub: Cannot open file: %s\n",fName); return 1; } /* Additional parameters*/ /* fprintf(fp3,"# Parameters are:\n"); fprintf(fp3,"# a=%d \n",a); fprintf(fp3,"# b=%d \n",b); fprintf(fp3,"# c=%d \n",c); fprintf(fp3,"# d=%f \n",d); printf("** Sub* parameters are: a=%d b=%d c=%d d=%f\n",a, b,c,d); */ printf("+++++ HarpSubProcess: N_position %d\n",nPosition); for (i=0;i