MED21datasetNumLire.c

Aller à la documentation de ce fichier.
00001 /*  This file is part of MED.
00002  *
00003  *  COPYRIGHT (C) 1999 - 2015  EDF R&D, CEA/DEN
00004  *  MED is free software: you can redistribute it and/or modify
00005  *  it under the terms of the GNU Lesser General Public License as published by
00006  *  the Free Software Foundation, either version 3 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  MED is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU Lesser General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU Lesser General Public License
00015  *  along with MED.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 
00018 
00019 #include "med_config.h"
00020 #include <med.h>
00021 #include <med_outils.h>
00022 #include <hdf5.h>
00023 #include <string.h>
00024 
00025 med_err _MED21datasetNumLire(med_idt pere,char *nom,med_type_champ type,
00026                            med_mode_switch interlace, med_size nbdim, med_size fixdim,
00027                            med_size psize, med_ssize * pfltab, med_int ngauss,
00028                            unsigned char *val,hid_t hdf_file)
00029 {
00030   med_idt    dataset, dataspace = 0, memspace = 0;
00031   med_size  start_mem[1],start_data[1],*pflmem=0,*pfldsk=0;
00032   med_size   stride[1],count[1],pcount[1],size[1],pflsize[1];
00033   med_err    ret;
00034   int        i,j,index,type_hdf;
00035   hid_t      datatype;
00036   size_t     typesize;
00037   int        dim, firstdim, dimutil, lastdim;
00038   med_mode_profil pflmod;
00039 
00040   /* Verify fixdim is between [0, nbdim] ( 0 is MED_ALL ) */
00041   if (  fixdim > nbdim ) 
00042     return -1;
00043  
00044   /* block pflmod to MED_COMPACT (until med2.2) */
00045   pflmod = MED_COMPACT;
00046 
00047   switch(type)
00048     {
00049     case MED_FLOAT64 :
00050       if (H5Tequal(hdf_file,H5T_IEEE_F64BE))
00051         type_hdf = H5T_IEEE_F64LE;
00052       if (H5Tequal(hdf_file,H5T_IEEE_F64LE))
00053         type_hdf = H5T_IEEE_F64BE;
00054       break;
00055 
00056     case MED_INT32 :
00057       type_hdf = H5T_NATIVE_INT;
00058       break;
00059 
00060     case MED_INT64 :
00061       type_hdf = H5T_NATIVE_LONG;
00062       break;
00063 
00064     default :
00065       return -1;
00066     }
00067 
00068   /* Ouverture du Dataset à lire */
00069   if ((dataset = H5Dopen(pere,nom)) < 0)
00070     return -1;
00071 
00072   /* Interrogation de la taille du dataset */
00073   if ( (datatype  = H5Dget_type(dataset )) < 0)  return -1;
00074   if ( (typesize  = H5Tget_size(datatype)) == 0) return -1;
00075   size[0] = H5Dget_storage_size(dataset) / typesize; 
00076   if ( H5Tclose(datatype) < 0) return -1;
00077 
00078   /* Create dataspace */
00079   if ((dataspace = H5Screate_simple(1,size,NULL)) < 0)
00080     return -1;
00081   
00082   switch(interlace)
00083     {
00084     case MED_FULL_INTERLACE :
00085 
00086       /*Initialisation des indices de boucle du traitement de l'entrelacement en fonction de la dimension fixee*/
00087       if ( fixdim != MED_ALL) 
00088         { 
00089           firstdim = fixdim-1;
00090           lastdim  = fixdim;
00091           dimutil  = 1;
00092         } else  {
00093           firstdim = 0;
00094           lastdim = nbdim;
00095           dimutil  = nbdim; 
00096         }
00097 
00098       count [0] = (*size)/(nbdim);
00099       
00100 
00101       /*rem: Pas de vérification de l'assertion (*size)=n*nbdim */
00102       if ( psize == MED_NOPF ) {  
00103 
00104       /* Creation d'un data space mémoire de dimension 1, de longeur size, et de longeur maxi size */
00105       if ( (memspace = H5Screate_simple (1, size, NULL)) <0)
00106         return -1;
00107 
00108         stride[0] = nbdim;  
00109 
00110         for (dim=firstdim; dim < lastdim; dim++) {
00111                   
00112           start_mem[0] = dim;
00113           if ( (ret = H5Sselect_hyperslab (memspace, H5S_SELECT_SET, start_mem, stride, 
00114                                            count, NULL)) <0)
00115             return -1; 
00116           
00117           start_data[0] = dim*count[0];
00118           if ( (ret = H5Sselect_hyperslab (dataspace, H5S_SELECT_SET, start_data, NULL, 
00119                                            count, NULL)) <0)
00120             return -1; 
00121           
00122           if ((ret = H5Dread(dataset,type_hdf,memspace,dataspace,
00123                              H5P_DEFAULT, val)) < 0)
00124             return -1;
00125         }
00126         
00127       } else {
00128 
00129         pflsize [0] = psize*ngauss*nbdim;
00130         pcount  [0] = psize*ngauss*dimutil;
00131         pflmem     = (med_size *) malloc (sizeof(med_size)*pcount[0]);
00132         pfldsk     = (med_size *) malloc (sizeof(med_size)*pcount[0]);
00133         
00134         switch(pflmod)
00135           { /* switch pflmod pour FULL_INTERLACE*/
00136           case MED_GLOBAL :
00137 
00138             /* Creation d'un data space mémoire de dimension 1, de longeur size, et de longeur maxi size */
00139             if ( (memspace = H5Screate_simple (1, size, NULL)) <0)
00140               return -1;
00141 
00142             for (dim=firstdim; dim < lastdim; dim++) {
00143               
00144               for (i=0; i < psize; i++)              /* i balaye les élements du profil */
00145                 for (j=0; j < ngauss; j++) {         
00146                   index = i*ngauss+j + (dim-firstdim)*(psize*ngauss);
00147                   pflmem[index] = (pfltab[i]-1)*ngauss*nbdim + j*nbdim+dim;
00148                   pfldsk[index] = dim*count[0] + (pfltab[i]-1)*ngauss+j;             
00149                 }
00150             }
00151             
00152             if ( (ret = H5Sselect_elements(memspace ,H5S_SELECT_SET, pcount[0], HDF5_SELECT_BUG pflmem ) ) <0) 
00153               return -1; 
00154             
00155             if ( (ret = H5Sselect_elements(dataspace,H5S_SELECT_SET, pcount[0], HDF5_SELECT_BUG pfldsk ) ) <0) 
00156               return -1; 
00157             
00158             break;
00159         
00160           case MED_COMPACT :
00161         
00162             /* Creation d'un data space mémoire de dimension 1, de la longeur du profil          */
00163             /* La dimension utilisée est ici nbdim, même pour un profil compact on suppose       */
00164             /*  que l'utilisateur a toutes les coordonées stockées, même si il en demande qu'une */ 
00165             
00166             if ( (memspace = H5Screate_simple (1, pflsize, NULL)) <0)
00167               return -1;
00168             
00169             for (dim=firstdim; dim < lastdim; dim++) {
00170               
00171               for (i=0; i < psize; i++)              /* i balaye les élements du profil */
00172                 for (j=0; j < ngauss; j++) {         
00173                   index = i*ngauss+j + (dim-firstdim)*(psize*ngauss);
00174                   pflmem[index] = i*ngauss*nbdim + j*nbdim+dim;
00175                   pfldsk[index] = dim*count[0] + (pfltab[i]-1)*ngauss+j;             
00176                 }             
00177             }
00178             
00179             if ( (ret = H5Sselect_elements(memspace ,H5S_SELECT_SET, pcount[0], HDF5_SELECT_BUG pflmem ) ) <0) 
00180               return -1; 
00181             
00182             if ( (ret = H5Sselect_elements(dataspace,H5S_SELECT_SET, pcount[0], HDF5_SELECT_BUG pfldsk ) ) <0) 
00183               return -1; 
00184             
00185             break;
00186 
00187           default :
00188             return -1; 
00189           }
00190         
00191         if ((ret = H5Dread(dataset,type_hdf,memspace,dataspace,H5P_DEFAULT, val)) < 0)
00192           return -1;
00193         
00194         free(pflmem);
00195         free(pfldsk);
00196       }
00197       
00198       break;
00199       
00200     case MED_NO_INTERLACE :
00201 
00202       /*Initialisation des indices de boucle du traitement de l'entrelacement en fonction de la dimension fixee*/
00203 
00204       count[0] = (*size)/nbdim;
00205       
00206       if ( psize == MED_NOPF ) {  
00207         
00208         if ( fixdim != MED_ALL) 
00209           start_data[0] = (fixdim-1)*count[0];
00210         else {
00211           count[0] = *size;
00212           start_data[0] =  0;
00213         };
00214         
00215         if ( (ret = H5Sselect_hyperslab (dataspace, H5S_SELECT_SET, start_data, NULL, 
00216                                          count, NULL)) <0)
00217           return -1; 
00218         
00219         if ((ret = H5Dread(dataset,type_hdf,dataspace,dataspace,
00220                            H5P_DEFAULT, val)) < 0)
00221           return -1;
00222         
00223       } else {
00224 
00225         if ( fixdim != MED_ALL) 
00226           { 
00227             firstdim = fixdim-1;
00228             lastdim  = fixdim;
00229             dimutil  = 1;
00230           } else        {
00231             firstdim = 0;
00232             lastdim  = nbdim;
00233             dimutil  = nbdim; 
00234           }
00235 
00236         pflsize [0] = psize*ngauss*nbdim;       
00237         pcount  [0] = psize*ngauss*dimutil; /* nom pas très coherent avec count !!! A revoir */        
00238         pfldsk      = (med_size *) malloc(sizeof(med_size)*pcount[0]);
00239         
00240         switch(pflmod)
00241           { /*switch plfmod pour NO_INTERLACE */
00242           case MED_GLOBAL :
00243             
00244             for (dim=firstdim; dim < lastdim; dim++) {
00245               
00246               for (i=0; i < psize; i++)              /* i balaye le nbre d'élements du profil                */
00247                 for (j=0; j < ngauss; j++) { 
00248                   index = i*ngauss+j + (dim-firstdim)*(psize*ngauss);
00249                   pfldsk[index] = dim*count[0]+(pfltab[i]-1)*ngauss+j;      
00250                 }
00251             }
00252             
00253             if ( (ret = H5Sselect_elements(dataspace,H5S_SELECT_SET,pcount[0], HDF5_SELECT_BUG pfldsk ) ) <0) 
00254               return -1;
00255             
00256             if ((ret = H5Dread(dataset,type_hdf,dataspace,dataspace,H5P_DEFAULT, val)) < 0)
00257               return -1;
00258               
00259             break;
00260             
00261           case MED_COMPACT :
00262             
00263             /* Creation d'un data space mémoire de dimension 1, de la longeur du profil          */
00264             /* La dimension utilisée est ici nbdim, même pour un profil compact on suppose       */
00265             /*  que l'utilisateur a toutes les coordonées stockées, même si il en demande qu'une */ 
00266 
00267             if ( (memspace = H5Screate_simple (1, pflsize, NULL)) <0)
00268               return -1;
00269 
00270             pflmem     = (med_size *) malloc (sizeof(med_size)*pcount[0]);
00271             
00272             /* Le profil COMPACT est contigüe, mais il est possible que l'on selectionne uniquemenent une dimension*/
00273 
00274             for (dim=firstdim; dim < lastdim; dim++) {
00275               
00276               for (i=0; i < psize; i++)              /* i balaye le nbre d'élements du profil                */
00277                 for (j=0; j < ngauss; j++) {
00278                   index = i*ngauss+j + (dim-firstdim)*(psize*ngauss);
00279                   pflmem[index] = dim*(psize*ngauss) + (pfltab[i]-1)*ngauss+j;
00280                   pfldsk[index] = dim*count[0]  + (pfltab[i]-1)*ngauss+j;           
00281                 }
00282             }
00283             
00284             if ( (ret = H5Sselect_elements(memspace ,H5S_SELECT_SET, pcount[0], HDF5_SELECT_BUG pflmem ) ) <0) 
00285               return -1; 
00286             
00287             if ( (ret = H5Sselect_elements(dataspace,H5S_SELECT_SET,pcount[0], HDF5_SELECT_BUG pfldsk ) ) <0) 
00288               return -1;          
00289             
00290             if ((ret = H5Dread(dataset,type_hdf,memspace,dataspace,H5P_DEFAULT, val)) < 0)
00291               return -1;
00292             
00293             break;
00294             
00295           default :
00296             return -1;      
00297             
00298           }
00299         
00300         free(pfldsk);
00301         
00302       };
00303       
00304       break;
00305       
00306     default :
00307       return -1;
00308     }
00309   
00310   
00311 
00312   if (memspace) 
00313     if ((ret = H5Sclose(memspace)) < 0)
00314       return -1;
00315 
00316   if ((ret = H5Sclose(dataspace)) < 0)
00317     return -1;
00318   
00319   if ((ret = H5Dclose(dataset)) < 0)
00320     return -1;      
00321 
00322   return 0;
00323 }

Généré le Thu Oct 8 14:26:16 2015 pour MED fichier par  doxygen 1.6.1