42 for(r=1;r<=M->
nrh;r++){
43 for(c=1;c<=M->
nch;c++){
44 S->
co[r][c]=(short)M->
co[r][c];
61 for(r=1;r<=M->
nrh;r++){
62 for(c=1;c<=M->
nch;c++){
63 L->
co[r][c]=(long)M->
co[r][c];
80 for(r=1;r<=S->
nrh;r++){
81 for(c=1;c<=S->
nch;c++){
82 M->
co[r][c]=(double)S->
co[r][c];
100 for(r=1;r<=L->
nrh;r++){
101 for(c=1;c<=L->
nch;c++){
102 M->
co[r][c]=(double)L->
co[r][c];
119 for(r=1;r<=M->
nrh;r++){
120 for(c=1;c<=M->
nch;c++){
121 if(Mref->
co[r][c]==NOVALUE){
142 for(r=1;r<=M->
nrh;r++){
143 for(c=1;c<=M->
nch;c++){
144 if(Mref->
co[r][c]==NOVALUE){
147 M->
co[r][c]=f*Mref->
co[r][c];
163 if(l<=0 || l>T->
ndh)
t_error(
"Invalid doubletensor construction");
164 if(T->
nrh!=M->
nrh)
t_error(
"Invalid doubletensor construction");
165 if(T->
nch!=M->
nch)
t_error(
"Invalid doubletensor construction");
167 for(r=1;r<=M->
nrh;r++){
168 for(c=1;c<=M->
nch;c++){
169 T->
co[l][r][c]=M->
co[r][c];
183 if(l<=0 || l>T->
ndh)
t_error(
"Invalid doubletensor extraction");
187 for(r=1;r<=M->
nrh;r++){
188 for(c=1;c<=M->
nch;c++){
189 M->
co[r][c]=T->
co[l][r][c];
207 if(l<1 || l>T->
ndh)
t_error(
"cannot extract a matrix from a tensor");
210 for(r=1;r<=T->
nrh;r++){
211 for(c=1;c<=T->
nch;c++){
212 M->
co[r][c]=T->
co[l][r][c];
228 if(lmax<1)
t_error(
"cannot build a tensor from a matrix");
229 if(l>lmax)
t_error(
"cannot build a tensor from a matrix");
233 for(r=1;r<=M->
nrh;r++){
234 for(c=1;c<=M->
nch;c++){
235 T->
co[l][r][c]=M->
co[r][c];
251 if(l<0 || l>T->
ndh)
t_error(
"cannot write a tensor from a matrix");
252 if(M->
nrh!=T->
nrh)
t_error(
"cannot write a tensor from a matrix");
253 if(M->
nch!=T->
nch)
t_error(
"cannot write a tensor from a matrix");
255 for(r=1;r<=M->
nrh;r++){
256 for(c=1;c<=M->
nch;c++){
257 T->
co[l][r][c]=M->
co[r][c];
271 if(origin->
nrh!=destination->
nrh)
t_error(
"cannot copy matrix");
272 if(origin->
nch!=destination->
nch)
t_error(
"cannot copy matrix");
273 for(r=1;r<=origin->
nrh;r++){
274 for(c=1;c<=origin->
nch;c++){
275 if(origin->
co[r][c]!=novalue){
276 destination->
co[r][c]=f*origin->
co[r][c];
278 destination->
co[r][c]=novalue;
291 if(origin->
nrh!=destination->
nrh)
t_error(
"cannot assign novalue");
292 if(origin->
nch!=destination->
nch)
t_error(
"cannot assign novalue");
293 for(r=1;r<=origin->
nrh;r++){
294 for(c=1;c<=origin->
nch;c++){
295 if(origin->
co[r][c]==novalue) destination->
co[r][c]=novalue;
321 d=(short)((i-100.0*c)/10.0);
325 c=(short)((i-1000.0*m)/100.0);
326 d=(short)((i-1000.0*m-100.0*c)/10.0);
327 u=i-1000*m-100.0*c-10*d;
349 char SSSS[ ]={
"SSSS"};
363 char SSSS[ ]={
"LSSSS"};
376 char SSSS[ ]={
"SSSS"};
396 char *ft, *grass, *esri;
401 if( (f=fopen(ft,
"r"))!=NULL ){
404 }
else if( (f=fopen(grass,
"r"))!=NULL ){
407 }
else if( (f=fopen(esri,
"r"))!=NULL ){
413 free(ft);free(grass);free(esri);
443 long index, r, c, nr, nc;
445 double Dxmap, Dymap, X0map, Y0map, novalue;
447 char *ft,*grass,*esri;
461 if(!UV)
t_error(
"UV was not allocated in read_map");
477 if(UV->
U->
co[2]!=UVref->
U->
co[2]){
478 printf(
"Dx in %s file is different from Dx in DTM file! \n",filename2);
481 if(UV->
U->
co[1]!=UVref->
U->
co[1]){
482 printf(
"Dy in %s file is different from Dy in DTM file! \n",filename2);
485 if(UV->
U->
co[4]!=UVref->
U->
co[4]){
486 printf(
"X0 in %s file is different from X0 in DTM file! \n",filename2);
489 if(UV->
U->
co[3]!=UVref->
U->
co[3]){
490 printf(
"Y0 in %s file is different from Y0 in DTM file! \n",filename2);
494 printf(
"Number of rows in %s file is not consistent with DTM file! \n",filename2);
498 printf(
"Number of columns in %s file is not consistent with DTM file! \n",filename2);
503 for(r=1;r<=M->
nrh;r++){
504 for(c=1;c<=M->
nch;c++){
505 if(M->
co[r][c]==UV->
V->
co[2]) M->
co[r][c]=UVref->
V->
co[2];
507 if(M->
co[r][c]==UVref->
V->
co[2] && Mref->
co[r][c]!=UVref->
V->
co[2]){
508 printf(
"Novalues not consistent in %s file",filename2);
509 printf(
"\nr:%ld c:%ld Mref:%f M:%f\n",r,c,Mref->
co[r][c], M->
co[r][c]);
512 if(M->
co[r][c]!=UVref->
V->
co[2] && Mref->
co[r][c]==UVref->
V->
co[2]) M->
co[r][c]=UVref->
V->
co[2];
514 if(M->
co[r][c]==UVref->
V->
co[2] && Mref->
co[r][c]!=UVref->
V->
co[2]){
515 printf(
"Novalues not consistent in %s file",filename2);
516 printf(
"\nr:%ld c:%ld Mref:%f M:%f\n",r,c,Mref->
co[r][c], M->
co[r][c]);
530 novalue=UVref->
V->
co[2];
534 header = (
double *) malloc(6*
sizeof(
double));
540 Dxmap=(header[2]-header[3])/((
long)header[5]);
541 Dymap=(header[0]-header[1])/((
long)header[4]);
555 printf(
"The file %s doesn't exist\n",filename);
562 if(Dxmap!=UVref->
U->
co[2]){
563 printf(
"Dx in %s file is different from Dx in DTM file! \n",filename2);
566 if(Dymap!=UVref->
U->
co[1]){
567 printf(
"Dy:%f in %s file is different from Dy:%f in DTM file! \n",Dymap,filename2,UVref->
U->
co[1]);
570 if(X0map!=UVref->
U->
co[4]){
571 printf(
"X0 in %s file is different from X0 in DTM file! \n",filename2);
574 if(Y0map!=UVref->
U->
co[3]){
575 printf(
"Y0 in %s file is different from Y0 in DTM file! \n",filename2);
579 printf(
"Number of rows in %s file (%ld) is not consistent with DTM file (%ld)! \n",filename2,nr,Mref->
nrh);
583 printf(
"Number of columns in %s file is not consistent with DTM file! \n",filename2);
590 UVref->
U->
co[2]=Dxmap;
591 UVref->
U->
co[1]=Dymap;
592 UVref->
U->
co[4]=X0map;
593 UVref->
U->
co[3]=Y0map;
595 UVref->
V->
co[2]=novalue;
602 M->
co[r][c]=m[(r-1)*nc+c-1];
604 if (M->
co[r][c]==UVref->
V->
co[2] && Mref->
co[r][c]!=UVref->
V->
co[2]){
605 printf(
"Novalues not consistent in %s file",filename2);
606 printf(
"\nr:%ld c:%ld Mref:%f M:%f\n",r,c,Mref->
co[r][c], M->
co[r][c]);
609 if(M->
co[r][c]!=UVref->
V->
co[2] && Mref->
co[r][c]==UVref->
V->
co[2]) M->
co[r][c]=UVref->
V->
co[2];
616 free(ft);free(grass);free(esri);
627 char SSSS[ ]={
"LSSSS"};
647 if(nl<1)
t_error(
"The dimension of the tensor must be greater than or equal to 1");
669 char SSSSLLLLL[ ]={
"SSSSLLLLL"};
675 if(i<0 || lmax<1)
t_error(
"cannot read a tensor with null or negative columns");
679 for(l=1;l<=lmax;l++){
721 char SSSS[ ]={
"SSSS"};
738 char SSSSLLLLL[ ]={
"SSSSLLLLL"};
739 char SSSS[ ]={
"SSSS"};
754 for(r=1;r<=T->
nrh;r++){
755 for(c=1;c<=T->
nch;c++){
756 M->
co[r][c]=T->
co[l][r][c];
773 char SSSSLLLLL[ ]={
"LLLLLNNNNN"};
774 char SSSS[ ]={
"NNNN"};
789 for(r=1;r<=T->
nrh;r++){
790 for(c=1;c<=T->
nch;c++){
791 M->
co[r][c]=T->
co[l][r][c];
807 for(l=1;l<=T->
ndh;l++){