OpenRadioss 2025.1.11
OpenRadioss project
Loading...
Searching...
No Matches
write_routtines.c
Go to the documentation of this file.
1//Copyright> OpenRadioss
2//Copyright> Copyright (C) 1986-2025 Altair Engineering Inc.
3//Copyright>
4//Copyright> This program is free software: you can redistribute it and/or modify
5//Copyright> it under the terms of the GNU Affero General Public License as published by
6//Copyright> the Free Software Foundation, either version 3 of the License, or
7//Copyright> (at your option) any later version.
8//Copyright>
9//Copyright> This program is distributed in the hope that it will be useful,
10//Copyright> but WITHOUT ANY WARRANTY; without even the implied warranty of
11//Copyright> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12//Copyright> GNU Affero General Public License for more details.
13//Copyright>
14//Copyright> You should have received a copy of the GNU Affero General Public License
15//Copyright> along with this program. If not, see <https://www.gnu.org/licenses/>.
16//Copyright>
17//Copyright>
18//Copyright> Commercial Alternative: Altair Radioss Software
19//Copyright>
20//Copyright> As an alternative to this open-source version, Altair also offers Altair Radioss
21//Copyright> software under a commercial license. Contact Altair to discuss further if the
22//Copyright> commercial version may interest you: https://www.altair.com/radioss/.
23#include "hardware.inc"
24#include <stdio.h>
25#include <string.h>
26#include <stdlib.h>
27#include <math.h>
28#include <fcntl.h>
29#include <zlib.h>
30
31
32#ifdef _WIN64
33
34#include <process.h>
35#include <io.h>
36#include <sys\types.h>
37#include <sys/stat.h>
38#include <time.h>
39#include <zlib.h>
40
41
42#elif 1
43#include <sys/resource.h>
44#include <sys/types.h>
45#include <time.h>
46#include <sys/stat.h>
47#include <unistd.h>
48#endif
49
50#define _FCALL
51
52void integer_to_IEEE_ASCII(int entier,unsigned char octet[4]);
53void IEEE_ASCII_to_integer(int *entier,unsigned char octet[4]);
54
55void real_to_IEEE_ASCII(float reel,unsigned char octet[4]);
56void IEEE_ASCII_to_real(float *reel,unsigned char octet[4]);
57
58void double_to_IEEE_ASCII(double *reel,unsigned char octet[1000][8],int len);
59void IEEE_ASCII_to_double(double *reel,unsigned char octet[1000][8],int len);
60
61// functions prototypes from this file
62// -------------------------------------
63void file_init_();
64void open_c(int *ifil,int *len,int *mod);
65void close_c();
66
67void fseek_c_rd(int * lseek);
68void fseek_end_c(int * lseek);
69void file_size(int * filesize);
70void filelen_sys(char * ffilnam,int *len,int * size);
71void cur_fil_c(int *nf);
72void eor_c(int *len);
73
74void write_r_c(float *w,int *len);
75void write_db_c(double *w,int *len);
76void write_db_array_c(double *w,int *len);
77void write_c_c(int *w,int *len);
78void write_c_c_txt(char *w,int *len);
79void write_i_c(int *w,int *len);
80void write_i_array_c(int *w,int *len);
81
82void write_s_c(int *w, int *len);
83
84void read_db_c(double *w,int *len);
85void read_db_array_c(double *w,int *len);
86void read_r_c(float *w, int *len);
87void read_i_c(int *w, int *len);
88void read_i_array_c(int *w, int *len);
89void read_c_c(int *w,int *len);
90void flu_fil_c();
91
92void arret_(int *n);
93void ARRET(int *n);
94void arret_c(int n);
95
96// Compress gzip functions
97int Compress_Buffer(unsigned char* input, int inputSize, unsigned char* output, int outputSize);
98void write_buffer(unsigned char *buf,int type_size,int length);
99void close_buffer();
100void delete_tmpfile_(char *name, int *size);
101
102
103// Some Defines / common variables
104// --------------------------------
105#define BUFLEN 256
106#define ZSUFFIX 0
107#define GZSUFFIX 1
108
109#define COMP_BUFFER_SIZE 10240
110
111// ---------------------------------------- //
112// FILE pointer already used : //
113// 0-->4 //
114// 20 : reopen the _0001.rst in order to //
115// add the real elapsed time //
116// 31-->41 //
117// 42-->42+n for sectio (but I don't known //
118// the value of n) //
119// ---------------------------------------- //
120FILE *outfile[100]; // List of FILE descriptors.
121int outfile_mod[100]; // Git the compression Mode : 0 no compression, 1 compress, 2 uncompress
122unsigned char *compress_write_buffer[100];
125FILE *curfile; // FILE pointer to current file call to cur_fil_c function set this.
126int cur_nf; // ID to current FILE descriptor call to cur_fil_c function set this.
127
128// Threadprivate: Starter Restarts
129#pragma omp threadprivate(outfile,outfile_mod,compress_write_buffer,compress_buffer_length,curfile,cur_nf,compress_read_buffer)
130
131// -------------------------------------------------------
132void arret_c(int n)
137{
138/*Appel a une routine Fortran */
139#ifdef _WIN64
140 ARRET(&n);
141#else
142 arret_(&n);
143#endif
144}
145
146// -------------------------------------------------------------------------------------
147
153//
154 int i;
155 for (i=0;i<100;i++){
156 outfile[i]=NULL;
157 outfile_mod[i]=0;
158 }
159}
160
162 int i;
163 for (i=0;i<100;i++){
164 outfile[i]=NULL;
165 outfile_mod[i]=0;
166 }
167}
168
170{
171 int i;
172 for (i=0;i<100;i++){
173 outfile[i]=NULL;
174 outfile_mod[i]=0;
175 }
176}
177
178// -------------------------------------------------------------------------------------
179
180void open_c(int *ifil,int *len,int *mod)
190{
191 char *filnam;
192 int i;
193 gzFile gzstream;
194
195 #ifdef _WIN64
196 /* Windows in Binary format */
197 _set_fmode(_O_BINARY);
198 #endif
199
200 // Create char* filnam
201 filnam = (char*) malloc(sizeof(char)*(*len+10) );
202
203
204 //printf("Mod:%i\n",*mod);
205
206 for(i=0;i<*len;i++) filnam[i]=(char)ifil[i];
207 filnam[*len]='\0';
208
209 // Global buffers initialization
210 outfile_mod[cur_nf]=0; // Saves compress mode (0 : non, 1 gzip, 2 gunzip)
211 compress_write_buffer[cur_nf]=NULL; // Intermediate buffer to store the data to compress
212 compress_buffer_length[cur_nf]=0; // Size of data to compress
213
214 if (*mod == 1 || *mod == 4 || *mod == 7){ // Open Read : 4 & 7 are gzipped
215
216 if (*mod !=1){ // unzip
217 #ifdef _WIN64
218 strcat_s(filnam,*len+10,".gz");
219 #else
220 strcat(filnam,".gz");
221 #endif
223 gzstream = gzopen(filnam,"r");
224 if (gzstream == NULL){
225 printf(" ** ERROR: FILE %s NOT FOUND\n",filnam);
226 /*force flush buffer to avoid missing error message on windows in some cases*/
227 fflush(stdout);
228 arret_c(2);
229 }
230 gzbuffer(gzstream, COMP_BUFFER_SIZE);
231 curfile=(FILE *)gzstream;
232
233 }else{ // Not zipped file
234
235 #ifdef _WIN64
236 curfile=fopen(filnam,"r");
237 #else
238 curfile=fopen(filnam,"r");
239 #endif
240
241 if (!curfile){
242 printf(" ** ERROR: FILE %s NOT FOUND\n",filnam);
243 /*force flush buffer to avoid missing error message on windows in some cases*/
244 fflush(stdout);
245 arret_c(2);
246 }
247 }
248 }
249 if (*mod==0 || *mod == 3 ||*mod==6 ){ // Open Write : 0 unzipped 3 & 6 are gzipped
250 if(*mod!=0){ // zip
251 #ifdef _WIN64
252 strcat_s(filnam,*len+10,".gz");
253 #else
254 strcat(filnam,".gz");
255 #endif
257 compress_write_buffer[cur_nf]=(unsigned char *)malloc(COMP_BUFFER_SIZE+2048); // Create a buffer of COMP_BUFFER_SIZE + 2k (gzip header) for compression
258 // Several buffers can be opened at same time.
259 }
260 #ifdef _WIN64
261 curfile=fopen(filnam,"w");
262 #else
263 curfile=fopen(filnam,"w");
264 #endif
265 }
266
267 if (*mod==2) { // Open Read/Write : uncompressed
268 #ifdef _WIN64
269 curfile=fopen(filnam,"r+");
270 #else
271 curfile=fopen(filnam,"r+");
272 #endif
273 }
274
275 if (*mod==8) { // Open Append mode - unzipped
276 #ifdef _WIN64
277 curfile=fopen(filnam,"a");
278 #else
279 curfile=fopen(filnam,"a");
280 #endif
281 }
282
284 free(filnam);
285}
286
287// C/Fortran interface
288void _FCALL OPEN_C(int *ifil,int *len,int *mod)
289{ open_c(ifil,len,mod);}
290
291void open_c_(int *ifil,int *len,int *mod)
292{ open_c(ifil,len,mod); }
293
294void open_c__(int *ifil,int *len,int *mod)
295{ open_c(ifil,len,mod); }
296
297// -------------------------------------------------------------------------------------
301{
302 if (outfile_mod[cur_nf] == 1){ // Close write with compression
303 close_buffer(); // flush the remaining values in buffer
304 fclose(curfile);
305 }else if (outfile_mod[cur_nf] == 2){ // Close read with compression
306 gzclose((gzFile)curfile);
307 }else{
308 fclose(curfile); // Close with No compression
309 outfile[cur_nf]=NULL;
310 }
311}
313{ close_c(); }
314
316{ close_c(); }
317
319{ close_c();}
320
321// -------------------------------------------------------------------------------------
322
323void fseek_c_rd(int * lseek){
328 fseek(curfile,*lseek,SEEK_CUR);
329}
330
331void fseek_c_rd_(int * lseek){
332 fseek_c_rd(lseek);
333}
334
335void fseek_c_rd__(int * lseek){
336 fseek_c_rd(lseek);
337}
338
339void _FCALL FSEEK_C_RD(int * lseek){
340 fseek_c_rd(lseek);
341}
342
343void fseek_end_c(int * lseek){
348 fseek(curfile,*lseek,SEEK_END);
349}
350
351void fseek_end_c_(int * lseek){
352 fseek_end_c(lseek);
353}
354
355void _FCALL FSEEK_END_C(int * lseek){
356 fseek_end_c(lseek);
357}
358
359
360void file_size_(int * filesize)
365{
366 long sz;
367 sz=ftell(curfile);
368 *filesize=sz/1024;
369}
370
371void file_size(int * filesize){
372 file_size_(filesize);
373}
374
375void file_size__(int * filesize){
376 file_size_(filesize);
377}
378
379void _FCALL FILE_SIZE(int * filesize){
380 file_size_(filesize);
381}
382
383
384void file_size_c_(long *size)
389{
390 *size= ftell(curfile)/1024;
391}
392
393void _FCALL FILE_SIZE_C(long *size)
394{
395 *size= ftell(curfile) / 1024;
396}
397/* --------------------- */
398
399
400// -------------------------------------------------------------------------------------
401
402
403#ifdef _WIN64
404
405void filelen_sys_(char * ffilnam,int *len,int * size)
412{
413 char * filnam;
414 char command[256],line[256];
415 char var1[128],var2[128],var3[128],fnam[128],ssize[128];
416 int i,found,ret;
417 struct _stat statbuf;
418
419 filnam = malloc(*len+10);
420 for (i=0;i<*len;i++) { filnam[i]=ffilnam[i]; }
421 filnam[*len]='\0';
422
423 ret = _stat (filnam,&statbuf);
424 if (ret != -1){
425 *size = statbuf.st_size / 1024;
426 }else{
427 *size = 0;
428 }
429
430 free(filnam);
431
432}
433
434#else
435void filelen_sys_(char * ffilnam,int *len,int * size)
442{
443 char * filnam;
444 char command[256],line[256];
445 char var1[128],var2[128],var3[128],var4[128],ssize[128];
446 int i,ret;
447 struct stat statbuf;
448 FILE * scall;
449 filnam = malloc(*len+10);
450 for (i=0;i<*len;i++) { filnam[i]=ffilnam[i]; }
451 filnam[*len]='\0';
452
453 ret = stat (filnam,&statbuf);
454 if (ret != -1){
455 *size = statbuf.st_size / 1024;
456 }else{
457 *size = 0;
458 }
459 free(filnam);
460
461}
462#endif
463
464void filelen_sys(char * ffilnam,int *len,int * size){
465 filelen_sys_(ffilnam,len, size);
466}
467
468void filelen_sys__(char * ffilnam,int *len,int * size){
469 filelen_sys_(ffilnam,len, size);
470}
471
472void _FCALL FILELEN_SYS(char * ffilnam,int *len,int * size){
473 filelen_sys_(ffilnam,len, size);
474}
475
476// -------------------------------------------------------------------------------------
477void cur_fil_c(int *nf)
482{
483 cur_nf = *nf;
484 curfile = outfile[*nf];
485}
486
487void _FCALL CUR_FIL_C(int *nf)
488{ cur_fil_c(nf);}
489
490void cur_fil_c_(int *nf)
491{ cur_fil_c(nf);}
492
493void cur_fil_c__(int *nf)
494{ cur_fil_c(nf); }
495
496// -------------------------------------------------------------------------------------
497
498void eor_c(int *len)
503{
504 int i;
505 unsigned char octet[4];
506
507 integer_to_IEEE_ASCII(*len,octet);
508 write_buffer(octet,sizeof(unsigned char),4);
509}
510void _FCALL EOR_C(int *len)
511{ eor_c(len);}
512
513void eor_c_(int *len)
514{ eor_c(len);}
515
516
517// -------------------------------------------------------------------------------------
518
519void write_r_c(float *w,int *len)
525{
526 int i,j,k,block;
527 unsigned char buf[BUFLEN*4];
528
529 for(k=0;k<*len;k+=BUFLEN){
530 block = ((*len-k) < BUFLEN)?(*len-k):BUFLEN;
531 for(i=0;i<block;i++){
532 real_to_IEEE_ASCII(w[i+k],&buf[i*4]);
533 }
534
535 //fwrite(buf,sizeof(unsigned char),block*4,curfile);
536 write_buffer(buf,sizeof(unsigned char),block*4);
537 }
538}
539
540
541void _FCALL WRITE_R_C(float *w,int *len)
542{
543 write_r_c(w,len);
544}
545
546void write_r_c_(float *w,int *len)
547{
548 write_r_c(w,len);
549}
550
551// -------------------------------------------------------------------------------------
552
553void write_db_c(double *w,int *len)
559{
560 int i,j;
561 unsigned char octet[1000][8];
562
563 if (*len > 1000){
564 printf(" ** ERROR: BAD SIZE FOR WRITING\n");
565 arret_c(2);
566 }
567 double_to_IEEE_ASCII(w,octet,*len);
568 //fwrite(octet,sizeof(char),(*len)*8,curfile);
569 write_buffer((unsigned char*)octet,sizeof(char),(*len)*8);
570}
571
572void _FCALL WRITE_DB_C(double *w,int *len)
573{write_db_c(w,len);}
574
575void write_db_c_(double *w,int *len)
576{ write_db_c(w,len);}
577
578void write_db_c__(double *w,int *len)
579{write_db_c(w,len);}
580
581void _FCALL WRITE_DB_ARRAY_C(double *w,int *len)
582{write_db_c(w,len);}
583
584void write_db_array_c_(double *w,int *len)
585{ write_db_c(w,len);}
586
587void write_db_array_c__(double *w,int *len)
588{write_db_c(w,len);}
589// -------------------------------------------------------------------------------------
590
591void write_c_c(int *w,int *len)
597{
598 int i;
599 for(i=0;i<*len;i++) write_buffer((unsigned char *)&w[i],sizeof(char),1);
600}
601
602void _FCALL WRITE_C_C(int *w,int *len)
603{ write_c_c(w,len);}
604void write_c_c_(int *w,int *len)
605{write_c_c(w,len);}
606
607void write_c_c__(int *w,int *len)
608{write_c_c(w,len);}
609
610// -------------------------------------------------------------------------------------
611
612void write_c_c_txt(char *w,int *len)
618{
619 char *buf;
620 int i,mod;
621 buf=(char*)malloc(sizeof(char)*(*len+2));
622
623 // Buffer may come from Fortran : Need to recopy it & add \n + \0 in
624 for(i=0;i<*len;i++)buf[i]=w[i];
625 buf[*len]='\n';
626 buf[*len+1]='\0';
627
628 mod = outfile_mod[cur_nf];
629
630 write_buffer((unsigned char*)buf,sizeof(unsigned char),*len+1);
631 free (buf);
632}
633void _FCALL WRITE_C_C_TXT(char *w,int *len)
634{ write_c_c_txt(w,len);}
635
636void write_c_c_txt_(char *w,int *len)
637{ write_c_c_txt(w,len);}
638
639
640void write_c_c_txt__(char *w,int *len)
641{ write_c_c_txt(w,len);}
642
643// -------------------------------------------------------------------------------------
644
645void write_i_c(int *w,int *len)
651{
652 int i,j,k,block;
653 unsigned char buf[BUFLEN*4];
654
655 for(k=0;k<*len;k+=BUFLEN){
656 block = ((*len-k) < BUFLEN)?(*len-k):BUFLEN;
657 for(i=0;i<block;i++){
658 integer_to_IEEE_ASCII(w[i+k],&buf[i*4]);
659 }
660 write_buffer(buf,sizeof(unsigned char),block*4);
661 }
662}
663
664void _FCALL WRITE_I_C(int *w,int *len)
665{write_i_c(w,len);}
666
667void write_i_c_(int *w,int *len)
668{ write_i_c(w,len); }
669
670
671void write_i_c__(int *w,int *len)
672{write_i_c(w,len);}
673
674
675void _FCALL WRITE_I_ARRAY_C(int *w,int *len)
676{write_i_c(w,len);}
677
678void write_i_array_c_(int *w,int *len)
679{ write_i_c(w,len); }
680
681
682void write_i_array_c__(int *w,int *len)
683{write_i_c(w,len);}
684
685
686// -------------------------------------------------------------------------------------
687void write_s_c(int *w, int *len)
693{
694 int i,j;
695 unsigned char octet[4];
696
697 for(j=0;j<*len;j++){
698 integer_to_IEEE_ASCII(w[j],octet);
699 for(i=2;i<4;i++) write_buffer(&octet[i],sizeof(unsigned char),1);
700 }
701}
702
703void _FCALL WRITE_S_C(int *w, int *len)
704{ write_s_c(w,len); }
705
706void write_s_c_(int *w, int *len)
707{ write_s_c(w,len); }
708
709// -------------------------------------------------------------------------------------
710
711void read_db_c(double *w,int *len){
717 int i, j, c,nitems;
718 unsigned char octet[1000][8];
719 gzFile gzstream;
720
721 if (*len > 1000){ // Read is done in blocks of 1000 floats
722 printf(" ** ERROR: BAD SIZE FOR READING\n");
723 arret_c(2);
724 }
725
726 if(outfile_mod[cur_nf]==0){ // Read unzipped
727 if(fread(octet,sizeof(char),(*len)*8,curfile)!=(*len)*8){
728 printf(" ** ERROR: END OF FILE DURING READING\n");
729 arret_c(2);
730 }
731 }else{ // Read Zipped
732 gzstream=(gzFile)curfile;
733 nitems=gzfread(octet,sizeof(unsigned char)*8,*len,gzstream);
734 if (nitems <*len ){
735 printf(" ** ERROR: END OF FILE DURING READING\n");
736 arret_c(2);
737 }
738 }
739 IEEE_ASCII_to_double(w,octet,*len);
740}
741
742void _FCALL READ_DB_C(double *w,int *len)
743{ read_db_c(w,len); }
744
745void read_db_c_(double *w,int *len)
746{ read_db_c(w,len); }
747
748
749void _FCALL READ_DB_ARRAY_C(double *w,int *len)
750{ read_db_c(w,len); }
751
752void read_db_array_c_(double *w,int *len)
753{ read_db_c(w,len); }
754
755// -------------------------------------------------------------------------------------
756void read_r_c(float *w, int *len)
762{
763 int i, j, k, block, n,nitems;
764 unsigned char buf[4*BUFLEN];
765 unsigned char * gzbuf;
766 gzFile gzstream;
767
768 if(outfile_mod[cur_nf]==0){ // Read unzipped
769 for(k=0;k<*len;k+=BUFLEN){ // Read is done according to blocks of BUFLEN (256 characters)
770 block = ((*len-k) < BUFLEN)?(*len-k):BUFLEN;
771 n = fread(buf,sizeof(unsigned char),block*4,curfile);
772 if (n!=block*4){
773 printf(" ** ERROR: END OF FILE DURING READING\n");
774 for(i=0;i<n/4;i++){
775 IEEE_ASCII_to_real(&w[i+k],&buf[4*i]);
776 }
777 w[k+n/4]=-1.;
778 }
779 for(i=0;i<block;i++){
780 IEEE_ASCII_to_real(&w[i+k],&buf[4*i]);
781 }
782 }
783 }else{ // Read Zipped
784 gzstream=(gzFile)curfile;
785 gzbuf=(unsigned char *)malloc(sizeof(unsigned char)* *len*4); // Read & decompress is done in one chunk
786 nitems=gzfread(buf,sizeof(unsigned char),*len*4,gzstream);
787 if (nitems != *len*4){
788 printf(" ** ERROR: END OF FILE DURING READING\n");
789 }
790 for(i=0;i<*len;i++){
791 IEEE_ASCII_to_real(&w[i],&gzbuf[4*i]);
792 }
793 free(gzbuf);
794 }
795} /* fin read_r_c */
796
797
798void _FCALL READ_R_C(float *w, int *len)
799{ read_r_c(w,len);} /* fin READ_R_C */
800
801void read_r_c_(float *w, int *len)
802{ read_r_c(w,len); } /* fin read_r_c_ */
803
804// -------------------------------------------------------------------------------------
805void read_i_c(int *w, int *len)
811{
812 int i, j, k, block,nitems;
813 unsigned char buf[4*BUFLEN];
814 unsigned char * gzbuf;
815 gzFile gzstream;
816
817 if(outfile_mod[cur_nf]==0){ // Read unzipped
818 for(k=0;k<*len;k+=BUFLEN){
819 block = ((*len-k) < BUFLEN)?(*len-k):BUFLEN; // Read is done in blocks of 256 items
820 if (fread(buf,sizeof(unsigned char),block*4,curfile)!=block*4){
821 printf(" ** ERROR: END OF FILE DURING READING\n");
822 arret_c(2);
823 }
824 for(i=0;i<block;i++){
825 IEEE_ASCII_to_integer(&w[i+k],&buf[4*i]);
826 }
827 }
828 }else{
829 gzstream=(gzFile)curfile;
830 gzbuf=(unsigned char *)malloc(sizeof(unsigned char)* *len*4); // Read is done in one chunk
831 nitems=gzfread(gzbuf,sizeof(int),*len,gzstream);
832 if (nitems != *len){
833 printf(" ** ERROR: END OF FILE DURING READING\n");
834 }
835 for(i=0;i<*len;i++){
836 IEEE_ASCII_to_integer(&w[i],&gzbuf[4*i]);
837 }
838 free(gzbuf);
839 }
840}
841
842void _FCALL READ_I_C(int *w, int *len)
843{ read_i_c(w,len);} /* READ_I_C */
844
845void read_i_c_(int *w, int *len)
846{ read_i_c(w,len);}
847
848
849void _FCALL READ_I_ARRAY_C(int *w, int *len)
850{ read_i_c(w,len);} /* READ_I_C */
851
852void read_i_array_c_(int *w, int *len)
853{ read_i_c(w,len);}
854
855
856// -------------------------------------------------------------------------------------
857void read_c_c(int *w, int *len)
863{
864 int j,nitems;
865 unsigned char * gzbuf;
866 gzFile gzstream;
867
868 if(outfile_mod[cur_nf]==0){ // Read unzipped
869
870 for(j=0;j<*len;j++){
871 if((w[j] = (int) getc(curfile)) == EOF){
872 printf(" ** ERROR: END OF FILE DURING READING\n");
873 arret_c(2);
874 }
875 }
876 }else{
877 gzstream=(gzFile)curfile;
878 gzbuf=(unsigned char *)malloc(sizeof(unsigned char)* *len);
879 nitems=gzfread(gzbuf,1,*len,gzstream);
880 if(nitems < *len){
881 printf(" ** ERROR: END OF FILE DURING READING\n");
882 arret_c(2);
883 }
884 for (j=0;j<*len;j++) w[j]=(int)gzbuf[j];
885 free(gzbuf);
886 }
887}
888
889void _FCALL READ_C_C(int *w, int *len)
890{ read_c_c(w,len); }
891
892
893void read_c_c_(int *w, int *len)
894{ read_c_c(w,len);}
895
896
897void read_c_c__(int *w, int *len)
898{ read_c_c(w,len);}
899
900// -------------------------------------------------------------------------------------
905 fflush(curfile);
906}
907
909 flu_fil_c();
910}
911
913 flu_fil_c();
914}
915
916
918{flu_fil_c();}
919
920// -------------------------------------------------------------------------------------
921int Compress_Buffer(unsigned char* input, int inputSize, unsigned char* output, int outputSize){
929 z_stream zs;
930 zs.zalloc = Z_NULL;
931 zs.zfree = Z_NULL;
932 zs.opaque = Z_NULL;
933 zs.avail_in = (uInt)inputSize;
934 zs.next_in = (Bytef *)input;
935 zs.avail_out = (uInt)outputSize;
936 zs.next_out = (Bytef *)output;
937
938 //printf("input: %i\n",inputSize);
939 // hard to believe they don't have a macro for gzip encoding, "Add 16" is the best thing zlib can do:
940 // "Add 16 to windowBits to write a simple gzip header and trailer around the compressed data instead of a zlib wrapper"
941 deflateInit2(&zs, Z_DEFAULT_COMPRESSION, Z_DEFLATED, 15 | 16, 8, Z_DEFAULT_STRATEGY);
942 deflate(&zs, Z_FINISH);
943 deflateEnd(&zs);
944 return zs.total_out;
945// *out_len = compress2(out_buffer,&lout_len,in_buffer,lin_len,level);
946}
947
948
949// -------------------------------------------------------------------------------------
950void write_buffer(unsigned char *buf,int type_size,int length){
959 int to_do;
960 int i,len,inputSize,compressed_buf_size,compressed_len,mod;
961 unsigned char *compressed_buf;
962 len=type_size*length;
963 i=0;
964 to_do=1;
965
966 mod=outfile_mod[cur_nf];
967 if( mod == 0){ // Write in non zipped format
968 fwrite(buf,sizeof(unsigned char),len,curfile);
969 }else{ // Write in gzip format
970
971 while( to_do==1 ){ // while buf has not been treated
972
973 // Copy arrays in a Buffer of COM_BUFFER_SIZE
976 i++;
978 }
979
981 // COM_BUFFER_SIZE Buffer is full. Compress & write on disk
982 compressed_buf=(unsigned char *)malloc(sizeof(unsigned char)*(COMP_BUFFER_SIZE+2048));
984 compressed_buf_size=COMP_BUFFER_SIZE+2048;
985 compressed_len = Compress_Buffer(compress_write_buffer[cur_nf], inputSize , compressed_buf, compressed_buf_size);
986 fwrite(compressed_buf,sizeof(unsigned char),compressed_len,curfile);
987
988 free(compressed_buf);
990 }
991
992 if (i==len) to_do=0;
993 }
994 }
995}
996
997
998
999// -------------------------------------------------------------------------------------
1005 int mod,len,compressed_len,compressed_buf_len;
1006 unsigned char *compressed_buf;
1007
1008 mod=outfile_mod[cur_nf];
1009 if( mod != 0){
1011 if (len > 0){
1012
1013 compressed_buf=(unsigned char *)malloc(sizeof(unsigned char)*(len+2048));
1014 compressed_buf_len=len+2048;
1015 compressed_len = Compress_Buffer(compress_write_buffer[cur_nf], len , compressed_buf, compressed_buf_len);
1016 fwrite(compressed_buf,sizeof(unsigned char),compressed_len,curfile);
1017 }
1018 free(compress_write_buffer[cur_nf]); // Compress buffer is freed
1019 compress_buffer_length[cur_nf]=0; // it length is set to zero
1020 }
1021}
1022
1023// -------------------------------------------------------------------------------------
1024void delete_tmpfile_(char *name, int *size)
1033
1034{
1035 char *cname;
1036 int cname_len;
1037 int i;
1038 cname_len = *size + 1;
1039 cname=(char*) malloc(sizeof(char)*cname_len);
1040 for(i=0;i<*size;i++) cname[i] = name[i];
1041 cname[*size]='\0';
1042 fclose(curfile);
1043 remove(cname);
1044 free(cname);
1045}
1046void _FCALL DELETE_TMPFILE (char *name, int *size)
1047{delete_tmpfile_ (name,size);}
1048
1049void delete_tmpfile__ (char *name, int *size)
1050{delete_tmpfile_ (name,size);}
1051
1052void delete_tmpfile (char *name, int *size)
1053{delete_tmpfile_ (name,size);}
1054
1055
1056
1057
#define _FCALL
integer(8), private ssize
n
void file_init()
#define COMP_BUFFER_SIZE
void _FCALL FILE_INIT()
void close_c_()
void write_s_c_(int *w, int *len)
void write_db_array_c_(double *w, int *len)
void _FCALL FILE_SIZE_C(long *size)
void write_c_c_txt(char *w, int *len)
void _FCALL WRITE_C_C(int *w, int *len)
void _FCALL CUR_FIL_C(int *nf)
void write_c_c_txt__(char *w, int *len)
void file_init_()
void write_db_c__(double *w, int *len)
void file_size_(int *filesize)
void _FCALL CLOSE_C()
void read_c_c_(int *w, int *len)
void read_c_c(int *w, int *len)
void write_i_array_c__(int *w, int *len)
void file_size_c_(long *size)
int Compress_Buffer(unsigned char *input, int inputSize, unsigned char *output, int outputSize)
void close_c__()
void arret_c(int n)
void read_c_c__(int *w, int *len)
void write_s_c(int *w, int *len)
void _FCALL WRITE_DB_ARRAY_C(double *w, int *len)
void write_i_c(int *w, int *len)
gzFile compress_read_buffer[100]
void flu_fil_c()
void _FCALL READ_I_C(int *w, int *len)
int outfile_mod[100]
void write_c_c__(int *w, int *len)
void write_c_c_(int *w, int *len)
void write_r_c(float *w, int *len)
void read_i_c(int *w, int *len)
void IEEE_ASCII_to_real(float *reel, unsigned char octet[4])
Definition ieee.cpp:126
void cur_fil_c_(int *nf)
void eor_c_(int *len)
void write_db_c_(double *w, int *len)
void read_db_c(double *w, int *len)
void eor_c(int *len)
void write_db_array_c__(double *w, int *len)
void close_c()
void IEEE_ASCII_to_integer(int *entier, unsigned char octet[4])
Definition ieee.cpp:47
void integer_to_IEEE_ASCII(int entier, unsigned char octet[4])
Definition ieee.cpp:39
void write_r_c_(float *w, int *len)
int cur_nf
void write_db_c(double *w, int *len)
void _FCALL WRITE_I_C(int *w, int *len)
void write_db_array_c(double *w, int *len)
void _FCALL WRITE_R_C(float *w, int *len)
void _FCALL READ_C_C(int *w, int *len)
void IEEE_ASCII_to_double(double *reel, unsigned char octet[1000][8], int len)
Definition ieee.cpp:256
void write_i_c__(int *w, int *len)
void open_c_(int *ifil, int *len, int *mod)
void open_c__(int *ifil, int *len, int *mod)
void read_db_array_c(double *w, int *len)
void fseek_end_c(int *lseek)
void cur_fil_c(int *nf)
void fseek_end_c_(int *lseek)
void flu_fil_c__()
void _FCALL DELETE_TMPFILE(char *name, int *size)
void _FCALL FILE_SIZE(int *filesize)
void _FCALL FSEEK_C_RD(int *lseek)
void _FCALL WRITE_DB_C(double *w, int *len)
void _FCALL WRITE_C_C_TXT(char *w, int *len)
void _FCALL READ_R_C(float *w, int *len)
void delete_tmpfile(char *name, int *size)
void flu_fil_c_()
void read_i_array_c_(int *w, int *len)
void ARRET(int *n)
void read_i_c_(int *w, int *len)
void read_r_c(float *w, int *len)
void double_to_IEEE_ASCII(double *reel, unsigned char octet[1000][8], int len)
Definition ieee.cpp:168
void write_i_array_c_(int *w, int *len)
void fseek_c_rd(int *lseek)
FILE * curfile
void filelen_sys__(char *ffilnam, int *len, int *size)
void delete_tmpfile_(char *name, int *size)
void close_buffer()
void file_size(int *filesize)
void arret_(int *n)
void _FCALL FLU_FIL_C()
void write_c_c_txt_(char *w, int *len)
void write_c_c(int *w, int *len)
void read_db_c_(double *w, int *len)
void fseek_c_rd__(int *lseek)
void _FCALL READ_I_ARRAY_C(int *w, int *len)
void _FCALL EOR_C(int *len)
void read_r_c_(float *w, int *len)
void _FCALL OPEN_C(int *ifil, int *len, int *mod)
void read_i_array_c(int *w, int *len)
void read_db_array_c_(double *w, int *len)
void fseek_c_rd_(int *lseek)
#define BUFLEN
void write_buffer(unsigned char *buf, int type_size, int length)
void open_c(int *ifil, int *len, int *mod)
void filelen_sys(char *ffilnam, int *len, int *size)
void real_to_IEEE_ASCII(float reel, unsigned char octet[4])
Definition ieee.cpp:65
void delete_tmpfile__(char *name, int *size)
void write_i_array_c(int *w, int *len)
void _FCALL WRITE_S_C(int *w, int *len)
void _FCALL WRITE_I_ARRAY_C(int *w, int *len)
void _FCALL READ_DB_C(double *w, int *len)
FILE * outfile[100]
void _FCALL FSEEK_END_C(int *lseek)
void _FCALL READ_DB_ARRAY_C(double *w, int *len)
int compress_buffer_length[100]
void _FCALL FILELEN_SYS(char *ffilnam, int *len, int *size)
void write_i_c_(int *w, int *len)
unsigned char * compress_write_buffer[100]
void cur_fil_c__(int *nf)
void filelen_sys_(char *ffilnam, int *len, int *size)
void file_size__(int *filesize)