Ejemplo n.º 1
0
static GstFlowReturn
gst_invtelecine_output_fields (GstInvtelecine * invtelecine, int num_fields)
{
  GstBuffer *buffer;
  int field_index;

  field_index = invtelecine->fifo[0].field_index;

  buffer = gst_buffer_new_and_alloc (720 * 480 + 360 * 240 + 360 * 240);

  copy_field (buffer, invtelecine->fifo[0].buffer, field_index);
  copy_field (buffer, invtelecine->fifo[1].buffer, field_index ^ 1);

  gst_buffer_set_caps (buffer, GST_BUFFER_CAPS (invtelecine->fifo[0].buffer));

  GST_BUFFER_TIMESTAMP (buffer) =
      GST_BUFFER_TIMESTAMP (invtelecine->fifo[0].buffer);
  GST_BUFFER_DURATION (buffer) =
      gst_util_uint64_scale (GST_SECOND, num_fields * 1001, 60000);
  if (num_fields == 3) {
    GST_BUFFER_FLAG_SET (buffer, GST_VIDEO_BUFFER_RFF);
  }
  if (num_fields == 1) {
    GST_BUFFER_FLAG_SET (buffer, GST_VIDEO_BUFFER_ONEFIELD);
  }
  if (field_index == 0) {
    GST_BUFFER_FLAG_SET (buffer, GST_VIDEO_BUFFER_TFF);
  }

  return gst_pad_push (invtelecine->srcpad, buffer);
}
Ejemplo n.º 2
0
static void pullup_pack_frame(PullupContext *s, PullupFrame *fr)
{
    int i;

    if (fr->buffer)
        return;

    if (fr->length < 2)
        return; /* FIXME: deal with this */

    for (i = 0; i < 2; i++) {
        if (fr->ofields[i]->lock[i^1])
            continue;

        fr->buffer = fr->ofields[i];
        pullup_lock_buffer(fr->buffer, 2);
        copy_field(s, fr->buffer, fr->ofields[i^1], i^1);
        return;
    }

    fr->buffer = pullup_get_buffer(s, 2);

    copy_field(s, fr->buffer, fr->ofields[0], 0);
    copy_field(s, fr->buffer, fr->ofields[1], 1);
}
Ejemplo n.º 3
0
/*
 * Read the list of file-entries
 */
static void
read_entries(CVS_WORK * cache)
{
    char name[MAXPATHLEN];
    char **list = 0;
    int j, k;

    if ((k = file2argv(admin_filename(name, cache, NAME_LIST), &list)) > 0) {
	cache->Entries = DOALLOC(0, CVS_ENTRY, (size_t) k);
	for (j = k = 0; list[j] != 0; ++j) {
	    char *s = list[j];
	    char *t;

	    cache->Entries[j].filename = 0;
	    cache->Entries[j].version = 0;
	    cache->Entries[j].status = 0;
	    cache->Entries[j].timestamp = 0;

	    if (s[0] == '/' && s[1] != '/') {
		++s;
		cache->Entries[k].filename = copy_field(parse_field(&s));
		cache->Entries[k].version = copy_field(parse_field(&s));
		if ((t = parse_field(&s)) != 0)
		    cache->Entries[k].timestamp = string2time(t);
		cache->Entries[k].status = copy_field(parse_field(&s));
		++k;
	    }
	}
	cache->num_entries = k;
    }
    if (list)
	vecfree(list);
}
Ejemplo n.º 4
0
static void copy_hes_fields( byte const* in, track_info_t* out )
{
	if ( *in >= ' ' )
	{
		in = copy_field( in, out->game );
		in = copy_field( in, out->author );
		in = copy_field( in, out->copyright );
	}
}
Ejemplo n.º 5
0
static byte const* copy_hes_fields( byte const in [], track_info_t* out )
{
	byte const* in_offset = in;
	if ( *in_offset >= ' ' )
	{
		in_offset = copy_field( in_offset, out->game      );
		in_offset = copy_field( in_offset, out->author    );
		in_offset = copy_field( in_offset, out->copyright );
	}
	return in_offset ? in_offset : in;
}
Ejemplo n.º 6
0
/* TODO aconway 2014-05-13: more detailed message representation. */
char* qd_message_repr(qd_message_t *msg, char* buffer, size_t len) {
    qd_message_check(msg, QD_DEPTH_BODY);
    char *begin = buffer;
    char *end = buffer + len - sizeof(REPR_END); /* Save space for ending */
    aprintf(&begin, end, "Message{", msg);
    copy_field(msg, QD_FIELD_TO, INT_MAX, "to='", "'", &begin, end);
    copy_field(msg, QD_FIELD_REPLY_TO, INT_MAX, " reply-to='", "'", &begin, end);
    copy_field(msg, QD_FIELD_BODY, 16, " body='", "'", &begin, end);
    aprintf(&begin, end, "%s", REPR_END);   /* We saved space at the beginning. */
    return buffer;
}
Ejemplo n.º 7
0
Archivo: crlprop.c Proyecto: mphy/crl
//ray addition			(field not used in recent implementation, changing)
int ray_addition(struct c2f* arg, int tag, double dz){
int ret=tag;
double wvl=arg->xray.wavelength;	   //wavelength
int i,j; 				   //counter
int N=arg->field->components;		   //Number of points
double L=arg->crl.aperture;		   //Lens aperure
int pix=arg->detector.number;		   //pixels in detector
double w=arg->detector.width;	           //detector width
double ph;				   //phase
double A;				   //amplitude
double y2;				   //position on detector
double y;				   //position on lens
complex double val;			   //complex value to add intensities

    struct field field;
    field.size=NULL;
    field.values=NULL;
    fprintf(stderr, "warning: using %s.\n", __FUNCTION__);

     field.size = malloc(arg->field->dimensions*sizeof(int));
     field.values = malloc((arg->field->components)*sizeof(complex double)); 
     copy_field(arg->field, &field);
////if (ray_add) printf("ray_add det.width=%fm pix=%d det_delta=%f \n ", w, pix, w/pix); //print

     N=field.components;	//     delta=L/N;     //     deltaf=1./(delta*N);


	for (j=0;j<pix;j++){
	val=0.;
	y2=(-0.5*pix+j)*w/pix;
	      for (i=0;i<N;i++){
	        A=cabs(arg->field->values[i]); 
	        y=((-0.5*N)+i)*L/N;
	        //d=taylor_sqrt_opd((y2-y),dz,5));   //d=sqrt((y1[j]-y)*(y1[j]-y)+dz*dz)-dz;
	        ph=getPhase(wvl,(y2-y),dz);
                //ADDITION
                val=val+A*cexp(I*ph); 

		}//loop on lens points
         arg->detector.intensity[j]=cabs(val)*cabs(val);


         }//loop on detector pix

copy_field(&field, arg->field);
write_intensity_file(arg->detector.intensity, "int.txt", pix, w);

if (field.size)   free(field.size);   field.size=NULL;
if (field.values) free(field.values); field.values=NULL;
return ret;
}
Ejemplo n.º 8
0
void initialize(field * temperature1, field * temperature2,
                parallel_data * parallel)
{
    int i, j;

    // Allocate also ghost layers
    temperature1->data =
        malloc_2d(temperature1->nx + 2, temperature1->ny + 2);
    temperature2->data =
        malloc_2d(temperature2->nx + 2, temperature2->ny + 2);

    // Initialize to zero
    memset(temperature1->data[0], 0.0,
           (temperature1->nx + 2) * (temperature1->ny + 2)
           * sizeof(double));


    for (i = 0; i < temperature1->nx + 2; i++) {
        temperature1->data[i][0] = 85.0;
        temperature1->data[i][temperature1->ny + 1] = 45.0;
    }

    if (parallel->rank == 0) {
        for (j = 0; j < temperature1->ny + 2; j++)
            temperature1->data[0][j] = 5.0;
    } else if (parallel->rank == parallel->size - 1) {
        for (j = 0; j < temperature1->ny + 2; j++)
            temperature1->data[temperature1->nx + 1][j] = 20.0;
    }

    copy_field(temperature1, temperature2);

}
Ejemplo n.º 9
0
/*
 * get_old_fields - parse the old gecos and use the old value for the fields
 *                  which are not set on the command line
 */
