00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 #include <med.h>
00024 #define MESGERR 1
00025 #include <med_utils.h>
00026 
00027 #include <string.h>
00028 
00029 
00030 int main (int argc, char **argv) {
00031   med_idt fid;
00032   const char meshname[MED_NAME_SIZE+1] = "2D unstructured mesh";
00033   const char fieldname[MED_NAME_SIZE+1] = "TEMPERATURE_FIELD";
00034   const med_int ncomponent = 1;
00035   const char componentname[MED_SNAME_SIZE+1] = "TEMPERATURE";
00036   const char componentunit[MED_SNAME_SIZE+1] = "C";
00037   const med_float tria3values_step1_profile1[9] = {1000.,1010.,1020.,    
00038                                                    4000.,4010.,4020.,    
00039                                                    8000.,8010.,8020. };
00040   const med_float tria3values_step2_profile1[24] = {1500.,1510.,1520.,    
00041                                                     0.,   0.,   0.,
00042                                                     0.,   0.,   0.,
00043                                                     4500.,4510,4520.,
00044                                                     0.,   0.,   0.,
00045                                                     0.,   0.,   0.,
00046                                                     0.,   0.,   0.,
00047                                                     8500., 8510, 8520 };
00048   const med_float tria3values_step2_profile2[32] = {   0.,   0.,   0.,  0.,
00049                                                        2500.,2510.,2520,2530., 
00050                                                        3500.,3510.,3520.,3530.,    
00051                                                        0.,   0.,   0.,  0.,
00052                                                        5500.,5510.,5520.,5530., 
00053                                                        6500.,6510.,6520.,6530., 
00054                                                        7500.,7510.,7520.,7530.,   
00055                                                        0.,   0.,   0.,   0. };
00056   const med_int ntria3 = 8;
00057   const med_int nquad4 = 4;
00058   const med_float quad4values_step1[4] = {10000., 20000., 30000., 40000.};
00059   const med_float quad4values_step2[4] = {15000., 25000., 35000., 45000.};
00060   const char profile1name[MED_NAME_SIZE+1] = "MED_TRIA3_PROFILE1";
00061   const med_int profile1[3] = {1, 4, 8}; 
00062   const med_int profile1size = 3;
00063   const char profile2name[MED_NAME_SIZE+1] = "MED_TRIA3_PROFILE2";
00064   const med_int profile2[5] = {2, 3, 5, 6, 7}; 
00065   const med_int profile2size = 5;
00066   const char localization1name[MED_NAME_SIZE+1] = "TRIA3_INTEGRATION_POINTS_3";
00067   const med_float weight1[3] = {1.0/6, 1.0/6, 1.0/6};
00068   const med_float elementcoordinate[6] = {0.0, 0.0,  1.0, 0.0,  0.0,1.0};
00069   const med_float ipoint1coordinate[6] = {1.0/6, 1.0/6,  2.0/3, 1.0/6,  1.0/6, 2.0/6};
00070   const char localization2name[MED_NAME_SIZE+1] = "TRIA3_INTEGRATION_POINTS_4";
00071   const med_float weight2[6] = {25.0/(24*4), 25.0/(24*4), 25.0/(24*4), -27.0/(24*4)};
00072   const med_float ipoint2coordinate[8] = {1.0/5, 1.0/5,  3.0/5, 1.0/5,  1.0/5, 3.0/5,  1.0/3, 1.0/3};
00073   med_int nipoint, spacedim;
00074   const char interpname[MED_NAME_SIZE+1] = "MED_TRIA3 interpolation family";
00075   int ret=-1;
00076 
00077   
00078   fid = MEDfileOpen("UsesCase_MEDfield_10.med",MED_ACC_CREAT);
00079   if (fid < 0) {
00080     MESSAGE("ERROR : file creation ...");
00081     goto ERROR;
00082   }
00083 
00084   
00085   if (MEDlinkWr(fid,meshname,"./UsesCase_MEDmesh_1.med") < 0) {
00086     MESSAGE("ERROR : create mesh link ...");
00087     goto ERROR;
00088   }
00089   
00090   
00091   if (MEDprofileWr(fid, profile1name, profile1size, profile1 ) < 0) {
00092     MESSAGE("ERROR : create profile ...");
00093     goto ERROR; 
00094   }
00095 
00096   if (MEDprofileWr(fid, profile2name, profile2size, profile2 ) < 0) {
00097     MESSAGE("ERROR : create profile ...");
00098     goto ERROR; 
00099   }
00100 
00101   
00102   spacedim = 2;
00103   nipoint = 3;
00104   if (MEDlocalizationWr(fid, localization1name, MED_TRIA3, spacedim, 
00105                         elementcoordinate, MED_FULL_INTERLACE, 
00106                         nipoint, ipoint1coordinate, weight1,
00107                         MED_NO_INTERPOLATION, MED_NO_MESH_SUPPORT) < 0) {
00108     MESSAGE("ERROR : create famlily of integration points ...");
00109     goto ERROR; 
00110   }
00111 
00112   spacedim = 2;
00113   nipoint = 4;
00114   if (MEDlocalizationWr(fid, localization2name, MED_TRIA3, spacedim, 
00115                         elementcoordinate, MED_FULL_INTERLACE, 
00116                         nipoint, ipoint2coordinate, weight2, 
00117                         MED_NO_INTERPOLATION, MED_NO_MESH_SUPPORT) < 0) {
00118     MESSAGE("ERROR : create famlily of integration points ...");
00119     goto ERROR; 
00120   }
00121 
00122   
00123 
00124 
00125 
00126 
00127 
00128  
00129   if (MEDfieldCr(fid, fieldname, MED_FLOAT64, 
00130                  ncomponent, componentname, componentunit,
00131                  "ms", meshname) < 0) {
00132     MESSAGE("ERROR : create field");
00133     goto ERROR;
00134   }
00135 
00136   
00137   
00138 
00139   if (MEDfieldInterpWr(fid,fieldname,interpname) <0) {
00140     MESSAGE("ERROR : write field interpolation family name ...");
00141     goto ERROR;
00142   }  
00143   
00144   
00145   
00146 
00147   
00148   
00149 
00150   if (MEDfieldValueWithProfileWr(fid, fieldname, 1, 1, 5.5, MED_CELL,MED_TRIA3, 
00151                                  MED_COMPACT_PFLMODE, profile1name, localization1name,    
00152                                  MED_FULL_INTERLACE, MED_ALL_CONSTITUENT, 
00153                                  ntria3, (unsigned char*) tria3values_step1_profile1) < 0) {
00154     MESSAGE("ERROR : write field values on MED_TRIA3");
00155     goto ERROR;
00156   }
00157     
00158   if (MEDfieldValueWithProfileWr(fid, fieldname, 1, 1, 5.5, MED_CELL, MED_QUAD4, 
00159                                  MED_COMPACT_PFLMODE, MED_NO_PROFILE, MED_NO_LOCALIZATION,
00160                                  MED_FULL_INTERLACE, MED_ALL_CONSTITUENT, 
00161                                  nquad4, (unsigned char*) quad4values_step1) < 0) {
00162     MESSAGE("ERROR : write field values on MED_QUAD4 ");
00163     goto ERROR;
00164   }
00165 
00166   
00167   
00168 
00169   if (MEDfieldValueWithProfileWr(fid, fieldname, 2 , 1 , 8.9 , MED_CELL, MED_TRIA3, 
00170                                  MED_GLOBAL_PFLMODE, profile1name, localization1name,    
00171                                  MED_FULL_INTERLACE, MED_ALL_CONSTITUENT,  
00172                                  ntria3, (unsigned char*) tria3values_step2_profile1) < 0) {
00173     MESSAGE("ERROR : write field values on MED_TRIA3 ...");
00174     goto ERROR;
00175   }
00176   if (MEDfieldValueWithProfileWr(fid, fieldname, 2 , 1 , 8.9 , MED_CELL, MED_TRIA3, 
00177                                  MED_GLOBAL_PFLMODE, profile2name, localization2name,    
00178                                  MED_FULL_INTERLACE, MED_ALL_CONSTITUENT,  
00179                                  ntria3, (unsigned char*) tria3values_step2_profile2) < 0) {
00180     MESSAGE("ERROR : write field values on MED_TRIA3 ...");
00181     goto ERROR;
00182   }
00183 
00184   
00185   if (MEDfieldValueWithProfileWr(fid, fieldname, 2, 1, 8.9, MED_CELL, MED_QUAD4, 
00186                                  MED_COMPACT_PFLMODE, MED_NO_PROFILE, MED_NO_LOCALIZATION,
00187                                  MED_FULL_INTERLACE, MED_ALL_CONSTITUENT,  
00188                                  nquad4, (unsigned char*) quad4values_step2) < 0) {
00189     MESSAGE("ERROR : write field values on MED_QUAD4 ... ");
00190     goto ERROR;
00191   }
00192 
00193   ret=0;
00194  ERROR:
00195   
00196   
00197   if (MEDfileClose(fid) < 0) {
00198     MESSAGE("ERROR : close file ...");             
00199     ret=-1; 
00200   } 
00201   
00202   return ret;
00203 }
00204