/* rocot_utility.f -- translated by f2c (version 20100827).
   You must link the resulting object file with libf2c:
	on Microsoft Windows system, link with libf2c.lib;
	on Linux or Unix systems, link with .../path/to/libf2c.a -lm
	or, if you install libf2c.a in a standard place, with -lf2c -lm
	-- in that order, at the end of the command line, as in
		cc *.o -lf2c -lm
	Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,

		http://www.netlib.org/f2c/libf2c.zip
*/

#include "f2c.h"

/* Table of constant values */

static integer c__1 = 1;
static integer c__9 = 9;
static integer c__2 = 2;
static integer c__4 = 4;
static integer c__7 = 7;
static integer c__3 = 3;

/* Main program */ int MAIN__(void)
{
    /* Initialized data */

    static char allowed[3*7] = "geo" "gei" "gsq" "gse" "gsm" "sma" "mag";

    /* Format strings */
    static char fmt_100[] = "(a,3i6)";

    /* System generated locals */
    address a__1[2];
    integer i__1, i__2[2];
    icilist ici__1;
    olist o__1;
    cllist cl__1;

    /* Builtin functions */
    integer s_wsfe(cilist *), e_wsfe(void), do_fio(integer *, char *, ftnlen),
	     s_wsle(cilist *), do_lio(integer *, integer *, char *, ftnlen), 
	    e_wsle(void), s_rsfe(cilist *), e_rsfe(void);
    /* Subroutine */ int s_copy(char *, char *, ftnlen, ftnlen);
    integer f_open(olist *), s_cmp(char *, char *, ftnlen, ftnlen), s_rsfi(
	    icilist *), e_rsfi(void);
    /* Subroutine */ int s_cat(char *, char **, integer *, integer *, ftnlen);
    integer s_rsli(icilist *), e_rsli(void), f_clos(cllist *);
    /* Subroutine */ int s_stop(char *, ftnlen);

    /* Local variables */
    extern /* Subroutine */ int cchalen___(char *, integer *, ftnlen);
    static integer i__, ic, nc, ih, im, is;
    static real ux, uy, uz, vx, vy, vz;
    extern /* Subroutine */ int t_sm_togsq__(real *, real *, real *, real *, 
	    real *, real *), t_mg_to_gse__(real *, real *, real *, real *, 
	    real *, real *), t_gei_to_sm__(real *, real *, real *, real *, 
	    real *, real *), t_sm_to_gei__(real *, real *, real *, real *, 
	    real *, real *), t_sm_to_mag__(real *, real *, real *, real *, 
	    real *, real *), t_mag_to_sm__(real *, real *, real *, real *, 
	    real *, real *), t_geo_to_sm__(real *, real *, real *, real *, 
	    real *, real *), t_sm_to_geo__(real *, real *, real *, real *, 
	    real *, real *), t_gse_to_sm__(real *, real *, real *, real *, 
	    real *, real *), t_sm_to_gse__(real *, real *, real *, real *, 
	    real *, real *);
    static char rep1[3], rep2[3];
    extern /* Subroutine */ int t_gsm_to_sm__(real *, real *, real *, real *, 
	    real *, real *), t_sm_to_gsm__(real *, real *, real *, real *, 
	    real *, real *), t_gsq_to_sm__(real *, real *, real *, real *, 
	    real *, real *);
    static integer iday;
    static char line[255];
    static integer irep;
    extern /* Subroutine */ int t_gei_to_mag__(real *, real *, real *, real *,
	     real *, real *), t_mag_to_gei__(real *, real *, real *, real *, 
	    real *, real *), test_(char *, char *, ftnlen, ftnlen), 
	    t_geo_to_gei__(real *, real *, real *, real *, real *, real *), 
	    t_geo_to_mag__(real *, real *, real *, real *, real *, real *), 
	    t_gei_to_geo__(real *, real *, real *, real *, real *, real *), 
	    t_mag_to_geo__(real *, real *, real *, real *, real *, real *), 
	    t_gei_to_gse__(real *, real *, real *, real *, real *, real *), 
	    t_gse_to_gei__(real *, real *, real *, real *, real *, real *), 
	    t_gse_to_mag__(real *, real *, real *, real *, real *, real *), 
	    t_geo_to_gse__(real *, real *, real *, real *, real *, real *), 
	    t_gse_to_geo__(real *, real *, real *, real *, real *, real *), 
	    t_gei_to_gsm__(real *, real *, real *, real *, real *, real *), 
	    t_gsm_to_gei__(real *, real *, real *, real *, real *, real *), 
	    t_gsm_to_mag__(real *, real *, real *, real *, real *, real *);
    static char file1[255], file2[255];
    extern /* Subroutine */ int t_gsq_to_mag__(real *, real *, real *, real *,
	     real *, real *), t_geo_to_gsm__(real *, real *, real *, real *, 
	    real *, real *), t_gsm_to_geo__(real *, real *, real *, real *, 
	    real *, real *), t_mag_to_gsq__(real *, real *, real *, real *, 
	    real *, real *), t_mag_to_gsm__(real *, real *, real *, real *, 
	    real *, real *), t_gse_to_gsm__(real *, real *, real *, real *, 
	    real *, real *), t_gsm_to_gse__(real *, real *, real *, real *, 
	    real *, real *);
    static integer iyear;
    extern /* Subroutine */ int cp_time_param__(integer *, integer *, integer 
	    *, integer *, integer *, integer *), t_gei_to_gseq__(real *, real 
	    *, real *, real *, real *, real *), t_gseq_to_gei__(real *, real *
	    , real *, real *, real *, real *), t_geo_to_gseq__(real *, real *,
	     real *, real *, real *, real *), t_gseq_to_geo__(real *, real *, 
	    real *, real *, real *, real *), t_gseq_to_gse__(real *, real *, 
	    real *, real *, real *, real *), t_gse_to_gseq__(real *, real *, 
	    real *, real *, real *, real *), t_gseq_to_gsm__(real *, real *, 
	    real *, real *, real *, real *), t_gsm_to_gseq__(real *, real *, 
	    real *, real *, real *, real *);
    static char header[255*6];
    static integer imonth;
    static char subname[7];

    /* Fortran I/O blocks */
    static cilist io___2 = { 0, 6, 0, fmt_100, 0 };
    static cilist io___3 = { 0, 6, 0, fmt_100, 0 };
    static cilist io___4 = { 0, 6, 0, fmt_100, 0 };
    static cilist io___5 = { 0, 6, 0, fmt_100, 0 };
    static cilist io___6 = { 0, 6, 0, fmt_100, 0 };
    static cilist io___7 = { 0, 6, 0, 0, 0 };
    static cilist io___8 = { 0, 5, 0, "(a)", 0 };
    static cilist io___11 = { 0, 6, 0, 0, 0 };
    static cilist io___14 = { 0, 1, 1, "(a)", 0 };
    static cilist io___18 = { 0, 6, 0, 0, 0 };
    static cilist io___19 = { 0, 6, 0, 0, 0 };
    static cilist io___20 = { 0, 6, 0, 0, 0 };
    static cilist io___21 = { 0, 5, 0, "(a)", 0 };
    static cilist io___23 = { 0, 6, 0, 0, 0 };
    static cilist io___24 = { 0, 6, 0, 0, 0 };
    static cilist io___25 = { 0, 5, 0, "(a)", 0 };
    static cilist io___27 = { 0, 6, 0, 0, 0 };
    static cilist io___29 = { 0, 2, 0, "(a)", 0 };
    static cilist io___30 = { 0, 1, 1, "(a)", 0 };
    static cilist io___31 = { 0, 6, 0, 0, 0 };
    static cilist io___32 = { 0, 6, 0, 0, 0 };
    static cilist io___33 = { 0, 6, 0, 0, 0 };
    static cilist io___34 = { 0, 6, 0, 0, 0 };
    static icilist io___35 = { 0, line, 0, "(i4,5(1x,i2))", 255, 1 };
    static icilist io___42 = { 0, line+24, 0, 0, 104, 1 };
    static cilist io___50 = { 0, 2, 0, "(a,3(1Pe15.5))", 0 };
    static cilist io___51 = { 0, 6, 0, fmt_100, 0 };
    static cilist io___52 = { 0, 6, 0, fmt_100, 0 };
    static cilist io___53 = { 0, 6, 0, fmt_100, 0 };
    static cilist io___54 = { 0, 6, 0, 0, 0 };
    static cilist io___55 = { 0, 6, 0, 0, 0 };


/*     ***************************************************************0** */
/* *   Rocot_Utility : tranform a file of time tagged vectors */
/*                     given in sys1 to sys2 */
/*     P. Robert, Jan 2008 */
/*     ***************************************************************0** */
    s_wsfe(&io___2);
    e_wsfe();
    s_wsfe(&io___3);
    do_fio(&c__1, "*****************************************************", (
	    ftnlen)53);
    e_wsfe();
    s_wsfe(&io___4);
    e_wsfe();
    s_wsfe(&io___5);
    do_fio(&c__1, "rocot_utility:", (ftnlen)14);
    e_wsfe();
    s_wsfe(&io___6);
    e_wsfe();
/* *** lecture des parametres */
    s_wsle(&io___7);
    do_lio(&c__9, &c__1, "input  file ? (ex: CLUFGM1-gse.txt)", (ftnlen)35);
    e_wsle();
    s_rsfe(&io___8);
    do_fio(&c__1, file1, (ftnlen)255);
    e_rsfe();
    cchalen___(file1, &nc, (ftnlen)255);
    s_wsle(&io___11);
    do_lio(&c__9, &c__1, file1, nc);
    e_wsle();
    s_copy(rep1, "XXX", (ftnlen)3, (ftnlen)3);
/* *** ouverture de fichier input */
    o__1.oerr = 0;
    o__1.ounit = 1;
    o__1.ofnmlen = 255;
    o__1.ofnm = file1;
    o__1.orl = 0;
    o__1.osta = "old";
    o__1.oacc = 0;
    o__1.ofm = 0;
    o__1.oblnk = 0;
    f_open(&o__1);
/* *** lecture du repere */
    for (i__ = 1; i__ <= 6; ++i__) {
	i__1 = s_rsfe(&io___14);
	if (i__1 != 0) {
	    goto L7;
	}
	i__1 = do_fio(&c__1, header + (i__ - 1) * 255, (ftnlen)255);
	if (i__1 != 0) {
	    goto L7;
	}
	i__1 = e_rsfe();
	if (i__1 != 0) {
	    goto L7;
	}
	if (s_cmp(header + (i__ - 1) * 255, "# CHA : COORDINATE_SYSTEM : ", (
		ftnlen)28, (ftnlen)28) != 0) {
	    goto L5;
	} else {
	    ici__1.icierr = 0;
	    ici__1.iciend = 0;
	    ici__1.icirnum = 1;
	    ici__1.icirlen = 255;
	    ici__1.iciunit = header + (i__ - 1) * 255;
	    ici__1.icifmt = "(28x,a3)";
	    s_rsfi(&ici__1);
	    do_fio(&c__1, rep1, (ftnlen)3);
	    e_rsfi();
	    irep = i__;
	}
L5:
	;
    }
/* *** conversion eventuelle en minuscule */
    for (i__ = 1; i__ <= 3; ++i__) {
	ic = *(unsigned char *)&rep1[i__ - 1];
	if (ic >= 65 && ic < 90) {
	    *(unsigned char *)&rep1[i__ - 1] = (char) (ic + 32);
	}
    }
    s_wsle(&io___18);
    do_lio(&c__9, &c__1, "input  coordinate system :", (ftnlen)26);
    do_lio(&c__9, &c__1, rep1, (ftnlen)3);
    e_wsle();
    test_(rep1, allowed, (ftnlen)3, (ftnlen)3);
    s_wsle(&io___19);
    e_wsle();
    s_wsle(&io___20);
    do_lio(&c__9, &c__1, "output coordinate system ? (ex: gsm)", (ftnlen)36);
    e_wsle();
    s_rsfe(&io___21);
    do_fio(&c__1, rep2, (ftnlen)3);
    e_rsfe();
    s_wsle(&io___23);
    do_lio(&c__9, &c__1, rep2, (ftnlen)3);
    e_wsle();
    s_wsle(&io___24);
    do_lio(&c__9, &c__1, "output file ? (ex: CLUFGM1-gsm.txt)", (ftnlen)35);
    e_wsle();
    s_rsfe(&io___25);
    do_fio(&c__1, file2, (ftnlen)255);
    e_rsfe();
    cchalen___(file2, &nc, (ftnlen)255);
    s_wsle(&io___27);
    do_lio(&c__9, &c__1, file2, nc);
    e_wsle();
    test_(rep2, allowed, (ftnlen)3, (ftnlen)3);
    o__1.oerr = 0;
    o__1.ounit = 2;
    o__1.ofnmlen = 255;
    o__1.ofnm = file2;
    o__1.orl = 0;
    o__1.osta = 0;
    o__1.oacc = 0;
    o__1.ofm = 0;
    o__1.oblnk = 0;
    f_open(&o__1);
/* Writing concatenation */
    i__2[0] = 28, a__1[0] = "# CHA : COORDINATE_SYSTEM : ";
    i__2[1] = 3, a__1[1] = rep2;
    s_cat(header + (irep - 1) * 255, a__1, i__2, &c__2, (ftnlen)255);
    cchalen___(line, &nc, (ftnlen)255);
    for (i__ = 1; i__ <= 6; ++i__) {
	cchalen___(header + (i__ - 1) * 255, &nc, (ftnlen)255);
	s_wsfe(&io___29);
	do_fio(&c__1, header + (i__ - 1) * 255, nc);
	e_wsfe();
/* L6: */
    }
/* *** lecture et traitement de chaque vecteur */
L10:
    i__1 = s_rsfe(&io___30);
    if (i__1 != 0) {
	goto L20;
    }
    i__1 = do_fio(&c__1, line, (ftnlen)255);
    if (i__1 != 0) {
	goto L20;
    }
    i__1 = e_rsfe();
    if (i__1 != 0) {
	goto L20;
    }
    if (*(unsigned char *)&line[4] != '-' || *(unsigned char *)&line[7] != 
	    '-' || *(unsigned char *)&line[10] != 'T' || *(unsigned char *)&
	    line[13] != ':' || *(unsigned char *)&line[16] != ':' || *(
	    unsigned char *)&line[19] != '.' || *(unsigned char *)&line[23] !=
	     'Z') {
	s_wsle(&io___31);
	do_lio(&c__9, &c__1, "date/time field=", (ftnlen)16);
	do_lio(&c__9, &c__1, line, (ftnlen)24);
	e_wsle();
	s_wsle(&io___32);
	do_lio(&c__9, &c__1, "*** date/time field is not in ISO format", (
		ftnlen)40);
	e_wsle();
	s_wsle(&io___33);
	do_lio(&c__9, &c__1, "    ex: 2003-08-17T16:33:07.000Z", (ftnlen)32);
	e_wsle();
	s_wsle(&io___34);
	do_lio(&c__9, &c__1, "    program aborted !!!", (ftnlen)23);
	e_wsle();
    }
/* **  lecture du vecteur et de son temps */
    s_rsfi(&io___35);
    do_fio(&c__1, (char *)&iyear, (ftnlen)sizeof(integer));
    do_fio(&c__1, (char *)&imonth, (ftnlen)sizeof(integer));
    do_fio(&c__1, (char *)&iday, (ftnlen)sizeof(integer));
    do_fio(&c__1, (char *)&ih, (ftnlen)sizeof(integer));
    do_fio(&c__1, (char *)&im, (ftnlen)sizeof(integer));
    do_fio(&c__1, (char *)&is, (ftnlen)sizeof(integer));
    e_rsfi();
    s_rsli(&io___42);
    do_lio(&c__4, &c__1, (char *)&ux, (ftnlen)sizeof(real));
    do_lio(&c__4, &c__1, (char *)&uy, (ftnlen)sizeof(real));
    do_lio(&c__4, &c__1, (char *)&uz, (ftnlen)sizeof(real));
    e_rsli();
/* **  initialisation des matrices */
    cp_time_param__(&iyear, &imonth, &iday, &ih, &im, &is);
/* **  tranformation dans le repere souhaite */
/* *   transformations possibles: geo gei gsq gse gsm sma mag */
/*     toutes les combinaisons sont: */
/*     geogei geogsq geogse geogsm geosma geomag */
/*     geigeo gsqgeo gsegeo gsmgeo smageo maggeo */
/*     geigsq geigse geigsm geisma geimag */
/*     gsqgei gsegei gsmgei smagei maggei */
/*     gsqgse gsqgsm gsqsma gsqmag */
/*     gsegsq gsmgsq smagsq maggsq */
/*     gsegsm gsesma gsemag */
/*     gsmgse smagse maggse */
/*     gsmsma gsmmag */
/*     smagsm maggsm */
/*     smmag */
/*     magsma */
/* Writing concatenation */
    i__2[0] = 3, a__1[0] = rep1;
    i__2[1] = 3, a__1[1] = rep2;
    s_cat(subname, a__1, i__2, &c__2, (ftnlen)7);
/* * les if de la mort:... */
    if (s_cmp(subname, "geogei", (ftnlen)7, (ftnlen)6) == 0) {
	t_geo_to_gei__(&ux, &uy, &uz, &vx, &vy, &vz);
    }
    if (s_cmp(subname, "geogsq", (ftnlen)7, (ftnlen)6) == 0) {
	t_geo_to_gseq__(&ux, &uy, &uz, &vx, &vy, &vz);
    }
    if (s_cmp(subname, "geogse", (ftnlen)7, (ftnlen)6) == 0) {
	t_geo_to_gse__(&ux, &uy, &uz, &vx, &vy, &vz);
    }
    if (s_cmp(subname, "geogsm", (ftnlen)7, (ftnlen)6) == 0) {
	t_geo_to_gsm__(&ux, &uy, &uz, &vx, &vy, &vz);
    }
    if (s_cmp(subname, "geosma", (ftnlen)7, (ftnlen)6) == 0) {
	t_geo_to_sm__(&ux, &uy, &uz, &vx, &vy, &vz);
    }
    if (s_cmp(subname, "geomag", (ftnlen)7, (ftnlen)6) == 0) {
	t_geo_to_mag__(&ux, &uy, &uz, &vx, &vy, &vz);
    }
    if (s_cmp(subname, "geigeo", (ftnlen)7, (ftnlen)6) == 0) {
	t_gei_to_geo__(&ux, &uy, &uz, &vx, &vy, &vz);
    }
    if (s_cmp(subname, "gsqgeo", (ftnlen)7, (ftnlen)6) == 0) {
	t_gseq_to_geo__(&ux, &uy, &uz, &vx, &vy, &vz);
    }
    if (s_cmp(subname, "gsegeo", (ftnlen)7, (ftnlen)6) == 0) {
	t_gse_to_geo__(&ux, &uy, &uz, &vx, &vy, &vz);
    }
    if (s_cmp(subname, "gsmgeo", (ftnlen)7, (ftnlen)6) == 0) {
	t_gsm_to_geo__(&ux, &uy, &uz, &vx, &vy, &vz);
    }
    if (s_cmp(subname, "smageo", (ftnlen)7, (ftnlen)6) == 0) {
	t_sm_to_geo__(&ux, &uy, &uz, &vx, &vy, &vz);
    }
    if (s_cmp(subname, "maggeo", (ftnlen)7, (ftnlen)6) == 0) {
	t_mag_to_geo__(&ux, &uy, &uz, &vx, &vy, &vz);
    }
    if (s_cmp(subname, "geigsq", (ftnlen)7, (ftnlen)6) == 0) {
	t_gei_to_gseq__(&ux, &uy, &uz, &vx, &vy, &vz);
    }
    if (s_cmp(subname, "geigse", (ftnlen)7, (ftnlen)6) == 0) {
	t_gei_to_gse__(&ux, &uy, &uz, &vx, &vy, &vz);
    }
    if (s_cmp(subname, "geigsm", (ftnlen)7, (ftnlen)6) == 0) {
	t_gei_to_gsm__(&ux, &uy, &uz, &vx, &vy, &vz);
    }
    if (s_cmp(subname, "geisma", (ftnlen)7, (ftnlen)6) == 0) {
	t_gei_to_sm__(&ux, &uy, &uz, &vx, &vy, &vz);
    }
    if (s_cmp(subname, "geimag", (ftnlen)7, (ftnlen)6) == 0) {
	t_gei_to_mag__(&ux, &uy, &uz, &vx, &vy, &vz);
    }
    if (s_cmp(subname, "gsqgei", (ftnlen)7, (ftnlen)6) == 0) {
	t_gseq_to_gei__(&ux, &uy, &uz, &vx, &vy, &vz);
    }
    if (s_cmp(subname, "gsegei", (ftnlen)7, (ftnlen)6) == 0) {
	t_gse_to_gei__(&ux, &uy, &uz, &vx, &vy, &vz);
    }
    if (s_cmp(subname, "gsmgei", (ftnlen)7, (ftnlen)6) == 0) {
	t_gsm_to_gei__(&ux, &uy, &uz, &vx, &vy, &vz);
    }
    if (s_cmp(subname, "smagei", (ftnlen)7, (ftnlen)6) == 0) {
	t_sm_to_gei__(&ux, &uy, &uz, &vx, &vy, &vz);
    }
    if (s_cmp(subname, "maggei", (ftnlen)7, (ftnlen)6) == 0) {
	t_mag_to_gei__(&ux, &uy, &uz, &vx, &vy, &vz);
    }
    if (s_cmp(subname, "gsqgse", (ftnlen)7, (ftnlen)6) == 0) {
	t_gseq_to_gse__(&ux, &uy, &uz, &vx, &vy, &vz);
    }
    if (s_cmp(subname, "gsqgsm", (ftnlen)7, (ftnlen)6) == 0) {
	t_gseq_to_gsm__(&ux, &uy, &uz, &vx, &vy, &vz);
    }
    if (s_cmp(subname, "gsqsma", (ftnlen)7, (ftnlen)6) == 0) {
	t_gsq_to_sm__(&ux, &uy, &uz, &vx, &vy, &vz);
    }
    if (s_cmp(subname, "gsqmag", (ftnlen)7, (ftnlen)6) == 0) {
	t_gsq_to_mag__(&ux, &uy, &uz, &vx, &vy, &vz);
    }
    if (s_cmp(subname, "gsegsq", (ftnlen)7, (ftnlen)6) == 0) {
	t_gse_to_gseq__(&ux, &uy, &uz, &vx, &vy, &vz);
    }
    if (s_cmp(subname, "gsmgsq", (ftnlen)7, (ftnlen)6) == 0) {
	t_gsm_to_gseq__(&ux, &uy, &uz, &vx, &vy, &vz);
    }
    if (s_cmp(subname, "smagsq", (ftnlen)7, (ftnlen)6) == 0) {
	t_sm_togsq__(&ux, &uy, &uz, &vx, &vy, &vz);
    }
    if (s_cmp(subname, "maggsq", (ftnlen)7, (ftnlen)6) == 0) {
	t_mag_to_gsq__(&ux, &uy, &uz, &vx, &vy, &vz);
    }
    if (s_cmp(subname, "gsegsm", (ftnlen)7, (ftnlen)6) == 0) {
	t_gse_to_gsm__(&ux, &uy, &uz, &vx, &vy, &vz);
    }
    if (s_cmp(subname, "gsesma", (ftnlen)7, (ftnlen)6) == 0) {
	t_gse_to_sm__(&ux, &uy, &uz, &vx, &vy, &vz);
    }
    if (s_cmp(subname, "gsemag", (ftnlen)7, (ftnlen)6) == 0) {
	t_gse_to_mag__(&ux, &uy, &uz, &vx, &vy, &vz);
    }
    if (s_cmp(subname, "gsmgse", (ftnlen)7, (ftnlen)6) == 0) {
	t_gsm_to_gse__(&ux, &uy, &uz, &vx, &vy, &vz);
    }
    if (s_cmp(subname, "smagse", (ftnlen)7, (ftnlen)6) == 0) {
	t_sm_to_gse__(&ux, &uy, &uz, &vx, &vy, &vz);
    }
    if (s_cmp(subname, "maggse", (ftnlen)7, (ftnlen)6) == 0) {
	t_mg_to_gse__(&ux, &uy, &uz, &vx, &vy, &vz);
    }
    if (s_cmp(subname, "gsmsma", (ftnlen)7, (ftnlen)6) == 0) {
	t_gsm_to_sm__(&ux, &uy, &uz, &vx, &vy, &vz);
    }
    if (s_cmp(subname, "gsmmag", (ftnlen)7, (ftnlen)6) == 0) {
	t_gsm_to_mag__(&ux, &uy, &uz, &vx, &vy, &vz);
    }
    if (s_cmp(subname, "smagsm", (ftnlen)7, (ftnlen)6) == 0) {
	t_sm_to_gsm__(&ux, &uy, &uz, &vx, &vy, &vz);
    }
    if (s_cmp(subname, "maggsm", (ftnlen)7, (ftnlen)6) == 0) {
	t_mag_to_gsm__(&ux, &uy, &uz, &vx, &vy, &vz);
    }
    if (s_cmp(subname, "smamag", (ftnlen)7, (ftnlen)6) == 0) {
	t_sm_to_mag__(&ux, &uy, &uz, &vx, &vy, &vz);
    }
    if (s_cmp(subname, "magsma", (ftnlen)7, (ftnlen)6) == 0) {
	t_mag_to_sm__(&ux, &uy, &uz, &vx, &vy, &vz);
    }
/* **  ecriture des resultats */
    s_wsfe(&io___50);
    do_fio(&c__1, line, (ftnlen)24);
    do_fio(&c__1, (char *)&vx, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&vy, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&vz, (ftnlen)sizeof(real));
    e_wsfe();
/* **  rebelote... */
    goto L10;
L20:
    cl__1.cerr = 0;
    cl__1.cunit = 1;
    cl__1.csta = 0;
    f_clos(&cl__1);
    cl__1.cerr = 0;
    cl__1.cunit = 2;
    cl__1.csta = 0;
    f_clos(&cl__1);
    s_wsfe(&io___51);
    e_wsfe();
    s_wsfe(&io___52);
    do_fio(&c__1, "*****************************************************", (
	    ftnlen)53);
    e_wsfe();
    s_wsfe(&io___53);
    e_wsfe();

    s_stop("rocot_utility.exe: normal termination", (ftnlen)37);
L7:
    s_wsle(&io___54);
    do_lio(&c__9, &c__1, "*** bad metadata", (ftnlen)16);
    e_wsle();
    s_wsle(&io___55);
    do_lio(&c__9, &c__1, "\"# CHA : COORDINATE_SYSTEM :\" not found", (ftnlen)
	    39);
    e_wsle();
    cl__1.cerr = 0;
    cl__1.cunit = 1;
    cl__1.csta = 0;
    f_clos(&cl__1);
    s_stop("rocot_utility.exe: bad metadata, aborted", (ftnlen)40);
    return 0;
} /* MAIN__ */