static void get_old_fields (const char *gecos)
{
	char *cp;		/* temporary character pointer       */
	char old_gecos[BUFSIZ];	/* buffer for old GECOS fields       */
	STRFCPY (old_gecos, gecos);

	/*
	 * Now get the full name. It is the first comma separated field in
	 * the GECOS field.
	 */
	cp = copy_field (old_gecos, fflg ? (char *) 0 : fullnm, slop);

	/*
	 * Now get the room number. It is the next comma separated field,
	 * if there is indeed one.
	 */
	if (NULL != cp) {
		cp = copy_field (cp, rflg ? (char *) 0 : roomno, slop);
	}

	/*
	 * Now get the work phone number. It is the third field.
	 */
	if (NULL != cp) {
		cp = copy_field (cp, wflg ? (char *) 0 : workph, slop);
	}

	/*
	 * Now get the home phone number. It is the fourth field.
	 */
	if (NULL != cp) {
		cp = copy_field (cp, hflg ? (char *) 0 : homeph, slop);
	}

	/*
	 * Anything left over is "slop".
	 */
	if ((NULL != cp) && !oflg) {
		if ('\0' != slop[0]) {
			strcat (slop, ",");
		}

		strcat (slop, cp);
	}
}
Ejemplo n.º 10
0
static schema_p copy_schema ( schema_p s, const char *dest_name )
{
  if (s == NULL ) return NULL;
  schema_p dest = new_schema (dest_name);
  field_desc_p f = s->first;
  for ( ; f != NULL; f = f->next)
    add_field (dest, copy_field (f));
  return dest;
}
Ejemplo n.º 11
0
void copy_abonent(Abonent* dest, Abonent* src)
{
    dest->id = src->id;
    copy_field(phone_no);
    copy_field(family_name);
    copy_field(name);
    copy_field(middle_name);
    copy_field(street);
    copy_field(house);
    copy_field(building);
    copy_field(flat);
}
Ejemplo n.º 12
0
Archivo: crlprop.c Proyecto: mphy/crl
//get spherical
int get_spherical(struct c2f* arg, int tag, double dz){
    int ret=tag;
    int i;
    double wvl=arg->xray.wavelength;	   //wavelength
    double N=arg->field->components;
    double L=arg->crl.aperture;
    double y;
    double d;
    double A;
    fprintf(stderr, "warning: using %s.\n", __FUNCTION__);

    struct field field;
    field.size=NULL;
    field.values=NULL;

     field.size = malloc(arg->field->dimensions*sizeof(int));
     field.values = malloc((arg->field->components)*sizeof(complex double)); 
     copy_field(arg->field, &field);

	//Gaussian Amplitude
	double sigma=L/3./2.;
        for (i=0;i<N;i++){
        y=(-0.5*N+i)*L/N;
        d=taylor_sqrt_opd(y,dz,5);
        A=exp(-y*y/2./sigma/sigma);


        //field.values[i]=A*cexp(I*((d-dz)*2.*M_PI/wvl));
field.values[i]=A*cexp(I*fmod(d*2.*M_PI/wvl,2.*M_PI));

}
write_field_to_file(&field, "spherical.txt", arg->crl.aperture);

copy_field(&field, arg->field);
if (field.size)   free(field.size);   field.size=NULL;
if (field.values) free(field.values); field.values=NULL;
return ret;
}
Ejemplo n.º 13
0
static int fields_filter_video(TCModuleInstance *self,
                               vframe_list_t *frame)
{
    FieldsPrivateData *pd = NULL;
    uint8_t *f1 = NULL, *f2 = NULL, *b1 = NULL, *b2 = NULL;
    int width, height;

    TC_MODULE_SELF_CHECK(self, "filter");
    TC_MODULE_SELF_CHECK(frame, "filter");

    pd = self->userdata;

    width = frame->v_width * (pd->rgb_mode ? 3 : 1);
    height = frame->v_height;
    f1 = frame->video_buf;
    f2 = frame->video_buf + width;
    b1 = pd->buffer;
    b2 = pd->buffer + width;

    switch (pd->field_ops) {
      case FIELD_OP_FLIP:
        swap_fields(pd->buffer, f1, f2, width, height);
        break;
      case FIELD_OP_SHIFT:
        copy_field(pd->buf_field ? b2 : b1, f2, width, height);
        copy_field(f2, f1, width, height);
        copy_field(f1, pd->buf_field ? b1 : b2, width, height);
        break;
      case FIELD_OP_SHIFTFLIP:
        // Shift + Flip is the same result as just delaying the second field by
        // one frame, so do that because it's faster.
        copy_field(pd->buf_field ? b1 : b2, f2, width, height);
        copy_field(f2, pd->buf_field ? b2 : b1, width, height);
        break;
      case FIELD_OP_FLIPSHIFT:
        // Flip + Shift is the same result as just delaying the first field by
        // one frame, so do that because it's faster.
        copy_field(pd->buf_field ? b1 : b2, f1, width, height);
        copy_field(f1, pd->buf_field ? b2 : b1, width, height);

        // Chroma information is usually taken from the top field, which we're
        // shifting here.  We probably should move the chroma info with it, but
        // this will be used so rarely (and this is only an issue in YUV mode
        // anyway, which is not reccomended to start with) that it's probably not
        // worth bothering.
        break;
    }
    pd->buf_field ^= 1;

    return TC_OK;
}
Ejemplo n.º 14
0
void initialize(field * temperature1, field * temperature2,
                parallel_data * parallel)
{
    int i, j;

    // Allocate also ghost layers
    temperature1->data =
        malloc_2d(temperature1->nx + 2, temperature1->ny + 2);
    temperature2->data =
        malloc_2d(temperature2->nx + 2, temperature2->ny + 2);

    // Create RMA window. In principle, only borders would be needed
    // but it is simpler to expose the whole array
    MPI_Win_create(&temperature1->data[0][0],
                   (temperature1->nx + 2) * (temperature1->ny +
                                             2) * sizeof(double),
                   sizeof(double), MPI_INFO_NULL, parallel->comm,
                   &temperature1->rma_window);
    MPI_Win_create(&temperature2->data[0][0],
                   (temperature2->nx + 2) * (temperature2->ny +
                                             2) * sizeof(double),
                   sizeof(double), MPI_INFO_NULL, parallel->comm,
                   &temperature2->rma_window);

    // Initialize to zero
    memset(temperature1->data[0], 0.0,
           (temperature1->nx + 2) * (temperature1->ny + 2)
           * sizeof(double));


    for (i = 0; i < temperature1->nx + 2; i++) {
        temperature1->data[i][0] = 30.0;
        temperature1->data[i][temperature1->ny + 1] = -10.0;
    }

    if (parallel->rank == 0) {
        for (j = 0; j < temperature1->ny + 2; j++)
            temperature1->data[0][j] = 15.0;
    } else if (parallel->rank == parallel->size - 1) {
        for (j = 0; j < temperature1->ny + 2; j++)
            temperature1->data[temperature1->nx + 1][j] = -25.0;
    }

    copy_field(temperature1, temperature2);

}
Ejemplo n.º 15
0
void initialize(field * temperature1, field * temperature2,
                parallel_data * parallel)
{
    int i, j;

    int dims[2], coords[2], periods[2];

    // Allocate also ghost layers
    temperature1->data =
        malloc_2d(temperature1->nx + 2, temperature1->ny + 2);
    temperature2->data =
        malloc_2d(temperature2->nx + 2, temperature2->ny + 2);

    // Initialize to zero
    memset(temperature1->data[0], 0.0,
           (temperature1->nx + 2) * (temperature1->ny + 2)
           * sizeof(double));

    MPI_Cart_get(parallel->comm, 2, dims, periods, coords);

    // Left boundary
    if (coords[1] == 0)
        for (i = 0; i < temperature1->nx + 2; i++)
            temperature1->data[i][0] = 30.0;

    // Upper boundary
    if (coords[0] == 0)
        for (j = 0; j < temperature1->ny + 2; j++)
            temperature1->data[0][j] = 15.0;

    // Right boundary
    if (coords[1] == dims[1] - 1)
        for (i = 0; i < temperature1->nx + 2; i++)
            temperature1->data[i][temperature1->ny + 1] = -10.0;

    // Lower boundary
    if (coords[0] == dims[0] - 1)
        for (j = 0; j < temperature1->ny + 2; j++)
            temperature1->data[temperature1->nx + 1][j] = -25.0;

    copy_field(temperature1, temperature2);

}
Ejemplo n.º 16
0
static schema_p make_sub_schema ( schema_p s, const char *dest_name,
				  int num_fields, char *fields[] )
{
  if (s == NULL ) return NULL;
  schema_p dest = new_schema (dest_name);
  field_desc_p f = NULL;
  int i = 0;
  for ( i= 0; i < num_fields; i++)
    {
      f = get_field ( s, fields[i] );
      if ( f != NULL)
	add_field (dest, copy_field (f));
      else
	{
	  put_msg (ERROR, "\"%s\" has no \"%s\" field\n",
		   s->name, fields[i]);
	  remove_schema (dest);
	  return NULL;
	}
    }
  return dest;
}
Ejemplo n.º 17
0
void initialize(field * temperature1, field * temperature2)
{
    int i, j;

    // Allocate also ghost layers
    temperature1->data =
        malloc_2d(temperature1->nx + 2, temperature1->ny + 2);
    temperature2->data =
        malloc_2d(temperature2->nx + 2, temperature2->ny + 2);

    for (i = 0; i < temperature1->nx + 2; i++) {
        temperature1->data[i][0] = 30.0;
        temperature1->data[i][temperature1->ny + 1] = -10.0;
    }

    for (j = 0; j < temperature1->ny + 2; j++) {
        temperature1->data[0][j] = 15.0;
        temperature1->data[temperature1->nx + 1][j] = -25.0;
    }

    copy_field(temperature1, temperature2);

}
Ejemplo n.º 18
0
void read_input(field * temperature1, field * temperature2, char *filename)
{
    FILE *fp;
    int nx, ny, i, j;

    fp = fopen(filename, "r");
    // Read the header
    fscanf(fp, "# %d %d \n", &nx, &ny);

    initialize_field_metadata(temperature1, nx, ny);
    initialize_field_metadata(temperature2, nx, ny);

    // Allocate arrays (including ghost layers
    temperature1->data = malloc_2d(nx + 2, ny + 2);
    temperature2->data = malloc_2d(nx + 2, ny + 2);

    // Read the actual data
    for (i = 1; i < nx + 1; i++) {
        for (j = 1; j < ny + 1; j++) {
            fscanf(fp, "%lf", &temperature1->data[i][j]);
        }
    }

    // Set the boundary values
    for (i = 1; i < nx + 1; i++) {
        temperature1->data[i][0] = temperature1->data[i][1];
        temperature1->data[i][ny + 1] = temperature1->data[i][ny];
    }
    for (j = 0; j < ny + 2; j++) {
        temperature1->data[0][j] = temperature1->data[1][j];
        temperature1->data[nx + 1][j] = temperature1->data[nx][j];
    }

    copy_field(temperature1, temperature2);

    fclose(fp);
}
Ejemplo n.º 19
0
Archivo: chfn.c Proyecto: OPSF/uClinux
/*
 * chfn - change a user's password file information
 *
 *	This command controls the GECOS field information in the password
 *	file entry.
 *
 *	The valid options are
 *
 *	-f	full name
 *	-r	room number
 *	-w	work phone number
 *	-h	home phone number
 *	-o	other information (*)
 *
 *	(*) requires root permission to execute.
 */
