if(Salida.ficheros.res){
	 *ext='r'; *(ext+1)='e'; *(ext+2)='s';
	 fvv.open(ficherof);
 }

//Fichero res-0
 if(Salida.ficheros.res){
	 if(LLOGGING_FILES) fprintf(log_file,"Escribiendo la primera parte del fichero de residuos\n");
	 restore_orig;
	 fvv<<'\n';
	 switch(idioma){
		 case Id_Eng:	fvv<<"    FILE OF RESIDUALS\n"; break;
		 case Id_It:	fvv<<"    FILE DI RESIDUI\n"; break;
		 default:		fvv<<"    FICHERO DE RESIDUOS\n";
	 }
	 fvv<<endl;
	 switch(idioma){
		 case Id_Eng:	cabecera_eng(&fvv,dec,ficherof,ficheroapr,ficheroapy,pym,ficherogps,gpm,tdgps,boffgps,tdins,boffins,ficheroint,inm,err_int,fijas,n_cal,ncalib!=0,completo,estimador,conjuntas,sigmaf,sigmaXY,sigmaZ,sigmagpsXY,sigmagpsZ,sigmainsWF,sigmainsK,sis,uni,(float)ccpi,UNIF,UNIT,cg,unig); break;
		 case Id_It:	cabecera_it(&fvv,dec,ficherof,ficheroapr,ficheroapy,pym,ficherogps,gpm,tdgps,boffgps,tdins,boffins,ficheroint,inm,err_int,fijas,n_cal,ncalib!=0,completo,estimador,conjuntas,sigmaf,sigmaXY,sigmaZ,sigmagpsXY,sigmagpsZ,sigmainsWF,sigmainsK,sis,uni,(float)ccpi,UNIF,UNIT,cg,unig); break;
		 default:		cabecera(&fvv,dec,ficherof,ficheroapr,ficheroapy,pym,ficherogps,gpm,tdgps,boffgps,tdins,boffins,ficheroint,inm,err_int,fijas,n_cal,ncalib!=0,completo,estimador,conjuntas,sigmaf,sigmaXY,sigmaZ,sigmagpsXY,sigmagpsZ,sigmainsWF,sigmainsK,sis,uni,(float)ccpi,UNIF,UNIT,cg,unig);
	 }
 }
//Fichero res-1
 if(Salida.ficheros.res){
	 fvv.unsetf(ios::floatfield);
	 switch(idioma){
		 case Id_Eng:	fvv<<"    **Residuals after the split adjustment**\n"; break;
		 case Id_It:	fvv<<"    **Residui dopo la compensazione alterna**\n"; break;
		 default:		fvv<<"    **Residuos tras el ajuste alterno**\n";
	 }
	 fvv<<endl;
	 switch(idioma){
		 case Id_Eng:	fvv<<"    Number of iterations: "<<iter<<'\n'; break;
		 case Id_It:	fvv<<"    Numero di iterazioni: "<<iter<<'\n'; break;
		 default:		fvv<<"    Nmero de iteraciones: "<<iter<<'\n';
	 }
	 fvv<<endl;
	 escribe_res_fotogramas(&fvv,0,centros,ncp,orden_cp,p_cp_acum,nombres,puntosM,mfp,L,L_norm,!completo,pm_acum,pM_a_pA,puntosA.ppio,flimites,nasterisco,decr.f,-1,NULL);
	 if(hayapoyo){fvv<<endl; escribe_res_puntos(&fvv,0,puntosA.ppio,npy,0,pA_a_pM,Lp,Lp_norm,!completo,flimites,nasterisco,decr.p);}
	 if(haygpsins){fvv<<endl; escribe_res_gps(&fvv,0,grupos,ngrupos,gx.calc_a_orig,gx.gps_acum,gpss.ppio,Lgps,Lgps_norm,Lins,Lins_norm,(float)ccpi,!completo,flimites,nasterisco,decr.gps,decr.ins);}
	 fvv<<endl;
	 switch(idioma){
		 case Id_Eng:	fvv<<"    A posteriori standard deviation (photo coordinate units): "<<vv; break;
		 case Id_It:	fvv<<"    Deviazion standard a posteriori (unit delle coordinate immagine): "<<vv; break;
		 default:		fvv<<"    Desviacin tpica a posteriori (unidades de fotocoordenadas): "<<vv;
	 }
	 fvv<<endl;
 }
//Fichero res-2
 if(Salida.ficheros.res){
	 if(LLOGGING_FILES) fprintf(log_file,"Escribiendo la segunda parte del fichero de residuos\n");
	 fvv<<endl;
	 switch(idioma){
		 case Id_Eng:	fvv<<"    **Residuals after the final adjustment**\n"; break;
		 case Id_It:	fvv<<"    **Residui dopo la compesazione congiunta**\n"; break;
		 default:		fvv<<"    **Residuos tras el ajuste conjunto**\n";
	 }
	 fvv<<endl;
	 switch(idioma){
		 case Id_Eng:	fvv<<"    Number of iterations: "<<iter<<'\n'; break;
		 case Id_It:	fvv<<"    Numero di iterazioni: "<<iter<<'\n'; break;
		 default:		fvv<<"    Nmero de iteraciones: "<<iter<<'\n';
	 }
	 fvv<<endl;
	 escribe_res_fotogramas(&fvv,0,centros,ncp,orden_cp,p_cp_acum,nombres,puntosM,mfp,L,L_norm,1,pm_acum,pM_a_pA,puntosA.ppio,flimites,nasterisco,decr.f,-1,NULL);
	 if(hayapoyo){fvv<<endl; escribe_res_puntos(&fvv,0,puntosA.ppio,npy,0,pA_a_pM,Lp,Lp_norm,1,flimites,nasterisco,decr.p);}
	 if(haygpsins){fvv<<endl; escribe_res_gps(&fvv,0,grupos,ngrupos,gx.calc_a_orig,gx.gps_acum,gpss.ppio,Lgps,Lgps_norm,Lins,Lins_norm,(float)ccpi,1,flimites,nasterisco,decr.gps,decr.ins);}
	 fvv<<endl;
	 switch(idioma){
		 case Id_Eng:	fvv<<"    A posteriori standard deviation (photo coordinate units): "<<vv; break;
		 case Id_It:	fvv<<"    Deviazione standard a posteriori (unit delle coordinate immagine): "<<vv; break;
		 default:		fvv<<"    Desviacin tpica a posteriori (unidades de fotocoordenadas): "<<vv;
	 }
	 fvv<<endl;
 }
 