void gpsgps_a_centroproy(PuntoGPSINS* gpss, uint ngps, CentroProyN* centros, uint ncp){
	uint i;
	*ncp=0;
	for(i=0;i<ngps;i++,gpss++){
		if(gpss->tipoGPS==-1) continue;
		centros->index=gpss->n;
		centros->b=gpss->bg!=0;
		if(centros->b!=0){
			if(gpss->bg==1) centros->b=1;
			else centros->b=2;
		}
		centros->P=gpss->P;
		memcpy_double(centros->M[0],gpss->M[0],9);
		centros++;
		(*ncp)++;
	}
}

//Obsoleto. El GPS suele ir siempre con inercial, y aunque no fuese as Aerotri permite calcular sin puntos de apoyo
#include "Rotacion.h"
#include "Funciones.h"
#include "Geodesica.h"
//from "Clasesdibuja.h". Hace falta en Transformaciones.h
class CentroProyDibujo : public CentroProyN{
 public:
	 bint bien;
	 float tgx,tgy;	//semilado para f=1
	 PuntoXYZ<double> marcas[4];
};
#define recibe() recibe(NULL)
#include "bucles_y_matrices.h"
#include "Transformaciones.h"
#include "trans_Hel3D.h"
int __stdcall Trficheros_gpsori(char* ficherogps,u8int gpm, char* ficheroapr,u8int prm,s8int uni2, char* ficheroori,char* mensaje, u8int idioma){
	initialize(0);
	int nret;

	vector<PuntoGPSINS> gpss;
	vector<GrupoGPSINS> grupos;
	vector<GrupoGPSextras> gruposextras;
	vector<CentroProy> centros;
	PuntoGPSINS* pungps;
	CentroProy*centrosg;
	uint ngps,ngrupos,ncpg, ncp;
	vector<PuntoXYZ<double>*> vec1, vec2;
	vector<uint> ind_f1,ind_f2;
	uint* ind1, *ind2;
	Hel3Dg Tr;
	uint i,nfc;
	Sistema sis;
		sis.proy=1;
		sis.a=6376000;
		sis.e=6376000;
		sis.elip=1;
		sis.par1=sis.phi0=sis.l0=0;
		sis.k0=1;
	double x0,y0;
	bint bnada;

	ngps=ngrupos=0;
	nret=lee_ficherogps(ficherogps,gpm,0,0,grupos,ngrupos,gpss,ngps,gruposextras,bnada,bnada);
	if(nret) return nret;

	pungps=gpss._Myfirst;
	x0=y0=0;
	nfc=0;
	for(i=0;i<ngps;i++,pungps++){
		if(pungps->bg){
			x0+=pungps->P.X;
			y0+=pungps->P.Y;
			nfc++;
	}	 }
	sis.X0=x0/nfc;
	sis.Y0=y0/nfc;
	transformar(gpss._Myfirst,ngps,&sis);
	pungps-=ngps;
	nfc=0;

	nret=lee_ficheroapr(ficheroapr,prm,NULL,NULL,&centros,&ncp,NULL,0,uni2);
	if(nret) return nret;

	centrosg=new CentroProy[ngps];
	gpsgps_a_centroproy(pungps,ngps,centrosg,ncpg);
	busca_centros(centrosg,ncpg,centros._Myfirst,ncp,sizeof(CentroProy), nfc,vec1,vec2,ind_f1,ind_f2);
	if(nfc<3){
		switch(idioma){
		  case 1:  strcpy(mensaje,"    Not enough common points\nto calculate the transformation"); break;
		  case 2:  strcpy(mensaje,"Non ci sono abbastanza punti comuni\nper calcolare la trasformazione"); break;
		  default:strcpy(mensaje,"Insuficiente nmero de puntos en comn\npara calcular la transformacin");
		}
		delete[] centrosg;
		return 4;
	}
	ind1=ind_f1._Myfirst;
	ind2=ind_f2._Myfirst;

	Hel_3Dg(vec1._Myfirst,vec2._Myfirst,nfc,&Tr,true,true);
	for(i=0;i<nfc;i++){
		mmulrot(Tr.M,centros[ind2[i]].M,centrosg[i].M);	//Note centrosg[i]. Los machacamos. Slo tienen que quedar los comunes
		centrosg[i].P=pungps[ind1[i]].P;
	}
	transformarrev((PuntoXYZM*)&centrosg->P,sizeof(CentroProy),nfc,&sis);

	escribe_ori_patb(ficheroori,centrosg,nfc);
	delete[] centrosg;
	return 0;
}
