Exemple #1
0
// cjfeng 01/03/2019
// Putting if2Qfiles into spec_param
// cjfeng 01/04/2019
// Added traj_param
int check_input_files(fin *fin, spec_param *spec_param, w_param *w_param, shift_info *shift_info, int *nframes, traj_param *traj_param, int nbonds) {
  int error = 0;
  int i;
  int if2Qfiles = spec_param->if2Qfiles;
  // Check validity of Hamiltonian file.
  error = check_ham(fin->Ham1Q.fnm, nframes, traj_param, nbonds, w_param->window, spec_param->nthreads);
  if(error) return error;
  // Check isotope shift file
  error = check_shift(shift_info, traj_param->nosc);
  if(error) return error;
  // Checking the consistency between Hamiltonian file and site energy file.
  error = check_sites(fin->Sites.fnm, fin->Ham1Q.fnm, traj_param->nosc, *nframes);
  if(error) return error;
  // Checking the consistency between Hamiltonian file and dipole moment files.
  for(i=0; i<3; i++) {
    error = check_dipole(fin->Dip1Q[i].fnm, fin->Ham1Q.fnm, traj_param->nosc, *nframes);
    if(error) return error;
  }
  // 2Q parts
  if(if2Qfiles) {
    error = check_ham2Q(fin->Ham2Q.fnm, nframes, traj_param, nbonds, w_param->win2d, spec_param->nthreads);
    if(error) return error;
    for(i=0; i<3; i++) {
      error = check_dip2Q(fin->Dip2Q[i].fnm, fin->Ham2Q.fnm, traj_param->n2Q, *nframes);
      if(error) return error;
    }
  }

  return error;
} 
 virtual void
 run (Arg) 
   {
     check_buildSeq();
     check_prepend ();
     check_shift   ();
     check_split   ();
   }