/*     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX0XX */

/* Subroutine */ int test_(char *rep, char *allowed, ftnlen rep_len, ftnlen 
	allowed_len)
{
    /* Format strings */
    static char fmt_100[] = "(a,/,7a5)";

    /* Builtin functions */
    integer s_cmp(char *, char *, ftnlen, ftnlen), s_wsle(cilist *), do_lio(
	    integer *, integer *, char *, ftnlen), e_wsle(void), s_wsfe(
	    cilist *), do_fio(integer *, char *, ftnlen), e_wsfe(void);
    /* Subroutine */ int s_stop(char *, ftnlen);

    /* Local variables */
    static integer i__;

    /* Fortran I/O blocks */
    static cilist io___57 = { 0, 6, 0, 0, 0 };
    static cilist io___58 = { 0, 6, 0, fmt_100, 0 };


    /* Parameter adjustments */
    allowed -= 3;

    /* Function Body */
    for (i__ = 1; i__ <= 7; ++i__) {
	if (s_cmp(rep, allowed + i__ * 3, (ftnlen)3, (ftnlen)3) == 0) {
	    return 0;
	}
    }
    s_wsle(&io___57);
    do_lio(&c__9, &c__1, "*** ", (ftnlen)4);
    do_lio(&c__9, &c__1, rep, (ftnlen)3);
    do_lio(&c__9, &c__1, " is not allowed", (ftnlen)15);
    e_wsle();
    s_wsfe(&io___58);
    do_fio(&c__1, "allowed coordinates are ", (ftnlen)24);
    do_fio(&c__7, allowed + 3, (ftnlen)3);
    e_wsfe();
    s_stop("   program aborted", (ftnlen)18);
    return 0;
} /* test_ */


