TheBoussinesqModel  3.2.1
 All Data Structures Files Functions Variables Typedefs Macros Pages
t_io.c
Go to the documentation of this file.
1 #include "turtle.h"
2 #include "t_utilities.h"
3 #include "tensor3D.h"
4 
5 char *WORKING_DIRECTORY='\0';
6 
7 /*WORKING_POSITION=SEEK_SET;*/
8 
9 FILE * EXTERNAL_FILE;
10 
12 
14 
15 long int EXTERNAL_FILE_POSITION=SEEK_SET;
16 
18 
19 
20 
21 short OPENYES=0;
22 
27 
28 
29 t_keywords T_KEYWORDS={{"2","ascii","binary"},
30 
31  {"7","char","short","int","long","float","double","string"},
32 
33  {"5","array","vector","matrix","list","tensor"},
34 
35  {"2","->","<-"},
36 
37  {"2"," ",","},
38 
39  {"2","{","}"}};
40 
41 
42 
43 
45 FILE *t_fopen(const char *name,const char *mode)
46 /* Safe file open */
47 {
48 
49 //char newname[256];
50 FILE *fp=NULL;
51 
52 
53 /*if(strcmp(mode,"w")==0 || strcmp(mode,"wb")==0){
54  if((fp=fopen(name,"r"))!=NULL ){
55  // The file already exist
56  //printf("\nWarning::Overwriting the file %s \n",name);
57  strcpy(newname,name);
58  strcat(newname,".old");
59  t_fclose(fp);
60  //rename(name,newname);
61  }
62 }*/
63 
64 if((fp=fopen(name,mode))==NULL){
65  printf("%s",name);
66  t_error(" The specified file could not be opened ");
67 
68  return NULL;
69 
70 }else{
71 
72  return fp;
73 
74 }
75 
76 }
77 
78 
79 
81 FILE * t_fclose(FILE * stream)
82 /* Safe file close */
83 {
84 
85 
86 if(stream==NULL){
87  printf(" An attemp was made to close an already closed file ");
88 }else{
89  fclose(stream);
90 }
91 
92  return NULL;
93 
94 }
95 
96 
97 
98 
100 long read_shortvector_elements(FILE *input, SHORTVECTOR *v,char *mode)
106 {
107 
108 
109 long count=0,i,tmp=0;
110 const char ascii[2]="a",binary[2]="b";
111 
112 if(input==NULL){
113  t_error("The input file was not opened properly or is not allocated");
114 }else if (v==NULL || v->co==NULL || (v->isdynamic)!=1){
115  t_error("The vector was not allocated properly");
116 }else if(v->nl > v->nh){
117  t_error("The vector has no proper dimensions");
118 } else if(strcmp(mode,ascii)==0){
119 
120  for(i=v->nl;i<=v->nh;i++){
121  tmp=fscanf(input,"%hd",&(v->co[i]));
122  if(tmp!=EOF){
123  count+=tmp;
124  }else{
125  printf("Error in stored data::Unespected End of file encountered");
126  printf(" after position %ld\n",count);
127  return -count;
128  }
129  }
130 } else if(strcmp(mode,binary)){
131  count=fread((short *)&(v->co[v->nl]),sizeof(short),v->nh-v->nl+1,input);
132 }else{
133  t_error("Error in reading mode::Mode not supported");
134 }
135 
136 if(count!=(v->nh-v->nl+1)){
137  printf("Error in stored data::Stored data number does not match the request");
138  return -count;
139 } else {
140  return count;
141 }
142 
143 }
144 
146 long write_shortvector_elements(FILE * output, SHORTVECTOR *v, long maxcols)
149 {
150 
151 long i,tmp=0;//count=0;
152 
153 
154 if(output==NULL){
155  t_error("The input file was not opened properly");
156 }else if (v==NULL || v->co==NULL || v->isdynamic !=1){
157  t_error("The vector was not allocated properly");
158 }else if(v->nl > v->nh ){
159  t_error("The vector has no proper dimensions");
160 } else {
161 
162  for(i=v->nl;i<=v->nh;i++){
163  tmp=fprintf(output,"%d ",v->co[i]);
164  if(i%maxcols==0 && i!=(v->nh)) putc('\n',output);
165  if(tmp==EOF){
166  printf("Error in storing data::Unespected End of file encountered\n");
167  return EOF;
168 
169  }
170 
171  }
172  putc('\n',output);
173 }
174 
175 return OK;
176 
177 }
178 
184 {
185 
186 
187 long count=0,tmp=0;
188 
189 
190 
191 if(output==NULL){
192  t_error("The input file was not opened properly");
193 }else if (v==NULL || v->co==NULL || v->isdynamic !=1){
194  t_error("The vector was not allocated properly");
195 }else if(v->nl > v->nh ){
196  t_error("The vector has no proper dimensions");
197 } else {
198  tmp=fwrite((short *)&(v->co[v->nl]),sizeof(short),v->nh-v->nl+1,output);
199  if(tmp!=EOF){
200  count+=tmp;
201  }else{
202  printf("Error in stored data::Unespected End of file encountered");
203  printf("after position %ld\n",count);
204  return -count;
205 
206  }
207 }
208 
209 if(count!=(v->nh-v->nl+1)){
210  printf("Error in stored data::Stored data number does not match the request");
211  return -count;
212 } else {
213  return count;
214 }
215 
216 
217 }
218 
219 
222 /* Write a vector of short int to the standard output */
223 
224 {
225 
226 long i;
227 
228 putchar('\n');
229 
230 if (v==NULL || v->co==NULL || v->isdynamic !=1){
231  t_error("The vector was not allocated properly");
232 }else if(v->nl > v->nh ){
233  t_error("The vector has no proper dimensions");
234 } else {
235 
236  for(i=v->nl;i<=v->nh;i++){
237  printf("%hd ",v->co[i]);
238  if(i%maxcols==0 && i!=(v->nh)) putchar('\n');
239  }
240 
241 putchar('\n');
242 }
243 
244 
245 
246 }
247 
249 long read_intvector_elements(FILE *input, INTVECTOR *v,char *mode)
255 {
256 
257 size_t i,tmp=0;
258 long count=0;
259 const char ascii[2]="a",binary[2]="b";
260 
261 if(input==NULL){
262  t_error("The input file was not opened properly or is not allocated");
263 }else if (v==NULL || v->co==NULL || (v->isdynamic)!=1){
264  t_error("The vector was not allocated properly");
265 }else if(v->nl > v->nh){
266  t_error("The vector has no proper dimensions");
267 } else if(strcmp(mode,ascii)==0){
268 
269  for(i=v->nl;i<=v->nh;i++){
270  tmp=fscanf(input,"%d",&(v->co[i]));
271  if(tmp!=EOF){
272  count+=tmp;
273  }else{
274  printf("Error in stored data::Unespected End of file encountered");
275  printf(" after position %ld\n",count);
276  return -count;
277  }
278  }
279 } else if(strcmp(mode,binary)){
280  count=fread((int *)&(v->co[v->nl]),sizeof(int),v->nh-v->nl+1,input);
281 }else{
282  t_error("Error in reading mode::Mode not supported");
283 }
284 
285 if(count!=(v->nh-v->nl+1)){
286  printf("Error in stored data::Stored data number does not match the request");
287  return -count;
288 } else {
289  return count;
290 }
291 
292 }
293 
294 
296 long write_intvector_elements(FILE * output, INTVECTOR *v, long maxcols)
299 {
300 
301 long i,tmp=0;//count=0
302 
303 
304 if(output==NULL){
305  t_error("The input file was not opened properly");
306 }else if (v==NULL || v->co==NULL || v->isdynamic !=1){
307  t_error("The vector was not allocated properly");
308 }else if(v->nl > v->nh ){
309  t_error("The vector has no proper dimensions");
310 } else {
311 
312  for(i=v->nl;i<=v->nh;i++){
313  tmp=fprintf(output,"%d ",v->co[i]);
314  if(i%maxcols==0 && i!=(v->nh)) putc('\n',output);
315  if(tmp ==EOF){
316  printf("Error in storing data::Unespected End of file encountered\n");
317  return EOF;
318 
319  }
320 
321  }
322  putc('\n',output);
323 }
324 
325  return OK;
326 
327 
328 
329 }
330 
331 
337 {
338 
339 long tmp=0;
340 long count=0;
341 
342 
343 
344 if(output==NULL){
345  t_error("The input file was not opened properly");
346 }else if (v==NULL || v->co==NULL || v->isdynamic !=1){
347  t_error("The vector was not allocated properly");
348 }else if(v->nl > v->nh ){
349  t_error("The vector has no proper dimensions");
350 } else {
351  tmp=fwrite((int *)&(v->co[v->nl]),sizeof(int),v->nh-v->nl+1,output);
352  if(tmp!=EOF){
353  count+=tmp;
354  }else{
355  printf("Error in stored data::Unespected End of file encountered");
356  printf("after position %ld\n",count);
357  return -count;
358 
359  }
360 }
361 
362 if(count!=(v->nh-v->nl+1)){
363  printf("Error in stored data::Stored data number does not match the request");
364  return -count;
365 } else {
366  return count;
367 }
368 
369 
370 }
371 
372 
374 void print_intvector_elements(INTVECTOR *v,long maxcols)
375 /* Write a vector of int to the standard output */
376 
377 {
378 
379 long i;
380 
381 putchar('\n');
382 
383 if (v==NULL || v->co==NULL || v->isdynamic !=1){
384  t_error("The vector was not allocated properly");
385 }else if(v->nl > v->nh ){
386  t_error("The vector has no proper dimensions");
387 } else {
388 
389  for(i=v->nl;i<=v->nh;i++){
390  printf("%d ",v->co[i]);
391  if(i%maxcols==0 && i!=(v->nh)) putchar('\n');
392  }
393 
394 
395 }
396 
397 putchar('\n');
398 
399 }
400 
402 long read_longvector_elements(FILE *input, LONGVECTOR *v,char *mode)
408 {
409 
410 size_t i,tmp=0;
411 long count=0;
412 const char ascii[2]="a",binary[2]="b";
413 
414 if(input==NULL){
415  t_error("The input file was not opened properly or is not allocated");
416 }else if (v==NULL || v->co==NULL || (v->isdynamic)!=1){
417  t_error("The vector was not allocated properly");
418 }else if(v->nl > v->nh){
419  t_error("The vector has no proper dimensions");
420 } else if(strcmp(mode,ascii)==0){
421 
422  for(i=v->nl;i<=v->nh;i++){
423  tmp=fscanf(input,"%ld",&(v->co[i]));
424  if(tmp!=EOF){
425  count+=tmp;
426  }else{
427  printf("Error in stored data::Unespected End of file encountered");
428  printf(" after position %ld\n",count);
429  return -count;
430  }
431  }
432 } else if(strcmp(mode,binary)){
433  count=fread((long *)&(v->co[v->nl]),sizeof(long),v->nh-v->nl+1,input);
434 }else{
435  t_error("Error in reading mode::Mode not supported");
436 }
437 
438 if(count!=(v->nh-v->nl+1)){
439  printf("Error in stored data::Stored data number does not match the request");
440  return -count;
441 } else {
442  return count;
443 }
444 
445 }
446 
448 long write_longvector_elements(FILE * output, LONGVECTOR *v, long maxcols)
451 {
452 
453 long i,tmp=0;//count=0;
454 
455 
456 if(output==NULL){
457  t_error("The input file was not opened properly");
458 }else if (v==NULL || v->co==NULL || v->isdynamic !=1){
459  t_error("The vector was not allocated properly");
460 }else if(v->nl > v->nh ){
461  t_error("The vector has no proper dimensions");
462 } else {
463 
464  for(i=v->nl;i<=v->nh;i++){
465  tmp=fprintf(output,"%ld ",v->co[i]);
466  if(i%maxcols==0 && i!=(v->nh)) putc('\n',output);
467  if(tmp==EOF){
468  printf("Error in storing data::Unespected End of file encountered\n");
469  return EOF;
470 
471  }
472 
473  }
474  putc('\n',output);
475 }
476 
477 return OK;
478 
479 }
480 
481 
482 
488 {
489 
490 long tmp=0;
491 long count=0;
492 
493 
494 
495 if(output==NULL){
496  t_error("The input file was not opened properly");
497 }else if (v==NULL || v->co==NULL || v->isdynamic !=1){
498  t_error("The vector was not allocated properly");
499 }else if(v->nl > v->nh ){
500  t_error("The vector has no proper dimensions");
501 } else {
502  tmp=fwrite((long *)&(v->co[v->nl]),sizeof(long),v->nh-v->nl+1,output);
503  if(tmp!=EOF){
504  count+=tmp;
505  }else{
506  printf("Error in stored data::Unespected End of file encountered");
507  printf("after position %ld\n",count);
508  return -count;
509 
510  }
511 }
512 
513 if(count!=(v->nh-v->nl+1)){
514  printf("Error in stored data::Stored data number does not match the request");
515  return -count;
516 } else {
517  return count;
518 }
519 
520 
521 }
522 
523 
526 /* Write a vector of long to the standard output */
527 
528 {
529 
530 long i;
531 
532 putchar('\n');
533 
534 if (v==NULL || v->co==NULL || v->isdynamic !=1){
535  t_error("The vector was not allocated properly");
536 }else if(v->nl > v->nh ){
537  t_error("The vector has no proper dimensions");
538 } else {
539 
540  for(i=v->nl;i<=v->nh;i++){
541  printf("%ld ",v->co[i]);
542  if(i%maxcols==0 && i!=(v->nh)) putchar('\n');
543  }
544 
545 
546 }
547 
548 putchar('\n');
549 
550 }
551 
553 long read_floatvector_elements(FILE *input, FLOATVECTOR *v,char *mode)
559 {
560 
561 size_t i,tmp=0;
562 long count=0;
563 const char ascii[2]="a",binary[2]="b";
564 
565 if(input==NULL){
566  t_error("The input file was not opened properly or is not allocated");
567 }else if (v==NULL || v->co==NULL || (v->isdynamic)!=1){
568  t_error("The vector was not allocated properly");
569 }else if(v->nl > v->nh){
570  t_error("The vector has no proper dimensions");
571 } else if(strcmp(mode,ascii)==0){
572 
573  for(i=v->nl;i<=v->nh;i++){
574  tmp=fscanf(input,"%f",&(v->co[i]));
575  if(tmp!=EOF){
576  count+=tmp;
577  }else{
578  printf("Error in stored data::Unespected End of file encountered");
579  printf(" after position %ld\n",count);
580  return -count;
581  }
582  }
583 } else if(strcmp(mode,binary)){
584  count=fread((float *)&(v->co[v->nl]),sizeof(float),v->nh-v->nl+1,input);
585 }else{
586  t_error("Error in reading mode::Mode not supported");
587 }
588 
589 if(count!=(v->nh-v->nl+1)){
590  printf("Error in stored data::Stored data number does not match the request");
591  return -count;
592 } else {
593  return count;
594 }
595 
596 }
597 
599 long write_floatvector_elements(FILE * output, FLOATVECTOR *v, long maxcols)
602 {
603 
604 long i,tmp=0;//count=0;
605 
606 
607 if(output==NULL){
608  t_error("The input file was not opened properly");
609 }else if (v==NULL || v->co==NULL || v->isdynamic !=1){
610  t_error("The vector was not allocated properly");
611 }else if(v->nl > v->nh ){
612  t_error("The vector has no proper dimensions");
613 } else {
614 
615  for(i=v->nl;i<=v->nh;i++){
616  tmp=fprintf(output,"%f ",v->co[i]);
617  if(i%maxcols==0 && i!=(v->nh)) putc('\n',output);
618  if(tmp==EOF){
619  printf("Error in storing data::Unespected End of file encountered\n");
620  return EOF;
621  }
622 
623  }
624  putc('\n',output);
625 }
626 
627 return OK;
628 
629 }
630 
631 
632 
638 {
639 
640 long tmp=0;
641 long count=0;
642 
643 
644 
645 if(output==NULL){
646  t_error("The input file was not opened properly");
647 }else if (v==NULL || v->co==NULL || v->isdynamic !=1){
648  t_error("The vector was not allocated properly");
649 }else if(v->nl > v->nh ){
650  t_error("The vector has no proper dimensions");
651 } else {
652  tmp=fwrite((float *)&(v->co[v->nl]),sizeof(float),v->nh-v->nl+1,output);
653  if(tmp!=EOF){
654  count+=tmp;
655  }else{
656  printf("Error in stored data::Unespected End of file encountered");
657  printf("after position %ld\n",count);
658  return -count;
659 
660  }
661 }
662 
663 if(count!=(v->nh-v->nl+1)){
664  printf("Error in stored data::Stored data number does not match the request");
665  return -count;
666 } else {
667  return count;
668 }
669 
670 
671 }
672 
673 
676 /* Write a vector of float to the standard output */
677 
678 {
679 
680 long i;
681 
682 putchar('\n');
683 
684 if (v==NULL || v->co==NULL || v->isdynamic !=1){
685  t_error("The vector was not allocated properly");
686 }else if(v->nl > v->nh ){
687  t_error("The vector has no proper dimensions");
688 } else {
689 
690  for(i=v->nl;i<=v->nh;i++){
691  printf("%f ",v->co[i]);
692  if(i%maxcols==0 && i!=(v->nh)) putchar('\n');
693  }
694 
695 
696 }
697 
698 putchar('\n');
699 
700 }
701 
703 long read_doublevector_elements(FILE *input, DOUBLEVECTOR *v,char *mode)
709 {
710 
711 size_t i,tmp=0;
712 long count=0;
713 const char ascii[2]="a",binary[2]="b";
714 
715 if(input==NULL){
716  t_error("The input file was not opened properly or is not allocated");
717 }else if (v==NULL || v->co==NULL || (v->isdynamic)!=1){
718  t_error("The vector was not allocated properly");
719 }else if(v->nl > v->nh){
720  t_error("The vector has no proper dimensions");
721 } else if(strcmp(mode,ascii)==0){
722 
723  for(i=v->nl;i<=v->nh;i++){
724  tmp=fscanf(input,"%lf",&(v->co[i]));
725  if(tmp!=EOF){
726  count+=tmp;
727  }else{
728  printf("Error in stored data::Unespected End of file encountered");
729  printf(" after position %ld\n",count);
730  return -count;
731  }
732  }
733 } else if(strcmp(mode,binary)){
734  count=fread((double *)&(v->co[v->nl]),sizeof(double),v->nh-v->nl+1,input);
735 }else{
736  t_error("Error in reading mode::Mode not supported");
737 }
738 
739 if(count!=(v->nh-v->nl+1)){
740  printf("Error in stored data::Stored data number does not match the request");
741  return -count;
742 } else {
743  return count;
744 }
745 
746 }
747 
749 long write_doublevector_elements(FILE * output, DOUBLEVECTOR *v, long maxcols)
752 {
753 
754 long i,tmp=0;//count=0;
755 
756 
757 if(output==NULL){
758  t_error("The input file was not opened properly");
759 }else if (v==NULL || v->co==NULL || v->isdynamic !=1){
760  t_error("The vector was not allocated properly");
761 }else if(v->nl > v->nh ){
762  t_error("The vector has no proper dimensions");
763 } else {
764 
765  for(i=v->nl;i<=v->nh;i++){
766  tmp=fprintf(output,"%f ",v->co[i]);
767  if(i%maxcols==0 && i!=(v->nh)) putc('\n',output);
768  if(tmp==EOF){
769  printf("Error in storing data::Unespected End of file encountered\n");
770  return EOF;
771 
772  }
773 
774  }
775  putc('\n',output);
776 }
777 
778 return OK;
779 
780 }
781 
782 
783 
789 {
790 
791 long tmp=0;
792 long count=0;
793 
794 
795 
796 if(output==NULL){
797  t_error("The input file was not opened properly");
798 }else if (v==NULL || v->co==NULL || v->isdynamic !=1){
799  t_error("The vector was not allocated properly");
800 }else if(v->nl > v->nh ){
801  t_error("The vector has no proper dimensions");
802 } else {
803  tmp=fwrite((double *)&(v->co[v->nl]),sizeof(double),v->nh-v->nl+1,output);
804  if(tmp!=EOF){
805  count+=tmp;
806  }else{
807  printf("Error in stored data::Unespected End of file encountered");
808  printf("after position %ld\n",count);
809  return -count;
810 
811  }
812 }
813 
814 if(count!=(v->nh-v->nl+1)){
815  printf("Error in stored data::Stored data number does not match the request");
816  return -count;
817 } else {
818  return count;
819 }
820 
821 
822 }
823 
824 
827 /* Write a vector of double to the standard output */
828 
829 {
830 
831 long i;
832 
833 putchar('\n');
834 
835 if (v==NULL || v->co==NULL || v->isdynamic !=1){
836  t_error("The vector was not allocated properly");
837 }else if(v->nl > v->nh ){
838  t_error("The vector has no proper dimensions");
839 } else {
840 
841  for(i=v->nl;i<=v->nh;i++){
842  printf("%f ",v->co[i]);
843  if(i%maxcols==0 && i!=(v->nh)) putchar('\n');
844  }
845 
846 
847 }
848 
849 putchar('\n');
850 
851 }
852 
854 long read_charvector_elements(FILE *input, CHARVECTOR *v,char *mode)
860 {
861 
862 size_t i,tmp=0;
863 long count=0;
864 const char ascii[2]="a",binary[2]="b";
865 
866 if(input==NULL){
867  t_error("The input file was not opened properly or is not allocated");
868 }else if (v==NULL || v->co==NULL || (v->isdynamic)!=1){
869  t_error("The vector was not allocated properly");
870 }else if(v->nl > v->nh){
871  t_error("The vector has no proper dimensions");
872 } else if(strcmp(mode,ascii)==0){
873  for(i=v->nl;i<=v->nh;i++){
874  v->co[i]='\0';
875  tmp=fscanf(input,"%c",&(v->co[i]));
876  if(tmp!=EOF){
877  count+=tmp;
878  }else{
879  printf("Error in stored data::Unespected End of file encountered");
880  printf(" after position %ld\n",count);
881  return -count;
882  }
883  }
884 } else if(strcmp(mode,binary)){
885  count=fread((char *)&(v->co[v->nl]),sizeof(char),v->nh-v->nl+1,input);
886 }else{
887  t_error("Error in reading mode::Mode not supported");
888 }
889 
890 if(count!=(v->nh-v->nl+1)){
891  printf("Error in stored data::Stored data number does not match the request");
892  return -count;
893 } else {
894  return count;
895 }
896 
897 }
898 
900 long write_charvector_elements(FILE * output, CHARVECTOR *v, long maxcols)
903 {
904 
905 long i,tmp=0; //count=0
906 
907 
908 if(output==NULL){
909  t_error("The input file was not opened properly");
910 }else if (v==NULL || v->co==NULL || v->isdynamic !=1){
911  t_error("The vector was not allocated properly");
912 }else if(v->nl > v->nh ){
913  t_error("The vector has no proper dimensions");
914 } else {
915 
916  for(i=v->nl;i<=v->nh;i++){
917  tmp=fprintf(output,"%c ",v->co[i]);
918  if(i%maxcols==0 && i!=(v->nh)) putc('\n',output);
919  if(tmp==EOF){
920  printf("Error in storing data::Unespected End of file encountered\n");
921  return EOF;
922 
923  }
924 
925  }
926  putc('\n',output);
927 }
928 
929 return OK;
930 
931 }
932 
933 
934 
940 {
941 
942 long tmp=0;
943 long count=0;
944 
945 
946 
947 if(output==NULL){
948  t_error("The input file was not opened properly");
949 }else if (v==NULL || v->co==NULL || v->isdynamic !=1){
950  t_error("The vector was not allocated properly");
951 }else if(v->nl > v->nh ){
952  t_error("The vector has no proper dimensions");
953 } else {
954  tmp=fwrite((char *)&(v->co[v->nl]),sizeof(char),v->nh-v->nl+1,output);
955  if(tmp!=EOF){
956  count+=tmp;
957  }else{
958  printf("Error in stored data::Unespected End of file encountered");
959  printf("after position %ld\n",count);
960  return -count;
961 
962  }
963 }
964 
965 if(count!=(v->nh-v->nl+1)){
966  printf("Error in stored data::Stored data number does not match the request");
967  return -count;
968 } else {
969  return count;
970 }
971 
972 
973 }
974 
975 
978 /* Write a vector of char to the standard output */
979 
980 {
981 
982 long i;
983 
984 putchar('\n');
985 
986 if (v==NULL || v->co==NULL || v->isdynamic !=1){
987  t_error("The vector was not allocated properly");
988 }else if(v->nl > v->nh ){
989  t_error("The vector has no proper dimensions");
990 } else {
991 
992  for(i=v->nl;i<=v->nh;i++){
993  printf("%c ",v->co[i]);
994  if(i%maxcols==0 && i!=(v->nh)) putchar('\n');
995  }
996 
997 
998 }
999 
1000 putchar('\n');
1001 
1002 }
1003 
1010 long read_shortmatrix_elements(FILE *input,SHORTMATRIX *m,char *mode)
1011 
1012 
1014 {
1015 
1016 long tmp=0,count=0;
1017 
1018 const char ascii[2]="a",binary[2]="b";
1019 long i,j;
1020 
1021 
1022 
1023 if(input==NULL){
1024  t_error("The input file was not opened properly");
1025 }else if (m==NULL || m->co==NULL || (m->isdynamic)!=1){
1026  t_error("The matrix was not allocated properly");
1027 }else if(m->nrl > m->nrh || m->ncl > m->nch){
1028  t_error("The matrix has no proper dimensions");
1029 } else if(strcmp(mode,ascii)==0){
1030 
1031  for(i=m->nrl;i<=m->nrh;i++){
1032  for(j=m->ncl;j<=m->nch;j++){
1033  tmp=fscanf(input,"%hd",&(m->co[i][j]));
1034  if(tmp!=EOF){
1035  count+=tmp;
1036  }else {
1037  printf("Error in stored data::Unexpected End of File encountered\n");
1038  printf(" after position %ld\n",count);
1039  return -count;
1040  }
1041  }
1042  }
1043 
1044 }else if(strcmp(mode,binary)==0){
1045 
1046  for(i=m->nrl;i<=m->nrh;i++){
1047  tmp=fread((short *)&(m->co[i][m->ncl]),sizeof(short),m->nch-m->ncl+1,input);
1048  if(tmp!=EOF){
1049  count+=tmp;
1050  }else{
1051  printf("Error in stored data::Unexpected End of File encountered\n");
1052  printf(" after position %ld\n",count);
1053  return -count;
1054  }
1055  }
1056 } else {
1057  t_error("Error in reading mode::Mode not supported");
1058 }
1059 
1060 if(count!=(m->nrh-m->nrl+1)*(m->nch-m->ncl+1)){
1061  printf("Error in stored data::Stored data number does not match the request");
1062  return -count;
1063 }else{
1064  return count;
1065 }
1066 
1067 }
1068 
1069 
1071 long write_shortmatrix_elements(FILE * output,SHORTMATRIX *m,long maxcols)
1072 /* Write a matrix of floating point numbers to a file */
1073 
1074 {
1075 
1076 long tmp=0,i,j;//buffer_index=0
1077 
1078 
1079 
1080 if(output==NULL){
1081  t_error("The input file was not opened properly");
1082 }else if (m==NULL || m->co==NULL || m->isdynamic !=1){
1083  t_error("The matrix was not allocated properly");
1084 }else if(m->nrl > m->nrh || m->ncl >m->nch ){
1085  t_error("The matrix has no proper dimensions");
1086 } else {
1087 
1088  for(i=m->nrl;i<=m->nrh;i++){
1089  for(j=m->ncl;j<=m->nch;j++){
1090  tmp=fprintf(output,"%hd\t ",m->co[i][j]);
1091  if(tmp==EOF){
1092  printf("Error in storing data::Unespected End of file encountered\n");
1093  return EOF;
1094  }
1095 
1096  if(j%maxcols==0 && j!=m->nch) putc('\n',output);
1097  }
1098  putc('\n',output);
1099  }
1100  putchar('\n');
1101 }
1102 
1103 return OK;
1104 
1105 }
1106 
1107 
1108 
1113 {
1114 
1115 
1116 long tmp,i,count=0;
1117 
1118 
1119 
1120 if(output==NULL){
1121  t_error("The input file was not opened properly");
1122 }else if (m==NULL || m->co==NULL || m->isdynamic !=1){
1123  t_error("The vector was not allocated properly");
1124 }else if(m->ncl > m->nch || m->nrl > m->nrh){
1125  t_error("The matrix has no proper dimensions");
1126 } else {
1127  for(i=m->nrl;i<=m->nrh;i++){
1128  tmp=fwrite((short *)&(m->co[i][m->nrl]),sizeof(short),m->nch-m->ncl+1,output);
1129  if(tmp!=EOF){
1130  count+=tmp;
1131  }else{
1132  printf("Error in stored data::Unespected End of file encountered");
1133  printf("after position %ld\n",count);
1134  return -count;
1135 
1136  }
1137  }
1138 }
1139 
1140 if(count!=(m->nch-m->ncl+1)*(m->nrh-m->nrl+1)){
1141  printf("Error in stored data::Stored data number does not match the request");
1142  return -count;
1143 } else {
1144  return count;
1145 }
1146 
1147 
1148 }
1149 
1152 /* Write a matrix of shorts to the standard output */
1153 
1154 {
1155 
1156 long i,j;
1157 
1158 putchar('\n');
1159 
1160 if (m==NULL || m->co==NULL || m->isdynamic !=1){
1161  t_error("The matrix was not allocated properly");
1162 }else if(m->nrl > m->nrh || m->ncl >m->nch ){
1163  t_error("The matrix has no proper dimensions");
1164 } else {
1165 
1166  for(i=m->nrl;i<=m->nrh;i++){
1167  for(j=m->ncl;j<=m->nch;j++){
1168  printf("%hd ",m->co[i][j]);
1169  if(j%maxcols==0 && j!=m->nch) putchar('\n');
1170  }
1171  putchar('\n');
1172  }
1173  putchar('\n');
1174 }
1175 
1176 
1177 }
1178 /*-----------------------------------------------------------------------*/
1179 
1180 long read_intmatrix_elements(FILE *input,INTMATRIX *m,char *mode)
1187 {
1188 
1189 long tmp=0,count=0;
1190 
1191 const char ascii[2]="a",binary[2]="b";
1192 long i,j;
1193 
1194 
1195 
1196 if(input==NULL){
1197  t_error("The input file was not opened properly");
1198 }else if (m==NULL || m->co==NULL || (m->isdynamic)!=1){
1199  t_error("The matrix was not allocated properly");
1200 }else if(m->nrl > m->nrh || m->ncl > m->nch){
1201  t_error("The matrix has no proper dimensions");
1202 } else if(strcmp(mode,ascii)==0){
1203 
1204  for(i=m->nrl;i<=m->nrh;i++){
1205  for(j=m->ncl;j<=m->nch;j++){
1206  tmp=fscanf(input,"%d",&(m->co[i][j]));
1207  if(tmp!=EOF){
1208  count+=tmp;
1209  }else {
1210  printf("Error in stored data::Unexpected End of File encountered\n");
1211  printf(" after position %ld\n",count);
1212  return -count;
1213  }
1214  }
1215  }
1216 
1217 }else if(strcmp(mode,binary)==0){
1218 
1219  for(i=m->nrl;i<=m->nrh;i++){
1220  tmp=fread((int *)&(m->co[i][m->ncl]),sizeof(int),m->nch-m->ncl+1,input);
1221  if(tmp!=EOF){
1222  count+=tmp;
1223  }else{
1224  printf("Error in stored data::Unexpected End of File encountered\n");
1225  printf(" after position %ld\n",count);
1226  return -count;
1227  }
1228  }
1229 } else {
1230  t_error("Error in reading mode::Mode not supported");
1231 }
1232 
1233 if(count!=(m->nrh-m->nrl+1)*(m->nch-m->ncl+1)){
1234  printf("Error in stored data::Stored data number does not match the request");
1235  return -count;
1236 }else{
1237  return count;
1238 }
1239 
1240 }
1241 
1242 
1244 long write_intmatrix_elements(FILE * output,INTMATRIX *m,long maxcols)
1245 /* Write a matrix of int numbers to a file */
1246 
1247 {
1248 
1249 long tmp=0,i,j; //count=0
1250 
1251 
1252 if(output==NULL){
1253  t_error("The input file was not opened properly");
1254 }else if (m==NULL || m->co==NULL || m->isdynamic !=1){
1255  t_error("The matrix was not allocated properly");
1256 }else if(m->nrl > m->nrh || m->ncl >m->nch ){
1257  t_error("The matrix has no proper dimensions");
1258 } else {
1259 
1260  for(i=m->nrl;i<=m->nrh;i++){
1261  for(j=m->ncl;j<=m->nch;j++){
1262  tmp=fprintf(output,"%d ",m->co[i][j]);
1263  if(tmp==EOF){
1264  printf("Error in storing data::Unespected End of file encountered\n");
1265  return EOF;
1266  }
1267 
1268  if(j%maxcols==0 && j!=m->nch) putc('\n',output);
1269  }
1270  putc('\n',output);
1271  }
1272  putchar('\n');
1273 }
1274 
1275 return OK;
1276 }
1277 
1278 
1279 
1284 {
1285 
1286 long tmp=0;
1287 long i,count=0;
1288 
1289 
1290 
1291 if(output==NULL){
1292  t_error("The input file was not opened properly");
1293 }else if (m==NULL || m->co==NULL || m->isdynamic !=1){
1294  t_error("The vector was not allocated properly");
1295 }else if(m->ncl > m->nch || m->nrl > m->nrh){
1296  t_error("The matrix has no proper dimensions");
1297 } else {
1298  for(i=m->nrl;i<=m->nrh;i++){
1299  tmp=fwrite((int *)&(m->co[i][m->nrl]),sizeof(int),m->nch-m->ncl+1,output);
1300  if(tmp!=EOF){
1301  count+=tmp;
1302  }else{
1303  printf("Error in stored data::Unespected End of file encountered");
1304  printf("after position %ld\n",count);
1305  return -count;
1306 
1307  }
1308  }
1309 }
1310 
1311 if(count!=(m->nch-m->ncl+1)*(m->nrh-m->nrl+1)){
1312  printf("Error in stored data::Stored data number does not match the request");
1313  return -count;
1314 } else {
1315  return count;
1316 }
1317 
1318 
1319 }
1320 
1323 /* Write a matrix of double to the standard output */
1324 
1325 {
1326 
1327 long i,j;
1328 
1329 putchar('\n');
1330 
1331 if (m==NULL || m->co==NULL || m->isdynamic !=1){
1332  t_error("The matrix was not allocated properly");
1333 }else if(m->nrl > m->nrh || m->ncl >m->nch ){
1334  t_error("The matrix has no proper dimensions");
1335 } else {
1336 
1337  for(i=m->nrl;i<=m->nrh;i++){
1338  for(j=m->ncl;j<=m->nch;j++){
1339  printf("%d ",m->co[i][j]);
1340  if(j%maxcols==0 && j!=m->nch) putchar('\n');
1341  }
1342  putchar('\n');
1343  }
1344  putchar('\n');
1345 }
1346 
1347 
1348 }
1349 
1350 
1351 
1352 /*-----------------------------------------------------------------------*/
1353 
1354 long read_longmatrix_elements(FILE *input,LONGMATRIX *m,char *mode)
1357 {
1358 
1359 long tmp=0,count=0;
1360 
1361 const char ascii[2]="a",binary[2]="b";
1362 long i,j;
1363 
1364 if(input==NULL){
1365  t_error("The input file was not opened properly");
1366 }else if (m==NULL || m->co==NULL || (m->isdynamic)!=1){
1367  t_error("The matrix was not allocated properly");
1368 }else if(m->nrl > m->nrh || m->ncl > m->nch){
1369  t_error("The matrix has no proper dimensions");
1370 } else if(strcmp(mode,ascii)==0){
1371 
1372  for(i=m->nrl;i<=m->nrh;i++){
1373  for(j=m->ncl;j<=m->nch;j++){
1374  tmp=fscanf(input,"%ld",&(m->co[i][j]));
1375 /* fscanf(input,"%c",&ch);
1376  printf("^^^%d %c\n",m->co[i][j],ch);
1377  scanf("%c",&ch);
1378 */ if(tmp!=EOF){
1379  count+=tmp;
1380 /* printf("^@^%d\n",count); */
1381  }else {
1382  printf("Error in stored data::Unexpected End of File encountered\n");
1383  printf(" after position %ld\n",count);
1384  return -count;
1385  }
1386  }
1387  }
1388 
1389 }else if(strcmp(mode,binary)==0){
1390 
1391  for(i=m->nrl;i<=m->nrh;i++){
1392  tmp=fread((long *)&(m->co[i][m->ncl]),sizeof(long),m->nch-m->ncl+1,input);
1393  if(tmp!=EOF){
1394  count+=tmp;
1395  }else{
1396  printf("Error in stored data::Unexpected End of File encountered\n");
1397  printf(" after position %ld\n",count);
1398  return -count;
1399  }
1400  }
1401 } else {
1402  t_error("Error in reading mode::Mode not supported");
1403 }
1404 
1405 if(count!=(m->nrh-m->nrl+1)*(m->nch-m->ncl+1)){
1406 /* printf("^^^%d %d\n",count,(m->nrh-m->nrl+1)*(m->nch-m->ncl+1)); */
1407  printf("Error in stored data::Stored data number does not match the request");
1408  return -count;
1409 }else{
1410  return count;
1411 }
1412 
1413 }
1414 
1415 
1417 long write_longmatrix_elements(FILE * output,LONGMATRIX *m,long maxcols)
1418 /* Write a matrix of long point numbers to a file */
1419 
1420 {
1421 
1422 long tmp=0,i,j;//count=0
1423 
1424 
1425 
1426 if(output==NULL){
1427  t_error("The input file was not opened properly");
1428 }else if (m==NULL || m->co==NULL || m->isdynamic !=1){
1429  t_error("The matrix was not allocated properly");
1430 }else if(m->nrl > m->nrh || m->ncl >m->nch ){
1431  t_error("The matrix has no proper dimensions");
1432 } else {
1433 
1434  for(i=m->nrl;i<=m->nrh;i++){
1435  for(j=m->ncl;j<=m->nch;j++){
1436  /*printf("i(%d,%d)m(%d)\n",i,j,m->co[i][j]);*/
1437  tmp=fprintf(output,"%ld ",m->co[i][j]);
1438  if(tmp==EOF){
1439  printf("Error in storing data::Unespected End of file encountered\n");
1440  return EOF;
1441  }
1442 
1443  if(j%maxcols==0 && j!=m->nch) putc('\n',output);
1444  }
1445  putc('\n',output);
1446  }
1447 }
1448 
1449 return OK;
1450 }
1451 
1452 
1453 
1458 {
1459 
1460 long tmp=0;
1461 long i,count=0;
1462 
1463 
1464 
1465 if(output==NULL){
1466  t_error("The input file was not opened properly");
1467 }else if (m==NULL || m->co==NULL || m->isdynamic !=1){
1468  t_error("The vector was not allocated properly");
1469 }else if(m->ncl > m->nch || m->nrl > m->nrh){
1470  t_error("The matrix has no proper dimensions");
1471 } else {
1472  for(i=m->nrl;i<=m->nrh;i++){
1473  tmp=fwrite((long *)&(m->co[i][m->nrl]),sizeof(long),m->nch-m->ncl+1,output);
1474  if(tmp!=EOF){
1475  count+=tmp;
1476  }else{
1477  printf("Error in stored data::Unespected End of file encountered");
1478  printf("after position %ld\n",count);
1479  return -count;
1480 
1481  }
1482  }
1483 }
1484 
1485 if(count!=(m->nch-m->ncl+1)*(m->nrh-m->nrl+1)){
1486  printf("Error in stored data::Stored data number does not match the request");
1487  return -count;
1488 } else {
1489  return count;
1490 }
1491 
1492 
1493 }
1494 
1497 /* Write a matrix of double to the standard output */
1498 
1499 {
1500 
1501 long i,j;
1502 
1503 putchar('\n');
1504 
1505 if (m==NULL || m->co==NULL || m->isdynamic !=1){
1506  t_error("The matrix was not allocated properly");
1507 }else if(m->nrl > m->nrh || m->ncl >m->nch ){
1508  t_error("The matrix has no proper dimensions");
1509 } else {
1510 
1511  for(i=m->nrl;i<=m->nrh;i++){
1512  for(j=m->ncl;j<=m->nch;j++){
1513  printf("%ld ",m->co[i][j]);
1514  if(j%maxcols==0 && j!=m->nch) putchar('\n');
1515  }
1516  putchar('\n');
1517  }
1518  putchar('\n');
1519 }
1520 
1521 
1522 }
1523 
1524 
1525 
1526 
1527 
1528 
1529 /*-----------------------------------------------------------------------*/
1530 
1531 long read_floatmatrix_elements(FILE *input,FLOATMATRIX *m,char *mode)
1538 {
1539 
1540 long tmp=0,count=0;
1541 
1542 const char ascii[2]="a",binary[2]="b";
1543 long i,j;
1544 
1545 
1546 
1547 if(input==NULL){
1548  t_error("The input file was not opened properly");
1549 }else if (m==NULL || m->co==NULL || (m->isdynamic)!=1){
1550  t_error("The matrix was not allocated properly");
1551 }else if(m->nrl > m->nrh || m->ncl > m->nch){
1552  t_error("The matrix has no proper dimensions");
1553 } else if(strcmp(mode,ascii)==0){
1554 
1555  for(i=m->nrl;i<=m->nrh;i++){
1556  for(j=m->ncl;j<=m->nch;j++){
1557  tmp=fscanf(input,"%f",&(m->co[i][j]));
1558  if(tmp!=EOF){
1559  count+=tmp;
1560  }else {
1561  printf("Error in stored data::Unexpected End of File encountered\n");
1562  printf(" after position %ld\n",count);
1563  return -count;
1564  }
1565  }
1566  }
1567 
1568 }else if(strcmp(mode,binary)==0){
1569 
1570  for(i=m->nrl;i<=m->nrh;i++){
1571  tmp=fread((float *)&(m->co[i][m->ncl]),sizeof(float),m->nch-m->ncl+1,input);
1572  if(tmp!=EOF){
1573  count+=tmp;
1574  }else{
1575  printf("Error in stored data::Unexpected End of File encountered\n");
1576  printf(" after position %ld\n",count);
1577  return -count;
1578  }
1579  }
1580 } else {
1581  t_error("Error in reading mode::Mode not supported");
1582 }
1583 
1584 if(count!=(m->nrh-m->nrl+1)*(m->nch-m->ncl+1)){
1585  printf("Error in stored data::Stored data number does not match the request");
1586  return -count;
1587 }else{
1588  return count;
1589 }
1590 
1591 }
1592 
1593 
1595 long write_floatmatrix_elements(FILE * output,FLOATMATRIX *m,long maxcols)
1596 /* Write a matrix of floating point numbers to a file */
1597 
1598 {
1599 
1600 long tmp=0,i,j; //count=0
1601 
1602 if(output==NULL){
1603  t_error("The input file was not opened properly");
1604 }else if (m==NULL || m->co==NULL || m->isdynamic !=1){
1605  t_error("The matrix was not allocated properly");
1606 }else if(m->nrl > m->nrh || m->ncl >m->nch ){
1607  t_error("The matrix has no proper dimensions");
1608 } else {
1609 
1610  for(i=m->nrl;i<=m->nrh;i++){
1611  for(j=m->ncl;j<=m->nch;j++){
1612  tmp=fprintf(output,"%f ",m->co[i][j]);
1613  if(tmp==EOF){
1614  printf("Error in storing data::Unespected End of file encountered\n");
1615  return EOF;
1616  }
1617 
1618  if(j%maxcols==0 && j!=m->nch) putc('\n',output);
1619  }
1620  putc('\n',output);
1621  }
1622  putchar('\n');
1623 }
1624 
1625 return OK;
1626 
1627 }
1628 
1629 
1630 
1635 {
1636 
1637 long tmp=0;
1638 long i,count=0;
1639 
1640 
1641 
1642 if(output==NULL){
1643  t_error("The input file was not opened properly");
1644 }else if (m==NULL || m->co==NULL || m->isdynamic !=1){
1645  t_error("The vector was not allocated properly");
1646 }else if(m->ncl > m->nch || m->nrl > m->nrh){
1647  t_error("The matrix has no proper dimensions");
1648 } else {
1649  for(i=m->nrl;i<=m->nrh;i++){
1650  tmp=fwrite((float *)&(m->co[i][m->nrl]),sizeof(float),m->nch-m->ncl+1,output);
1651  if(tmp!=EOF){
1652  count+=tmp;
1653  }else{
1654  printf("Error in stored data::Unexpected End of file encountered");
1655  printf("after position %ld\n",count);
1656  return -count;
1657 
1658  }
1659  }
1660 }
1661 
1662 if(count!=(m->nch-m->ncl+1)*(m->nrh-m->nrl+1)){
1663  printf("Error in stored data::Stored data number does not match the request");
1664  return -count;
1665 } else {
1666  return count;
1667 }
1668 
1669 
1670 }
1671 
1674 /* Write a matrix of float to the standard output */
1675 
1676 {
1677 
1678 long i,j;
1679 
1680 putchar('\n');
1681 
1682 if (m==NULL || m->co==NULL || m->isdynamic !=1){
1683  t_error("The matrix was not allocated properly");
1684 }else if(m->nrl > m->nrh || m->ncl >m->nch ){
1685  t_error("The matrix has no proper dimensions");
1686 } else {
1687 
1688  for(i=m->nrl;i<=m->nrh;i++){
1689  for(j=m->ncl;j<=m->nch;j++){
1690  printf("%f ",m->co[i][j]);
1691  if(j%maxcols==0 && j!=m->nch) putchar('\n');
1692  }
1693  putchar('\n');
1694  }
1695  putchar('\n');
1696 }
1697 
1698 
1699 }
1700 
1701 
1702 /*-----------------------------------------------------------------------*/
1703 
1704 long read_doublematrix_elements(FILE *input,DOUBLEMATRIX *m,char *mode)
1707 {
1708 
1709 long tmp=0,count=0;
1710 
1711 const char ascii[2]="a",binary[2]="b";
1712 long i,j;
1713 
1714 
1715 
1716 if(input==NULL){
1717  t_error("The input file was not opened properly");
1718 }else if (m==NULL || m->co==NULL || (m->isdynamic)!=1){
1719  t_error("The matrix was not allocated properly");
1720 }else if(m->nrl > m->nrh || m->ncl > m->nch){
1721  t_error("The matrix has no proper dimensions");
1722 } else if(strcmp(mode,ascii)==0){
1723 
1724  for(i=m->nrl;i<=m->nrh;i++){
1725  for(j=m->ncl;j<=m->nch;j++){
1726  tmp=fscanf(input,"%lf",&(m->co[i][j]));
1727  if(tmp!=EOF){
1728  count+=tmp;
1729  }else {
1730  printf("Error in stored data::Unexpected End of File encountered\n");
1731  printf(" after position %ld\n",count);
1732  return -count;
1733  }
1734  }
1735  }
1736 
1737 }else if(strcmp(mode,binary)==0){
1738 
1739  for(i=m->nrl;i<=m->nrh;i++){
1740  tmp=fread((double *)&(m->co[i][m->ncl]),sizeof(double),m->nch-m->ncl+1,input);
1741  if(tmp!=EOF){
1742  count+=tmp;
1743  }else{
1744  printf("Error in stored data::Unexpected End of File encountered\n");
1745  printf(" after position %ld\n",count);
1746  return -count;
1747  }
1748  }
1749 } else {
1750  t_error("Error in reading mode::Mode not supported");
1751 }
1752 
1753 if(count!=(m->nrh-m->nrl+1)*(m->nch-m->ncl+1)){
1754  printf("Error in stored data::Stored data number does not match the request");
1755  return -count;
1756 }else{
1757  return count;
1758 }
1759 
1760 }
1761 
1762 
1764 long write_doublematrix_elements(FILE * output,DOUBLEMATRIX *m,long maxcols)
1765 /* Write a matrix of double numbers to a file */
1766 
1767 {
1768 
1769 long tmp=0,i,j; //count=0,
1770 
1771 
1772 
1773 if(output==NULL){
1774  t_error("The input file was not opened properly");
1775 }else if (m==NULL || m->co==NULL || m->isdynamic !=1){
1776  t_error("The matrix was not allocated properly");
1777 }else if(m->nrl > m->nrh || m->ncl >m->nch ){
1778  t_error("The matrix has no proper dimensions");
1779 } else {
1780 
1781  for(i=m->nrl;i<=m->nrh;i++){
1782  for(j=m->ncl;j<=m->nch;j++){
1783  tmp=fprintf(output,"%g\t",m->co[i][j]);
1784  if(tmp==EOF){
1785  printf("Error in storing data::Unespected End of file encountered\n");
1786  return EOF;
1787  }
1788 
1789  if(j%maxcols==0 && j!= m->ncl) putc('\n',output);
1790  }
1791  putc('\n',output);
1792  }
1793  /*putchar('\n');*/
1794 }
1795 
1796 return OK;
1797 
1798 }
1799 
1800 
1801 
1806 {
1807 
1808 
1809 long i,tmp=0,count=0;
1810 
1811 
1812 
1813 if(output==NULL){
1814  t_error("The input file was not opened properly");
1815 }else if (m==NULL || m->co==NULL || m->isdynamic !=1){
1816  t_error("The vector was not allocated properly");
1817 }else if(m->ncl > m->nch || m->nrl > m->nrh){
1818  t_error("The matrix has no proper dimensions");
1819 } else {
1820  for(i=m->nrl;i<=m->nrh;i++){
1821  tmp=fwrite((double *)&(m->co[i][m->nrl]),sizeof(double),m->nch-m->ncl+1,output);
1822  if(tmp!=EOF){
1823  count+=tmp;
1824  }else{
1825  printf("Error in stored data::Unespected End of file encountered");
1826  printf("after position %ld\n",count);
1827  return -count;
1828 
1829  }
1830  }
1831 }
1832 
1833 if(count!=(m->nch-m->ncl+1)*(m->nrh-m->nrl+1)){
1834  printf("Error in stored data::Stored data number does not match the request");
1835  return -count;
1836 } else {
1837  return count;
1838 }
1839 
1840 
1841 }
1842 
1845 /* Write a matrix of double to the standard output */
1846 
1847 {
1848 
1849 long i,j;
1850 
1851 putchar('\n');
1852 
1853 if (m==NULL || m->co==NULL || m->isdynamic !=1){
1854  t_error("The matrix was not allocated properly");
1855 }else if(m->nrl > m->nrh || m->ncl >m->nch ){
1856  t_error("The matrix has no proper dimensions");
1857 } else {
1858 
1859  for(i=m->nrl;i<=m->nrh;i++){
1860  for(j=m->ncl;j<=m->nch;j++){
1861  printf("%f ",m->co[i][j]);
1862  if(j%maxcols==0 && j!= m->nch) putchar('\n');
1863  }
1864  putchar('\n');
1865  }
1866  putchar('\n');
1867 }
1868 
1869 
1870 }
1871 
1872 
1874 long read_intbin_elements(FILE *input,INTBIN *l,char *mode)
1875 /* Read a list of int numbers */
1876 
1877 
1878 {
1879 
1880 long i,j,tmp=0,count=0,chksum=0;
1881 const char ascii[2]="a",binary[2]="b";
1882 
1883 
1884 if(input==NULL){
1885  t_error("The input file was not opened properly");
1886 } else if(l==NULL || l->co==NULL || (l->isdynamic)!=1 || l->index==NULL ){
1887  t_error("The bin was not allocated properly");
1888 
1889 } else if(strcmp(mode,ascii)==0){
1890 
1891  for(i=1;i<=(l->index)->nh;i++){
1892  chksum+=l->index->co[i];
1893  for(j=1;j<=(l->index)->co[i];j++){
1894 
1895  tmp=fscanf(input,"%d",&(l->co[i][j]));
1896  if(tmp!=EOF){
1897  count+=tmp;
1898  }else{
1899  printf("Error in stored data::Unespected End of file encountered");
1900  printf("after position %ld\n",count);
1901  return -count;
1902 
1903 
1904  }
1905 
1906  }
1907 
1908  }
1909 
1910 
1911 }else if(strcmp(mode,binary)==0){
1912 
1913  for(i=1;i<=(l->index)->nh;i++){
1914  chksum+=l->index->co[i];
1915  tmp=fread((int *)&(l->co[i][1]),sizeof(int),l->index->co[i],input);
1916  if(tmp!=EOF){
1917  count+=tmp;
1918  }else{
1919  printf("Error in stored data::Unexpected End of File encountered");
1920  printf(" after position %ld\n",count);
1921  return -count;
1922  }
1923  }
1924 
1925 
1926 } else {
1927 
1928  t_error("Error in reading mode::Mode not supported");
1929 }
1930 
1931 if(count!=chksum){
1932  printf("Error in stored data::Stored data number does not match the request");
1933  return -count;
1934 } else {
1935  return count;
1936 }
1937 
1938 }
1939 
1941 long write_intbin_elements(FILE * output, INTBIN *l,long maxcols)
1944 {
1945 
1946 
1947 
1948 long i,j,tmp=0,chksum=0; //count=0,
1949 
1950 
1951 
1952 if(output==NULL){
1953  t_error("The output file was not opened properly");
1954 } else if(l==NULL || l->co==NULL || (l->isdynamic)!=1 || l->index==NULL){
1955  t_error("The bin was not allocated properly");
1956 } else {
1957  putc('\n',output);
1958  for(i=1;i<=(l->index)->nh;i++){
1959  chksum+=l->index->co[i];
1960  for(j=1;j<=(l->index)->co[i];j++){
1961  tmp=fprintf(output,"%d ",l->co[i][j]);
1962  if(tmp==EOF){
1963  printf("Error in storing data::Unespected End of file encountered");
1964  return EOF;
1965  }
1966  if(j%maxcols==0 && j!=(l->index)->co[i]) putc('\n',output);
1967  }
1968  putc('\n',output);
1969  }
1970 
1971 }
1972 
1973 return OK;
1974 
1975 }
1976 
1977 
1978 
1980 long binarywrite_intbin_elements(FILE * output, INTBIN *l)
1983 {
1984 
1985 
1986 
1987 long i,tmp=0,count=0,chksum=0;
1988 
1991 if(output==NULL){
1992  t_error("The output file was not opened properly");
1993 } else if(l==NULL || l->co==NULL || (l->isdynamic)!=1 || l->index==NULL){
1994  t_error("The bin was not allocated properly");
1995 } else {
1996  putc('\n',output);
1997  for(i=1;i<=(l->index)->nh;i++){
1998  chksum+=l->index->co[i];
1999  tmp=fwrite((int *)&(l->co[i][1]),sizeof(int),l->index->co[i],output);
2000  if(tmp!=EOF){
2001  count+=tmp;
2002  }else {
2003  printf("Error in storing data::Unespected End of file encountered");
2004  printf("after position %ld\n",count);
2005  return -count;
2006 
2007  }
2008  }
2009 
2010 }
2011 
2012 if(count!=chksum){
2013  printf("Error in stored data::Stored data number does not match the request");
2014  return -count;
2015 } else {
2016  return count;
2017 }
2018 
2019 }
2020 
2021 
2022 
2023 
2024 
2026 void print_intbin_elements(INTBIN *l,long maxcols)
2027 /* Write a list of int to the standard output */
2028 
2029 {
2030 
2031 
2032 
2033 long i,j;
2034 
2035 
2036 
2037 if(l==NULL || l->co==NULL || (l->isdynamic)!=1 || l->index==NULL){
2038  t_error("The bin was not allocated properly");
2039 } else {
2040  putchar('\n');
2041  for(i=1;i<=(l->index)->nh;i++){
2042  for(j=1;j<=(l->index)->co[i];j++){
2043  /* This is the specialized code for int */
2044  printf("%d ",l->co[i][j]);
2045  if(j%maxcols==0 && j!=(l->index)->co[i]) putchar('\n');
2046  }
2047  putchar('\n');
2048  }
2049 
2050 }
2051 
2052 }
2053 
2055 long read_shortbin_elements(FILE *input,SHORTBIN *l,char *mode)
2056 /* Read a list of int numbers */
2057 
2058 
2059 {
2060 
2061 long i,j,tmp=0,count=0,chksum=0;
2062 const char ascii[2]="a",binary[2]="b";
2063 
2064 
2065 if(input==NULL){
2066  t_error("The input file was not opened properly");
2067 } else if(l==NULL || l->co==NULL || (l->isdynamic)!=1 || l->index==NULL ){
2068  t_error("The bin was not allocated properly");
2069 
2070 } else if(strcmp(mode,ascii)==0){
2071 
2072  for(i=1;i<=(l->index)->nh;i++){
2073  chksum+=l->index->co[i];
2074  for(j=1;j<=(l->index)->co[i];j++){
2075 
2076  tmp=fscanf(input,"%hd",&(l->co[i][j]));
2077  if(tmp!=EOF){
2078  count+=tmp;
2079  }else{
2080  printf("Error in stored data::Unespected End of file encountered");
2081  printf("after position %ld\n",count);
2082  return -count;
2083 
2084 
2085  }
2086 
2087  }
2088 
2089  }
2090 
2091 
2092 }else if(strcmp(mode,binary)==0){
2093 
2094  for(i=1;i<=(l->index)->nh;i++){
2095  chksum+=l->index->co[i];
2096  tmp=fread((short *)&(l->co[i][1]),sizeof(short),l->index->co[i],input);
2097  if(tmp!=EOF){
2098  count+=tmp;
2099  }else{
2100  printf("Error in stored data::Unexpected End of File encountered");
2101  printf(" after position %ld\n",count);
2102  return -count;
2103  }
2104  }
2105 
2106 
2107 } else {
2108 
2109  t_error("Error in reading mode::Mode not supported");
2110 }
2111 
2112 if(count!=chksum){
2113  printf("Error in stored data::Stored data number does not match the request");
2114  return -count;
2115 } else {
2116  return count;
2117 }
2118 
2119 }
2120 
2122 long write_shortbin_elements(FILE * output, SHORTBIN *l,long maxcols)
2125 {
2126 
2127 
2128 
2129 long i,j,tmp=0,chksum=0; //count=0
2130 
2131 
2132 
2133 if(output==NULL){
2134  t_error("The output file was not opened properly");
2135 } else if(l==NULL || l->co==NULL || (l->isdynamic)!=1 || l->index==NULL){
2136  t_error("The bin was not allocated properly");
2137 } else {
2138  putc('\n',output);
2139  for(i=1;i<=(l->index)->nh;i++){
2140  chksum+=l->index->co[i];
2141  for(j=1;j<=(l->index)->co[i];j++){
2142  tmp=fprintf(output,"%hd ",l->co[i][j]);
2143  if(tmp==EOF){
2144  printf("Error in storing data::Unespected End of file encountered");
2145  return EOF;
2146  }
2147  if(j%maxcols==0 && j!=(l->index)->co[i]) putc('\n',output);
2148  }
2149  putc('\n',output);
2150  }
2151 
2152 }
2153 
2154 return OK;
2155 
2156 }
2157 
2158 
2159 
2164 {
2165 
2166 
2167 
2168 long i,tmp=0,count=0,chksum=0;
2169 
2172 if(output==NULL){
2173  t_error("The output file was not opened properly");
2174 } else if(l==NULL || l->co==NULL || (l->isdynamic)!=1 || l->index==NULL){
2175  t_error("The bin was not allocated properly");
2176 } else {
2177  putc('\n',output);
2178  for(i=1;i<=(l->index)->nh;i++){
2179  chksum+=l->index->co[i];
2180  tmp=fwrite((short *)&(l->co[i][1]),sizeof(short),l->index->co[i],output);
2181  if(tmp!=EOF){
2182  count+=tmp;
2183  }else {
2184  printf("Error in storing data::Unespected End of file encountered");
2185  printf("after position %ld\n",count);
2186  return -count;
2187 
2188  }
2189  }
2190 
2191 }
2192 
2193 if(count!=chksum){
2194  printf("Error in stored data::Stored data number does not match the request");
2195  return -count;
2196 } else {
2197  return count;
2198 }
2199 
2200 }
2201 
2202 
2203 
2204 
2205 
2207 void print_shortbin_elements(SHORTBIN *l,long maxcols)
2208 /* Write a list of int to the standard output */
2209 
2210 {
2211 
2212 
2213 
2214 long i,j;
2215 
2216 
2217 
2218 if(l==NULL || l->co==NULL || (l->isdynamic)!=1 || l->index==NULL){
2219  t_error("The bin was not allocated properly");
2220 } else {
2221  putchar('\n');
2222  for(i=1;i<=(l->index)->nh;i++){
2223  for(j=1;j<=(l->index)->co[i];j++){
2224  /* This is the specialized code for int */
2225  printf("%d ",l->co[i][j]);
2226  if(j%maxcols==0 && j!=(l->index)->co[i]) putchar('\n');
2227  }
2228  putchar('\n');
2229  }
2230 
2231 }
2232 
2233 }
2234 
2236 long read_longbin_elements(FILE *input,LONGBIN *l,char *mode)
2237 /* Read a list of long numbers */
2238 
2239 
2240 {
2241 
2242 long i,j,tmp=0,count=0,chksum=0;
2243 const char ascii[2]="a",binary[2]="b";
2244 
2245 
2246 if(input==NULL){
2247  t_error("The input file was not opened properly");
2248 } else if(l==NULL || l->co==NULL || (l->isdynamic)!=1 || l->index==NULL ){
2249  t_error("The bin was not allocated properly");
2250 
2251 } else if(strcmp(mode,ascii)==0){
2252 
2253  for(i=1;i<=(l->index)->nh;i++){
2254  chksum+=l->index->co[i];
2255  for(j=1;j<=(l->index)->co[i];j++){
2256 
2257  tmp=fscanf(input,"%ld",&(l->co[i][j]));
2258  if(tmp!=EOF){
2259  count+=tmp;
2260  }else{
2261  printf("Error in stored data::Unespected End of file encountered");
2262  printf("after position %ld\n",count);
2263  return -count;
2264 
2265 
2266  }
2267 
2268  }
2269 
2270  }
2271 
2272 
2273 }else if(strcmp(mode,binary)==0){
2274 
2275  for(i=1;i<=(l->index)->nh;i++){
2276  chksum+=l->index->co[i];
2277  tmp=fread((long *)&(l->co[i][1]),sizeof(long),l->index->co[i],input);
2278  if(tmp!=EOF){
2279  count+=tmp;
2280  }else{
2281  printf("Error in stored data::Unexpected End of File encountered");
2282  printf(" after position %ld\n",count);
2283  return -count;
2284  }
2285  }
2286 
2287 
2288 } else {
2289 
2290  t_error("Error in reading mode::Mode not supported");
2291 }
2292 
2293 if(count!=chksum){
2294  printf("Error in stored data::Stored data number does not match the request");
2295  return -count;
2296 } else {
2297  return count;
2298 }
2299 
2300 }
2301 
2303 long write_longbin_elements(FILE * output, LONGBIN *l,long maxcols)
2306 {
2307 
2308 
2309 
2310 long i,j,tmp=0,chksum=0; //count=0
2311 
2312 
2313 
2314 if(output==NULL){
2315  t_error("The output file was not opened properly");
2316 } else if(l==NULL || l->co==NULL || (l->isdynamic)!=1 || l->index==NULL){
2317  t_error("The bin was not allocated properly");
2318 } else {
2319  putc('\n',output);
2320  for(i=1;i<=(l->index)->nh;i++){
2321  chksum+=l->index->co[i];
2322  for(j=1;j<=(l->index)->co[i];j++){
2323  tmp=fprintf(output,"%ld ",l->co[i][j]);
2324  if(tmp==EOF){
2325  printf("Error in storing data::Unespected End of file encountered");
2326  return EOF;
2327  }
2328  if(j%maxcols==0 && j!=(l->index)->co[i]) putc('\n',output);
2329  }
2330  putc('\n',output);
2331  }
2332 
2333 }
2334 
2335 return OK;
2336 
2337 }
2338 
2339 
2340 
2342 long binarywrite_longbin_elements(FILE * output, LONGBIN *l)
2345 {
2346 
2347 
2348 
2349 long i,tmp=0,count=0,chksum=0;
2350 
2353 if(output==NULL){
2354  t_error("The output file was not opened properly");
2355 } else if(l==NULL || l->co==NULL || (l->isdynamic)!=1 || l->index==NULL){
2356  t_error("The bin was not allocated properly");
2357 } else {
2358  putc('\n',output);
2359  for(i=1;i<=(l->index)->nh;i++){
2360  chksum+=l->index->co[i];
2361  tmp=fwrite((long *)&(l->co[i][1]),sizeof(long),l->index->co[i],output);
2362  if(tmp!=EOF){
2363  count+=tmp;
2364  }else {
2365  printf("Error in storing data::Unespected End of file encountered");
2366  printf("after position %ld\n",count);
2367  return -count;
2368 
2369  }
2370  }
2371 
2372 }
2373 
2374 if(count!=chksum){
2375  printf("Error in stored data::Stored data number does not match the request");
2376  return -count;
2377 } else {
2378  return count;
2379 }
2380 
2381 }
2382 
2383 
2384 
2385 
2386 
2388 void print_longbin_elements(LONGBIN *l,long maxcols)
2389 /* Write a list of long to the standard output */
2390 
2391 {
2392 
2393 
2394 
2395 long i,j;
2396 
2397 
2398 
2399 if(l==NULL || l->co==NULL || (l->isdynamic)!=1 || l->index==NULL){
2400  t_error("The bin was not allocated properly");
2401 } else {
2402  putchar('\n');
2403  for(i=1;i<=(l->index)->nh;i++){
2404  for(j=1;j<=(l->index)->co[i];j++){
2405  /* This is the specialized code for long */
2406  printf("%ld ",l->co[i][j]);
2407  if(j%maxcols==0 && j!=(l->index)->co[i]) putchar('\n');
2408  }
2409  putchar('\n');
2410  }
2411 
2412 }
2413 
2414 }
2415 
2417 long read_doublebin_elements(FILE *input,DOUBLEBIN *l,char *mode)
2418 /* Read a list of double numbers */
2419 
2420 
2421 {
2422 
2423 long i,j,tmp=0,count=0,chksum=0;
2424 const char ascii[2]="a",binary[2]="b";
2425 
2426 
2427 if(input==NULL){
2428  t_error("The input file was not opened properly");
2429 } else if(l==NULL || l->co==NULL || (l->isdynamic)!=1 || l->index==NULL ){
2430  t_error("The bin was not allocated properly");
2431 
2432 } else if(strcmp(mode,ascii)==0){
2433 
2434  for(i=1;i<=(l->index)->nh;i++){
2435  chksum+=l->index->co[i];
2436  for(j=1;j<=(l->index)->co[i];j++){
2437 
2438  tmp=fscanf(input,"%lf",&(l->co[i][j]));
2439  if(tmp!=EOF){
2440  count+=tmp;
2441  }else{
2442  printf("Error in stored data::Unespected End of file encountered");
2443  printf("after position %ld\n",count);
2444  return -count;
2445 
2446 
2447  }
2448 
2449  }
2450 
2451  }
2452 
2453 
2454 }else if(strcmp(mode,binary)==0){
2455 
2456  for(i=1;i<=(l->index)->nh;i++){
2457  chksum+=l->index->co[i];
2458  tmp=fread((double *)&(l->co[i][1]),sizeof(double),l->index->co[i],input);
2459  if(tmp!=EOF){
2460  count+=tmp;
2461  }else{
2462  printf("Error in stored data::Unexpected End of File encountered");
2463  printf(" after position %ld\n",count);
2464  return -count;
2465  }
2466  }
2467 
2468 
2469 } else {
2470 
2471  t_error("Error in reading mode::Mode not supported");
2472 }
2473 
2474 if(count!=chksum){
2475  printf("Error in stored data::Stored data number does not match the request");
2476  return -count;
2477 } else {
2478  return count;
2479 }
2480 
2481 }
2482 
2484 long write_doublebin_elements(FILE * output, DOUBLEBIN *l,long maxcols)
2487 {
2488 
2489 
2490 
2491 long i,j,tmp=0,chksum=0; //count=0
2492 
2493 
2494 
2495 if(output==NULL){
2496  t_error("The output file was not opened properly");
2497 } else if(l==NULL || l->co==NULL || (l->isdynamic)!=1 || l->index==NULL){
2498  t_error("The bin was not allocated properly");
2499 } else {
2500  putc('\n',output);
2501  for(i=1;i<=(l->index)->nh;i++){
2502  chksum+=l->index->co[i];
2503  for(j=1;j<=(l->index)->co[i];j++){
2504  tmp=fprintf(output,"%lf ",l->co[i][j]);
2505  if(tmp==EOF){
2506  printf("Error in storing data::Unespected End of file encountered");
2507  return EOF;
2508  }
2509  if(j%maxcols==0 && j!=(l->index)->co[i]) putc('\n',output);
2510  }
2511  putc('\n',output);
2512  }
2513 
2514 }
2515 
2516 return OK;
2517 
2518 }
2519 
2520 
2521 
2526 {
2527 
2528 
2529 
2530 long i,tmp=0,count=0,chksum=0;
2531 
2534 if(output==NULL){
2535  t_error("The output file was not opened properly");
2536 } else if(l==NULL || l->co==NULL || (l->isdynamic)!=1 || l->index==NULL){
2537  t_error("The bin was not allocated properly");
2538 } else {
2539  putc('\n',output);
2540  for(i=1;i<=(l->index)->nh;i++){
2541  chksum+=l->index->co[i];
2542  tmp=fwrite((double *)&(l->co[i][1]),sizeof(double),l->index->co[i],output);
2543  if(tmp!=EOF){
2544  count+=tmp;
2545  }else {
2546  printf("Error in storing data::Unespected End of file encountered");
2547  printf("after position %ld\n",count);
2548  return -count;
2549 
2550  }
2551  }
2552 
2553 }
2554 
2555 if(count!=chksum){
2556  printf("Error in stored data::Stored data number does not match the request");
2557  return -count;
2558 } else {
2559  return count;
2560 }
2561 
2562 }
2563 
2564 
2565 
2566 
2567 
2570 /* Write a list of double to the standard output */
2571 
2572 {
2573 
2574 
2575 
2576 long i,j;
2577 
2578 
2579 
2580 if(l==NULL || l->co==NULL || (l->isdynamic)!=1 || l->index==NULL){
2581  t_error("The bin was not allocated properly");
2582 } else {
2583  putchar('\n');
2584  for(i=1;i<=(l->index)->nh;i++){
2585  for(j=1;j<=(l->index)->co[i];j++){
2586  /* This is the specialized code for double */
2587  printf("%f ",l->co[i][j]);
2588  if(j%maxcols==0 && j!=(l->index)->co[i]) putchar('\n');
2589  }
2590  putchar('\n');
2591  }
2592 
2593 }
2594 
2595 }
2596 
2597 
2598 
2602 STRINGBIN *read_plane_strings(FILE *inputfile,long length,long maxbuffersize)
2603 
2604 {
2605 
2606 //short ind=1;
2607 
2608 long count=0, ll=0, df;
2609 
2610 char *buffer=NULL;
2611 
2612 long int buffer_index=0, buffer_size=0;
2613 
2614 LONGVECTOR *v;
2615 
2616 STRINGBIN *m;
2617 
2618 
2619 
2620 v=new_longvector(length);
2621 
2622 skip_whitespaces(inputfile);
2623 
2624 buffer_size=BUFFERINCREMENT;
2625 
2626  buffer=(char *)malloc((buffer_size+1)*sizeof(char));
2627 
2628  if(buffer==NULL){
2629 
2630  t_error("Cannot allocate the buffer");
2631 
2632  }
2633 
2634 /* The buffer is NULL terminated */
2635 
2636 buffer[buffer_size]='\0';
2637 
2638 do{
2639  if(buffer_index < buffer_size){
2640 
2641  buffer[buffer_index]=fgetc(inputfile);
2642 
2643  if(isspace(buffer[buffer_index])){
2644 
2645  count++;
2646 
2647  /* dimensions of the index of string bins is increased by one
2648  in order to contain the termination character */
2649 
2650  v->co[count]=ll+1;
2651 
2652  ll=0;
2653 
2654  buffer_index++;
2655 
2656  skip_whitespaces(inputfile);
2657 
2658 
2659  }else {
2660 
2661  ++buffer_index;
2662  ll++;
2663 
2664 
2665  }
2666 
2667  }else {
2668 
2669 
2670  if(buffer_size==maxbuffersize){
2671 
2672  printf("Warning::A very long string has exceeded the maximum buffer size\n");
2673 
2674  count++;
2675 
2676  v->co[count]=ll+1;
2677 
2678  ll=0;
2679 
2680  df=v->nh-count;
2681 
2682  printf ("Warning::missing part of string %ld and other %ld strings\n",count,df);
2683 
2684  v->nh=count;
2685 
2686  do{
2687 
2688  buffer[buffer_size-1]=getc(inputfile);
2689 
2690  }while(buffer[buffer_size-1]!=EOF);
2691 
2692 
2693  buffer[buffer_size-1]=' ';
2694 
2695 
2696  break;
2697 
2698 
2699 
2700  } else if(buffer_size + BUFFERINCREMENT > maxbuffersize){
2701 
2702  buffer_size=maxbuffersize;
2703 
2704  buffer=(char *)realloc(buffer,(buffer_size+1)*sizeof(char));
2705 
2706  if(buffer==NULL){
2707 
2708  t_error("Cannot expand the buffer");
2709 
2710  }
2711 
2712  buffer[buffer_size]='\0';
2713 
2714  } else {
2715 
2716  buffer_size+=BUFFERINCREMENT;
2717 
2718  buffer=(char *)realloc(buffer,(buffer_size+1)*sizeof(char));
2719 
2720  if(buffer==NULL){
2721 
2722  t_error("Cannot expand the buffer");
2723 
2724  }
2725 
2726  buffer[buffer_size]='\0';
2727 
2728  }
2729 
2730 
2731  }
2732 
2733 
2734  } while(count < length && buffer[buffer_index-1]!=EOF);
2735 
2736  if(buffer[buffer_index-1]==EOF){
2737 
2738  t_error("Unespected End of file");
2739 
2740  }
2741 
2742 
2743 m=new_stringbin(v);
2744 
2745 copy_buffer_into_stringbin(buffer,m);
2746 
2747 free_longvector(v);
2748 
2749 free(buffer);
2750 
2751 
2752 return m;
2753 
2754 }
2755 
2756 
2758 long write_stringbin_elements(FILE * output, STRINGBIN *l,long maxcols)
2761 {
2762 
2763 
2764 
2765 long i,j,tmp=0,chksum=0; //count=0
2766 
2767 
2768 if(output==NULL){
2769  t_error("The output file was not opened properly");
2770 } else if(l==NULL || l->co==NULL || (l->isdynamic)!=1 || l->index==NULL){
2771  t_error("The bin was not allocated properly");
2772 } else {
2773  putc('\n',output);
2774  for(i=1;i<=(l->index)->nh;i++){
2775  chksum+=l->index->co[i];
2776  for(j=1;j<=(l->index)->co[i];j++){
2777  tmp=fprintf(output,"%c",l->co[i][j]);
2778  if(tmp==EOF){
2779  printf("Error in storing data::Unespected End of file encountered");
2780  return EOF;
2781  }
2782  if(j%maxcols==0 && j!=(l->index)->co[i]-1) putc('\n',output);
2783 
2784  }
2785  putc('\n',output);
2786  }
2787 putc('\n',output);
2788 }
2789 
2790 return OK;
2791 
2792 }
2793 
2794 
2795 
2798 /* Write a list of strings to the standard output */
2799 
2800 {
2801 
2802 
2803 
2804 long i,j;
2805 
2806 
2807 
2808 if(l==NULL || l->co==NULL || (l->isdynamic)!=1 || l->index==NULL){
2809  // printf("%d %d %d\n",l,l->co,l->isdynamic);
2811  t_error("The bin was not allocated properly");
2812 } else {
2813  putchar('\n');
2814  for(i=1;i<=(l->index)->nh;i++){
2815  /* The index below do not go to the last - \0 - element */
2816  for(j=1;j<(l->index)->co[i];j++){
2817  /* This is the specialized code for characters */
2818  printf("%c",l->co[i][j]);
2819  if(j%maxcols==0 && j!=(l->index)->co[i]-1) putchar('\n');
2820  }
2821  putchar('\n');
2822  }
2823 
2824 }
2825 
2826 }
2827 
2828 
2831 /* Write a buffer of strings into its stringbin. "Its" means that
2832 the string bin is already correctly allocated and inizialized */
2833 
2834 {
2835 
2836 
2837 
2838 long i,j,count=0;
2839 
2840 
2841 if(l==NULL || l->co==NULL || (l->isdynamic)!=1 || l->index==NULL){
2842  t_error("The bin was not allocated properly");
2843 
2844 }else if(buffer==NULL){
2845  t_error("The buffer is NULL");
2846 } else {
2847  for(i=1;i<=(l->index)->nh;i++){
2848  for(j=1;j<(l->index)->co[i];j++){
2849  if(buffer[count]!='\0'){
2850  l->co[i][j]=buffer[count];
2851  count++;
2852  } else {
2853  t_error("Unespected end of buffer::The buffer has been scanned completely ");
2854  }
2855  }
2856  if(isspace(buffer[count])) {
2857  count++;
2858  }
2859  l->co[i][(l->index)->co[i]]='\0';
2860  }
2861 
2862 }
2863 
2864 return OK;
2865 
2866 }
2867 
2868 
2869 
2870 
2874 
2875 {
2876 
2877 long count=0,i;
2878 
2879 if(A->isdynamic!=B->isdynamic) {
2880 
2881 count=1;
2882 
2883 }
2884 
2885 if(A->nh!=B->nh) {
2886 
2887 count +=10;
2888 
2889 }
2890 
2891 
2892 for(i=1;i<=A->nh; i++){
2893 
2894  if(A->co[i]!=B->co[i]){
2895 
2896  count+=100;
2897 
2898  }
2899 
2900 }
2901 
2902 return count;
2903 
2904 
2905 }
2906 
2909 void skip_whitespaces(FILE *inputfile)
2910 
2911 {
2912 
2913 int whitespace;
2914 char ctmp;
2915 
2916 do{
2917  whitespace=fgetc(inputfile);
2918  if(whitespace==EOF) printf("\nWarning::Unespected End of File encountered\n");
2919 }while(isspace(whitespace) || iscntrl(whitespace));
2920 
2921 ctmp=ungetc(whitespace,inputfile);
2922 
2923 }
2924 
2927 void goto_EOF(FILE *inputfile)
2928 
2929 
2930 
2931 {
2932 
2933 
2934 
2935 int whitespace;
2936 char ctmp;
2937 
2938 
2939  do{
2940 
2941  whitespace=fgetc(inputfile);
2942 
2943  if(whitespace==EOF) break;
2944 
2945  }while(isspace(whitespace));
2946 
2947  ctmp=ungetc(whitespace,inputfile);
2948 
2949 
2950 
2951 
2952 }
2953 
2954 
2955 
2956 
2959 int iscomment(char *buffer, FILE *inputfile)
2960 
2961 {
2962 
2963 
2964 long buffer_index=0, pos;
2965 
2966 
2967  pos=ftell(inputfile);
2968  skip_whitespaces(inputfile);
2969  while(buffer_index<3){
2970 
2971  buffer[buffer_index]=fgetc(inputfile);
2972  buffer_index++;
2973 
2974  }
2975 
2976  buffer[buffer_index]='\0'; /* buffer_index is 3 */
2977 
2978 
2979  if(strcmp(buffer,"/**")!=0) {
2980  fseek(inputfile,pos,SEEK_SET);
2981  return buffer_index=0;
2982 
2983  } else {
2984 
2985  return buffer_index;
2986 
2987  }
2988 
2989 }
2990 
2993 
2994 {
2995 
2996  char buffer[64*FILENAME_MAX],*bf,*pathfile="$WorkingPath";
2997  long len,i;
2998  short a;
2999  FILE *istream;
3000 
3001  istream=fopen(pathfile,"r");
3002  if(istream){
3003  i=0;
3004  a=0;
3005  do{
3006  if(i==0){
3007  bf = (char *) malloc(sizeof(char));
3008  }else{
3009  bf = (char *)realloc(bf,(i+1)*sizeof(char));
3010  }
3011  bf[i]=fgetc(istream);
3012  if(bf[i]==10 || bf[i]==-1){
3013  a=1;
3014  bf[i]=0;
3015  }
3016  i+=1;
3017  }while(a==0);
3018  fclose(istream);
3019  }else{
3020 
3021  printf("ENTER THE WORKING DIRECTORY PATH:\n");
3022  scanf("%s",buffer); /* This line is note clear, comment by Emanuele Cordano on 1 September 2009 */
3023  len=64*FILENAME_MAX;
3024 
3025  if(len > (64*FILENAME_MAX)){
3026  t_error("Maximum path length exceeded");
3027  } else {
3028  bf=(char *)malloc(len*sizeof(char));
3029  }
3030 
3031  strcpy(bf,buffer);
3032  }
3033  return bf;
3034 }
3035 
3036 
3039 char * join_strings(char *first,char *second)
3040 
3041 {
3042 
3043  char *string;
3044  long len=0;
3045 
3046 
3047  len=strlen(first);
3048  len+=strlen(second)+2;
3049  string=(char *)malloc(len*sizeof(char));
3050  string=strcpy(string,first);
3051  string=strcat(string,second);
3052  return string;
3053 }
3054 
3058 char *get_filename(char *working_directory,char *program)
3059 
3060 {
3061 
3062  char *name="\0",*fullname="\0",*pathfile="\0",*S=".inpts";
3063  FILE *istream;
3064  static STRINGBIN *strg;
3065  long position=-1;
3066  short sign=0;
3067 
3068 
3069  pathfile=join_strings(working_directory,join_strings(program,S));
3070 
3071  if(IO_FILES_COUNTER==0){
3072  istream=fopen(pathfile,"r");
3073  if(istream){
3074  position=simplefind(istream,"1:");
3075  if(position==-1){
3076  t_error("String not found");
3077  }else{
3078  strg=read_stringarray(istream, NOPRINT);
3079  if(strg==NULL){
3080  name=(char *)malloc(FILENAME_MAX*sizeof(char));
3081  if(!name) t_error("There was no allocation space");
3082  sign++;
3083  scanf("%s",name);
3084 
3085  }else{
3086  /* print_stringbin_elements(s,80); */
3087  IO_FILES_COUNTER++;
3088  name=(strg->co[IO_FILES_COUNTER]+1);
3089  WORKING_POSITION=ftell(istream);
3090  t_fclose(istream);
3091  }
3092 
3093  }
3094 
3095  } else {
3096  name=(char *)malloc(FILENAME_MAX*sizeof(char));
3097  if(!name) t_error("There was no allocation space");
3098  sign++;
3099  scanf("%s",name);
3100 
3101  }
3102 
3103  } else if(IO_FILES_COUNTER < strg->index->nh){
3104  IO_FILES_COUNTER++;
3105  name=(strg->co[IO_FILES_COUNTER]+1);
3106 
3107  } else {
3108  name=(char *)malloc(FILENAME_MAX*sizeof(char));
3109  if(!name) t_error("There was no allocation space");
3110  sign++;
3111  scanf("%s",name);
3112  }
3113 
3114  fullname=join_strings(working_directory,name);
3115  printf("%s\n",fullname);
3116  if(sign==1) free(name);
3117  sign=0;
3118 
3119  return fullname;
3120 
3121 }
3122 
3123 
3126 double get_parameter(char *working_directory,char *program)
3127 
3128 {
3129 
3130 char *pathfile="\0",*S=".inpts"; //*fullname="\0",
3131 FILE *istream;
3132 static DOUBLEVECTOR *s;
3133 long position=-1;
3134 //short sign=0;
3135 double parameter=0;
3136 
3137 pathfile=join_strings(working_directory,join_strings(program,S));
3138 
3139 if(IO_PARMS_COUNTER==0){
3140  istream=fopen(pathfile,"r");
3141 
3142  if(istream){
3143  position=simplefind(istream,"2:");
3144  if(position==-1){
3145  t_error("String not found");
3146  }else{
3147  s=read_doublearray(istream,NOPRINT);
3148  IO_PARMS_COUNTER++;
3149  parameter=s->co[IO_PARMS_COUNTER];
3150  WORKING_POSITION=ftell(istream);
3151  t_fclose(istream);
3152  }
3153  } else {
3154  scanf(" %lf",&parameter);
3155  }
3156 } else if(IO_PARMS_COUNTER < s->nh){
3157  IO_PARMS_COUNTER++;
3158  parameter=s->co[IO_PARMS_COUNTER];
3159 } else {
3160  scanf(" %lf",&parameter);
3161 }
3162 printf("%f\n",parameter);
3163 return parameter;
3164 
3165 }
3166 
3167 
3170 char *get_strings(char *working_directory,char *program)
3171 
3172 {
3173 
3174  char *name="\0",*pathfile="\0",*S=".inpts";//*fullname="\0"
3175  FILE *istream;
3176  static STRINGBIN *s;
3177  long position=-1;
3178  short sign=0;
3179 
3180  pathfile=join_strings(working_directory,join_strings(program,S));
3181  if(IO_FILES_COUNTER==0){
3182  istream=fopen(pathfile,"r");
3183  if(istream){
3184  position=simplefind(istream,"1:");
3185  if(position==-1){
3186  t_error("String not found");
3187  }else{
3188  s=read_stringarray(istream, NOPRINT);
3189  if(s==NULL){
3190  name=(char *)malloc(FILENAME_MAX*sizeof(char));
3191  if(!name) t_error("There was no allocation space");
3192  sign++;
3193  scanf("%s",name);
3194 
3195  }else{
3196  /* print_stringbin_elements(s,80); */
3197  IO_FILES_COUNTER++;
3198  name=(s->co[IO_FILES_COUNTER]+1);
3199  WORKING_POSITION=ftell(istream);
3200  t_fclose(istream);
3201  }
3202 
3203  }
3204  } else {
3205  name=(char *)malloc(FILENAME_MAX*sizeof(char));
3206  if(!name) t_error("There was no allocation space");
3207  sign++;
3208  scanf("%s",name);
3209 
3210  }
3211 
3212  } else if(IO_FILES_COUNTER < s->index->nh){
3213  IO_FILES_COUNTER++;
3214  name=(s->co[IO_FILES_COUNTER]+1);
3215  } else {
3216  name=(char *)malloc(FILENAME_MAX*sizeof(char));
3217  if(!name) t_error("There was no allocation space");
3218  sign++;
3219  scanf("%s",name);
3220  }
3221 
3222 
3223  printf("%s\n",name);
3224  return name;
3225 
3226 }
3227 
3230 STRINGBIN *read_filenames(char *working_directory,char *program, char *extension, char *position){
3231 
3232  STRINGBIN *strg;
3233  FILE *istream;
3234  long i,pos=-1;
3235 
3236  istream=fopen(join_strings(working_directory,join_strings(program,extension)),"r");
3237 
3238  if(istream){
3239  pos=simplefind(istream,position);
3240  if(pos==-1) t_error("string not found");
3241  strg=read_stringarray(istream, NOPRINT);
3242  fclose(istream);
3243  }else{
3244  t_error("File does not exist");
3245  }
3246 
3247  for(i=1;i<=strg->index->nh;i++){
3248  strg->co[i]=join_strings(working_directory,strg->co[i]+1)-1;
3249  }
3250 
3251  return strg;
3252 }
3253 
3255 DOUBLEVECTOR *read_parameters(char *working_directory,char *program, char *extension, char *position){
3256 
3257  DOUBLEVECTOR *v;
3258  FILE *istream;
3259  long pos=-1;
3260 
3261  istream=fopen(join_strings(working_directory,join_strings(program,extension)),"r");
3262 
3263  if(istream){
3264  pos=simplefind(istream,position);
3265  if(pos==-1) t_error("string not found");
3266  v=read_doublearray(istream, NOPRINT);
3267  fclose(istream);
3268  }else{
3269  t_error("File does not exist");
3270  }
3271 
3272  return v;
3273 }
3274 
3275 
3278 char *query_for_label(FILE *inputfile)
3279 
3280 
3281 
3282 {
3283 
3284 char ch,ocurl='{';
3285 static char *label=NULL;
3286 long i=0,label_size=0;
3287 
3288 
3289  label_size=LABELINCREMENT;
3290 
3291  label=(char *)malloc(label_size*sizeof(char));
3292 
3293  if(label==NULL){
3294 
3295  t_error("Cannot allocate the label");
3296 
3297  }
3298 
3299 
3300 
3301  skip_whitespaces(inputfile);
3302 
3303  do{
3304 
3305  if(i< label_size-1) {
3306 
3307 
3308  label[i]=fgetc(inputfile);
3309 
3310  if(label[i]==EOF){
3311 
3312  t_error("Unespected End Of File");
3313 
3314  }
3315 
3316  i++;
3317 
3318 
3319  } else {
3320 
3321  if(label_size==MAXLABELSIZE){
3322 
3323  printf("\nWarning:: the name of the stored data exceeded the LABELSIZE\n");
3324 
3325  printf("Warning:: flushing the rest of the name\n");
3326 
3327  do{
3328 
3329  ch=fgetc(inputfile);
3330 
3331  }while(ch!=ocurl && ch!=EOF);
3332 
3333  if(ch==EOF){
3334 
3335  t_error("Unespected End Of File");
3336 
3337  }
3338 
3339  label[i-1]=ch;
3340 
3341  }else if(label_size + LABELINCREMENT > MAXLABELSIZE){
3342 
3343  label_size=MAXLABELSIZE;
3344 
3345  label=(char *)realloc(label,label_size*sizeof(char));
3346 
3347  if(label==NULL){
3348 
3349  t_error("Cannot expand the label");
3350 
3351 
3352  }
3353 
3354 
3355 
3356  } else {
3357 
3358  label_size+=LABELINCREMENT;
3359 
3360  label=(char *)realloc(label,label_size*sizeof(char));
3361 
3362  if(label==NULL){
3363 
3364  t_error("Cannot expand the label");
3365 
3366 
3367  }
3368  }
3369  }
3370 
3371  } while(label[i-1]!=EOF && label[i-1]!=ocurl);
3372 
3373  ungetc(label[i-1],inputfile);
3374  label[i]=label[i-1]='\0';
3375  i-=2;
3376 
3377  while(isspace(label[i])){
3378  label[i]='\0';
3379  i--;
3380  }
3381 
3382  i++;
3383 
3384 
3385  if(i<=0){
3386 
3387  label="NOLABEL";
3388 
3389  }
3390 
3391  return label;
3392 
3393 
3394 
3395 
3396 }
3397 
3400 char *get_phrase(FILE *inputfile,const char separator)
3401 
3402 
3403 
3404 {
3405 
3406 
3407 
3408 static char *label=NULL,ch;
3409 
3410 long i=0,label_size=0;
3411 
3412 
3413  label_size=LABELINCREMENT;
3414 
3415  label=(char *)malloc(label_size*sizeof(char));
3416 
3417  if(label==NULL){
3418 
3419  t_error("Cannot allocate the label");
3420 
3421  }
3422 
3423 
3424 
3425  skip_whitespaces(inputfile);
3426 
3427  do{
3428 
3429  if(i< label_size-1) {
3430 
3431  label[i]=fgetc(inputfile);
3432 
3433  if(label[i]==EOF){
3434 
3435  t_error("Unespected End Of File");
3436 
3437  }
3438 
3439  i++;
3440 
3441 
3442  } else {
3443 
3444  if(label_size==MAXLABELSIZE){
3445 
3446  printf("\nWarning:: the name of the stored data exceeded the LABELSIZE\n");
3447 
3448  printf("Warning:: flushing the rest of the name\n");
3449 
3450  do{
3451 
3452  ch=fgetc(inputfile);
3453 
3454  }while(ch!=EOF && ch!=separator);
3455 
3456  if(ch==EOF){
3457 
3458  t_error("Unespected End Of File");
3459 
3460  }
3461 
3462  label[i-1]=ch;
3463 
3464 
3465  }else if(label_size + LABELINCREMENT > MAXLABELSIZE){
3466 
3467  label_size=MAXLABELSIZE;
3468 
3469  label=(char *)realloc(label,label_size*sizeof(char));
3470 
3471  if(label==NULL){
3472 
3473  t_error("Cannot expand the label");
3474 
3475 
3476  }
3477 
3478 
3479 
3480  } else {
3481 
3482  label_size+=LABELINCREMENT;
3483 
3484  label=(char *)realloc(label,label_size*sizeof(char));
3485 
3486  if(label==NULL){
3487 
3488  t_error("Cannot expand the label");
3489 
3490 
3491  }
3492  }
3493 
3494 
3495  }
3496 
3497  } while(label[i-1]!=EOF && label[i-1]!=separator);
3498 
3499  /* if( giveback ) ungetc(label[i-1],inputfile); */
3500 
3501  label[i-1]='\0';
3502 
3503  i--;
3504 
3505  if(i==0){
3506 
3507  label="NOLABEL";
3508 
3509  }
3510 
3511 
3512  /* return label; */
3513  return join_strings(WORKING_DIRECTORY,label);
3514 
3515 
3516 
3517 
3518 }
3519 
3522 int query_for_token(FILE *inputfile,const char *token)
3523 
3524 
3525 
3526 {
3527 
3528 
3529 
3530 char keyword[64];
3531 
3532 long pos,len,i;
3533 
3534  pos=ftell(inputfile);
3535 
3536  skip_whitespaces(inputfile);
3537 
3538  len=strlen(token);
3539 
3540  for(i=0;i<=len-1;i++){
3541 
3542  keyword[i]=fgetc(inputfile);
3543  /* printf("%c",keyword[i]); */
3544 
3545  }
3546 
3547  keyword[len]='\0';
3548 
3549  if(strcmp(token,keyword)!=0){
3550 
3551  fseek(inputfile,pos,SEEK_SET);
3552 
3553  return 0;
3554 
3555  }else{
3556 
3557  return 1;
3558 
3559  }
3560 
3561 
3562 }
3563 
3564 
3571 int read_comment(FILE *inputfile,int opt,long maxbuffersize,short print)
3572 
3573 
3574 
3575 {
3576 
3577 
3578 
3579 
3580 
3581 char *buffer=NULL;
3582 
3583 
3584 
3585 long int buffer_index=0, buffer_size=0;
3586 
3587 
3588 
3589 
3590 
3591 if(inputfile==NULL){
3592 
3593 
3594 
3595  t_error("You tried to read from a closed file ");
3596 
3597 
3598 
3599 }
3600 
3601 
3602 
3603 
3604 
3605 buffer_size=BUFFERINCREMENT;
3606 
3607 
3608 
3609 buffer=(char *)malloc(buffer_size*sizeof(char));
3610 
3611 
3612 
3613 if(buffer==NULL){
3614 
3615 
3616 
3617  t_error("Cannot allocate the buffer");
3618 
3619 
3620 
3621 }
3622 
3623 
3624 
3625 
3626 
3627 buffer[buffer_size-1]='\0';
3628 buffer[0]=buffer[1]=buffer[2]='\0';
3629 
3630 
3631 if(opt==1){
3632 
3633 
3634 
3635  buffer_index=iscomment(buffer,inputfile);
3636 
3637 
3638 
3639 }else{
3640 
3641 
3642 
3643  buffer[0]='/'; buffer[1]='*'; buffer[2]='*';
3644 
3645 
3646 
3647  buffer_index=3;
3648 
3649 
3650 
3651 }
3652 
3653 
3654 
3655 if (buffer_index==0){
3656 
3657  printf("\nWarning:: no comment found\n");
3658 
3659  return 0;
3660 }
3661 
3662 
3663 
3664 do{
3665 
3666 
3667 
3668 
3669 
3670  if(buffer_index < buffer_size-2){
3671 
3672 
3673 
3674 
3675 
3676  buffer[buffer_index]=fgetc(inputfile);
3677 
3678 
3679 
3680  if(buffer[buffer_index]=='*'){
3681 
3682 
3683 
3684  buffer_index++;
3685 
3686 
3687 
3688  buffer[buffer_index]=fgetc(inputfile);
3689 
3690 
3691 
3692  if(buffer[buffer_index]=='/'){
3693 
3694 
3695 
3696  buffer_index++;
3697 
3698 
3699 
3700  buffer[buffer_index]='\0';
3701 
3702 
3703 
3704  break;
3705 
3706 
3707 
3708  } else {
3709 
3710 
3711 
3712  buffer_index++;
3713 
3714 
3715 
3716  }
3717 
3718 
3719 
3720  } else {
3721 
3722 
3723 
3724  ++buffer_index;
3725 
3726 
3727 
3728  }
3729 
3730 
3731 
3732  } else {
3733 
3734 
3735 
3736  if(buffer_size==maxbuffersize){
3737 
3738 
3739 
3740 
3741 
3742  printf("\nWarning::A very long comment has exceeded the maximum buffer size\n");
3743 
3744 
3745 
3746  printf("\nWarnin::Flushing the rest of the comment \n" );
3747 
3748 
3749 
3750  buffer[buffer_size-8]=' ';
3751 
3752 
3753 
3754  buffer[buffer_size-7]='.';
3755 
3756 
3757 
3758  buffer[buffer_size-6]='.';
3759 
3760 
3761 
3762  buffer[buffer_size-5]='.';
3763 
3764 
3765 
3766  buffer[buffer_size-4]=' ';
3767 
3768 
3769 
3770  do{
3771 
3772  do{
3773 
3774 
3775 
3776  buffer[buffer_size-3]=getc(inputfile);
3777 
3778 
3779 
3780  }while(buffer[buffer_size-3]!='*');
3781 
3782 
3783 
3784  buffer[buffer_size-2]=getc(inputfile);
3785 
3786 
3787 
3788  }while(buffer[buffer_size-2] !='/');
3789 
3790 
3791 
3792  if(buffer[buffer_size-2]==EOF){
3793 
3794 
3795 
3796  t_error("Unespected end of file: comment closed by End of file");
3797 
3798 
3799 
3800  } else {
3801 
3802 
3803 
3804  break;
3805 
3806 
3807 
3808  }
3809 
3810 
3811 
3812  } else if(buffer_size + BUFFERINCREMENT > maxbuffersize){
3813 
3814 
3815 
3816  buffer_size=maxbuffersize;
3817 
3818 
3819 
3820  buffer=(char *)realloc(buffer,buffer_size*sizeof(char));
3821 
3822 
3823 
3824  if(buffer==NULL){
3825 
3826 
3827 
3828  t_error("Cannot expand the buffer");
3829 
3830 
3831 
3832  }
3833 
3834 
3835 
3836  buffer[buffer_size-1]='\0';
3837 
3838 
3839 
3840  } else {
3841 
3842 
3843 
3844  buffer_size+=BUFFERINCREMENT;
3845 
3846 
3847 
3848  buffer=(char *)realloc(buffer,buffer_size*sizeof(char));
3849 
3850 
3851 
3852  if(buffer==NULL){
3853 
3854 
3855 
3856  t_error("Cannot expand the buffer");
3857 
3858 
3859 
3860  }
3861 
3862 
3863 
3864  buffer[buffer_size-1]='\0';
3865 
3866 
3867 
3868  }
3869 
3870  }
3871 
3872 
3873 
3874 } while( buffer[buffer_index-1]!=EOF );
3875 
3876 
3877 
3878 
3879 
3880 if(buffer[buffer_index-1]==EOF ){
3881 
3882 
3883 
3884  t_error("Unespected end of file: comment closed by End of file");
3885 
3886 
3887 
3888 }
3889 
3890 
3891 
3892 
3893 
3894 if(print) printf("\n%s\n",buffer);
3895 
3896 
3897 
3898 free(buffer);
3899 
3900 
3901 
3902 return buffer_index;
3903 
3904 
3905 
3906 
3907 
3908 }
3909 
3910 
3911 
3912 
3913 
3914 
3921 char *readandstore_comment(FILE *inputfile,int opt,long maxbuffersize)
3922 
3923 
3924 {
3925 
3926 
3927 
3928 
3929 
3930 char *buffer=NULL;
3931 
3932 
3933 
3934 long int buffer_index=0, buffer_size=0;
3935 
3936 
3937 
3938 
3939 
3940 if(inputfile==NULL){
3941 
3942 
3943 
3944  t_error("You tried to read from a closed file ");
3945 
3946 
3947 
3948 }
3949 
3950 
3951 
3952 
3953 
3954 buffer_size=BUFFERINCREMENT;
3955 
3956 
3957 
3958 buffer=(char *)malloc(buffer_size*sizeof(char));
3959 
3960 
3961 
3962 if(buffer==NULL){
3963 
3964 
3965 
3966  t_error("Cannot allocate the buffer");
3967 
3968 
3969 
3970 }
3971 
3972 
3973 
3974 
3975 
3976 buffer[buffer_size-1]='\0';
3977 
3978 
3979 
3980 if(opt==1){
3981 
3982 
3983 
3984  buffer_index=iscomment(buffer,inputfile);
3985 
3986 
3987 
3988 }else{
3989 
3990 
3991 
3992  buffer[0]='/'; buffer[1]='*'; buffer[2]='*';
3993 
3994 
3995 
3996  buffer_index=3;
3997 
3998 
3999 
4000 }
4001 
4002 
4003 
4004 
4005 
4006 
4007 
4008 do{
4009 
4010 
4011 
4012 
4013 
4014  if(buffer_index < buffer_size-2){
4015 
4016 
4017 
4018 
4019 
4020  buffer[buffer_index]=fgetc(inputfile);
4021 
4022 
4023 
4024  if(buffer[buffer_index]=='*'){
4025 
4026 
4027 
4028  buffer_index++;
4029 
4030 
4031 
4032  buffer[buffer_index]=fgetc(inputfile);
4033 
4034 
4035 
4036  if(buffer[buffer_index]=='/'){
4037 
4038 
4039 
4040  buffer_index++;
4041 
4042 
4043 
4044  buffer[buffer_index]='\0';
4045 
4046 
4047 
4048  break;
4049 
4050 
4051 
4052  } else {
4053 
4054 
4055 
4056  buffer_index++;
4057 
4058 
4059 
4060  }
4061 
4062 
4063 
4064  } else {
4065 
4066 
4067 
4068  ++buffer_index;
4069 
4070 
4071 
4072  }
4073 
4074 
4075 
4076  } else {
4077 
4078 
4079 
4080  if(buffer_size==maxbuffersize){
4081 
4082 
4083 
4084 
4085 
4086  printf("\nWarning::A very long comment has exceeded the maximum buffer size\n");
4087 
4088 
4089 
4090  printf("\nWarnin::Flushing the rest of the comment \n" );
4091 
4092 
4093 
4094  buffer[buffer_size-8]=' ';
4095 
4096 
4097 
4098  buffer[buffer_size-7]='.';
4099 
4100 
4101 
4102  buffer[buffer_size-6]='.';
4103 
4104 
4105 
4106  buffer[buffer_size-5]='.';
4107 
4108 
4109 
4110  buffer[buffer_size-4]=' ';
4111 
4112 
4113 
4114  do{
4115 
4116  do{
4117 
4118 
4119 
4120  buffer[buffer_size-3]=getc(inputfile);
4121 
4122 
4123 
4124  }while(buffer[buffer_size-3]!='*');
4125 
4126 
4127 
4128  buffer[buffer_size-2]=getc(inputfile);
4129 
4130 
4131 
4132  }while(buffer[buffer_size-2] !='/');
4133 
4134 
4135 
4136  if(buffer[buffer_size-2]==EOF){
4137 
4138 
4139 
4140  t_error("Unespected end of file: comment closed by End of file");
4141 
4142 
4143 
4144  } else {
4145 
4146 
4147 
4148  break;
4149 
4150 
4151 
4152  }
4153 
4154 
4155 
4156  } else if(buffer_size + BUFFERINCREMENT > maxbuffersize){
4157 
4158 
4159 
4160  buffer_size=maxbuffersize;
4161 
4162 
4163 
4164  buffer=(char *)realloc(buffer,buffer_size*sizeof(char));
4165 
4166 
4167 
4168  if(buffer==NULL){
4169 
4170 
4171 
4172  t_error("Cannot expand the buffer");
4173 
4174 
4175 
4176  }
4177 
4178 
4179 
4180  buffer[buffer_size-1]='\0';
4181 
4182 
4183 
4184  } else {
4185 
4186 
4187 
4188  buffer_size+=BUFFERINCREMENT;
4189 
4190 
4191 
4192  buffer=(char *)realloc(buffer,buffer_size*sizeof(char));
4193 
4194 
4195 
4196  if(buffer==NULL){
4197 
4198 
4199 
4200  t_error("Cannot expand the buffer");
4201 
4202 
4203 
4204  }
4205 
4206 
4207 
4208  buffer[buffer_size-1]='\0';
4209 
4210 
4211 
4212  }
4213 
4214  }
4215 
4216 
4217 
4218 } while( buffer[buffer_index-1]!=EOF );
4219 
4220 
4221 
4222 
4223 
4224 if(buffer[buffer_index-1]==EOF ){
4225 
4226 
4227 
4228  t_error("Unespected end of file: comment closed by End of file");
4229 
4230 
4231 
4232 }
4233 
4234 
4235 return buffer;
4236 
4237 
4238 
4239 
4240 
4241 }
4242 
4243 
4244 
4245 
4246 
4247 
4256 char *read_buffer_from_stdio(long maxbuffersize)
4257 
4258 
4259 
4260 
4261 
4262 {
4263 
4264 
4265 
4266 char *bffr=NULL;
4267 
4268 long int buffer_index=0, buffer_size=0,h;
4269 
4270 if(BUFFERINCREMENT > maxbuffersize){
4271  printf("\nWarning::BUFFERINCREMENT is larger than MAXBUFFERSIZE\n");
4272  buffer_size=maxbuffersize;
4273 }else{
4274  buffer_size=BUFFERINCREMENT;
4275 }
4276 
4277 
4278 bffr=(char *)malloc(buffer_size*sizeof(char));
4279 
4280 if(bffr==NULL){
4281  t_error("Cannot allocate the buffer");
4282 }
4283 
4284 
4285 
4286 bffr[buffer_size-1]='\0';
4287 bffr[0]='\0';
4288 bffr[1]='\0';
4289 bffr[2]='\0';
4290 
4291 
4292 
4293 
4294 h=1;
4295 
4296 
4297 
4298 while(!(bffr[0]=='/' && bffr[1]=='*' && bffr[2]=='*')){
4299 
4300  if(h>1){
4301 
4302  printf("TO START A COMMENT DIGIT '/**' OTHERWISE 'N' \n");
4303 
4304 
4305 
4306  }
4307 
4308 
4309 
4310  do{
4311 
4312  bffr[0]=getchar();
4313 
4314  if(bffr[0]=='N') {
4315 
4316  bffr[0]='\0';
4317 
4318  return bffr;
4319 
4320  }
4321 
4322 
4323  }while(bffr[0]!='/');
4324 
4325  bffr[1]=getchar();
4326 
4327  bffr[2]=getchar();
4328 
4329  h++;
4330 
4331 
4332 }
4333 
4334 buffer_index=0;
4335 
4336 
4337 
4338 do{
4339 
4340 
4341 
4342  if(buffer_index < buffer_size-1){
4343 
4344  bffr[buffer_index]=getchar();
4345 
4346  buffer_index++;
4347 
4348  } else {
4349 
4350 
4351 
4352  if(buffer_size==maxbuffersize){
4353 
4354  printf("\nWarning::A very long comment has exceeded the maximum buffer size\n");
4355 
4356  printf("Warning::Closing the comment\n");
4357 
4358  bffr[buffer_index-2]='\n';
4359 
4360  bffr[buffer_index-3]=' ';
4361 
4362  bffr[buffer_index-4]='.';
4363 
4364  bffr[buffer_index-5]='.';
4365 
4366  bffr[buffer_index-6]='.';
4367 
4368  bffr[buffer_index-7]=' ';
4369 
4370  break;
4371 
4372 } else if(buffer_size + BUFFERINCREMENT > maxbuffersize){
4373 
4374 
4375 
4376  buffer_size=maxbuffersize;
4377 
4378  bffr=(char *)realloc(bffr,buffer_size*sizeof(char));
4379 
4380  if(bffr==NULL){
4381 
4382  t_error("Cannot expand the buffer");
4383 
4384 
4385 
4386 }
4387 
4388 
4389 
4390  bffr[buffer_size-1]='\0';
4391 
4392 
4393 
4394 } else {
4395 
4396 
4397 
4398  buffer_size+=BUFFERINCREMENT;
4399 
4400  bffr=(char *)realloc(bffr,buffer_size*sizeof(char));
4401 
4402  if(bffr==NULL){
4403 
4404  t_error("Cannot expand the buffer");
4405 
4406 
4407 
4408  }
4409 
4410 
4411 
4412  bffr[buffer_size-1]='\0';
4413 
4414 }
4415 
4416 
4417 
4418 }
4419 
4420 
4421 
4422 } while( !(bffr[buffer_index-1]=='\n' && bffr[buffer_index-2]=='/' && bffr[buffer_index-3]=='*') );
4423 
4424 
4425 
4426 bffr[buffer_index-3]='\0';
4427 
4428 
4429 
4430 return bffr;
4431 
4432 
4433 
4434 }
4435 
4436 
4437 
4438 
4439 
4442 long read_index(FILE *inputfile,short print)
4443 
4444 {
4445 
4446 char buffer[FILENAME_MAX],curl,ocurl='{',ccurl='}';
4447 long buffer_index=0,pos=0;//blocksnumber=0
4448 long blocks;
4449 
4450 if(inputfile==NULL){
4451  t_error("You tried to read from a closed file ");
4452 }
4453 
4454 while(iscomment(buffer,inputfile)){
4455  /* read_comment(inputfile,0,MAXBUFFERSIZE,NOPRINT); */
4456  read_comment(inputfile,0,MAXBUFFERSIZE,print);
4457 }
4458 pos=ftell(inputfile);
4459 skip_whitespaces(inputfile);
4460 
4461 if(query_for_token(inputfile,"index")){
4462 
4463  skip_whitespaces(inputfile);
4464  curl=fgetc(inputfile);
4465 
4466  if(curl!=ocurl) {
4467  t_error("A non expected character found");
4468  }
4469 
4470  fscanf(inputfile,"%ld",&blocks);
4471  skip_whitespaces(inputfile);
4472 
4473  buffer_index=0;
4474  buffer[buffer_index]=fgetc(inputfile);
4475  buffer_index++;
4476 
4477  if(buffer[buffer_index-1]==','){
4478  buffer_index--;
4479  do{
4480  buffer[buffer_index]=fgetc(inputfile);
4481  buffer_index++;
4482  }while(buffer_index < FILENAME_MAX && buffer[buffer_index-1]!=ccurl);
4483  }
4484 
4485  if(buffer[buffer_index-1]!=ccurl){
4486  t_error("Missing closing curl");
4487  } else {
4488  buffer[buffer_index-1]='\0';
4489  if(print) printf("\nTHIS FILE TYPE %s\n\n",buffer);
4490  }
4491 }else{
4492  printf("No blocks specified. One asci block assumed. \n");
4493  blocks=1;
4494 }
4495 
4496 return blocks;
4497 
4498 }
4499 
4504 int header_scan(FILE* inputfile,HEADER * h)
4505 
4506 {
4507 
4508 
4509 
4510 char buffer[64],semicolon, keyword[MAX_KEYWORD_LENGTH+1],ch;
4511 
4512 char ocurl='{';//ccurl='}';
4513 
4514 //short y=-1,yy=-1;
4515 
4516 
4517 
4518 long i,j,len,pos;
4519 
4520 extern t_keywords T_KEYWORDS;
4521 
4522 
4523 
4524 
4525 
4526 if((h)==NULL){
4527 
4528 
4529 
4530  t_error("This header was not allocated");
4531 
4532 
4533 
4534 }
4535 
4536 
4537 while(iscomment(buffer,inputfile)){
4538  read_comment(inputfile,0,MAXBUFFERSIZE,NOPRINT);
4539 }
4540 
4541 /*
4542 read_comment(inputfile,1,MAXBUFFERSIZE,PRINT);
4543 */
4544 pos=ftell(inputfile);
4545 
4546 fscanf(inputfile,"%ld %c",&(h->number),&semicolon);
4547 
4548 
4549 if(semicolon!=':'){
4550 
4551  h->number=0;
4552 
4553  fseek(inputfile,pos,SEEK_SET);
4554 
4555 } else {
4556 
4557 
4558 
4559  pos=ftell(inputfile);
4560 
4561 }
4562 
4563 
4564 
4565 /* scans the gender, the type and the category of the variable and fills the
4566 
4567 appropriate subvariable of the header */
4568 
4569 
4570 
4571 skip_whitespaces(inputfile);
4572 
4573 
4574 
4575  /* Looking for the gender */
4576 
4577 
4578 
4579 i=0;
4580 
4581 
4582 
4583 ch=fgetc(inputfile);
4584 
4585 /*
4586 printf("^^^%c^^^\n",ch);
4587 */
4588 do{
4589 
4590 
4591 
4592  keyword[i]=ch;
4593 
4594  ch=fgetc(inputfile);
4595 
4596  i++;
4597 
4598 
4599 
4600  }while(!isspace(ch) && ch!=ocurl);
4601 
4602 
4603 
4604 
4605 
4606 keyword[i]='\0';
4607 
4608 
4609 
4610 /* len=strtol(T_KEYWORDS.gender[0],tmp , 10);
4611 
4612 
4613 
4614  if(!len){
4615 
4616  t_error("Error in reading the number of keyword genders");
4617 
4618  }
4619 
4620 */
4621 
4622 
4623 
4624 len=2;
4625 
4626 
4627 
4628 
4629 
4630 j=0;
4631 
4632 
4633 
4634 
4635 
4636 do{
4637 
4638  j++;
4639 
4640 
4641 
4642 } while(strcmp(T_KEYWORDS.gender[j],keyword)!=0 && j <=len);
4643 
4644 
4645 
4646 
4647 
4648 if(j > len){
4649 
4650 
4651 
4652  h->gender=1;
4653 
4654 
4655 
4656 }else{
4657 
4658 
4659 
4660  h->gender=j;
4661 
4662 
4663 
4664  if(ch!=ocurl) i=0;
4665 
4666 
4667 
4668  else i=-1;
4669 
4670 }
4671 
4672 
4673 
4674 
4675 
4676 /* Looking for the type */
4677 
4678 
4679 
4680 
4681 
4682 if(i==0){
4683 
4684 
4685 
4686  pos=ftell(inputfile);
4687 
4688 
4689 
4690  skip_whitespaces(inputfile);
4691 
4692 
4693 
4694  ch=fgetc(inputfile);
4695 
4696 
4697 
4698  do{
4699 
4700 
4701 
4702  keyword[i]=ch;
4703 
4704  ch=fgetc(inputfile);
4705 
4706  i++;
4707 
4708 
4709 
4710  }while(!isspace(ch) && ch!=ocurl );
4711 
4712 
4713 
4714  keyword[i]='\0';
4715 
4716 
4717 
4718 }
4719 
4720 
4721 
4722 /* len=strtol(T_KEYWORDS.type[0],tmp,10);\
4723 
4724 if(!len){
4725 
4726  t_error("Error in reading the number of keywords types");
4727 
4728 }
4729 
4730  */
4731 
4732 
4733 
4734 len=7;
4735 
4736 
4737 
4738 
4739 
4740 j=0;
4741 
4742 
4743 
4744 do{
4745 
4746  j++;
4747 
4748 
4749 
4750 } while(strcmp(T_KEYWORDS.type[j],keyword)!=0 && j <=len);
4751 
4752 
4753 
4754 if(j > len){
4755 
4756 
4757 
4758  h->type=5;
4759 
4760 
4761 
4762 }else{
4763 
4764 
4765 
4766  h->type=j;
4767 
4768 
4769 
4770  if(ch!=ocurl) i=0;
4771 
4772 
4773 
4774  else i=-1;
4775 
4776 
4777 
4778 
4779 
4780 }
4781 
4782 
4783 
4784 
4785 
4786 
4787 
4788 /* Looking for the category */
4789 
4790 
4791 
4792 
4793 
4794 if(i==0){
4795 
4796 
4797 
4798 pos=ftell(inputfile);
4799 
4800 
4801 
4802 skip_whitespaces(inputfile);
4803 
4804 
4805 
4806 ch=fgetc(inputfile);
4807 
4808 
4809 
4810 do{
4811 
4812 
4813 
4814 
4815 
4816  keyword[i]=ch;
4817 
4818 
4819 
4820  ch=fgetc(inputfile);
4821 
4822 
4823 
4824  i++;
4825 
4826 
4827 
4828 }while(!isspace(ch) && ch!=ocurl);
4829 
4830 
4831 
4832 keyword[i]='\0';
4833 
4834 
4835 
4836 }
4837 
4838 
4839 
4840 /* printf("keyword=%s+\n",keyword); */
4841 
4842 /* len=strtol(T_KEYWORDS.category[0],tmp,10);
4843 
4844  if(!len){
4845 
4846  t_error("Error in reading the number of keywords types");
4847 
4848  }
4849 
4850 
4851 
4852 */
4853 
4854 
4855 
4856  len=5;
4857 
4858 
4859 
4860  j=0;
4861 
4862 
4863 
4864  do{
4865 
4866  j++;
4867  /* printf("%s+%s+\n",T_KEYWORDS.category[j],keyword); */
4868 
4869  } while(strcmp(T_KEYWORDS.category[j],keyword)!=0 && j <=len);
4870 
4871 
4872 
4873 
4874 
4875 if(j > len){
4876 
4877 
4878 
4879  h->category=3;
4880 
4881 
4882 
4883 }else{
4884 
4885 
4886 
4887  h->category=j;
4888 
4889 
4890 
4891  if(ch!=ocurl) i=0;
4892 
4893 
4894 
4895  else i=-1;
4896 
4897 
4898 
4899 }
4900 
4901 
4902 
4903 
4904 
4905 if(i > 0){
4906 
4907 
4908 
4909  fseek(inputfile,pos,SEEK_SET);
4910 
4911 
4912 
4913 } else if( i < 0 ){
4914 
4915 
4916 
4917  ungetc(ch,inputfile);
4918 
4919 
4920 
4921 }
4922 
4923 
4924 
4925 h->name=query_for_label(inputfile);
4926 
4927 
4928 /* printf("^^^%s^^^\n",h->name); */
4929 
4930 
4931 return OK;
4932 
4933 
4934 
4935 }
4936 
4937 
4938 
4939 
4940 
4944 
4945 
4946 
4947 {
4948 
4949 
4950 
4951 short i,count=0;
4952 
4953 
4954 
4955 if(a==NULL || b==NULL){
4956 
4957 
4958 
4959  t_error("At least one of the headers was not allocated");
4960 
4961 
4962 
4963 }
4964 
4965 
4966 
4967  if(a->gender!=b->gender){
4968 
4969  count++;
4970 
4971  }
4972 
4973  if(a->type!=b->type){
4974 
4975  count+=10;
4976 
4977  }
4978 
4979  if(a->category!=b->category) {
4980 
4981  count+=100;
4982 
4983  }
4984 
4985  if(strcmp(a->name,b->name)!=0) {
4986 
4987  count+=1000;
4988 
4989  }
4990 
4991  if(a->category!=1 && a->category!=4){
4992 
4993  for(i=1;i<=a->dimensions[0];i++){
4994 
4995  if(a->dimensions[i]!=b->dimensions[i]){
4996 
4997  count+=10000;
4998 
4999  }
5000 
5001  }
5002 
5003  }
5004 
5005 
5006 
5007  return count;
5008 
5009 }
5010 
5011 
5012 
5023 LONGVECTOR *read_longarray(FILE *inputfile,short print)
5024 
5025 
5026 
5027 
5028 
5029 
5030 
5031 {
5032 
5033 
5034 
5035 
5036 
5037 
5038 
5039 char curl,ch;
5040 
5041 const char ocurl='{', ccurl='}';
5042 
5043 //short ind=1;
5044 
5045 HEADER h;
5046 
5047 long buffer_size=0,i, jj; //buffer_index=0,blocksnumber=0,
5048 
5049 long *numbers;
5050 
5051 LONGVECTOR *vec=NULL;
5052 
5053 
5054 
5055 
5056 
5057 if(inputfile==NULL){
5058 
5059 
5060 
5061  t_error("You tried to read from a closed file ");
5062 
5063 
5064 
5065 }
5066 
5067 
5068 
5069 
5070 /*Scanning the first part of the array */
5071 
5072 
5073 
5074 header_scan(inputfile,&h);
5075 
5076 
5077 
5078 if(print==1){
5079 
5080  print_header(&h);
5081 
5082 }
5083 
5084 /*Scan for the data in array */
5085 
5086  if((h.category!=1 || h.type!=4) && h.category!=4)
5087  printf("\nWarning::the data being read are not stored as an array of long\n");
5088 
5089 
5090 skip_whitespaces(inputfile);
5091 
5092 
5093 
5094 curl=fgetc(inputfile);
5095 
5096 
5097 
5098 if(curl!=ocurl) {
5099 
5100 
5101 
5102  t_error("A non expected character found");
5103 
5104 
5105 
5106 } else {
5107 
5108 
5109 
5110  i=0;
5111 
5112 
5113 
5114  skip_whitespaces(inputfile);
5115 
5116 
5117 
5118  buffer_size=BUFFERINCREMENT;
5119 
5120 
5121 
5122  numbers=(long *)malloc(buffer_size*sizeof(long));
5123 
5124 
5125 
5126  if(numbers==NULL){
5127 
5128 
5129 
5130  t_error("Cannot allocate the buffer");
5131 
5132 
5133 
5134  }
5135 
5136 
5137 
5138 }
5139 
5140 
5141 
5142 do{
5143 
5144 
5145 
5146  if(i< buffer_size) {
5147 
5148 
5149 
5150 
5151 
5152  fscanf(inputfile,"%ld ",&numbers[i]);
5153 
5154 
5155 
5156  ch=fgetc(inputfile);
5157 
5158 
5159 
5160  if(ch==EOF){
5161 
5162 
5163 
5164  t_error("Unespected End Of File");
5165 
5166 
5167 
5168  }
5169 
5170 
5171 
5172  i++;
5173 
5174 
5175 
5176 
5177 
5178  } else {
5179 
5180 
5181 
5182  if(i==MAXBUFFERSIZE){
5183 
5184 
5185 
5186  printf(" A very long array has exceeded the maximum buffer size\n");
5187 
5188 
5189 
5190  printf(" Flushing the rest of the array \n" );
5191 
5192 
5193 
5194  do{
5195 
5196 
5197 
5198  ch=getc(inputfile);
5199 
5200 
5201 
5202  }while(ch!=ccurl && ch!=EOF);
5203 
5204 
5205 
5206 
5207 
5208  if(ch==EOF){
5209 
5210 
5211 
5212  t_error("Unespected end of file: comment closed by End of file");
5213 
5214 
5215 
5216  } else {
5217 
5218 
5219 
5220  break;
5221 
5222 
5223 
5224  }
5225 
5226 
5227 
5228  } else if(buffer_size + BUFFERINCREMENT > MAXBUFFERSIZE){
5229 
5230 
5231 
5232  buffer_size=MAXBUFFERSIZE;
5233 
5234 
5235 
5236  numbers=(long *)realloc(numbers,buffer_size*sizeof(long));
5237 
5238 
5239 
5240  if(numbers==NULL){
5241 
5242 
5243 
5244  t_error("Cannot expand the buffer");
5245 
5246 
5247 
5248  }
5249 
5250 
5251 
5252  numbers[buffer_size-1]=0;
5253 
5254 
5255 
5256  } else {
5257 
5258 
5259 
5260  buffer_size+=BUFFERINCREMENT;
5261 
5262 
5263 
5264  numbers=(long *)realloc(numbers,buffer_size*sizeof(long));
5265 
5266 
5267 
5268  if(numbers==NULL){
5269 
5270 
5271 
5272  t_error("Cannot expand the buffer");
5273 
5274 
5275 
5276  }
5277 
5278 
5279 
5280  numbers[buffer_size-1]=0;
5281 
5282 
5283 
5284  }
5285 
5286 
5287 
5288 
5289 
5290  }
5291 
5292 }while(ch !=EOF && ch!=ccurl );
5293 
5294 
5295 
5296 
5297 
5298 if(i==0){
5299 
5300 
5301 
5302  t_error("Empty array body was encountered");
5303 
5304 
5305 
5306 }
5307 
5308 
5309 
5310 
5311 
5312 vec=new_longvector(i);
5313 
5314 
5315 
5316 for(jj=0;jj<i;jj++){
5317 
5318  vec->co[jj+1]=numbers[jj];
5319 
5320 }
5321 
5322 
5323 
5324 free(numbers);
5325 
5326 
5327 
5328 
5329 
5330 return vec;
5331 
5332 
5333 
5334 
5335 
5336 }
5337 
5338 
5339 
5344 FLOATVECTOR *read_floatarray(FILE *inputfile,short print)
5345 
5346 
5347 
5348 
5349 
5350 
5351 
5352 {
5353 
5354 
5355 
5356 
5357 
5358 
5359 
5360 char curl,ch;
5361 
5362 const char ocurl='{', ccurl='}';
5363 
5364 //short ind=1;
5365 
5366 long buffer_size=0,i, jj; //,blocksnumber=0,buffer_index=0
5367 
5368 float *numbers;
5369 
5370 FLOATVECTOR *vec=NULL;
5371 
5372 HEADER h;
5373 
5374 
5375 
5376 
5377 if(inputfile==NULL){
5378 
5379 
5380 
5381  t_error("You tried to read from a closed file ");
5382 
5383 
5384 
5385 }
5386 
5387 
5388 
5389 
5390 
5391 /*Scanning the first part of the array */
5392 
5393 /* printf("reading a floatarray****\n"); */
5394 
5395 header_scan(inputfile,&h);
5396 /*
5397 printf("nnnnn\n");
5398 print_header(&h);
5399 printf("mmmmm\n");
5400 scanf("%c ",&ch);
5401 */
5402 if(print==1){
5403 
5404  print_header(&h);
5405 
5406 }
5407 
5408  if(h.category!=1 || h.type!=5)
5409  printf("\nWarning::the data being read are not stored as an array of float\n");
5410 
5411 
5412 /*Scan for the data in array */
5413 
5414 
5415 
5416 skip_whitespaces(inputfile);
5417 
5418 
5419 
5420 curl=fgetc(inputfile);
5421 
5422 
5423 
5424 if(curl!=ocurl) {
5425 
5426 
5427 
5428  t_error("A non expected character found");
5429 
5430 
5431 
5432 } else {
5433 
5434 
5435 
5436  i=0;
5437 
5438 
5439 
5440  skip_whitespaces(inputfile);
5441 
5442 
5443 
5444  buffer_size=BUFFERINCREMENT;
5445 
5446 
5447 
5448  numbers=(float *)malloc(buffer_size*sizeof(float));
5449 
5450 
5451 
5452  if(numbers==NULL){
5453 
5454 
5455 
5456  t_error("Cannot allocate the buffer");
5457 
5458 
5459 
5460  }
5461 
5462 
5463 
5464 }
5465 
5466 
5467 
5468 do{
5469 
5470 
5471 
5472  if(i< buffer_size) {
5473 
5474 
5475 
5476 
5477 
5478  fscanf(inputfile,"%f ",&numbers[i]);
5479 
5480 
5481 
5482  ch=fgetc(inputfile);
5483 
5484 
5485  if(ch==EOF){
5486 
5487 
5488 
5489  t_error("Unespected End Of File");
5490 
5491 
5492 
5493  }
5494 
5495 
5496 
5497  i++;
5498 
5499 
5500 
5501 
5502 
5503  } else {
5504 
5505 
5506 
5507  if(i==MAXBUFFERSIZE){
5508 
5509 
5510 
5511  printf(" A very long array has exceeded the maximum buffer size\n");
5512 
5513 
5514 
5515  printf(" Flushing the rest of the array \n" );
5516 
5517 
5518 
5519  do{
5520 
5521 
5522 
5523  ch=getc(inputfile);
5524 
5525 
5526 
5527  }while(ch!=ccurl && ch!=EOF);
5528 
5529 
5530 
5531 
5532 
5533  if(ch==EOF){
5534 
5535 
5536 
5537  t_error("Unespected end of file: comment closed by End of file");
5538 
5539 
5540 
5541  } else {
5542 
5543 
5544 
5545  break;
5546 
5547 
5548 
5549  }
5550 
5551 
5552 
5553  } else if(buffer_size + BUFFERINCREMENT > MAXBUFFERSIZE){
5554 
5555 
5556 
5557  buffer_size=MAXBUFFERSIZE;
5558 
5559 
5560 
5561  numbers=(float *)realloc(numbers,buffer_size*sizeof(float));
5562 
5563 
5564 
5565  if(numbers==NULL){
5566 
5567 
5568 
5569  t_error("Cannot expand the buffer");
5570 
5571 
5572 
5573  }
5574 
5575 
5576 
5577  numbers[buffer_size-1]=0;
5578 
5579 
5580 
5581  } else {
5582 
5583 
5584 
5585  buffer_size+=BUFFERINCREMENT;
5586 
5587 
5588 
5589  numbers=(float *)realloc(numbers,buffer_size*sizeof(float));
5590 
5591 
5592 
5593  if(numbers==NULL){
5594 
5595 
5596 
5597  t_error("Cannot expand the buffer");
5598 
5599 
5600 
5601  }
5602 
5603 
5604 
5605  numbers[buffer_size-1]=0;
5606 
5607 
5608 
5609  }
5610 
5611 
5612 
5613 
5614 
5615  }
5616 
5617 }while(ch !=EOF && ch!=ccurl );
5618 
5619 
5620 
5621 
5622 
5623 if(i==0){
5624 
5625 
5626 
5627  t_error("Empty array body was encountered");
5628 
5629 
5630 
5631 }
5632 
5633 
5634 
5635 
5636 
5637 vec=new_floatvector(i);
5638 
5639 
5640 
5641 for(jj=0;jj<i;jj++){
5642 
5643  vec->co[jj+1]=numbers[jj];
5644 
5645 }
5646 
5647 
5648 
5649 free(numbers);
5650 
5651 
5652 
5653 
5654 
5655 return vec;
5656 
5657 
5658 
5659 
5660 
5661 }
5662 
5667 DOUBLEVECTOR *read_doublearray(FILE *inputfile,short print)
5668 
5669 
5670 
5671 
5672 
5673 
5674 
5675 {
5676 
5677 
5678 
5679 
5680 
5681 
5682 
5683 char curl,ch;
5684 
5685 const char ocurl='{', ccurl='}';
5686 
5687 //short ind=1;
5688 
5689 long buffer_size=0,i, jj; //buffer_index=0,blocksnumber=0
5690 
5691 double *numbers;
5692 
5693 DOUBLEVECTOR *vec=NULL;
5694 
5695 HEADER h;
5696 
5697 
5698 
5699 if(inputfile==NULL){
5700 
5701 
5702 
5703  t_error("You tried to read from a closed file ");
5704 
5705 
5706 
5707 }
5708 
5709 
5710 
5711 
5712 
5713 
5714 /*Scanning the first part of the array */
5715 
5716 
5717 
5718 header_scan(inputfile,&h);
5719 
5720 
5721 if(print==1){
5722 
5723  print_header(&h);
5724 
5725 }
5726 
5727 
5728 if(h.category!=1 || h.type!=6)
5729  printf("\nWarning::the data being read are not stored as an array of double\n");
5730 
5731 
5732 /*Scan for the data in array */
5733 
5734 
5735 
5736 skip_whitespaces(inputfile);
5737 
5738 
5739 
5740 curl=fgetc(inputfile);
5741 
5742 
5743 
5744 if(curl!=ocurl) {
5745 
5746 
5747 
5748  t_error("A non expected character found");
5749 
5750 
5751 
5752 } else {
5753 
5754 
5755 
5756  i=0;
5757 
5758 
5759 
5760  skip_whitespaces(inputfile);
5761 
5762 
5763 
5764  buffer_size=BUFFERINCREMENT;
5765 
5766 
5767 
5768  numbers=(double *)malloc(buffer_size*sizeof(double));
5769 
5770 
5771 
5772  if(numbers==NULL){
5773 
5774 
5775 
5776  t_error("Cannot allocate the buffer");
5777 
5778 
5779 
5780  }
5781 
5782 
5783 
5784 }
5785 
5786 
5787 
5788 do{
5789 
5790 
5791 
5792  if(i< buffer_size) {
5793 
5794 
5795 
5796 
5797 
5798  fscanf(inputfile,"%lf ",&numbers[i]);
5799 
5800 
5801 
5802  ch=fgetc(inputfile);
5803 
5804 
5805 
5806  if(ch==EOF){
5807 
5808 
5809 
5810  t_error("Unespected End Of File");
5811 
5812 
5813 
5814  }
5815 
5816 
5817 
5818  i++;
5819 
5820 
5821 
5822 
5823 
5824  } else {
5825 
5826 
5827 
5828  if(i==MAXBUFFERSIZE){
5829 
5830 
5831 
5832  printf(" A very long array has exceeded the maximum buffer size\n");
5833 
5834 
5835 
5836  printf(" Flushing the rest of the array \n" );
5837 
5838 
5839 
5840  do{
5841 
5842 
5843 
5844  ch=getc(inputfile);
5845 
5846 
5847 
5848  }while(ch!=ccurl && ch!=EOF);
5849 
5850 
5851 
5852 
5853 
5854  if(ch==EOF){
5855 
5856 
5857 
5858  t_error("Unespected end of file: comment closed by End of file");
5859 
5860 
5861 
5862  } else {
5863 
5864 
5865 
5866  break;
5867 
5868 
5869 
5870  }
5871 
5872 
5873 
5874  } else if(buffer_size + BUFFERINCREMENT > MAXBUFFERSIZE){
5875 
5876 
5877 
5878  buffer_size=MAXBUFFERSIZE;
5879 
5880 
5881 
5882  numbers=(double *)realloc(numbers,buffer_size*sizeof(double));
5883 
5884 
5885 
5886  if(numbers==NULL){
5887 
5888 
5889 
5890  t_error("Cannot expand the buffer");
5891 
5892 
5893 
5894  }
5895 
5896 
5897 
5898  numbers[buffer_size-1]=0;
5899 
5900 
5901 
5902  } else {
5903 
5904 
5905 
5906  buffer_size+=BUFFERINCREMENT;
5907 
5908 
5909 
5910  numbers=(double *)realloc(numbers,buffer_size*sizeof(double));
5911 
5912 
5913 
5914  if(numbers==NULL){
5915 
5916 
5917 
5918  t_error("Cannot expand the buffer");
5919 
5920 
5921 
5922  }
5923 
5924 
5925 
5926  numbers[buffer_size-1]=0;
5927 
5928 
5929 
5930  }
5931 
5932 
5933 
5934 
5935 
5936  }
5937 
5938 }while(ch !=EOF && ch!=ccurl );
5939 
5940 
5941 
5942 
5943 
5944 if(i==0){
5945 
5946 
5947 
5948  t_error("Empty array body was encountered");
5949 
5950 
5951 
5952 }
5953 
5954 
5955 
5956 
5957 
5958 vec=new_doublevector(i);
5959 
5960 
5961 
5962 for(jj=0;jj<i;jj++){
5963 
5964  vec->co[jj+1]=numbers[jj];
5965 
5966 }
5967 
5968 
5969 free_header(h);/* modified by Emanuele Cordano on 8 september 2009 */
5970 
5971 free(numbers);
5972 
5973 
5974 
5975 return vec;
5976 
5977 
5978 
5979 
5980 
5981 }
5982 
5983 
5984 
5987 SHORTVECTOR *read_shortarray(FILE *inputfile,short print)
5988 
5989 {
5990 
5991 
5992 char curl,ch;
5993 const char ocurl='{', ccurl='}';
5994 //short ind=1;
5995 long buffer_size=0,i,jj;//blocksnumber=0,buffer_index=0
5996 short *numbers;
5997 SHORTVECTOR *vec=NULL;
5998 HEADER h;
5999 
6000 if(inputfile==NULL){
6001  t_error("You tried to read from a closed file ");
6002 }
6003 
6004 /*Scanning the first part of the array */
6005 header_scan(inputfile,&h);
6006 if(print==1){
6007  print_header(&h);
6008 }
6009 
6010 if(h.category!=1 || h.type!=2)
6011  printf("\nWarning::the data being read are not stored as an array of short\n");
6012 
6013 /*Scan for the data in array */
6014 skip_whitespaces(inputfile);
6015 curl=fgetc(inputfile);
6016 
6017 if(curl!=ocurl) {
6018  t_error("A non expected character found");
6019 } else {
6020  i=0;
6021  skip_whitespaces(inputfile);
6022  buffer_size=BUFFERINCREMENT;
6023  numbers=(short *)malloc(buffer_size*sizeof(short));
6024  if(numbers==NULL){
6025  t_error("Cannot allocate the buffer");
6026 
6027  }
6028 }
6029 
6030 do{
6031  if(i< buffer_size) {
6032  fscanf(inputfile,"%hd",&numbers[i]);
6033  ch=fgetc(inputfile);
6034  if(ch==EOF){
6035  t_error("Unespected End Of File");
6036  }
6037  i++;
6038  } else {
6039  if(i==MAXBUFFERSIZE){
6040  printf(" A very long array has exceeded the maximum buffer size\n");
6041  printf(" Flushing the rest of the array \n" );
6042  do{
6043  ch=getc(inputfile);
6044  }while(ch!=ccurl && ch!=EOF);
6045  if(ch==EOF){
6046  t_error("Unespected end of file: comment closed by End of file");
6047  } else {
6048  break;
6049  }
6050  } else if(buffer_size + BUFFERINCREMENT > MAXBUFFERSIZE){
6051  buffer_size=MAXBUFFERSIZE;
6052  numbers=(short *)realloc(numbers,buffer_size*sizeof(short));
6053  if(numbers==NULL){
6054  t_error("Cannot expand the buffer");
6055  }
6056  numbers[buffer_size-1]=0;
6057  } else {
6058  buffer_size+=BUFFERINCREMENT;
6059  numbers=(short *)realloc(numbers,buffer_size*sizeof(short));
6060  if(numbers==NULL){
6061  t_error("Cannot expand the buffer");
6062  }
6063  numbers[buffer_size-1]=0;
6064  }
6065  }
6066 }while(ch !=EOF && ch!=ccurl );
6067 
6068 if(i==0){
6069  t_error("Empty array body was encountered");
6070 
6071 }
6072 
6073 
6074 vec=new_shortvector(i);
6075 
6076 for(jj=0;jj<i;jj++){
6077  vec->co[jj+1]=numbers[jj];
6078 }
6079 
6080 free(numbers);
6081 
6082 return vec;
6083 
6084 }
6085 
6090 STRINGBIN *read_stringarray(FILE *inputfile,short print)
6091 
6092 
6093 
6094 
6095 
6096 {
6097 
6098 
6099 
6100 
6101 
6102 
6103 
6104 char curl;
6105 
6106 const char ocurl='{', ccurl='}';
6107 
6108 //short ind=1;
6109 
6110 long strings_size=0,char_counter=0,strings_counter=0; //blocksnumber=0,strings_index=0,
6111 
6112 long numbers_size=0;//number_index=0;
6113 
6114 char *strings,ch;
6115 
6116 long *numbers,iu,ju,sum=0;
6117 
6118 
6119 HEADER h;
6120 
6121 LONGVECTOR *vec=NULL;
6122 
6123 STRINGBIN *ST=NULL;
6124 
6125 
6126 
6127 
6128 
6129 if(inputfile==NULL){
6130 
6131 
6132 
6133  t_error("You tried to read from a closed file ");
6134 
6135 
6136 
6137 }
6138 
6139 
6140 
6141 
6142 
6143 /*Scanning the first part of the array */
6144 
6145 
6146 
6147 header_scan(inputfile,&h);
6148 
6149 
6150 if(print==1){
6151 
6152  print_header(&h);
6153 
6154 }
6155 
6156 
6157 if(h.category!=1 || h.type!=7)
6158  printf("\nWarning::the data being read are not stored as an array of strings\n");
6159 
6160 
6161 /*Scan for the data in array */
6162 
6163 
6164 
6165 skip_whitespaces(inputfile);
6166 
6167 
6168 
6169 curl=fgetc(inputfile);
6170 
6171 
6172 
6173 if(curl!=ocurl) {
6174 
6175 
6176 
6177  t_error("A non expected character found");
6178 
6179 
6180 
6181 } else {
6182 
6183 
6184 
6185  char_counter=0;
6186 
6187 
6188 
6189  skip_whitespaces(inputfile);
6190 
6191 
6192 
6193  strings_size=BUFFERINCREMENT;
6194 
6195  numbers_size=BUFFERINCREMENT;
6196 
6197 
6198 
6199  strings=(char *)malloc((strings_size+1)*sizeof(char));
6200 
6201  numbers=(long *)malloc(numbers_size*sizeof(long));
6202 
6203 
6204 
6205  if(numbers==NULL || strings==NULL){
6206 
6207 
6208 
6209  t_error("Cannot allocate the buffers");
6210 
6211 
6212 
6213  }
6214 
6215 
6216 
6217 }
6218 
6219 
6220 
6221 strings[strings_size-1]='\0';
6222 
6223 
6224 
6225 do{
6226 
6227 
6228 
6229  if(char_counter< strings_size-1 && strings_counter < numbers_size-1) {
6230 
6231 
6232 
6233 
6234 
6235  strings[char_counter]=fgetc(inputfile);
6236 /* printf("%d:%c+",char_counter,strings[char_counter]); */
6237  if(strings[char_counter]==EOF){
6238 
6239 
6240 
6241  t_error("Unespected End Of File");
6242 
6243 
6244 
6245  } else if (strings[char_counter]==','){
6246 
6247 
6248 
6249  while(strings[char_counter-1]==' '){
6250 
6251  char_counter--;
6252 
6253  }
6254 
6255 
6256 
6257  numbers[strings_counter]=char_counter;
6258 
6259 
6260 
6261  strings_counter++;
6262 
6263 
6264 
6265  skip_whitespaces(inputfile);
6266 
6267 
6268 
6269  } else {
6270 
6271 
6272 
6273  char_counter++;
6274 
6275 
6276 
6277  }
6278 
6279 
6280 
6281  } else if(strings_counter >= numbers_size-1){
6282 
6283 
6284 
6285  numbers_size+=BUFFERINCREMENT;
6286 
6287  numbers=(long *)realloc(numbers,numbers_size*sizeof(long));
6288 
6289 
6290 
6291  if(numbers==NULL){
6292 
6293  t_error("Cannot expand the buffer");
6294 
6295  }
6296 
6297 
6298 
6299  } else if(char_counter==MAXBUFFERSIZE-1){
6300 
6301 
6302 
6303  printf("\nWarning::A very long array has exceeded the maximum buffer size\n");
6304 
6305 
6306 
6307  printf("Warning::Flushing the rest of the array \n" );
6308 
6309 
6310 
6311  do{
6312 
6313 
6314 
6315  ch=getc(inputfile);
6316 
6317 
6318 
6319  }while(ch!=ccurl && ch!=EOF);
6320 
6321 
6322 
6323 
6324 
6325  if(ch==EOF){
6326 
6327 
6328 
6329  t_error("Unespected end of file: comment closed by End of file");
6330 
6331 
6332 
6333  } else {
6334 
6335 
6336 
6337  strings[char_counter-1]=ch;
6338 
6339 
6340 
6341  break;
6342 
6343 
6344 
6345  }
6346 
6347 
6348 
6349  } else if(strings_size + BUFFERINCREMENT > MAXBUFFERSIZE){
6350 
6351 
6352 
6353  strings_size=MAXBUFFERSIZE;
6354 
6355 
6356 
6357  strings=(char *)realloc(strings,(strings_size+1)*sizeof(char));
6358 
6359 
6360 
6361  if(strings==NULL){
6362 
6363 
6364 
6365  t_error("Cannot expand the buffer");
6366 
6367 
6368 
6369  }
6370 
6371 
6372 
6373  strings[MAXBUFFERSIZE-1]='\0';
6374 
6375 
6376 
6377 
6378 
6379  } else {
6380 
6381 
6382 
6383  strings_size+=BUFFERINCREMENT;
6384 
6385 
6386 
6387  strings=(char *)realloc(strings,(strings_size+1)*sizeof(char));
6388 
6389 
6390 
6391  if(strings==NULL){
6392 
6393 
6394 
6395  t_error("Cannot expand the buffer");
6396 
6397 
6398 
6399  }
6400 
6401 
6402 
6403  strings[strings_size-1]='\0';
6404 
6405  }
6406 
6407 
6408 
6409 }while(strings[char_counter-1] !=EOF && strings[char_counter-1]!=ccurl );
6410 
6411 
6412 
6413 
6414 
6415 /* ungetc(strings[char_counter],inputfile); */
6416 
6417 
6418 
6419 char_counter--;
6420 
6421 
6422 
6423 if(char_counter==0){
6424 
6425 
6426 
6427  /* t_error("Empty array body was encountered"); */
6428  printf("\nWarning :: Empty array body was encountered\n");
6429 
6430  return NULL;
6431 
6432 } else if( strings[char_counter]==ccurl){
6433 
6434 
6435 
6436  numbers[strings_counter]=char_counter;
6437 
6438  if(char_counter >1){
6439  while(char_counter >0 && isspace(strings[char_counter-1])){
6440  char_counter--;
6441  }
6442  }
6443  strings[char_counter]='\0';
6444 
6445 
6446 
6447 } else {
6448 
6449 
6450 
6451  t_error("Unespected End of File Encountered");
6452 
6453 
6454 
6455 }
6456 
6457 
6458 
6459 
6460 
6461 
6462 
6463 vec=new_longvector(strings_counter+1);
6464 
6465 
6466 
6467 vec->co[1]=numbers[0]+1;
6468 
6469 
6470 
6471 for(iu=1;iu<=strings_counter;iu++){
6472 
6473  vec->co[iu+1]=numbers[iu]-numbers[iu-1]+1;
6474 
6475 }
6476 
6477 
6478 
6479 free(numbers);
6480 
6481 
6482 
6483 /* print_longvector_elements(vec,10); */
6484 
6485 
6486 
6487 ST=new_stringbin(vec);
6488 
6489 
6490 
6491 /* print_longvector_elements(ST->index,10); */
6492 
6493 
6494 
6495  for(iu=1;iu<=(ST->index)->nh;iu++){
6496 
6497 
6498 
6499 
6500 
6501  for(ju=1;ju< (ST->index)->co[iu];ju++){
6502 
6503 
6504 
6505  ST->co[iu][ju]=strings[sum];
6506 
6507 
6508 
6509  sum++;
6510 
6511  }
6512 
6513 
6514 
6515  ST->co[iu][ju]='\0';
6516 
6517 
6518 
6519 }
6520 //free(h.name);/* modified by Matteo on 31 Augyst 2009 */
6521 //free(&h);
6522 free_header(h);
6523 
6524 free(vec->element); /* modified by Emanuele Cordano on 31 Augyst 2009 */
6525 free(vec);
6526 free(strings);
6527 
6528 
6529 return ST;
6530 
6531 
6532 
6533 
6534 
6535 }
6536 
6537 
6538 
6539 
6540 
6541 
6546 void justread_longarray(FILE *inputfile,LONGVECTOR *vec,short print)
6547 
6548 {
6549 
6550 char curl,ch;
6551 const char ocurl='{', ccurl='}';
6552 HEADER h;
6553 long i;
6554 
6555 if(inputfile==NULL){
6556  t_error("You tried to read from a closed file ");
6557 
6558 }
6559 
6560 if(vec==NULL || vec->isdynamic!=1){
6561 
6562  t_error("This vector was not properly allocated");
6563 }
6564 
6565 /*Scanning the first part of the array */
6566 header_scan(inputfile,&h);
6567 if(print==1){
6568  print_header(&h);
6569 
6570 }
6571 
6572 if(h.category!=1 || !(h.type==4 || h.type==3 || h.type==2))
6573  printf("\nWarning::the data being read cannot be stored as an array of long\n");
6574 
6575 /*Scan for the data in array */
6576 skip_whitespaces(inputfile);
6577  curl=fgetc(inputfile);
6578  if(curl!=ocurl) {
6579  t_error("A non expected character found");
6580  }
6581  for(i=1;i<=vec->nh;i++){
6582 
6583  ch=fscanf(inputfile," %ld %c",&(vec->co[i]),&curl);
6584 
6585  }
6586 
6587  if(curl!=ccurl){
6588 
6589  t_error("Closing bracket not found");
6590  } else if(ch==EOF){
6591 
6592  t_error("Unespected End of file");
6593  }
6594 }
6595 
6596 
6597 
6600 void justread_floatarray(FILE *inputfile,FLOATVECTOR *vec,short print)
6601 
6602 {
6603 
6604 char curl,ch;
6605 const char ocurl='{', ccurl='}';
6606 HEADER h;
6607 long i;
6608 
6609 if(inputfile==NULL){
6610  t_error("You tried to read from a closed file ");
6611 }
6612 
6613 if(vec==NULL || vec->isdynamic!=1){
6614  t_error("This vector was not properly allocated");
6615 }
6616 
6617 header_scan(inputfile,&h);
6618 if(print==1){
6619  print_header(&h);
6620 }
6621 
6622 if(h.category!=1 || !(h.type==5 || h.type==6))
6623  printf("\nWarning::the data being read cannot be stored as an array of long\n");
6624 
6625 skip_whitespaces(inputfile);
6626 curl=fgetc(inputfile);
6627 if(curl!=ocurl) {
6628  t_error("A non expected character found");
6629 }
6630 for(i=1;i<=vec->nh;i++){
6631  ch=fscanf(inputfile," %f %c",&(vec->co[i]),&curl);
6632 }
6633 if(curl!=ccurl){
6634  t_error("Closing bracket not found");
6635 } else if(ch==EOF){
6636  t_error("Unespected End of file");
6637 }
6638 }
6639 
6642 void justread_floatmatrix(FILE *inputfile, FLOATMATRIX *C, char *mode,short print)
6643 
6644 {
6645 char ch;
6646 HEADER h;
6647 /*FLOATMATRIX * C;*/
6648 long u;
6649 
6650 if(inputfile==NULL){
6651  t_error("You tried to read from a closed file ");
6652 } else {
6653  read_matrixheader(inputfile, &h);
6654  if(print==1){
6655  print_header(&h);
6656  printf("Dimensions: %ld %ld \n",h.dimensions[1],h.dimensions[2]);
6657  }
6658  if(h.category!=3 || h.type!=5)
6659  printf("\nWarning::the data being read are not stored as a matrix of float\n");
6660  /***/
6661  /*C=new_floatmatrix(h.dimensions[1],h.dimensions[2]);*/
6662  skip_whitespaces(inputfile);
6663  if(query_for_token(inputfile,"->")) {
6664  if (OPENYES==1){
6665  t_error("It is not permitted to have more than one external file open");
6666  } else {
6667  OPENYES=1;
6668  strcpy(EXTERNAL_FILE_NAME,get_phrase(inputfile,';'));
6669  if(strcmp(EXTERNAL_FILE_NAME,OLD_NAME) && EXTERNAL_FILE_POSITION !=SEEK_SET){
6670  EXTERNAL_FILE_POSITION =SEEK_SET;
6671  printf("\nWarning::The external file could open in a wrong position\n");
6673  } else if(!strcmp(EXTERNAL_FILE_NAME,OLD_NAME) && EXTERNAL_FILE_POSITION!=SEEK_SET){
6675  fseek(EXTERNAL_FILE,EXTERNAL_FILE_POSITION,SEEK_SET);
6676  } else {
6679  }
6680  read_matrixheader(EXTERNAL_FILE,&EXTERNAL_HEADER);
6682  if(headercmp(&h,&EXTERNAL_HEADER)) {
6683  t_error("External data file does not match the request ");
6684  } else {
6687  if(ch == EOF){
6688  EXTERNAL_FILE_POSITION=SEEK_SET;
6690  free_header(EXTERNAL_HEADER);
6691  OPENYES=0;
6692  } else {
6693  ungetc(ch,EXTERNAL_FILE);
6695  strcpy(OLD_NAME,EXTERNAL_FILE_NAME);
6697  free_header(EXTERNAL_HEADER);
6698  OPENYES=0;
6699  }
6700  }
6701  }
6702  } else {
6703  read_floatmatrix_elements(inputfile,C,mode);
6704  }
6705 }
6706 free_header(h);
6707 /*return C;*/
6708 }
6709 
6712 void justread_chararray(FILE *inputfile,CHARVECTOR *vec,short print)
6713 
6714 {
6715 
6716 char curl,ch;
6717 const char ocurl='{', ccurl='}';
6718 HEADER h;
6719 long i;
6720 
6721 if(inputfile==NULL){
6722  t_error("You tried to read from a closed file ");
6723 
6724 }
6725 
6726 if(vec==NULL || vec->isdynamic!=1){
6727 
6728  t_error("This vector was not properly allocated");
6729 }
6730 
6731 header_scan(inputfile,&h);
6732 if(print==1){
6733  print_header(&h);
6734 
6735 }
6736 
6737 
6738 if(h.category!=1 || h.type!=1)
6739  printf("\nWarning::the data being read are not stored as an array of char\n");
6740 
6741 skip_whitespaces(inputfile);
6742  curl=fgetc(inputfile);
6743  if(curl!=ocurl) {
6744  t_error("A non expected character found");
6745  }
6746  for(i=1;i<=vec->nh;i++){
6747 
6748  ch=fscanf(inputfile," %c %c",&(vec->co[i]),&curl);
6749 
6750  }
6751 
6752  if(curl!=ccurl){
6753 
6754  t_error("Closing bracket not found");
6755  } else if(ch==EOF){
6756 
6757  t_error("Unespected End of file");
6758  }
6759 }
6760 
6761 
6762 
6763 
6764 
6769 void read_vectorheader(FILE *inputfile,HEADER *h)
6770 
6771 
6772 
6773 
6774 
6775 
6776 
6777 {
6778 
6779 
6780 
6781 
6782 
6783 
6784 
6785 char curl;
6786 
6787 const char ocurl='{', ccurl='}';
6788 
6789 //short ind=1;
6790 
6791 //long buffer_index=0,buffer_size=0,blocksnumber=0; //
6792 
6793 
6794 
6795 if(inputfile==NULL){
6796 
6797 
6798 
6799  t_error("You tried to read from a closed file ");
6800 
6801 
6802 
6803 } else if(h==NULL){
6804 
6805 
6806 
6807  t_error("You addresses a null header ");
6808 
6809 
6810 
6811 } else {
6812 
6813 
6814 
6815 
6816 
6817  /*Scanning the first part of the array */
6818 
6819 
6820 
6821  header_scan(inputfile,h);
6822 
6823 
6824 
6825  /*Scan for the data in array */
6826 
6827 
6828 
6829  skip_whitespaces(inputfile);
6830 
6831 
6832 
6833  curl=fgetc(inputfile);
6834 
6835 
6836 
6837  if(curl!=ocurl) {
6838 
6839 
6840 
6841  t_error("A non expected character found");
6842 
6843 
6844 
6845  } else {
6846 
6847  h->dimensions[0]=1;
6848 
6849  fscanf(inputfile," %ld ",&(h->dimensions[1]));
6850 
6851  h->dimensions[2]=0;
6852 
6853  h->dimensions[3]=0;
6854 
6855 
6856 
6857  }
6858 
6859 
6860 
6861  curl=fgetc(inputfile);
6862 
6863 
6864 
6865  if(curl!=ccurl){
6866 
6867  t_error("Closing delimiter not found");
6868 
6869  }
6870 
6871 
6872 
6873 }
6874 
6875 
6876 
6877 }
6878 
6879 
6880 
6885 void read_matrixheader(FILE *inputfile,HEADER *h)
6886 
6887 
6888 
6889 
6890 
6891 
6892 
6893 {
6894 
6895 
6896 
6897 
6898 
6899 
6900 
6901 char curl;
6902 
6903 const char ocurl='{', ccurl='}';
6904 
6905 //short ind=1;
6906 
6907 //long buffer_index=0,buffer_size=0,blocksnumber=0;
6908 
6909 
6910 
6911 
6912 
6913 /*Scanning the first part of the array */
6914 
6915 
6916 
6917 if(inputfile==NULL){
6918 
6919 
6920 
6921  t_error("You tried to read from a closed file ");
6922 
6923 
6924 
6925 } else if(h==NULL){
6926 
6927 
6928 
6929  t_error("You addressed a null header ");
6930 
6931 
6932 
6933 } else {
6934 
6935 
6936 
6937  header_scan(inputfile,h);
6938 
6939 
6940  skip_whitespaces(inputfile);
6941 
6942 
6943 
6944  curl=fgetc(inputfile);
6945 
6946 
6947 
6948  if(curl!=ocurl) {
6949 
6950 
6951 
6952  t_error("A non expected character found");
6953 
6954 
6955 
6956  } else {
6957 
6958  h->dimensions[0]=2;
6959 
6960  fscanf(inputfile," %ld , %ld ",&(h->dimensions[1]),&(h->dimensions[2]));
6961 
6962  h->dimensions[3]=0;
6963 
6964 
6965 
6966  }
6967 
6968 
6969 
6970  curl=fgetc(inputfile);
6971 
6972 
6973 
6974  if(curl!=ccurl){
6975 
6976  t_error("Closing delimiter not found");
6977 
6978  }
6979 
6980 
6981 
6982 }
6983 
6984 
6985 
6986 }
6987 
6988 
6989 
6992 CHARVECTOR *read_charvector(FILE *inputfile,char *mode,short print)
6993 
6994 
6995 
6996 {
6997 
6998 
6999 
7000 char ch;
7001 HEADER h;
7002 CHARVECTOR *C;
7003 long u;
7004 
7005 
7006 
7007 
7008  if(inputfile==NULL){
7009 
7010 
7011 
7012  t_error("You tried to read from a closed file ");
7013 
7014 
7015 
7016 } else {
7017 
7018 
7019  read_vectorheader(inputfile,&h);
7020 
7021  if(print==1){
7022 
7023  print_header(&h);
7024 
7025  printf("Dimension: %ld \n",h.dimensions[1]);
7026 
7027  }
7028 
7029  if(h.category!=2 || h.type!=1) printf("\nWarning::the data being read are not stored as a vector of char\n");
7030 
7031  C=new_charvector(h.dimensions[1]);
7032 
7033 
7034  skip_whitespaces(inputfile);
7035 
7036 
7037 
7038  if(query_for_token(inputfile,"->")) {
7039 
7040 
7041 
7042  if (OPENYES==1){
7043 
7044 
7045 
7046  t_error("It is not permitted to have more than one external file open");
7047 
7048 
7049 
7050  } else {
7051 
7052 
7053 
7054  OPENYES=1;
7055 
7056 
7057  strcpy(EXTERNAL_FILE_NAME,get_phrase(inputfile,';'));
7058 
7059 
7060 
7061  if(strcmp(EXTERNAL_FILE_NAME,OLD_NAME) && EXTERNAL_FILE_POSITION !=SEEK_SET){
7062 
7063 
7064 
7065 
7066 
7067  EXTERNAL_FILE_POSITION =SEEK_SET;
7068 
7069 
7070 
7071  printf("\nWarning::The external file could open in a wrong position\n");
7072 
7073 
7074 
7076 
7077 
7078 
7079  } else if(!strcmp(EXTERNAL_FILE_NAME,OLD_NAME) && EXTERNAL_FILE_POSITION!=SEEK_SET){
7080 
7081 
7082 
7083 
7085 
7086 
7087 
7088  fseek(EXTERNAL_FILE,EXTERNAL_FILE_POSITION,SEEK_SET);
7089 
7090 
7091 
7092  } else {
7093 
7094 
7095 
7097 
7099 
7100  }
7101 
7102 
7103  read_vectorheader(EXTERNAL_FILE,&EXTERNAL_HEADER);
7104 
7105 
7107 
7108 
7109 
7110  if(headercmp(&h,&EXTERNAL_HEADER)) {
7111 
7112 
7113 
7114  t_error("External data file does not match the request ");
7115 
7116 
7117 
7118  } else {
7119 
7120 
7122 
7123 
7125 
7126 
7127 
7128  ch=getc(EXTERNAL_FILE);
7129 
7130 
7131 
7132 
7133 
7134  if(ch == EOF){
7135 
7136 
7137 
7138 
7140 
7141 
7142 
7143  free_header(EXTERNAL_HEADER);
7144 
7145 
7146 
7147  EXTERNAL_FILE_POSITION=SEEK_SET;
7148 
7149 
7150 
7151  OPENYES=0;
7152 
7153 
7154 
7155  } else {
7156 
7157 
7158 
7159  ungetc(ch,EXTERNAL_FILE);
7160 
7161 
7162 
7164 
7165 
7166 
7167  strcpy(OLD_NAME,EXTERNAL_FILE_NAME);
7168 
7169 
7170 
7172 
7173 
7174 
7175  free_header(EXTERNAL_HEADER);
7176 
7177 
7178 
7179  OPENYES=0;
7180 
7181 
7182 
7183  }
7184 
7185  }
7186 
7187 
7188 
7189  }
7190 
7191 
7192 
7193  } else { /* Not an external file */
7194 
7195 
7196 
7197  read_charvector_elements(inputfile,C,mode);
7198 
7199 
7200 
7201  }
7202 
7203 }
7204 
7205 free_header(h);
7206 return C;
7207 
7208 }
7209 
7210 
7211 
7214 SHORTVECTOR* read_shortvector(FILE *inputfile,char *mode, short print)
7215 
7216 
7217 
7218 {
7219 
7220 
7221 
7222 char ch;
7223 HEADER h;
7224 SHORTVECTOR *C;
7225 long u;
7226 
7227 
7228 
7229  if(inputfile==NULL){
7230 
7231 
7232 
7233  t_error("You tried to read from a closed file ");
7234 
7235 
7236 
7237 } else {
7238 
7239 
7240  read_vectorheader(inputfile,&h);
7241 
7242  if(print==1){
7243 
7244  print_header(&h);
7245 
7246  printf("Dimensions: %ld %ld \n",h.dimensions[1],h.dimensions[2]);
7247 
7248  }
7249 
7250  if(h.category!=2 || h.type!=2) printf("\nWarning::the data being read are not stored as an vector of short\n");
7251 
7252 
7253  C=new_shortvector(h.dimensions[1]);
7254 
7255  skip_whitespaces(inputfile);
7256 
7257 
7258 
7259  if(query_for_token(inputfile,"->")) {
7260 
7261 
7262 
7263 
7264 
7265  if (OPENYES==1){
7266 
7267 
7268 
7269  t_error("It is not permitted to have more than one external file open");
7270 
7271 
7272 
7273  } else {
7274 
7275 
7276 
7277  OPENYES=1;
7278 
7279 
7280 
7281  strcpy(EXTERNAL_FILE_NAME,get_phrase(inputfile,';'));
7282 
7283 
7284 
7285  if(strcmp(EXTERNAL_FILE_NAME,OLD_NAME) && EXTERNAL_FILE_POSITION !=SEEK_SET){
7286 
7287 
7288 
7289 
7290 
7291  EXTERNAL_FILE_POSITION =SEEK_SET;
7292 
7293 
7294 
7295  printf("\nWarning::The external file could open in a wrong position\n");
7296 
7297 
7298 
7300 
7301 
7302 
7303  } else if(!strcmp(EXTERNAL_FILE_NAME,OLD_NAME) && EXTERNAL_FILE_POSITION!=SEEK_SET){
7304 
7305 
7306 
7308 
7309 
7310 
7311  fseek(EXTERNAL_FILE,EXTERNAL_FILE_POSITION,SEEK_SET);
7312 
7313 
7314 
7315  } else {
7316 
7317 
7318 
7320 
7322 
7323  }
7324 
7325 
7326 
7327  read_vectorheader(EXTERNAL_FILE,&EXTERNAL_HEADER);
7328 
7329 
7330 
7332 
7333 
7334 
7335  if(headercmp(&h,&EXTERNAL_HEADER)) {
7336 
7337 
7338 
7339  t_error("External data file does not match the request ");
7340 
7341 
7342 
7343  } else {
7344 
7345 
7346 
7348 
7349 
7350 
7352 
7353 
7354 
7355  ch=getc(EXTERNAL_FILE);
7356 
7357 
7358 
7359 
7360 
7361  if(ch == EOF){
7362 
7363 
7364 
7365 
7366 
7368 
7369 
7370 
7371  free_header(EXTERNAL_HEADER);
7372 
7373 
7374 
7375  EXTERNAL_FILE_POSITION=SEEK_SET;
7376 
7377 
7378 
7379  OPENYES=0;
7380 
7381 
7382 
7383  } else {
7384 
7385 
7386 
7387  ungetc(ch,EXTERNAL_FILE);
7388 
7389 
7390 
7392 
7393 
7394 
7395  strcpy(OLD_NAME,EXTERNAL_FILE_NAME);
7396 
7397 
7398 
7400 
7401 
7402 
7403  free_header(EXTERNAL_HEADER);
7404 
7405 
7406 
7407  OPENYES=0;
7408 
7409 
7410 
7411  }
7412 
7413  }
7414 
7415 
7416 
7417  }
7418 
7419 
7420 
7421  } else { /* Not an external file */
7422 
7423 
7424 
7425  read_shortvector_elements(inputfile,C,mode);
7426 
7427 
7428 
7429  }
7430 
7431 }
7432 
7433 free_header(h);
7434 return C;
7435 
7436 }
7437 
7438 
7439 
7442 INTVECTOR* read_intvector(FILE *inputfile,char *mode,short print)
7443 
7444 
7445 
7446 {
7447 
7448 
7449 
7450 char ch;
7451 HEADER h;
7452 INTVECTOR *C;
7453 long u;
7454 
7455 
7456 
7457  if(inputfile==NULL){
7458 
7459 
7460 
7461  t_error("You tried to read from a closed file ");
7462 
7463 
7464 
7465 } else {
7466 
7467  read_vectorheader(inputfile,&h);
7468 
7469  if(print==1){
7470 
7471  print_header(&h);
7472 
7473  printf("Dimensions: %ld \n",h.dimensions[1]);
7474 
7475  }
7476 
7477  if(h.category!=2 || h.type!=3) printf("\nWarning::the data being read are not stored as a vector of int\n");
7478 
7479 
7480  C=new_intvector(h.dimensions[1]);
7481 
7482  skip_whitespaces(inputfile);
7483 
7484 
7485 
7486  if(query_for_token(inputfile,"->")) {
7487 
7488 
7489 
7490 
7491 
7492  if (OPENYES==1){
7493 
7494 
7495 
7496  t_error("It is not permitted to have more than one external file open");
7497 
7498 
7499 
7500  } else {
7501 
7502 
7503 
7504  OPENYES=1;
7505 
7506 
7507 
7508  strcpy(EXTERNAL_FILE_NAME,get_phrase(inputfile,';'));
7509 
7510 
7511 
7512  if(strcmp(EXTERNAL_FILE_NAME,OLD_NAME) && EXTERNAL_FILE_POSITION !=SEEK_SET){
7513 
7514 
7515 
7516 
7517 
7518  EXTERNAL_FILE_POSITION =SEEK_SET;
7519 
7520 
7521 
7522  printf("\nWarning::The external file could open in a wrong position\n");
7523 
7524 
7525 
7527 
7528 
7529 
7530  } else if(!strcmp(EXTERNAL_FILE_NAME,OLD_NAME) && EXTERNAL_FILE_POSITION!=SEEK_SET){
7531 
7532 
7533 
7535 
7536 
7537 
7538  fseek(EXTERNAL_FILE,EXTERNAL_FILE_POSITION,SEEK_SET);
7539 
7540 
7541 
7542  } else {
7543 
7544 
7545 
7548 
7549  }
7550 
7551 
7552 
7553  read_vectorheader(EXTERNAL_FILE,&EXTERNAL_HEADER);
7554 
7555 
7556 
7558 
7559 
7560 
7561  if(headercmp(&h,&EXTERNAL_HEADER)) {
7562 
7563 
7564 
7565  t_error("External data file does not match the request ");
7566 
7567 
7568 
7569  } else {
7570 
7571 
7572 
7574 
7575 
7576 
7578 
7579 
7580 
7581  ch=getc(EXTERNAL_FILE);
7582 
7583 
7584 
7585 
7586 
7587  if(ch == EOF){
7588 
7589 
7590 
7591 
7592 
7594 
7595 
7596 
7597  free_header(EXTERNAL_HEADER);
7598 
7599 
7600 
7601  EXTERNAL_FILE_POSITION=SEEK_SET;
7602 
7603 
7604 
7605  OPENYES=0;
7606 
7607 
7608 
7609  } else {
7610 
7611 
7612 
7613  ungetc(ch,EXTERNAL_FILE);
7614 
7615 
7616 
7618 
7619 
7620 
7621  strcpy(OLD_NAME,EXTERNAL_FILE_NAME);
7622 
7623 
7624 
7626 
7627 
7628 
7629  free_header(EXTERNAL_HEADER);
7630 
7631 
7632 
7633  OPENYES=0;
7634 
7635 
7636 
7637  }
7638 
7639  }
7640 
7641 
7642 
7643  }
7644 
7645 
7646 
7647  } else { /* Not an external file */
7648 
7649 
7650 
7651  read_intvector_elements(inputfile,C,mode);
7652 
7653 
7654 
7655  }
7656 
7657 }
7658 
7659 free_header(h);
7660 return C;
7661 
7662 }
7663 
7664 
7665 
7668 LONGVECTOR *read_longvector(FILE *inputfile,char *mode, short print)
7669 
7670 
7671 
7672 {
7673 
7674 
7675 
7676 char ch;
7677 HEADER h;
7678 LONGVECTOR *C;
7679 long u;
7680 
7681 
7682 
7683  if(inputfile==NULL){
7684 
7685 
7686 
7687  t_error("You tried to read from a closed file ");
7688 
7689 
7690 
7691 } else {
7692 
7693 
7694  read_vectorheader(inputfile,&h);
7695 
7696  if(print==1){
7697 
7698  print_header(&h);
7699 
7700  printf("Dimensions: %ld\n",h.dimensions[1]);
7701 
7702  }
7703 
7704 
7705  read_vectorheader(inputfile,&h);
7706 
7707  if(print==1){
7708 
7709  print_header(&h);
7710 
7711  printf("Dimensions: %ld \n",h.dimensions[1]);
7712 
7713  }
7714 
7715  if(h.category!=2 || h.type!=4)
7716  printf("\nWarning::the data being read are not stored as a vector of long\n");
7717 
7718 
7719  C=new_longvector(h.dimensions[1]);
7720 
7721  skip_whitespaces(inputfile);
7722 
7723 
7724 
7725  if(query_for_token(inputfile,"->")) {
7726 
7727 
7728 
7729 
7730 
7731  if (OPENYES==1){
7732 
7733 
7734 
7735  t_error("It is not permitted to have more than one external file open");
7736 
7737 
7738 
7739  } else {
7740 
7741 
7742 
7743  OPENYES=1;
7744 
7745 
7746 
7747  strcpy(EXTERNAL_FILE_NAME,get_phrase(inputfile,';'));
7748 
7749 
7750 
7751  if(strcmp(EXTERNAL_FILE_NAME,OLD_NAME) && EXTERNAL_FILE_POSITION !=SEEK_SET){
7752 
7753 
7754 
7755 
7756 
7757  EXTERNAL_FILE_POSITION =SEEK_SET;
7758 
7759 
7760 
7761  printf("\nWarning::The external file could open in a wrong position\n");
7762 
7763 
7764 
7766 
7767 
7768 
7769  } else if(!strcmp(EXTERNAL_FILE_NAME,OLD_NAME) && EXTERNAL_FILE_POSITION!=SEEK_SET){
7770 
7771 
7772 
7774 
7775 
7776 
7777  fseek(EXTERNAL_FILE,EXTERNAL_FILE_POSITION,SEEK_SET);
7778 
7779 
7780 
7781  } else {
7782 
7783 
7784 
7787 
7788  }
7789 
7790 
7791 
7792  read_vectorheader(EXTERNAL_FILE,&EXTERNAL_HEADER);
7793 
7794 
7795 
7797 
7798 
7799 
7800  if(headercmp(&h,&EXTERNAL_HEADER)) {
7801 
7802 
7803 
7804  t_error("External data file does not match the request ");
7805 
7806 
7807 
7808  } else {
7809 
7810 
7811 
7813 
7814 
7815 
7817 
7818 
7819 
7820  ch=getc(EXTERNAL_FILE);
7821 
7822 
7823 
7824 
7825 
7826  if(ch == EOF){
7827 
7828 
7829 
7830 
7831 
7833 
7834 
7835 
7836  free_header(EXTERNAL_HEADER);
7837 
7838 
7839 
7840  EXTERNAL_FILE_POSITION=SEEK_SET;
7841 
7842 
7843 
7844  OPENYES=0;
7845 
7846 
7847 
7848  } else {
7849 
7850 
7851 
7852  ungetc(ch,EXTERNAL_FILE);
7853 
7854 
7855 
7857 
7858 
7859 
7860  strcpy(OLD_NAME,EXTERNAL_FILE_NAME);
7861 
7862 
7863 
7865 
7866 
7867 
7868  free_header(EXTERNAL_HEADER);
7869 
7870 
7871 
7872  OPENYES=0;
7873 
7874 
7875 
7876  }
7877 
7878  }
7879 
7880 
7881 
7882  }
7883 
7884 
7885 
7886  } else { /* Not an external file */
7887 
7888 
7889 
7890  read_longvector_elements(inputfile,C,mode);
7891 
7892 
7893 
7894  }
7895 
7896 }
7897 
7898 free_header(h);
7899 return C;
7900 
7901 }
7902 
7903 
7904 
7905 
7906 
7909 FLOATVECTOR *read_floatvector(FILE *inputfile,char *mode, short print)
7910 
7911 
7912 
7913 {
7914 
7915 
7916 
7917 char ch;
7918 HEADER h;
7919 FLOATVECTOR *C;
7920 long u;
7921 
7922 
7923 
7924  if(inputfile==NULL){
7925 
7926 
7927 
7928  t_error("You tried to read from a closed file ");
7929 
7930 
7931 
7932 } else {
7933 
7934 
7935  read_vectorheader(inputfile,&h);
7936 
7937  if(print==1){
7938 
7939  print_header(&h);
7940 
7941  printf("Dimensions: %ld \n",h.dimensions[1]);
7942 
7943  }
7944 
7945  if(h.category!=2 || h.type!=5)
7946  printf("\nWarning::the data being read are not stored as a vector of float\n");
7947 
7948 
7949  C=new_floatvector(h.dimensions[1]);
7950 
7951  skip_whitespaces(inputfile);
7952 
7953 
7954 
7955  if(query_for_token(inputfile,"->")) {
7956 
7957 
7958 
7959 
7960 
7961  if (OPENYES==1){
7962 
7963 
7964 
7965  t_error("It is not permitted to have more than one external file open");
7966 
7967 
7968 
7969  } else {
7970 
7971 
7972 
7973  OPENYES=1;
7974 
7975 
7976 
7977  strcpy(EXTERNAL_FILE_NAME,get_phrase(inputfile,';'));
7978 
7979 
7980 
7981  if(strcmp(EXTERNAL_FILE_NAME,OLD_NAME) && EXTERNAL_FILE_POSITION !=SEEK_SET){
7982 
7983 
7984 
7985 
7986 
7987  EXTERNAL_FILE_POSITION =SEEK_SET;
7988 
7989 
7990 
7991  printf("\nWarning::The external file could open in a wrong position\n");
7992 
7993 
7994 
7996 
7997 
7998 
7999  } else if(!strcmp(EXTERNAL_FILE_NAME,OLD_NAME) && EXTERNAL_FILE_POSITION!=SEEK_SET){
8000 
8001 
8002 
8004 
8005 
8006 
8007  fseek(EXTERNAL_FILE,EXTERNAL_FILE_POSITION,SEEK_SET);
8008 
8009 
8010 
8011  } else {
8012 
8013 
8014 
8017 
8018  }
8019 
8020 
8021 
8022  read_vectorheader(EXTERNAL_FILE,&EXTERNAL_HEADER);
8023 
8024 
8025 
8027 
8028 
8029 
8030  if(headercmp(&h,&EXTERNAL_HEADER)) {
8031 
8032 
8033 
8034  t_error("External data file does not match the request ");
8035 
8036 
8037 
8038  } else {
8039 
8040 
8041 
8043 
8044 
8045 
8047 
8048 
8049 
8050  ch=getc(EXTERNAL_FILE);
8051 
8052 
8053 
8054 
8055 
8056  if(ch == EOF){
8057 
8058 
8059 
8060 
8061 
8063 
8064 
8065 
8066  free_header(EXTERNAL_HEADER);
8067 
8068 
8069 
8070  EXTERNAL_FILE_POSITION=SEEK_SET;
8071 
8072 
8073 
8074  OPENYES=0;
8075 
8076 
8077 
8078  } else {
8079 
8080 
8081 
8082  ungetc(ch,EXTERNAL_FILE);
8083 
8084 
8085 
8087 
8088 
8089 
8090  strcpy(OLD_NAME,EXTERNAL_FILE_NAME);
8091 
8092 
8093 
8095 
8096 
8097 
8098  free_header(EXTERNAL_HEADER);
8099 
8100 
8101 
8102  OPENYES=0;
8103 
8104 
8105 
8106  }
8107 
8108  }
8109 
8110 
8111 
8112  }
8113 
8114 
8115 
8116  } else { /* Not an external file */
8117 
8118 
8119 
8120  read_floatvector_elements(inputfile,C,mode);
8121 
8122 
8123 
8124  }
8125 
8126 }
8127 
8128 free_header(h);
8129 return C;
8130 
8131 }
8132 
8133 
8134 
8135 
8136 
8137 
8138 
8141 DOUBLEVECTOR *read_doublevector(FILE *inputfile,char *mode, short print)
8142 
8143 
8144 
8145 {
8146 
8147 
8148 
8149 char ch;
8150 HEADER h;
8151 DOUBLEVECTOR *C;
8152 long u;
8153 
8154 
8155 
8156  if(inputfile==NULL){
8157 
8158 
8159 
8160  t_error("You tried to read from a closed file ");
8161 
8162 
8163 
8164 } else {
8165 
8166  read_vectorheader(inputfile,&h);
8167 
8168  if(print==1){
8169 
8170  print_header(&h);
8171 
8172  printf("Dimensions: %ld\n",h.dimensions[1]);
8173 
8174  }
8175 
8176  if(h.category!=2 || h.type!=6)
8177  printf("\nWarning::the data being read are not stored as a vector of double\n");
8178 
8179 
8180  C=new_doublevector(h.dimensions[1]);
8181 
8182  skip_whitespaces(inputfile);
8183 
8184 
8185 
8186  if(query_for_token(inputfile,"->")) {
8187 
8188 
8189 
8190 
8191 
8192  if (OPENYES==1){
8193 
8194 
8195 
8196  t_error("It is not permitted to have more than one external file open");
8197 
8198 
8199 
8200  } else {
8201 
8202 
8203 
8204  OPENYES=1;
8205 
8206 
8207 
8208  strcpy(EXTERNAL_FILE_NAME,get_phrase(inputfile,';'));
8209 
8210 
8211 
8212  if(strcmp(EXTERNAL_FILE_NAME,OLD_NAME) && EXTERNAL_FILE_POSITION !=SEEK_SET){
8213 
8214 
8215 
8216 
8217 
8218  EXTERNAL_FILE_POSITION =SEEK_SET;
8219 
8220 
8221 
8222  printf("\nWarning::The external file could open in a wrong position\n");
8223 
8224 
8225 
8227 
8228 
8229 
8230  } else if(!strcmp(EXTERNAL_FILE_NAME,OLD_NAME) && EXTERNAL_FILE_POSITION!=SEEK_SET){
8231 
8232 
8233 
8235 
8236 
8237 
8238  fseek(EXTERNAL_FILE,EXTERNAL_FILE_POSITION,SEEK_SET);
8239 
8240 
8241 
8242  } else {
8243 
8244 
8245 
8248 
8249  }
8250 
8251 
8252 
8253  read_vectorheader(EXTERNAL_FILE,&EXTERNAL_HEADER);
8254 
8255 
8256 
8258 
8259 
8260 
8261  if(headercmp(&h,&EXTERNAL_HEADER)) {
8262 
8263 
8264 
8265  t_error("External data file does not match the request ");
8266 
8267 
8268 
8269  } else {
8270 
8271 
8272 
8274 
8275 
8276 
8278 
8279 
8280 
8281  ch=getc(EXTERNAL_FILE);
8282 
8283 
8284 
8285 
8286 
8287  if(ch == EOF){
8288 
8289 
8290 
8291 
8292 
8294 
8295 
8296 
8297  free_header(EXTERNAL_HEADER);
8298 
8299 
8300 
8301  EXTERNAL_FILE_POSITION=SEEK_SET;
8302 
8303 
8304 
8305  OPENYES=0;
8306 
8307 
8308 
8309  } else {
8310 
8311 
8312 
8313  ungetc(ch,EXTERNAL_FILE);
8314 
8315 
8316 
8318 
8319 
8320 
8321  strcpy(OLD_NAME,EXTERNAL_FILE_NAME);
8322 
8323 
8324 
8326 
8327 
8328 
8329  free_header(EXTERNAL_HEADER);
8330 
8331 
8332 
8333  OPENYES=0;
8334 
8335 
8336 
8337  }
8338 
8339  }
8340 
8341 
8342 
8343  }
8344 
8345 
8346 
8347  } else { /* Not an external file */
8348 
8349 
8350 
8351  read_doublevector_elements(inputfile,C,mode);
8352 
8353 
8354 
8355  }
8356 
8357 }
8358 
8359 free_header(h);
8360 return C;
8361 
8362 }
8363 
8364 
8365 
8366 
8367 
8368 
8369 
8370 
8371 
8374 SHORTMATRIX* read_shortmatrix(FILE *inputfile, char *mode, short print)
8375 
8376 
8377 
8378 {
8379 
8380 
8381 
8382 char ch;
8383 HEADER h;
8384 SHORTMATRIX *C;
8385 long u;
8386 
8387 
8388 
8389  if(inputfile==NULL){
8390 
8391 
8392 
8393  t_error("You tried to read from a closed file ");
8394 
8395 
8396 
8397 } else {
8398 
8399 
8400  read_matrixheader(inputfile,&h);
8401 
8402  if(print==1){
8403 
8404  print_header(&h);
8405 
8406  printf("Dimensions: %ld %ld \n",h.dimensions[1],h.dimensions[2]);
8407 
8408  }
8409 
8410 if(h.category!=3 || h.type!=2)
8411  printf("\nWarning::the data being read are not stored as a matrix of short\n");
8412 
8413 
8414  C=new_shortmatrix(h.dimensions[1],h.dimensions[2]);
8415 
8416  skip_whitespaces(inputfile);
8417 
8418 
8419 
8420  if(query_for_token(inputfile,"->")) {
8421 
8422 
8423 
8424 
8425 
8426  if (OPENYES==1){
8427 
8428 
8429 
8430  t_error("It is not permitted to have more than one external file open");
8431 
8432 
8433 
8434  } else {
8435 
8436 
8437 
8438  OPENYES=1;
8439 
8440 
8441 
8442  strcpy(EXTERNAL_FILE_NAME,get_phrase(inputfile,';'));
8443 
8444 
8445 
8446 
8447 
8448  if(strcmp(EXTERNAL_FILE_NAME,OLD_NAME) && EXTERNAL_FILE_POSITION !=SEEK_SET){
8449 
8450 
8451 
8452 
8453 
8454  EXTERNAL_FILE_POSITION =SEEK_SET;
8455 
8456 
8457 
8458  printf("\nWarning::The external file could open in a wrong position\n");
8459 
8460 
8461 
8463 
8464 
8465 
8466 
8467 
8468  } else if(!strcmp(EXTERNAL_FILE_NAME,OLD_NAME) && EXTERNAL_FILE_POSITION!=SEEK_SET){
8469 
8470 
8471 
8473 
8474 
8475 
8476  fseek(EXTERNAL_FILE,EXTERNAL_FILE_POSITION,SEEK_SET);
8477 
8478 
8479 
8480  } else {
8481 
8482 
8483 
8486 
8487  }
8488 
8489 
8490 
8491  read_matrixheader(EXTERNAL_FILE,&EXTERNAL_HEADER);
8492 
8493 
8494 
8496 
8497 
8498 
8499  if(headercmp(&h,&EXTERNAL_HEADER)) {
8500 
8501 
8502 
8503  t_error("External data file does not match the request ");
8504 
8505 
8506 
8507  } else {
8508 
8509 
8510 
8512 
8513 
8514 
8516 
8517 
8518 
8519  ch=getc(EXTERNAL_FILE);
8520 
8521 
8522 
8523 
8524 
8525  if(ch == EOF){
8526 
8527 
8528 
8529  EXTERNAL_FILE_POSITION=SEEK_SET;
8530 
8531 
8532 
8534 
8535 
8536 
8537  free_header(EXTERNAL_HEADER);
8538 
8539 
8540 
8541  OPENYES=0;
8542 
8543 
8544 
8545  } else {
8546 
8547 
8548 
8549  ungetc(ch,EXTERNAL_FILE);
8550 
8551 
8552 
8554 
8555 
8556 
8557 
8558 
8559  strcpy(OLD_NAME,EXTERNAL_FILE_NAME);
8560 
8561 
8562 
8564 
8565 
8566 
8567  free_header(EXTERNAL_HEADER);
8568 
8569 
8570 
8571  OPENYES=0;
8572 
8573 
8574 
8575  }
8576 
8577  }
8578 
8579 
8580 
8581  /* }
8582 
8583 
8584 
8585  }
8586 
8587  */
8588 
8589  }
8590 
8591 
8592 
8593  } else { /* Not an external file */
8594 
8595 
8596 
8597  read_shortmatrix_elements(inputfile,C,mode);
8598 
8599 
8600 
8601  }
8602 
8603 }
8604 
8605 free_header(h);
8606 return C;
8607 
8608 }
8609 
8610 
8611 
8612 
8613 
8614 
8615 
8618 INTMATRIX *read_intmatrix(FILE *inputfile, char *mode,short print)
8619 
8620 
8621 
8622 {
8623 
8624 
8625 
8626 char ch;
8627 HEADER h;
8628 INTMATRIX *C;
8629 long u;
8630 
8631 
8632 
8633  if(inputfile==NULL){
8634 
8635 
8636 
8637  t_error("You tried to read from a closed file ");
8638 
8639 
8640 
8641 } else {
8642 
8643 
8644 
8645  read_matrixheader(inputfile,&h);
8646 
8647  if(print==1){
8648 
8649  print_header(&h);
8650 
8651  printf("Dimensions: %ld %ld \n",h.dimensions[1],h.dimensions[2]);
8652 
8653  }
8654 
8655  if(h.category!=3 || h.type!=3)
8656  printf("\nWarning::the data being read are not stored as a matrix of int\n");
8657 
8658 
8659  C=new_intmatrix(h.dimensions[1],h.dimensions[2]);
8660 
8661 
8662  skip_whitespaces(inputfile);
8663 
8664 
8665 
8666  if(query_for_token(inputfile,"->")) {
8667 
8668 
8669 
8670 
8671 
8672  if (OPENYES==1){
8673 
8674 
8675 
8676  t_error("It is not permitted to have more than one external file open");
8677 
8678 
8679 
8680  } else {
8681 
8682 
8683 
8684  OPENYES=1;
8685 
8686 
8687 
8688  strcpy(EXTERNAL_FILE_NAME,get_phrase(inputfile,';'));
8689 
8690 
8691 
8692 
8693 
8694  if(strcmp(EXTERNAL_FILE_NAME,OLD_NAME) && EXTERNAL_FILE_POSITION !=SEEK_SET){
8695 
8696 
8697 
8698 
8699 
8700  EXTERNAL_FILE_POSITION =SEEK_SET;
8701 
8702 
8703 
8704  printf("\nWarning::The external file could open in a wrong position\n");
8705 
8706 
8707 
8709 
8710 
8711 
8712 
8713 
8714  } else if(!strcmp(EXTERNAL_FILE_NAME,OLD_NAME) && EXTERNAL_FILE_POSITION!=SEEK_SET){
8715 
8716 
8717 
8719 
8720 
8721 
8722  fseek(EXTERNAL_FILE,EXTERNAL_FILE_POSITION,SEEK_SET);
8723 
8724 
8725 
8726  } else {
8727 
8728 
8729 
8732 
8733  }
8734 
8735 
8736 
8737  read_matrixheader(EXTERNAL_FILE,&EXTERNAL_HEADER);
8738 
8739 
8740 
8742 
8743 
8744 
8745  if(headercmp(&h,&EXTERNAL_HEADER)) {
8746 
8747 
8748 
8749  t_error("External data file does not match the request ");
8750 
8751 
8752 
8753  } else {
8754 
8755 
8756 
8758 
8759 
8760 
8762 
8763 
8764 
8765  ch=getc(EXTERNAL_FILE);
8766 
8767 
8768 
8769 
8770 
8771  if(ch == EOF){
8772 
8773 
8774 
8775  EXTERNAL_FILE_POSITION=SEEK_SET;
8776 
8777 
8778 
8780 
8781 
8782 
8783  free_header(EXTERNAL_HEADER);
8784 
8785 
8786 
8787  OPENYES=0;
8788 
8789 
8790 
8791  } else {
8792 
8793 
8794 
8795  ungetc(ch,EXTERNAL_FILE);
8796 
8797 
8798 
8800 
8801 
8802 
8803 
8804 
8805  strcpy(OLD_NAME,EXTERNAL_FILE_NAME);
8806 
8807 
8808 
8810 
8811 
8812 
8813  free_header(EXTERNAL_HEADER);
8814 
8815 
8816 
8817  OPENYES=0;
8818 
8819 
8820 
8821  }
8822 
8823  }
8824 
8825  }
8826 
8827 
8828 
8829  } else { /* Not an external file */
8830 
8831 
8832 
8833  read_intmatrix_elements(inputfile,C,mode);
8834 
8835 
8836 
8837  }
8838 
8839 }
8840 
8841 free_header(h);
8842 return C;
8843 
8844 }
8845 
8846 
8847 
8848 
8849 
8850 
8851 
8852 
8853 
8856 LONGMATRIX *read_longmatrix(FILE *inputfile, char *mode, short print)
8857 
8858 
8859 
8860 {
8861 
8862 
8863 
8864 char ch;
8865 HEADER h;
8866 LONGMATRIX *C;
8867 long u;
8868 
8869 
8870 
8871  if(inputfile==NULL){
8872 
8873 
8874 
8875  t_error("You tried to read from a closed file ");
8876 
8877 
8878 
8879 } else {
8880 
8881 
8882  read_matrixheader(inputfile,&h);
8883 
8884  if(print==1){
8885 
8886  print_header(&h);
8887 
8888  printf("Dimensions: %ld %ld \n",h.dimensions[1],h.dimensions[2]);
8889 
8890  }
8891 
8892 if(h.category!=3 || h.type!=4)
8893  printf("\nWarning::the data being read are not stored as a matrix of long\n");
8894 
8895 
8896  C=new_longmatrix(h.dimensions[1],h.dimensions[2]);
8897 
8898 
8899  skip_whitespaces(inputfile);
8900 
8901 
8902 
8903  if(query_for_token(inputfile,"->")) {
8904 
8905 
8906 
8907 
8908 
8909  if (OPENYES==1){
8910 
8911 
8912 
8913  t_error("It is not permitted to have more than one external file open");
8914 
8915 
8916 
8917  } else {
8918 
8919 
8920 
8921  OPENYES=1;
8922 
8923  strcpy(EXTERNAL_FILE_NAME,get_phrase(inputfile,';'));
8924 
8925 
8926 
8927  if(strcmp(EXTERNAL_FILE_NAME,OLD_NAME) && EXTERNAL_FILE_POSITION !=SEEK_SET){
8928 
8929 
8930 
8931  EXTERNAL_FILE_POSITION =SEEK_SET;
8932 
8933 
8934 
8935  printf("\nWarning::The external file could open in a wrong position\n");
8936 
8937 
8938 
8940 
8941 
8942 
8943 
8944 
8945  } else if(!strcmp(EXTERNAL_FILE_NAME,OLD_NAME) && EXTERNAL_FILE_POSITION!=SEEK_SET){
8946 
8947 
8949 
8950 
8951 
8952  fseek(EXTERNAL_FILE,EXTERNAL_FILE_POSITION,SEEK_SET);
8953 
8954 
8955 
8956  } else {
8957 
8958 
8960 
8961  u=read_index(EXTERNAL_FILE,NOPRINT); /* & */
8962 
8963 
8964 
8965  }
8966 
8967 
8968 
8969  read_matrixheader(EXTERNAL_FILE,&EXTERNAL_HEADER);
8970 
8971 
8972 
8974 
8975 
8976 
8977  if(headercmp(&h,&EXTERNAL_HEADER)) {
8978 
8979  print_header(&h);
8980 
8981  print_header(&EXTERNAL_HEADER);
8982 
8983  t_error("External data file does not match the request ");
8984 
8985 
8986 
8987  } else {
8988 
8989 
8990 
8992 
8993 
8994 
8996 
8997 
8998 
8999  ch=getc(EXTERNAL_FILE);
9000 
9001 
9002 
9003 
9004 
9005  if(ch == EOF){
9006 
9007 
9008 
9009 
9010 
9011  EXTERNAL_FILE_POSITION=SEEK_SET;
9012 
9013 
9014 
9016 
9017 
9018 
9019  free_header(EXTERNAL_HEADER);
9020 
9021 
9022 
9023  OPENYES=0;
9024 
9025 
9026 
9027  } else {
9028 
9029 
9030 
9031  ungetc(ch,EXTERNAL_FILE);
9032 
9033 
9034 
9036 
9037 
9038 
9039 
9040 
9041  strcpy(OLD_NAME,EXTERNAL_FILE_NAME);
9042 
9043 
9044 
9046 
9047 
9048 
9049  free_header(EXTERNAL_HEADER);
9050 
9051 
9052 
9053  OPENYES=0;
9054 
9055 
9056 
9057  }
9058 
9059  }
9060 
9061 
9062 
9063  }
9064 
9065 
9066 
9067  } else { /* Not an external file */
9068 
9069 
9070 
9071  read_longmatrix_elements(inputfile,C,mode);
9072 
9073 
9074 
9075  }
9076 
9077 }
9078 
9079 free_header(h);
9080 return C;
9081 
9082 }
9083 
9084 
9085 
9086 
9087 
9088 
9089 
9092 FLOATMATRIX *read_floatmatrix(FILE *inputfile, char *mode,short print)
9093 
9094 
9095 {
9096 
9097 char ch;
9098 HEADER h;
9099 FLOATMATRIX * C;
9100 long u;
9101 
9102 if(inputfile==NULL){
9103  t_error("You tried to read from a closed file ");
9104 } else {
9105  read_matrixheader(inputfile, &h);
9106  if(print==1){
9107  print_header(&h);
9108  printf("Dimensions: %ld %ld \n",h.dimensions[1],h.dimensions[2]);
9109  }
9110  if(h.category!=3 || h.type!=5)
9111  printf("\nWarning::the data being read are not stored as a matrix of float\n");
9112  /***/
9113  C=new_floatmatrix(h.dimensions[1],h.dimensions[2]);
9114  skip_whitespaces(inputfile);
9115  if(query_for_token(inputfile,"->")) {
9116  if (OPENYES==1){
9117  t_error("It is not permitted to have more than one external file open");
9118  } else {
9119  OPENYES=1;
9120  strcpy(EXTERNAL_FILE_NAME,get_phrase(inputfile,';'));
9121  if(strcmp(EXTERNAL_FILE_NAME,OLD_NAME) && EXTERNAL_FILE_POSITION !=SEEK_SET){
9122  EXTERNAL_FILE_POSITION =SEEK_SET;
9123  printf("\nWarning::The external file could open in a wrong position\n");
9125  } else if(!strcmp(EXTERNAL_FILE_NAME,OLD_NAME) && EXTERNAL_FILE_POSITION!=SEEK_SET){
9127  fseek(EXTERNAL_FILE,EXTERNAL_FILE_POSITION,SEEK_SET);
9128  } else {
9131  }
9132  read_matrixheader(EXTERNAL_FILE,&EXTERNAL_HEADER);
9134  if(headercmp(&h,&EXTERNAL_HEADER)) {
9135  t_error("External data file does not match the request ");
9136  } else {
9139  ch=getc(EXTERNAL_FILE);
9140  if(ch == EOF){
9141  EXTERNAL_FILE_POSITION=SEEK_SET;
9143  free_header(EXTERNAL_HEADER);
9144  OPENYES=0;
9145  } else {
9146  ungetc(ch,EXTERNAL_FILE);
9148  strcpy(OLD_NAME,EXTERNAL_FILE_NAME);
9150  free_header(EXTERNAL_HEADER);
9151  OPENYES=0;
9152  }
9153  }
9154 }
9155  } else {
9156  read_floatmatrix_elements(inputfile,C,mode);
9157  }
9158 }
9159 free_header(h);
9160 return C;
9161 }
9162 
9163 
9166 DOUBLEMATRIX *read_doublematrix(FILE *inputfile, char *mode,short print)
9167 
9168 {
9169 
9170 char ch;
9171 HEADER h;
9172 DOUBLEMATRIX *C;
9173 long u;
9174 
9175 if(inputfile==NULL){
9176  t_error("You tried to read from a closed file ");
9177 } else {
9178  read_matrixheader(inputfile,&h);
9179  if(print==1){
9180  print_header(&h);
9181  printf("Dimensions: %ld %ld \n",h.dimensions[1],h.dimensions[2]);
9182  }
9183 
9184  if(h.category!=3 || h.type!=6)
9185  printf("\nWarning::the data being read are not stored as a matrix of double\n");
9186  C=new_doublematrix(h.dimensions[1],h.dimensions[2]);
9187  skip_whitespaces(inputfile);
9188 
9189  if(query_for_token(inputfile,"->")) {
9190 
9191  if (OPENYES==1){
9192  t_error("It is not permitted to have more than one external file open");
9193 
9194  } else {
9195  OPENYES=1;
9196  strcpy(EXTERNAL_FILE_NAME,get_phrase(inputfile,';'));
9197 
9198  if(strcmp(EXTERNAL_FILE_NAME,OLD_NAME) && EXTERNAL_FILE_POSITION !=SEEK_SET){
9199  EXTERNAL_FILE_POSITION =SEEK_SET;
9200  printf("\nWarning::The external file could open in a wrong position\n");
9202 
9203  } else if(!strcmp(EXTERNAL_FILE_NAME,OLD_NAME) && EXTERNAL_FILE_POSITION!=SEEK_SET){
9205  fseek(EXTERNAL_FILE,EXTERNAL_FILE_POSITION,SEEK_SET);
9206 
9207  } else {
9210  }
9211 
9212  read_matrixheader(EXTERNAL_FILE,&EXTERNAL_HEADER);
9214 
9215  if(headercmp(&h,&EXTERNAL_HEADER)) {
9216  t_error("External data file does not match the request ");
9217 
9218  } else {
9221  ch=getc(EXTERNAL_FILE);
9222 
9223  if(ch == EOF){
9224  EXTERNAL_FILE_POSITION=SEEK_SET;
9226  free_header(EXTERNAL_HEADER);
9227  OPENYES=0;
9228 
9229  } else {
9230 
9231  ungetc(ch,EXTERNAL_FILE);
9233  strcpy(OLD_NAME,EXTERNAL_FILE_NAME);
9235  free_header(EXTERNAL_HEADER);
9236  OPENYES=0;
9237  }
9238  }
9239  }
9240  } else { /* Not an external file */
9241  read_doublematrix_elements(inputfile,C,mode);
9242  }
9243 
9244 }
9245 
9246 free_header(h);
9247 return C;
9248 
9249 }
9250 
9251 
9254 INTBIN *read_intbin(FILE *inputfile, char *mode,short print)
9255 
9256 
9257 
9258 {
9259 
9260 
9261 
9262 char ch;
9263 INTBIN* C;
9264 LONGVECTOR *P;
9265 long u;
9266 
9267 
9268 
9269  if(inputfile==NULL){
9270 
9271 
9272 
9273  t_error("You tried to read from a closed file ");
9274 
9275 
9276 
9277 } else {
9278 
9279 
9280  P=read_longarray(inputfile,print);
9281 
9282  if(print==1){
9284 
9285  }
9286 
9287 
9288  C=new_intbin(P);
9289  skip_whitespaces(inputfile);
9290 
9291 
9292 
9293  if(query_for_token(inputfile,"->")) {
9294 
9295 
9296 
9297  if (OPENYES==1){
9298 
9299 
9300 
9301  t_error("It is not permitted to have more than one external file open");
9302 
9303 
9304 
9305  } else {
9306 
9307 
9308 
9309  OPENYES=1;
9310 
9311 
9312 
9313  strcpy(EXTERNAL_FILE_NAME,query_for_label(inputfile));
9314 
9315 
9316 
9317  if(strcmp(EXTERNAL_FILE_NAME,OLD_NAME) && EXTERNAL_FILE_POSITION !=SEEK_SET){
9318 
9319 
9320 
9321 
9322 
9323  EXTERNAL_FILE_POSITION =SEEK_SET;
9324 
9325 
9326 
9327  printf("\nWarning::The external file could open in a wrong position\n");
9328 
9329 
9330 
9332 
9333 
9334 
9335  } else if(!strcmp(EXTERNAL_FILE_NAME,OLD_NAME) && EXTERNAL_FILE_POSITION!=SEEK_SET){
9336 
9337 
9338 
9340 
9341 
9342 
9343  fseek(EXTERNAL_FILE,EXTERNAL_FILE_POSITION,SEEK_SET);
9344 
9345 
9346 
9347  } else {
9348 
9349 
9350 
9352 
9354 
9355  }
9356 
9357 
9358  EXTERNAL_P=read_longarray(EXTERNAL_FILE,NOPRINT);
9359 
9360 
9362 
9363 
9364 
9365  if(longvectorcmp(P,EXTERNAL_P)) {
9366 
9367 
9368  t_error("External data file does not match the request ");
9369 
9370 
9371 
9372  } else {
9373 
9374 
9375  free_longvector(EXTERNAL_P);
9376 
9378 
9379 
9381 
9382 
9383 
9384  ch=getc(EXTERNAL_FILE);
9385 
9386 
9387 
9388  if(ch == EOF){
9389 
9390 
9391 
9392  EXTERNAL_FILE_POSITION=SEEK_SET;
9393 
9394 
9395 
9397 
9398 
9399 
9400  free_header(EXTERNAL_HEADER);
9401 
9402 
9403 
9404  OPENYES=0;
9405 
9406 
9407 
9408  } else {
9409 
9410 
9411 
9412  ungetc(ch,EXTERNAL_FILE);
9413 
9414 
9415 
9417 
9418 
9419 
9420  strcpy(OLD_NAME,EXTERNAL_FILE_NAME);
9421 
9422 
9423 
9425 
9426 
9427 
9428  free_header(EXTERNAL_HEADER);
9429 
9430 
9431 
9432  OPENYES=0;
9433 
9434 
9435 
9436  }
9437 
9438 
9439 
9440  }
9441 
9442 
9443 
9444  }
9445 
9446 
9447 
9448  } else {
9449 
9450 
9451 
9452  read_intbin_elements(inputfile,C,mode);
9453 
9454 
9455 
9456  }
9457 
9458 
9459 
9460 }
9461 
9462 
9463 return C;
9464 
9465 
9466 }
9467 
9468 
9469 
9472 SHORTBIN * read_shortbin(FILE *inputfile, char *mode,short print)
9473 
9474 
9475 
9476 {
9477 
9478 
9479 
9480 char ch;
9481 LONGVECTOR *P;
9482 SHORTBIN *C;
9483 long u;
9484 
9485 
9486 
9487  if(inputfile==NULL){
9488 
9489 
9490 
9491  t_error("You tried to read from a closed file ");
9492 
9493 
9494 
9495 } else {
9496 
9497 
9498  P=read_longarray(inputfile,print);
9499 
9500  if(print==1){
9501 
9503 
9504  }
9505 
9506 
9507  C=new_shortbin(P);
9508 
9509 
9510  skip_whitespaces(inputfile);
9511 
9512 
9513 
9514  if(query_for_token(inputfile,"->")) {
9515 
9516 
9517 
9518  if (OPENYES==1){
9519 
9520 
9521 
9522  t_error("It is not permitted to have more than one external file open");
9523 
9524 
9525 
9526  } else {
9527 
9528 
9529 
9530  OPENYES=1;
9531 
9532 
9533 
9534  strcpy(EXTERNAL_FILE_NAME,query_for_label(inputfile));
9535 
9536 
9537 
9538  if(strcmp(EXTERNAL_FILE_NAME,OLD_NAME) && EXTERNAL_FILE_POSITION !=SEEK_SET){
9539 
9540 
9541 
9542 
9543 
9544  EXTERNAL_FILE_POSITION =SEEK_SET;
9545 
9546 
9547 
9548  printf("\nWarning::The external file could open in a wrong position\n");
9549 
9550 
9551 
9553 
9554 
9555 
9556  } else if(!strcmp(EXTERNAL_FILE_NAME,OLD_NAME) && EXTERNAL_FILE_POSITION!=SEEK_SET){
9557 
9558 
9559 
9561 
9562 
9563 
9564  fseek(EXTERNAL_FILE,EXTERNAL_FILE_POSITION,SEEK_SET);
9565 
9566 
9567 
9568  } else {
9569 
9570 
9571 
9573 
9575 
9576  }
9577 
9578 
9579  EXTERNAL_P=read_longarray(EXTERNAL_FILE,NOPRINT);
9580 
9581 
9583 
9584 
9585 
9586  if(longvectorcmp(P,EXTERNAL_P)) {
9587 
9588 
9589  t_error("External data file does not match the request ");
9590 
9591 
9592 
9593  } else {
9594 
9595 
9596  free_longvector(EXTERNAL_P);
9597 
9598 
9599 
9601 
9602 
9603 
9605 
9606 
9607 
9608  ch=getc(EXTERNAL_FILE);
9609 
9610 
9611 
9612  if(ch == EOF){
9613 
9614 
9615 
9616  EXTERNAL_FILE_POSITION=SEEK_SET;
9617 
9618 
9619 
9621 
9622 
9623 
9624  free_header(EXTERNAL_HEADER);
9625 
9626 
9627 
9628  OPENYES=0;
9629 
9630 
9631 
9632  } else {
9633 
9634 
9635 
9636  ungetc(ch,EXTERNAL_FILE);
9637 
9638 
9639 
9641 
9642 
9643 
9644  strcpy(OLD_NAME,EXTERNAL_FILE_NAME);
9645 
9646 
9647 
9649 
9650 
9651 
9652  free_header(EXTERNAL_HEADER);
9653 
9654 
9655 
9656  OPENYES=0;
9657 
9658 
9659 
9660  }
9661 
9662 
9663 
9664  }
9665 
9666 
9667 
9668  }
9669 
9670 
9671 
9672  } else { /* Not an external file */
9673 
9674 
9675 
9676  read_shortbin_elements(inputfile,C,mode);
9677 
9678 
9679 
9680  }
9681 
9682 }
9683 
9684 
9685 return C;
9686 
9687 }
9688 
9689 
9690 
9691 
9692 
9695 LONGBIN *read_longbin(FILE *inputfile, char *mode, short print)
9696 
9697 
9698 
9699 {
9700 
9701 
9702 
9703 char ch;
9704 LONGVECTOR *P;
9705 LONGBIN *C;
9706 long u;
9707 
9708 
9709 
9710  if(inputfile==NULL){
9711 
9712 
9713 
9714  t_error("You tried to read from a closed file ");
9715 
9716 
9717 
9718 } else {
9719 
9720 
9721  P=read_longarray(inputfile,print);
9722 
9723  if(print==1){
9724 
9726 
9727  }
9728 
9729 
9730  C=new_longbin(P);
9731 
9732 
9733  skip_whitespaces(inputfile);
9734 
9735 
9736 
9737  if(query_for_token(inputfile,"->")) {
9738 
9739 
9740 
9741  if (OPENYES==1){
9742 
9743 
9744 
9745  t_error("It is not permitted to have more than one external file open");
9746 
9747 
9748 
9749  } else {
9750 
9751 
9752 
9753  OPENYES=1;
9754 
9755 
9756 
9757  strcpy(EXTERNAL_FILE_NAME,query_for_label(inputfile));
9758 
9759 
9760 
9761  if(strcmp(EXTERNAL_FILE_NAME,OLD_NAME) && EXTERNAL_FILE_POSITION !=SEEK_SET){
9762 
9763 
9764 
9765 
9766 
9767  EXTERNAL_FILE_POSITION =SEEK_SET;
9768 
9769 
9770 
9771  printf("\nWarning::The external file could open in a wrong position\n");
9772 
9773 
9774 
9776 
9777 
9778 
9779  } else if(!strcmp(EXTERNAL_FILE_NAME,OLD_NAME) && EXTERNAL_FILE_POSITION!=SEEK_SET){
9780 
9781 
9782 
9784 
9785 
9786 
9787  fseek(EXTERNAL_FILE,EXTERNAL_FILE_POSITION,SEEK_SET);
9788 
9789 
9790 
9791  } else {
9792 
9793 
9794 
9795 
9797 
9799 
9800  }
9801 
9802 
9803  EXTERNAL_P=read_longarray(EXTERNAL_FILE,NOPRINT);
9804 
9805 
9807 
9808 
9809 
9810  if(longvectorcmp(P,EXTERNAL_P)) {
9811 
9812 
9813  t_error("External data file does not match the request ");
9814 
9815 
9816 
9817  } else {
9818 
9819 
9820  free_longvector(EXTERNAL_P);
9821 
9822 
9823 
9825 
9826 
9827 
9829 
9830 
9831 
9832  ch=getc(EXTERNAL_FILE);
9833 
9834 
9835 
9836  if(ch == EOF){
9837 
9838 
9839 
9840  EXTERNAL_FILE_POSITION=SEEK_SET;
9841 
9842 
9843 
9845 
9846 
9847 
9848  free_header(EXTERNAL_HEADER);
9849 
9850 
9851 
9852  OPENYES=0;
9853 
9854 
9855 
9856  } else {
9857 
9858 
9859 
9860  ungetc(ch,EXTERNAL_FILE);
9861 
9862 
9863 
9865 
9866 
9867 
9868  strcpy(OLD_NAME,EXTERNAL_FILE_NAME);
9869 
9870 
9871 
9873 
9874 
9875 
9876  free_header(EXTERNAL_HEADER);
9877 
9878 
9879 
9880  OPENYES=0;
9881 
9882 
9883 
9884  }
9885 
9886 
9887 
9888  }
9889 
9890 
9891 
9892  }
9893 
9894 
9895 
9896  } else { /* Not an external file */
9897 
9898 
9899 
9900  read_longbin_elements(inputfile,C,mode);
9901 
9902 
9903 
9904  }
9905 
9906 }
9907 
9908 
9909 return C;
9910 
9911 }
9912 
9913 
9914 
9915 
9916 
9919 DOUBLEBIN *read_doublebin(FILE *inputfile, char *mode,short print)
9920 
9921 
9922 
9923 {
9924 
9925 
9926 
9927 char ch;
9928 LONGVECTOR *P;
9929 DOUBLEBIN *C;
9930 long u;
9931 
9932 
9933 
9934 
9935  if(inputfile==NULL){
9936 
9937 
9938 
9939  t_error("You tried to read from a closed file ");
9940 
9941 
9942 
9943 } else {
9944 
9945  P=read_longarray(inputfile,print);
9946 
9947  if(print==1){
9948 
9950 
9951  }
9952 
9953 
9954 
9955  C=new_doublebin(P);
9956 
9957 
9958  skip_whitespaces(inputfile);
9959 
9960 
9961 
9962  if(query_for_token(inputfile,"->")) {
9963 
9964 
9965 
9966  if (OPENYES==1){
9967 
9968 
9969 
9970  t_error("It is not permitted to have more than one external file open");
9971 
9972 
9973 
9974  } else {
9975 
9976 
9977 
9978  OPENYES=1;
9979 
9980 
9981 
9982  strcpy(EXTERNAL_FILE_NAME,query_for_label(inputfile));
9983 
9984 
9985 
9986  if(strcmp(EXTERNAL_FILE_NAME,OLD_NAME) && EXTERNAL_FILE_POSITION !=SEEK_SET){
9987 
9988 
9989 
9990 
9991 
9992  EXTERNAL_FILE_POSITION =SEEK_SET;
9993 
9994 
9995 
9996  printf("\nWarning::The external file could open in a wrong position\n");
9997 
9998 
9999 
10001 
10002 
10003 
10004  } else if(!strcmp(EXTERNAL_FILE_NAME,OLD_NAME) && EXTERNAL_FILE_POSITION!=SEEK_SET){
10005 
10006 
10007 
10009 
10010 
10011 
10012  fseek(EXTERNAL_FILE,EXTERNAL_FILE_POSITION,SEEK_SET);
10013 
10014 
10015 
10016  } else {
10017 
10018 
10019 
10020 
10022 
10024 
10025  }
10026 
10027 
10028  EXTERNAL_P=read_longarray(EXTERNAL_FILE,NOPRINT);
10029 
10030 
10032 
10033 
10034 
10035  if(longvectorcmp(P,EXTERNAL_P)) {
10036 
10037 
10038  t_error("External data file does not match the request ");
10039 
10040 
10041 
10042  } else {
10043 
10044 
10045  free_longvector(EXTERNAL_P);
10046 
10048 
10049 
10050 
10052 
10053 
10054 
10055  ch=getc(EXTERNAL_FILE);
10056 
10057 
10058 
10059  if(ch == EOF){
10060 
10061 
10062 
10063  EXTERNAL_FILE_POSITION=SEEK_SET;
10064 
10065 
10066 
10068 
10069 
10070 
10071  free_header(EXTERNAL_HEADER);
10072 
10073 
10074 
10075  OPENYES=0;
10076 
10077 
10078 
10079  } else {
10080 
10081 
10082 
10083  ungetc(ch,EXTERNAL_FILE);
10084 
10085 
10086 
10088 
10089 
10090 
10091  strcpy(OLD_NAME,EXTERNAL_FILE_NAME);
10092 
10093 
10094 
10096 
10097 
10098 
10099  free_header(EXTERNAL_HEADER);
10100 
10101 
10102 
10103  OPENYES=0;
10104 
10105 
10106 
10107  }
10108 
10109 
10110 
10111  }
10112 
10113 
10114 
10115  }
10116 
10117 
10118 
10119  } else { /* Not an external file */
10120 
10121 
10122 
10123  read_doublebin_elements(inputfile,C,mode);
10124 
10125 
10126 
10127  }
10128 
10129 }
10130 
10131 
10132 return C;
10133 
10134 }
10135 
10136 
10137 
10138 
10139 
10140 
10141 
10142 
10145 void write_shortarray_elements(FILE *outputfile,SHORTVECTOR *V, long columns)
10146 
10147 
10148 
10149 {
10150 
10151 
10152 
10153 long i;
10154 
10155 
10156 
10157 
10158 
10159 putchar(' ');
10160 
10161 
10162 
10163 if (V==NULL || V->co==NULL || V->isdynamic !=1){
10164 
10165  t_error("The vector was not allocated properly");
10166 
10167 }else if(V->nl > V->nh ){
10168 
10169  t_error("The vector has no proper dimensions");
10170 
10171 } else {
10172 
10173 
10174 
10175  fprintf(outputfile,"{");
10176 
10177 
10178 
10179  for(i=V->nl;i<V->nh;i++){
10180 
10181  fprintf(outputfile,"%hd,",V->co[i]);
10182 
10183  if(i%columns==0) putchar('\n');
10184 
10185  }
10186 
10187 
10188 
10189  fprintf(outputfile,"%hd}\n",V->co[i]);
10190 
10191 
10192 
10193 }
10194 
10195 
10196 
10197 putchar('\n');
10198 
10199 
10200 
10201 
10202 
10203 
10204 
10205 }
10206 
10207 
10208 
10209 
10210 
10213 void write_intarray_elements(FILE *outputfile,INTVECTOR *V, long columns)
10214 
10215 
10216 
10217 {
10218 
10219 
10220 
10221 long i;
10222 
10223 
10224 
10225 
10226 
10227 putchar(' ');
10228 
10229 
10230 
10231 if (V==NULL || V->co==NULL || V->isdynamic !=1){
10232 
10233  t_error("The vector was not allocated properly");
10234 
10235 }else if(V->nl > V->nh ){
10236 
10237  t_error("The vector has no proper dimensions");
10238 
10239 } else {
10240 
10241 
10242 
10243  fprintf(outputfile,"{");
10244 
10245 
10246 
10247  for(i=V->nl;i<V->nh;i++){
10248 
10249  fprintf(outputfile,"%d,",V->co[i]);
10250 
10251  if(i%columns==0) putchar('\n');
10252 
10253  }
10254 
10255 
10256 
10257  fprintf(outputfile,"%d}\n",V->co[i]);
10258 
10259 
10260 
10261 }
10262 
10263 
10264 
10265 putchar('\n');
10266 
10267 
10268 
10269 
10270 
10271 
10272 
10273 }
10274 
10275 
10276 
10277 
10278 
10279 
10280 
10283 void write_longarray_elements(FILE *outputfile,LONGVECTOR *V, long columns)
10284 
10285 
10286 
10287 {
10288 
10289 
10290 
10291 long i;
10292 
10293 
10294 
10295 
10296 
10297 putchar(' ');
10298 
10299 
10300 
10301 if (V==NULL || V->co==NULL || V->isdynamic !=1){
10302 
10303  t_error("The vector was not allocated properly");
10304 
10305 }else if(V->nl > V->nh ){
10306 
10307  t_error("The vector has no proper dimensions");
10308 
10309 } else {
10310 
10311 
10312 
10313  fprintf(outputfile,"{");
10314 
10315 
10316 
10317  for(i=V->nl;i<V->nh;i++){
10318 
10319  fprintf(outputfile,"%ld,",V->co[i]);
10320 
10321  if(i%columns==0) putchar('\n');
10322 
10323  }
10324 
10325 
10326 
10327  fprintf(outputfile,"%ld}\n",V->co[i]);
10328 
10329 
10330 
10331 }
10332 
10333 
10334 
10335 putchar('\n');
10336 
10337 
10338 
10339 
10340 
10341 
10342 
10343 }
10344 
10345 
10346 
10347 
10348 
10351 void write_floatarray_elements(FILE *outputfile,FLOATVECTOR *V, long columns)
10352 
10353 
10354 
10355 {
10356 
10357 
10358 
10359 long i;
10360 
10361 
10362 
10363 
10364 
10365 putchar(' ');
10366 
10367 
10368 
10369 if (V==NULL || V->co==NULL || V->isdynamic !=1){
10370 
10371  t_error("The vector was not allocated properly");
10372 
10373 }else if(V->nl > V->nh ){
10374 
10375  t_error("The vector has no proper dimensions");
10376 
10377 } else {
10378 
10379 
10380 
10381  fprintf(outputfile,"{");
10382 
10383 
10384 
10385  for(i=V->nl;i<V->nh;i++){
10386 
10387  fprintf(outputfile,"%f,",V->co[i]);
10388 
10389  if(i%columns==0) putchar('\n');
10390 
10391  }
10392 
10393 
10394 
10395  fprintf(outputfile,"%f}\n",V->co[i]);
10396 
10397 
10398 
10399 }
10400 
10401 
10402 
10403 putchar('\n');
10404 
10405 
10406 
10407 
10408 
10409 
10410 
10411 }
10412 
10413 
10414 
10417 void write_doublearray_elements(FILE *outputfile,DOUBLEVECTOR *V, long columns)
10418 
10419 
10420 
10421 {
10422 
10423 
10424 
10425 long i;
10426 
10427 
10428 
10429 
10430 
10431 putchar(' ');
10432 
10433 
10434 
10435 if (V==NULL || V->co==NULL || V->isdynamic !=1){
10436 
10437  t_error("The vector was not allocated properly");
10438 
10439 }else if(V->nl > V->nh ){
10440 
10441  t_error("The vector has no proper dimensions");
10442 
10443 } else {
10444 
10445 
10446 
10447  fprintf(outputfile,"{");
10448 
10449 
10450 
10451  for(i=V->nl;i<V->nh;i++){
10452 
10453  fprintf(outputfile,"%lf,",V->co[i]);
10454 
10455  if(i%columns==0) putchar('\n');
10456 
10457  }
10458 
10459 
10460 
10461  fprintf(outputfile,"%lf}\n",V->co[i]);
10462 
10463 
10464 
10465 }
10466 
10467 
10468 
10469 putchar('\n');
10470 
10471 
10472 
10473 
10474 
10475 
10476 
10477 }
10478 
10479 
10480 
10481 
10482 
10485 void write_chararray_elements(FILE *outputfile, CHARVECTOR *V, long columns)
10486 
10487 
10488 
10489 {
10490 
10491 
10492 
10493 long i;
10494 
10495 
10496 
10497 
10498 
10499 putchar(' ');
10500 
10501 
10502 
10503 if (V==NULL || V->co==NULL || V->isdynamic !=1){
10504 
10505  t_error("The vector was not allocated properly");
10506 
10507 }else if(V->nl > V->nh ){
10508 
10509  t_error("The vector has no proper dimensions");
10510 
10511 } else {
10512 
10513 
10514 
10515  fprintf(outputfile,"{");
10516 
10517 
10518 
10519  for(i=V->nl;i<V->nh;i++){
10520 
10521  fprintf(outputfile,"%c,",V->co[i]);
10522 
10523  if(i%columns==0) putchar('\n');
10524 
10525  }
10526 
10527 
10528 
10529  fprintf(outputfile,"%c}\n",V->co[i]);
10530 
10531 
10532 
10533 }
10534 
10535 
10536 
10537 putchar('\n');
10538 
10539 
10540 
10541 
10542 
10543 
10544 
10545 }
10546 
10547 
10548 
10551 void write_stringsarray_elements(FILE *outputfile,STRINGBIN *V)
10552 
10553 
10554 
10555 {
10556 
10557 
10558 
10559 long i;
10560 
10561 
10562 
10563 
10564 
10565 putchar(' ');
10566 
10567 
10568 
10569 if (V==NULL || V->co==NULL || V->isdynamic !=1){
10570 
10571  t_error("The vector was not allocated properly");
10572 
10573 } else {
10574 
10575 
10576 
10577  fprintf(outputfile,"{");
10578 
10579 
10580 
10581  for(i=(V->index)->nl;i<(V->index)->nh;i++){
10582 
10583  fprintf(outputfile,"%s,\n",V->co[i]);
10584 
10585  }
10586 
10587 
10588 
10589  fprintf(outputfile,"%s}\n",V->co[i]);
10590 
10591 
10592 
10593 }
10594 
10595 
10596 
10597 putchar('\n');
10598 
10599 
10600 
10601 
10602 
10603 
10604 
10605 }
10606 
10607 
10608 
10609 
10610 
10611 
10617 
10618 
10619 
10620 {
10621 
10622 
10623 
10624 extern t_keywords T_KEYWORDS;
10625 
10626 
10627 
10628 if(H != NULL){
10629 
10630  printf("\nBlock number: %ld.\nType: %s %s %s\nName: %s\n",\
10631 
10632  H->number, \
10633 
10634  T_KEYWORDS.gender[H->gender],\
10635 
10636  T_KEYWORDS.type[H->type], \
10637 
10638  T_KEYWORDS.category[H->category],\
10639 
10640  H->name);
10641 
10642 }else {
10643 
10644  printf("\nWarning::This header was not allocated\n");
10645 
10646 }
10647 
10648 }
10649 
10650 
10651 
10654 void write_header_header(FILE *outputfile,HEADER *H)
10655 
10656 
10657 
10658 {
10659 
10660 
10661 
10662 long i;
10663 
10664 
10665 
10666 if(outputfile==NULL || H==NULL || H->name==NULL ){
10667 
10668 
10669 
10670  t_error("An attempt was made to write on a not opened file or a NULL vector");
10671 
10672 
10673 
10674 }else {
10675 
10676 
10677 
10678 
10679 
10680  fprintf(outputfile,"%ld: %s %s %s %s ",\
10681 
10682  H->number, \
10683 
10684  T_KEYWORDS.gender[H->gender],\
10685 
10686  T_KEYWORDS.type[H->type], \
10687 
10688  T_KEYWORDS.category[H->category],\
10689 
10690  H->name);
10691 
10692 
10693 
10694  if(H->dimensions[0]!=0 && H->dimensions[0] < 3){
10695 
10696 
10697 
10698  fprintf(outputfile,"%s",T_KEYWORDS.delimiter[1]);
10699 
10700 
10701 
10702  for(i=1;i<H->dimensions[0];i++){
10703 
10704 
10705 
10706  fprintf(outputfile,"%ld,",H->dimensions[i]);
10707 
10708 
10709 
10710  }
10711 
10712 
10713 
10714  fprintf(outputfile,"%ld%s\n",H->dimensions[i],T_KEYWORDS.delimiter[2]);
10715 
10716 
10717 
10718  }
10719 
10720 
10721 
10722  }
10723 
10724 
10725 
10726 }
10727 
10728 
10729 
10730 
10731 
10732 
10733 
10734 
10735 
10738 void write_turtle(FILE * outputfile,char *creator, char *inputs)
10739 
10740 
10741 
10742 {
10743 
10744 
10745 
10746 
10747 
10748 if(outputfile==NULL){
10749 
10750 
10751 
10752  t_error("An attempt was made towrite on a not opened file");
10753 
10754 
10755 
10756 } else if(inputs ==NULL && creator==NULL) {
10757 
10758 
10759  fprintf(outputfile,"%3s %21s created on %s at %s %2s \n",\
10760 
10761  "/**","This_is_a_turtle_file",__DATE__,__TIME__,"*/");
10762 
10763 
10764 } else if(inputs ==NULL) {
10765 
10766 
10767  fprintf(outputfile,"%3s %21s created on %s at %s by %s %2s\n",\
10768 
10769  "/**","This_is_a_turtle_file",__DATE__,__TIME__,creator,"*/");
10770 
10771 
10772 } else if(creator==NULL) {
10773 
10774 
10775  fprintf(outputfile,"%3s %21s created on %s at %s\n inputs processed: %s %2s\n",\
10776 
10777  "/**","This_is_a_turtle_file",__DATE__,__TIME__,inputs,"*/");
10778 
10779 
10780 
10781 } else {
10782 
10783  fprintf(outputfile,"%3s %21s created on %s at %s by %s \n inputs processed :%s %s\n",\
10784 
10785  "/**","This_is_a_turtle_file",__DATE__,__TIME__,creator,inputs,"*/");
10786 
10787 
10788 }
10789 
10790 }
10791 
10792 
10793 
10796 void write_comment(FILE * outputfile,const char *comment, long columns)
10797 
10798 
10799 
10800 {
10801 
10802 
10803 
10804 
10805 
10806 const char opening[5]="/** ",closing[4]=" */";
10807 
10808 long i,j,len;
10809 
10810 
10811 
10812 if(outputfile==NULL){
10813 
10814 
10815 
10816  t_error("An attempt was made to write on a not opened file");
10817 
10818 
10819 
10820 } else if(comment!=NULL) {
10821 
10822 
10823 
10824  len=strlen(comment);
10825 
10826 
10827 
10828  /* buffer=(char *)malloc((columns+1+NR_END)*sizeof(char)); */
10829 
10830  putc('\n',outputfile);
10831 
10832  fprintf(outputfile,"%s",opening);
10833 
10834  j=5;
10835 
10836  for(i=0;i<len;i++){
10837 
10838 
10839 
10840  if( j< columns){
10841 
10842 
10843 
10844  if( comment[i]!='\n' && comment[i]!='\t'){
10845 
10846  putc(comment[i],outputfile);
10847 
10848  } else {
10849 
10850 
10851 
10852  putc(' ',outputfile);
10853 
10854  }
10855 
10856 
10857 
10858  j++;
10859 
10860 
10861 
10862  }
10863 
10864 
10865 
10866 
10867 
10868  if(j == columns && !isspace(comment[i-1])){
10869 
10870 
10871 
10872  putc('-',outputfile);
10873 
10874 
10875 
10876  putc('\n',outputfile);
10877 
10878 
10879 
10880  j=0;
10881 
10882 
10883 
10884  }
10885 
10886 
10887 
10888 
10889 
10890  }
10891 
10892 
10893 
10894  if( j+2 < columns){
10895 
10896  fprintf(outputfile,closing);
10897 
10898  } else {
10899 
10900  putc('\n',outputfile);
10901 
10902  fprintf(outputfile,closing);
10903 
10904  }
10905 
10906 
10907 
10908  putc('\n',outputfile);
10909 
10910 }
10911 
10912 
10913 
10914 }
10915 
10916 
10917 /*-----------------------------------------------------------------------*/
10918 
10919 long read_doubletensor_elements(FILE *input,DOUBLETENSOR *m,char *mode)
10922 {
10923 
10924 long tmp=0,count=0;
10925 
10926 const char ascii[2]="a",binary[2]="b";
10927 long i,j,k;
10928 
10929 
10930 
10931 if(input==NULL){
10932  t_error("The input file was not opened properly");
10933 }else if (m==NULL || m->co==NULL || (m->isdynamic)!=1){
10934  t_error("The tensor was not allocated properly");
10935 }else if(m->nrl > m->nrh || m->ncl > m->nch || m->ndl > m->ndh){
10936  t_error("The tensor has no proper dimensions");
10937 } else if(strcmp(mode,ascii)==0){
10938 
10939 for(k=m->ndl;k<=m->ndh;k++){
10940  for(i=m->nrl;i<=m->nrh;i++){
10941  for(j=m->ncl;j<=m->nch;j++){
10942  tmp=fscanf(input,"%lf",&(m->co[k][i][j]));
10943  if(tmp!=EOF){
10944  count+=tmp;
10945  }else {
10946  printf("Error in stored data::Unexpected End of File encountered\n");
10947  printf(" after position %ld\n",count);
10948  return -count;
10949  }
10950  }
10951  }
10952  }
10953 
10954 }else if(strcmp(mode,binary)==0){
10955  t_error("Error in reading mode::Mode not yet implemented");
10956 } else {
10957  t_error("Error in reading mode::Mode not supported");
10958 }
10959 
10960 if(count!=(m->nrh-m->nrl+1)*(m->nch-m->ncl+1)*(m->ndh-m->ndl+1)){
10961  printf("Error in stored data::Stored data number does not match the request");
10962  return -count;
10963 }else{
10964  return count;
10965 }
10966 
10967 }
10968 
10969 
10971 long write_doubletensor_elements(FILE * output,DOUBLETENSOR *m,long maxcols)
10972 
10973 /* Write a matrix of double numbers to a file */
10974 
10975 {
10976 
10977 long tmp=0,i,j,k; //count=0
10978 
10979 
10980 
10981 if(output==NULL){
10982  t_error("The input file was not opened properly");
10983 }else if (m==NULL || m->co==NULL || m->isdynamic !=1){
10984  t_error("The tensor was not allocated properly");
10985 }else if(m->nrl > m->nrh || m->ncl >m->nch || m->ndl > m->ndh){
10986  t_error("The tensor has no proper dimensions");
10987 } else {
10988 
10989 for(k=m->ndl;k<=m->ndh;k++){
10990  for(i=m->nrl;i<=m->nrh;i++){
10991  for(j=m->ncl;j<=m->nch;j++){
10992  tmp=fprintf(output,"%f ",m->co[k][i][j]);
10993  if(tmp==EOF){
10994  printf("Error in storing data::Unespected End of file encountered\n");
10995  return EOF;
10996  }
10997  }
10998  putc('\n',output);
10999  if(j%maxcols==0 && j!= m->ncl) putc('\n',output);
11000  }
11001  putc('\n',output);
11002  }
11003  putchar('\n');
11004 }
11005 
11006 return OK;
11007 
11008 }
11009 
11010 
11011 
11014 /* Write a matrix of double to the standard output */
11015 
11016 {
11017 
11018 long i,j,k;
11019 /* char ch; */
11020 
11021 putchar('\n');
11022 
11023 if (m==NULL || m->co==NULL || m->isdynamic !=1){
11024  t_error("The matrix was not allocated properly");
11025 }else if(m->nrl > m->nrh || m->ncl >m->nch ){
11026  t_error("The matrix has no proper dimensions");
11027 } else {
11028 
11029 for(k=m->ndl;k<=m->ndh;k++){
11030  for(i=m->nrl;i<=m->nrh;i++){
11031  for(j=m->ncl;j<=m->nch;j++){
11032  printf("%f ",m->co[k][i][j]);
11033  if(j%maxcols==0 && j!= m->nch) putchar('\n');
11034  /* scanf("%c",&ch); */
11035  } putchar('\n');
11036  }
11037  putchar('\n');
11038  }
11039  putchar('\n');
11040 }
11041 
11042 
11043 }
11044 
11045 
11048 DOUBLETENSOR *read_doubletensor(FILE *inputfile, char *mode,short print)
11049 
11050 
11051 
11052 {
11053 
11054 
11055 
11056 char ch;
11057 HEADER h;
11058 DOUBLETENSOR *C;
11059 long u;
11060 
11061 
11062 
11063  if(inputfile==NULL){
11064  t_error("You tried to read from a closed file ");
11065 } else {
11066  read_tensorheader(inputfile,&h);
11067  if(print==1){
11068  print_header(&h);
11069  printf("Dimensions: %ld %ld %ld\n",h.dimensions[1],h.dimensions[2],h.dimensions[3]);
11070 
11071  }
11072 
11073 
11074 if(h.category!=5 || h.type!=6)
11075  printf("\nWarning::the data being read are not stored as a tensor of double\n");
11077  skip_whitespaces(inputfile);
11078  if(query_for_token(inputfile,"->")) {
11079  if (OPENYES==1){
11080  t_error("It is not permitted to have more than one external file open");
11081  } else {
11082 
11083  OPENYES=1;
11084  strcpy(EXTERNAL_FILE_NAME,get_phrase(inputfile,';'));
11085  if(strcmp(EXTERNAL_FILE_NAME,OLD_NAME) && EXTERNAL_FILE_POSITION !=SEEK_SET){
11086  EXTERNAL_FILE_POSITION =SEEK_SET;
11087  printf("\nWarning::The external file could open in a wrong position\n");
11089  } else if(!strcmp(EXTERNAL_FILE_NAME,OLD_NAME) && EXTERNAL_FILE_POSITION!=SEEK_SET){
11091  fseek(EXTERNAL_FILE,EXTERNAL_FILE_POSITION,SEEK_SET);
11092 
11093  } else {
11096  }
11097 
11098  read_matrixheader(EXTERNAL_FILE,&EXTERNAL_HEADER);
11100  if(headercmp(&h,&EXTERNAL_HEADER)) {
11101  t_error("External data file does not match the request ");
11102  } else {
11105  ch=getc(EXTERNAL_FILE);
11106  if(ch == EOF){
11107  EXTERNAL_FILE_POSITION=SEEK_SET;
11109  free_header(EXTERNAL_HEADER);
11110  OPENYES=0;
11111  } else {
11112  ungetc(ch,EXTERNAL_FILE);
11114  strcpy(OLD_NAME,EXTERNAL_FILE_NAME);
11116  free_header(EXTERNAL_HEADER);
11117  OPENYES=0;
11118  }
11119 
11120  }
11121 
11122 
11123 
11124  }
11125 
11126 
11127 
11128  } else { /* Not an external file */
11129  read_doubletensor_elements(inputfile,C,mode);
11130  }
11131 
11132 }
11133 
11134 free_header(h);
11135 return C;
11136 
11137 }
11138 
11139 
11140 
11145 void read_tensorheader(FILE *inputfile,HEADER *h)
11146 
11147 
11148 {
11149 
11150 
11151 
11152 
11153 char curl;
11154 
11155 const char ocurl='{', ccurl='}';
11156 
11157 //short ind=1;
11158 
11159 //long buffer_index=0,buffer_size=0,blocksnumber=0;
11160 
11161 /*Scanning the first part of the array */
11162 
11163 if(inputfile==NULL){
11164  t_error("You tried to read from a closed file ");
11165 } else if(h==NULL){
11166  t_error("You addressed a null header ");
11167 } else {
11168  header_scan(inputfile,h);
11169  skip_whitespaces(inputfile);
11170  curl=fgetc(inputfile);
11171  if(curl!=ocurl) {
11172  t_error("A non expected character found");
11173  } else {
11174  h->dimensions[0]=3;
11175  fscanf(inputfile," %ld , %ld , %ld",&(h->dimensions[1]),&(h->dimensions[2]),&(h->dimensions[3]));
11176  }
11177 
11178  curl=fgetc(inputfile);
11179  if(curl!=ccurl){
11180  t_error("Closing delimiter not found");
11181 
11182  }
11183 }
11184 }
11185 
11186 
11187 
11188 
11189 
11190 
11191 
11192 
11193