#include #include #include #include /* fst2xml : Convertisseur de fichier standard RPN version 2000 a XML Auteur: Yves Chartier Statut: Embryonnaire */ #define NCARMAX 256 extern void c_ccard(char **argv,int argc,char **cle,char val[][NCARMAX], char **def,int n,int *npos); void nettoyer(char chaine[]); fst2bin(int argc, char **argv) { char fstFile[256],xmlFile[256]; char encoding[16]; char format[32]; int ok, iun, key; char *liste[4], lcl_liste[4][256], *def[4], lcl_def[4][16], val[4][256]; int i, n, npos, nptsRLE; int ni, nj, nk; int ier, ip1, ip2, ip3, ig1, ig2, ig3, ig4; int dateo, datev, datyp, deet,nbits, npak, npas,swa, lng; int dltf, ubc, extra1, extra2, extra3; char etiket[16], nomvar[8], typvar[4], grtyp[2]; char xmldateo[32], xmldatev[32]; char xmlip1[32], xmlip2[32], xmlip3[32]; double nhours; float *fld; FILE *fd; char nomFichier[256]; strcpy(lcl_liste[0], "fst."); liste[0] = (char *) lcl_liste[0]; strcpy(lcl_def[0],"bidon.fst"); def[0] = (char *) lcl_def[0]; strcpy(val[0],def[0]); npos = 0; c_ccard(argv,argc,(char **) liste,val, (char **) def,1,&npos); strcpy(fstFile, val[0]); iun = 1; c_fnom(iun,fstFile,"RND+R/O",0); ier = c_fstouv(iun, "RND"); key = c_fstinf(iun,&ni,&nj,&nk,-1," ",-1,-1,-1," "," "); do { strcpy(etiket, " "); strcpy(nomvar, " "); strcpy(typvar, " "); strcpy(grtyp, " "); ier = c_fstprm(key, &dateo, &deet, &npas, &ni, &nj, &nk, &nbits, &datyp, &ip1, &ip2, &ip3, typvar, nomvar, etiket, grtyp, &ig1, &ig2, &ig3, &ig4, &swa, &lng, &dltf, &ubc, &extra1, &extra2, &extra3); etiket[12] = '\0'; nomvar[4] = '\0'; typvar[2] = '\0'; nettoyer(nomvar); nettoyer(typvar); nettoyer(etiket); sprintf(nomFichier,"%s-%s-%04d-%03d-%03d-%08d-%s",nomvar,typvar,ip1,ip2,ip3,dateo,etiket); fld = (float *) malloc(ni*nj*nk*sizeof(float)); ier = c_fstluk(fld, key, &ni, &nj, &nk); fd = fopen(nomFichier, "w"); fwrite(&ni, sizeof(int), 1, fd); fwrite(&nj, sizeof(int), 1, fd); fwrite(&nk, sizeof(int), 1, fd); fwrite(fld, sizeof(float), ni*nj*nk, fd); fclose(fd); key=c_fstsui(iun,&ni,&nj,&nk); } while (key >= 0); ier = c_fstfrm(iun); ier = c_fclos(iun); } void nettoyer(char chaine[]) { int longueur; longueur = strlen(chaine)-1; while (chaine[longueur] == ' ' || chaine[longueur] == '\0') { chaine[longueur] = '\0'; longueur--; } }