/*     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX0XX */

/* Subroutine */ int t_sm_to_gse__(real *x1, real *y1, real *z1, real *x2, 
	real *y2, real *z2)
{
    static real x3, y3, z3;
    extern /* Subroutine */ int t_sm_to_gsm__(real *, real *, real *, real *, 
	    real *, real *), t_gsm_to_gse__(real *, real *, real *, real *, 
	    real *, real *);

    t_sm_to_gsm__(x1, y1, z1, &x3, &y3, &z3);
    t_gsm_to_gse__(&x3, &y3, &z3, x2, y2, z2);
    return 0;
} /* t_sm_to_gse__ */


/*     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX0XX */

/* Subroutine */ int t_gse_to_sm__(real *x1, real *y1, real *z1, real *x2, 
	real *y2, real *z2)
{
    static real x3, y3, z3;
    extern /* Subroutine */ int t_gsm_to_sm__(real *, real *, real *, real *, 
	    real *, real *), t_gse_to_gsm__(real *, real *, real *, real *, 
	    real *, real *);

    t_gse_to_gsm__(x1, y1, z1, &x3, &y3, &z3);
    t_gsm_to_sm__(&x3, &y3, &z3, x2, y2, z2);
    return 0;
} /* t_gse_to_sm__ */


/*     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX0XX */

