CEMPD / SMOKE

Create emissions inputs for multiple air quality modeling systems with unmatched speed and flexibility
https://www.cmascenter.org/smoke/
48 stars 22 forks source link

garbage binary in log files when Y/N env var is set to ' ' #81

Open cseppan opened 1 year ago

cseppan commented 1 year ago

Noticed this in some of the log files created from the training data package. Some of the log files have binary data which means grep needs the "-a" flag to work.

grep ARINV smkinven_rwc_2018gg_18j.log Binary file smkinven_rwc_2018gg_18j.log matches

grep -a ARINV smkinven_rwc_2018gg_18j.log File "ARINV" opened for input on unit: 98

Looking at the file in vi, the binary characters show up when a setting read with ENVYN is ' ':

 >>--->> WARNING in subroutine envync
 Value for DAY_SPECIFIC_YN not T,F,Y, or N : ' ', returning defaultval    FALSE^@ ^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@Valu0^@     ô³^Nrûf0^Pý^Xý^?^@^@0^Pý^Xý^?^@^@@^Rý^Xý^?^@^@<88>­u^@^@^@^@^@`^Qý^Xý^?^@^@^@^@^@^@^@^@^@^@,^A^@^@^@^@^@^@^Uëê^QÚ^T^@^@^A<80>­ûÚ^T^@^@@^Rý^Xý^?^@^@@^Rý^Xý^?^@^@@^Rý^Xý^?^@^@@^Rý^Xý^?^@^@^V¢a^@^@^@^@^@^A^@^@^@ÿÿÿÿ^@ ^@^@^@^@^@^@<90>8m^D^@^@^@^@^D^Qý^Xý^?^@^@

Need to check the version of the I/O API in use

cseppan commented 1 year ago

Training data package with SMOKE 5.0 executables /proj/ie/proj/SMOKE/training/smoke_training_20231003.tar.gz

hnqtran commented 1 year ago

Garbage binary also found in smoke report files. e.g. $REP_ROOT/inv/rep_rwc_2018gg_18j_inv_state.txt

hnqtran commented 1 year ago

No garbage found in smkinven_rwc_2018gg_18j.log if SMOKE was compiled with gfortran.

However, there was array out-of-bound issue in variable OUTDNAM( RPT_%NUMDATA, RCNT ) occurred in subroutine WRREPHDR (src/smqa/wrrephdr.f) when SMOKE was compiled with gfortran.

When SMOKE is compiled with gfortran, segmentation fault occurred and point back to this error

At line 1900 of file /proj/ie/proj/SMOKE/htran/SMOKE_DEV/src/emqa/wrrephdr.f 
Fortran runtime error: Index '20' of dimension 1 of array 'outdnam' above upper bound of 19 
Error termination. Backtrace: 
#0  0x46a061 in ??? 
#1  0x45a848 in ??? 
#2  0x4036ec in ??? 
#3  0x14d1c9451d84 in ??? 
#4  0x40374d in ??? 
#5  0xffffffffffffffff in ??? 
0.196u 0.018s 0:00.38 52.6% 0+0k 22064+56io 102pf+0w 

Code snip set with new line inserted for debuging:

 write(*,*)"HTdbg: ", "STIDX=",STIDX,"EDIDX=",EDIDX 
            DO J = STIDX, EDIDX 
                    write(*,*)"HTdbg: ", "J=",J,";",OUTDNAM( J,RCNT ) 
                    IF( RPT_%RPTMODE .EQ. 3 ) THEN 
                        L2 = LEN_TRIM( HEADERS( IHDRDATA ) ) 
                        W1 = MAX( NLEFT, W1, L2 ) 
                    ELSE 
                        L2 = LEN_TRIM( OUTDNAM( J,RCNT ) ) 
                        W1  = MAX( NLEFT, W1, L2, LN ) 
                    END IF 
           END DO 

Such error did not occur if SMOKE was compiled with ifort, which just assign garbage value to OUTDNAME untill it is filled

HTdbg: SIZE(OUTDNAM)          19 
HTdbg: STIDX=           1 EDIDX=          77 
HTdbg: J=           1 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=           2 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=           3 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=           4 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=           5 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=           6 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=           7 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=           8 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=           9 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=          10 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=          11 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=          12 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=          13 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=          14 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=          15 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=          16 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=          17 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=          18 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=          19 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=          20 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=          21 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=          22 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=          23 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=          24 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=          25 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=          26 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=          27 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=          28 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=          29 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=          30 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=          31 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=          32 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=          33 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=          34 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=          35 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=          36 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=          37 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=          38 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=          39 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=          40 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=          41 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=          42 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=          43 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=          44 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=          45 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=          46 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=          47 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=          48 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=          49 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=          50 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=          51 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=          52 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=          53 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=          54 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=          55 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=          56 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=          57 ;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 
HTdbg: J=          58 ;PM2_5 
HTdbg: J=          59 ;PAL 
HTdbg: J=          60 ;PCA 
HTdbg: J=          61 ;PCL 
HTdbg: J=          62 ;PEC 
HTdbg: J=          63 ;PFE 
HTdbg: J=          64 ;PH2O 
HTdbg: J=          65 ;PK 
HTdbg: J=          66 ;PMG 
HTdbg: J=          67 ;PMN 
HTdbg: J=          68 ;PMOTHR 
HTdbg: J=          69 ;PNA 
HTdbg: J=          70 ;PNCOM 
HTdbg: J=          71 ;PNH4 
HTdbg: J=          72 ;PNO3 
HTdbg: J=          73 ;POC 
HTdbg: J=          74 ;PSI 
HTdbg: J=          75 ;PSO4 
HTdbg: J=          76 ;PTI 
HTdbg: J=          77 ;PM2_5 

gcc.smkinven_rwc_2018gg_18j.log

hnqtran commented 1 year ago

Update: ifortran would pick up out-of-bound error if SMOKE was compiled with "-check bounds" flag. In SMOKE/src/Makeinclude

EFLAG = -extend-source 132 -zero -static-intel -debug -check bounds # Intel Fortran

hnqtran commented 9 months ago

Fixed by modified $IOAPI_HOME/ioapi/m3err.F

Original code block:

        IF ( FATAL ) THEN
            CALL M3EXIT( CALLER, JDATE, JTIME, MSGTXT, 2 )
        ELSE    !  not endflag
            CALL M3WARN( CALLER, JDATE, JTIME, MSGTXT )
        END IF

Modified code block:

        INTEGER         L

        L = LEN_TRIM( MSGTXT )
        IF ( FATAL ) THEN
            CALL M3EXIT( CALLER, JDATE, JTIME, MSGTXT(1:L), 2 )
        ELSE    !  not endflag
            CALL M3WARN( CALLER, JDATE, JTIME, MSGTXT(1:L) )
        END IF

Re-compile both IOAPI and SMOKE to take the fix into effect.

cjcoats commented 5 months ago

^@ is the normal text-representation of ASCII-NULL. This log-output looks like something coming from a C-language subroutine or something, where calloc() fills the entire allocated array with NULLs rather than something from Fortran, where the Standard says that strings are always filled or padded with ACII blanks (and so that the TRIM() in M3EXIT and M3WARN works correctly -- which it doesn't with NULL-padded strings). So this is a programmer-error somewhere upstream of these calls.

And probably coming from C programmer who does not know how to correctly interface with Fortran, in spite of the fact that there are numerous examples of that in the I/O API ;-(

NOTE: M3ERR was declared OBSOLETE for I/O API Prototype 0.5 in July 1992, and has remained obsolete since. Do not use it !!!