I have the following code:
#!/bin/csh
clear
set cloud_file="/home/labs/koren/davidsr/general_scripts/MFP_10_PP_Parmas.txt" # to fill
set mie_tables_dir='/home/labs/koren/davidsr/SHDOM_MAIN/MIE_TABLES/non_polo_wave_0.7_water_50R_s0.5_e25_max_70.mie' # to fill
set prp_dir='${pp_dir}/pp_prp/'
set num_lwp=7 # to fill
set num_r=3 # to fill
#for each wavelength
foreach wav (0.7 1.61)
echo "current wavelength is: $wav"
set iter=1
while ($iter <= $num_r)
@ last_line=$iter * $num_lwp + $iter
@ first_line=$last_line - $num_lwp
@ second_line=$first_line + 1
set R_eff=`awk "NR==$first_line {print}" $cloud_file`
set LWP=`awk "NR==$second_line, NR==$last_line {print}" $cloud_file`
@ iter++
foreach r ($R_eff)
set r=$r | tr "\n" " "
set r=$r | tr "\r" " "
echo "current radius is: $r"
foreach lwp ($LWP)
set lwp=$lwp | tr "\n" " "
set lwp=$lwp | tr "\r" " "
echo "current lwp is: $lwp"
# echo "${prp_name}"
# prp_name+="${prp_name}_Re_${r}"
# echo "${prp_name}"
# set prp_name3="${prp_name2}_wav_${wav}"
# echo "${prp_name3}"
set prp_name="pp_LWP_${lwp}_Re_${r}_wav_${wav}.prp"
echo "${prp_name}"
end
end
end
end
which the cloud file looks like:
1.0
39.999
80.001
120.0
159.999
200.001
240.0
279.999
2.0
39.999
80.001
120.0
159.999
200.001
240.0
279.999
although it should print the prp_name as constructed above I get the following:
current radius is: 3.0
current lwp is: 39.999
_wav_1.61.prp
current lwp is: 80.001
_wav_1.61.prp
current lwp is: 120.0
_wav_1.61.prp
current lwp is: 159.999
_wav_1.61.prp9
current lwp is: 200.001
_wav_1.61.prp1
current lwp is: 240.0
_wav_1.61.prp
current lwp is: 279.999
_wav_1.61.prp9
I couldn't fix the issue, would appreciate some help
This code seems to run ok...here's the output I get when run on my Linux system..
current wavelength is: 0.7
current radius is: 1.0
current lwp is: 39.999
pp_LWP_39.999_Re_1.0_wav_0.7.prp
current lwp is: 80.001
pp_LWP_80.001_Re_1.0_wav_0.7.prp
current lwp is: 120.0
pp_LWP_120.0_Re_1.0_wav_0.7.prp
current lwp is: 159.999
pp_LWP_159.999_Re_1.0_wav_0.7.prp
current lwp is: 200.001
pp_LWP_200.001_Re_1.0_wav_0.7.prp
current lwp is: 240.0
pp_LWP_240.0_Re_1.0_wav_0.7.prp
current lwp is: 279.999
pp_LWP_279.999_Re_1.0_wav_0.7.prp
current radius is: 2.0
current lwp is: 39.999
pp_LWP_39.999_Re_2.0_wav_0.7.prp
current lwp is: 80.001
pp_LWP_80.001_Re_2.0_wav_0.7.prp
current lwp is: 120.0
pp_LWP_120.0_Re_2.0_wav_0.7.prp
current lwp is: 159.999
pp_LWP_159.999_Re_2.0_wav_0.7.prp
current lwp is: 200.001
pp_LWP_200.001_Re_2.0_wav_0.7.prp
current lwp is: 240.0
pp_LWP_240.0_Re_2.0_wav_0.7.prp
current lwp is: 279.999
pp_LWP_279.999_Re_2.0_wav_0.7.prp
current wavelength is: 1.61
current radius is: 1.0
current lwp is: 39.999
pp_LWP_39.999_Re_1.0_wav_1.61.prp
current lwp is: 80.001
pp_LWP_80.001_Re_1.0_wav_1.61.prp
current lwp is: 120.0
pp_LWP_120.0_Re_1.0_wav_1.61.prp
current lwp is: 159.999
pp_LWP_159.999_Re_1.0_wav_1.61.prp
current lwp is: 200.001
pp_LWP_200.001_Re_1.0_wav_1.61.prp
current lwp is: 240.0
pp_LWP_240.0_Re_1.0_wav_1.61.prp
current lwp is: 279.999
pp_LWP_279.999_Re_1.0_wav_1.61.prp
current radius is: 2.0
current lwp is: 39.999
pp_LWP_39.999_Re_2.0_wav_1.61.prp
current lwp is: 80.001
pp_LWP_80.001_Re_2.0_wav_1.61.prp
current lwp is: 120.0
pp_LWP_120.0_Re_2.0_wav_1.61.prp
current lwp is: 159.999
pp_LWP_159.999_Re_2.0_wav_1.61.prp
current lwp is: 200.001
pp_LWP_200.001_Re_2.0_wav_1.61.prp
current lwp is: 240.0
pp_LWP_240.0_Re_2.0_wav_1.61.prp
current lwp is: 279.999
pp_LWP_279.999_Re_2.0_wav_1.61.prp
1 Like
The following does not work as intended:
set r=$r | tr "\n" " "
set r=$r | tr "\r" " "
set lwp=$lwp | tr "\n" " "
set lwp=$lwp | tr "\r" " "
Perhaps the input is DOS format, and you want to convert \r and \n to space; then the following might work better
set r=`echo "$r" | tr "\r\n" " "`
set lwp=`echo "$lwp" | tr "\r\n" " "`
In tr the string1 can ccontain more than one character; then string2 should have more than one character (here: two spaces) to allow a one-to-one mapping (otherwise different tr versions produce different results).