/* Subroutine */ int t_mg_to_gse__(real *x1, real *y1, real *z1, real *x2, 
	real *y2, real *z2)
{
    static real x3, y3, z3;
    extern /* Subroutine */ int t_mag_to_sm__(real *, real *, real *, real *, 
	    real *, real *), t_sm_to_gse__(real *, real *, real *, real *, 
	    real *, real *);

    t_mag_to_sm__(x1, y1, z1, &x3, &y3, &z3);
    t_sm_to_gse__(&x3, &y3, &z3, x2, y2, z2);
    return 0;
} /* t_mg_to_gse__ */


/*     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX0XX */

/* Subroutine */ int t_gse_to_mag__(real *x1, real *y1, real *z1, real *x2, 
	real *y2, real *z2)
{
    static real x3, y3, z3;
    extern /* Subroutine */ int t_sm_to_mag__(real *, real *, real *, real *, 
	    real *, real *), t_gse_to_sm__(real *, real *, real *, real *, 
	    real *, real *);

    t_gse_to_sm__(x1, y1, z1, &x3, &y3, &z3);
    t_sm_to_mag__(&x3, &y3, &z3, x2, y2, z2);
    return 0;
} /* t_gse_to_mag__ */


/*     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX0XX */

/* Subroutine */ int t_sm_togsq__(real *x1, real *y1, real *z1, real *x2, 
	real *y2, real *z2)
{
    static real x3, y3, z3;
    extern /* Subroutine */ int t_sm_to_gsm__(real *, real *, real *, real *, 
	    real *, real *), t_gsm_to_gseq__(real *, real *, real *, real *, 
	    real *, real *);

    t_sm_to_gsm__(x1, y1, z1, &x3, &y3, &z3);
    t_gsm_to_gseq__(&x3, &y3, &z3, x2, y2, z2);
    return 0;
} /* t_sm_togsq__ */