int main (int argc, char **argv)
{
	char *cp;		/* temporary character pointer       */
	const struct passwd *pw;	/* password file entry               */
	struct passwd pwent;	/* modified password file entry      */
	char old_gecos[BUFSIZ];	/* buffer for old GECOS fields       */
	char new_gecos[BUFSIZ];	/* buffer for new GECOS fields       */
	int flag;		/* flag currently being processed    */
	int fflg = 0;		/* -f - set full name                */
	int rflg = 0;		/* -r - set room number              */
	int wflg = 0;		/* -w - set work phone number        */
	int hflg = 0;		/* -h - set home phone number        */
	int oflg = 0;		/* -o - set other information        */
	char *user;

#ifdef USE_PAM
	pam_handle_t *pamh = NULL;
	struct passwd *pampw;
	int retval;
#endif

	sanitize_env ();
	setlocale (LC_ALL, "");
	bindtextdomain (PACKAGE, LOCALEDIR);
	textdomain (PACKAGE);

	/*
	 * This command behaves different for root and non-root
	 * users.
	 */
	amroot = (getuid () == 0);

	/*
	 * Get the program name. The program name is used as a
	 * prefix to most error messages.
	 */
	Prog = Basename (argv[0]);

	OPENLOG ("chfn");

	/* 
	 * The remaining arguments will be processed one by one and executed
	 * by this command. The name is the last argument if it does not
	 * begin with a "-", otherwise the name is determined from the
	 * environment and must agree with the real UID. Also, the UID will
	 * be checked for any commands which are restricted to root only.
	 */
	while ((flag = getopt (argc, argv, "f:r:w:h:o:")) != EOF) {
		switch (flag) {
		case 'f':
			if (!may_change_field ('f')) {
				fprintf (stderr,
					 _("%s: Permission denied.\n"), Prog);
				exit (E_NOPERM);
			}
			fflg++;
			STRFCPY (fullnm, optarg);
			break;
		case 'h':
			if (!may_change_field ('h')) {
				fprintf (stderr,
					 _("%s: Permission denied.\n"), Prog);
				exit (E_NOPERM);
			}
			hflg++;
			STRFCPY (homeph, optarg);
			break;
		case 'r':
			if (!may_change_field ('r')) {
				fprintf (stderr,
					 _("%s: Permission denied.\n"), Prog);
				exit (E_NOPERM);
			}
			rflg++;
			STRFCPY (roomno, optarg);
			break;
		case 'o':
			if (!amroot) {
				fprintf (stderr,
					 _("%s: Permission denied.\n"), Prog);
				exit (E_NOPERM);
			}
			oflg++;
			STRFCPY (slop, optarg);
			break;
		case 'w':
			if (!may_change_field ('w')) {
				fprintf (stderr,
					 _("%s: Permission denied.\n"), Prog);
				exit (E_NOPERM);
			}
			wflg++;
			STRFCPY (workph, optarg);
			break;
		default:
			usage ();
		}
	}

	/*
	 * Get the name of the user to check. It is either the command line
	 * name, or the name getlogin() returns.
	 */
	if (optind < argc) {
		user = argv[optind];
		pw = getpwnam (user);
		if (!pw) {
			fprintf (stderr, _("%s: unknown user %s\n"), Prog,
				 user);
			exit (E_NOPERM);
		}
	} else {
		pw = get_my_pwent ();
		if (!pw) {
			fprintf (stderr,
				 _
				 ("%s: Cannot determine your user name.\n"),
				 Prog);
			exit (E_NOPERM);
		}
		user = xstrdup (pw->pw_name);
	}

#ifdef	USE_NIS
	/*
	 * Now we make sure this is a LOCAL password entry for this user ...
	 */
	if (__ispwNIS ()) {
		char *nis_domain;
		char *nis_master;

		fprintf (stderr,
			 _("%s: cannot change user `%s' on NIS client.\n"),
			 Prog, user);

		if (!yp_get_default_domain (&nis_domain) &&
		    !yp_master (nis_domain, "passwd.byname", &nis_master)) {
			fprintf (stderr,
				 _
				 ("%s: `%s' is the NIS master for this client.\n"),
				 Prog, nis_master);
		}
		exit (E_NOPERM);
	}
#endif

	/*
	 * Non-privileged users are only allowed to change the gecos field
	 * if the UID of the user matches the current real UID.
	 */
	if (!amroot && pw->pw_uid != getuid ()) {
		fprintf (stderr, _("%s: Permission denied.\n"), Prog);
		closelog ();
		exit (E_NOPERM);
	}
#ifdef WITH_SELINUX
	/*
	 * If the UID of the user does not match the current real UID,
	 * check if the change is allowed by SELinux policy.
	 */
	if ((pw->pw_uid != getuid ())
	    && (selinux_check_passwd_access (PASSWD__CHFN) != 0)) {
		fprintf (stderr, _("%s: Permission denied.\n"), Prog);
		closelog ();
		exit (E_NOPERM);
	}
#endif

#ifndef USE_PAM
	/*
	 * Non-privileged users are optionally authenticated (must enter the
	 * password of the user whose information is being changed) before
	 * any changes can be made. Idea from util-linux chfn/chsh. 
	 * --marekm
	 */
	if (!amroot && getdef_bool ("CHFN_AUTH"))
		passwd_check (pw->pw_name, pw->pw_passwd, "chfn");

#else				/* !USE_PAM */
	retval = PAM_SUCCESS;

	pampw = getpwuid (getuid ());
	if (pampw == NULL) {
		retval = PAM_USER_UNKNOWN;
	}

	if (retval == PAM_SUCCESS) {
		retval = pam_start ("chfn", pampw->pw_name, &conv, &pamh);
	}

	if (retval == PAM_SUCCESS) {
		retval = pam_authenticate (pamh, 0);
		if (retval != PAM_SUCCESS) {
			pam_end (pamh, retval);
		}
	}

	if (retval == PAM_SUCCESS) {
		retval = pam_acct_mgmt (pamh, 0);
		if (retval != PAM_SUCCESS) {
			pam_end (pamh, retval);
		}
	}

	if (retval != PAM_SUCCESS) {
		fprintf (stderr, _("%s: PAM authentication failed\n"), Prog);
		exit (E_NOPERM);
	}
#endif				/* USE_PAM */

	/*
	 * Now get the full name. It is the first comma separated field in
	 * the GECOS field.
	 */
	STRFCPY (old_gecos, pw->pw_gecos);
	cp = copy_field (old_gecos, fflg ? (char *) 0 : fullnm, slop);

	/*
	 * Now get the room number. It is the next comma separated field,
	 * if there is indeed one.
	 */
	if (cp)
		cp = copy_field (cp, rflg ? (char *) 0 : roomno, slop);

	/*
	 * Now get the work phone number. It is the third field.
	 */
	if (cp)
		cp = copy_field (cp, wflg ? (char *) 0 : workph, slop);

	/*
	 * Now get the home phone number. It is the fourth field.
	 */
	if (cp)
		cp = copy_field (cp, hflg ? (char *) 0 : homeph, slop);

	/*
	 * Anything left over is "slop".
	 */
	if (cp && !oflg) {
		if (slop[0])
			strcat (slop, ",");

		strcat (slop, cp);
	}

	/*
	 * If none of the fields were changed from the command line, let the
	 * user interactively change them.
	 */
	if (!fflg && !rflg && !wflg && !hflg && !oflg) {
		printf (_("Changing the user information for %s\n"), user);
		new_fields ();
	}

	/*
	 * Check all of the fields for valid information
	 */
	if (valid_field (fullnm, ":,=")) {
		fprintf (stderr, _("%s: invalid name: \"%s\"\n"), Prog, fullnm);
		closelog ();
		exit (E_NOPERM);
	}
	if (valid_field (roomno, ":,=")) {
		fprintf (stderr, _("%s: invalid room number: \"%s\"\n"),
			 Prog, roomno);
		closelog ();
		exit (E_NOPERM);
	}
	if (valid_field (workph, ":,=")) {
		fprintf (stderr, _("%s: invalid work phone: \"%s\"\n"),
			 Prog, workph);
		closelog ();
		exit (E_NOPERM);
	}
	if (valid_field (homeph, ":,=")) {
		fprintf (stderr, _("%s: invalid home phone: \"%s\"\n"),
			 Prog, homeph);
		closelog ();
		exit (E_NOPERM);
	}
	if (valid_field (slop, ":")) {
		fprintf (stderr,
			 _("%s: \"%s\" contains illegal characters\n"),
			 Prog, slop);
		closelog ();
		exit (E_NOPERM);
	}

	/*
	 * Build the new GECOS field by plastering all the pieces together,
	 * if they will fit ...
	 */
	if (strlen (fullnm) + strlen (roomno) + strlen (workph) +
	    strlen (homeph) + strlen (slop) > (unsigned int) 80) {
		fprintf (stderr, _("%s: fields too long\n"), Prog);
		closelog ();
		exit (E_NOPERM);
	}
	snprintf (new_gecos, sizeof new_gecos, "%s,%s,%s,%s%s%s",
		  fullnm, roomno, workph, homeph, slop[0] ? "," : "", slop);

	/*
	 * Before going any further, raise the ulimit to prevent colliding
	 * into a lowered ulimit, and set the real UID to root to protect
	 * against unexpected signals. Any keyboard signals are set to be
	 * ignored.
	 */
	if (setuid (0)) {
		fprintf (stderr, _("Cannot change ID to root.\n"));
		SYSLOG ((LOG_ERR, "can't setuid(0)"));
		closelog ();
		exit (E_NOPERM);
	}
	pwd_init ();

	/*
	 * The passwd entry is now ready to be committed back to the
	 * password file. Get a lock on the file and open it.
	 */
	if (!pw_lock ()) {
		fprintf (stderr,
			 _
			 ("Cannot lock the password file; try again later.\n"));
		SYSLOG ((LOG_WARN, "can't lock /etc/passwd"));
		closelog ();
		exit (E_NOPERM);
	}
	if (!pw_open (O_RDWR)) {
		fprintf (stderr, _("Cannot open the password file.\n"));
		pw_unlock ();
		SYSLOG ((LOG_ERR, "can't open /etc/passwd"));
		closelog ();
		exit (E_NOPERM);
	}

	/*
	 * Get the entry to update using pw_locate() - we want the real one
	 * from /etc/passwd, not the one from getpwnam() which could contain
	 * the shadow password if (despite the warnings) someone enables
	 * AUTOSHADOW (or SHADOW_COMPAT in libc).  --marekm
	 */
	pw = pw_locate (user);
	if (!pw) {
		pw_unlock ();
		fprintf (stderr,
			 _("%s: %s not found in /etc/passwd\n"), Prog, user);
		exit (E_NOPERM);
	}

	/*
	 * Make a copy of the entry, then change the gecos field. The other
	 * fields remain unchanged.
	 */
	pwent = *pw;
	pwent.pw_gecos = new_gecos;

	/*
	 * Update the passwd file entry. If there is a DBM file, update that
	 * entry as well.
	 */
	if (!pw_update (&pwent)) {
		fprintf (stderr, _("Error updating the password entry.\n"));
		pw_unlock ();
		SYSLOG ((LOG_ERR, "error updating passwd entry"));
		closelog ();
		exit (E_NOPERM);
	}

	/*
	 * Changes have all been made, so commit them and unlock the file.
	 */
	if (!pw_close ()) {
		fprintf (stderr, _("Cannot commit password file changes.\n"));
		pw_unlock ();
		SYSLOG ((LOG_ERR, "can't rewrite /etc/passwd"));
		closelog ();
		exit (E_NOPERM);
	}
	if (!pw_unlock ()) {
		fprintf (stderr, _("Cannot unlock the password file.\n"));
		SYSLOG ((LOG_ERR, "can't unlock /etc/passwd"));
		closelog ();
		exit (E_NOPERM);
	}
	SYSLOG ((LOG_INFO, "changed user `%s' information", user));

	nscd_flush_cache ("passwd");

#ifdef USE_PAM
	if (retval == PAM_SUCCESS)
		pam_end (pamh, PAM_SUCCESS);
#endif				/* USE_PAM */

	closelog ();
	exit (E_SUCCESS);
}
Ejemplo n.º 20
0
Archivo: crlprop.c Proyecto: mphy/crl
/* propagate point-source to CRL device */
int source_to_crl(struct s2c* arg, double L)
{
    int ret = 0;

    complex double* u = NULL;		//array to create field
    int N = Nmin;			//Number of points 
    int n = 1;				//dimensions (components)
    int i;				//counter
    double delta=L/N;		        //discretisation grid space (sampling)
    double posy=0;			//lens plane vertical position(y) from axis, to give an offset
    double dz=arg->source.distance;     //distance z
    double dy=0;			//distance y 
    double A;				//Amplitude
    double ph;           		//phase
    double Re, Im;			//Real and Imaginary components of field
    double wvl=(arg->xray.wavelength);	//wavelength
    char* fnamewrite="entrance_plane.txt";   //file name

    struct field field;
    field.size=NULL;
    field.values=NULL;

    if (arg == NULL)
    {
	fprintf(stderr, "error: arg points to NULL (%s:%d)\n", __FILE__, __LINE__);
	ret = -1;
	goto cleanup;
    }


  /*Delta-N loop, max phase difference - Sets N and delta*/
  //optimizeDelta(&N, &delta, L, wvl, dz, posy);
  N=Nmin; delta=L/N;
  double phdif=fabs(getPhase(wvl,delta*(N/2),dz)-getPhase(wvl,delta*(N/2-1),dz));
  phdif=(phdif<(2.*M_PI-phdif)) ? phdif : 2.*M_PI-phdif; 
  if (phdif>=0.1*M_PI) fprintf(stderr, "warning: Wrong N, delta values phdif=%f \n", phdif);
      
////printf("N=%d  delta=%1.6fμ 	Manually set\n", N, delta*1e6);
//printf("Press 'Enter' to continue: ... "); while ( getchar() != '\n') ; 
   
 
    u = malloc(N*sizeof(complex double)); //dim 1
    if (u == NULL)
    {
	fprintf(stderr, "error: malloc failed (%s:%d) [%s]\n", __FILE__, __LINE__, strerror(errno));
	ret = -1;
	goto cleanup;
    }


	//Gaussian Amplitude
	double sigma=L/3./2.;
    for (i=0;i<N;i++)
    {
        dy=-0.5*L+i*delta+posy;
	ph=getPhase(wvl,dy,dz);

    A=exp(-dy*dy/2./sigma/sigma);

    Re=A*cos(ph);
    Im=A*sin(ph);
    u[i]=Re+I*Im;    
    }

    /* copy u to field; first get some memory */
    field.dimensions = field_dim;
    field.size = malloc(field.dimensions*sizeof(int));

    //Start allocation for s2c
    arg->field->size = malloc(field.dimensions*sizeof(int));


    /* calculate total number of points in all dimensions */
    for (i=0; i<field.dimensions; i++)
    {
	field.size[i] = N;	//as many components as dimensions
	n *= field.size[i];
    }

    /*copy n to field.components and allocate both for field and s2c.field*/ 
    field.components = n;
    field.values = malloc(n*sizeof(complex double));
    arg->field->values = malloc(n*sizeof(complex double));

    /* copy u to field.values */
    for (i=0; i<n;i++){
    field.values[i]=u[i];		
    }

    copy_field(&field, arg->field);

    /* now save the entrance field to a file */
    write_field_to_file(&field, fnamewrite, L);

cleanup:
    if (field.size)   free(field.size);   field.size=NULL;
    if (field.values) free(field.values); field.values=NULL;
    if (u) free(u); u=NULL;
    return ret;
}
Ejemplo n.º 21
0
void read_input(field * temperature1, field * temperature2, char *filename,
                parallel_data * parallel)
{
    FILE *fp;
    int nx, ny, i, j;

    double **full_data;

    int coords[2];
    int ix, jy, p;

    fp = fopen(filename, "r");
    // Read the header
    fscanf(fp, "# %d %d \n", &nx, &ny);

    parallel_initialize(parallel, nx, ny);
    initialize_field_metadata(temperature1, nx, ny, parallel);
    initialize_field_metadata(temperature2, nx, ny, parallel);

    // Allocate arrays (including ghost layers)
    temperature1->data =
        malloc_2d(temperature1->nx + 2, temperature1->ny + 2);
    temperature2->data =
        malloc_2d(temperature2->nx + 2, temperature2->ny + 2);

    if (parallel->rank == 0) {
        // Full array
        full_data = malloc_2d(nx, ny);

        // Read the actual data
        for (i = 0; i < nx; i++) {
            for (j = 0; j < ny; j++) {
                fscanf(fp, "%lf", &full_data[i][j]);
            }
        }
        // Copy to own local array
        for (i = 0; i < temperature1->nx; i++)
            memcpy(&temperature1->data[i + 1][1], full_data[i],
                   temperature1->ny * sizeof(double));
        // Send to other processes
        for (p = 1; p < parallel->size; p++) {
            MPI_Cart_coords(parallel->comm, p, 2, coords);
            ix = coords[0] * temperature1->nx;
            jy = coords[1] * temperature1->ny;
            MPI_Send(&full_data[ix][jy], 1, parallel->subarraytype, p, 44,
                     parallel->comm);
        }
    } else
        // Receive data
        MPI_Recv(&temperature1->data[1][1], 1, parallel->subarraytype, 0,
                 44, parallel->comm, MPI_STATUS_IGNORE);

    // Set the boundary values
    for (i = 0; i < temperature1->nx + 1; i++) {
        temperature1->data[i][0] = temperature1->data[i][1];
        temperature1->data[i][temperature1->ny + 1] =
            temperature1->data[i][temperature1->ny];
    }
    for (j = 0; j < temperature1->ny + 2; j++) {
        temperature1->data[0][j] = temperature1->data[1][j];
        temperature1->data[temperature1->nx + 1][j] =
            temperature1->data[temperature1->nx][j];
    }

    copy_field(temperature1, temperature2);

    if (parallel->rank == 0)
        free_2d(full_data);

    fclose(fp);
}
Ejemplo n.º 22
0
Archivo: crlprop.c Proyecto: mphy/crl
/* parse programm line arguments, set-up parameter, initialise and run the simulation */
int main(int argc, const char* argv[])
{
    int ret = 0;

    double energy_keV, distance1_m, f_m, distance2_m;
    struct parameters parameters;
    //argument structures for funtions and field memory allocation 
    struct s2c s2c; 			s2c.field = malloc(sizeof(struct field));
    struct insidecrl insidecrl; 	insidecrl.field = malloc(sizeof(struct field));
    struct c2f c2f;			c2f.field = malloc(sizeof(struct field));

    int tag = tag_val;           //tag determines whether initially create field or read from file
    int current=0;	         //int used to keep track of the step the simulation goes through (identifying propagation)
    double distance;		 //distance to perform fourier propagation
    char fnameread[20];		 //name of the file to be read
    char fnamewrite[20];	 //name of the file to wite to

    if (argc != 5)
    {
	fprintf(stderr, "usage: %s <energy/keV> <distance1/m> <f/m> <distance2/m>\n", argv[0]);
	ret = -1;
	goto cleanup;
    }

    energy_keV  = atof(argv[1]); /* energy in keV */
    distance1_m = atof(argv[2]); /* distance from point-source to crl device in m */
    f_m         = atof(argv[3]); /* focal distance of individual lens in m */
    distance2_m = atof(argv[4]); /* distance from crl device to detector in m */

    parameters.xray.energy        = energy_keV;
    parameters.xray.wavelength    =   12.398/energy_keV*1e-10; /* conversion factor from keV to angstrom to metre */
    parameters.xray.wavenumber    =    2*M_PI / parameters.xray.wavelength;

    parameters.source.distance    = distance1_m;

    parameters.crl.f              = f_m;
    parameters.crl.aperture       =    1e-3; /* 1 mm */
    parameters.crl.separation     =   10e-6; /* 10 µm */
    parameters.crl.number         =   lenses;
    parameters.crl.deltafactor    =   3.53e-6;
    parameters.crl.R		  =  f_m*2.*M_PI*parameters.crl.deltafactor;

    parameters.detector.distance  = distance2_m;// (40/39 is q for s=40 and f=1);
    parameters.detector.number    = 1;		//to be defined by field propagation
    parameters.detector.width     = 1;		//to be defined by field propagation
//    print_parameters(&parameters, stdout);


    /* If noread then copy parameters to s2c and generate field*/
    if (tag==-1){
    copy_xray(&parameters.xray,   &s2c.xray);
    copy_source(&parameters.source, &s2c.source);
    source_to_crl(&s2c, parameters.crl.aperture);
////    printf("FIRST STEP:  Create field tag=%d \n", tag);
    if (padf) pad_field(s2c.field);
    write_field_to_file(s2c.field, "entrance_plane.txt", parameters.crl.aperture);
    }			

    /* copy parameters to insidecrl structure*/
    copy_xray(&parameters.xray, &insidecrl.xray);
    copy_crl(&parameters.crl, &insidecrl.crl);

    /* copy parameters to c2f structure for the propagation*/
    copy_xray(&insidecrl.xray, &c2f.xray);
    copy_crl(&parameters.crl, &c2f.crl);
    copy_detector(&parameters.detector,&c2f.detector); 

    //Pre-process: Create/read field and allocate memory. Starting point will be after the lens
    //if field is coming from entrance_plane (both generated or read) allocate and execute PREVIOUS phase-shifting 
    if (tag>0){
	sprintf(fnameread,"crl_plane");
	sprintf(fnameread,"%s%d.txt", fnameread, tag);
	read_field_from_file(insidecrl.field, fnameread);
	tag=-1;//CHANGE (fourier propagation)
        } 

	//Get entrance plane field	  
	else{
	   if (tag==-1){	
	    //Getting from field already generated
            insidecrl.field->size = malloc(s2c.field->dimensions*sizeof(int));
            insidecrl.field->values = malloc(s2c.field->components*sizeof(complex double));
            copy_field(s2c.field, insidecrl.field);  
	    }

	    //Reading from entrance_plane
            else if (tag==0){
	    sprintf(fnameread,"entrance_plane");
	    sprintf(fnameread,"%s.txt", fnameread);
	    read_field_from_file(insidecrl.field, fnameread);
	    tag=-1;
 	    }
////        printf("CRL STEP:  Apply phase-shift tag=%d \n", tag);
     	sprintf(fnamewrite,"crl_plane");
	sprintf(fnamewrite,"%s1.txt", fnamewrite);
        crl_inside(&insidecrl, fnamewrite);
	} 

    //Once N is set, get detector parameters
    parameters.detector.number=pix_num; //previously parameters.detector.number=insidecrl.field->components;
//    parameters.detector.width=parameters.detector.number*c2f.xray.wavelength*c2f.detector.distance/parameters.crl.aperture;
    parameters.detector.width=0.01;
    parameters.detector.intensity = malloc(parameters.detector.number * sizeof(double)); 

    copy_detector(&parameters.detector,&c2f.detector); 
    print_parameters(&parameters, stderr);

    // Start lens loop: while current state (lens) has not reached total lens amount. (phshift) + /PROP+(PHSHIFT)/
    //										      (previous) +/LOOP+(post)/
	while(current!=lenses){

////	   printf("NEW STEP:  current state=%d , tag=%d \n", current, tag);

	       // get field from previous steps, allocate if first time
	       if (current==0){
	           c2f.field->size = malloc(insidecrl.field->dimensions*sizeof(int));
	           c2f.field->values = malloc(insidecrl.field->components*sizeof(complex double));
	           }
	       copy_field(insidecrl.field, c2f.field);


//RUN 	   //perform fourier propagation: from CRL to CRL or Detector (different methods)
////	   printf("Call propagation... \n");
   	   if (current==(lenses-1)){
	   distance=parameters.detector.distance;
//           get_spherical(&c2f, tag, distance);
	   if (padf) pad_field(c2f.field);

	   if (ray_add) ray_addition(&c2f, tag, distance);
           else crl_to_focus(&c2f, tag, distance);
	   }
	   else{
           distance=parameters.crl.separation;  
           crl_to_fourier(&c2f, tag, distance);
	   }
	  

////    	   printf("distance for propagation %d was %f \n", current, distance);
////	   printf("propagation successfully done. \n");
	   copy_field(c2f.field, insidecrl.field);

	   //if not reached detector then phase-shift before propagation 
	   if (current!=(lenses-1)){
	   sprintf(fnamewrite,"crl_plane");
	   sprintf(fnamewrite,"%s%d.txt", fnamewrite, current+2);
           crl_inside(&insidecrl, fnamewrite);
	   }

	   current=current+1;
      }
      write_field_to_file(c2f.field, "det_plane.txt", parameters.detector.width);

    
    /* call gnuplot script to generate plots */
    system ("gnuplot gpscript.gp");

cleanup:
    if (parameters.detector.intensity)   free(parameters.detector.intensity);   parameters.detector.intensity=NULL;
    return ret;
}//main
Ejemplo n.º 23
0
Archivo: crlprop.c Proyecto: mphy/crl
//11111111111111111111111111111111111111111111111111111111111111111111111111111
int crl_inside(struct insidecrl* arg, char* fnamewrite){
    int ret = 0;


    double y;				           //postition on lens
    double wvl=arg->xray.wavelength;		   //wavelength
    double L = arg->crl.aperture;      		   //aperture
    //double posy = arg->crl.offset;      	   //lens off-axis
    double R = arg->crl.R;		      	   //radius  
    double deltafactor = arg->crl.deltafactor;     //delta factor (phase shift)
    int i; 					   //counter
    int N=Nmin;					   //Number of points 
    int n = 1;					   //dimensions (components)
    double* w;    				   //array holdind lens profile values
    double delta;
    double phshift;

    struct field field;
    field.size=NULL;
    field.values=NULL;

    if (arg == NULL)
    {
	fprintf(stderr, "error: arg points to NULL (%s:%d)\n", __FILE__, __LINE__);
	ret = -1;
	goto cleanup;
    }
    
    fprintf(stderr, "warning: equal CRL profiles are used and computed for each step.\n");
    fprintf(stderr, "warning: no scaling nor fft used in %s.\n", __FUNCTION__);
    
	  //Allocate memory for the field
          field.size = malloc(arg->field->dimensions*sizeof(int));
    	  field.values = malloc((arg->field->components)*sizeof(complex double)); //explicit allocation field
	  copy_field(arg->field, &field);

    n=field.components;

   //  retrieve size from total number of points in all dimensions 
    for (i=0; i<field.dimensions; i++)
    {
	//Problems with inverse process dim!=1. Usage of pow nth root is an option. 
        //field.size[i] = N;	//as many components as dimensions
	//n *= field.size[i];
      N=n; //dim 1
    field.size[i]=N;
    }
    delta=L/N;

    // calculate crl profile and apply phase shift 
    w = (double*) malloc(N*sizeof(double));
    for (i=0;i<N;i++){
    y=-0.5*L+delta*i;
    w[i]=0.5*y*y/R;
    phshift=fmod(2.*M_PI*deltafactor*2.*w[i]/wvl,2*M_PI);

    field.values[i] *= cexp(I*phshift);
    }

    // now save the crl field to a file and structure
    write_field_to_file(&field, fnamewrite, L);
    copy_field(&field, arg->field);
    //show_field(&field, N/2, 10, "in crl_inside after shifting");

cleanup:
    if (field.size)   free(field.size);   field.size=NULL;
    if (field.values) free(field.values); field.values=NULL;
    if (w) free(w); w=NULL; 
    return ret;
}
Ejemplo n.º 24
0
Archivo: crlprop.c Proyecto: mphy/crl
//33333333333333333333333333333333333333333333333333333333333333333333333333
int crl_to_focus(struct c2f* arg, int tag, double distance){
    int ret=tag;

    
    double y;				           //position on final lens/detector
    double wvl=arg->xray.wavelength;		   //wavelength
    double L = arg->crl.aperture;    		   //size of lens
    int i; 					   //counter
    int N=Nmin;					   //Number of points 
    int n = 1;					   //dimensions (components)
    double delta;				   //grid spacing on lens
    double deltaf;				   //freq grid spacing
    double complex quadratic;			   //quadratic phase factor
    double complex constphase;			   //constant phase
    double complex scaling;			   //normalisation (scaling) fft

    fftw_complex* in, *out;
    fftw_plan p;
    fftw_complex val;

    struct field field;
    field.size=NULL;
    field.values=NULL;

    if (arg == NULL)
    {
	fprintf(stderr, "error: arg points to NULL (%s:%d)\n", __FILE__, __LINE__);
	ret = -1;
	goto cleanup;
    }
   fprintf(stderr, "warning: detector members are not used.\n");
   fprintf(stderr, "warning: scaling and correct use of fft to be reviewed in %s.\n", __FUNCTION__);

     field.size = malloc(arg->field->dimensions*sizeof(int));
     field.values = malloc((arg->field->components)*sizeof(complex double)); //explicit allocation field
     copy_field(arg->field, &field);
    
    n=field.components;
    
    // retrieve size from total number of points in all dimensions 
    for (i=0; i<field.dimensions; i++)
    {
	//Problems with inverse process dim!=1. Usage of pow nth root is an option. 
        //field.size[i] = N;	//as many components as dimensions
	//n *= field.size[i];
      N=n;
    field.size[i]=N;
    }
    delta=L/N;
    deltaf=1./(delta*N);
printf("CRL to focus propagation N=%d delta=%fμ deltaf=%f \n", N, delta*1e6, deltaf); 
    in  = fftw_malloc(sizeof(fftw_complex) * n);
    out = fftw_malloc(sizeof(fftw_complex) * n);
    p   = fftw_plan_dft_1d(n, in, out, FFTW_FORWARD, FFTW_ESTIMATE);

    // fftw  and quadratic phase (y1)
    for (i=0; i<n; i++)
    {
        y=(-0.5*N+i)*delta;
        quadratic=cexp(I*M_PI*y*y/(wvl*distance));
	in[i]=quadratic*field.values[i];
    }

/*    //previous fftshift
    if (fftshift)
    for (i=0; i<N/2; i++){
    val=in[i];
    in[i]=in[i+N/2];
    in[i+N/2]=val;
    }
*/
    //fftexecute
    fftw_execute(p);

    //fftshift
   if (fftshift)
    for (i=0; i<N/2; i++){
    val=out[i];
    out[i]=out[i+N/2];
    out[i+N/2]=val;
    }

    constphase = cexp(I*distance*2.*M_PI/wvl);
      scaling=sqrt(1./(wvl*distance));
//    scaling = 1./(I*wvl*distance);
//    scaling = 1.;
//    scaling = cpow(1./(I*wvl*distance), 0.5);



  //apply quadratic phase (y2), scaling and constant phase
  for (i=0; i<n; i++)
    {
        y=(-0.5*N+i)*deltaf*wvl*distance;
        quadratic=cexp(I*M_PI*y*y/(wvl*distance));
        field.values[i]=scaling*constphase*quadratic*delta*out[i];

    }

//    write_field_to_file(&field, fnamewrite);  done in main
      copy_field(&field, arg->field);

    fftw_destroy_plan(p);
    fftw_free(in);
    fftw_free(out);

cleanup:
    if (field.size)   free(field.size);   field.size=NULL;
    if (field.values) free(field.values); field.values=NULL;
    return ret;
}
Ejemplo n.º 25
0
int lwlibav_get_video_frame
(
    lwlibav_video_decode_handler_t *vdhp,
    lwlibav_video_output_handler_t *vohp,
    uint32_t                        frame_number
)
{
    if( !vohp->repeat_control )
        return get_requested_picture( vdhp, vdhp->frame_buffer, frame_number );
    /* Get picture to applied the repeat control. */
    uint32_t t = vohp->frame_order_list[frame_number].top;
    uint32_t b = vohp->frame_order_list[frame_number].bottom;
    uint32_t first_field_number  = MIN( t, b );
    uint32_t second_field_number = MAX( t, b );
    /* Check repeat targets and cache datas. */
    enum
    {
        REPEAT_CONTROL_COPIED_FROM_CACHE   = 0x00,
        REPEAT_CONTROL_DECODE_TOP_FIELD    = 0x01,
        REPEAT_CONTROL_DECODE_BOTTOM_FIELD = 0x02,
        REPEAT_CONTROL_DECODE_BOTH_FIELDS  = 0x03,  /* REPEAT_CONTROL_DECODE_TOP_FIELD | REPEAT_CONTROL_DECODE_BOTTOM_FIELD */
        REPEAT_CONTROL_DECODE_ONE_FRAME    = 0x04
    };
    int repeat_control;
    if( first_field_number == second_field_number )
    {
        repeat_control = REPEAT_CONTROL_DECODE_ONE_FRAME;
        if( first_field_number == vohp->frame_cache_numbers[0] )
            return copy_frame( &vdhp->lh, vdhp->frame_buffer, vohp->frame_cache_buffers[0] );
        if( first_field_number == vohp->frame_cache_numbers[1] )
            return copy_frame( &vdhp->lh, vdhp->frame_buffer, vohp->frame_cache_buffers[1] );
        if( first_field_number != vohp->frame_order_list[frame_number - 1].top
         && first_field_number != vohp->frame_order_list[frame_number - 1].bottom
         && first_field_number != vohp->frame_order_list[frame_number + 1].top
         && first_field_number != vohp->frame_order_list[frame_number + 1].bottom )
        {
            if( get_requested_picture( vdhp, vdhp->frame_buffer, first_field_number ) < 0 )
                return -1;
            /* Treat this frame as interlaced. */
            vdhp->frame_buffer->interlaced_frame = 1;
            return 0;
        }
    }
    else
    {
        repeat_control = REPEAT_CONTROL_DECODE_BOTH_FIELDS;
        for( int i = 0; i < REPEAT_CONTROL_CACHE_NUM; i++ )
        {
            if( t == vohp->frame_cache_numbers[i] )
            {
                if( copy_field( &vdhp->lh, vdhp->frame_buffer, vohp->frame_cache_buffers[i], 0 ) < 0 )
                    return -1;
                repeat_control &= ~REPEAT_CONTROL_DECODE_TOP_FIELD;
            }
            if( b == vohp->frame_cache_numbers[i] )
            {
                if( copy_field( &vdhp->lh, vdhp->frame_buffer, vohp->frame_cache_buffers[i], 1 ) < 0 )
                    return -1;
                repeat_control &= ~REPEAT_CONTROL_DECODE_BOTTOM_FIELD;
            }
        }
        if( repeat_control == REPEAT_CONTROL_COPIED_FROM_CACHE )
            return 0;
    }
    /* Decode target frames and copy to output buffer. */
    if( repeat_control == REPEAT_CONTROL_DECODE_BOTH_FIELDS )
    {
        /* Decode 2 frames, and copy each a top and bottom fields. */
        if( get_requested_picture( vdhp, vohp->frame_cache_buffers[0], first_field_number ) < 0 )
            return -1;
        vohp->frame_cache_numbers[0] = first_field_number;
        if( get_requested_picture( vdhp, vohp->frame_cache_buffers[1], second_field_number ) < 0 )
            return -1;
        vohp->frame_cache_numbers[1] = second_field_number;
        if( check_frame_buffer_identical( vohp->frame_cache_buffers[0], vohp->frame_cache_buffers[1] ) )
            return copy_frame( &vdhp->lh, vdhp->frame_buffer, vohp->frame_cache_buffers[0] );
        if( copy_field( &vdhp->lh, vdhp->frame_buffer, vohp->frame_cache_buffers[0], t > b ? 1 : 0 ) < 0
         || copy_field( &vdhp->lh, vdhp->frame_buffer, vohp->frame_cache_buffers[1], t < b ? 1 : 0 ) < 0 )
            return -1;
        return 0;
    }
    else
    {
        /* Decode 1 frame, and copy 1 frame or 1 field. */
        int decode_number = repeat_control == REPEAT_CONTROL_DECODE_ONE_FRAME ? first_field_number
                          : repeat_control == REPEAT_CONTROL_DECODE_TOP_FIELD ? t : b;
        int idx = vohp->frame_cache_numbers[0] > vohp->frame_cache_numbers[1] ? 1 : 0;
        if( get_requested_picture( vdhp, vohp->frame_cache_buffers[idx], decode_number ) < 0 )
            return -1;
        vohp->frame_cache_numbers[idx] = decode_number;
        if( repeat_control == REPEAT_CONTROL_DECODE_ONE_FRAME )
            return copy_frame( &vdhp->lh, vdhp->frame_buffer, vohp->frame_cache_buffers[idx] );
        else
            return copy_field( &vdhp->lh, vdhp->frame_buffer, vohp->frame_cache_buffers[idx],
                               repeat_control == REPEAT_CONTROL_DECODE_TOP_FIELD ? 0 : 1 );
    }
}
Ejemplo n.º 26
0
static GstFlowReturn
gst_interlace_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
{
  GstInterlace *interlace = GST_INTERLACE (parent);
  GstFlowReturn ret = GST_FLOW_OK;
  gint num_fields = 0;
  int current_fields;
  const PulldownFormat *format;

  GST_DEBUG ("Received buffer at %u:%02u:%02u:%09u",
      (guint) (GST_BUFFER_TIMESTAMP (buffer) / (GST_SECOND * 60 * 60)),
      (guint) ((GST_BUFFER_TIMESTAMP (buffer) / (GST_SECOND * 60)) % 60),
      (guint) ((GST_BUFFER_TIMESTAMP (buffer) / GST_SECOND) % 60),
      (guint) (GST_BUFFER_TIMESTAMP (buffer) % GST_SECOND));

  GST_DEBUG ("duration %" GST_TIME_FORMAT " flags %04x %s %s %s",
      GST_TIME_ARGS (GST_BUFFER_DURATION (buffer)),
      GST_BUFFER_FLAGS (buffer),
      (GST_BUFFER_FLAGS (buffer) & GST_VIDEO_BUFFER_FLAG_TFF) ? "tff" : "",
      (GST_BUFFER_FLAGS (buffer) & GST_VIDEO_BUFFER_FLAG_RFF) ? "rff" : "",
      (GST_BUFFER_FLAGS (buffer) & GST_VIDEO_BUFFER_FLAG_ONEFIELD) ? "onefield"
      : "");

  if (GST_BUFFER_FLAGS (buffer) & GST_BUFFER_FLAG_DISCONT) {
    GST_DEBUG ("discont");

    if (interlace->stored_frame) {
      gst_buffer_unref (interlace->stored_frame);
    }
    interlace->stored_frame = NULL;
    interlace->stored_fields = 0;

    if (interlace->top_field_first) {
      interlace->field_index = 0;
    } else {
      interlace->field_index = 1;
    }
  }

  if (interlace->timebase == GST_CLOCK_TIME_NONE) {
    /* get the initial ts */
    interlace->timebase = GST_BUFFER_TIMESTAMP (buffer);
  }

  format = &formats[interlace->pattern];

  if (interlace->stored_fields == 0
      && interlace->phase_index == interlace->pattern_offset
      && GST_CLOCK_TIME_IS_VALID (GST_BUFFER_TIMESTAMP (buffer))) {
    interlace->timebase = GST_BUFFER_TIMESTAMP (buffer);
    interlace->fields_since_timebase = 0;
  }

  if (!format->n_fields[interlace->phase_index]) {
    interlace->phase_index = 0;
  }

  current_fields = format->n_fields[interlace->phase_index];
  /* increment the phase index */
  interlace->phase_index++;
  GST_DEBUG ("incoming buffer assigned %d fields", current_fields);

  num_fields = interlace->stored_fields + current_fields;
  while (num_fields >= 2) {
    GstBuffer *output_buffer;
    int n_output_fields;
    gboolean interlaced = FALSE;

    GST_DEBUG ("have %d fields, %d current, %d stored",
        num_fields, current_fields, interlace->stored_fields);

    if (interlace->stored_fields > 0) {
      GST_DEBUG ("1 field from stored, 1 from current");

      output_buffer = gst_buffer_new_and_alloc (gst_buffer_get_size (buffer));
      /* take the first field from the stored frame */
      copy_field (interlace, output_buffer, interlace->stored_frame,
          interlace->field_index);
      interlace->stored_fields--;
      /* take the second field from the incoming buffer */
      copy_field (interlace, output_buffer, buffer, interlace->field_index ^ 1);
      current_fields--;
      n_output_fields = 2;
      interlaced = TRUE;
    } else {
      output_buffer = gst_buffer_make_writable (gst_buffer_ref (buffer));
      if (num_fields >= 3 && interlace->allow_rff) {
        GST_DEBUG ("3 fields from current");
        /* take both fields from incoming buffer */
        current_fields -= 3;
        n_output_fields = 3;
      } else {
        GST_DEBUG ("2 fields from current");
        /* take both buffers from incoming buffer */
        current_fields -= 2;
        n_output_fields = 2;
      }
    }
    num_fields -= n_output_fields;

    gst_interlace_decorate_buffer (interlace, output_buffer, n_output_fields,
        interlaced);
    interlace->fields_since_timebase += n_output_fields;
    interlace->field_index ^= (n_output_fields & 1);

    GST_DEBUG_OBJECT (interlace, "output timestamp %" GST_TIME_FORMAT
        " duration %" GST_TIME_FORMAT " flags %04x %s %s %s",
        GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (output_buffer)),
        GST_TIME_ARGS (GST_BUFFER_DURATION (output_buffer)),
        GST_BUFFER_FLAGS (output_buffer),
        (GST_BUFFER_FLAGS (output_buffer) & GST_VIDEO_BUFFER_FLAG_TFF) ? "tff" :
        "",
        (GST_BUFFER_FLAGS (output_buffer) & GST_VIDEO_BUFFER_FLAG_RFF) ? "rff" :
        "",
        (GST_BUFFER_FLAGS (output_buffer) & GST_VIDEO_BUFFER_FLAG_ONEFIELD) ?
        "onefield" : "");

    ret = gst_pad_push (interlace->srcpad, output_buffer);
    if (ret != GST_FLOW_OK) {
      GST_DEBUG_OBJECT (interlace, "Failed to push buffer %p", output_buffer);
      break;
    }
  }

  GST_DEBUG ("done.  %d fields remaining", current_fields);

  if (interlace->stored_frame) {
    gst_buffer_unref (interlace->stored_frame);
    interlace->stored_frame = NULL;
    interlace->stored_fields = 0;
  }

  if (current_fields > 0) {
    interlace->stored_frame = buffer;
    interlace->stored_fields = current_fields;
  } else {
    gst_buffer_unref (buffer);
  }
  return ret;
}
Ejemplo n.º 27
0
void read_input(field * temperature1, field * temperature2, char *filename,
                parallel_data * parallel)
{
    FILE *fp;
    int nx, ny, i, j;

    double **full_data;
    double **inner_data;

    int nx_local;

    fp = fopen(filename, "r");
    // Read the header
    fscanf(fp, "# %d %d \n", &nx, &ny);

    parallel_initialize(parallel, nx, ny);
    initialize_field_metadata(temperature1, nx, ny, parallel);
    initialize_field_metadata(temperature2, nx, ny, parallel);

    // Allocate arrays (including ghost layers)
    temperature1->data =
        malloc_2d(temperature1->nx + 2, temperature1->ny + 2);
    temperature2->data =
        malloc_2d(temperature2->nx + 2, temperature2->ny + 2);

    inner_data = malloc_2d(temperature1->nx, temperature1->ny);

    if (parallel->rank == 0) {
        // Full array
        full_data = malloc_2d(nx, ny);

        // Read the actual data
        for (i = 0; i < nx; i++) {
            for (j = 0; j < ny; j++) {
                fscanf(fp, "%lf", &full_data[i][j]);
            }
        }
    } else
        // dummy array for full data
        full_data = malloc_2d(1, 1);

    nx_local = temperature1->nx;

    MPI_Scatter(full_data[0], nx_local * ny, MPI_DOUBLE, inner_data[0],
                nx_local * ny, MPI_DOUBLE, 0, parallel->comm);

    // Copy to the array containing also boundaries
    for (i = 0; i < nx_local; i++)
        memcpy(&temperature1->data[i + 1][1], &inner_data[i][0],
               ny * sizeof(double));

    // Set the boundary values
    for (i = 0; i < nx_local + 1; i++) {
        temperature1->data[i][0] = temperature1->data[i][1];
        temperature1->data[i][ny + 1] = temperature1->data[i][ny];
    }
    for (j = 0; j < ny + 2; j++) {
        temperature1->data[0][j] = temperature1->data[1][j];
        temperature1->data[nx_local + 1][j] =
            temperature1->data[nx_local][j];
    }

    copy_field(temperature1, temperature2);

    free_2d(full_data);
    free_2d(inner_data);
    fclose(fp);
}
Ejemplo n.º 28
0
int
main(int argc, char **argv)
{
	char	*cp;			/* temporary character pointer       */
	const struct passwd *pw;	/* password file entry               */
	struct	passwd	pwent;		/* modified password file entry      */
	char	old_gecos[BUFSIZ];	/* buffer for old GECOS fields       */
	char	new_gecos[BUFSIZ];	/* buffer for new GECOS fields       */
	int	flag;			/* flag currently being processed    */
	int	fflg = 0;		/* -f - set full name                */
	int	rflg = 0;		/* -r - set room number              */
	int	wflg = 0;		/* -w - set work phone number        */
	int	hflg = 0;		/* -h - set home phone number        */
	int	oflg = 0;		/* -o - set other information        */
	char *user;

	sanitize_env();
	setlocale(LC_ALL, "");
	bindtextdomain(PACKAGE, LOCALEDIR);
	textdomain(PACKAGE);

	/*
	 * This command behaves different for root and non-root
	 * users.
	 */

	amroot = (getuid () == 0);
#ifdef	NDBM
	pw_dbm_mode = O_RDWR;
#endif

	/*
	 * Get the program name.  The program name is used as a
	 * prefix to most error messages.  It is also used as input
	 * to the openlog() function for error logging.
	 */

	Prog = Basename(argv[0]);

	openlog("chfn", LOG_PID, LOG_AUTH);

	/* 
	 * The remaining arguments will be processed one by one and
	 * executed by this command.  The name is the last argument
	 * if it does not begin with a "-", otherwise the name is
	 * determined from the environment and must agree with the
	 * real UID.  Also, the UID will be checked for any commands
	 * which are restricted to root only.
	 */

	while ((flag = getopt (argc, argv, "f:r:w:h:o:")) != EOF) {
		switch (flag) {
			case 'f':
				if (!may_change_field('f')) {
					fprintf(stderr, _("%s: Permission denied.\n"), Prog);
					exit(1);
				}
				fflg++;
				STRFCPY(fullnm, optarg);
				break;
			case 'r':
				if (!may_change_field('r')) {
					fprintf(stderr, _("%s: Permission denied.\n"), Prog);
					exit(1);
				}
				rflg++;
				STRFCPY(roomno, optarg);
				break;
			case 'w':
				if (!may_change_field('w')) {
					fprintf(stderr, _("%s: Permission denied.\n"), Prog);
					exit(1);
				}
				wflg++;
				STRFCPY(workph, optarg);
				break;
			case 'h':
				if (!may_change_field('h')) {
					fprintf(stderr, _("%s: Permission denied.\n"), Prog);
					exit(1);
				}
				hflg++;
				STRFCPY(homeph, optarg);
				break;
			case 'o':
				if (!amroot) {
					fprintf(stderr, _("%s: Permission denied.\n"), Prog);
					exit(1);
				}
				oflg++;
				STRFCPY(slop, optarg);
				break;
			default:
				usage();
		}
	}

	/*
	 * Get the name of the user to check.  It is either
	 * the command line name, or the name getlogin()
	 * returns.
	 */

	if (optind < argc) {
		user = argv[optind];
		pw = getpwnam(user);
		if (!pw) {
			fprintf(stderr, _("%s: Unknown user %s\n"), Prog, user);
			exit(1);
		}
	} else {
		pw = get_my_pwent();
		if (!pw) {
			fprintf(stderr, _("%s: Cannot determine your user name.\n"), Prog);
			exit(1);
		}
		user = xstrdup(pw->pw_name);
	}

#ifdef	USE_NIS
	/*
	 * Now we make sure this is a LOCAL password entry for
	 * this user ...
	 */

	if (__ispwNIS ()) {
		char	*nis_domain;
		char	*nis_master;

		fprintf (stderr, _("%s: cannot change user `%s' on NIS client.\n"), Prog, user);

		if (! yp_get_default_domain (&nis_domain) &&
				! yp_master (nis_domain, "passwd.byname",
				&nis_master)) {
			fprintf (stderr, _("%s: `%s' is the NIS master for this client.\n"), Prog, nis_master);
		}
		exit (1);
	}
#endif

	/*
	 * Non-privileged users are only allowed to change the
	 * gecos field if the UID of the user matches the current
	 * real UID.
	 */

	if (!amroot && pw->pw_uid != getuid()) {
		fprintf (stderr, _("%s: Permission denied.\n"), Prog);
		closelog();
		exit(1);
	}

	/*
	 * Non-privileged users are optionally authenticated
	 * (must enter the password of the user whose information
	 * is being changed) before any changes can be made.
	 * Idea from util-linux chfn/chsh.  --marekm
	 */

	if (!amroot && getdef_bool("CHFN_AUTH"))
		passwd_check(pw->pw_name, pw->pw_passwd, "chfn");
	
	/*
	 * Now get the full name.  It is the first comma separated field
	 * in the GECOS field.
	 */

	STRFCPY(old_gecos, pw->pw_gecos);
	cp = copy_field (old_gecos, fflg ? (char *) 0:fullnm, slop);

	/*
	 * Now get the room number.  It is the next comma separated field,
	 * if there is indeed one.
	 */

	if (cp)
		cp = copy_field (cp, rflg ? (char *) 0:roomno, slop);

	/*
	 * Now get the work phone number.  It is the third field.
	 */

	if (cp)
		cp = copy_field (cp, wflg ? (char *) 0:workph, slop);

	/*
	 * Now get the home phone number.  It is the fourth field.
	 */

	if (cp)
		cp = copy_field (cp, hflg ? (char *) 0:homeph, slop);

	/*
	 * Anything left over is "slop".
	 */

	if (cp && !oflg) {
		if (slop[0])
			strcat (slop, ",");

		strcat (slop, cp);
	}

	/*
	 * If none of the fields were changed from the command line,
	 * let the user interactively change them.
	 */

	if (!fflg && !rflg && !wflg && !hflg && !oflg) {
		printf(_("Changing the user information for %s\n"), user);
		new_fields();
	}

	/*
	 * Check all of the fields for valid information
	 */

	if (valid_field(fullnm, ":,=")) {
		fprintf(stderr, _("%s: invalid name: \"%s\"\n"), Prog, fullnm);
		closelog();
		exit(1);
	}
	if (valid_field(roomno, ":,=")) {
		fprintf(stderr, _("%s: invalid room number: \"%s\"\n"), Prog, roomno);
		closelog();
		exit(1);
	}
	if (valid_field(workph, ":,=")) {
		fprintf(stderr, _("%s: invalid work phone: \"%s\"\n"), Prog, workph);
		closelog();
		exit(1);
	}
	if (valid_field (homeph, ":,=")) {
		fprintf(stderr, _("%s: invalid home phone: \"%s\"\n"), Prog, homeph);
		closelog();
		exit(1);
	}
	if (valid_field(slop, ":")) {
		fprintf(stderr, _("%s: \"%s\" contains illegal characters\n"), Prog, slop);
		closelog();
		exit(1);
	}

	/*
	 * Build the new GECOS field by plastering all the pieces together,
	 * if they will fit ...
	 */

	if (strlen(fullnm) + strlen(roomno) + strlen(workph) +
			strlen(homeph) + strlen(slop) > (unsigned int) 80) {
		fprintf(stderr, _("%s: fields too long\n"), Prog);
		closelog();
		exit(1);
	}
	snprintf(new_gecos, sizeof new_gecos, "%s,%s,%s,%s%s%s",
		 fullnm, roomno, workph, homeph, slop[0] ? "," : "", slop);

	/*
	 * Before going any further, raise the ulimit to prevent
	 * colliding into a lowered ulimit, and set the real UID
	 * to root to protect against unexpected signals.  Any
	 * keyboard signals are set to be ignored.
	 */

	if (setuid(0)) {
		fprintf(stderr, _("Cannot change ID to root.\n"));
		SYSLOG((LOG_ERR, NOTROOT2));
		closelog();
		exit(1);
	}
	pwd_init();

	/*
	 * The passwd entry is now ready to be committed back to
	 * the password file.  Get a lock on the file and open it.
	 */

	if (!pw_lock()) {
		fprintf(stderr, _("Cannot lock the password file; try again later.\n"));
		SYSLOG((LOG_WARN, PWDBUSY2));
		closelog();
		exit(1);
	}
	if (!pw_open(O_RDWR)) {
		fprintf(stderr, _("Cannot open the password file.\n"));
		pw_unlock();
		SYSLOG((LOG_ERR, OPNERROR2));
		closelog();
		exit(1);
	}

	/*
	 * Get the entry to update using pw_locate() - we want the real
	 * one from /etc/passwd, not the one from getpwnam() which could
	 * contain the shadow password if (despite the warnings) someone
	 * enables AUTOSHADOW (or SHADOW_COMPAT in libc).  --marekm
	 */
	pw = pw_locate(user);
	if (!pw) {
		pw_unlock();
		fprintf(stderr,
			_("%s: %s not found in /etc/passwd\n"), Prog, user);
		exit(1);
	}

	/*
	 * Make a copy of the entry, then change the gecos field.  The other
	 * fields remain unchanged.
	 */
	pwent = *pw;
	pwent.pw_gecos = new_gecos;

	/*
	 * Update the passwd file entry.  If there is a DBM file,
	 * update that entry as well.
	 */

	if (!pw_update(&pwent)) {
		fprintf(stderr, _("Error updating the password entry.\n"));
		pw_unlock();
		SYSLOG((LOG_ERR, UPDERROR2));
		closelog();
		exit(1);
	}
#ifdef NDBM
	if (pw_dbm_present() && !pw_dbm_update(&pwent)) {
		fprintf(stderr, _("Error updating the DBM password entry.\n"));
		pw_unlock ();
		SYSLOG((LOG_ERR, DBMERROR2));
		closelog();
		exit(1);
	}
	endpwent();
#endif

	/*
	 * Changes have all been made, so commit them and unlock the
	 * file.
	 */

	if (!pw_close()) {
		fprintf(stderr, _("Cannot commit password file changes.\n"));
		pw_unlock();
		SYSLOG((LOG_ERR, CLSERROR2));
		closelog();
		exit(1);
	}
	if (!pw_unlock()) {
		fprintf(stderr, _("Cannot unlock the password file.\n"));
		SYSLOG((LOG_ERR, UNLKERROR2));
		closelog();
		exit(1);
	}
	SYSLOG((LOG_INFO, CHGGECOS, user));
	closelog();
	exit (0);
}