Exemple #3
0
static void worker_looper(void)
{
    if (shut_down_flag)
    {
        log_vip("worker id: %d, shut down...", settings.worker_id);

        exit(0);
    }

    struct timeval now;
    gettimeofday(&now, NULL);

    dlog_check(NULL, &now);

    static time_t last_check;
    if (settings.shift_table_type != TABLE_NO_SHIFT && now.tv_sec != last_check)
    {
        check_shift(now.tv_sec);

        last_check = now.tv_sec;
    }

    static time_t last_log_min;
    time_t curr_min = now.tv_sec / 60;
    if (curr_min != last_log_min)
    {
        if (last_log_min != 0)
        {
            log_info("worker %d: insert succ: %d, fail: %d, other succ: %d, fail: %d", \
                    settings.worker_id, insert_db_succ_count, insert_db_fail_count, \
                    exec_sql_succ_count, exec_sql_fail_count);

            insert_db_succ_count = 0;
            insert_db_fail_count = 0;
            exec_sql_succ_count  = 0;
            exec_sql_fail_count  = 0;
        }

        last_log_min = curr_min;
    }
}
Exemple #4
0
long read_ALOS_data_SS (FILE *imagefile, FILE *outfile, struct PRM *prm, long *byte_offset, 
                        int *nsub, int *burst_skip, int *num_burst) {

	char *data, *shift_data, *gap_data;
	int	header_size;		/* file header size          720 bytes */
	int	line_prefix_size; 	/* line header size           412 bytes*/
	int     record_length0;		/* data record size start  10788 bytes */
	int	totrecl;		/* total record length	   11200 bytes = line_prefix_size + record_length */
	int	record_length1;		/* data record size curr.  10788 bytes */
	int	line_suffix_size;	/* number of bytes after data 36 bytes */
	int	kswath0=0;		/* subswath at start of file */
	int	skip_swath;             /* number of subswaths to skip to get to desired subswath */
	int	skiprecl;               /* number of lines to skip to get to desired subswath */
	int	data_length;		/* bytes of data			*/
	int     n = 1, ishift, shift, shift0;
	int	k, kburst = 0, totburst = 0;
	int	j, ngap, nlines = 0, ntot;
	int	nprfchange, nburstchange;

	double 	tbias = 0.0, get_clock();
	double  ttot=0.,dt=0.,tgap=0.;		/* total time, burst interval, burst gap, fractional gap */
	settable(12345);

	if (debug) fprintf(stderr,".... reading header \n");

	/* read header information */
	read_sardata_info(imagefile, prm, &header_size, &line_prefix_size);
	assign_sardata_params(prm, line_prefix_size, &line_suffix_size, &record_length0);
	totrecl = line_prefix_size + record_length0;
	set_file_position(imagefile, byte_offset, header_size);

	/* get the sarting burst number and the PRF information for all the bursts and rewind the file */
	for (k=0;k<5;k++) totburst = totburst + n_burst[k];
	for(j = 0; j < totburst; j++) {
		if ( fread((void *) &sdr,sizeof(struct sardata_info), 1, imagefile) !=1 ) break;
		fseek(imagefile, record_length0, SEEK_CUR);
		if (swap) swap_ALOS_data_info(&sdr);
		for (k=0;k<5;k++) {
			if(sdr.n_data_pixels == n_data_burst[k]) {
				PRF[k]=sdr.PRF;
				if(j == 0) kswath0 = k;
			}
		}
	}

        /* get the time interval of a burst  and rewind the file */
	dt = 0.;
	for (k=0;k<5;k++) if(PRF[k] > 0.)  dt = dt + (double)n_burst[k]/(0.001*PRF[k]);
 	tgap = dt - (double)n_burst[*nsub]/(0.001*PRF[*nsub]);
        ngap = (int)(tgap*(0.001*PRF[*nsub])+0.5);
	prm->num_valid_az = 6*(n_burst[*nsub] + ngap);    /* use 6 bursts per aperture */
	rewind(imagefile);
	fseek(imagefile, header_size, SEEK_SET);
	if (verbose) fprintf(stderr," totburst start_busrt# burstcycle_time %d %d %f \n", totburst, kswath0, dt);

	/* set the total number of lines output based on the number of patches requested or default 1000 */
	ntot = *num_burst * (n_burst[*nsub] + ngap);
	if (verbose) fprintf(stderr," dt, tgap, n_burst, ngap ,ntot %f %f %d %d %d %d \n", dt, tgap, n_burst[*nsub], ngap, prm->num_valid_az,ntot);

	/* allocate the memory for data */
	if ((data = (char *) malloc(record_length0)) == NULL) die("couldn't allocate memory for input indata.\n","");
	if ((shift_data = (char *) malloc(record_length0)) == NULL) die("couldn't allocate memory for input indata.\n","");
	if ((gap_data = (char *) malloc(record_length0)) == NULL) die("couldn't allocate memory for input indata.\n","");

	/* seek to beginning of next burst of sub swath nsub, read the line header, reset the parameters, and set the counters */
	skip_swath = ((*nsub +5) - kswath0)%5;
	skiprecl = 0;
	for( k = kswath0; k < kswath0 + skip_swath; k++) skiprecl = skiprecl + n_burst[k%5];
	skiprecl = skiprecl + *burst_skip * totburst;
	if (verbose) fprintf(stderr, " skip_swath skiprecl %d %d \n",skip_swath, skiprecl);
	fseek(imagefile,skiprecl*totrecl, SEEK_CUR);

        /* recalculate the PRF at the new skip location */
	for(j = 0; j < totburst; j++) {
		if ( fread((void *) &sdr,sizeof(struct sardata_info), 1, imagefile) !=1 ) break;
		fseek(imagefile, record_length0, SEEK_CUR);
		if (swap) swap_ALOS_data_info(&sdr);
		for (k=0;k<5;k++) {
			if(sdr.n_data_pixels == n_data_burst[k]) {
				PRF[k]=sdr.PRF;
			}
		}
	}
        /* get the time interval of a burst at the new skip location and rewind the file */
	dt = 0.;
	for (k=0;k<5;k++) if(PRF[k] > 0.)  dt = dt + (double)n_burst[k]/(0.001*PRF[k]);
 	tgap = dt - (double)n_burst[*nsub]/(0.001*PRF[*nsub]);
        ngap = (int)(tgap*(0.001*PRF[*nsub])+0.5);
	prm->num_valid_az = 6*(n_burst[*nsub] + ngap);    /* use 6 bursts per aperture */
	if (verbose) fprintf(stderr," totburst start_busrt# burstcycle_time %d %d %f \n", totburst, kswath0, dt);

	/* rewind and seek again to start in the correct location */
	rewind(imagefile);
	fseek(imagefile, header_size, SEEK_SET);
	fseek(imagefile,skiprecl*totrecl, SEEK_CUR);
	
        /* read the line header and set the parameters for this subswath */
	fread((void *) &sdr,line_prefix_size, 1, imagefile);
	if (swap) swap_ALOS_data_info(&sdr);
        prm->clock_start =  get_clock(sdr, tbias);
        prm->SC_clock_start = ((double) sdr.sensor_acquisition_year)*1000 + prm->clock_start;
	prm->prf = sdr.PRF;
	if(prm->near_range < 0) prm->near_range = sdr.slant_range;
	fseek(imagefile, -1*line_prefix_size, SEEK_CUR);
	n = sdr.sequence_number -1;
	//m = sdr.sequence_number;
	*byte_offset = ftell(imagefile);
	if (verbose) fprintf(stderr," n skiprecl byte_offset %d %d %ld \n", n, skiprecl, *byte_offset);

	/* now start at the beginning but with the intervals known */
	if (verbose) fprintf(stderr,".... reading data (byte %ld) \n",ftell(imagefile));
	shift0 = 0;
  	//m = 0;

	/* read the rest of the file */
	while ( (fread((void *) &sdr,sizeof(struct sardata_info), 1, imagefile)) == 1 ) {
        	n++;
		if (swap) swap_ALOS_data_info(&sdr);

	/* check to make sure there is no prf-change in any of the subswaths */
		for (k=0;k<5;k++) {
			if(sdr.n_data_pixels == n_data_burst[k]) {
          		if ((sdr.PRF) != PRF[k]) {
				PRF[*nsub] = 0.;
			}
			}
		}

		/* detect a different subswath and skip intil the next subswath */
		if(sdr.n_data_pixels == n_data_burst[*nsub]) {

			kburst++;

          		if (sdr.sequence_number != n) printf(" missing line: n, seq# %d %d \n", n, sdr.sequence_number);

			/* check for changes in record_length and PRF */
          		record_length1 = sdr.record_length - line_prefix_size;
          		if (record_length0  != record_length1)  die("record_length changed",""); 

			/* if prf changes exit */
          		if ((sdr.PRF) != PRF[*nsub]) {
				fprintf(stderr," ERROR  PRF changed, oldPRF, newPRF %f %f \n",PRF[*nsub]*.001,sdr.PRF*.001);
				*byte_offset=ftell(imagefile);
				nprfchange = (*byte_offset - header_size)/totrecl;
				nburstchange = nprfchange/totburst;
				fprintf(stderr," rec# burst# %d %d \n",nprfchange,nburstchange);
                                break;
			}

			/* check shift to see if it varies from beginning or from command line value */
			check_shift(prm, &shift, &ishift, &shift0, record_length1);
		
			if ((verbose) && (n/2000.0 == n/2000)) {
				fprintf(stderr," Working on line %d prf %f record length %d slant_range %d \n"
				,sdr.sequence_number, 0.001*sdr.PRF, record_length1, sdr.slant_range);
			}

			/* read data (and trailing bytes) */
          		if ( fread ((char *) data, record_length1, (size_t) 1, imagefile) != 1 ) break;

			data_length = 2*n_data_burst[*nsub];

			/* write line header to output data  */
          		fwrite((void *) &sdr, line_prefix_size, 1, outfile);
			nlines++;

			/* check to see if this is enough data */
			if(nlines >= ntot) break;

			/* Shimada says the first 13 lines are bad.  I only saw 11 bad. shift these lines outside the window */
			if(kburst < 12) ishift = data_length;
			/* ishift and write the data */
			fill_shift_data(shift, ishift, data_length, line_suffix_size, record_length1, data, shift_data, outfile); 

			/* if kburst it equal to the length of this burst then write the appropriate number of zero lines */
			if(kburst == n_burst[*nsub]) {
				ttot = ttot + dt;
				if(verbose) fprintf(stderr," %d %d %f %f %d %f \n",*nsub+1,kburst,dt,tgap,ngap,ttot);
				kburst = 0;
			/* write the appropriate number of zero lines  */
				for(j=0;j<ngap;j++) {
          				fwrite((void *) &sdr, line_prefix_size, 1, outfile);
					nlines++;
				/* set the gap data to 15.5 */
					for (k=0;k<record_length0;k++) gap_data[k]=NULL_DATA+znew%2;
					fwrite((char *) gap_data, record_length1, 1, outfile); 
				}
			}
		}
		else {
			record_length1 = sdr.record_length - line_prefix_size;
			if ( fread ((char *) data, record_length1, (size_t) 1, imagefile) != 1 ) break;
		}
	}
      
	/* calculate end time and fix prf */
	prm->prf = 0.001*PRF[*nsub];

        prm->clock_stop =  get_clock(sdr, tbias);
        prm->SC_clock_stop = ((double) sdr.sensor_acquisition_year)*1000 + prm->clock_stop;

	/* m is non-zero only in the event of a prf change */
	prm->num_lines = nlines-1;
	prm->num_patches = (int)((1.0*prm->num_lines)/(1.0*prm->num_valid_az));
	if (prm->num_lines == 0) prm->num_lines = 1;

	if (verbose) print_params(prm); 

	free(data);
	free(shift_data);
	fclose (outfile);

	return(*byte_offset);
}