/*     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX0XX */

/* Subroutine */ int t_gsq_to_sm__(real *x1, real *y1, real *z1, real *x2, 
	real *y2, real *z2)
{
    static real x3, y3, z3;
    extern /* Subroutine */ int t_gsm_to_sm__(real *, real *, real *, real *, 
	    real *, real *), t_gseq_to_gsm__(real *, real *, real *, real *, 
	    real *, real *);

    t_gseq_to_gsm__(x1, y1, z1, &x3, &y3, &z3);
    t_gsm_to_sm__(&x3, &y3, &z3, x2, y2, z2);
    return 0;
} /* t_gsq_to_sm__ */


/*     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX0XX */

/* Subroutine */ int t_mag_to_gsq__(real *x1, real *y1, real *z1, real *x2, 
	real *y2, real *z2)
{
    static real x3, y3, z3;
    extern /* Subroutine */ int t_sm_togsq__(real *, real *, real *, real *, 
	    real *, real *), t_mag_to_sm__(real *, real *, real *, real *, 
	    real *, real *);

    t_mag_to_sm__(x1, y1, z1, &x3, &y3, &z3);
    t_sm_togsq__(&x3, &y3, &z3, x2, y2, z2);
    return 0;
} /* t_mag_to_gsq__ */


/*     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX0XX */

