[11991] | 1 | Index: /proj/ice/larour/issm-uci-clean/trunk-jpl/src/c/shared/Exp/DomainOutlineRead.cpp.bak
|
---|
| 2 | ===================================================================
|
---|
| 3 | --- /proj/ice/larour/issm-uci-clean/trunk-jpl/src/c/shared/Exp/DomainOutlineRead.cpp.bak (revision 11955)
|
---|
| 4 | +++ /proj/ice/larour/issm-uci-clean/trunk-jpl/src/c/shared/Exp/DomainOutlineRead.cpp.bak (revision 11956)
|
---|
| 5 | @@ -1,162 +0,0 @@
|
---|
| 6 | -/*!\file: DomainOutlineRead.cpp
|
---|
| 7 | - * \brief DomainOutlineRead.c: read the vertex coordinates defined in a domain
|
---|
| 8 | - * outline from Argus (.exp file). The first contour in the file is for
|
---|
| 9 | - * the outside domain outline. The following contours represent holes in
|
---|
| 10 | - * the domain.
|
---|
| 11 | - */
|
---|
| 12 | -
|
---|
| 13 | -#include <stdio.h>
|
---|
| 14 | -#include "../Alloc/alloc.h"
|
---|
| 15 | -#include "../../include/include.h"
|
---|
| 16 | -#include "../../objects/objects.h"
|
---|
| 17 | -#include "../Exceptions/exceptions.h"
|
---|
| 18 | -#include "../../Container/DataSet.h"
|
---|
| 19 | -
|
---|
| 20 | -int DomainOutlineRead(int* pnprof,int** pprofnvertices,double*** ppprofx,double*** ppprofy,bool** pclosed,char* domainname,bool whole=true){
|
---|
| 21 | -
|
---|
| 22 | -
|
---|
| 23 | - /*indexing: */
|
---|
| 24 | - int i,counter;
|
---|
| 25 | -
|
---|
| 26 | - /*I/O: */
|
---|
| 27 | - FILE* fid=NULL;
|
---|
| 28 | - char chardummy[256];
|
---|
| 29 | - double ddummy;
|
---|
| 30 | -
|
---|
| 31 | - /*output: */
|
---|
| 32 | - int nprof; //number of profiles in the domainname file
|
---|
| 33 | - int* profnvertices=NULL; //array holding the number of vertices for the nprof profiles
|
---|
| 34 | - double** pprofx=NULL; //array of profiles x coordinates
|
---|
| 35 | - double** pprofy=NULL; //array of profiles y coordinates
|
---|
| 36 | - bool* closed=NULL; //array holding closed flags for the nprof profiles
|
---|
| 37 | -
|
---|
| 38 | - /*For each profile: */
|
---|
| 39 | - int n;
|
---|
| 40 | - double* x=NULL;
|
---|
| 41 | - double* y=NULL;
|
---|
| 42 | - bool cl;
|
---|
| 43 | -
|
---|
| 44 | - /*open domain outline file for reading: */
|
---|
| 45 | - if ((fid=fopen(domainname,"r"))==NULL){
|
---|
| 46 | - _error_("%s%s","could not find domain file ",domainname);
|
---|
| 47 | - }
|
---|
| 48 | -
|
---|
| 49 | - /*Do a first pass through the domainname file, to figure out how many profiles
|
---|
| 50 | - *we need to read: */
|
---|
| 51 | - nprof=1;
|
---|
| 52 | - for(;;){
|
---|
| 53 | - fscanf(fid,"%256s %256s\n",chardummy,chardummy);
|
---|
| 54 | - fscanf(fid,"%256s %256s\n",chardummy,chardummy);
|
---|
| 55 | - fscanf(fid,"%256s %256s %256s %256s\n",chardummy,chardummy,chardummy,chardummy);
|
---|
| 56 | - fscanf(fid,"%20u %256s\n",&n,chardummy);
|
---|
| 57 | - fscanf(fid,"%256s %256s %256s %256s %256s\n",chardummy,chardummy,chardummy,chardummy,chardummy);
|
---|
| 58 | - for (i=0;i<n;i++){
|
---|
| 59 | - fscanf(fid,"%20lf %20lf\n",&ddummy,&ddummy);
|
---|
| 60 | - }
|
---|
| 61 | - /*Ok, we have faked one profile reading, check whether we are at the end of the file, otherwise, keep fake reading next profile:*/
|
---|
| 62 | - if (feof(fid)){
|
---|
| 63 | - break;
|
---|
| 64 | - }
|
---|
| 65 | - nprof++;
|
---|
| 66 | - }
|
---|
| 67 | -
|
---|
| 68 | - /*Allocate and initialize all the profiles: */
|
---|
| 69 | - profnvertices=(int*)xmalloc(nprof*sizeof(int));
|
---|
| 70 | - pprofx=(double**)xmalloc(nprof*sizeof(double*));
|
---|
| 71 | - pprofy=(double**)xmalloc(nprof*sizeof(double*));
|
---|
| 72 | - for (i=0;i<nprof;i++){
|
---|
| 73 | - pprofx[i]=NULL;
|
---|
| 74 | - pprofy[i]=NULL;
|
---|
| 75 | - }
|
---|
| 76 | - closed=(bool*)xmalloc(nprof*sizeof(bool));
|
---|
| 77 | -
|
---|
| 78 | - /*Reaset file pointer to beginning of file: */
|
---|
| 79 | - fseek(fid,0,SEEK_SET);
|
---|
| 80 | -
|
---|
| 81 | - /*Start reading profiles: */
|
---|
| 82 | - for(counter=0;counter<nprof;counter++){
|
---|
| 83 | -
|
---|
| 84 | - /*Skip header: */
|
---|
| 85 | - fscanf(fid,"%256s %256s\n",chardummy,chardummy);
|
---|
| 86 | - fscanf(fid,"%256s %256s\n",chardummy,chardummy);
|
---|
| 87 | - fscanf(fid,"%256s %256s %256s %256s\n",chardummy,chardummy,chardummy,chardummy);
|
---|
| 88 | -
|
---|
| 89 | - /*Get number of profile vertices: */
|
---|
| 90 | - fscanf(fid,"%20u %256s\n",&n,chardummy);
|
---|
| 91 | -
|
---|
| 92 | - /*Skip next line: */
|
---|
| 93 | - fscanf(fid,"%256s %256s %256s %256s %256s\n",chardummy,chardummy,chardummy,chardummy,chardummy);
|
---|
| 94 | -
|
---|
| 95 | - /*Allocate vertices: */
|
---|
| 96 | - printf("number of n: %i\n",n);
|
---|
| 97 | - x=(double*)xmalloc(n*sizeof(double));
|
---|
| 98 | - y=(double*)xmalloc(n*sizeof(double));
|
---|
| 99 | -
|
---|
| 100 | -
|
---|
| 101 | - /*Read vertices: */
|
---|
| 102 | - for (i=0;i<n;i++){
|
---|
| 103 | - fscanf(fid,"%20lf %20lf\n",&x[i],&y[i]);
|
---|
| 104 | - }
|
---|
| 105 | -
|
---|
| 106 | - /*Now check that we are dealing with open contours: */
|
---|
| 107 | - cl=false;
|
---|
| 108 | - if((x[0]==x[n-1]) && (y[0]==y[n-1])){
|
---|
| 109 | - cl=true;
|
---|
| 110 | - if (!whole) {
|
---|
| 111 | - n=n-1;
|
---|
| 112 | - }
|
---|
| 113 | - }
|
---|
| 114 | -
|
---|
| 115 | - /*Assign pointers: */
|
---|
| 116 | - profnvertices[counter]=n;
|
---|
| 117 | - pprofx[counter]=x;
|
---|
| 118 | - pprofy[counter]=y;
|
---|
| 119 | - closed[counter]=cl;
|
---|
| 120 | - }
|
---|
| 121 | -
|
---|
| 122 | - /*close domain outline file: */
|
---|
| 123 | - fclose(fid);
|
---|
| 124 | -
|
---|
| 125 | - /*Assign output pointers: */
|
---|
| 126 | - *pnprof=nprof;
|
---|
| 127 | - *pprofnvertices=profnvertices;
|
---|
| 128 | - *ppprofx=pprofx;
|
---|
| 129 | - *ppprofy=pprofy;
|
---|
| 130 | - if(pclosed)*pclosed=closed;
|
---|
| 131 | - else xfree((void**)&closed);
|
---|
| 132 | -}
|
---|
| 133 | -
|
---|
| 134 | -DataSet* DomainOutlineRead(char* domainname,bool whole=true){
|
---|
| 135 | -
|
---|
| 136 | - /*indexing: */
|
---|
| 137 | - int i;
|
---|
| 138 | -
|
---|
| 139 | - /*intermediary: */
|
---|
| 140 | - int nprof;
|
---|
| 141 | - int* profnvertices=NULL;
|
---|
| 142 | - double** pprofx=NULL;
|
---|
| 143 | - double** pprofy=NULL;
|
---|
| 144 | -
|
---|
| 145 | - Contour* contour=NULL;
|
---|
| 146 | -
|
---|
| 147 | - /*output: */
|
---|
| 148 | - DataSet* domain=NULL;
|
---|
| 149 | -
|
---|
| 150 | - /*get domain outline from intermediary function:*/
|
---|
| 151 | - DomainOutlineRead(&nprof,&profnvertices,&pprofx, &pprofy, NULL,domainname,whole);
|
---|
| 152 | -
|
---|
| 153 | - double* a=pprofx[0]; for(i=0;i<4;i++)printf("%g\n",a[i]);
|
---|
| 154 | - a=pprofy[0]; for(i=0;i<4;i++)printf("%g\n",a[i]);
|
---|
| 155 | - printf("%i %i\n",profnvertices[0],nprof);
|
---|
| 156 | -
|
---|
| 157 | - /*now create dataset of contours: */
|
---|
| 158 | - domain=new DataSet(0);
|
---|
| 159 | - printf("ok1\n");
|
---|
| 160 | -
|
---|
| 161 | - for(i=0;i<nprof;i++){
|
---|
| 162 | - domain->AddObject(new Contour(i,profnvertices[i],pprofx[i],pprofy[i],1));
|
---|
| 163 | - }
|
---|
| 164 | - printf("ok2\n");
|
---|
| 165 | -
|
---|
| 166 | - return domain;
|
---|
| 167 | -}
|
---|
| 168 | Index: /proj/ice/larour/issm-uci-clean/trunk-jpl/src/c/objects/Contour.h
|
---|
| 169 | ===================================================================
|
---|
| 170 | --- /proj/ice/larour/issm-uci-clean/trunk-jpl/src/c/objects/Contour.h (revision 11955)
|
---|
| 171 | +++ /proj/ice/larour/issm-uci-clean/trunk-jpl/src/c/objects/Contour.h (revision 11956)
|
---|
| 172 | @@ -18,7 +18,7 @@
|
---|
| 173 | public:
|
---|
| 174 |
|
---|
| 175 | int id;
|
---|
| 176 | - int nods; //number of vertices in the contour
|
---|
| 177 | + int nods; //number of vertices in the contour
|
---|
| 178 | double* x;
|
---|
| 179 | double* y;
|
---|
| 180 | bool closed; //is this contour closed?
|
---|