
#include <stdio.h>
#include "pi.h"
#include "type.h"

/* structure which saves line parameters */

typedef struct {

	float capacitance; /* capacitance in farads */

	} SERIES_C;

extern FILE *fdata;

extern COMPLEX unity,zero;

/**********************************************************************

			series_c()

************************************************************************

Function computes the ABCD matrix of a series capacitance

Inputs: pointer to the data structure for the twoport and the frequency
Output: ABCD matrix for the twoport
*/

ABCD series_c(current,f)
TWOPORT *current; 	/* twoport being modelled */
double f;		/* frequency */

{
	ABCD tmsect;
	POINTER calloc();
	SERIES_C *param;

/* the first time this function is called we simply read the parameters
   of the line from the input line */

	if(current->line != NULL) {

		/* allocate storage for the line parameters -- this
		   function may be called for many lines so it has to
		   be unique */

		if((current->param = calloc(1,sizeof(SERIES_C))) == NULL)
			error_alloc();

		param = (SERIES_C *) current->param;

		if(sscanf(current->line,"series_c%f", &param->capacitance) != 1) {
			fprintf(stderr,
		"series_c(): cannot read parameters on line\n%s\n",
			current->line);
			exit(1);
			}

		fprintf(fdata,"Series capacitance %g farads\n", param->capacitance);
		}

/* every other time this function is called we calculate the ABCD matrix */

	else 	{

		param = (SERIES_C *) current->param;

		/* ABCD matrix has impedance in B, unity in
		   A and D, zero in C */
		tmsect.b.real = 0.0;

		/* if f is zero, make impedance very large */
		if(f < 1.e-10) tmsect.b.imag = - 1.e6;
		else tmsect.b.imag = - 1./(2.0*PI*f*param->capacitance);

		tmsect.a = tmsect.d = unity;
		tmsect.c = zero;
		}

	return(tmsect);
}