/* Subroutine */ int t_gsq_to_mag__(real *x1, real *y1, real *z1, real *x2, 
	real *y2, real *z2)
{
    static real x3, y3, z3;
    extern /* Subroutine */ int t_sm_to_mag__(real *, real *, real *, real *, 
	    real *, real *), t_gsq_to_sm__(real *, real *, real *, real *, 
	    real *, real *);

    t_gsq_to_sm__(x1, y1, z1, &x3, &y3, &z3);
    t_sm_to_mag__(&x3, &y3, &z3, x2, y2, z2);
    return 0;
} /* t_gsq_to_mag__ */


/*     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX0XX */

/* Subroutine */ int cchalen___(char *chast, integer *nbcha, ftnlen chast_len)
{
    /* System generated locals */
    integer i__1;

    /* Builtin functions */
    integer i_len(char *, ftnlen), s_wsle(cilist *), do_lio(integer *, 
	    integer *, char *, ftnlen), e_wsle(void);
    /* Subroutine */ int s_stop(char *, ftnlen);

    /* Local variables */
    static integer i__, ii, nbc;

    /* Fortran I/O blocks */
    static cilist io___84 = { 0, 6, 0, 0, 0 };
    static cilist io___85 = { 0, 6, 0, 0, 0 };



/*     ---------------------------------------------------------------+-- */
/* *   Object : compute_character_length without end blanks */
/* *   Class  : compute modules of Rogralib Software */
/* *   Author : P. Robert, PatCie, 1992 */
/*     ---------------------------------------------------------------+-- */


/*     calcule la longueur utile d'une chaine de caracteres */
/*     les blancs de fin sont ignores */


    nbc = i_len(chast, chast_len);
    if (nbc > 255) {
	s_wsle(&io___84);
	do_lio(&c__9, &c__1, "***nbc=", (ftnlen)7);
	do_lio(&c__3, &c__1, (char *)&nbc, (ftnlen)sizeof(integer));
	do_lio(&c__9, &c__1, " > 255", (ftnlen)6);
	e_wsle();
	s_wsle(&io___85);
	do_lio(&c__9, &c__1, "   program aborted", (ftnlen)18);
	e_wsle();
	s_stop("*** program aborted", (ftnlen)19);
    }


    i__1 = nbc;
    for (i__ = 1; i__ <= i__1; ++i__) {
	ii = nbc - i__ + 1;
	if (*(unsigned char *)&chast[ii - 1] != ' ') {
	    goto L12;
	}
/* L10: */
    }
    ii = 0;
L12:

    *nbcha = ii;

    return 0;
} /* cchalen___ */

/* Main program alias */ int rocot_utility__ () { MAIN__ (); return 0; }
