@@ -570,6 +570,66 @@ XDI_readfile(char *filename, XDIFile *xdifile) {
570
570
571
571
}
572
572
573
+ _EXPORT (void )
574
+ XDI_writefile (XDIFile * xdifile , char * filename ) {
575
+ int i , j , count ;
576
+
577
+ char quote [1025 ];
578
+ const char s [2 ] = "\n" ;
579
+ char * token ;
580
+
581
+ int regex_status ;
582
+ struct slre_cap caps [3 ];
583
+
584
+ FILE * fp ;
585
+ fp = fopen (filename , "w" );
586
+
587
+ /* version line */
588
+ strcpy (quote , xdifile -> comments );
589
+ fprintf (fp , "# XDI/%s %s\n" , xdifile -> xdi_version , xdifile -> extra_version );
590
+
591
+ /* metadata section */
592
+ for (i = 0 ; i < xdifile -> nmetadata ; i ++ ) {
593
+ fprintf (fp , "# %s.%s: %s\n" ,
594
+ xdifile -> meta_families [i ],
595
+ xdifile -> meta_keywords [i ],
596
+ xdifile -> meta_values [i ]);
597
+ }
598
+
599
+ /* user comments */
600
+ fprintf (fp , "#////////////////////////\n" );
601
+ count = 0 ;
602
+ token = strtok (quote , s ); /* get the first token */
603
+ while ( token != NULL ) { /* walk through other tokens, skipping empty */
604
+ if (count == 0 ) { /* take care with empty first token */
605
+ regex_status = slre_match ("^\\s*$" , token , strlen (token ), caps , 2 , 0 );
606
+ if (regex_status < 0 ) {
607
+ fprintf (fp , "#%s\n" , token );
608
+ }
609
+ } else {
610
+ fprintf (fp , "#%s\n" , token );
611
+ }
612
+ ++ count ;
613
+ token = strtok (NULL , s );
614
+ }
615
+ fprintf (fp , "#------------------------\n" );
616
+
617
+ /* column labels */
618
+ fprintf (fp , "# " );
619
+ for (i = 0 ; i < xdifile -> narrays ; i ++ ) {
620
+ fprintf (fp , " %s " , xdifile -> array_labels [i ]);
621
+ }
622
+ fprintf (fp , "\n" );
623
+
624
+ /* data table */
625
+ for (i = 0 ; i < xdifile -> npts ; i ++ ) {
626
+ for (j = 0 ; j < xdifile -> narrays ; j ++ ) {
627
+ fprintf (fp , " %-12.8g" , xdifile -> array [j ][i ]);
628
+ }
629
+ fprintf (fp , "\n" );
630
+ }
631
+
632
+ }
573
633
574
634
/* ============================================================================ */
575
635
/* array management section */
0 commit comments